File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.56: download - view: text, annotated - select for diffs
Sat May 8 00:48:30 2004 UTC (20 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Work on key authority - can now create a course with key authority in
environment

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.56 2004/05/08 00:48:30 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::loncreatecourse;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use Apache::lonnet;
   35: use Apache::loncommon;
   36: use Apache::lonratedt;
   37: use Apache::londocs;
   38: use Apache::lonlocal;
   39: use Apache::londropadd;
   40: use lib '/home/httpd/lib/perl';
   41: use localenroll;
   42: 
   43: # ================================================ Get course directory listing
   44: 
   45: sub crsdirlist {
   46:     my ($courseid,$which)=@_;
   47:     unless ($which) { $which=''; }
   48:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   49:     my @listing=&Apache::lonnet::dirlist
   50: 	($which,$crsdata{'domain'},$crsdata{'num'},
   51: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
   52:     my @output=();
   53:     foreach (@listing) {
   54: 	unless ($_=~/^\./) {
   55: 	    push (@output,(split(/\&/,$_))[0]);
   56: 	}
   57:     }
   58:     return @output;
   59: }
   60: 
   61: # ============================================================= Read a userfile
   62: 
   63: sub readfile {
   64:     my ($courseid,$which)=@_;
   65:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   66:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
   67: 				    $crsdata{'num'}.'/'.$which);
   68: }
   69: 
   70: # ============================================================ Write a userfile
   71: 
   72: sub writefile {
   73:     (my $courseid, my $which,$ENV{'form.output'})=@_;
   74:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   75:     return &Apache::lonnet::finishuserfileupload(
   76: 					  $crsdata{'num'},$crsdata{'domain'},
   77: 					  $crsdata{'home'},
   78: 					  'output',$which);
   79: }
   80: 
   81: # ===================================================================== Rewrite
   82: 
   83: sub rewritefile {
   84:     my ($contents,%rewritehash)=@_;
   85:     foreach (keys %rewritehash) {
   86: 	my $pattern=$_;
   87: 	$pattern=~s/(\W)/\\$1/gs;
   88: 	my $new=$rewritehash{$_};
   89: 	$contents=~s/$pattern/$new/gs;
   90:     }
   91:     return $contents;
   92: }
   93: 
   94: # ============================================================= Copy a userfile
   95: 
   96: sub copyfile {
   97:     my ($origcrsid,$newcrsid,$which)=@_;
   98:     unless ($which=~/\.sequence$/) {
   99: 	return &writefile($newcrsid,$which,
  100: 		      &readfile($origcrsid,$which));
  101:     } else {
  102: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  103: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  104: 	return &writefile($newcrsid,$which,
  105: 		 &rewritefile(
  106:                      &readfile($origcrsid,$which),
  107: 	    (
  108:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  109:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
  110:             )));
  111:     }
  112: }
  113: 
  114: # =============================================================== Copy a dbfile
  115: 
  116: sub copydb {
  117:     my ($origcrsid,$newcrsid,$which)=@_;
  118:     $which=~s/\.db$//;
  119:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  120:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  121:     my %data=&Apache::lonnet::dump
  122: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
  123:     return &Apache::lonnet::put
  124: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
  125: }
  126: 
  127: # ========================================================== Copy resourcesdata
  128: 
  129: sub copyresourcedb {
  130:     my ($origcrsid,$newcrsid)=@_;
  131:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  132:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  133:     my %data=&Apache::lonnet::dump
  134: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
  135:     $origcrsid=~s/^\///;
  136:     $origcrsid=~s/\//\_/;
  137:     $newcrsid=~s/^\///;
  138:     $newcrsid=~s/\//\_/;
  139:     my %newdata=();
  140:     undef %newdata;
  141:     my $startdate=$data{$origcrsid.'.0.opendate'};
  142:     my $today=time;
  143:     my $delta=0;
  144:     if ($startdate) {
  145: 	my $oneday=60*60*24;
  146: 	$delta=$today-$startdate;
  147: 	$delta=int($delta/$oneday)*$oneday;
  148:     }
  149: # ugly retro fix for broken version of types
  150:     foreach (keys %data) {
  151: 	if ($_=~/\wtype$/) {
  152: 	    my $newkey=$_;
  153: 	    $newkey=~s/type$/\.type/;
  154: 	    $data{$newkey}=$data{$_};
  155: 	    delete $data{$_};
  156: 	}
  157:     }
  158: # adjust symbs
  159:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
  160:     $pattern=~s/(\W)/\\$1/gs;
  161:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
  162:     foreach (keys %data) {
  163: 	if ($_=~/$pattern/) {
  164: 	    my $newkey=$_;
  165: 	    $newkey=~s/$pattern/$new/;
  166: 	    $data{$newkey}=$data{$_};
  167: 	    delete $data{$_};
  168: 	}
  169:     }
  170: # adjust dates
  171:     foreach (keys %data) {
  172: 	my $thiskey=$_;
  173: 	$thiskey=~s/^$origcrsid/$newcrsid/;
  174: 	$newdata{$thiskey}=$data{$_};
  175: 	if ($data{$_.'.type'}=~/^date/) {
  176: 	    $newdata{$thiskey}=$newdata{$thiskey}+$delta;
  177: 	}
  178:     }
  179:     return &Apache::lonnet::put
  180: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
  181: }
  182: 
  183: # ========================================================== Copy all userfiles
  184: 
  185: sub copyuserfiles {
  186:     my ($origcrsid,$newcrsid)=@_;
  187:     foreach (&crsdirlist($origcrsid,'userfiles')) {
  188: 	&copyfile($origcrsid,$newcrsid,$_);
  189:     }
  190: }
  191: # ========================================================== Copy all userfiles
  192: 
  193: sub copydbfiles {
  194:     my ($origcrsid,$newcrsid)=@_;
  195:     foreach (&crsdirlist($origcrsid)) {
  196: 	if ($_=~/\.db$/) {
  197: 	    unless 
  198:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
  199: 		 &copydb($origcrsid,$newcrsid,$_);
  200: 	     }
  201: 	}
  202:     }
  203: }
  204: 
  205: # ======================================================= Copy all course files
  206: 
  207: sub copycoursefiles {
  208:     my ($origcrsid,$newcrsid)=@_;
  209:     &copyuserfiles($origcrsid,$newcrsid);
  210:     &copydbfiles($origcrsid,$newcrsid);
  211:     &copyresourcedb($origcrsid,$newcrsid);
  212: }
  213: 
  214: # ===================================================== Phase one: fill-in form
  215: 
  216: sub print_course_creation_page {
  217:     my $r=shift;
  218:     my $defdom=$ENV{'request.role.domain'};
  219:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
  220:     my $course_home = '<select name="course_home" size="1">'."\n";
  221:     foreach my $server (sort(keys(%host_servers))) {
  222:         $course_home .= qq{<option value="$server"};
  223:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
  224:             $course_home .= " selected ";
  225:         }
  226:         $course_home .= qq{>$server $host_servers{$server}</option>};
  227:     }
  228:     $course_home .= "\n</select>\n";
  229:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  230:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  231:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
  232:     my $cloneform=&Apache::loncommon::select_dom_form
  233: 	($ENV{'request.role.domain'},'clonedomain').
  234: 		     &Apache::loncommon::selectcourse_link
  235: 		     ('ccrs','clonecourse','clonedomain');
  236:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
  237:     my $starttime = time;
  238:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  239:     my $date_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'createcourse');
  240:     my ($krbdef,$krbdefdom) =
  241:     &Apache::loncommon::get_kerberos_defaults($defdom);
  242:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
  243:     my %param = ( formname => 'document.ccrs',
  244:                    kerb_def_dom => $krbdefdom,
  245:                    kerb_def_auth => $krbdef
  246:                 );
  247:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  248:     my $intform = &Apache::loncommon::authform_internal(%param);
  249:     my $locform = &Apache::loncommon::authform_local(%param);
  250:     my %lt=&Apache::lonlocal::texthash(
  251: 		    'cinf' => "Course Information",
  252:                     'ctit' => "Course Title",
  253:                     'chsr' => "Course Home Server",
  254:                     'cidn' => "Course ID/Number",
  255:                     'opt'  => "optional",
  256:                     'iinf' => "Institutional Information",
  257:                     'stat' => "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.",
  258:                     'ccod' => "Course Code",
  259:                     'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
  260:                     'snid' => "Section Numbers and corresponding LON-CAPA section/group IDs",
  261:                     'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2",
  262:                     'crcs' => "Crosslisted courses",
  263:                     'cscs' => "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", 
  264:                     'crco' => "Course Content",
  265:                     'cncr' => "Completely new course",
  266:                     'cecr' => "Clone an existing course", 
  267:                     'map'  => "Map",
  268:                     'smap' => "Select Map",
  269:                     'sacr' => "Do NOT generate as standard course",
  270:                     'ocik' => "only check if you know what you are doing",
  271:                     'fres' => "First Resource",
  272:                     'stco' => "standard courses only",
  273:                     'blnk' => "Blank",
  274:                     'sllb' => "Syllabus",
  275:                     'navi' => "Navigate",
  276:                     'cid'  => "Course ID",
  277:                     'dmn'  => "Domain",
  278:                     'asov' => "Additional settings, if specified below, will override cloned settings",
  279:                     'assp' => "Assessment Parameters",
  280:                     'oaas' => "Open all assessments",
  281:                     'mssg' => "Messaging",
  282:                     'scpf' => "Set course policy feedback to Course Coordinator",
  283:                     'scfc' => "Set content feedback to Course Coordinator",
  284:                     'cmmn' => "Communication",
  285:                     'dsrd' => "Disable student resource discussion",
  286:                     'dsuc' => "Disable student use of chatrooms",
  287:                     'acco' => "Access Control",
  288:                     'snak' => "Students need access key to enter course",
  289: 		    'kaut' => 
  290: 		    'Key authority (<tt>id@domain</tt>) if other than course',
  291:                     'cc'   => "Course Coordinator",
  292:                     'user' => "Username",
  293:                     'ierc' => "Immediately expire own role as Course Coordinator",
  294:                     'aens' => "Automated enrollment settings",
  295:                     'aesc' => "The following settings control automatic enrollment of students in this class based on information available for this specific course from your institution's official classlists.",
  296:                     'aadd' => "Automated adds",
  297:                     'yes'  => "Yes",
  298:                     'no'   => "No",
  299:                     'audr' => "Automated drops",
  300:                     'dacu' => "Duration of automated classlist updates",
  301:                     'psam' => "Please select the authentication mechanism",
  302:                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
  303:                     'nech' => "Notification of enrollment changes",
  304:                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  305:                     'irsp' => "Include retrieval of student photographs?",
  306: 		    'rshm' => 'Resource Space Home',
  307:                     'opco' => "Open Course"
  308: 				       );
  309:     $r->print(<<ENDDOCUMENT);
  310: <html>
  311: <script language="JavaScript" type="text/javascript">
  312: var editbrowser = null;
  313: function openbrowser(formname,elementname) {
  314:     var url = '/res/?';
  315:     if (editbrowser == null) {
  316:         url += 'launch=1&';
  317:     }
  318:     url += 'catalogmode=interactive&';
  319:     url += 'mode=edit&';
  320:     url += 'form=' + formname + '&';
  321:     url += 'element=' + elementname + '&';
  322:     url += 'only=sequence' + '';
  323:     var title = 'Browser';
  324:     var options = 'scrollbars=1,resizable=1,menubar=0';
  325:     options += ',width=700,height=600';
  326:     editbrowser = open(url,title,options,'1');
  327:     editbrowser.focus();
  328: }
  329: $javascript_validations
  330: </script>
  331: $coursebrowserjs
  332: <head>
  333: <title>The LearningOnline Network with CAPA</title>
  334: </head>
  335: $bodytag
  336: $helplink
  337: <form action="/adm/createcourse" method="post" name="ccrs">
  338: <h2>$lt{'cinf'}</h2>
  339: <p>
  340: <b>$lt{'ctit'}:</b>
  341: <input type="text" size="50" name="title">
  342: </p><p>
  343: <b>$lt{'chsr'}:</b>$course_home
  344: </p><p>
  345: <b>$lt{'cidn'} ($lt{'opt'})</b>
  346: <input type="text" size="30" name="crsid">
  347: </p><p>
  348: <h2>$lt{'iinf'}</h2>
  349: <p>
  350: $lt{'stat'}
  351: </p><p>
  352: <b>$lt{'ccod'}</b>
  353: <input type="text" size="30" name="crscode" /><br/>
  354: ($lt{'toin'})
  355: </p><p>
  356: <b>$lt{'snid'}</b>
  357:  <input type="text" size="30" name="crssections" /><br/>
  358: ($lt{'csli'})
  359: </p><p>
  360: <b>$lt{'crcs'}</b>
  361: <input type="text" size="30" name="crsxlist" /><br/>
  362: ($lt{'cscs'})
  363: </p>
  364: <h2>$lt{'crco'}</h2>
  365: <table border="2">
  366: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
  367: <tr><td>
  368: <p>
  369: <b>$lt{'map'}:</b>
  370: <input type="text" size="50" name="topmap">
  371: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  372: </p><p>
  373: <b>$lt{'sacr'}</b><br /> 
  374: ($lt{'ocik'}):
  375: <input type="checkbox" name="nonstandard">
  376: </p>
  377: <p>
  378: <b>$lt{'fres'}</b><br />($lt{'stco'}):
  379: <input type="radio" name="firstres" value="blank">$lt{'blnk'}
  380: &nbsp;
  381: <input type="radio" name="firstres" value="syl" checked>$lt{'sllb'}
  382: &nbsp;
  383: <input type="radio" name="firstres" value="nav">$lt{'navi'}
  384: </p>
  385: </td><td>
  386: $lt{'cid'}: <input input type="text" size="25" name="clonecourse" value="" />
  387: <br />
  388: $lt{'dmn'}: 
  389: $cloneform<br />&nbsp;<br />
  390: $lt{'asov'}.
  391: </td></tr>
  392: </table>
  393: <h2>$lt{'assp'}</h2>
  394: <p>
  395: <b>$lt{'oaas'}: </b>
  396: <input type="checkbox" name="openall" />
  397: </p>
  398: <h2>$lt{'mssg'}</h2>
  399: <p>
  400: <b>$lt{'scpf'}: </b>
  401: <input type="checkbox" name="setpolicy" checked>
  402: <br />
  403: <b>$lt{'scfc'}: </b>
  404: <input type="checkbox" name="setcontent" checked>
  405: </p>
  406: <h2>$lt{'cmmn'}</h2>
  407: <p>
  408: <b>$lt{'dsrd'}: </b>
  409: <input type="checkbox" name="disresdis" /> <br />
  410: <b>$lt{'dsuc'}: </b>
  411: <input type="checkbox" name="disablechat" />
  412: </p>
  413: <h2>$lt{'acco'}</h2>
  414: <p>
  415: <b>$lt{'snak'}: </b>
  416: <input type="checkbox" name="setkeys" /><br />
  417: <b>$lt{'kaut'}: </b>
  418: <input type="text" size="30" name="keyauth" />
  419: </p>
  420: <h2>$lt{'rshm'}</h2>
  421: <p>
  422: <b>$lt{'rshm'}: </b>
  423: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
  424: </p>
  425: <p>
  426: <h2>$lt{'aens'}</h2>
  427: $lt{'aesc'}
  428: </p>
  429: <p>
  430: <b>$lt{'aadd'}</b>
  431: <input type="radio" name="autoadds" value="1" />$lt{'yes'} <input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
  432: </p><p>
  433: <b>$lt{'audr'}</b>
  434: <input type="radio" name="autodrops" value="1" />$lt{'yes'} <input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}
  435: </p><p>
  436: <b>$lt{'dacu'}</b>
  437: $date_table
  438: </p><p>
  439: <b>$lt{'psam'}.</b><br />
  440: $lt{'pcda'}.
  441: </p><p>
  442: $krbform
  443: <br />
  444: $intform
  445: <br />
  446: $locform
  447: </p><p>
  448: <b>$lt{'nech'}</b><br />
  449: $lt{'nccl'}<br/>
  450: <input type="radio" name="notify" value="1" />$lt{'yes'} <input type="radio" name="notify"
  451: value="0" checked="true" />$lt{'no'}
  452: </p><p>
  453: <b>$lt{'irsp'}</b> <input type="radio" name="showphotos" value="1" />$lt{'yes'} <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
  454: </p>
  455: <hr />
  456: <h2>$lt{'cc'}</h2>
  457: <p>
  458: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
  459: </p><p>
  460: <b>$lt{'dmn'}:</b> $domform
  461: </p><p>
  462: <b>$lt{'ierc'}:</b>
  463: <input type="checkbox" name="expireown" checked>
  464: </p>
  465: <p>
  466: <input type="hidden" name="phase" value="two" />
  467: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}">
  468: </p>
  469: </form>
  470: </body>
  471: </html>
  472: ENDDOCUMENT
  473: }
  474: 
  475: # ====================================================== Phase two: make course
  476: 
  477: sub create_course {
  478:     my $r=shift;
  479:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  480:     my $ccuname=$ENV{'form.ccuname'};
  481:     my $ccdomain=$ENV{'form.ccdomain'};
  482:     $ccuname=~s/\W//g;
  483:     $ccdomain=~s/\W//g;
  484:     my $cdescr=$ENV{'form.title'};
  485:     my $curl=$ENV{'form.topmap'};
  486:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  487:     $r->print(<<ENDENHEAD);
  488: <html>
  489: <head>
  490: <title>The LearningOnline Network with CAPA</title>
  491: </head>
  492: $bodytag
  493: ENDENHEAD
  494:     #
  495:     # Verify data
  496:     #
  497:     # Check the veracity of the course coordinator
  498:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  499: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
  500:         $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
  501: 	$r->print(&mt("Please click Back on your browser and select another user, or "));
  502: 	$r->print('
  503: 	    <input type="hidden" name="phase" value="get_user_info" />
  504:             <input type="hidden" name="ccuname" value="'.$ccuname.'" />
  505:             <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
  506:             <input name="userrole" type="submit" value="'.
  507: 		  &mt('Create User').'" />
  508: 	</form></body></html>');
  509: 	return;
  510:     }
  511:     # Check the proposed home server for the course
  512:     my %host_servers = &Apache::loncommon::get_library_servers
  513:         ($ENV{'request.role.domain'});
  514:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  515:         $r->print(&mt('Invalid home server for course').': '.
  516:                   $ENV{'form.course_home'}.'</body></html>');
  517:         return;
  518:     }
  519: #
  520: # Open course
  521: #
  522:     my %cenv=();
  523:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  524:                                                $cdescr,$curl,
  525:                                                $ENV{'form.course_home'},
  526:                                                $ENV{'form.nonstandard'});
  527: 
  528:     # Note: The testing routines depend on this being output; see 
  529:     # Utils::Course. This needs to at least be output as a comment
  530:     # if anyone ever decides to not show this, and Utils::Course::new
  531:     # will need to be suitably modified.
  532:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  533: #
  534: # Check if created correctly
  535: #
  536:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  537:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  538:     $r->print(&mt('Created on').': '.$crsuhome.'<br>');
  539: #
  540: # Are we cloning?
  541: #
  542:     my $cloneid='';
  543:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
  544: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
  545:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
  546: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  547: 	if ($clonehome eq 'no_host') {
  548: 	    $r->print(
  549:     '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>');
  550: 	} else {
  551: 	    $r->print(
  552:     '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>');
  553: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
  554: # Copy all files
  555: 	    &copycoursefiles($cloneid,$courseid);
  556: # Restore URL
  557: 	    $cenv{'url'}=$oldcenv{'url'};
  558: # Restore title
  559: 	    $cenv{'description'}=$oldcenv{'description'};
  560: # Mark as cloned
  561: 	    $cenv{'clonedfrom'}=$cloneid;
  562: 	    delete($cenv{'default_enrollment_start_date'});
  563: 	    delete($cenv{'default_enrollment_end_date'});
  564: 	}
  565:     }
  566: #
  567: # Set environment (will override cloned, if existing)
  568: #
  569:     my @affiliates = ();  # Used to accumulate sections and crosslistings
  570:     if ($ENV{'form.crsid'}) {
  571:         $cenv{'courseid'}=$ENV{'form.crsid'};
  572:     }
  573:     if ($ENV{'form.crscode'}) {
  574:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
  575:     }
  576:     if ($ENV{'form.crssections'}) {
  577:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
  578:         my @sections = ();
  579:         if ($cenv{'internal.sectionnums'} =~ m/,/) {
  580:             @sections = split/,/,$cenv{'internal.sectionnums'};
  581:         } else {
  582:             $sections[0] = $cenv{'internal.sectionnums'};
  583:         }
  584:         if (@sections > 0) {
  585:             foreach (@sections) {
  586:                 my ($sec,$gp) = split/:/,$_; 
  587:                 push @affiliates,$ENV{'form.crscode'}.$sec;
  588:             }
  589:         }
  590:     }
  591: # do not hide course coordinator from staff listing, 
  592: # even if privileged
  593:     $cenv{'nothideprivileged'}=$ccuname.':'.$ccdomain;
  594:     if ($ENV{'form.crsxlist'}) {
  595:        $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
  596:        my @xlists = ();
  597:         if ($cenv{'internal.crosslistings'} =~ m/,/) {
  598:             @xlists = split/,/,$cenv{'internal.crosslistings'};
  599:         } else {
  600:             $xlists[0] = $cenv{'internal.crosslistings'};
  601:         }
  602:         if (@xlists > 0) {
  603:             foreach (@xlists) {
  604:                 my ($xl,$gp) = split/:/,$_;
  605:                 push @affiliates,$xl;
  606:             }
  607:         }
  608:     }
  609:     if ($ENV{'form.autoadds'}) {
  610:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
  611:     }
  612:     if ($ENV{'form.autodrops'}) {
  613:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
  614:     }
  615:     if ($ENV{'form.notify'}) {
  616:       if ($ccuname) {
  617:         $cenv{'internal.notifylist'} = $ccuname;
  618:       }
  619:     }
  620:     if ($ccuname) {
  621:         $cenv{'internal.courseowner'} = $ccuname;
  622:     } else {
  623:         $cenv{'internal.courseowner'} = $ENV{'user.name'};
  624:     }
  625:     if (@affiliates > 0) {
  626:         my @badclasses = ();
  627:         foreach my $class (@affiliates) {
  628:             my $addcheck =  &localenroll::new_course($class,$cenv{'internal.courseowner'});
  629:             unless ($addcheck eq 'ok') {
  630:                 push @badclasses, $class; 
  631:             }
  632:         }
  633:         if (@badclasses > 0) {
  634:             $r->print('<font color="red">'.
  635:                       "The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. If automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course ($cenv{'internal.courseowner'}) - does not have rights to access enrollment in these classes (as determined by your instititution's policies on access to official classlists).<br/><ul>\n");
  636:             foreach (@badclasses) {
  637:                 $r->print("<li>$_</li>\n");
  638:             }
  639:             $r->print ("</ul><br/><br/></font>\n");
  640:         }
  641:     }
  642:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
  643:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
  644:     if ($ENV{'form.no_end_date'}) {
  645:       $enddate = 0;
  646:     }
  647:     $cenv{'internal.autostart'}=$startdate;
  648:     $cenv{'internal.autoend'}=$enddate;
  649:     if ($ENV{'form.showphotos'}) {
  650:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
  651:     }
  652:     if ($ENV{'form.login'} eq 'krb') {
  653:         $cenv{'internal.authtype'} = 'krb';
  654:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
  655:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
  656:     } elsif ($ENV{'form.login'} eq 'int') {
  657:         $cenv{'internal.authtype'} ='internal';
  658:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
  659:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
  660:         }
  661:     } elsif ($ENV{'form.login'} eq 'loc') {
  662:         $cenv{'internal.authtype'} = 'localauth';
  663:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
  664:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
  665:         }
  666:     }
  667:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
  668:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
  669:             $r->print('<font color="red" size="+1">'.
  670:                       &mt('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>');
  671:         }
  672:     }
  673:     if (($ccdomain) && ($ccuname)) {
  674:        if ($ENV{'form.setpolicy'}) {
  675:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  676:        }
  677:        if ($ENV{'form.setcontent'}) {
  678:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  679:        }
  680:     }
  681:     if ($ENV{'form.reshome'}) {
  682: 	$cenv{'reshome'}=$ENV{'form.reshome'}.'/';
  683: 	$cenv{'reshome'}=~s/\/+$/\//;
  684:     }
  685: #
  686: # course has keyed access
  687: #
  688:     if ($ENV{'form.setkeys'}) {
  689:        $cenv{'keyaccess'}='yes';
  690:     }
  691: # if specified, key authority is not course, but user
  692: # only active if keyaccess is yes
  693:     if ($ENV{'form.keyauth'}) {
  694: 	$ENV{'form.keyauth'}=~s/[^\w\@]//g;
  695: 	if ($ENV{'form.keyauth'}) {
  696: 	    $cenv{'keyauth'}=$ENV{'form.keyauth'};
  697: 	}
  698:     }
  699: 
  700:     if ($ENV{'form.disresdis'}) {
  701:         $cenv{'pch.roles.denied'}='st';
  702:     }
  703:     if ($ENV{'form.disablechat'}) {
  704:         $cenv{'plc.roles.denied'}='st';
  705:     }
  706: 
  707:     # Record we've not yet viewed the Course Initialization Helper for this 
  708:     # course
  709:     $cenv{'course.helper.not.run'} = 1;
  710:     #
  711:     # Use new Randomseed
  712:     #
  713:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  714:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
  715:     #
  716:     # The encryption code and receipt prefix for this course
  717:     #
  718:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
  719:     $cenv{'internal.encpref'}=100+int(9*rand(99));
  720:     #
  721:     # By default, use standard grading
  722:     $cenv{'grading'} = 'standard';
  723: 
  724:     $r->print('<br />'.&mt('Setting environment').': '.                 
  725:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  726: #
  727: # Open all assignments
  728: #
  729:     if ($ENV{'form.openall'}) {
  730:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  731:        my %storecontent = ($storeunder         => time,
  732:                            $storeunder.'.type' => 'date_start');
  733:        
  734:        $r->print(&mt('Opening all assignments').': '.&Apache::lonnet::cput
  735:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  736:    }
  737: #
  738: # Set first page
  739: #
  740:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')
  741: 	    || ($cloneid)) {
  742: 	$r->print(&mt('Setting first resource').': ');
  743:         my ($errtext,$fatal)=
  744:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  745:         $r->print(($fatal?$errtext:'read ok').' - ');
  746:         my $title; my $url;
  747:         if ($ENV{'form.firstres'} eq 'syl') {
  748: 	    $title='Syllabus';
  749:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  750:         } else {
  751:             $title='Navigate Contents';
  752:             $url='/adm/navmaps';
  753:         }
  754:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  755:         ($errtext,$fatal)=
  756:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  757:         $r->print(($fatal?$errtext:'write ok').'<br>');
  758:   }
  759: #
  760: # Make current user course adminstrator
  761: #
  762:     my $end=undef;
  763:     my $addition='';
  764:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  765:     $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.
  766:     &Apache::lonnet::assignrole(
  767:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  768: #
  769: # Make additional user course administrator
  770: #
  771:    if (($ccdomain) && ($ccuname)) {
  772:     $r->print(&mt('Assigning role of course coordinator to').' '.
  773:                $ccuname.' at '.$ccdomain.': '.
  774:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  775:    }
  776:     if ($ENV{'form.setkeys'}) {
  777: 	$r->print(
  778:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
  779:     }
  780: # Flush the course logs so reverse user roles immediately updated
  781:     &Apache::lonnet::flushcourselogs();
  782:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
  783: }
  784: 
  785: # ===================================================================== Handler
  786: sub handler {
  787:     my $r = shift;
  788: 
  789:     if ($r->header_only) {
  790:        &Apache::loncommon::content_type($r,'text/html');
  791:        $r->send_http_header;
  792:        return OK;
  793:     }
  794: 
  795:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  796:        &Apache::loncommon::content_type($r,'text/html');
  797:        $r->send_http_header;
  798: 
  799:        if ($ENV{'form.phase'} eq 'two') {
  800:            &create_course($r);
  801:        } else {
  802: 	   &print_course_creation_page($r);
  803:        }
  804:    } else {
  805:       $ENV{'user.error.msg'}=
  806:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  807:       return HTTP_NOT_ACCEPTABLE; 
  808:    }
  809:    return OK;
  810: } 
  811: 
  812: 1;
  813: __END__

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