File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.66: download - view: text, annotated - select for diffs
Wed Aug 25 20:48:04 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- /public links were not being updated in the cloning process

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

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