File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.42: download - view: text, annotated - select for diffs
Fri Dec 5 21:59:31 2003 UTC (20 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- removing Debug message

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

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