File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.40: download - view: text, annotated - select for diffs
Fri Dec 5 15:57:37 2003 UTC (20 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Added form elements to support setting of parameters for automated classlist updates, and saving of these choices to internal.parameter keys in the new course's environment.db GDBM file.

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

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