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

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

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