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

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

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