File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.86: download - view: text, annotated - select for diffs
Tue Mar 21 18:34:23 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- start_page

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

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