Annotation of loncom/interface/loncreatecourse.pm, revision 1.86

1.65      raeburn     1: # The LearningOnline Network
1.1       www         2: # Create a course
1.5       albertel    3: #
1.86    ! albertel    4: # $Id: loncreatecourse.pm,v 1.85 2006/01/16 23:11:50 albertel Exp $
1.5       albertel    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: #
1.48      www        28: ###
                     29: 
1.1       www        30: package Apache::loncreatecourse;
                     31: 
                     32: use strict;
                     33: use Apache::Constants qw(:common :http);
                     34: use Apache::lonnet;
1.12      www        35: use Apache::loncommon;
1.13      www        36: use Apache::lonratedt;
                     37: use Apache::londocs;
1.38      www        38: use Apache::lonlocal;
1.41      raeburn    39: use Apache::londropadd;
1.44      raeburn    40: use lib '/home/httpd/lib/perl';
1.28      www        41: 
                     42: # ================================================ Get course directory listing
                     43: 
1.62      www        44: my @output=();
                     45: 
1.28      www        46: sub crsdirlist {
                     47:     my ($courseid,$which)=@_;
1.62      www        48:     @output=();
                     49:     return &innercrsdirlist($courseid,$which);
                     50: }
                     51: 
                     52: sub innercrsdirlist {
                     53:     my ($courseid,$which,$path)=@_;
                     54:     my $dirptr=16384;
1.63      www        55:     unless ($which) { $which=''; } else { $which.='/'; }
                     56:     unless ($path)  { $path=''; } else { $path.='/'; }
1.28      www        57:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     58:     my @listing=&Apache::lonnet::dirlist
                     59: 	($which,$crsdata{'domain'},$crsdata{'num'},
1.39      albertel   60: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
1.28      www        61:     foreach (@listing) {
                     62: 	unless ($_=~/^\./) {
1.62      www        63: 	    my @unpackline = split (/\&/,$_);
                     64: 	    if ($unpackline[3]&$dirptr) {
                     65: # is a directory, recurse
1.63      www        66: 		&innercrsdirlist($courseid,$which.$unpackline[0],
                     67: 				            $path.$unpackline[0]);
1.62      www        68: 	    } else { 
                     69: # is a file, put into output
1.63      www        70: 		push (@output,$path.$unpackline[0]);
1.62      www        71: 	    }
1.28      www        72: 	}
                     73:     }
                     74:     return @output;
1.29      www        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 {
1.78      albertel   89:     (my $courseid, my $which,$env{'form.output'})=@_;
1.29      www        90:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     91:     return &Apache::lonnet::finishuserfileupload(
                     92: 					  $crsdata{'num'},$crsdata{'domain'},
                     93: 					  'output',$which);
                     94: }
                     95: 
1.36      www        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: 
1.29      www       109: # ============================================================= Copy a userfile
                    110: 
                    111: sub copyfile {
                    112:     my ($origcrsid,$newcrsid,$which)=@_;
1.36      www       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'}.'/'
1.66      albertel  124:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/',
                    125:        '/public/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
                    126:     => '/public/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
1.36      www       127:             )));
                    128:     }
1.30      www       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'});
1.72      albertel  140:     foreach my $key (keys(%data)) {
                    141: 	if ($key=~/^internal./) { delete($data{$key}); }
                    142:     }
1.30      www       143:     return &Apache::lonnet::put
                    144: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
                    145: }
                    146: 
1.35      www       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'};
1.85      albertel  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:     }
1.35      www       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:     }
1.37      www       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:     }
1.35      www       198: # adjust dates
                    199:     foreach (keys %data) {
                    200: 	my $thiskey=$_;
                    201: 	$thiskey=~s/^$origcrsid/$newcrsid/;
                    202: 	$newdata{$thiskey}=$data{$_};
1.75      albertel  203: 	if ($data{$_.'.type'}=~/^date_(start|end)$/) {
1.85      albertel  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: 	    }
1.35      www       211: 	}
                    212:     }
                    213:     return &Apache::lonnet::put
                    214: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
                    215: }
                    216: 
1.30      www       217: # ========================================================== Copy all userfiles
                    218: 
                    219: sub copyuserfiles {
                    220:     my ($origcrsid,$newcrsid)=@_;
                    221:     foreach (&crsdirlist($origcrsid,'userfiles')) {
1.69      albertel  222: 	if ($_ !~m|^scantron_|) {
                    223: 	    &copyfile($origcrsid,$newcrsid,$_);
                    224: 	}
1.30      www       225:     }
                    226: }
                    227: # ========================================================== Copy all userfiles
                    228: 
                    229: sub copydbfiles {
                    230:     my ($origcrsid,$newcrsid)=@_;
1.82      albertel  231: 
                    232:     my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|);
                    233:     $origcrs_discussion=~s|/|_|g;
1.30      www       234:     foreach (&crsdirlist($origcrsid)) {
                    235: 	if ($_=~/\.db$/) {
                    236: 	    unless 
1.84      albertel  237:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|(grading|review)queue|CODEs)/) {
1.30      www       238: 		 &copydb($origcrsid,$newcrsid,$_);
1.80      www       239: 		 my $histfile=$_;
                    240: 		 $histfile=~s/\.db$/\.hist/;
                    241: 		 &copyfile($origcrsid,$newcrsid,$histfile);
1.30      www       242: 	     }
                    243: 	}
                    244:     }
1.31      www       245: }
                    246: 
                    247: # ======================================================= Copy all course files
                    248: 
                    249: sub copycoursefiles {
                    250:     my ($origcrsid,$newcrsid)=@_;
                    251:     &copyuserfiles($origcrsid,$newcrsid);
                    252:     &copydbfiles($origcrsid,$newcrsid);
1.35      www       253:     &copyresourcedb($origcrsid,$newcrsid);
1.28      www       254: }
1.13      www       255: 
1.2       www       256: # ===================================================== Phase one: fill-in form
                    257: 
1.10      matthew   258: sub print_course_creation_page {
1.2       www       259:     my $r=shift;
1.78      albertel  260:     my $defdom=$env{'request.role.domain'};
1.10      matthew   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))) {
1.14      matthew   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>};
1.10      matthew   269:     }
                    270:     $course_home .= "\n</select>\n";
1.9       matthew   271:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.46      sakharuk  272:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
1.32      www       273:     my $cloneform=&Apache::loncommon::select_dom_form
1.78      albertel  274: 	($env{'request.role.domain'},'clonedomain').
1.32      www       275: 		     &Apache::loncommon::selectcourse_link
                    276: 		     ('ccrs','clonecourse','clonedomain');
1.78      albertel  277:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.43      raeburn   278:     my $starttime = time;
                    279:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.60      raeburn   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');
1.40      raeburn   282:     my ($krbdef,$krbdefdom) =
                    283:     &Apache::loncommon::get_kerberos_defaults($defdom);
1.41      raeburn   284:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
1.40      raeburn   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);
1.46      sakharuk  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",
1.65      raeburn   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",
1.46      sakharuk  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",
1.56      www       331: 		    'kaut' => 
                    332: 		    'Key authority (<tt>id@domain</tt>) if other than course',
1.46      sakharuk  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",
1.60      raeburn   343:                     'dacc' => "Default start and end dates for student access",
1.46      sakharuk  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?",
1.77      raeburn   348:                     'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
1.46      sakharuk  349:                     'irsp' => "Include retrieval of student photographs?",
1.55      www       350: 		    'rshm' => 'Resource Space Home',
1.46      sakharuk  351:                     'opco' => "Open Course"
                    352: 				       );
1.86    ! albertel  353:     my $js = <<END;
        !           354: <script type="text/javascript">
1.6       matthew   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 + '&';
1.7       matthew   364:     url += 'element=' + elementname + '&';
                    365:     url += 'only=sequence' + '';
1.6       matthew   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: }
1.41      raeburn   372: $javascript_validations
1.6       matthew   373: </script>
1.32      www       374: $coursebrowserjs
1.86    ! albertel  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
1.17      www       384: $helplink
1.6       matthew   385: <form action="/adm/createcourse" method="post" name="ccrs">
1.46      sakharuk  386: <h2>$lt{'cinf'}</h2>
1.10      matthew   387: <p>
1.68      matthew   388: <label><b>$lt{'ctit'}:</b>
                    389: <input type="text" size="50" name="title" /></label>
1.10      matthew   390: </p><p>
1.68      matthew   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>
1.40      raeburn   399: </p><p>
1.46      sakharuk  400: <h2>$lt{'iinf'}</h2>
1.40      raeburn   401: <p>
1.46      sakharuk  402: $lt{'stat'}
1.40      raeburn   403: </p><p>
1.68      matthew   404: <label>
                    405:     <b>$lt{'ccod'}</b>
                    406:     <input type="text" size="30" name="crscode" />
                    407: </label>
                    408: <br/>
1.46      sakharuk  409: ($lt{'toin'})
1.40      raeburn   410: </p><p>
1.68      matthew   411: <label>
                    412:     <b>$lt{'snid'}</b>
                    413:     <input type="text" size="30" name="crssections" />
                    414: </label>
                    415: <br/>
1.46      sakharuk  416: ($lt{'csli'})
1.40      raeburn   417: </p><p>
1.68      matthew   418: <label>
                    419:     <b>$lt{'crcs'}</b>
                    420:     <input type="text" size="30" name="crsxlist" />
                    421: </label>
                    422: <br/>
1.46      sakharuk  423: ($lt{'cscs'})
1.13      www       424: </p>
1.46      sakharuk  425: <h2>$lt{'crco'}</h2>
1.32      www       426: <table border="2">
1.46      sakharuk  427: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
1.32      www       428: <tr><td>
1.13      www       429: <p>
1.68      matthew   430: <label>
                    431:     <b>$lt{'map'}:</b>
                    432:     <input type="text" size="50" name="topmap" />
                    433: </label>
1.46      sakharuk  434: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
1.10      matthew   435: </p><p>
1.68      matthew   436: <label for="nonstd"><b>$lt{'sacr'}</b></label>
                    437: <br />
1.46      sakharuk  438: ($lt{'ocik'}):
1.68      matthew   439: <input id="nonstd" type="checkbox" name="nonstandard" />
                    440: </p><p>
1.46      sakharuk  441: <b>$lt{'fres'}</b><br />($lt{'stco'}):
1.68      matthew   442: <label>
                    443:     <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
                    444: </label>
1.13      www       445: &nbsp;
1.68      matthew   446: <label>
                    447:     <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
                    448: </label>
1.13      www       449: &nbsp;
1.68      matthew   450: <label>
                    451:     <input type="radio" name="firstres" value="nav" />$lt{'navi'}
                    452: </label>
1.13      www       453: </p>
1.32      www       454: </td><td>
1.68      matthew   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>
1.32      www       462: <br />
1.68      matthew   463: &nbsp;<br />
1.46      sakharuk  464: $lt{'asov'}.
1.32      www       465: </td></tr>
                    466: </table>
1.46      sakharuk  467: <h2>$lt{'assp'}</h2>
1.13      www       468: <p>
1.68      matthew   469: <label>
                    470:     <b>$lt{'oaas'}: </b>
                    471:     <input type="checkbox" name="openall" />
                    472: </label>
1.13      www       473: </p>
1.46      sakharuk  474: <h2>$lt{'mssg'}</h2>
1.13      www       475: <p>
1.68      matthew   476: <label>
                    477:     <b>$lt{'scpf'}: </b>
                    478:     <input type="checkbox" name="setpolicy" checked />
                    479: </label>
1.55      www       480: <br />
1.68      matthew   481: <label>
                    482:     <b>$lt{'scfc'}: </b>
                    483:     <input type="checkbox" name="setcontent" checked />
                    484: </label>
1.11      www       485: </p>
1.46      sakharuk  486: <h2>$lt{'cmmn'}</h2>
1.16      www       487: <p>
1.68      matthew   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>
1.16      www       497: </p>
1.46      sakharuk  498: <h2>$lt{'acco'}</h2>
1.18      www       499: <p>
1.68      matthew   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>
1.18      www       509: </p>
1.55      www       510: <h2>$lt{'rshm'}</h2>
                    511: <p>
1.68      matthew   512: <label>
                    513:     <b>$lt{'rshm'}: </b>
                    514:     <input type="text" name="reshome" size="30" value="/res/$defdom/" />
                    515: </label>
1.55      www       516: </p>
1.10      matthew   517: <p>
1.46      sakharuk  518: <h2>$lt{'aens'}</h2>
                    519: $lt{'aesc'}
1.40      raeburn   520: </p>
                    521: <p>
1.46      sakharuk  522: <b>$lt{'aadd'}</b>
1.68      matthew   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>
1.40      raeburn   526: </p><p>
1.46      sakharuk  527: <b>$lt{'audr'}</b>
1.68      matthew   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>
1.40      raeburn   530: </p><p>
1.46      sakharuk  531: <b>$lt{'dacu'}</b>
1.60      raeburn   532: $enroll_table
1.40      raeburn   533: </p><p>
1.60      raeburn   534: <b>$lt{'dacc'}</b>
                    535: $access_table
                    536: <p></p>
1.46      sakharuk  537: <b>$lt{'psam'}.</b><br />
                    538: $lt{'pcda'}.
1.40      raeburn   539: </p><p>
                    540: $krbform
                    541: <br />
                    542: $intform
                    543: <br />
                    544: $locform
                    545: </p><p>
1.46      sakharuk  546: <b>$lt{'nech'}</b><br />
                    547: $lt{'nccl'}<br/>
1.68      matthew   548: <label>
1.77      raeburn   549:     <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
1.68      matthew   550: </label> 
                    551: <label>
1.77      raeburn   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'}
1.68      matthew   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>
1.55      www       570: </p>
                    571: <hr />
                    572: <h2>$lt{'cc'}</h2>
                    573: <p>
1.68      matthew   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>
1.55      www       581: </p>
                    582: <p>
1.10      matthew   583: <input type="hidden" name="phase" value="two" />
1.68      matthew   584: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
1.10      matthew   585: </p>
1.2       www       586: </form>
1.86    ! albertel  587: $end_page
1.2       www       588: ENDDOCUMENT
1.40      raeburn   589: }
                    590: 
1.2       www       591: # ====================================================== Phase two: make course
                    592: 
1.10      matthew   593: sub create_course {
1.2       www       594:     my $r=shift;
1.78      albertel  595:     my $ccuname=$env{'form.ccuname'};
                    596:     my $ccdomain=$env{'form.ccdomain'};
1.2       www       597:     $ccuname=~s/\W//g;
                    598:     $ccdomain=~s/\W//g;
1.74      raeburn   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: 
1.78      albertel  608:     if ($env{'form.login'} eq 'krb') {
1.74      raeburn   609:         $authtype = 'krb';
1.78      albertel  610:         $authtype .=$env{'form.krbver'};
                    611:         $autharg = $env{'form.krbarg'};
                    612:     } elsif ($env{'form.login'} eq 'int') {
1.74      raeburn   613:         $authtype ='internal';
1.78      albertel  614:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
                    615:             $autharg = $env{'form.intarg'};
1.74      raeburn   616:         }
1.78      albertel  617:     } elsif ($env{'form.login'} eq 'loc') {
1.74      raeburn   618:         $authtype = 'localauth';
1.78      albertel  619:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                    620:             $autharg = $env{'form.locarg'};
1.74      raeburn   621:         }
                    622:     }
                    623: 
                    624:     my $logmsg;
1.86    ! albertel  625:     my $start_page=&Apache::loncommon::start_page('Create a New Course');
        !           626:     $r->print($start_page);
1.74      raeburn   627: 
                    628:     my $args = {
                    629:                ccuname => $ccuname,
                    630:                ccdomain => $ccdomain,
1.78      albertel  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'},
1.74      raeburn   649:                authtype => $authtype,
                    650:                autharg => $autharg,
                    651:                enrollstart => $enrollstart,
                    652:                enrollend => $enrollend,
                    653:                startaccess => $startaccess,
                    654:                endaccess => $endaccess,
1.78      albertel  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'}
1.74      raeburn   664:                };
                    665: 
1.10      matthew   666:     #
                    667:     # Verify data
                    668:     #
                    669:     # Check the veracity of the course coordinator
1.2       www       670:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52      albertel  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').'" />
1.86    ! albertel  680: 	</form>'.&Apache::loncommon::end_page());
1.2       www       681: 	return;
                    682:     }
1.10      matthew   683:     # Check the proposed home server for the course
                    684:     my %host_servers = &Apache::loncommon::get_library_servers
1.78      albertel  685:         ($env{'request.role.domain'});
                    686:     if (! exists($host_servers{$env{'form.course_home'}})) {
1.46      sakharuk  687:         $r->print(&mt('Invalid home server for course').': '.
1.86    ! albertel  688:                   $env{'form.course_home'}.&Apache::loncommon::end_page());
1.10      matthew   689:         return;
                    690:     }
1.74      raeburn   691:     my ($courseid,$crsudom,$crsunum);
1.78      albertel  692:     $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
1.74      raeburn   693: 
                    694: #
1.77      raeburn   695: # Make the requested user a course coordinator
1.74      raeburn   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:    }
1.78      albertel  702:     if ($env{'form.setkeys'}) {
1.74      raeburn   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();
1.86    ! albertel  708:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
        !           709: 	      &Apache::loncommon::end_page());
1.74      raeburn   710: }
                    711: 
                    712: sub construct_course {
1.77      raeburn   713:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
1.74      raeburn   714:     my $outcome;
                    715: 
1.2       www       716: #
                    717: # Open course
                    718: #
1.32      www       719:     my %cenv=();
1.74      raeburn   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'});
1.2       www       727: 
1.27      bowersj2  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.
1.74      raeburn   732:     $outcome .= 'New LON-CAPA Course ID: '.$$courseid.'<br>';
1.4       www       733: #
1.12      www       734: # Check if created correctly
1.4       www       735: #
1.74      raeburn   736:     ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);
                    737:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
                    738:     $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
1.12      www       739: #
1.32      www       740: # Are we cloning?
                    741: #
                    742:     my $cloneid='';
1.74      raeburn   743:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
                    744: 	$cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
1.32      www       745:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
                    746: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                    747: 	if ($clonehome eq 'no_host') {
1.74      raeburn   748: 	    $outcome .=
                    749:     '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>';
1.32      www       750: 	} else {
1.74      raeburn   751: 	    $outcome .= 
                    752:     '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>';
                    753: 	    my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.32      www       754: # Copy all files
1.74      raeburn   755: 	    &copycoursefiles($cloneid,$$courseid);
1.37      www       756: # Restore URL
                    757: 	    $cenv{'url'}=$oldcenv{'url'};
1.32      www       758: # Restore title
1.37      www       759: 	    $cenv{'description'}=$oldcenv{'description'};
1.67      albertel  760: # restore grading mode
                    761: 	    if (defined($oldcenv{'grading'})) {
                    762: 		$cenv{'grading'}=$oldcenv{'grading'};
                    763: 	    }
1.37      www       764: # Mark as cloned
1.35      www       765: 	    $cenv{'clonedfrom'}=$cloneid;
1.54      albertel  766: 	    delete($cenv{'default_enrollment_start_date'});
                    767: 	    delete($cenv{'default_enrollment_end_date'});
1.32      www       768: 	}
                    769:     }
                    770: #
                    771: # Set environment (will override cloned, if existing)
1.12      www       772: #
1.64      raeburn   773:     my @sections = ();
                    774:     my @xlists = ();
1.74      raeburn   775:     if ($args->{'crsid'}) {
                    776:         $cenv{'courseid'}=$args->{'crsid'};
1.40      raeburn   777:     }
1.74      raeburn   778:     if ($args->{'crscode'}) {
                    779:         $cenv{'internal.coursecode'}=$args->{'crscode'};
1.40      raeburn   780:     }
1.74      raeburn   781:     if ($args->{'ccuname'}) {
                    782:         $cenv{'internal.courseowner'} = $args->{'ccuname'};
1.64      raeburn   783:     } else {
1.74      raeburn   784:         $cenv{'internal.courseowner'} = $args->{'curruser'};
1.64      raeburn   785:     }
                    786: 
                    787:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.74      raeburn   788:     if ($args->{'crssections'}) {
1.64      raeburn   789:         $cenv{'internal.sectionnums'} = '';
1.74      raeburn   790:         if ($args->{'crssections'} =~ m/,/) {
                    791:             @sections = split/,/,$args->{'crssections'};
1.44      raeburn   792:         } else {
1.74      raeburn   793:             $sections[0] = $args->{'crssections'};
1.44      raeburn   794:         }
                    795:         if (@sections > 0) {
1.64      raeburn   796:             foreach my $item (@sections) {
                    797:                 my ($sec,$gp) = split/:/,$item;
1.74      raeburn   798:                 my $class = $args->{'crscode'}.$sec;
1.81      raeburn   799:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
1.73      raeburn   800:                 $cenv{'internal.sectionnums'} .= $item.',';
                    801:                 unless ($addcheck eq 'ok') {
1.64      raeburn   802:                     push @badclasses, $class;
                    803:                 }
1.44      raeburn   804:             }
1.64      raeburn   805:             $cenv{'internal.sectionnums'} =~ s/,$//;
1.44      raeburn   806:         }
1.40      raeburn   807:     }
1.49      www       808: # do not hide course coordinator from staff listing, 
                    809: # even if privileged
1.74      raeburn   810:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                    811: # add crosslistings
                    812:     if ($args->{'crsxlist'}) {
1.64      raeburn   813:         $cenv{'internal.crosslistings'}='';
1.74      raeburn   814:         if ($args->{'crsxlist'} =~ m/,/) {
                    815:             @xlists = split/,/,$args->{'crsxlist'};
1.44      raeburn   816:         } else {
1.74      raeburn   817:             $xlists[0] = $args->{'crsxlist'};
1.44      raeburn   818:         }
                    819:         if (@xlists > 0) {
1.64      raeburn   820:             foreach my $item (@xlists) {
                    821:                 my ($xl,$gp) = split/:/,$item;
1.74      raeburn   822:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
1.73      raeburn   823:                 $cenv{'internal.crosslistings'} .= $item.',';
                    824:                 unless ($addcheck eq 'ok') {
1.64      raeburn   825:                     push @badclasses, $xl;
                    826:                 }
1.44      raeburn   827:             }
1.64      raeburn   828:             $cenv{'internal.crosslistings'} =~ s/,$//;
1.44      raeburn   829:         }
1.40      raeburn   830:     }
1.74      raeburn   831:     if ($args->{'autoadds'}) {
                    832:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
1.40      raeburn   833:     }
1.74      raeburn   834:     if ($args->{'autodrops'}) {
                    835:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
1.40      raeburn   836:     }
1.77      raeburn   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;
1.40      raeburn   857:     }
1.64      raeburn   858:     if (@badclasses > 0) {
                    859:         my %lt=&Apache::lonlocal::texthash(
1.73      raeburn   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',
1.64      raeburn   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:         );
1.74      raeburn   864:         $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
1.64      raeburn   865:         foreach (@badclasses) {
1.74      raeburn   866:             $outcome .= "<li>$_</li>\n";
1.44      raeburn   867:         }
1.74      raeburn   868:         $outcome .= "</ul><br /><br /></font>\n";
1.40      raeburn   869:     }
1.74      raeburn   870:     if ($args->{'no_end_date'}) {
                    871:         $args->{'endaccess'} = 0;
1.40      raeburn   872:     }
1.74      raeburn   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'};
1.40      raeburn   879:     }
1.74      raeburn   880:     $cenv{'internal.authtype'} = $args->{'authtype'};
                    881:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
1.40      raeburn   882:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                    883:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.74      raeburn   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>';
1.40      raeburn   886:         }
1.12      www       887:     }
1.74      raeburn   888:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                    889:        if ($args->{'setpolicy'}) {
                    890:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.12      www       891:        }
1.74      raeburn   892:        if ($args->{'setcontent'}) {
                    893:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.18      www       894:        }
1.55      www       895:     }
1.74      raeburn   896:     if ($args->{'reshome'}) {
                    897: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
1.55      www       898: 	$cenv{'reshome'}=~s/\/+$/\//;
1.18      www       899:     }
1.56      www       900: #
                    901: # course has keyed access
                    902: #
1.74      raeburn   903:     if ($args->{'setkeys'}) {
1.18      www       904:        $cenv{'keyaccess'}='yes';
1.16      www       905:     }
1.56      www       906: # if specified, key authority is not course, but user
                    907: # only active if keyaccess is yes
1.74      raeburn   908:     if ($args->{'keyauth'}) {
                    909: 	$args->{'keyauth'}=~s/[^\w\@]//g;
                    910: 	if ($args->{'keyauth'}) {
                    911: 	    $cenv{'keyauth'}=$args->{'keyauth'};
1.56      www       912: 	}
                    913:     }
                    914: 
1.74      raeburn   915:     if ($args->{'disresdis'}) {
1.16      www       916:         $cenv{'pch.roles.denied'}='st';
1.26      matthew   917:     }
1.74      raeburn   918:     if ($args->{'disablechat'}) {
1.26      matthew   919:         $cenv{'plc.roles.denied'}='st';
1.21      albertel  920:     }
1.23      bowersj2  921: 
1.32      www       922:     # Record we've not yet viewed the Course Initialization Helper for this 
                    923:     # course
1.23      bowersj2  924:     $cenv{'course.helper.not.run'} = 1;
1.21      albertel  925:     #
                    926:     # Use new Randomseed
                    927:     #
1.22      albertel  928:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.51      albertel  929:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
1.53      www       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));
1.25      matthew   935:     #
                    936:     # By default, use standard grading
1.67      albertel  937:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
1.22      albertel  938: 
1.74      raeburn   939:     $outcome .= ('<br />'.&mt('Setting environment').': '.                 
                    940:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
1.12      www       941: #
                    942: # Open all assignments
                    943: #
1.74      raeburn   944:     if ($args->{'openall'}) {
                    945:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.33      www       946:        my %storecontent = ($storeunder         => time,
                    947:                            $storeunder.'.type' => 'date_start');
1.12      www       948:        
1.74      raeburn   949:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
                    950:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
1.12      www       951:    }
1.13      www       952: #
                    953: # Set first page
                    954: #
1.74      raeburn   955:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
1.48      www       956: 	    || ($cloneid)) {
1.74      raeburn   957: 	$outcome .= &mt('Setting first resource').': ';
1.13      www       958:         my ($errtext,$fatal)=
1.74      raeburn   959:            &Apache::londocs::mapread($$crsunum,$$crsudom,'default.sequence');
                    960:         $outcome .= ($fatal?$errtext:'read ok').' - ';
1.13      www       961:         my $title; my $url;
1.74      raeburn   962:         if ($args->{'firstres'} eq 'syl') {
1.13      www       963: 	    $title='Syllabus';
1.74      raeburn   964:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
1.13      www       965:         } else {
                    966:             $title='Navigate Contents';
                    967:             $url='/adm/navmaps';
                    968:         }
                    969:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15      albertel  970:         ($errtext,$fatal)=
1.74      raeburn   971:            &Apache::londocs::storemap($$crsunum,$$crsudom,'default.sequence');
                    972:         $outcome .= ($fatal?$errtext:'write ok').'<br>';
1.20      www       973:     }
1.74      raeburn   974:     return $outcome;
1.2       www       975: }
                    976: 
                    977: # ===================================================================== Handler
1.1       www       978: sub handler {
                    979:     my $r = shift;
                    980: 
                    981:     if ($r->header_only) {
1.38      www       982:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       983:        $r->send_http_header;
                    984:        return OK;
                    985:     }
                    986: 
1.78      albertel  987:     if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.38      www       988:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       989:        $r->send_http_header;
                    990: 
1.78      albertel  991:        if ($env{'form.phase'} eq 'two') {
1.10      matthew   992:            &create_course($r);
1.2       www       993:        } else {
1.10      matthew   994: 	   &print_course_creation_page($r);
1.2       www       995:        }
1.1       www       996:    } else {
1.78      albertel  997:       $env{'user.error.msg'}=
1.1       www       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>