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

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

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