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

1.58      raeburn     1: #meserver The LearningOnline Network
1.1       www         2: # Create a course
1.5       albertel    3: #
1.59    ! raeburn     4: # $Id: loncreatecourse.pm,v 1.58 2004/06/08 22:09:44 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
                    241:     my $date_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'createcourse');
1.40      raeburn   242:     my ($krbdef,$krbdefdom) =
                    243:     &Apache::loncommon::get_kerberos_defaults($defdom);
1.41      raeburn   244:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
1.40      raeburn   245:     my %param = ( formname => 'document.ccrs',
                    246:                    kerb_def_dom => $krbdefdom,
                    247:                    kerb_def_auth => $krbdef
                    248:                 );
                    249:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    250:     my $intform = &Apache::loncommon::authform_internal(%param);
                    251:     my $locform = &Apache::loncommon::authform_local(%param);
1.46      sakharuk  252:     my %lt=&Apache::lonlocal::texthash(
                    253: 		    'cinf' => "Course Information",
                    254:                     'ctit' => "Course Title",
                    255:                     'chsr' => "Course Home Server",
                    256:                     'cidn' => "Course ID/Number",
                    257:                     'opt'  => "optional",
                    258:                     'iinf' => "Institutional Information",
                    259:                     '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.",
                    260:                     'ccod' => "Course Code",
                    261:                     'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
                    262:                     'snid' => "Section Numbers and corresponding LON-CAPA section/group IDs",
                    263:                     '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",
                    264:                     'crcs' => "Crosslisted courses",
                    265:                     '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", 
                    266:                     'crco' => "Course Content",
                    267:                     'cncr' => "Completely new course",
                    268:                     'cecr' => "Clone an existing course", 
                    269:                     'map'  => "Map",
                    270:                     'smap' => "Select Map",
                    271:                     'sacr' => "Do NOT generate as standard course",
                    272:                     'ocik' => "only check if you know what you are doing",
                    273:                     'fres' => "First Resource",
                    274:                     'stco' => "standard courses only",
                    275:                     'blnk' => "Blank",
                    276:                     'sllb' => "Syllabus",
                    277:                     'navi' => "Navigate",
                    278:                     'cid'  => "Course ID",
                    279:                     'dmn'  => "Domain",
                    280:                     'asov' => "Additional settings, if specified below, will override cloned settings",
                    281:                     'assp' => "Assessment Parameters",
                    282:                     'oaas' => "Open all assessments",
                    283:                     'mssg' => "Messaging",
                    284:                     'scpf' => "Set course policy feedback to Course Coordinator",
                    285:                     'scfc' => "Set content feedback to Course Coordinator",
                    286:                     'cmmn' => "Communication",
                    287:                     'dsrd' => "Disable student resource discussion",
                    288:                     'dsuc' => "Disable student use of chatrooms",
                    289:                     'acco' => "Access Control",
                    290:                     'snak' => "Students need access key to enter course",
1.56      www       291: 		    'kaut' => 
                    292: 		    'Key authority (<tt>id@domain</tt>) if other than course',
1.46      sakharuk  293:                     'cc'   => "Course Coordinator",
                    294:                     'user' => "Username",
                    295:                     'ierc' => "Immediately expire own role as Course Coordinator",
                    296:                     'aens' => "Automated enrollment settings",
                    297:                     '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.",
                    298:                     'aadd' => "Automated adds",
                    299:                     'yes'  => "Yes",
                    300:                     'no'   => "No",
                    301:                     'audr' => "Automated drops",
                    302:                     'dacu' => "Duration of automated classlist updates",
                    303:                     'psam' => "Please select the authentication mechanism",
                    304:                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
                    305:                     'nech' => "Notification of enrollment changes",
                    306:                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
                    307:                     'irsp' => "Include retrieval of student photographs?",
1.55      www       308: 		    'rshm' => 'Resource Space Home',
1.46      sakharuk  309:                     'opco' => "Open Course"
                    310: 				       );
1.2       www       311:     $r->print(<<ENDDOCUMENT);
                    312: <html>
1.6       matthew   313: <script language="JavaScript" type="text/javascript">
                    314: var editbrowser = null;
                    315: function openbrowser(formname,elementname) {
                    316:     var url = '/res/?';
                    317:     if (editbrowser == null) {
                    318:         url += 'launch=1&';
                    319:     }
                    320:     url += 'catalogmode=interactive&';
                    321:     url += 'mode=edit&';
                    322:     url += 'form=' + formname + '&';
1.7       matthew   323:     url += 'element=' + elementname + '&';
                    324:     url += 'only=sequence' + '';
1.6       matthew   325:     var title = 'Browser';
                    326:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    327:     options += ',width=700,height=600';
                    328:     editbrowser = open(url,title,options,'1');
                    329:     editbrowser.focus();
                    330: }
1.41      raeburn   331: $javascript_validations
1.6       matthew   332: </script>
1.32      www       333: $coursebrowserjs
1.2       www       334: <head>
                    335: <title>The LearningOnline Network with CAPA</title>
                    336: </head>
1.12      www       337: $bodytag
1.17      www       338: $helplink
1.6       matthew   339: <form action="/adm/createcourse" method="post" name="ccrs">
1.46      sakharuk  340: <h2>$lt{'cinf'}</h2>
1.10      matthew   341: <p>
1.46      sakharuk  342: <b>$lt{'ctit'}:</b>
1.6       matthew   343: <input type="text" size="50" name="title">
1.10      matthew   344: </p><p>
1.46      sakharuk  345: <b>$lt{'chsr'}:</b>$course_home
1.13      www       346: </p><p>
1.46      sakharuk  347: <b>$lt{'cidn'} ($lt{'opt'})</b>
1.13      www       348: <input type="text" size="30" name="crsid">
1.40      raeburn   349: </p><p>
1.46      sakharuk  350: <h2>$lt{'iinf'}</h2>
1.40      raeburn   351: <p>
1.46      sakharuk  352: $lt{'stat'}
1.40      raeburn   353: </p><p>
1.46      sakharuk  354: <b>$lt{'ccod'}</b>
1.40      raeburn   355: <input type="text" size="30" name="crscode" /><br/>
1.46      sakharuk  356: ($lt{'toin'})
1.40      raeburn   357: </p><p>
1.46      sakharuk  358: <b>$lt{'snid'}</b>
1.40      raeburn   359:  <input type="text" size="30" name="crssections" /><br/>
1.46      sakharuk  360: ($lt{'csli'})
1.40      raeburn   361: </p><p>
1.46      sakharuk  362: <b>$lt{'crcs'}</b>
1.40      raeburn   363: <input type="text" size="30" name="crsxlist" /><br/>
1.46      sakharuk  364: ($lt{'cscs'})
1.13      www       365: </p>
1.46      sakharuk  366: <h2>$lt{'crco'}</h2>
1.32      www       367: <table border="2">
1.46      sakharuk  368: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
1.32      www       369: <tr><td>
1.13      www       370: <p>
1.46      sakharuk  371: <b>$lt{'map'}:</b>
1.6       matthew   372: <input type="text" size="50" name="topmap">
1.46      sakharuk  373: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
1.10      matthew   374: </p><p>
1.46      sakharuk  375: <b>$lt{'sacr'}</b><br /> 
                    376: ($lt{'ocik'}):
1.11      www       377: <input type="checkbox" name="nonstandard">
1.13      www       378: </p>
                    379: <p>
1.46      sakharuk  380: <b>$lt{'fres'}</b><br />($lt{'stco'}):
                    381: <input type="radio" name="firstres" value="blank">$lt{'blnk'}
1.13      www       382: &nbsp;
1.46      sakharuk  383: <input type="radio" name="firstres" value="syl" checked>$lt{'sllb'}
1.13      www       384: &nbsp;
1.46      sakharuk  385: <input type="radio" name="firstres" value="nav">$lt{'navi'}
1.13      www       386: </p>
1.32      www       387: </td><td>
1.46      sakharuk  388: $lt{'cid'}: <input input type="text" size="25" name="clonecourse" value="" />
1.32      www       389: <br />
1.46      sakharuk  390: $lt{'dmn'}: 
1.32      www       391: $cloneform<br />&nbsp;<br />
1.46      sakharuk  392: $lt{'asov'}.
1.32      www       393: </td></tr>
                    394: </table>
1.46      sakharuk  395: <h2>$lt{'assp'}</h2>
1.13      www       396: <p>
1.46      sakharuk  397: <b>$lt{'oaas'}: </b>
1.50      www       398: <input type="checkbox" name="openall" />
1.13      www       399: </p>
1.46      sakharuk  400: <h2>$lt{'mssg'}</h2>
1.13      www       401: <p>
1.46      sakharuk  402: <b>$lt{'scpf'}: </b>
1.11      www       403: <input type="checkbox" name="setpolicy" checked>
1.55      www       404: <br />
1.46      sakharuk  405: <b>$lt{'scfc'}: </b>
1.11      www       406: <input type="checkbox" name="setcontent" checked>
                    407: </p>
1.46      sakharuk  408: <h2>$lt{'cmmn'}</h2>
1.16      www       409: <p>
1.46      sakharuk  410: <b>$lt{'dsrd'}: </b>
1.26      matthew   411: <input type="checkbox" name="disresdis" /> <br />
1.46      sakharuk  412: <b>$lt{'dsuc'}: </b>
1.26      matthew   413: <input type="checkbox" name="disablechat" />
1.16      www       414: </p>
1.46      sakharuk  415: <h2>$lt{'acco'}</h2>
1.18      www       416: <p>
1.46      sakharuk  417: <b>$lt{'snak'}: </b>
1.56      www       418: <input type="checkbox" name="setkeys" /><br />
                    419: <b>$lt{'kaut'}: </b>
                    420: <input type="text" size="30" name="keyauth" />
1.18      www       421: </p>
1.55      www       422: <h2>$lt{'rshm'}</h2>
                    423: <p>
                    424: <b>$lt{'rshm'}: </b>
                    425: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
                    426: </p>
1.10      matthew   427: <p>
1.46      sakharuk  428: <h2>$lt{'aens'}</h2>
                    429: $lt{'aesc'}
1.40      raeburn   430: </p>
                    431: <p>
1.46      sakharuk  432: <b>$lt{'aadd'}</b>
                    433: <input type="radio" name="autoadds" value="1" />$lt{'yes'} <input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
1.40      raeburn   434: </p><p>
1.46      sakharuk  435: <b>$lt{'audr'}</b>
                    436: <input type="radio" name="autodrops" value="1" />$lt{'yes'} <input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}
1.40      raeburn   437: </p><p>
1.46      sakharuk  438: <b>$lt{'dacu'}</b>
1.40      raeburn   439: $date_table
                    440: </p><p>
1.46      sakharuk  441: <b>$lt{'psam'}.</b><br />
                    442: $lt{'pcda'}.
1.40      raeburn   443: </p><p>
                    444: $krbform
                    445: <br />
                    446: $intform
                    447: <br />
                    448: $locform
                    449: </p><p>
1.46      sakharuk  450: <b>$lt{'nech'}</b><br />
                    451: $lt{'nccl'}<br/>
                    452: <input type="radio" name="notify" value="1" />$lt{'yes'} <input type="radio" name="notify"
                    453: value="0" checked="true" />$lt{'no'}
1.40      raeburn   454: </p><p>
1.46      sakharuk  455: <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       456: </p>
                    457: <hr />
                    458: <h2>$lt{'cc'}</h2>
                    459: <p>
                    460: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
                    461: </p><p>
                    462: <b>$lt{'dmn'}:</b> $domform
1.40      raeburn   463: </p><p>
1.55      www       464: <b>$lt{'ierc'}:</b>
                    465: <input type="checkbox" name="expireown" checked>
                    466: </p>
                    467: <p>
1.10      matthew   468: <input type="hidden" name="phase" value="two" />
1.46      sakharuk  469: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}">
1.10      matthew   470: </p>
1.2       www       471: </form>
                    472: </body>
                    473: </html>
                    474: ENDDOCUMENT
1.40      raeburn   475: }
                    476: 
1.2       www       477: # ====================================================== Phase two: make course
                    478: 
1.10      matthew   479: sub create_course {
1.2       www       480:     my $r=shift;
                    481:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
1.58      raeburn   482:     my $this_server = $Apache::lonnet::perlvar{'lonHostID'};
1.2       www       483:     my $ccuname=$ENV{'form.ccuname'};
                    484:     my $ccdomain=$ENV{'form.ccdomain'};
                    485:     $ccuname=~s/\W//g;
                    486:     $ccdomain=~s/\W//g;
                    487:     my $cdescr=$ENV{'form.title'};
                    488:     my $curl=$ENV{'form.topmap'};
1.12      www       489:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2       www       490:     $r->print(<<ENDENHEAD);
                    491: <html>
                    492: <head>
                    493: <title>The LearningOnline Network with CAPA</title>
                    494: </head>
1.12      www       495: $bodytag
1.2       www       496: ENDENHEAD
1.10      matthew   497:     #
                    498:     # Verify data
                    499:     #
                    500:     # Check the veracity of the course coordinator
1.2       www       501:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52      albertel  502: 	$r->print('<form action="/adm/createuser" method="post" name="crtuser">');
                    503:         $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
                    504: 	$r->print(&mt("Please click Back on your browser and select another user, or "));
                    505: 	$r->print('
                    506: 	    <input type="hidden" name="phase" value="get_user_info" />
                    507:             <input type="hidden" name="ccuname" value="'.$ccuname.'" />
                    508:             <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
                    509:             <input name="userrole" type="submit" value="'.
                    510: 		  &mt('Create User').'" />
                    511: 	</form></body></html>');
1.2       www       512: 	return;
                    513:     }
1.10      matthew   514:     # Check the proposed home server for the course
                    515:     my %host_servers = &Apache::loncommon::get_library_servers
                    516:         ($ENV{'request.role.domain'});
                    517:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
1.46      sakharuk  518:         $r->print(&mt('Invalid home server for course').': '.
1.10      matthew   519:                   $ENV{'form.course_home'}.'</body></html>');
                    520:         return;
                    521:     }
1.2       www       522: #
                    523: # Open course
                    524: #
1.32      www       525:     my %cenv=();
1.10      matthew   526:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
                    527:                                                $cdescr,$curl,
1.11      www       528:                                                $ENV{'form.course_home'},
                    529:                                                $ENV{'form.nonstandard'});
1.2       www       530: 
1.27      bowersj2  531:     # Note: The testing routines depend on this being output; see 
                    532:     # Utils::Course. This needs to at least be output as a comment
                    533:     # if anyone ever decides to not show this, and Utils::Course::new
                    534:     # will need to be suitably modified.
1.4       www       535:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    536: #
1.12      www       537: # Check if created correctly
1.4       www       538: #
                    539:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    540:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
1.46      sakharuk  541:     $r->print(&mt('Created on').': '.$crsuhome.'<br>');
1.12      www       542: #
1.32      www       543: # Are we cloning?
                    544: #
                    545:     my $cloneid='';
                    546:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
                    547: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
                    548:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
                    549: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                    550: 	if ($clonehome eq 'no_host') {
                    551: 	    $r->print(
1.46      sakharuk  552:     '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>');
1.32      www       553: 	} else {
                    554: 	    $r->print(
1.46      sakharuk  555:     '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>');
1.37      www       556: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
1.32      www       557: # Copy all files
                    558: 	    &copycoursefiles($cloneid,$courseid);
1.37      www       559: # Restore URL
                    560: 	    $cenv{'url'}=$oldcenv{'url'};
1.32      www       561: # Restore title
1.37      www       562: 	    $cenv{'description'}=$oldcenv{'description'};
                    563: # Mark as cloned
1.35      www       564: 	    $cenv{'clonedfrom'}=$cloneid;
1.54      albertel  565: 	    delete($cenv{'default_enrollment_start_date'});
                    566: 	    delete($cenv{'default_enrollment_end_date'});
1.32      www       567: 	}
                    568:     }
                    569: #
                    570: # Set environment (will override cloned, if existing)
1.12      www       571: #
1.44      raeburn   572:     my @affiliates = ();  # Used to accumulate sections and crosslistings
1.4       www       573:     if ($ENV{'form.crsid'}) {
1.12      www       574:         $cenv{'courseid'}=$ENV{'form.crsid'};
1.40      raeburn   575:     }
                    576:     if ($ENV{'form.crscode'}) {
                    577:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
                    578:     }
                    579:     if ($ENV{'form.crssections'}) {
                    580:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
1.44      raeburn   581:         my @sections = ();
                    582:         if ($cenv{'internal.sectionnums'} =~ m/,/) {
                    583:             @sections = split/,/,$cenv{'internal.sectionnums'};
                    584:         } else {
                    585:             $sections[0] = $cenv{'internal.sectionnums'};
                    586:         }
                    587:         if (@sections > 0) {
                    588:             foreach (@sections) {
                    589:                 my ($sec,$gp) = split/:/,$_; 
                    590:                 push @affiliates,$ENV{'form.crscode'}.$sec;
                    591:             }
                    592:         }
1.40      raeburn   593:     }
1.49      www       594: # do not hide course coordinator from staff listing, 
                    595: # even if privileged
                    596:     $cenv{'nothideprivileged'}=$ccuname.':'.$ccdomain;
1.40      raeburn   597:     if ($ENV{'form.crsxlist'}) {
1.44      raeburn   598:        $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
                    599:        my @xlists = ();
                    600:         if ($cenv{'internal.crosslistings'} =~ m/,/) {
                    601:             @xlists = split/,/,$cenv{'internal.crosslistings'};
                    602:         } else {
                    603:             $xlists[0] = $cenv{'internal.crosslistings'};
                    604:         }
                    605:         if (@xlists > 0) {
                    606:             foreach (@xlists) {
                    607:                 my ($xl,$gp) = split/:/,$_;
                    608:                 push @affiliates,$xl;
                    609:             }
                    610:         }
1.40      raeburn   611:     }
                    612:     if ($ENV{'form.autoadds'}) {
                    613:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
                    614:     }
                    615:     if ($ENV{'form.autodrops'}) {
                    616:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
                    617:     }
                    618:     if ($ENV{'form.notify'}) {
                    619:       if ($ccuname) {
                    620:         $cenv{'internal.notifylist'} = $ccuname;
                    621:       }
                    622:     }
                    623:     if ($ccuname) {
                    624:         $cenv{'internal.courseowner'} = $ccuname;
1.44      raeburn   625:     } else {
                    626:         $cenv{'internal.courseowner'} = $ENV{'user.name'};
                    627:     }
                    628:     if (@affiliates > 0) {
                    629:         my @badclasses = ();
                    630:         foreach my $class (@affiliates) {
1.59    ! raeburn   631:             my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$class,$cenv{'internal.courseowner'});
1.44      raeburn   632:             unless ($addcheck eq 'ok') {
                    633:                 push @badclasses, $class; 
                    634:             }
                    635:         }
                    636:         if (@badclasses > 0) {
                    637:             $r->print('<font color="red">'.
                    638:                       "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");
                    639:             foreach (@badclasses) {
                    640:                 $r->print("<li>$_</li>\n");
                    641:             }
                    642:             $r->print ("</ul><br/><br/></font>\n");
                    643:         }
1.40      raeburn   644:     }
                    645:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                    646:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                    647:     if ($ENV{'form.no_end_date'}) {
                    648:       $enddate = 0;
                    649:     }
                    650:     $cenv{'internal.autostart'}=$startdate;
                    651:     $cenv{'internal.autoend'}=$enddate;
                    652:     if ($ENV{'form.showphotos'}) {
                    653:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
                    654:     }
                    655:     if ($ENV{'form.login'} eq 'krb') {
                    656:         $cenv{'internal.authtype'} = 'krb';
                    657:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
                    658:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
                    659:     } elsif ($ENV{'form.login'} eq 'int') {
                    660:         $cenv{'internal.authtype'} ='internal';
                    661:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                    662:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
                    663:         }
                    664:     } elsif ($ENV{'form.login'} eq 'loc') {
                    665:         $cenv{'internal.authtype'} = 'localauth';
                    666:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                    667:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
                    668:         }
                    669:     }
                    670:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                    671:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
                    672:             $r->print('<font color="red" size="+1">'.
1.46      sakharuk  673:                       &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   674:         }
1.12      www       675:     }
                    676:     if (($ccdomain) && ($ccuname)) {
                    677:        if ($ENV{'form.setpolicy'}) {
                    678:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
                    679:        }
                    680:        if ($ENV{'form.setcontent'}) {
1.18      www       681:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
                    682:        }
1.55      www       683:     }
                    684:     if ($ENV{'form.reshome'}) {
                    685: 	$cenv{'reshome'}=$ENV{'form.reshome'}.'/';
                    686: 	$cenv{'reshome'}=~s/\/+$/\//;
1.18      www       687:     }
1.56      www       688: #
                    689: # course has keyed access
                    690: #
1.18      www       691:     if ($ENV{'form.setkeys'}) {
                    692:        $cenv{'keyaccess'}='yes';
1.16      www       693:     }
1.56      www       694: # if specified, key authority is not course, but user
                    695: # only active if keyaccess is yes
                    696:     if ($ENV{'form.keyauth'}) {
                    697: 	$ENV{'form.keyauth'}=~s/[^\w\@]//g;
                    698: 	if ($ENV{'form.keyauth'}) {
                    699: 	    $cenv{'keyauth'}=$ENV{'form.keyauth'};
                    700: 	}
                    701:     }
                    702: 
1.16      www       703:     if ($ENV{'form.disresdis'}) {
                    704:         $cenv{'pch.roles.denied'}='st';
1.26      matthew   705:     }
                    706:     if ($ENV{'form.disablechat'}) {
                    707:         $cenv{'plc.roles.denied'}='st';
1.21      albertel  708:     }
1.23      bowersj2  709: 
1.32      www       710:     # Record we've not yet viewed the Course Initialization Helper for this 
                    711:     # course
1.23      bowersj2  712:     $cenv{'course.helper.not.run'} = 1;
1.21      albertel  713:     #
                    714:     # Use new Randomseed
                    715:     #
1.22      albertel  716:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.51      albertel  717:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
1.53      www       718:     #
                    719:     # The encryption code and receipt prefix for this course
                    720:     #
                    721:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                    722:     $cenv{'internal.encpref'}=100+int(9*rand(99));
1.25      matthew   723:     #
                    724:     # By default, use standard grading
                    725:     $cenv{'grading'} = 'standard';
1.22      albertel  726: 
1.46      sakharuk  727:     $r->print('<br />'.&mt('Setting environment').': '.                 
1.12      www       728:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
                    729: #
                    730: # Open all assignments
                    731: #
                    732:     if ($ENV{'form.openall'}) {
                    733:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
1.33      www       734:        my %storecontent = ($storeunder         => time,
                    735:                            $storeunder.'.type' => 'date_start');
1.12      www       736:        
1.46      sakharuk  737:        $r->print(&mt('Opening all assignments').': '.&Apache::lonnet::cput
1.12      www       738:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
                    739:    }
1.13      www       740: #
                    741: # Set first page
                    742: #
1.48      www       743:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')
                    744: 	    || ($cloneid)) {
1.46      sakharuk  745: 	$r->print(&mt('Setting first resource').': ');
1.13      www       746:         my ($errtext,$fatal)=
                    747:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
                    748:         $r->print(($fatal?$errtext:'read ok').' - ');
                    749:         my $title; my $url;
                    750:         if ($ENV{'form.firstres'} eq 'syl') {
                    751: 	    $title='Syllabus';
                    752:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
                    753:         } else {
                    754:             $title='Navigate Contents';
                    755:             $url='/adm/navmaps';
                    756:         }
                    757:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15      albertel  758:         ($errtext,$fatal)=
1.13      www       759:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
                    760:         $r->print(($fatal?$errtext:'write ok').'<br>');
                    761:   }
1.2       www       762: #
                    763: # Make current user course adminstrator
                    764: #
1.12      www       765:     my $end=undef;
                    766:     my $addition='';
                    767:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
1.46      sakharuk  768:     $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.
1.2       www       769:     &Apache::lonnet::assignrole(
1.12      www       770:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2       www       771: #
                    772: # Make additional user course administrator
                    773: #
1.12      www       774:    if (($ccdomain) && ($ccuname)) {
1.46      sakharuk  775:     $r->print(&mt('Assigning role of course coordinator to').' '.
1.2       www       776:                $ccuname.' at '.$ccdomain.': '.
1.3       www       777:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12      www       778:    }
1.20      www       779:     if ($ENV{'form.setkeys'}) {
                    780: 	$r->print(
1.46      sakharuk  781:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
1.20      www       782:     }
1.47      www       783: # Flush the course logs so reverse user roles immediately updated
                    784:     &Apache::lonnet::flushcourselogs();
1.46      sakharuk  785:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
1.2       www       786: }
                    787: 
                    788: # ===================================================================== Handler
1.1       www       789: sub handler {
                    790:     my $r = shift;
                    791: 
                    792:     if ($r->header_only) {
1.38      www       793:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       794:        $r->send_http_header;
                    795:        return OK;
                    796:     }
                    797: 
1.10      matthew   798:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.38      www       799:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       800:        $r->send_http_header;
                    801: 
1.2       www       802:        if ($ENV{'form.phase'} eq 'two') {
1.10      matthew   803:            &create_course($r);
1.2       www       804:        } else {
1.10      matthew   805: 	   &print_course_creation_page($r);
1.2       www       806:        }
1.1       www       807:    } else {
                    808:       $ENV{'user.error.msg'}=
                    809:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    810:       return HTTP_NOT_ACCEPTABLE; 
                    811:    }
                    812:    return OK;
                    813: } 
                    814: 
                    815: 1;
                    816: __END__

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