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

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

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