File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.85: download - view: text, annotated - select for diffs
Mon Jan 16 23:11:50 2006 UTC (18 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, HEAD
- dates didn't shift when cloned if there wasn't a global iopendate set.
  - delete dates if no global start time is found
  - try the 'default_nerollemtn_start_time' as a possbile global start

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.85 2006/01/16 23:11:50 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: ###
   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: 
   42: # ================================================ Get course directory listing
   43: 
   44: my @output=();
   45: 
   46: sub crsdirlist {
   47:     my ($courseid,$which)=@_;
   48:     @output=();
   49:     return &innercrsdirlist($courseid,$which);
   50: }
   51: 
   52: sub innercrsdirlist {
   53:     my ($courseid,$which,$path)=@_;
   54:     my $dirptr=16384;
   55:     unless ($which) { $which=''; } else { $which.='/'; }
   56:     unless ($path)  { $path=''; } else { $path.='/'; }
   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:     foreach (@listing) {
   62: 	unless ($_=~/^\./) {
   63: 	    my @unpackline = split (/\&/,$_);
   64: 	    if ($unpackline[3]&$dirptr) {
   65: # is a directory, recurse
   66: 		&innercrsdirlist($courseid,$which.$unpackline[0],
   67: 				            $path.$unpackline[0]);
   68: 	    } else { 
   69: # is a file, put into output
   70: 		push (@output,$path.$unpackline[0]);
   71: 	    }
   72: 	}
   73:     }
   74:     return @output;
   75: }
   76: 
   77: # ============================================================= Read a userfile
   78: 
   79: sub readfile {
   80:     my ($courseid,$which)=@_;
   81:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   82:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
   83: 				    $crsdata{'num'}.'/'.$which);
   84: }
   85: 
   86: # ============================================================ Write a userfile
   87: 
   88: sub writefile {
   89:     (my $courseid, my $which,$env{'form.output'})=@_;
   90:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   91:     return &Apache::lonnet::finishuserfileupload(
   92: 					  $crsdata{'num'},$crsdata{'domain'},
   93: 					  'output',$which);
   94: }
   95: 
   96: # ===================================================================== Rewrite
   97: 
   98: sub rewritefile {
   99:     my ($contents,%rewritehash)=@_;
  100:     foreach (keys %rewritehash) {
  101: 	my $pattern=$_;
  102: 	$pattern=~s/(\W)/\\$1/gs;
  103: 	my $new=$rewritehash{$_};
  104: 	$contents=~s/$pattern/$new/gs;
  105:     }
  106:     return $contents;
  107: }
  108: 
  109: # ============================================================= Copy a userfile
  110: 
  111: sub copyfile {
  112:     my ($origcrsid,$newcrsid,$which)=@_;
  113:     unless ($which=~/\.sequence$/) {
  114: 	return &writefile($newcrsid,$which,
  115: 		      &readfile($origcrsid,$which));
  116:     } else {
  117: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  118: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  119: 	return &writefile($newcrsid,$which,
  120: 		 &rewritefile(
  121:                      &readfile($origcrsid,$which),
  122: 	    (
  123:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  124:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/',
  125:        '/public/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  126:     => '/public/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
  127:             )));
  128:     }
  129: }
  130: 
  131: # =============================================================== Copy a dbfile
  132: 
  133: sub copydb {
  134:     my ($origcrsid,$newcrsid,$which)=@_;
  135:     $which=~s/\.db$//;
  136:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  137:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  138:     my %data=&Apache::lonnet::dump
  139: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
  140:     foreach my $key (keys(%data)) {
  141: 	if ($key=~/^internal./) { delete($data{$key}); }
  142:     }
  143:     return &Apache::lonnet::put
  144: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
  145: }
  146: 
  147: # ========================================================== Copy resourcesdata
  148: 
  149: sub copyresourcedb {
  150:     my ($origcrsid,$newcrsid)=@_;
  151:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  152:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  153:     my %data=&Apache::lonnet::dump
  154: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
  155:     $origcrsid=~s/^\///;
  156:     $origcrsid=~s/\//\_/;
  157:     $newcrsid=~s/^\///;
  158:     $newcrsid=~s/\//\_/;
  159:     my %newdata=();
  160:     undef %newdata;
  161:     my $startdate=$data{$origcrsid.'.0.opendate'};
  162:     if (!$startdate) {
  163: 	# now global start date for assements try the enrollment start
  164: 	my %start=&Apache::lonnet::get('environment',
  165: 				   ['default_enrollment_start_date'],
  166: 				   $origcrsdata{'domain'},$origcrsdata{'num'});
  167: 
  168: 	$startdate = $start{'default_enrollment_start_date'};
  169:     }
  170:     my $today=time;
  171:     my $delta=0;
  172:     if ($startdate) {
  173: 	my $oneday=60*60*24;
  174: 	$delta=$today-$startdate;
  175: 	$delta=int($delta/$oneday)*$oneday;
  176:     }
  177: # ugly retro fix for broken version of types
  178:     foreach (keys %data) {
  179: 	if ($_=~/\wtype$/) {
  180: 	    my $newkey=$_;
  181: 	    $newkey=~s/type$/\.type/;
  182: 	    $data{$newkey}=$data{$_};
  183: 	    delete $data{$_};
  184: 	}
  185:     }
  186: # adjust symbs
  187:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
  188:     $pattern=~s/(\W)/\\$1/gs;
  189:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
  190:     foreach (keys %data) {
  191: 	if ($_=~/$pattern/) {
  192: 	    my $newkey=$_;
  193: 	    $newkey=~s/$pattern/$new/;
  194: 	    $data{$newkey}=$data{$_};
  195: 	    delete $data{$_};
  196: 	}
  197:     }
  198: # adjust dates
  199:     foreach (keys %data) {
  200: 	my $thiskey=$_;
  201: 	$thiskey=~s/^$origcrsid/$newcrsid/;
  202: 	$newdata{$thiskey}=$data{$_};
  203: 	if ($data{$_.'.type'}=~/^date_(start|end)$/) {
  204: 	    if ($delta > 0) {
  205: 		$newdata{$thiskey}=$newdata{$thiskey}+$delta;
  206: 	    } else {
  207: 		# no delta, it's unlikely we want the old dates and times
  208: 		delete($newdata{$thiskey});
  209: 		delete($newdata{$thiskey.'.type'});
  210: 	    }
  211: 	}
  212:     }
  213:     return &Apache::lonnet::put
  214: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
  215: }
  216: 
  217: # ========================================================== Copy all userfiles
  218: 
  219: sub copyuserfiles {
  220:     my ($origcrsid,$newcrsid)=@_;
  221:     foreach (&crsdirlist($origcrsid,'userfiles')) {
  222: 	if ($_ !~m|^scantron_|) {
  223: 	    &copyfile($origcrsid,$newcrsid,$_);
  224: 	}
  225:     }
  226: }
  227: # ========================================================== Copy all userfiles
  228: 
  229: sub copydbfiles {
  230:     my ($origcrsid,$newcrsid)=@_;
  231: 
  232:     my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|);
  233:     $origcrs_discussion=~s|/|_|g;
  234:     foreach (&crsdirlist($origcrsid)) {
  235: 	if ($_=~/\.db$/) {
  236: 	    unless 
  237:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|(grading|review)queue|CODEs)/) {
  238: 		 &copydb($origcrsid,$newcrsid,$_);
  239: 		 my $histfile=$_;
  240: 		 $histfile=~s/\.db$/\.hist/;
  241: 		 &copyfile($origcrsid,$newcrsid,$histfile);
  242: 	     }
  243: 	}
  244:     }
  245: }
  246: 
  247: # ======================================================= Copy all course files
  248: 
  249: sub copycoursefiles {
  250:     my ($origcrsid,$newcrsid)=@_;
  251:     &copyuserfiles($origcrsid,$newcrsid);
  252:     &copydbfiles($origcrsid,$newcrsid);
  253:     &copyresourcedb($origcrsid,$newcrsid);
  254: }
  255: 
  256: # ===================================================== Phase one: fill-in form
  257: 
  258: sub print_course_creation_page {
  259:     my $r=shift;
  260:     my $defdom=$env{'request.role.domain'};
  261:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
  262:     my $course_home = '<select name="course_home" size="1">'."\n";
  263:     foreach my $server (sort(keys(%host_servers))) {
  264:         $course_home .= qq{<option value="$server"};
  265:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
  266:             $course_home .= " selected ";
  267:         }
  268:         $course_home .= qq{>$server $host_servers{$server}</option>};
  269:     }
  270:     $course_home .= "\n</select>\n";
  271:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  272:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  273:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
  274:     my $cloneform=&Apache::loncommon::select_dom_form
  275: 	($env{'request.role.domain'},'clonedomain').
  276: 		     &Apache::loncommon::selectcourse_link
  277: 		     ('ccrs','clonecourse','clonedomain');
  278:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
  279:     my $starttime = time;
  280:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  281:     my $enroll_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_enrolldates');
  282:     my $access_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_defaultdates');
  283:     my ($krbdef,$krbdefdom) =
  284:     &Apache::loncommon::get_kerberos_defaults($defdom);
  285:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
  286:     my %param = ( formname => 'document.ccrs',
  287:                    kerb_def_dom => $krbdefdom,
  288:                    kerb_def_auth => $krbdef
  289:                 );
  290:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
  291:     my $intform = &Apache::loncommon::authform_internal(%param);
  292:     my $locform = &Apache::loncommon::authform_local(%param);
  293:     my %lt=&Apache::lonlocal::texthash(
  294: 		    'cinf' => "Course Information",
  295:                     'ctit' => "Course Title",
  296:                     'chsr' => "Course Home Server",
  297:                     'cidn' => "Course ID/Number",
  298:                     'opt'  => "optional",
  299:                     'iinf' => "Institutional Information",
  300:                     '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.",
  301:                     'ccod' => "Course Code",
  302:                     'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
  303:                     'snid' => "Section Numbers and corresponding LON-CAPA section/group IDs",
  304:                     '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",
  305:                     'crcs' => "Crosslisted courses",
  306:                     '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:zol2",
  307:                     'crco' => "Course Content",
  308:                     'cncr' => "Completely new course",
  309:                     'cecr' => "Clone an existing course", 
  310:                     'map'  => "Map",
  311:                     'smap' => "Select Map",
  312:                     'sacr' => "Do NOT generate as standard course",
  313:                     'ocik' => "only check if you know what you are doing",
  314:                     'fres' => "First Resource",
  315:                     'stco' => "standard courses only",
  316:                     'blnk' => "Blank",
  317:                     'sllb' => "Syllabus",
  318:                     'navi' => "Navigate",
  319:                     'cid'  => "Course ID",
  320:                     'dmn'  => "Domain",
  321:                     'asov' => "Additional settings, if specified below, will override cloned settings",
  322:                     'assp' => "Assessment Parameters",
  323:                     'oaas' => "Open all assessments",
  324:                     'mssg' => "Messaging",
  325:                     'scpf' => "Set course policy feedback to Course Coordinator",
  326:                     'scfc' => "Set content feedback to Course Coordinator",
  327:                     'cmmn' => "Communication",
  328:                     'dsrd' => "Disable student resource discussion",
  329:                     'dsuc' => "Disable student use of chatrooms",
  330:                     'acco' => "Access Control",
  331:                     'snak' => "Students need access key to enter course",
  332: 		    'kaut' => 
  333: 		    'Key authority (<tt>id@domain</tt>) if other than course',
  334:                     'cc'   => "Course Coordinator",
  335:                     'user' => "Username",
  336:                     'ierc' => "Immediately expire own role as Course Coordinator",
  337:                     'aens' => "Automated enrollment settings",
  338:                     '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.",
  339:                     'aadd' => "Automated adds",
  340:                     'yes'  => "Yes",
  341:                     'no'   => "No",
  342:                     'audr' => "Automated drops",
  343:                     'dacu' => "Duration of automated classlist updates",
  344:                     'dacc' => "Default start and end dates for student access",
  345:                     'psam' => "Please select the authentication mechanism",
  346:                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
  347:                     'nech' => "Notification of enrollment changes",
  348:                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  349:                     'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  350:                     'irsp' => "Include retrieval of student photographs?",
  351: 		    'rshm' => 'Resource Space Home',
  352:                     'opco' => "Open Course"
  353: 				       );
  354:     my $html=&Apache::lonxml::xmlbegin();
  355:     $r->print(<<ENDDOCUMENT);
  356: $html
  357: <head>
  358: <script language="JavaScript" type="text/javascript">
  359: var editbrowser = null;
  360: function openbrowser(formname,elementname) {
  361:     var url = '/res/?';
  362:     if (editbrowser == null) {
  363:         url += 'launch=1&';
  364:     }
  365:     url += 'catalogmode=interactive&';
  366:     url += 'mode=edit&';
  367:     url += 'form=' + formname + '&';
  368:     url += 'element=' + elementname + '&';
  369:     url += 'only=sequence' + '';
  370:     var title = 'Browser';
  371:     var options = 'scrollbars=1,resizable=1,menubar=0';
  372:     options += ',width=700,height=600';
  373:     editbrowser = open(url,title,options,'1');
  374:     editbrowser.focus();
  375: }
  376: $javascript_validations
  377: </script>
  378: $coursebrowserjs
  379: <title>The LearningOnline Network with CAPA</title>
  380: </head>
  381: $bodytag
  382: $helplink
  383: <form action="/adm/createcourse" method="post" name="ccrs">
  384: <h2>$lt{'cinf'}</h2>
  385: <p>
  386: <label><b>$lt{'ctit'}:</b>
  387: <input type="text" size="50" name="title" /></label>
  388: </p><p>
  389: <label>
  390:     <b>$lt{'chsr'}:</b>$course_home
  391: </label>
  392: </p><p>
  393: <label>
  394:     <b>$lt{'cidn'} ($lt{'opt'})</b>
  395:     <input type="text" size="30" name="crsid" />
  396: </label>
  397: </p><p>
  398: <h2>$lt{'iinf'}</h2>
  399: <p>
  400: $lt{'stat'}
  401: </p><p>
  402: <label>
  403:     <b>$lt{'ccod'}</b>
  404:     <input type="text" size="30" name="crscode" />
  405: </label>
  406: <br/>
  407: ($lt{'toin'})
  408: </p><p>
  409: <label>
  410:     <b>$lt{'snid'}</b>
  411:     <input type="text" size="30" name="crssections" />
  412: </label>
  413: <br/>
  414: ($lt{'csli'})
  415: </p><p>
  416: <label>
  417:     <b>$lt{'crcs'}</b>
  418:     <input type="text" size="30" name="crsxlist" />
  419: </label>
  420: <br/>
  421: ($lt{'cscs'})
  422: </p>
  423: <h2>$lt{'crco'}</h2>
  424: <table border="2">
  425: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
  426: <tr><td>
  427: <p>
  428: <label>
  429:     <b>$lt{'map'}:</b>
  430:     <input type="text" size="50" name="topmap" />
  431: </label>
  432: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  433: </p><p>
  434: <label for="nonstd"><b>$lt{'sacr'}</b></label>
  435: <br />
  436: ($lt{'ocik'}):
  437: <input id="nonstd" type="checkbox" name="nonstandard" />
  438: </p><p>
  439: <b>$lt{'fres'}</b><br />($lt{'stco'}):
  440: <label>
  441:     <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
  442: </label>
  443: &nbsp;
  444: <label>
  445:     <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
  446: </label>
  447: &nbsp;
  448: <label>
  449:     <input type="radio" name="firstres" value="nav" />$lt{'navi'}
  450: </label>
  451: </p>
  452: </td><td>
  453: <label>
  454:     $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
  455: </label>
  456: <br />
  457: <label>
  458:     $lt{'dmn'}: $cloneform
  459: </label>
  460: <br />
  461: &nbsp;<br />
  462: $lt{'asov'}.
  463: </td></tr>
  464: </table>
  465: <h2>$lt{'assp'}</h2>
  466: <p>
  467: <label>
  468:     <b>$lt{'oaas'}: </b>
  469:     <input type="checkbox" name="openall" />
  470: </label>
  471: </p>
  472: <h2>$lt{'mssg'}</h2>
  473: <p>
  474: <label>
  475:     <b>$lt{'scpf'}: </b>
  476:     <input type="checkbox" name="setpolicy" checked />
  477: </label>
  478: <br />
  479: <label>
  480:     <b>$lt{'scfc'}: </b>
  481:     <input type="checkbox" name="setcontent" checked />
  482: </label>
  483: </p>
  484: <h2>$lt{'cmmn'}</h2>
  485: <p>
  486: <label>
  487:     <b>$lt{'dsrd'}: </b>
  488:     <input type="checkbox" name="disresdis" />
  489: </label>
  490: <br />
  491: <label>
  492:     <b>$lt{'dsuc'}: </b>
  493:     <input type="checkbox" name="disablechat" />
  494: </label>
  495: </p>
  496: <h2>$lt{'acco'}</h2>
  497: <p>
  498: <label>
  499:     <b>$lt{'snak'}: </b>
  500:     <input type="checkbox" name="setkeys" />
  501: </label>
  502: <br />
  503: <label>
  504:     <b>$lt{'kaut'}: </b>
  505:     <input type="text" size="30" name="keyauth" />
  506: </label>
  507: </p>
  508: <h2>$lt{'rshm'}</h2>
  509: <p>
  510: <label>
  511:     <b>$lt{'rshm'}: </b>
  512:     <input type="text" name="reshome" size="30" value="/res/$defdom/" />
  513: </label>
  514: </p>
  515: <p>
  516: <h2>$lt{'aens'}</h2>
  517: $lt{'aesc'}
  518: </p>
  519: <p>
  520: <b>$lt{'aadd'}</b>
  521: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label> 
  522: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
  523: </label>
  524: </p><p>
  525: <b>$lt{'audr'}</b>
  526: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label> 
  527: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
  528: </p><p>
  529: <b>$lt{'dacu'}</b>
  530: $enroll_table
  531: </p><p>
  532: <b>$lt{'dacc'}</b>
  533: $access_table
  534: <p></p>
  535: <b>$lt{'psam'}.</b><br />
  536: $lt{'pcda'}.
  537: </p><p>
  538: $krbform
  539: <br />
  540: $intform
  541: <br />
  542: $locform
  543: </p><p>
  544: <b>$lt{'nech'}</b><br />
  545: $lt{'nccl'}<br/>
  546: <label>
  547:     <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
  548: </label> 
  549: <label>
  550:     <input type="radio" name="notify_owner" value="0" checked="true" />$lt{'no'}
  551: </label>
  552: <br />
  553: $lt{'ndcl'}<br/>
  554: <label>
  555:     <input type="radio" name="notify_dc" value="1" />$lt{'yes'}
  556: </label>
  557: <label>
  558:     <input type="radio" name="notify_dc" value="0" checked="true" />$lt{'no'}
  559: </label>
  560: </p><p>
  561: <b>$lt{'irsp'}</b>
  562: <label>
  563:     <input type="radio" name="showphotos" value="1" />$lt{'yes'}
  564: </label> 
  565: <label>
  566:     <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
  567: </label>
  568: </p>
  569: <hr />
  570: <h2>$lt{'cc'}</h2>
  571: <p>
  572: <label>
  573:     <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
  574: </label>
  575: </p><p>
  576: <label>
  577:     <b>$lt{'dmn'}:</b> $domform
  578: </label>
  579: </p>
  580: <p>
  581: <input type="hidden" name="phase" value="two" />
  582: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
  583: </p>
  584: </form>
  585: </body>
  586: </html>
  587: ENDDOCUMENT
  588: }
  589: 
  590: # ====================================================== Phase two: make course
  591: 
  592: sub create_course {
  593:     my $r=shift;
  594:     my $ccuname=$env{'form.ccuname'};
  595:     my $ccdomain=$env{'form.ccdomain'};
  596:     $ccuname=~s/\W//g;
  597:     $ccdomain=~s/\W//g;
  598: 
  599:     my $enrollstart = &Apache::lonhtmlcommon::get_date_from_form('startenroll');
  600:     my $enrollend   = &Apache::lonhtmlcommon::get_date_from_form('endenroll');
  601:     my $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
  602:     my $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
  603: 
  604:     my $autharg;
  605:     my $authtype;
  606: 
  607:     if ($env{'form.login'} eq 'krb') {
  608:         $authtype = 'krb';
  609:         $authtype .=$env{'form.krbver'};
  610:         $autharg = $env{'form.krbarg'};
  611:     } elsif ($env{'form.login'} eq 'int') {
  612:         $authtype ='internal';
  613:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
  614:             $autharg = $env{'form.intarg'};
  615:         }
  616:     } elsif ($env{'form.login'} eq 'loc') {
  617:         $authtype = 'localauth';
  618:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
  619:             $autharg = $env{'form.locarg'};
  620:         }
  621:     }
  622: 
  623:     my $logmsg;
  624:     my $html=&Apache::lonxml::xmlbegin();
  625:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  626:     $r->print(<<ENDENHEAD);
  627: $html
  628: <head>
  629: <title>The LearningOnline Network with CAPA</title>
  630: </head>
  631: $bodytag
  632: ENDENHEAD
  633: 
  634:     my $args = {
  635:                ccuname => $ccuname,
  636:                ccdomain => $ccdomain,
  637:                cdescr => $env{'form.title'},
  638:                curl => $env{'form.topmap'},
  639:                course_domain => $env{'request.role.domain'},
  640:                course_home =>  $env{'form.course_home'},
  641:                nonstandard => $env{'form.nonstandard'},
  642:                crscode => $env{'form.crscode'},
  643:                clonecourse => $env{'form.clonecourse'},
  644:                clonedomain => $env{'form.clonedomain'},
  645:                crsid => $env{'form.crsid'},
  646:                curruser => $env{'user.name'},
  647:                crssections => $env{'form.crssections'},
  648:                crsxlist => $env{'form.crsxlist'},
  649:                autoadds => $env{'form.autoadds'},
  650:                autodrops => $env{'form.autodrops'},
  651:                notify_owner => $env{'form.notify_owner'},
  652:                notify_dc => $env{'form.notify_dc'},
  653:                no_end_date => $env{'form.no_end_date'},
  654:                showphotos => $env{'form.showphotos'},
  655:                authtype => $authtype,
  656:                autharg => $autharg,
  657:                enrollstart => $enrollstart,
  658:                enrollend => $enrollend,
  659:                startaccess => $startaccess,
  660:                endaccess => $endaccess,
  661:                setpolicy => $env{'form.setpolicy'},
  662:                setcontent => $env{'form.setcontent'},
  663:                reshome => $env{'form.reshome'},
  664:                setkeys => $env{'form.setkeys'},
  665:                keyauth => $env{'form.keyauth'},
  666:                disresdis => $env{'form.disresdis'},
  667:                disablechat => $env{'form.disablechat'},
  668:                openall => $env{'form.openall'},
  669:                firstres => $env{'form.firstres'}
  670:                };
  671: 
  672:     #
  673:     # Verify data
  674:     #
  675:     # Check the veracity of the course coordinator
  676:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  677: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
  678:         $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
  679: 	$r->print(&mt("Please click Back on your browser and select another user, or "));
  680: 	$r->print('
  681: 	    <input type="hidden" name="phase" value="get_user_info" />
  682:             <input type="hidden" name="ccuname" value="'.$ccuname.'" />
  683:             <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
  684:             <input name="userrole" type="submit" value="'.
  685: 		  &mt('Create User').'" />
  686: 	</form></body></html>');
  687: 	return;
  688:     }
  689:     # Check the proposed home server for the course
  690:     my %host_servers = &Apache::loncommon::get_library_servers
  691:         ($env{'request.role.domain'});
  692:     if (! exists($host_servers{$env{'form.course_home'}})) {
  693:         $r->print(&mt('Invalid home server for course').': '.
  694:                   $env{'form.course_home'}.'</body></html>');
  695:         return;
  696:     }
  697:     my ($courseid,$crsudom,$crsunum);
  698:     $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
  699: 
  700: #
  701: # Make the requested user a course coordinator
  702: #
  703:    if (($ccdomain) && ($ccuname)) {
  704:     $r->print(&mt('Assigning role of course coordinator to').' '.
  705:                $ccuname.' at '.$ccdomain.': '.
  706:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  707:    }
  708:     if ($env{'form.setkeys'}) {
  709:         $r->print(
  710:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
  711:     }
  712: # Flush the course logs so reverse user roles immediately updated
  713:     &Apache::lonnet::flushcourselogs();
  714:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
  715: }
  716: 
  717: sub construct_course {
  718:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
  719:     my $outcome;
  720: 
  721: #
  722: # Open course
  723: #
  724:     my %cenv=();
  725:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
  726:                                                $args->{'cdescr'},
  727:                                                $args->{'curl'},
  728:                                                $args->{'course_home'},
  729:                                                $args->{'nonstandard'},
  730:                                                $args->{'crscode'},
  731:                                                $args->{'ccuname'});
  732: 
  733:     # Note: The testing routines depend on this being output; see 
  734:     # Utils::Course. This needs to at least be output as a comment
  735:     # if anyone ever decides to not show this, and Utils::Course::new
  736:     # will need to be suitably modified.
  737:     $outcome .= 'New LON-CAPA Course ID: '.$$courseid.'<br>';
  738: #
  739: # Check if created correctly
  740: #
  741:     ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);
  742:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
  743:     $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
  744: #
  745: # Are we cloning?
  746: #
  747:     my $cloneid='';
  748:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
  749: 	$cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
  750:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
  751: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  752: 	if ($clonehome eq 'no_host') {
  753: 	    $outcome .=
  754:     '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>';
  755: 	} else {
  756: 	    $outcome .= 
  757:     '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>';
  758: 	    my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
  759: # Copy all files
  760: 	    &copycoursefiles($cloneid,$$courseid);
  761: # Restore URL
  762: 	    $cenv{'url'}=$oldcenv{'url'};
  763: # Restore title
  764: 	    $cenv{'description'}=$oldcenv{'description'};
  765: # restore grading mode
  766: 	    if (defined($oldcenv{'grading'})) {
  767: 		$cenv{'grading'}=$oldcenv{'grading'};
  768: 	    }
  769: # Mark as cloned
  770: 	    $cenv{'clonedfrom'}=$cloneid;
  771: 	    delete($cenv{'default_enrollment_start_date'});
  772: 	    delete($cenv{'default_enrollment_end_date'});
  773: 	}
  774:     }
  775: #
  776: # Set environment (will override cloned, if existing)
  777: #
  778:     my @sections = ();
  779:     my @xlists = ();
  780:     if ($args->{'crsid'}) {
  781:         $cenv{'courseid'}=$args->{'crsid'};
  782:     }
  783:     if ($args->{'crscode'}) {
  784:         $cenv{'internal.coursecode'}=$args->{'crscode'};
  785:     }
  786:     if ($args->{'ccuname'}) {
  787:         $cenv{'internal.courseowner'} = $args->{'ccuname'};
  788:     } else {
  789:         $cenv{'internal.courseowner'} = $args->{'curruser'};
  790:     }
  791: 
  792:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
  793:     if ($args->{'crssections'}) {
  794:         $cenv{'internal.sectionnums'} = '';
  795:         if ($args->{'crssections'} =~ m/,/) {
  796:             @sections = split/,/,$args->{'crssections'};
  797:         } else {
  798:             $sections[0] = $args->{'crssections'};
  799:         }
  800:         if (@sections > 0) {
  801:             foreach my $item (@sections) {
  802:                 my ($sec,$gp) = split/:/,$item;
  803:                 my $class = $args->{'crscode'}.$sec;
  804:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
  805:                 $cenv{'internal.sectionnums'} .= $item.',';
  806:                 unless ($addcheck eq 'ok') {
  807:                     push @badclasses, $class;
  808:                 }
  809:             }
  810:             $cenv{'internal.sectionnums'} =~ s/,$//;
  811:         }
  812:     }
  813: # do not hide course coordinator from staff listing, 
  814: # even if privileged
  815:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
  816: # add crosslistings
  817:     if ($args->{'crsxlist'}) {
  818:         $cenv{'internal.crosslistings'}='';
  819:         if ($args->{'crsxlist'} =~ m/,/) {
  820:             @xlists = split/,/,$args->{'crsxlist'};
  821:         } else {
  822:             $xlists[0] = $args->{'crsxlist'};
  823:         }
  824:         if (@xlists > 0) {
  825:             foreach my $item (@xlists) {
  826:                 my ($xl,$gp) = split/:/,$item;
  827:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
  828:                 $cenv{'internal.crosslistings'} .= $item.',';
  829:                 unless ($addcheck eq 'ok') {
  830:                     push @badclasses, $xl;
  831:                 }
  832:             }
  833:             $cenv{'internal.crosslistings'} =~ s/,$//;
  834:         }
  835:     }
  836:     if ($args->{'autoadds'}) {
  837:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
  838:     }
  839:     if ($args->{'autodrops'}) {
  840:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
  841:     }
  842: # check for notification of enrollment changes
  843:     my @notified = ();
  844:     if ($args->{'notify_owner'}) {
  845:         if ($args->{'ccuname'} ne '') {
  846:             push(@notified,$args->{'ccuname'}.'@'.$args->{'ccdomain'});
  847:         }
  848:     }
  849:     if ($args->{'notify_dc'}) {
  850:         if ($uname ne '') { 
  851:             push(@notified,$uname.'@'.$udom);
  852:         }
  853:     }
  854:     if (@notified > 0) {
  855:         my $notifylist;
  856:         if (@notified > 1) {
  857:             $notifylist = join(',',@notified);
  858:         } else {
  859:             $notifylist = $notified[0];
  860:         }
  861:         $cenv{'internal.notifylist'} = $notifylist;
  862:     }
  863:     if (@badclasses > 0) {
  864:         my %lt=&Apache::lonlocal::texthash(
  865:                 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.  However, 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',
  866:                 'dnhr' => 'does not have rights to access enrollment in these classes',
  867:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
  868:         );
  869:         $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
  870:         foreach (@badclasses) {
  871:             $outcome .= "<li>$_</li>\n";
  872:         }
  873:         $outcome .= "</ul><br /><br /></font>\n";
  874:     }
  875:     if ($args->{'no_end_date'}) {
  876:         $args->{'endaccess'} = 0;
  877:     }
  878:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
  879:     $cenv{'internal.autoend'}=$args->{'enrollend'};
  880:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
  881:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
  882:     if ($args->{'showphotos'}) {
  883:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
  884:     }
  885:     $cenv{'internal.authtype'} = $args->{'authtype'};
  886:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
  887:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
  888:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
  889:             $outcome .= '<font color="red" size="+1">'.
  890:                       &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>';
  891:         }
  892:     }
  893:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
  894:        if ($args->{'setpolicy'}) {
  895:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
  896:        }
  897:        if ($args->{'setcontent'}) {
  898:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
  899:        }
  900:     }
  901:     if ($args->{'reshome'}) {
  902: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
  903: 	$cenv{'reshome'}=~s/\/+$/\//;
  904:     }
  905: #
  906: # course has keyed access
  907: #
  908:     if ($args->{'setkeys'}) {
  909:        $cenv{'keyaccess'}='yes';
  910:     }
  911: # if specified, key authority is not course, but user
  912: # only active if keyaccess is yes
  913:     if ($args->{'keyauth'}) {
  914: 	$args->{'keyauth'}=~s/[^\w\@]//g;
  915: 	if ($args->{'keyauth'}) {
  916: 	    $cenv{'keyauth'}=$args->{'keyauth'};
  917: 	}
  918:     }
  919: 
  920:     if ($args->{'disresdis'}) {
  921:         $cenv{'pch.roles.denied'}='st';
  922:     }
  923:     if ($args->{'disablechat'}) {
  924:         $cenv{'plc.roles.denied'}='st';
  925:     }
  926: 
  927:     # Record we've not yet viewed the Course Initialization Helper for this 
  928:     # course
  929:     $cenv{'course.helper.not.run'} = 1;
  930:     #
  931:     # Use new Randomseed
  932:     #
  933:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  934:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
  935:     #
  936:     # The encryption code and receipt prefix for this course
  937:     #
  938:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
  939:     $cenv{'internal.encpref'}=100+int(9*rand(99));
  940:     #
  941:     # By default, use standard grading
  942:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
  943: 
  944:     $outcome .= ('<br />'.&mt('Setting environment').': '.                 
  945:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
  946: #
  947: # Open all assignments
  948: #
  949:     if ($args->{'openall'}) {
  950:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
  951:        my %storecontent = ($storeunder         => time,
  952:                            $storeunder.'.type' => 'date_start');
  953:        
  954:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
  955:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
  956:    }
  957: #
  958: # Set first page
  959: #
  960:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
  961: 	    || ($cloneid)) {
  962: 	$outcome .= &mt('Setting first resource').': ';
  963:         my ($errtext,$fatal)=
  964:            &Apache::londocs::mapread($$crsunum,$$crsudom,'default.sequence');
  965:         $outcome .= ($fatal?$errtext:'read ok').' - ';
  966:         my $title; my $url;
  967:         if ($args->{'firstres'} eq 'syl') {
  968: 	    $title='Syllabus';
  969:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
  970:         } else {
  971:             $title='Navigate Contents';
  972:             $url='/adm/navmaps';
  973:         }
  974:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  975:         ($errtext,$fatal)=
  976:            &Apache::londocs::storemap($$crsunum,$$crsudom,'default.sequence');
  977:         $outcome .= ($fatal?$errtext:'write ok').'<br>';
  978:     }
  979:     return $outcome;
  980: }
  981: 
  982: # ===================================================================== Handler
  983: sub handler {
  984:     my $r = shift;
  985: 
  986:     if ($r->header_only) {
  987:        &Apache::loncommon::content_type($r,'text/html');
  988:        $r->send_http_header;
  989:        return OK;
  990:     }
  991: 
  992:     if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
  993:        &Apache::loncommon::content_type($r,'text/html');
  994:        $r->send_http_header;
  995: 
  996:        if ($env{'form.phase'} eq 'two') {
  997:            &create_course($r);
  998:        } else {
  999: 	   &print_course_creation_page($r);
 1000:        }
 1001:    } else {
 1002:       $env{'user.error.msg'}=
 1003:         "/adm/createcourse:ccc:0:0:Cannot create courses";
 1004:       return HTTP_NOT_ACCEPTABLE; 
 1005:    }
 1006:    return OK;
 1007: } 
 1008: 
 1009: 1;
 1010: __END__

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