File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.41: download - view: text, annotated - select for diffs
Fri Dec 5 21:34:48 2003 UTC (20 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Replaced local versions of javascript_validations and date_setting_table with calls to londropadd.pm to retrieve these functions, customized based on passed parameter - $mode = 'createcourse'.  This now supports entry of default authentication method and start and end dates for automated enrollment process.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.41 2003/12/05 21:34:48 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:     print STDERR "Course browser js is $coursebrowserjs\n";
  248:     my $date_table = &Apache::londropadd::date_setting_table('','','createcourse');
  249:     my ($krbdef,$krbdefdom) =
  250:     &Apache::loncommon::get_kerberos_defaults($defdom);
  251:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
  252:     my %param = ( formname => 'document.ccrs',
  253:                    kerb_def_dom => $krbdefdom,
  254:                    kerb_def_auth => $krbdef
  255:                 );
  256:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  257:     my $intform = &Apache::loncommon::authform_internal(%param);
  258:     my $locform = &Apache::loncommon::authform_local(%param);
  259:     $r->print(<<ENDDOCUMENT);
  260: <html>
  261: <script language="JavaScript" type="text/javascript">
  262: var editbrowser = null;
  263: function openbrowser(formname,elementname) {
  264:     var url = '/res/?';
  265:     if (editbrowser == null) {
  266:         url += 'launch=1&';
  267:     }
  268:     url += 'catalogmode=interactive&';
  269:     url += 'mode=edit&';
  270:     url += 'form=' + formname + '&';
  271:     url += 'element=' + elementname + '&';
  272:     url += 'only=sequence' + '';
  273:     var title = 'Browser';
  274:     var options = 'scrollbars=1,resizable=1,menubar=0';
  275:     options += ',width=700,height=600';
  276:     editbrowser = open(url,title,options,'1');
  277:     editbrowser.focus();
  278: }
  279: $javascript_validations
  280: </script>
  281: $coursebrowserjs
  282: <head>
  283: <title>The LearningOnline Network with CAPA</title>
  284: </head>
  285: $bodytag
  286: $helplink
  287: <form action="/adm/createcourse" method="post" name="ccrs">
  288: <h2>Course Information</h2>
  289: <p>
  290: <b>Course Title:</b>
  291: <input type="text" size="50" name="title">
  292: </p><p>
  293: <b>Course Home Server:</b>$course_home
  294: </p><p>
  295: <b>Course ID/Number (optional)</b>
  296: <input type="text" size="30" name="crsid">
  297: </p><p>
  298: <h2>Institutional Information</h2>
  299: <p>
  300: 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.
  301: </p><p>
  302: <b>Course Code</b>
  303: <input type="text" size="30" name="crscode" /><br/>
  304: (to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231)
  305: </p><p>
  306: <b>Section Numbers and corresponding LON-CAPA section/group IDs</b>
  307:  <input type="text" size="30" name="crssections" /><br/>
  308: (a comma separated list of institutional section numbers, each separated by a colon
  309: from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2)
  310: </p><p>
  311: <b>Crosslisted courses</b>
  312: <input type="text" size="30" name="crsxlist" /><br/>
  313: (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)
  314: </p>
  315: <h2>Course Content</h2>
  316: <table border="2">
  317: <tr><th>Completely new course</th><th>Clone an existing course</th></tr>
  318: <tr><td>
  319: <p>
  320: <b>Map:</b>
  321: <input type="text" size="50" name="topmap">
  322: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
  323: </p><p>
  324: <b>Do NOT generate as standard course</b><br /> 
  325: (only check if you know what you are doing):
  326: <input type="checkbox" name="nonstandard">
  327: </p>
  328: <p>
  329: <b>First Resource</b><br />(standard courses only):
  330: <input type="radio" name="firstres" value="blank">Blank
  331: &nbsp;
  332: <input type="radio" name="firstres" value="syl" checked>Syllabus
  333: &nbsp;
  334: <input type="radio" name="firstres" value="nav">Navigate
  335: </p>
  336: </td><td>
  337: Course ID: <input input type="text" size="25" name="clonecourse" value="" />
  338: <br />
  339: Domain: 
  340: $cloneform<br />&nbsp;<br />
  341: Additional settings, if specified below, will override cloned settings.
  342: </td></tr>
  343: </table>
  344: <h2>Assessment Parameters</h2>
  345: <p>
  346: <b>Open all assessments: </b>
  347: <input type="checkbox" name="openall" checked>
  348: </p>
  349: <h2>Messaging</h2>
  350: <p>
  351: <b>Set course policy feedback to Course Coordinator: </b>
  352: <input type="checkbox" name="setpolicy" checked>
  353: </p><p>
  354: <b>Set content feedback to Course Coordinator: </b>
  355: <input type="checkbox" name="setcontent" checked>
  356: </p>
  357: <h2>Communication</h2>
  358: <p>
  359: <b>Disable student resource discussion: </b>
  360: <input type="checkbox" name="disresdis" /> <br />
  361: <b>Disable student use of chatrooms: </b>
  362: <input type="checkbox" name="disablechat" />
  363: </p>
  364: <h2>Access Control</h2>
  365: <p>
  366: <b>Students need access key to enter course: </b>
  367: <input type="checkbox" name="setkeys" />
  368: </p>
  369: <h2>Course Coordinator</h2>
  370: <p>
  371: <b>Username:</b> <input type="text" size="15" name="ccuname" />
  372: </p><p>
  373: <b>Domain:</b> $domform
  374: </p><p>
  375: <b>Immediately expire own role as Course Coordinator:</b>
  376: <input type="checkbox" name="expireown" checked>
  377: </p><p>
  378: <h2>Automated enrollment settings</h2>
  379: The following settings control automatic enrollment of students in this class based
  380: on information available for this specific course from your institution's official classlists.
  381: </p>
  382: <p>
  383: <b>Automated adds</b>
  384: <input type="radio" name="autoadds" value="1" checked="true" />Yes <input type="radio" name="autoadds" value="0" />No
  385: </p><p>
  386: <b>Automated drops</b>
  387: <input type="radio" name="autodrops" value="1" checked="true" />Yes <input type="radio" name="autodrops" value="0" />No
  388: </p><p>
  389: <b>Duration of automated classlist updates</b>
  390: $date_table
  391: </p><p>
  392: <b>Please select the authentication mechanism.</b><br />
  393: Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process.
  394: </p><p>
  395: $krbform
  396: <br />
  397: $intform
  398: <br />
  399: $locform
  400: </p><p>
  401: <b>Notification of enrollment changes</b><br />
  402: Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?<br/>
  403: <input type="radio" name="notify" value="1" />Yes <input type="radio" name="notify"
  404: value="0" />No
  405: </p><p>
  406: <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
  407: </p><p>
  408: <input type="hidden" name="phase" value="two" />
  409: <input type="button" onClick="verify_message(this.form)" value="Open Course">
  410: </p>
  411: </form>
  412: </body>
  413: </html>
  414: ENDDOCUMENT
  415: }
  416: 
  417: # ====================================================== Phase two: make course
  418: 
  419: sub create_course {
  420:     my $r=shift;
  421:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  422:     my $ccuname=$ENV{'form.ccuname'};
  423:     my $ccdomain=$ENV{'form.ccdomain'};
  424:     $ccuname=~s/\W//g;
  425:     $ccdomain=~s/\W//g;
  426:     my $cdescr=$ENV{'form.title'};
  427:     my $curl=$ENV{'form.topmap'};
  428:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  429:     $r->print(<<ENDENHEAD);
  430: <html>
  431: <head>
  432: <title>The LearningOnline Network with CAPA</title>
  433: </head>
  434: $bodytag
  435: ENDENHEAD
  436:     #
  437:     # Verify data
  438:     #
  439:     # Check the veracity of the course coordinator
  440:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  441:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  442: 	return;
  443:     }
  444:     # Check the proposed home server for the course
  445:     my %host_servers = &Apache::loncommon::get_library_servers
  446:         ($ENV{'request.role.domain'});
  447:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  448:         $r->print('Invalid home server for course: '.
  449:                   $ENV{'form.course_home'}.'</body></html>');
  450:         return;
  451:     }
  452: #
  453: # Open course
  454: #
  455:     my %cenv=();
  456:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  457:                                                $cdescr,$curl,
  458:                                                $ENV{'form.course_home'},
  459:                                                $ENV{'form.nonstandard'});
  460: 
  461:     # Note: The testing routines depend on this being output; see 
  462:     # Utils::Course. This needs to at least be output as a comment
  463:     # if anyone ever decides to not show this, and Utils::Course::new
  464:     # will need to be suitably modified.
  465:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  466: #
  467: # Check if created correctly
  468: #
  469:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  470:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  471:     $r->print('Created on: '.$crsuhome.'<br>');
  472: #
  473: # Are we cloning?
  474: #
  475:     my $cloneid='';
  476:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
  477: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
  478:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
  479: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  480: 	if ($clonehome eq 'no_host') {
  481: 	    $r->print(
  482:     '<br /><font color="red">Attempting to clone non-existing course '.$cloneid.'</font>');
  483: 	} else {
  484: 	    $r->print(
  485:     '<br /><font color="green">Cloning course from '.$clonehome.'</font>');
  486: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
  487: # Copy all files
  488: 	    &copycoursefiles($cloneid,$courseid);
  489: # Restore URL
  490: 	    $cenv{'url'}=$oldcenv{'url'};
  491: # Restore title
  492: 	    $cenv{'description'}=$oldcenv{'description'};
  493: # Mark as cloned
  494: 	    $cenv{'clonedfrom'}=$cloneid;
  495: 	}
  496:     }
  497: #
  498: # Set environment (will override cloned, if existing)
  499: #
  500:     if ($ENV{'form.crsid'}) {
  501:         $cenv{'courseid'}=$ENV{'form.crsid'};
  502:     }
  503:     if ($ENV{'form.crscode'}) {
  504:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
  505:     }
  506:     if ($ENV{'form.crssections'}) {
  507:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
  508:     }
  509:     if ($ENV{'form.crsxlist'}) {
  510:         $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
  511:     }
  512:     if ($ENV{'form.autoadds'}) {
  513:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
  514:     }
  515:     if ($ENV{'form.autodrops'}) {
  516:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
  517:     }
  518:     if ($ENV{'form.notify'}) {
  519:       if ($ccuname) {
  520:         $cenv{'internal.notifylist'} = $ccuname;
  521:       }
  522:     }
  523:     if ($ccuname) {
  524:         $cenv{'internal.courseowner'} = $ccuname;
  525:     }
  526:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
  527:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
  528:     if ($ENV{'form.no_end_date'}) {
  529:       $enddate = 0;
  530:     }
  531:     $cenv{'internal.autostart'}=$startdate;
  532:     $cenv{'internal.autoend'}=$enddate;
  533:     if ($ENV{'form.showphotos'}) {
  534:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
  535:     }
  536:     if ($ENV{'form.login'} eq 'krb') {
  537:         $cenv{'internal.authtype'} = 'krb';
  538:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
  539:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
  540:     } elsif ($ENV{'form.login'} eq 'int') {
  541:         $cenv{'internal.authtype'} ='internal';
  542:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
  543:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
  544:         }
  545:     } elsif ($ENV{'form.login'} eq 'loc') {
  546:         $cenv{'internal.authtype'} = 'localauth';
  547:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
  548:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
  549:         }
  550:     }
  551:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
  552:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
  553:             $r->print('<font color="red" size="+1">'.
  554:                       '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>');
  555:         }
  556:     }
  557:     if (($ccdomain) && ($ccuname)) {
  558:        if ($ENV{'form.setpolicy'}) {
  559:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  560:        }
  561:        if ($ENV{'form.setcontent'}) {
  562:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  563:        }
  564:     }
  565:     if ($ENV{'form.setkeys'}) {
  566:        $cenv{'keyaccess'}='yes';
  567:     }
  568:     if ($ENV{'form.disresdis'}) {
  569:         $cenv{'pch.roles.denied'}='st';
  570:     }
  571:     if ($ENV{'form.disablechat'}) {
  572:         $cenv{'plc.roles.denied'}='st';
  573:     }
  574: 
  575:     # Record we've not yet viewed the Course Initialization Helper for this 
  576:     # course
  577:     $cenv{'course.helper.not.run'} = 1;
  578:     #
  579:     # Use new Randomseed
  580:     #
  581:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  582:     #
  583:     # By default, use standard grading
  584:     $cenv{'grading'} = 'standard';
  585: 
  586:     $r->print('<br />Setting environment: '.                 
  587:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  588: #
  589: # Open all assignments
  590: #
  591:     if ($ENV{'form.openall'}) {
  592:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  593:        my %storecontent = ($storeunder         => time,
  594:                            $storeunder.'.type' => 'date_start');
  595:        
  596:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
  597:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  598:    }
  599: #
  600: # Set first page
  601: #
  602:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
  603: 	$r->print('Setting first resource: ');
  604:         my ($errtext,$fatal)=
  605:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  606:         $r->print(($fatal?$errtext:'read ok').' - ');
  607:         my $title; my $url;
  608:         if ($ENV{'form.firstres'} eq 'syl') {
  609: 	    $title='Syllabus';
  610:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  611:         } else {
  612:             $title='Navigate Contents';
  613:             $url='/adm/navmaps';
  614:         }
  615:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  616:         ($errtext,$fatal)=
  617:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  618:         $r->print(($fatal?$errtext:'write ok').'<br>');
  619:   }
  620: #
  621: # Make current user course adminstrator
  622: #
  623:     my $end=undef;
  624:     my $addition='';
  625:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  626:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
  627:     &Apache::lonnet::assignrole(
  628:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  629: #
  630: # Make additional user course administrator
  631: #
  632:    if (($ccdomain) && ($ccuname)) {
  633:     $r->print('Assigning role of course coordinator to '.
  634:                $ccuname.' at '.$ccdomain.': '.
  635:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  636:    }
  637:     if ($ENV{'form.setkeys'}) {
  638: 	$r->print(
  639:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
  640:     }
  641:     $r->print('<p>Roles will be active at next login.</p></body></html>');
  642: }
  643: 
  644: # ===================================================================== Handler
  645: sub handler {
  646:     my $r = shift;
  647: 
  648:     if ($r->header_only) {
  649:        &Apache::loncommon::content_type($r,'text/html');
  650:        $r->send_http_header;
  651:        return OK;
  652:     }
  653: 
  654:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  655:        &Apache::loncommon::content_type($r,'text/html');
  656:        $r->send_http_header;
  657: 
  658:        if ($ENV{'form.phase'} eq 'two') {
  659:            &create_course($r);
  660:        } else {
  661: 	   &print_course_creation_page($r);
  662:        }
  663:    } else {
  664:       $ENV{'user.error.msg'}=
  665:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  666:       return HTTP_NOT_ACCEPTABLE; 
  667:    }
  668:    return OK;
  669: } 
  670: 
  671: 1;
  672: __END__

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