File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.43: download - view: text, annotated - select for diffs
Tue Dec 9 00:43:47 2003 UTC (20 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Default autoenroll start and end times set to now and 6 months hence. Changes to some other default settings as per Matthew's suggestions.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.43 2003/12/09 00:43:47 raeburn 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: use Apache::lonlocal;
   51: use Apache::londropadd;
   52: 
   53: # ================================================ Get course directory listing
   54: 
   55: sub crsdirlist {
   56:     my ($courseid,$which)=@_;
   57:     unless ($which) { $which=''; }
   58:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   59:     my @listing=&Apache::lonnet::dirlist
   60: 	($which,$crsdata{'domain'},$crsdata{'num'},
   61: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
   62:     my @output=();
   63:     foreach (@listing) {
   64: 	unless ($_=~/^\./) {
   65: 	    push (@output,(split(/\&/,$_))[0]);
   66: 	}
   67:     }
   68:     return @output;
   69: }
   70: 
   71: # ============================================================= Read a userfile
   72: 
   73: sub readfile {
   74:     my ($courseid,$which)=@_;
   75:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   76:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
   77: 				    $crsdata{'num'}.'/'.$which);
   78: }
   79: 
   80: # ============================================================ Write a userfile
   81: 
   82: sub writefile {
   83:     (my $courseid, my $which,$ENV{'form.output'})=@_;
   84:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   85:     return &Apache::lonnet::finishuserfileupload(
   86: 					  $crsdata{'num'},$crsdata{'domain'},
   87: 					  $crsdata{'home'},
   88: 					  'output',$which);
   89: }
   90: 
   91: # ===================================================================== Rewrite
   92: 
   93: sub rewritefile {
   94:     my ($contents,%rewritehash)=@_;
   95:     foreach (keys %rewritehash) {
   96: 	my $pattern=$_;
   97: 	$pattern=~s/(\W)/\\$1/gs;
   98: 	my $new=$rewritehash{$_};
   99: 	$contents=~s/$pattern/$new/gs;
  100:     }
  101:     return $contents;
  102: }
  103: 
  104: # ============================================================= Copy a userfile
  105: 
  106: sub copyfile {
  107:     my ($origcrsid,$newcrsid,$which)=@_;
  108:     unless ($which=~/\.sequence$/) {
  109: 	return &writefile($newcrsid,$which,
  110: 		      &readfile($origcrsid,$which));
  111:     } else {
  112: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  113: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  114: 	return &writefile($newcrsid,$which,
  115: 		 &rewritefile(
  116:                      &readfile($origcrsid,$which),
  117: 	    (
  118:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  119:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
  120:             )));
  121:     }
  122: }
  123: 
  124: # =============================================================== Copy a dbfile
  125: 
  126: sub copydb {
  127:     my ($origcrsid,$newcrsid,$which)=@_;
  128:     $which=~s/\.db$//;
  129:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  130:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  131:     my %data=&Apache::lonnet::dump
  132: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
  133:     return &Apache::lonnet::put
  134: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
  135: }
  136: 
  137: # ========================================================== Copy resourcesdata
  138: 
  139: sub copyresourcedb {
  140:     my ($origcrsid,$newcrsid)=@_;
  141:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  142:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  143:     my %data=&Apache::lonnet::dump
  144: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
  145:     $origcrsid=~s/^\///;
  146:     $origcrsid=~s/\//\_/;
  147:     $newcrsid=~s/^\///;
  148:     $newcrsid=~s/\//\_/;
  149:     my %newdata=();
  150:     undef %newdata;
  151:     my $startdate=$data{$origcrsid.'.0.opendate'};
  152:     my $today=time;
  153:     my $delta=0;
  154:     if ($startdate) {
  155: 	my $oneday=60*60*24;
  156: 	$delta=$today-$startdate;
  157: 	$delta=int($delta/$oneday)*$oneday;
  158:     }
  159: # ugly retro fix for broken version of types
  160:     foreach (keys %data) {
  161: 	if ($_=~/\wtype$/) {
  162: 	    my $newkey=$_;
  163: 	    $newkey=~s/type$/\.type/;
  164: 	    $data{$newkey}=$data{$_};
  165: 	    delete $data{$_};
  166: 	}
  167:     }
  168: # adjust symbs
  169:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
  170:     $pattern=~s/(\W)/\\$1/gs;
  171:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
  172:     foreach (keys %data) {
  173: 	if ($_=~/$pattern/) {
  174: 	    my $newkey=$_;
  175: 	    $newkey=~s/$pattern/$new/;
  176: 	    $data{$newkey}=$data{$_};
  177: 	    delete $data{$_};
  178: 	}
  179:     }
  180: # adjust dates
  181:     foreach (keys %data) {
  182: 	my $thiskey=$_;
  183: 	$thiskey=~s/^$origcrsid/$newcrsid/;
  184: 	$newdata{$thiskey}=$data{$_};
  185: 	if ($data{$_.'.type'}=~/^date/) {
  186: 	    $newdata{$thiskey}=$newdata{$thiskey}+$delta;
  187: 	}
  188:     }
  189:     return &Apache::lonnet::put
  190: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
  191: }
  192: 
  193: # ========================================================== Copy all userfiles
  194: 
  195: sub copyuserfiles {
  196:     my ($origcrsid,$newcrsid)=@_;
  197:     foreach (&crsdirlist($origcrsid,'userfiles')) {
  198: 	&copyfile($origcrsid,$newcrsid,$_);
  199:     }
  200: }
  201: # ========================================================== Copy all userfiles
  202: 
  203: sub copydbfiles {
  204:     my ($origcrsid,$newcrsid)=@_;
  205:     foreach (&crsdirlist($origcrsid)) {
  206: 	if ($_=~/\.db$/) {
  207: 	    unless 
  208:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
  209: 		 &copydb($origcrsid,$newcrsid,$_);
  210: 	     }
  211: 	}
  212:     }
  213: }
  214: 
  215: # ======================================================= Copy all course files
  216: 
  217: sub copycoursefiles {
  218:     my ($origcrsid,$newcrsid)=@_;
  219:     &copyuserfiles($origcrsid,$newcrsid);
  220:     &copydbfiles($origcrsid,$newcrsid);
  221:     &copyresourcedb($origcrsid,$newcrsid);
  222: }
  223: 
  224: # ===================================================== Phase one: fill-in form
  225: 
  226: sub print_course_creation_page {
  227:     my $r=shift;
  228:     my $defdom=$ENV{'request.role.domain'};
  229:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
  230:     my $course_home = '<select name="course_home" size="1">'."\n";
  231:     foreach my $server (sort(keys(%host_servers))) {
  232:         $course_home .= qq{<option value="$server"};
  233:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
  234:             $course_home .= " selected ";
  235:         }
  236:         $course_home .= qq{>$server $host_servers{$server}</option>};
  237:     }
  238:     $course_home .= "\n</select>\n";
  239:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  240:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  241:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
  242:     my $cloneform=&Apache::loncommon::select_dom_form
  243: 	($ENV{'request.role.domain'},'clonedomain').
  244: 		     &Apache::loncommon::selectcourse_link
  245: 		     ('ccrs','clonecourse','clonedomain');
  246:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
  247:     my $starttime = time;
  248:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  249:     my $date_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'createcourse');
  250:     my ($krbdef,$krbdefdom) =
  251:     &Apache::loncommon::get_kerberos_defaults($defdom);
  252:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
  253:     my %param = ( formname => 'document.ccrs',
  254:                    kerb_def_dom => $krbdefdom,
  255:                    kerb_def_auth => $krbdef
  256:                 );
  257:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  258:     my $intform = &Apache::loncommon::authform_internal(%param);
  259:     my $locform = &Apache::loncommon::authform_local(%param);
  260:     $r->print(<<ENDDOCUMENT);
  261: <html>
  262: <script language="JavaScript" type="text/javascript">
  263: var editbrowser = null;
  264: function openbrowser(formname,elementname) {
  265:     var url = '/res/?';
  266:     if (editbrowser == null) {
  267:         url += 'launch=1&';
  268:     }
  269:     url += 'catalogmode=interactive&';
  270:     url += 'mode=edit&';
  271:     url += 'form=' + formname + '&';
  272:     url += 'element=' + elementname + '&';
  273:     url += 'only=sequence' + '';
  274:     var title = 'Browser';
  275:     var options = 'scrollbars=1,resizable=1,menubar=0';
  276:     options += ',width=700,height=600';
  277:     editbrowser = open(url,title,options,'1');
  278:     editbrowser.focus();
  279: }
  280: $javascript_validations
  281: </script>
  282: $coursebrowserjs
  283: <head>
  284: <title>The LearningOnline Network with CAPA</title>
  285: </head>
  286: $bodytag
  287: $helplink
  288: <form action="/adm/createcourse" method="post" name="ccrs">
  289: <h2>Course Information</h2>
  290: <p>
  291: <b>Course Title:</b>
  292: <input type="text" size="50" name="title">
  293: </p><p>
  294: <b>Course Home Server:</b>$course_home
  295: </p><p>
  296: <b>Course ID/Number (optional)</b>
  297: <input type="text" size="30" name="crsid">
  298: </p><p>
  299: <h2>Institutional Information</h2>
  300: <p>
  301: The following entries will be used to identify the course according to the naming scheme adopted by your institution. Your choices will be used to map an internal LON-CAPA course ID to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution. This mapping is required if you choose to employ automatic population of class lists.
  302: </p><p>
  303: <b>Course Code</b>
  304: <input type="text" size="30" name="crscode" /><br/>
  305: (to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231)
  306: </p><p>
  307: <b>Section Numbers and corresponding LON-CAPA section/group IDs</b>
  308:  <input type="text" size="30" name="crssections" /><br/>
  309: (a comma separated list of institutional section numbers, each separated by a colon
  310: from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2)
  311: </p><p>
  312: <b>Crosslisted courses</b>
  313: <input type="text" size="30" name="crsxlist" /><br/>
  314: (a comma separated list of course sections crosslisted with the current course, with each entry including the institutional course section name followed by a colon and then the (optional) groupID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:bot2)
  315: </p>
  316: <h2>Course Content</h2>
  317: <table border="2">
  318: <tr><th>Completely new course</th><th>Clone an existing course</th></tr>
  319: <tr><td>
  320: <p>
  321: <b>Map:</b>
  322: <input type="text" size="50" name="topmap">
  323: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
  324: </p><p>
  325: <b>Do NOT generate as standard course</b><br /> 
  326: (only check if you know what you are doing):
  327: <input type="checkbox" name="nonstandard">
  328: </p>
  329: <p>
  330: <b>First Resource</b><br />(standard courses only):
  331: <input type="radio" name="firstres" value="blank">Blank
  332: &nbsp;
  333: <input type="radio" name="firstres" value="syl" checked>Syllabus
  334: &nbsp;
  335: <input type="radio" name="firstres" value="nav">Navigate
  336: </p>
  337: </td><td>
  338: Course ID: <input input type="text" size="25" name="clonecourse" value="" />
  339: <br />
  340: Domain: 
  341: $cloneform<br />&nbsp;<br />
  342: Additional settings, if specified below, will override cloned settings.
  343: </td></tr>
  344: </table>
  345: <h2>Assessment Parameters</h2>
  346: <p>
  347: <b>Open all assessments: </b>
  348: <input type="checkbox" name="openall" checked>
  349: </p>
  350: <h2>Messaging</h2>
  351: <p>
  352: <b>Set course policy feedback to Course Coordinator: </b>
  353: <input type="checkbox" name="setpolicy" checked>
  354: </p><p>
  355: <b>Set content feedback to Course Coordinator: </b>
  356: <input type="checkbox" name="setcontent" checked>
  357: </p>
  358: <h2>Communication</h2>
  359: <p>
  360: <b>Disable student resource discussion: </b>
  361: <input type="checkbox" name="disresdis" /> <br />
  362: <b>Disable student use of chatrooms: </b>
  363: <input type="checkbox" name="disablechat" />
  364: </p>
  365: <h2>Access Control</h2>
  366: <p>
  367: <b>Students need access key to enter course: </b>
  368: <input type="checkbox" name="setkeys" />
  369: </p>
  370: <h2>Course Coordinator</h2>
  371: <p>
  372: <b>Username:</b> <input type="text" size="15" name="ccuname" />
  373: </p><p>
  374: <b>Domain:</b> $domform
  375: </p><p>
  376: <b>Immediately expire own role as Course Coordinator:</b>
  377: <input type="checkbox" name="expireown" checked>
  378: </p><p>
  379: <h2>Automated enrollment settings</h2>
  380: The following settings control automatic enrollment of students in this class based
  381: on information available for this specific course from your institution's official classlists.
  382: </p>
  383: <p>
  384: <b>Automated adds</b>
  385: <input type="radio" name="autoadds" value="1" />Yes <input type="radio" name="autoadds" value="0" checked="true" />No
  386: </p><p>
  387: <b>Automated drops</b>
  388: <input type="radio" name="autodrops" value="1" />Yes <input type="radio" name="autodrops" value="0" checked="true" />No
  389: </p><p>
  390: <b>Duration of automated classlist updates</b>
  391: $date_table
  392: </p><p>
  393: <b>Please select the authentication mechanism.</b><br />
  394: Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process.
  395: </p><p>
  396: $krbform
  397: <br />
  398: $intform
  399: <br />
  400: $locform
  401: </p><p>
  402: <b>Notification of enrollment changes</b><br />
  403: Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?<br/>
  404: <input type="radio" name="notify" value="1" />Yes <input type="radio" name="notify"
  405: value="0" checked="true" />No
  406: </p><p>
  407: <b>Include retrieval of student photographs?</b> <input type="radio" name="showphotos" value="1" />Yes <input type="radio" name="showphotos" value="0" checked="true" />No
  408: </p><p>
  409: <input type="hidden" name="phase" value="two" />
  410: <input type="button" onClick="verify_message(this.form)" value="Open Course">
  411: </p>
  412: </form>
  413: </body>
  414: </html>
  415: ENDDOCUMENT
  416: }
  417: 
  418: # ====================================================== Phase two: make course
  419: 
  420: sub create_course {
  421:     my $r=shift;
  422:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  423:     my $ccuname=$ENV{'form.ccuname'};
  424:     my $ccdomain=$ENV{'form.ccdomain'};
  425:     $ccuname=~s/\W//g;
  426:     $ccdomain=~s/\W//g;
  427:     my $cdescr=$ENV{'form.title'};
  428:     my $curl=$ENV{'form.topmap'};
  429:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  430:     $r->print(<<ENDENHEAD);
  431: <html>
  432: <head>
  433: <title>The LearningOnline Network with CAPA</title>
  434: </head>
  435: $bodytag
  436: ENDENHEAD
  437:     #
  438:     # Verify data
  439:     #
  440:     # Check the veracity of the course coordinator
  441:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  442:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  443: 	return;
  444:     }
  445:     # Check the proposed home server for the course
  446:     my %host_servers = &Apache::loncommon::get_library_servers
  447:         ($ENV{'request.role.domain'});
  448:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  449:         $r->print('Invalid home server for course: '.
  450:                   $ENV{'form.course_home'}.'</body></html>');
  451:         return;
  452:     }
  453: #
  454: # Open course
  455: #
  456:     my %cenv=();
  457:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  458:                                                $cdescr,$curl,
  459:                                                $ENV{'form.course_home'},
  460:                                                $ENV{'form.nonstandard'});
  461: 
  462:     # Note: The testing routines depend on this being output; see 
  463:     # Utils::Course. This needs to at least be output as a comment
  464:     # if anyone ever decides to not show this, and Utils::Course::new
  465:     # will need to be suitably modified.
  466:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  467: #
  468: # Check if created correctly
  469: #
  470:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  471:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  472:     $r->print('Created on: '.$crsuhome.'<br>');
  473: #
  474: # Are we cloning?
  475: #
  476:     my $cloneid='';
  477:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
  478: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
  479:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
  480: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  481: 	if ($clonehome eq 'no_host') {
  482: 	    $r->print(
  483:     '<br /><font color="red">Attempting to clone non-existing course '.$cloneid.'</font>');
  484: 	} else {
  485: 	    $r->print(
  486:     '<br /><font color="green">Cloning course from '.$clonehome.'</font>');
  487: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
  488: # Copy all files
  489: 	    &copycoursefiles($cloneid,$courseid);
  490: # Restore URL
  491: 	    $cenv{'url'}=$oldcenv{'url'};
  492: # Restore title
  493: 	    $cenv{'description'}=$oldcenv{'description'};
  494: # Mark as cloned
  495: 	    $cenv{'clonedfrom'}=$cloneid;
  496: 	}
  497:     }
  498: #
  499: # Set environment (will override cloned, if existing)
  500: #
  501:     if ($ENV{'form.crsid'}) {
  502:         $cenv{'courseid'}=$ENV{'form.crsid'};
  503:     }
  504:     if ($ENV{'form.crscode'}) {
  505:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
  506:     }
  507:     if ($ENV{'form.crssections'}) {
  508:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
  509:     }
  510:     if ($ENV{'form.crsxlist'}) {
  511:         $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
  512:     }
  513:     if ($ENV{'form.autoadds'}) {
  514:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
  515:     }
  516:     if ($ENV{'form.autodrops'}) {
  517:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
  518:     }
  519:     if ($ENV{'form.notify'}) {
  520:       if ($ccuname) {
  521:         $cenv{'internal.notifylist'} = $ccuname;
  522:       }
  523:     }
  524:     if ($ccuname) {
  525:         $cenv{'internal.courseowner'} = $ccuname;
  526:     }
  527:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
  528:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
  529:     if ($ENV{'form.no_end_date'}) {
  530:       $enddate = 0;
  531:     }
  532:     $cenv{'internal.autostart'}=$startdate;
  533:     $cenv{'internal.autoend'}=$enddate;
  534:     if ($ENV{'form.showphotos'}) {
  535:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
  536:     }
  537:     if ($ENV{'form.login'} eq 'krb') {
  538:         $cenv{'internal.authtype'} = 'krb';
  539:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
  540:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
  541:     } elsif ($ENV{'form.login'} eq 'int') {
  542:         $cenv{'internal.authtype'} ='internal';
  543:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
  544:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
  545:         }
  546:     } elsif ($ENV{'form.login'} eq 'loc') {
  547:         $cenv{'internal.authtype'} = 'localauth';
  548:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
  549:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
  550:         }
  551:     }
  552:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
  553:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
  554:             $r->print('<font color="red" size="+1">'.
  555:                       'As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student'.'</font></p>');
  556:         }
  557:     }
  558:     if (($ccdomain) && ($ccuname)) {
  559:        if ($ENV{'form.setpolicy'}) {
  560:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  561:        }
  562:        if ($ENV{'form.setcontent'}) {
  563:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  564:        }
  565:     }
  566:     if ($ENV{'form.setkeys'}) {
  567:        $cenv{'keyaccess'}='yes';
  568:     }
  569:     if ($ENV{'form.disresdis'}) {
  570:         $cenv{'pch.roles.denied'}='st';
  571:     }
  572:     if ($ENV{'form.disablechat'}) {
  573:         $cenv{'plc.roles.denied'}='st';
  574:     }
  575: 
  576:     # Record we've not yet viewed the Course Initialization Helper for this 
  577:     # course
  578:     $cenv{'course.helper.not.run'} = 1;
  579:     #
  580:     # Use new Randomseed
  581:     #
  582:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  583:     #
  584:     # By default, use standard grading
  585:     $cenv{'grading'} = 'standard';
  586: 
  587:     $r->print('<br />Setting environment: '.                 
  588:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  589: #
  590: # Open all assignments
  591: #
  592:     if ($ENV{'form.openall'}) {
  593:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  594:        my %storecontent = ($storeunder         => time,
  595:                            $storeunder.'.type' => 'date_start');
  596:        
  597:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
  598:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  599:    }
  600: #
  601: # Set first page
  602: #
  603:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
  604: 	$r->print('Setting first resource: ');
  605:         my ($errtext,$fatal)=
  606:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  607:         $r->print(($fatal?$errtext:'read ok').' - ');
  608:         my $title; my $url;
  609:         if ($ENV{'form.firstres'} eq 'syl') {
  610: 	    $title='Syllabus';
  611:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  612:         } else {
  613:             $title='Navigate Contents';
  614:             $url='/adm/navmaps';
  615:         }
  616:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  617:         ($errtext,$fatal)=
  618:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  619:         $r->print(($fatal?$errtext:'write ok').'<br>');
  620:   }
  621: #
  622: # Make current user course adminstrator
  623: #
  624:     my $end=undef;
  625:     my $addition='';
  626:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  627:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
  628:     &Apache::lonnet::assignrole(
  629:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  630: #
  631: # Make additional user course administrator
  632: #
  633:    if (($ccdomain) && ($ccuname)) {
  634:     $r->print('Assigning role of course coordinator to '.
  635:                $ccuname.' at '.$ccdomain.': '.
  636:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  637:    }
  638:     if ($ENV{'form.setkeys'}) {
  639: 	$r->print(
  640:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
  641:     }
  642:     $r->print('<p>Roles will be active at next login.</p></body></html>');
  643: }
  644: 
  645: # ===================================================================== Handler
  646: sub handler {
  647:     my $r = shift;
  648: 
  649:     if ($r->header_only) {
  650:        &Apache::loncommon::content_type($r,'text/html');
  651:        $r->send_http_header;
  652:        return OK;
  653:     }
  654: 
  655:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  656:        &Apache::loncommon::content_type($r,'text/html');
  657:        $r->send_http_header;
  658: 
  659:        if ($ENV{'form.phase'} eq 'two') {
  660:            &create_course($r);
  661:        } else {
  662: 	   &print_course_creation_page($r);
  663:        }
  664:    } else {
  665:       $ENV{'user.error.msg'}=
  666:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  667:       return HTTP_NOT_ACCEPTABLE; 
  668:    }
  669:    return OK;
  670: } 
  671: 
  672: 1;
  673: __END__

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