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

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

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