File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.93.2.4: download - view: text, annotated - select for diffs
Thu Jul 20 22:10:22 2006 UTC (17 years, 10 months ago) by albertel
Branches: version_2_2_X
CVS tags: version_2_1_99_2, version_2_1_99_1
- backport 1.195

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.93.2.4 2006/07/20 22:10:22 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 LONCAPA::batchcreatecourse;
   41: use lib '/home/httpd/lib/perl';
   42: use LONCAPA;
   43: 
   44: # ================================================ Get course directory listing
   45: 
   46: my @output=();
   47: 
   48: sub crsdirlist {
   49:     my ($courseid,$which)=@_;
   50:     @output=();
   51:     return &innercrsdirlist($courseid,$which);
   52: }
   53: 
   54: sub innercrsdirlist {
   55:     my ($courseid,$which,$path)=@_;
   56:     my $dirptr=16384;
   57:     unless ($which) { $which=''; } else { $which.='/'; }
   58:     unless ($path)  { $path=''; } else { $path.='/'; }
   59:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   60:     my @listing=&Apache::lonnet::dirlist
   61: 	($which,$crsdata{'domain'},$crsdata{'num'},
   62: 	 &propath($crsdata{'domain'},$crsdata{'num'}));
   63:     foreach (@listing) {
   64: 	unless ($_=~/^\./) {
   65: 	    my @unpackline = split (/\&/,$_);
   66: 	    if ($unpackline[3]&$dirptr) {
   67: # is a directory, recurse
   68: 		&innercrsdirlist($courseid,$which.$unpackline[0],
   69: 				            $path.$unpackline[0]);
   70: 	    } else { 
   71: # is a file, put into output
   72: 		push (@output,$path.$unpackline[0]);
   73: 	    }
   74: 	}
   75:     }
   76:     return @output;
   77: }
   78: 
   79: # ============================================================= Read a userfile
   80: 
   81: sub readfile {
   82:     my ($courseid,$which)=@_;
   83:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   84:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
   85: 				    $crsdata{'num'}.'/'.$which);
   86: }
   87: 
   88: # ============================================================ Write a userfile
   89: 
   90: sub writefile {
   91:     (my $courseid, my $which,$env{'form.output'})=@_;
   92:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   93:     return &Apache::lonnet::finishuserfileupload(
   94: 					  $crsdata{'num'},$crsdata{'domain'},
   95: 					  'output',$which);
   96: }
   97: 
   98: # ===================================================================== Rewrite
   99: 
  100: sub rewritefile {
  101:     my ($contents,%rewritehash)=@_;
  102:     foreach (keys %rewritehash) {
  103: 	my $pattern=$_;
  104: 	$pattern=~s/(\W)/\\$1/gs;
  105: 	my $new=$rewritehash{$_};
  106: 	$contents=~s/$pattern/$new/gs;
  107:     }
  108:     return $contents;
  109: }
  110: 
  111: # ============================================================= Copy a userfile
  112: 
  113: sub copyfile {
  114:     my ($origcrsid,$newcrsid,$which)=@_;
  115:     unless ($which=~/\.sequence$/) {
  116: 	return &writefile($newcrsid,$which,
  117: 		      &readfile($origcrsid,$which));
  118:     } else {
  119: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  120: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  121: 	return &writefile($newcrsid,$which,
  122: 		 &rewritefile(
  123:                      &readfile($origcrsid,$which),
  124: 	    (
  125:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  126:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/',
  127:        '/public/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
  128:     => '/public/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
  129:             )));
  130:     }
  131: }
  132: 
  133: # =============================================================== Copy a dbfile
  134: 
  135: sub copydb {
  136:     my ($origcrsid,$newcrsid,$which)=@_;
  137:     $which=~s/\.db$//;
  138:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  139:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  140:     my %data=&Apache::lonnet::dump
  141: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
  142:     foreach my $key (keys(%data)) {
  143: 	if ($key=~/^internal./) { delete($data{$key}); }
  144:     }
  145:     return &Apache::lonnet::put
  146: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
  147: }
  148: 
  149: # ========================================================== Copy resourcesdata
  150: 
  151: sub copyresourcedb {
  152:     my ($origcrsid,$newcrsid)=@_;
  153:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  154:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
  155:     my %data=&Apache::lonnet::dump
  156: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
  157:     $origcrsid=~s/^\///;
  158:     $origcrsid=~s/\//\_/;
  159:     $newcrsid=~s/^\///;
  160:     $newcrsid=~s/\//\_/;
  161:     my %newdata=();
  162:     undef %newdata;
  163:     my $startdate=$data{$origcrsid.'.0.opendate'};
  164:     if (!$startdate) {
  165: 	# now global start date for assements try the enrollment start
  166: 	my %start=&Apache::lonnet::get('environment',
  167: 				   ['default_enrollment_start_date'],
  168: 				   $origcrsdata{'domain'},$origcrsdata{'num'});
  169: 
  170: 	$startdate = $start{'default_enrollment_start_date'};
  171:     }
  172:     my $today=time;
  173:     my $delta=0;
  174:     if ($startdate) {
  175: 	my $oneday=60*60*24;
  176: 	$delta=$today-$startdate;
  177: 	$delta=int($delta/$oneday)*$oneday;
  178:     }
  179: # ugly retro fix for broken version of types
  180:     foreach (keys %data) {
  181: 	if ($_=~/\wtype$/) {
  182: 	    my $newkey=$_;
  183: 	    $newkey=~s/type$/\.type/;
  184: 	    $data{$newkey}=$data{$_};
  185: 	    delete $data{$_};
  186: 	}
  187:     }
  188: # adjust symbs
  189:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
  190:     $pattern=~s/(\W)/\\$1/gs;
  191:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
  192:     foreach (keys %data) {
  193: 	if ($_=~/$pattern/) {
  194: 	    my $newkey=$_;
  195: 	    $newkey=~s/$pattern/$new/;
  196: 	    $data{$newkey}=$data{$_};
  197: 	    delete $data{$_};
  198: 	}
  199:     }
  200: # adjust dates
  201:     foreach (keys %data) {
  202: 	my $thiskey=$_;
  203: 	$thiskey=~s/^$origcrsid/$newcrsid/;
  204: 	$newdata{$thiskey}=$data{$_};
  205: 	if ($data{$_.'.type'}=~/^date_(start|end)$/) {
  206: 	    if ($delta > 0) {
  207: 		$newdata{$thiskey}=$newdata{$thiskey}+$delta;
  208: 	    } else {
  209: 		# no delta, it's unlikely we want the old dates and times
  210: 		delete($newdata{$thiskey});
  211: 		delete($newdata{$thiskey.'.type'});
  212: 	    }
  213: 	}
  214:     }
  215:     return &Apache::lonnet::put
  216: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
  217: }
  218: 
  219: # ========================================================== Copy all userfiles
  220: 
  221: sub copyuserfiles {
  222:     my ($origcrsid,$newcrsid)=@_;
  223:     foreach (&crsdirlist($origcrsid,'userfiles')) {
  224: 	if ($_ !~m|^scantron_|) {
  225: 	    &copyfile($origcrsid,$newcrsid,$_);
  226: 	}
  227:     }
  228: }
  229: # ========================================================== Copy all userfiles
  230: 
  231: sub copydbfiles {
  232:     my ($origcrsid,$newcrsid)=@_;
  233: 
  234:     my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|);
  235:     $origcrs_discussion=~s|/|_|g;
  236:     foreach (&crsdirlist($origcrsid)) {
  237: 	if ($_=~/\.db$/) {
  238: 	    unless 
  239:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|gradingqueue|reviewqueue|CODEs|groupmembership)/) {
  240: 		 &copydb($origcrsid,$newcrsid,$_);
  241: 	     }
  242: 	}
  243:     }
  244: }
  245: 
  246: # ======================================================= Copy all course files
  247: 
  248: sub copycoursefiles {
  249:     my ($origcrsid,$newcrsid)=@_;
  250:     &copyuserfiles($origcrsid,$newcrsid);
  251:     &copydbfiles($origcrsid,$newcrsid);
  252:     &copyresourcedb($origcrsid,$newcrsid);
  253: }
  254: 
  255: # ===================================================== Phase one: fill-in form
  256: 
  257: sub print_course_creation_page {
  258:     my $r=shift;
  259:     my $crstype = 'Course';
  260: #    my $crstype = 'Group';
  261: #    if ($env{'form.phase'} eq 'courseone') {
  262: #        $crstype = 'Course';
  263: #    }
  264:     my $defdom=$env{'request.role.domain'};
  265:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
  266:     my $course_home = '<select name="course_home" size="1">'."\n";
  267:     foreach my $server (sort(keys(%host_servers))) {
  268:         $course_home .= qq{<option value="$server"};
  269:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
  270:             $course_home .= " selected ";
  271:         }
  272:         $course_home .= qq{>$server $host_servers{$server}</option>};
  273:     }
  274:     $course_home .= "\n</select>\n";
  275:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  276:     my $cloneform=&Apache::loncommon::select_dom_form
  277: 	($env{'request.role.domain'},'clonedomain').
  278: 		     &Apache::loncommon::selectcourse_link
  279: 	     ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
  280:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
  281:     my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform,
  282:         $javascript_validations);
  283:     if ($crstype eq 'Course') {
  284:         my $starttime = time;
  285:         my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  286:         $enroll_table = &Apache::londropadd::date_setting_table($starttime,
  287:                                                 $endtime,'create_enrolldates');
  288:         $access_table = &Apache::londropadd::date_setting_table($starttime,
  289:                                                $endtime,'create_defaultdates');
  290:         ($krbdef,$krbdefdom) =
  291:         &Apache::loncommon::get_kerberos_defaults($defdom);
  292:         $javascript_validations=&Apache::londropadd::javascript_validations(
  293:                                                     'createcourse',$krbdefdom);
  294:         my %param = ( formname      => 'document.ccrs',
  295:                       kerb_def_dom  => $krbdefdom,
  296:                       kerb_def_auth => $krbdef
  297:                     );
  298:         $krbform = &Apache::loncommon::authform_kerberos(%param);
  299:         $intform = &Apache::loncommon::authform_internal(%param);
  300:         $locform = &Apache::loncommon::authform_local(%param);
  301:     } else {
  302:         $javascript_validations = qq|
  303: function validate(formname) {
  304:     if (formname.title == '') {
  305:         alert("A group title is required");
  306:         return;
  307:     }
  308:     if (formname.ccuname == '') {
  309:         alert("The username of the group coordinator is required");
  310:     }
  311:     formname.submit();
  312: }
  313:         |;
  314:     }
  315:     my %lt=&Apache::lonlocal::texthash(
  316: 		    'cinf' => "Course Information",
  317:                     'ctit' => "Course Title",
  318:                     'chsr' => "Course Home Server",
  319:                     'cidn' => "Course ID/Number",
  320:                     'opt'  => "optional",
  321:                     'iinf' => "Institutional Information",
  322:                     '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.",
  323:                     'ccod' => "Course Code",
  324:                     'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
  325:                     'snid' => "Section Numbers and corresponding LON-CAPA section IDs",
  326:                     'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section ID to be used in LON-CAPA e.g., 001:1,002:2",
  327:                     'crcs' => "Crosslisted courses",
  328:                     '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) sectionID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2",
  329:                     'crco' => "Course Content",
  330:                     'cncr' => "Completely new course",
  331:                     'cecr' => "Clone an existing course", 
  332:                     'map'  => "Map",
  333:                     'smap' => "Select Map",
  334:                     'sacr' => "Do NOT generate as standard course",
  335:                     'ocik' => "only check if you know what you are doing",
  336:                     'fres' => "First Resource",
  337:                     'stco' => "standard courses only",
  338:                     'blnk' => "Blank",
  339:                     'sllb' => "Syllabus",
  340:                     'navi' => "Navigate",
  341:                     'cid'  => "Course ID",
  342:                     'dmn'  => "Domain",
  343:                     'asov' => "Additional settings, if specified below, will override cloned settings",
  344:                     'assp' => "Assessment Parameters",
  345:                     'oaas' => "Open all assessments",
  346:                     'mssg' => "Messaging",
  347:                     'scpf' => "Set course policy feedback to Course Coordinator",
  348:                     'scfc' => "Set content feedback to Course Coordinator",
  349:                     'cmmn' => "Communication",
  350:                     'dsrd' => "Disable student resource discussion",
  351:                     'dsuc' => "Disable student use of chatrooms",
  352:                     'acco' => "Access Control",
  353:                     'snak' => "Students need access key to enter course",
  354: 		    'kaut' => 
  355: 		    'Key authority (<tt>id@domain</tt>) if other than course',
  356:                     'cc'   => "Course Coordinator",
  357:                     'user' => "Username",
  358:                     'aens' => "Automated enrollment settings",
  359:                     '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.",
  360:                     'aadd' => "Automated adds",
  361:                     'yes'  => "Yes",
  362:                     'no'   => "No",
  363:                     'audr' => "Automated drops",
  364:                     'dacu' => "Duration of automated classlist updates",
  365:                     'dacc' => "Default start and end dates for student access",
  366:                     'psam' => "Please select the authentication mechanism",
  367:                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
  368:                     'nech' => "Notification of enrollment changes",
  369:                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  370:                     'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
  371:                     'irsp' => "Include retrieval of student photographs?",
  372: 		    'rshm' => 'Resource Space Home',
  373:                     'cgrs' => "Course Group Settings",
  374:                     'cgrq' => "Set a quota for the total disk space available for storage of course group portfolio files.",
  375:                     'opco' => "Open Course",
  376:                     'ginf' => "Group Information",
  377:                     'gtit' => "Group Title",
  378:                     'ghsr' => "Group Home Server",
  379:                     'gidn' => "Group ID/Number",
  380:                     'grco' => "Group Content",
  381:                     'cngr' => "Completely new group",
  382:                     'cegr' => "Clone an existing group",
  383:                     'sagr' => "Do NOT generate as standard group",
  384:                     'stgo' => "standard groups only",
  385:                     'sgpf' => "Set group policy feedback to Group Coordinator",
  386:                     'scfg' => "Set content feedback to Group Coordinator",
  387:                     'dmrd' => "Disable member resource discussion",
  388:                     'dmuc' => "Disable member use of chatrooms",
  389:                     'mnak' => "Members need access key to enter group",
  390:                     'kaug' =>
  391:                     'Key authority (<tt>id@domain</tt>) if other than group',
  392:                     'gc'   => "Group Coordinator",
  393:                     'gid'  => "Group ID",
  394:                     'crgr' => "Create Group",
  395:                     'grts' => "Group Teams Settings",
  396:                     'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.",
  397: 
  398: 				       );
  399:     my $js = <<END;
  400: <script type="text/javascript">
  401: var editbrowser = null;
  402: function openbrowser(formname,elementname) {
  403:     var url = '/res/?';
  404:     if (editbrowser == null) {
  405:         url += 'launch=1&';
  406:     }
  407:     url += 'catalogmode=interactive&';
  408:     url += 'mode=edit&';
  409:     url += 'form=' + formname + '&';
  410:     url += 'element=' + elementname + '&';
  411:     url += 'only=sequence' + '';
  412:     var title = 'Browser';
  413:     var options = 'scrollbars=1,resizable=1,menubar=0';
  414:     options += ',width=700,height=600';
  415:     editbrowser = open(url,title,options,'1');
  416:     editbrowser.focus();
  417: }
  418: $javascript_validations
  419: </script>
  420: $coursebrowserjs
  421: END
  422: 
  423:     my %titles = &Apache::lonlocal::texthash(
  424:                   courseone => 'Create a New Course',
  425:                   groupone => 'Create a New Group',
  426:     );  
  427:     my $start_page = 
  428:         &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
  429:     my $end_page = 
  430:         &Apache::loncommon::end_page();
  431:     my $crumbs = 
  432: 	&Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
  433: 					    'Create_Course',undef,
  434: 					    'Create_Courses');
  435:     $r->print($start_page.$crumbs);
  436:     if ($crstype eq 'Course') {
  437:         $r->print(<<ENDDOCUMENT);
  438: <form action="/adm/createcourse" method="post" name="ccrs">
  439: <h2>$lt{'cinf'}</h2>
  440: <p>
  441: <label><b>$lt{'ctit'}:</b>
  442: <input type="text" size="50" name="title" /></label>
  443: </p><p>
  444: <label>
  445:     <b>$lt{'chsr'}:</b>$course_home
  446: </label>
  447: </p><p>
  448: <label>
  449:     <b>$lt{'cidn'} ($lt{'opt'})</b>
  450:     <input type="text" size="30" name="crsid" />
  451: </label>
  452: </p><p>
  453: <h2>$lt{'iinf'}</h2>
  454: <p>
  455: $lt{'stat'}
  456: </p><p>
  457: <label>
  458:     <b>$lt{'ccod'}</b>
  459:     <input type="text" size="30" name="crscode" />
  460: </label>
  461: <br/>
  462: ($lt{'toin'})
  463: </p><p>
  464: <label>
  465:     <b>$lt{'snid'}</b>
  466:     <input type="text" size="30" name="crssections" />
  467: </label>
  468: <br/>
  469: ($lt{'csli'})
  470: </p><p>
  471: <label>
  472:     <b>$lt{'crcs'}</b>
  473:     <input type="text" size="30" name="crsxlist" />
  474: </label>
  475: <br/>
  476: ($lt{'cscs'})
  477: </p>
  478: <h2>$lt{'crco'}</h2>
  479: <table border="2">
  480: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
  481: <tr><td>
  482: <p>
  483: <label>
  484:     <b>$lt{'map'}:</b>
  485:     <input type="text" size="50" name="topmap" />
  486: </label>
  487: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  488: </p><p>
  489: <label for="nonstd"><b>$lt{'sacr'}</b></label>
  490: <br />
  491: ($lt{'ocik'}):
  492: <input id="nonstd" type="checkbox" name="nonstandard" />
  493: </p><p>
  494: <b>$lt{'fres'}</b><br />($lt{'stco'}):
  495: <label>
  496:     <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
  497: </label>
  498: &nbsp;
  499: <label>
  500:     <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
  501: </label>
  502: &nbsp;
  503: <label>
  504:     <input type="radio" name="firstres" value="nav" />$lt{'navi'}
  505: </label>
  506: </p>
  507: </td><td>
  508: <label>
  509:     $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
  510: </label>
  511: <br />
  512: <label>
  513:     $lt{'dmn'}: $cloneform
  514: </label>
  515: <br />
  516: &nbsp;<br />
  517: $lt{'asov'}.
  518: </td></tr>
  519: </table>
  520: <h2>$lt{'assp'}</h2>
  521: <p>
  522: <label>
  523:     <b>$lt{'oaas'}: </b>
  524:     <input type="checkbox" name="openall" />
  525: </label>
  526: </p>
  527: <h2>$lt{'mssg'}</h2>
  528: <p>
  529: <label>
  530:     <b>$lt{'scpf'}: </b>
  531:     <input type="checkbox" name="setpolicy" checked />
  532: </label>
  533: <br />
  534: <label>
  535:     <b>$lt{'scfc'}: </b>
  536:     <input type="checkbox" name="setcontent" checked />
  537: </label>
  538: </p>
  539: <h2>$lt{'cmmn'}</h2>
  540: <p>
  541: <label>
  542:     <b>$lt{'dsrd'}: </b>
  543:     <input type="checkbox" name="disresdis" />
  544: </label>
  545: <br />
  546: <label>
  547:     <b>$lt{'dsuc'}: </b>
  548:     <input type="checkbox" name="disablechat" />
  549: </label>
  550: </p>
  551: <h2>$lt{'acco'}</h2>
  552: <p>
  553: <label>
  554:     <b>$lt{'snak'}: </b>
  555:     <input type="checkbox" name="setkeys" />
  556: </label>
  557: <br />
  558: <label>
  559:     <b>$lt{'kaut'}: </b>
  560:     <input type="text" size="30" name="keyauth" />
  561: </label>
  562: </p>
  563: <h2>$lt{'rshm'}</h2>
  564: <p>
  565: <label>
  566:     <b>$lt{'rshm'}: </b>
  567:     <input type="text" name="reshome" size="30" value="/res/$defdom/" />
  568: </label>
  569: </p>
  570: <p>
  571: <h2>$lt{'aens'}</h2>
  572: $lt{'aesc'}
  573: </p>
  574: <p>
  575: <b>$lt{'aadd'}</b>
  576: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label> 
  577: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
  578: </label>
  579: </p><p>
  580: <b>$lt{'audr'}</b>
  581: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label> 
  582: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
  583: </p><p>
  584: <b>$lt{'dacu'}</b>
  585: $enroll_table
  586: </p><p>
  587: <b>$lt{'dacc'}</b>
  588: $access_table
  589: <p></p>
  590: <b>$lt{'psam'}.</b><br />
  591: $lt{'pcda'}.
  592: </p><p>
  593: $krbform
  594: <br />
  595: $intform
  596: <br />
  597: $locform
  598: </p><p>
  599: <b>$lt{'nech'}</b><br />
  600: $lt{'nccl'}<br/>
  601: <label>
  602:     <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
  603: </label> 
  604: <label>
  605:     <input type="radio" name="notify_owner" value="0" checked="true" />$lt{'no'}
  606: </label>
  607: <br />
  608: $lt{'ndcl'}<br/>
  609: <label>
  610:     <input type="radio" name="notify_dc" value="1" />$lt{'yes'}
  611: </label>
  612: <label>
  613:     <input type="radio" name="notify_dc" value="0" checked="true" />$lt{'no'}
  614: </label>
  615: </p><p>
  616: <b>$lt{'irsp'}</b>
  617: <label>
  618:     <input type="radio" name="showphotos" value="1" />$lt{'yes'}
  619: </label> 
  620: <label>
  621:     <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
  622: </label>
  623: </p>
  624: <p>
  625: <h2>$lt{'cgrs'}</h2>
  626: $lt{'cgrq'}
  627: <input type="text" name="crsquota" value="20" size="6" />Mb 
  628: </p>
  629: <hr />
  630: <h2>$lt{'cc'}</h2>
  631: <p>
  632: <label>
  633:     <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
  634: </label>
  635: </p><p>
  636: <label>
  637:     <b>$lt{'dmn'}:</b> $domform
  638: </label>
  639: </p>
  640: <p>
  641: <input type="hidden" name="prevphase" value="courseone" />
  642: <input type="hidden" name="phase" value="coursetwo" />
  643: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
  644: </p>
  645: </form>
  646: ENDDOCUMENT
  647:     } elsif ($crstype eq 'Group') {
  648:         $r->print(<<ENDDOCUMENT);
  649: <form action="/adm/createcourse" method="post" name="ccrs">
  650: <h2>$lt{'ginf'}</h2>
  651: <p>
  652: <label><b>$lt{'gtit'}:</b>
  653: <input type="text" size="50" name="title" /></label>
  654: </p><p>
  655: <label>
  656:     <b>$lt{'ghsr'}:</b>$course_home
  657: </label>
  658: </p><p>
  659: <label>
  660:     <b>$lt{'gidn'} ($lt{'opt'})</b>
  661:     <input type="text" size="30" name="crsid" />
  662: </label>
  663: </p>
  664: <h2>$lt{'grco'}</h2>
  665: <table border="2">
  666: <tr><th>$lt{'cngr'}</th><th>$lt{'cegr'}</th></tr>
  667: <tr><td>
  668: <p>
  669: <label>
  670:     <b>$lt{'map'}:</b>
  671:     <input type="text" size="50" name="topmap" />
  672: </label>
  673: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  674: </p><p>
  675: <label for="nonstd"><b>$lt{'sagr'}</b></label>
  676: <br />
  677: ($lt{'ocik'}):
  678: <input id="nonstd" type="checkbox" name="nonstandard" />
  679: </p><p>
  680: <b>$lt{'fres'}</b><br />($lt{'stgo'}):
  681: <label>
  682:     <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
  683: </label>
  684: &nbsp;
  685: <label>
  686:     <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
  687: </label>
  688: &nbsp;
  689: <label>
  690:     <input type="radio" name="firstres" value="nav" />$lt{'navi'}
  691: </label>
  692: </p>
  693: </td><td>
  694: <label>
  695:     $lt{'gid'}: <input type="text" size="25" name="clonecourse" value="" />
  696: </label>
  697: <br />
  698: <label>
  699:     $lt{'dmn'}: $cloneform
  700: </label>
  701: <br />
  702: &nbsp;<br />
  703: $lt{'asov'}.
  704: </td></tr>
  705: </table>
  706: </p>
  707: <p>
  708: <h2>$lt{'mssg'}</h2>
  709: <p>
  710: <label>
  711:     <b>$lt{'sgpf'}: </b>
  712:     <input type="checkbox" name="setpolicy" checked />
  713: </label>
  714: <br />
  715: <label>
  716:     <b>$lt{'scfg'}: </b>
  717:     <input type="checkbox" name="setcontent" checked />
  718: </label>
  719: </p>
  720: <h2>$lt{'cmmn'}</h2>
  721: <p>
  722: <label>
  723:     <b>$lt{'dmrd'}: </b>
  724:     <input type="checkbox" name="disresdis" />
  725: </label>
  726: <br />
  727: <label>
  728:     <b>$lt{'dmuc'}: </b>
  729:     <input type="checkbox" name="disablechat" />
  730: </label>
  731: </p>
  732: <h2>$lt{'acco'}</h2>
  733: <p>
  734: <label>
  735:     <b>$lt{'mnak'}: </b>
  736:     <input type="checkbox" name="setkeys" />
  737: </label>
  738: <br />
  739: <label>
  740:     <b>$lt{'kaug'}: </b>
  741:     <input type="text" size="30" name="keyauth" />
  742: </label>
  743: </p>
  744: <h2>$lt{'rshm'}</h2>
  745: <p>
  746: <label>
  747:     <b>$lt{'rshm'}: </b>
  748:     <input type="text" name="reshome" size="30" value="/res/$defdom/" />
  749: </label>
  750: </p>
  751: <p>
  752: <h2>$lt{'grts'}</h2>
  753: $lt{'grtq'}
  754: <input type="text" name="crsquota" value="20" />Mb
  755: </p>
  756: <hr />
  757: <h2>$lt{'gc'}</h2>
  758: <p>
  759: <label>
  760:     <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
  761: </label>
  762: </p><p>
  763: <label>
  764:     <b>$lt{'dmn'}:</b> $domform
  765: </label>
  766: </p>
  767: <p>
  768: <input type="hidden" name="prevphase" value="groupone" />
  769: <input type="hidden" name="phase" value="grouptwo" />
  770: <input type="button" onClick="validate(this.form)" value="$lt{'crgr'}" />
  771: </p>
  772: </form>
  773: ENDDOCUMENT
  774:     }
  775:     $r->print($end_page);
  776: }
  777: 
  778: # ====================================================== Phase two: make course
  779: 
  780: sub create_course {
  781:     my $r=shift;
  782:     my $ccuname=$env{'form.ccuname'};
  783:     my $ccdomain=$env{'form.ccdomain'};
  784:     $ccuname=~s/\W//g;
  785:     $ccdomain=~s/\W//g;
  786:     my $crstype = 'Group';
  787:     my ($enrollstart,$enrollend,$startaccess,$endaccess);
  788: 
  789:     if ($env{'form.phase'} eq 'coursetwo') {
  790:         $crstype='Course';
  791:         $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
  792:         $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
  793: 
  794:     }
  795:     $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
  796:     $endaccess   = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
  797: 
  798:     my $autharg;
  799:     my $authtype;
  800: 
  801:     if ($env{'form.login'} eq 'krb') {
  802:         $authtype = 'krb';
  803:         $authtype .=$env{'form.krbver'};
  804:         $autharg = $env{'form.krbarg'};
  805:     } elsif ($env{'form.login'} eq 'int') {
  806:         $authtype ='internal';
  807:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
  808:             $autharg = $env{'form.intarg'};
  809:         }
  810:     } elsif ($env{'form.login'} eq 'loc') {
  811:         $authtype = 'localauth';
  812:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
  813:             $autharg = $env{'form.locarg'};
  814:         }
  815:     }
  816:     my $logmsg;
  817:     my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
  818:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
  819: 
  820:     $r->print($start_page.$crumbs);
  821: 
  822:     my $args = {
  823:                crstype => $crstype,
  824:                ccuname => $ccuname,
  825:                ccdomain => $ccdomain,
  826:                cdescr => $env{'form.title'},
  827:                curl => $env{'form.topmap'},
  828:                course_domain => $env{'request.role.domain'},
  829:                course_home =>  $env{'form.course_home'},
  830:                nonstandard => $env{'form.nonstandard'},
  831:                crscode => $env{'form.crscode'},
  832:                crsquota => $env{'form.crsquota'},
  833:                clonecourse => $env{'form.clonecourse'},
  834:                clonedomain => $env{'form.clonedomain'},
  835:                crsid => $env{'form.crsid'},
  836:                curruser => $env{'user.name'}.':'.$env{'user.domain'},
  837:                crssections => $env{'form.crssections'},
  838:                crsxlist => $env{'form.crsxlist'},
  839:                autoadds => $env{'form.autoadds'},
  840:                autodrops => $env{'form.autodrops'},
  841:                notify_owner => $env{'form.notify_owner'},
  842:                notify_dc => $env{'form.notify_dc'},
  843:                no_end_date => $env{'form.no_end_date'},
  844:                showphotos => $env{'form.showphotos'},
  845:                authtype => $authtype,
  846:                autharg => $autharg,
  847:                enrollstart => $enrollstart,
  848:                enrollend => $enrollend,
  849:                startaccess => $startaccess,
  850:                endaccess => $endaccess,
  851:                setpolicy => $env{'form.setpolicy'},
  852:                setcontent => $env{'form.setcontent'},
  853:                reshome => $env{'form.reshome'},
  854:                setkeys => $env{'form.setkeys'},
  855:                keyauth => $env{'form.keyauth'},
  856:                disresdis => $env{'form.disresdis'},
  857:                disablechat => $env{'form.disablechat'},
  858:                openall => $env{'form.openall'},
  859:                firstres => $env{'form.firstres'}
  860:                };
  861: 
  862:     #
  863:     # Verify data
  864:     #
  865:     # Check the veracity of the course coordinator
  866:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  867: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
  868:         $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
  869: 	$r->print(&mt("Please click Back on your browser and select another user, or "));
  870: 	$r->print('
  871: 	    <input type="hidden" name="phase" value="get_user_info" />
  872:             <input type="hidden" name="ccuname" value="'.$ccuname.'" />
  873:             <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
  874:             <input name="userrole" type="submit" value="'.
  875: 		  &mt('Create User').'" />
  876: 	</form>'.&Apache::loncommon::end_page());
  877: 	return;
  878:     }
  879:     # Check the proposed home server for the course
  880:     my %host_servers = &Apache::loncommon::get_library_servers
  881:         ($env{'request.role.domain'});
  882:     if (! exists($host_servers{$env{'form.course_home'}})) {
  883:         $r->print(&mt('Invalid home server for course').': '.
  884:                   $env{'form.course_home'}.&Apache::loncommon::end_page());
  885:         return;
  886:     }
  887:     my ($courseid,$crsudom,$crsunum);
  888:     $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
  889: 
  890: #
  891: # Make the requested user a course coordinator or group coordinator
  892: #
  893:     if (($ccdomain) && ($ccuname)) {
  894:         $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]:',
  895:                      $crstype,$ccuname,$ccdomain).
  896:                   &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
  897:                                               'cc').'<p>');
  898:     }
  899:     if ($env{'form.setkeys'}) {
  900:         $r->print(
  901:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
  902:     }
  903: # Flush the course logs so reverse user roles immediately updated
  904:     &Apache::lonnet::flushcourselogs();
  905:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
  906: 	      '<p><a href="/adm/createcourse">'.
  907: 	      &mt('Create Another [_1]',$crstype).'</a></p>'.
  908: 	      &Apache::loncommon::end_page());
  909: }
  910: 
  911: sub construct_course {
  912:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
  913:     my $outcome;
  914: 
  915: #
  916: # Open course
  917: #
  918:     my $crstype = lc($args->{'crstype'});
  919:     my %cenv=();
  920:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
  921:                                              $args->{'cdescr'},
  922:                                              $args->{'curl'},
  923:                                              $args->{'course_home'},
  924:                                              $args->{'nonstandard'},
  925:                                              $args->{'crscode'},
  926:                                              $args->{'ccuname'}.':'.
  927:                                              $args->{'ccdomain'},
  928:                                              $args->{'crstype'});
  929: 
  930:     # Note: The testing routines depend on this being output; see 
  931:     # Utils::Course. This needs to at least be output as a comment
  932:     # if anyone ever decides to not show this, and Utils::Course::new
  933:     # will need to be suitably modified.
  934:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]<br />',$crstype,$$courseid);
  935: #
  936: # Check if created correctly
  937: #
  938:     ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);
  939:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
  940:     $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
  941: #
  942: # Are we cloning?
  943: #
  944:     my $cloneid='';
  945:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
  946: 	$cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
  947:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
  948: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
  949: 	if ($clonehome eq 'no_host') {
  950: 	    $outcome .=
  951:     '<br /><font color="red">'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.'</font>';
  952: 	} else {
  953: 	    $outcome .= 
  954:     '<br /><font color="green">'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).'</font>';
  955: 	    my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
  956: # Copy all files
  957: 	    &copycoursefiles($cloneid,$$courseid);
  958: # Restore URL
  959: 	    $cenv{'url'}=$oldcenv{'url'};
  960: # Restore title
  961: 	    $cenv{'description'}=$oldcenv{'description'};
  962: # restore grading mode
  963: 	    if (defined($oldcenv{'grading'})) {
  964: 		$cenv{'grading'}=$oldcenv{'grading'};
  965: 	    }
  966: # Mark as cloned
  967: 	    $cenv{'clonedfrom'}=$cloneid;
  968: 	    delete($cenv{'default_enrollment_start_date'});
  969: 	    delete($cenv{'default_enrollment_end_date'});
  970: 	}
  971:     }
  972: #
  973: # Set environment (will override cloned, if existing)
  974: #
  975:     my @sections = ();
  976:     my @xlists = ();
  977:     if ($args->{'crstype'}) {
  978:         $cenv{'type'}=$args->{'crstype'};
  979:     }
  980:     if ($args->{'crsid'}) {
  981:         $cenv{'courseid'}=$args->{'crsid'};
  982:     }
  983:     if ($args->{'crscode'}) {
  984:         $cenv{'internal.coursecode'}=$args->{'crscode'};
  985:     }
  986:     if ($args->{'crsquota'} ne '') {
  987:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
  988:     } else {
  989:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
  990:     }
  991:     if ($args->{'ccuname'}) {
  992:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
  993:                                         ':'.$args->{'ccdomain'};
  994:     } else {
  995:         $cenv{'internal.courseowner'} = $args->{'curruser'};
  996:     }
  997: 
  998:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
  999:     if ($args->{'crssections'}) {
 1000:         $cenv{'internal.sectionnums'} = '';
 1001:         if ($args->{'crssections'} =~ m/,/) {
 1002:             @sections = split/,/,$args->{'crssections'};
 1003:         } else {
 1004:             $sections[0] = $args->{'crssections'};
 1005:         }
 1006:         if (@sections > 0) {
 1007:             foreach my $item (@sections) {
 1008:                 my ($sec,$gp) = split/:/,$item;
 1009:                 my $class = $args->{'crscode'}.$sec;
 1010:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
 1011:                 $cenv{'internal.sectionnums'} .= $item.',';
 1012:                 unless ($addcheck eq 'ok') {
 1013:                     push @badclasses, $class;
 1014:                 }
 1015:             }
 1016:             $cenv{'internal.sectionnums'} =~ s/,$//;
 1017:         }
 1018:     }
 1019: # do not hide course coordinator from staff listing, 
 1020: # even if privileged
 1021:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
 1022: # add crosslistings
 1023:     if ($args->{'crsxlist'}) {
 1024:         $cenv{'internal.crosslistings'}='';
 1025:         if ($args->{'crsxlist'} =~ m/,/) {
 1026:             @xlists = split/,/,$args->{'crsxlist'};
 1027:         } else {
 1028:             $xlists[0] = $args->{'crsxlist'};
 1029:         }
 1030:         if (@xlists > 0) {
 1031:             foreach my $item (@xlists) {
 1032:                 my ($xl,$gp) = split/:/,$item;
 1033:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
 1034:                 $cenv{'internal.crosslistings'} .= $item.',';
 1035:                 unless ($addcheck eq 'ok') {
 1036:                     push @badclasses, $xl;
 1037:                 }
 1038:             }
 1039:             $cenv{'internal.crosslistings'} =~ s/,$//;
 1040:         }
 1041:     }
 1042:     if ($args->{'autoadds'}) {
 1043:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
 1044:     }
 1045:     if ($args->{'autodrops'}) {
 1046:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
 1047:     }
 1048: # check for notification of enrollment changes
 1049:     my @notified = ();
 1050:     if ($args->{'notify_owner'}) {
 1051:         if ($args->{'ccuname'} ne '') {
 1052:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
 1053:         }
 1054:     }
 1055:     if ($args->{'notify_dc'}) {
 1056:         if ($uname ne '') { 
 1057:             push(@notified,$uname.'@'.$udom);
 1058:         }
 1059:     }
 1060:     if (@notified > 0) {
 1061:         my $notifylist;
 1062:         if (@notified > 1) {
 1063:             $notifylist = join(',',@notified);
 1064:         } else {
 1065:             $notifylist = $notified[0];
 1066:         }
 1067:         $cenv{'internal.notifylist'} = $notifylist;
 1068:     }
 1069:     if (@badclasses > 0) {
 1070:         my %lt=&Apache::lonlocal::texthash(
 1071:                 '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',
 1072:                 'dnhr' => 'does not have rights to access enrollment in these classes',
 1073:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
 1074:         );
 1075:         $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
 1076:         foreach (@badclasses) {
 1077:             $outcome .= "<li>$_</li>\n";
 1078:         }
 1079:         $outcome .= "</ul><br /><br /></font>\n";
 1080:     }
 1081:     if ($args->{'no_end_date'}) {
 1082:         $args->{'endaccess'} = 0;
 1083:     }
 1084:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
 1085:     $cenv{'internal.autoend'}=$args->{'enrollend'};
 1086:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
 1087:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
 1088:     if ($args->{'showphotos'}) {
 1089:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
 1090:     }
 1091:     $cenv{'internal.authtype'} = $args->{'authtype'};
 1092:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
 1093:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
 1094:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
 1095:             $outcome .= '<font color="red" size="+1">'.
 1096:                       &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>';
 1097:         }
 1098:     }
 1099:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
 1100:        if ($args->{'setpolicy'}) {
 1101:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
 1102:        }
 1103:        if ($args->{'setcontent'}) {
 1104:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
 1105:        }
 1106:     }
 1107:     if ($args->{'reshome'}) {
 1108: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
 1109: 	$cenv{'reshome'}=~s/\/+$/\//;
 1110:     }
 1111: #
 1112: # course has keyed access
 1113: #
 1114:     if ($args->{'setkeys'}) {
 1115:        $cenv{'keyaccess'}='yes';
 1116:     }
 1117: # if specified, key authority is not course, but user
 1118: # only active if keyaccess is yes
 1119:     if ($args->{'keyauth'}) {
 1120: 	$args->{'keyauth'}=~s/[^\w\@]//g;
 1121: 	if ($args->{'keyauth'}) {
 1122: 	    $cenv{'keyauth'}=$args->{'keyauth'};
 1123: 	}
 1124:     }
 1125: 
 1126:     if ($args->{'disresdis'}) {
 1127:         $cenv{'pch.roles.denied'}='st';
 1128:     }
 1129:     if ($args->{'disablechat'}) {
 1130:         $cenv{'plc.roles.denied'}='st';
 1131:     }
 1132: 
 1133:     # Record we've not yet viewed the Course Initialization Helper for this 
 1134:     # course
 1135:     $cenv{'course.helper.not.run'} = 1;
 1136:     #
 1137:     # Use new Randomseed
 1138:     #
 1139:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
 1140:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
 1141:     #
 1142:     # The encryption code and receipt prefix for this course
 1143:     #
 1144:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
 1145:     $cenv{'internal.encpref'}=100+int(9*rand(99));
 1146:     #
 1147:     # By default, use standard grading
 1148:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
 1149: 
 1150:     $outcome .= ('<br />'.&mt('Setting environment').': '.                 
 1151:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
 1152: #
 1153: # Open all assignments
 1154: #
 1155:     if ($args->{'openall'}) {
 1156:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
 1157:        my %storecontent = ($storeunder         => time,
 1158:                            $storeunder.'.type' => 'date_start');
 1159:        
 1160:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
 1161:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
 1162:    }
 1163: #
 1164: # Set first page
 1165: #
 1166:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
 1167: 	    || ($cloneid)) {
 1168: 	$outcome .= &mt('Setting first resource').': ';
 1169:         my ($errtext,$fatal)=
 1170:            &Apache::londocs::mapread($$crsunum,$$crsudom,'default.sequence');
 1171:         $outcome .= ($fatal?$errtext:'read ok').' - ';
 1172:         my $title; my $url;
 1173:         if ($args->{'firstres'} eq 'syl') {
 1174: 	    $title='Syllabus';
 1175:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
 1176:         } else {
 1177:             $title='Navigate Contents';
 1178:             $url='/adm/navmaps';
 1179:         }
 1180:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
 1181:         ($errtext,$fatal)=
 1182:            &Apache::londocs::storemap($$crsunum,$$crsudom,'default.sequence');
 1183:         $outcome .= ($fatal?$errtext:'write ok').'<br>';
 1184:     }
 1185:     return $outcome;
 1186: }
 1187: 
 1188: sub print_intro_page {
 1189:     my $r = shift;
 1190:     my $start_page =
 1191:         &Apache::loncommon::start_page('Create a New Course');
 1192:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
 1193:     my $end_page =
 1194:         &Apache::loncommon::end_page();
 1195:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
 1196: 
 1197:     my @choices = ({ internal_name => 'courseone',
 1198:                      name => &mt('Create a single course'),
 1199:                      short_description =>
 1200:     &mt('Create a new course by completing an online form.'),
 1201:                  },
 1202: #                   { internal_name => 'groupone',
 1203: #                     name => &mt('Create a single collaborative group space '),
 1204: #                     short_description =>
 1205: #    &mt('Create a new group space for non-course use by completing an online form .'),
 1206: #                 },
 1207:                    { internal_name => 'batchone',
 1208:                      name => &mt('Create courses/groups by uploading an attributes file'),
 1209:                      short_description =>
 1210:     &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
 1211:                  },
 1212:     );
 1213:     my $options;
 1214:     foreach my $choice (@choices) {
 1215:         $options .='    <h3><a href="/adm/createcourse?phase='.
 1216:             $choice->{'internal_name'}.'" >'.
 1217:             $choice->{'name'}."</a></h3>\n";
 1218:         $options .= '    '.('&nbsp;'x8).$choice->{'short_description'}.
 1219:             "\n";
 1220:     }
 1221: 
 1222:     $r->print(<<ENDDOCUMENT);
 1223: $start_page
 1224: $crumbs
 1225: $options
 1226: $end_page
 1227: ENDDOCUMENT
 1228: }
 1229: 
 1230: sub upload_batchfile {
 1231:     my $r = shift;
 1232:     my $start_page =
 1233:         &Apache::loncommon::start_page('Create a New Course or Group Space');
 1234:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course Attributes File','Create_Course',undef,'Create_Courses');
 1235:     my $end_page =
 1236:         &Apache::loncommon::end_page();
 1237:     $r->print($start_page.$crumbs);
 1238:     $r->print('<h3>'.&mt('Upload a courses attributes file').'</h3>');
 1239:     $r->print('<form name="batchcreate" method="post" '.
 1240:                 'enctype="multipart/form-data" action="/adm/createcourse">'.
 1241:               '<input type="file" name="coursecreatorxml" />'.
 1242:               '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
 1243:               '<input type="submit" name="batchsubmit" '.
 1244:               'value="Create Courses/Groups" /></form>');
 1245:     $r->print($end_page);
 1246:     return;
 1247: }
 1248: 
 1249: sub process_batchfile {
 1250:     my $r = shift;
 1251:     my $start_page =
 1252:         &Apache::loncommon::start_page('Create a New Course or Group Space');
 1253:     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
 1254:     my $end_page =
 1255:         &Apache::loncommon::end_page();
 1256:     my $defdom=$env{'request.role.domain'};
 1257:     my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
 1258:                                                       'batchupload',undef,undef,
 1259:                                                        undef,undef,$defdom);
 1260:     my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
 1261:     my ($result,$logmsg);
 1262:     if (-e "$batchfilepath") {
 1263:         open(FILE,"<$batchfilepath");
 1264:         my @buffer = <FILE>;
 1265:         close(FILE);
 1266:         if ((defined($filename)) && (defined($batchdir))) {
 1267:             my @requests = ($filename);
 1268:             my %courseids = ();
 1269:             ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
 1270:                                         \@requests,\%courseids,'web',$defdom,
 1271:                                         $env{'user.name'},$env{'user.domain'});
 1272:             if ($result) {
 1273:                 if (!-e "$batchdir/processed") {
 1274:                     mkdir("$batchdir/processed", 0755);
 1275:                     open(FILE,">$batchdir/processed/$filename");
 1276:                     print FILE @buffer;
 1277:                     close(FILE);
 1278:                     if (-e "$batchdir/processed/$filename") {
 1279:                         unlink("$batchdir/pending/$filename");
 1280:                     }
 1281:                 }
 1282:             }
 1283:         }
 1284:     }
 1285:     $r->print($start_page.$crumbs.$result.$end_page);
 1286:  
 1287: }
 1288: 
 1289: # ===================================================================== Handler
 1290: sub handler {
 1291:     my $r = shift;
 1292: 
 1293:     if ($r->header_only) {
 1294:        &Apache::loncommon::content_type($r,'text/html');
 1295:        $r->send_http_header;
 1296:        return OK;
 1297:     }
 1298: 
 1299:     if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
 1300:        &Apache::loncommon::content_type($r,'text/html');
 1301:        $r->send_http_header;
 1302: 
 1303:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1304:                                             ['phase']);
 1305:        &Apache::lonhtmlcommon::clear_breadcrumbs();
 1306:        &Apache::lonhtmlcommon::add_breadcrumb
 1307:           ({href=>"/adm/createcourse",
 1308:             text=>"Creation Options",
 1309:             faq=>79,bug=>'Dom Coord Interface',});
 1310:        if (($env{'form.phase'} eq 'coursetwo') ||
 1311:            ($env{'form.phase'} eq 'grouptwo')) {
 1312:            &Apache::lonhtmlcommon::add_breadcrumb
 1313:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
 1314:                    text=>&mt('[_1] Creation Settings',),
 1315:                    faq=>9,bug=>'Dom Coord Interface',});
 1316:           &Apache::lonhtmlcommon::add_breadcrumb
 1317:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
 1318:                    text=>"Creation Outcome",
 1319:                    faq=>9,bug=>'Dom Coord Interface',});
 1320:            &create_course($r);
 1321:        } elsif (($env{'form.phase'} eq 'courseone') || 
 1322:                 ($env{'form.phase'} eq 'groupone')) {
 1323:            &Apache::lonhtmlcommon::add_breadcrumb
 1324:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
 1325:                    text=>&mt('[_1] Creation Settings',),
 1326:                    faq=>9,bug=>'Dom Coord Interface',});
 1327: 	   &print_course_creation_page($r);
 1328:        } elsif ($env{'form.phase'} eq 'batchone') {
 1329:            &Apache::lonhtmlcommon::add_breadcrumb
 1330:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
 1331:                    text=>"Upload Description File",
 1332:                    faq=>9,bug=>'Dom Coord Interface',});
 1333:            &upload_batchfile($r);
 1334:        } elsif ($env{'form.phase'} eq 'batchtwo') {
 1335:            &Apache::lonhtmlcommon::add_breadcrumb
 1336:                  ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
 1337:                    text=>"Upload Description File",
 1338:                    faq=>9,bug=>'Dom Coord Interface',});
 1339:            &Apache::lonhtmlcommon::add_breadcrumb
 1340:                  ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
 1341:                    text=>"Creation Outcome",
 1342:                    faq=>9,bug=>'Dom Coord Interface',});
 1343:            &process_batchfile($r);
 1344:        } else {
 1345:            &print_intro_page($r);
 1346:        }
 1347:    } else {
 1348:       $env{'user.error.msg'}=
 1349:         "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
 1350:       return HTTP_NOT_ACCEPTABLE; 
 1351:    }
 1352:    return OK;
 1353: }
 1354: 
 1355: 1;
 1356: __END__

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