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

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

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