File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.61: download - view: text, annotated - select for diffs
Tue Jun 29 14:56:32 2004 UTC (19 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Include institutional course code in nohist_courseids.db.
Format of entries in nohist_courseids.db now -
course_id = description:institutional code:last activity
both (keys and values are escaped).
lonnet::courseiddump now returns escaped values in hash (keys are unescaped),
to preserve the : separator between description and institutional code.

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

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