File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.63: download - view: text, annotated - select for diffs
Fri Jul 2 00:27:44 2004 UTC (19 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_1_1_99_2, version_1_1_99_1, HEAD
Toward Bug #3161 - dump course still kaputt, though.

    1: #meserver The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.63 2004/07/02 00:27:44 www Exp $
    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: #
   28: ###
   29: 
   30: package Apache::loncreatecourse;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use Apache::lonnet;
   35: use Apache::loncommon;
   36: use Apache::lonratedt;
   37: use Apache::londocs;
   38: use Apache::lonlocal;
   39: use Apache::londropadd;
   40: use lib '/home/httpd/lib/perl';
   41: use localenroll;
   42: 
   43: # ================================================ Get course directory listing
   44: 
   45: my @output=();
   46: 
   47: sub crsdirlist {
   48:     my ($courseid,$which)=@_;
   49:     @output=();
   50:     return &innercrsdirlist($courseid,$which);
   51: }
   52: 
   53: sub innercrsdirlist {
   54:     my ($courseid,$which,$path)=@_;
   55:     my $dirptr=16384;
   56:     unless ($which) { $which=''; } else { $which.='/'; }
   57:     unless ($path)  { $path=''; } else { $path.='/'; }
   58:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
   59:     my @listing=&Apache::lonnet::dirlist
   60: 	($which,$crsdata{'domain'},$crsdata{'num'},
   61: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
   62:     foreach (@listing) {
   63: 	unless ($_=~/^\./) {
   64: 	    my @unpackline = split (/\&/,$_);
   65: 	    if ($unpackline[3]&$dirptr) {
   66: # is a directory, recurse
   67: 		&innercrsdirlist($courseid,$which.$unpackline[0],
   68: 				            $path.$unpackline[0]);
   69: 	    } else { 
   70: # is a file, put into output
   71: 		push (@output,$path.$unpackline[0]);
   72: 	    }
   73: 	}
   74:     }
   75:     return @output;
   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 {
   90:     (my $courseid, my $which,$ENV{'form.output'})=@_;
   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: 
   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: 
  111: # ============================================================= Copy a userfile
  112: 
  113: sub copyfile {
  114:     my ($origcrsid,$newcrsid,$which)=@_;
  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:     }
  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: 
  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:     }
  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:     }
  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: 
  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 
  215:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
  216: 		 &copydb($origcrsid,$newcrsid,$_);
  217: 	     }
  218: 	}
  219:     }
  220: }
  221: 
  222: # ======================================================= Copy all course files
  223: 
  224: sub copycoursefiles {
  225:     my ($origcrsid,$newcrsid)=@_;
  226:     &copyuserfiles($origcrsid,$newcrsid);
  227:     &copydbfiles($origcrsid,$newcrsid);
  228:     &copyresourcedb($origcrsid,$newcrsid);
  229: }
  230: 
  231: # ===================================================== Phase one: fill-in form
  232: 
  233: sub print_course_creation_page {
  234:     my $r=shift;
  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))) {
  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>};
  244:     }
  245:     $course_home .= "\n</select>\n";
  246:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  247:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  248:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
  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();
  254:     my $starttime = time;
  255:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
  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');
  258:     my ($krbdef,$krbdefdom) =
  259:     &Apache::loncommon::get_kerberos_defaults($defdom);
  260:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
  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);
  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",
  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:bot2", 
  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",
  307: 		    'kaut' => 
  308: 		    'Key authority (<tt>id@domain</tt>) if other than course',
  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",
  319:                     'dacc' => "Default start and end dates for student access",
  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?",
  325: 		    'rshm' => 'Resource Space Home',
  326:                     'opco' => "Open Course"
  327: 				       );
  328:     $r->print(<<ENDDOCUMENT);
  329: <html>
  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 + '&';
  340:     url += 'element=' + elementname + '&';
  341:     url += 'only=sequence' + '';
  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: }
  348: $javascript_validations
  349: </script>
  350: $coursebrowserjs
  351: <head>
  352: <title>The LearningOnline Network with CAPA</title>
  353: </head>
  354: $bodytag
  355: $helplink
  356: <form action="/adm/createcourse" method="post" name="ccrs">
  357: <h2>$lt{'cinf'}</h2>
  358: <p>
  359: <b>$lt{'ctit'}:</b>
  360: <input type="text" size="50" name="title">
  361: </p><p>
  362: <b>$lt{'chsr'}:</b>$course_home
  363: </p><p>
  364: <b>$lt{'cidn'} ($lt{'opt'})</b>
  365: <input type="text" size="30" name="crsid">
  366: </p><p>
  367: <h2>$lt{'iinf'}</h2>
  368: <p>
  369: $lt{'stat'}
  370: </p><p>
  371: <b>$lt{'ccod'}</b>
  372: <input type="text" size="30" name="crscode" /><br/>
  373: ($lt{'toin'})
  374: </p><p>
  375: <b>$lt{'snid'}</b>
  376:  <input type="text" size="30" name="crssections" /><br/>
  377: ($lt{'csli'})
  378: </p><p>
  379: <b>$lt{'crcs'}</b>
  380: <input type="text" size="30" name="crsxlist" /><br/>
  381: ($lt{'cscs'})
  382: </p>
  383: <h2>$lt{'crco'}</h2>
  384: <table border="2">
  385: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
  386: <tr><td>
  387: <p>
  388: <b>$lt{'map'}:</b>
  389: <input type="text" size="50" name="topmap">
  390: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
  391: </p><p>
  392: <b>$lt{'sacr'}</b><br /> 
  393: ($lt{'ocik'}):
  394: <input type="checkbox" name="nonstandard">
  395: </p>
  396: <p>
  397: <b>$lt{'fres'}</b><br />($lt{'stco'}):
  398: <input type="radio" name="firstres" value="blank">$lt{'blnk'}
  399: &nbsp;
  400: <input type="radio" name="firstres" value="syl" checked>$lt{'sllb'}
  401: &nbsp;
  402: <input type="radio" name="firstres" value="nav">$lt{'navi'}
  403: </p>
  404: </td><td>
  405: $lt{'cid'}: <input input type="text" size="25" name="clonecourse" value="" />
  406: <br />
  407: $lt{'dmn'}: 
  408: $cloneform<br />&nbsp;<br />
  409: $lt{'asov'}.
  410: </td></tr>
  411: </table>
  412: <h2>$lt{'assp'}</h2>
  413: <p>
  414: <b>$lt{'oaas'}: </b>
  415: <input type="checkbox" name="openall" />
  416: </p>
  417: <h2>$lt{'mssg'}</h2>
  418: <p>
  419: <b>$lt{'scpf'}: </b>
  420: <input type="checkbox" name="setpolicy" checked>
  421: <br />
  422: <b>$lt{'scfc'}: </b>
  423: <input type="checkbox" name="setcontent" checked>
  424: </p>
  425: <h2>$lt{'cmmn'}</h2>
  426: <p>
  427: <b>$lt{'dsrd'}: </b>
  428: <input type="checkbox" name="disresdis" /> <br />
  429: <b>$lt{'dsuc'}: </b>
  430: <input type="checkbox" name="disablechat" />
  431: </p>
  432: <h2>$lt{'acco'}</h2>
  433: <p>
  434: <b>$lt{'snak'}: </b>
  435: <input type="checkbox" name="setkeys" /><br />
  436: <b>$lt{'kaut'}: </b>
  437: <input type="text" size="30" name="keyauth" />
  438: </p>
  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>
  444: <p>
  445: <h2>$lt{'aens'}</h2>
  446: $lt{'aesc'}
  447: </p>
  448: <p>
  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'}
  451: </p><p>
  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'}
  454: </p><p>
  455: <b>$lt{'dacu'}</b>
  456: $enroll_table
  457: </p><p>
  458: <b>$lt{'dacc'}</b>
  459: $access_table
  460: <p></p>
  461: <b>$lt{'psam'}.</b><br />
  462: $lt{'pcda'}.
  463: </p><p>
  464: $krbform
  465: <br />
  466: $intform
  467: <br />
  468: $locform
  469: </p><p>
  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'}
  474: </p><p>
  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'}
  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
  483: </p><p>
  484: <b>$lt{'ierc'}:</b>
  485: <input type="checkbox" name="expireown" checked>
  486: </p>
  487: <p>
  488: <input type="hidden" name="phase" value="two" />
  489: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}">
  490: </p>
  491: </form>
  492: </body>
  493: </html>
  494: ENDDOCUMENT
  495: }
  496: 
  497: # ====================================================== Phase two: make course
  498: 
  499: sub create_course {
  500:     my $r=shift;
  501:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  502:     my $this_server = $Apache::lonnet::perlvar{'lonHostID'};
  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'};
  509:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  510:     $r->print(<<ENDENHEAD);
  511: <html>
  512: <head>
  513: <title>The LearningOnline Network with CAPA</title>
  514: </head>
  515: $bodytag
  516: ENDENHEAD
  517:     #
  518:     # Verify data
  519:     #
  520:     # Check the veracity of the course coordinator
  521:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  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>');
  532: 	return;
  533:     }
  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'}})) {
  538:         $r->print(&mt('Invalid home server for course').': '.
  539:                   $ENV{'form.course_home'}.'</body></html>');
  540:         return;
  541:     }
  542: #
  543: # Open course
  544: #
  545:     my %cenv=();
  546:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  547:                                                $cdescr,$curl,
  548:                                                $ENV{'form.course_home'},
  549:                                                $ENV{'form.nonstandard'},
  550:                                                $ENV{'form.crscode'});
  551: 
  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.
  556:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  557: #
  558: # Check if created correctly
  559: #
  560:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  561:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  562:     $r->print(&mt('Created on').': '.$crsuhome.'<br>');
  563: #
  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(
  573:     '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>');
  574: 	} else {
  575: 	    $r->print(
  576:     '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>');
  577: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
  578: # Copy all files
  579: 	    &copycoursefiles($cloneid,$courseid);
  580: # Restore URL
  581: 	    $cenv{'url'}=$oldcenv{'url'};
  582: # Restore title
  583: 	    $cenv{'description'}=$oldcenv{'description'};
  584: # Mark as cloned
  585: 	    $cenv{'clonedfrom'}=$cloneid;
  586: 	    delete($cenv{'default_enrollment_start_date'});
  587: 	    delete($cenv{'default_enrollment_end_date'});
  588: 	}
  589:     }
  590: #
  591: # Set environment (will override cloned, if existing)
  592: #
  593:     my @affiliates = ();  # Used to accumulate sections and crosslistings
  594:     if ($ENV{'form.crsid'}) {
  595:         $cenv{'courseid'}=$ENV{'form.crsid'};
  596:     }
  597:     if ($ENV{'form.crscode'}) {
  598:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
  599:     }
  600:     if ($ENV{'form.crssections'}) {
  601:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
  602:         my @sections = ();
  603:         if ($cenv{'internal.sectionnums'} =~ m/,/) {
  604:             @sections = split/,/,$cenv{'internal.sectionnums'};
  605:         } else {
  606:             $sections[0] = $cenv{'internal.sectionnums'};
  607:         }
  608:         if (@sections > 0) {
  609:             foreach (@sections) {
  610:                 my ($sec,$gp) = split/:/,$_; 
  611:                 push @affiliates,$ENV{'form.crscode'}.$sec;
  612:             }
  613:         }
  614:     }
  615: # do not hide course coordinator from staff listing, 
  616: # even if privileged
  617:     $cenv{'nothideprivileged'}=$ccuname.':'.$ccdomain;
  618:     if ($ENV{'form.crsxlist'}) {
  619:        $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
  620:        my @xlists = ();
  621:         if ($cenv{'internal.crosslistings'} =~ m/,/) {
  622:             @xlists = split/,/,$cenv{'internal.crosslistings'};
  623:         } else {
  624:             $xlists[0] = $cenv{'internal.crosslistings'};
  625:         }
  626:         if (@xlists > 0) {
  627:             foreach (@xlists) {
  628:                 my ($xl,$gp) = split/:/,$_;
  629:                 push @affiliates,$xl;
  630:             }
  631:         }
  632:     }
  633:     if ($ENV{'form.autoadds'}) {
  634:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
  635:     }
  636:     if ($ENV{'form.autodrops'}) {
  637:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
  638:     }
  639:     if ($ENV{'form.notify'}) {
  640:       if ($ccuname) {
  641:         $cenv{'internal.notifylist'} = $ccuname;
  642:       }
  643:     }
  644:     if ($ccuname) {
  645:         $cenv{'internal.courseowner'} = $ccuname;
  646:     } else {
  647:         $cenv{'internal.courseowner'} = $ENV{'user.name'};
  648:     }
  649:     if (@affiliates > 0) {
  650:         my @badclasses = ();
  651:         foreach my $class (@affiliates) {
  652:             my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$class,$cenv{'internal.courseowner'});
  653:             unless ($addcheck eq 'ok') {
  654:                 push @badclasses, $class; 
  655:             }
  656:         }
  657:         if (@badclasses > 0) {
  658:             $r->print('<font color="red">'.
  659:                       "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");
  660:             foreach (@badclasses) {
  661:                 $r->print("<li>$_</li>\n");
  662:             }
  663:             $r->print ("</ul><br/><br/></font>\n");
  664:         }
  665:     }
  666:     my $enrollstart = &Apache::lonhtmlcommon::get_date_from_form('startenroll');
  667:     my $enrollend   = &Apache::lonhtmlcommon::get_date_from_form('endenroll');
  668:     my $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
  669:     my $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
  670:     if ($ENV{'form.no_end_date'}) {
  671:       $endaccess = 0;
  672:     }
  673:     $cenv{'internal.autostart'}=$enrollstart;
  674:     $cenv{'internal.autoend'}=$enrollend;
  675:     $cenv{'default_enrollment_start_date'}=$startaccess;
  676:     $cenv{'default_enrollment_end_date'}=$endaccess;
  677:     if ($ENV{'form.showphotos'}) {
  678:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
  679:     }
  680:     if ($ENV{'form.login'} eq 'krb') {
  681:         $cenv{'internal.authtype'} = 'krb';
  682:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
  683:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
  684:     } elsif ($ENV{'form.login'} eq 'int') {
  685:         $cenv{'internal.authtype'} ='internal';
  686:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
  687:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
  688:         }
  689:     } elsif ($ENV{'form.login'} eq 'loc') {
  690:         $cenv{'internal.authtype'} = 'localauth';
  691:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
  692:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
  693:         }
  694:     }
  695:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
  696:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
  697:             $r->print('<font color="red" size="+1">'.
  698:                       &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>');
  699:         }
  700:     }
  701:     if (($ccdomain) && ($ccuname)) {
  702:        if ($ENV{'form.setpolicy'}) {
  703:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  704:        }
  705:        if ($ENV{'form.setcontent'}) {
  706:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  707:        }
  708:     }
  709:     if ($ENV{'form.reshome'}) {
  710: 	$cenv{'reshome'}=$ENV{'form.reshome'}.'/';
  711: 	$cenv{'reshome'}=~s/\/+$/\//;
  712:     }
  713: #
  714: # course has keyed access
  715: #
  716:     if ($ENV{'form.setkeys'}) {
  717:        $cenv{'keyaccess'}='yes';
  718:     }
  719: # if specified, key authority is not course, but user
  720: # only active if keyaccess is yes
  721:     if ($ENV{'form.keyauth'}) {
  722: 	$ENV{'form.keyauth'}=~s/[^\w\@]//g;
  723: 	if ($ENV{'form.keyauth'}) {
  724: 	    $cenv{'keyauth'}=$ENV{'form.keyauth'};
  725: 	}
  726:     }
  727: 
  728:     if ($ENV{'form.disresdis'}) {
  729:         $cenv{'pch.roles.denied'}='st';
  730:     }
  731:     if ($ENV{'form.disablechat'}) {
  732:         $cenv{'plc.roles.denied'}='st';
  733:     }
  734: 
  735:     # Record we've not yet viewed the Course Initialization Helper for this 
  736:     # course
  737:     $cenv{'course.helper.not.run'} = 1;
  738:     #
  739:     # Use new Randomseed
  740:     #
  741:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  742:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
  743:     #
  744:     # The encryption code and receipt prefix for this course
  745:     #
  746:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
  747:     $cenv{'internal.encpref'}=100+int(9*rand(99));
  748:     #
  749:     # By default, use standard grading
  750:     $cenv{'grading'} = 'standard';
  751: 
  752:     $r->print('<br />'.&mt('Setting environment').': '.                 
  753:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  754: #
  755: # Open all assignments
  756: #
  757:     if ($ENV{'form.openall'}) {
  758:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  759:        my %storecontent = ($storeunder         => time,
  760:                            $storeunder.'.type' => 'date_start');
  761:        
  762:        $r->print(&mt('Opening all assignments').': '.&Apache::lonnet::cput
  763:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  764:    }
  765: #
  766: # Set first page
  767: #
  768:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')
  769: 	    || ($cloneid)) {
  770: 	$r->print(&mt('Setting first resource').': ');
  771:         my ($errtext,$fatal)=
  772:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  773:         $r->print(($fatal?$errtext:'read ok').' - ');
  774:         my $title; my $url;
  775:         if ($ENV{'form.firstres'} eq 'syl') {
  776: 	    $title='Syllabus';
  777:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  778:         } else {
  779:             $title='Navigate Contents';
  780:             $url='/adm/navmaps';
  781:         }
  782:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  783:         ($errtext,$fatal)=
  784:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  785:         $r->print(($fatal?$errtext:'write ok').'<br>');
  786:   }
  787: #
  788: # Make current user course adminstrator
  789: #
  790:     my $end=undef;
  791:     my $addition='';
  792:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  793:     $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.
  794:     &Apache::lonnet::assignrole(
  795:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  796: #
  797: # Make additional user course administrator
  798: #
  799:    if (($ccdomain) && ($ccuname)) {
  800:     $r->print(&mt('Assigning role of course coordinator to').' '.
  801:                $ccuname.' at '.$ccdomain.': '.
  802:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  803:    }
  804:     if ($ENV{'form.setkeys'}) {
  805: 	$r->print(
  806:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
  807:     }
  808: # Flush the course logs so reverse user roles immediately updated
  809:     &Apache::lonnet::flushcourselogs();
  810:     $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
  811: }
  812: 
  813: # ===================================================================== Handler
  814: sub handler {
  815:     my $r = shift;
  816: 
  817:     if ($r->header_only) {
  818:        &Apache::loncommon::content_type($r,'text/html');
  819:        $r->send_http_header;
  820:        return OK;
  821:     }
  822: 
  823:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  824:        &Apache::loncommon::content_type($r,'text/html');
  825:        $r->send_http_header;
  826: 
  827:        if ($ENV{'form.phase'} eq 'two') {
  828:            &create_course($r);
  829:        } else {
  830: 	   &print_course_creation_page($r);
  831:        }
  832:    } else {
  833:       $ENV{'user.error.msg'}=
  834:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  835:       return HTTP_NOT_ACCEPTABLE; 
  836:    }
  837:    return OK;
  838: } 
  839: 
  840: 1;
  841: __END__

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