File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.13: download - view: text, annotated - select for diffs
Thu Sep 5 19:37:00 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug 705 and various small fixes to londocs.pm

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.13 2002/09/05 19:37:00 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (My Desk
   29: #
   30: # (Internal Server Error Handler
   31: #
   32: # (Login Screen
   33: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   34: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
   35: #
   36: # 3/1/1 Gerd Kortemeyer)
   37: #
   38: # 3/1 Gerd Kortemeyer)
   39: #
   40: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
   41: #
   42: package Apache::loncreatecourse;
   43: 
   44: use strict;
   45: use Apache::Constants qw(:common :http);
   46: use Apache::lonnet;
   47: use Apache::loncommon;
   48: use Apache::lonratedt;
   49: use Apache::londocs;
   50: 
   51: # ===================================================== Phase one: fill-in form
   52: 
   53: sub print_course_creation_page {
   54:     my $r=shift;
   55:     my $defdom=$ENV{'request.role.domain'};
   56:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
   57:     my $course_home = '<select name="course_home" size="1">'."\n";
   58:     foreach my $server (sort(keys(%host_servers))) {
   59:         $course_home .= 
   60:           qq{<option value="$server">$server $host_servers{$server}</option>};
   61:     }
   62:     $course_home .= "\n</select>\n";
   63:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
   64:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
   65: 
   66:     $r->print(<<ENDDOCUMENT);
   67: <html>
   68: <script language="JavaScript" type="text/javascript">
   69: var editbrowser = null;
   70: function openbrowser(formname,elementname) {
   71:     var url = '/res/?';
   72:     if (editbrowser == null) {
   73:         url += 'launch=1&';
   74:     }
   75:     url += 'catalogmode=interactive&';
   76:     url += 'mode=edit&';
   77:     url += 'form=' + formname + '&';
   78:     url += 'element=' + elementname + '&';
   79:     url += 'only=sequence' + '';
   80:     var title = 'Browser';
   81:     var options = 'scrollbars=1,resizable=1,menubar=0';
   82:     options += ',width=700,height=600';
   83:     editbrowser = open(url,title,options,'1');
   84:     editbrowser.focus();
   85: }
   86: </script>
   87: <head>
   88: <title>The LearningOnline Network with CAPA</title>
   89: </head>
   90: $bodytag
   91: <form action="/adm/createcourse" method="post" name="ccrs">
   92: <h2>Course Information</h2>
   93: <p>
   94: <b>Course Title:</b>
   95: <input type="text" size="50" name="title">
   96: </p><p>
   97: <b>Course Home Server:</b>$course_home
   98: </p><p>
   99: <b>Course ID/Number (optional)</b>
  100: <input type="text" size="30" name="crsid">
  101: </p>
  102: <h2>Course Content</h2>
  103: <p>
  104: <b>Map:</b>
  105: <input type="text" size="50" name="topmap">
  106: <a href="javascript:openbrowser('ccrs','topmap')">Browse</a>
  107: </p><p>
  108: <b>Do NOT generate as standard course</b> 
  109: (only check if you know what you are doing):
  110: <input type="checkbox" name="nonstandard">
  111: </p>
  112: <p>
  113: <b>First Resource</b> (standard courses only):
  114: <input type="radio" name="firstres" value="blank" checked>Blank
  115: &nbsp;
  116: <input type="radio" name="firstres" value="syl">Syllabus
  117: &nbsp;
  118: <input type="radio" name="firstres" value="nav">Navigate
  119: </p>
  120: 
  121: <h2>Assessment Parameters</h2>
  122: <p>
  123: <b>Open all assessments: </b>
  124: <input type="checkbox" name="openall" checked>
  125: </p>
  126: <h2>Messaging</h2>
  127: <p>
  128: <b>Set course policy feedback to Course Coordinator: </b>
  129: <input type="checkbox" name="setpolicy" checked>
  130: </p><p>
  131: <b>Set content feedback to Course Coordinator: </b>
  132: <input type="checkbox" name="setcontent" checked>
  133: </p>
  134: 
  135: <h2>Course Coordinator</h2>
  136: <p>
  137: <b>Username:</b> <input type="text" size="15" name="ccuname" />
  138: </p><p>
  139: <b>Domain:</b> $domform
  140: </p><p>
  141: <b>Immediately expire own role as Course Coordinator:</b>
  142: <input type="checkbox" name="expireown" checked>
  143: </p><p>
  144: <input type="hidden" name="phase" value="two" />
  145: <input type="submit" value="Open Course">
  146: </p>
  147: </form>
  148: </body>
  149: </html>
  150: ENDDOCUMENT
  151: }
  152: 
  153: # ====================================================== Phase two: make course
  154: 
  155: sub create_course {
  156:     my $r=shift;
  157:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  158:     my $ccuname=$ENV{'form.ccuname'};
  159:     my $ccdomain=$ENV{'form.ccdomain'};
  160:     $ccuname=~s/\W//g;
  161:     $ccdomain=~s/\W//g;
  162:     my $cdescr=$ENV{'form.title'};
  163:     my $curl=$ENV{'form.topmap'};
  164:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  165:     $r->print(<<ENDENHEAD);
  166: <html>
  167: <head>
  168: <title>The LearningOnline Network with CAPA</title>
  169: </head>
  170: $bodytag
  171: ENDENHEAD
  172:     #
  173:     # Verify data
  174:     #
  175:     # Check the veracity of the course coordinator
  176:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  177:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  178: 	return;
  179:     }
  180:     # Check the proposed home server for the course
  181:     my %host_servers = &Apache::loncommon::get_library_servers
  182:         ($ENV{'request.role.domain'});
  183:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  184:         $r->print('Invalid home server for course: '.
  185:                   $ENV{'form.course_home'}.'</body></html>');
  186:         return;
  187:     }
  188: #
  189: # Open course
  190: #
  191:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  192:                                                $cdescr,$curl,
  193:                                                $ENV{'form.course_home'},
  194:                                                $ENV{'form.nonstandard'});
  195: 
  196:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  197: #
  198: # Check if created correctly
  199: #
  200:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  201:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  202:     $r->print('Created on: '.$crsuhome.'<br>');
  203: #
  204: # Set environment
  205: #
  206:     my %cenv=();
  207:     my $envflag=0;
  208:     if ($ENV{'form.crsid'}) {
  209: 	$envflag=1;
  210:         $cenv{'courseid'}=$ENV{'form.crsid'};
  211:     }
  212:     if (($ccdomain) && ($ccuname)) {
  213:        if ($ENV{'form.setpolicy'}) {
  214: 	   $envflag=1;
  215:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  216:        }
  217:        if ($ENV{'form.setcontent'}) {
  218:            $envflag=1;
  219:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  220:        }
  221:     }
  222:     if ($envflag) {
  223:        $r->print('Setting environment: '.                 
  224:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  225:    }
  226: #
  227: # Open all assignments
  228: #
  229:     if ($ENV{'form.openall'}) {
  230:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  231:        my %storecontent = ($storeunder        => time,
  232:                            $storeunder.'type' => 'date_start');
  233:        
  234:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
  235:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  236:    }
  237: #
  238: # Set first page
  239: #
  240:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
  241: 	$r->print('Setting first resource: ');
  242:         my ($errtext,$fatal)=
  243:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  244:         $r->print(($fatal?$errtext:'read ok').' - ');
  245:         my $title; my $url;
  246:         if ($ENV{'form.firstres'} eq 'syl') {
  247: 	    $title='Syllabus';
  248:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  249:         } else {
  250:             $title='Navigate Contents';
  251:             $url='/adm/navmaps';
  252:         }
  253:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  254:         my ($errtext,$fatal)=
  255:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  256:         $r->print(($fatal?$errtext:'write ok').'<br>');
  257:   }
  258: #
  259: # Make current user course adminstrator
  260: #
  261:     my $end=undef;
  262:     my $addition='';
  263:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  264:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
  265:     &Apache::lonnet::assignrole(
  266:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  267: #
  268: # Make additional user course administrator
  269: #
  270:    if (($ccdomain) && ($ccuname)) {
  271:     $r->print('Assigning role of course coordinator to '.
  272:                $ccuname.' at '.$ccdomain.': '.
  273:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  274:    }
  275:     $r->print('Roles will be active at next login.</body></html>');
  276: }
  277: 
  278: # ===================================================================== Handler
  279: sub handler {
  280:     my $r = shift;
  281: 
  282:     if ($r->header_only) {
  283:        $r->content_type('text/html');
  284:        $r->send_http_header;
  285:        return OK;
  286:     }
  287: 
  288:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  289:        $r->content_type('text/html');
  290:        $r->send_http_header;
  291: 
  292:        if ($ENV{'form.phase'} eq 'two') {
  293:            &create_course($r);
  294:        } else {
  295: 	   &print_course_creation_page($r);
  296:        }
  297:    } else {
  298:       $ENV{'user.error.msg'}=
  299:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  300:       return HTTP_NOT_ACCEPTABLE; 
  301:    }
  302:    return OK;
  303: } 
  304: 
  305: 1;
  306: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>