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

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

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