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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.43    ! raeburn     4: # $Id: loncreatecourse.pm,v 1.42 2003/12/05 21:59:31 albertel Exp $
1.5       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       www        28: # (My Desk
                     29: #
                     30: # (Internal Server Error Handler
                     31: #
                     32: # (Login Screen
                     33: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                     34: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     35: #
                     36: # 3/1/1 Gerd Kortemeyer)
                     37: #
                     38: # 3/1 Gerd Kortemeyer)
                     39: #
1.4       www        40: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
1.1       www        41: #
                     42: package Apache::loncreatecourse;
                     43: 
                     44: use strict;
                     45: use Apache::Constants qw(:common :http);
                     46: use Apache::lonnet;
1.12      www        47: use Apache::loncommon;
1.13      www        48: use Apache::lonratedt;
                     49: use Apache::londocs;
1.38      www        50: use Apache::lonlocal;
1.41      raeburn    51: use Apache::londropadd;
1.28      www        52: 
                     53: # ================================================ Get course directory listing
                     54: 
                     55: sub crsdirlist {
                     56:     my ($courseid,$which)=@_;
                     57:     unless ($which) { $which=''; }
                     58:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     59:     my @listing=&Apache::lonnet::dirlist
                     60: 	($which,$crsdata{'domain'},$crsdata{'num'},
1.39      albertel   61: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
1.28      www        62:     my @output=();
                     63:     foreach (@listing) {
                     64: 	unless ($_=~/^\./) {
                     65: 	    push (@output,(split(/\&/,$_))[0]);
                     66: 	}
                     67:     }
                     68:     return @output;
1.29      www        69: }
                     70: 
                     71: # ============================================================= Read a userfile
                     72: 
                     73: sub readfile {
                     74:     my ($courseid,$which)=@_;
                     75:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     76:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
                     77: 				    $crsdata{'num'}.'/'.$which);
                     78: }
                     79: 
                     80: # ============================================================ Write a userfile
                     81: 
                     82: sub writefile {
1.30      www        83:     (my $courseid, my $which,$ENV{'form.output'})=@_;
1.29      www        84:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     85:     return &Apache::lonnet::finishuserfileupload(
                     86: 					  $crsdata{'num'},$crsdata{'domain'},
                     87: 					  $crsdata{'home'},
                     88: 					  'output',$which);
                     89: }
                     90: 
1.36      www        91: # ===================================================================== Rewrite
                     92: 
                     93: sub rewritefile {
                     94:     my ($contents,%rewritehash)=@_;
                     95:     foreach (keys %rewritehash) {
                     96: 	my $pattern=$_;
                     97: 	$pattern=~s/(\W)/\\$1/gs;
                     98: 	my $new=$rewritehash{$_};
                     99: 	$contents=~s/$pattern/$new/gs;
                    100:     }
                    101:     return $contents;
                    102: }
                    103: 
1.29      www       104: # ============================================================= Copy a userfile
                    105: 
                    106: sub copyfile {
                    107:     my ($origcrsid,$newcrsid,$which)=@_;
1.36      www       108:     unless ($which=~/\.sequence$/) {
                    109: 	return &writefile($newcrsid,$which,
                    110: 		      &readfile($origcrsid,$which));
                    111:     } else {
                    112: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    113: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    114: 	return &writefile($newcrsid,$which,
                    115: 		 &rewritefile(
                    116:                      &readfile($origcrsid,$which),
                    117: 	    (
                    118:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
                    119:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
                    120:             )));
                    121:     }
1.30      www       122: }
                    123: 
                    124: # =============================================================== Copy a dbfile
                    125: 
                    126: sub copydb {
                    127:     my ($origcrsid,$newcrsid,$which)=@_;
                    128:     $which=~s/\.db$//;
                    129:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    130:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    131:     my %data=&Apache::lonnet::dump
                    132: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
                    133:     return &Apache::lonnet::put
                    134: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
                    135: }
                    136: 
1.35      www       137: # ========================================================== Copy resourcesdata
                    138: 
                    139: sub copyresourcedb {
                    140:     my ($origcrsid,$newcrsid)=@_;
                    141:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    142:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    143:     my %data=&Apache::lonnet::dump
                    144: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
                    145:     $origcrsid=~s/^\///;
                    146:     $origcrsid=~s/\//\_/;
                    147:     $newcrsid=~s/^\///;
                    148:     $newcrsid=~s/\//\_/;
                    149:     my %newdata=();
                    150:     undef %newdata;
                    151:     my $startdate=$data{$origcrsid.'.0.opendate'};
                    152:     my $today=time;
                    153:     my $delta=0;
                    154:     if ($startdate) {
                    155: 	my $oneday=60*60*24;
                    156: 	$delta=$today-$startdate;
                    157: 	$delta=int($delta/$oneday)*$oneday;
                    158:     }
                    159: # ugly retro fix for broken version of types
                    160:     foreach (keys %data) {
                    161: 	if ($_=~/\wtype$/) {
                    162: 	    my $newkey=$_;
                    163: 	    $newkey=~s/type$/\.type/;
                    164: 	    $data{$newkey}=$data{$_};
                    165: 	    delete $data{$_};
                    166: 	}
                    167:     }
1.37      www       168: # adjust symbs
                    169:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
                    170:     $pattern=~s/(\W)/\\$1/gs;
                    171:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
                    172:     foreach (keys %data) {
                    173: 	if ($_=~/$pattern/) {
                    174: 	    my $newkey=$_;
                    175: 	    $newkey=~s/$pattern/$new/;
                    176: 	    $data{$newkey}=$data{$_};
                    177: 	    delete $data{$_};
                    178: 	}
                    179:     }
1.35      www       180: # adjust dates
                    181:     foreach (keys %data) {
                    182: 	my $thiskey=$_;
                    183: 	$thiskey=~s/^$origcrsid/$newcrsid/;
                    184: 	$newdata{$thiskey}=$data{$_};
                    185: 	if ($data{$_.'.type'}=~/^date/) {
                    186: 	    $newdata{$thiskey}=$newdata{$thiskey}+$delta;
                    187: 	}
                    188:     }
                    189:     return &Apache::lonnet::put
                    190: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
                    191: }
                    192: 
1.30      www       193: # ========================================================== Copy all userfiles
                    194: 
                    195: sub copyuserfiles {
                    196:     my ($origcrsid,$newcrsid)=@_;
                    197:     foreach (&crsdirlist($origcrsid,'userfiles')) {
                    198: 	&copyfile($origcrsid,$newcrsid,$_);
                    199:     }
                    200: }
                    201: # ========================================================== Copy all userfiles
                    202: 
                    203: sub copydbfiles {
                    204:     my ($origcrsid,$newcrsid)=@_;
                    205:     foreach (&crsdirlist($origcrsid)) {
                    206: 	if ($_=~/\.db$/) {
                    207: 	    unless 
1.34      www       208:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
1.30      www       209: 		 &copydb($origcrsid,$newcrsid,$_);
                    210: 	     }
                    211: 	}
                    212:     }
1.31      www       213: }
                    214: 
                    215: # ======================================================= Copy all course files
                    216: 
                    217: sub copycoursefiles {
                    218:     my ($origcrsid,$newcrsid)=@_;
                    219:     &copyuserfiles($origcrsid,$newcrsid);
                    220:     &copydbfiles($origcrsid,$newcrsid);
1.35      www       221:     &copyresourcedb($origcrsid,$newcrsid);
1.28      www       222: }
1.13      www       223: 
1.2       www       224: # ===================================================== Phase one: fill-in form
                    225: 
1.10      matthew   226: sub print_course_creation_page {
1.2       www       227:     my $r=shift;
1.10      matthew   228:     my $defdom=$ENV{'request.role.domain'};
                    229:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
                    230:     my $course_home = '<select name="course_home" size="1">'."\n";
                    231:     foreach my $server (sort(keys(%host_servers))) {
1.14      matthew   232:         $course_home .= qq{<option value="$server"};
                    233:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
                    234:             $course_home .= " selected ";
                    235:         }
                    236:         $course_home .= qq{>$server $host_servers{$server}</option>};
1.10      matthew   237:     }
                    238:     $course_home .= "\n</select>\n";
1.9       matthew   239:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12      www       240:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.17      www       241:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
1.32      www       242:     my $cloneform=&Apache::loncommon::select_dom_form
                    243: 	($ENV{'request.role.domain'},'clonedomain').
                    244: 		     &Apache::loncommon::selectcourse_link
                    245: 		     ('ccrs','clonecourse','clonedomain');
                    246:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
1.43    ! raeburn   247:     my $starttime = time;
        !           248:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
        !           249:     my $date_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'createcourse');
1.40      raeburn   250:     my ($krbdef,$krbdefdom) =
                    251:     &Apache::loncommon::get_kerberos_defaults($defdom);
1.41      raeburn   252:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
1.40      raeburn   253:     my %param = ( formname => 'document.ccrs',
                    254:                    kerb_def_dom => $krbdefdom,
                    255:                    kerb_def_auth => $krbdef
                    256:                 );
                    257:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    258:     my $intform = &Apache::loncommon::authform_internal(%param);
                    259:     my $locform = &Apache::loncommon::authform_local(%param);
1.2       www       260:     $r->print(<<ENDDOCUMENT);
                    261: <html>
1.6       matthew   262: <script language="JavaScript" type="text/javascript">
                    263: var editbrowser = null;
                    264: function openbrowser(formname,elementname) {
                    265:     var url = '/res/?';
                    266:     if (editbrowser == null) {
                    267:         url += 'launch=1&';
                    268:     }
                    269:     url += 'catalogmode=interactive&';
                    270:     url += 'mode=edit&';
                    271:     url += 'form=' + formname + '&';
1.7       matthew   272:     url += 'element=' + elementname + '&';
                    273:     url += 'only=sequence' + '';
1.6       matthew   274:     var title = 'Browser';
                    275:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    276:     options += ',width=700,height=600';
                    277:     editbrowser = open(url,title,options,'1');
                    278:     editbrowser.focus();
                    279: }
1.41      raeburn   280: $javascript_validations
1.6       matthew   281: </script>
1.32      www       282: $coursebrowserjs
1.2       www       283: <head>
                    284: <title>The LearningOnline Network with CAPA</title>
                    285: </head>
1.12      www       286: $bodytag
1.17      www       287: $helplink
1.6       matthew   288: <form action="/adm/createcourse" method="post" name="ccrs">
1.10      matthew   289: <h2>Course Information</h2>
                    290: <p>
                    291: <b>Course Title:</b>
1.6       matthew   292: <input type="text" size="50" name="title">
1.10      matthew   293: </p><p>
1.13      www       294: <b>Course Home Server:</b>$course_home
                    295: </p><p>
                    296: <b>Course ID/Number (optional)</b>
                    297: <input type="text" size="30" name="crsid">
1.40      raeburn   298: </p><p>
                    299: <h2>Institutional Information</h2>
                    300: <p>
                    301: 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.
                    302: </p><p>
                    303: <b>Course Code</b>
                    304: <input type="text" size="30" name="crscode" /><br/>
                    305: (to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231)
                    306: </p><p>
                    307: <b>Section Numbers and corresponding LON-CAPA section/group IDs</b>
                    308:  <input type="text" size="30" name="crssections" /><br/>
                    309: (a comma separated list of institutional section numbers, each separated by a colon
                    310: from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2)
                    311: </p><p>
                    312: <b>Crosslisted courses</b>
                    313: <input type="text" size="30" name="crsxlist" /><br/>
                    314: (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)
1.13      www       315: </p>
                    316: <h2>Course Content</h2>
1.32      www       317: <table border="2">
                    318: <tr><th>Completely new course</th><th>Clone an existing course</th></tr>
                    319: <tr><td>
1.13      www       320: <p>
1.11      www       321: <b>Map:</b>
1.6       matthew   322: <input type="text" size="50" name="topmap">
1.24      www       323: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
1.10      matthew   324: </p><p>
1.32      www       325: <b>Do NOT generate as standard course</b><br /> 
1.11      www       326: (only check if you know what you are doing):
                    327: <input type="checkbox" name="nonstandard">
1.13      www       328: </p>
                    329: <p>
1.32      www       330: <b>First Resource</b><br />(standard courses only):
1.17      www       331: <input type="radio" name="firstres" value="blank">Blank
1.13      www       332: &nbsp;
1.17      www       333: <input type="radio" name="firstres" value="syl" checked>Syllabus
1.13      www       334: &nbsp;
                    335: <input type="radio" name="firstres" value="nav">Navigate
                    336: </p>
1.32      www       337: </td><td>
                    338: Course ID: <input input type="text" size="25" name="clonecourse" value="" />
                    339: <br />
                    340: Domain: 
                    341: $cloneform<br />&nbsp;<br />
                    342: Additional settings, if specified below, will override cloned settings.
                    343: </td></tr>
                    344: </table>
1.13      www       345: <h2>Assessment Parameters</h2>
                    346: <p>
1.11      www       347: <b>Open all assessments: </b>
                    348: <input type="checkbox" name="openall" checked>
1.13      www       349: </p>
                    350: <h2>Messaging</h2>
                    351: <p>
1.11      www       352: <b>Set course policy feedback to Course Coordinator: </b>
                    353: <input type="checkbox" name="setpolicy" checked>
                    354: </p><p>
                    355: <b>Set content feedback to Course Coordinator: </b>
                    356: <input type="checkbox" name="setcontent" checked>
                    357: </p>
1.16      www       358: <h2>Communication</h2>
                    359: <p>
                    360: <b>Disable student resource discussion: </b>
1.26      matthew   361: <input type="checkbox" name="disresdis" /> <br />
                    362: <b>Disable student use of chatrooms: </b>
                    363: <input type="checkbox" name="disablechat" />
1.16      www       364: </p>
1.18      www       365: <h2>Access Control</h2>
                    366: <p>
                    367: <b>Students need access key to enter course: </b>
                    368: <input type="checkbox" name="setkeys" />
                    369: </p>
1.10      matthew   370: <h2>Course Coordinator</h2>
                    371: <p>
1.11      www       372: <b>Username:</b> <input type="text" size="15" name="ccuname" />
                    373: </p><p>
                    374: <b>Domain:</b> $domform
1.10      matthew   375: </p><p>
1.11      www       376: <b>Immediately expire own role as Course Coordinator:</b>
                    377: <input type="checkbox" name="expireown" checked>
1.10      matthew   378: </p><p>
1.40      raeburn   379: <h2>Automated enrollment settings</h2>
                    380: The following settings control automatic enrollment of students in this class based
                    381: on information available for this specific course from your institution's official classlists.
                    382: </p>
                    383: <p>
                    384: <b>Automated adds</b>
1.43    ! raeburn   385: <input type="radio" name="autoadds" value="1" />Yes <input type="radio" name="autoadds" value="0" checked="true" />No
1.40      raeburn   386: </p><p>
                    387: <b>Automated drops</b>
1.43    ! raeburn   388: <input type="radio" name="autodrops" value="1" />Yes <input type="radio" name="autodrops" value="0" checked="true" />No
1.40      raeburn   389: </p><p>
                    390: <b>Duration of automated classlist updates</b>
                    391: $date_table
                    392: </p><p>
                    393: <b>Please select the authentication mechanism.</b><br />
                    394: Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process.
                    395: </p><p>
                    396: $krbform
                    397: <br />
                    398: $intform
                    399: <br />
                    400: $locform
                    401: </p><p>
                    402: <b>Notification of enrollment changes</b><br />
                    403: Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?<br/>
                    404: <input type="radio" name="notify" value="1" />Yes <input type="radio" name="notify"
1.43    ! raeburn   405: value="0" checked="true" />No
1.40      raeburn   406: </p><p>
                    407: <b>Include retrieval of student photographs?</b> <input type="radio" name="showphotos" value="1" />Yes <input type="radio" name="showphotos" value="0" checked="true" />No
                    408: </p><p>
1.10      matthew   409: <input type="hidden" name="phase" value="two" />
1.41      raeburn   410: <input type="button" onClick="verify_message(this.form)" value="Open Course">
1.10      matthew   411: </p>
1.2       www       412: </form>
                    413: </body>
                    414: </html>
                    415: ENDDOCUMENT
1.40      raeburn   416: }
                    417: 
1.2       www       418: # ====================================================== Phase two: make course
                    419: 
1.10      matthew   420: sub create_course {
1.2       www       421:     my $r=shift;
                    422:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                    423:     my $ccuname=$ENV{'form.ccuname'};
                    424:     my $ccdomain=$ENV{'form.ccdomain'};
                    425:     $ccuname=~s/\W//g;
                    426:     $ccdomain=~s/\W//g;
                    427:     my $cdescr=$ENV{'form.title'};
                    428:     my $curl=$ENV{'form.topmap'};
1.12      www       429:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2       www       430:     $r->print(<<ENDENHEAD);
                    431: <html>
                    432: <head>
                    433: <title>The LearningOnline Network with CAPA</title>
                    434: </head>
1.12      www       435: $bodytag
1.2       www       436: ENDENHEAD
1.10      matthew   437:     #
                    438:     # Verify data
                    439:     #
                    440:     # Check the veracity of the course coordinator
1.2       www       441:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       442:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       443: 	return;
                    444:     }
1.10      matthew   445:     # Check the proposed home server for the course
                    446:     my %host_servers = &Apache::loncommon::get_library_servers
                    447:         ($ENV{'request.role.domain'});
                    448:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
                    449:         $r->print('Invalid home server for course: '.
                    450:                   $ENV{'form.course_home'}.'</body></html>');
                    451:         return;
                    452:     }
1.2       www       453: #
                    454: # Open course
                    455: #
1.32      www       456:     my %cenv=();
1.10      matthew   457:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
                    458:                                                $cdescr,$curl,
1.11      www       459:                                                $ENV{'form.course_home'},
                    460:                                                $ENV{'form.nonstandard'});
1.2       www       461: 
1.27      bowersj2  462:     # Note: The testing routines depend on this being output; see 
                    463:     # Utils::Course. This needs to at least be output as a comment
                    464:     # if anyone ever decides to not show this, and Utils::Course::new
                    465:     # will need to be suitably modified.
1.4       www       466:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    467: #
1.12      www       468: # Check if created correctly
1.4       www       469: #
                    470:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    471:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    472:     $r->print('Created on: '.$crsuhome.'<br>');
1.12      www       473: #
1.32      www       474: # Are we cloning?
                    475: #
                    476:     my $cloneid='';
                    477:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
                    478: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
                    479:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
                    480: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                    481: 	if ($clonehome eq 'no_host') {
                    482: 	    $r->print(
                    483:     '<br /><font color="red">Attempting to clone non-existing course '.$cloneid.'</font>');
                    484: 	} else {
                    485: 	    $r->print(
                    486:     '<br /><font color="green">Cloning course from '.$clonehome.'</font>');
1.37      www       487: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
1.32      www       488: # Copy all files
                    489: 	    &copycoursefiles($cloneid,$courseid);
1.37      www       490: # Restore URL
                    491: 	    $cenv{'url'}=$oldcenv{'url'};
1.32      www       492: # Restore title
1.37      www       493: 	    $cenv{'description'}=$oldcenv{'description'};
                    494: # Mark as cloned
1.35      www       495: 	    $cenv{'clonedfrom'}=$cloneid;
1.32      www       496: 	}
                    497:     }
                    498: #
                    499: # Set environment (will override cloned, if existing)
1.12      www       500: #
1.4       www       501:     if ($ENV{'form.crsid'}) {
1.12      www       502:         $cenv{'courseid'}=$ENV{'form.crsid'};
1.40      raeburn   503:     }
                    504:     if ($ENV{'form.crscode'}) {
                    505:         $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
                    506:     }
                    507:     if ($ENV{'form.crssections'}) {
                    508:         $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
                    509:     }
                    510:     if ($ENV{'form.crsxlist'}) {
                    511:         $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
                    512:     }
                    513:     if ($ENV{'form.autoadds'}) {
                    514:         $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
                    515:     }
                    516:     if ($ENV{'form.autodrops'}) {
                    517:         $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
                    518:     }
                    519:     if ($ENV{'form.notify'}) {
                    520:       if ($ccuname) {
                    521:         $cenv{'internal.notifylist'} = $ccuname;
                    522:       }
                    523:     }
                    524:     if ($ccuname) {
                    525:         $cenv{'internal.courseowner'} = $ccuname;
                    526:     }
                    527:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                    528:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                    529:     if ($ENV{'form.no_end_date'}) {
                    530:       $enddate = 0;
                    531:     }
                    532:     $cenv{'internal.autostart'}=$startdate;
                    533:     $cenv{'internal.autoend'}=$enddate;
                    534:     if ($ENV{'form.showphotos'}) {
                    535:       $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
                    536:     }
                    537:     if ($ENV{'form.login'} eq 'krb') {
                    538:         $cenv{'internal.authtype'} = 'krb';
                    539:         $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
                    540:         $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
                    541:     } elsif ($ENV{'form.login'} eq 'int') {
                    542:         $cenv{'internal.authtype'} ='internal';
                    543:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                    544:             $cenv{'internal.autharg'} = $ENV{'form.intarg'};
                    545:         }
                    546:     } elsif ($ENV{'form.login'} eq 'loc') {
                    547:         $cenv{'internal.authtype'} = 'localauth';
                    548:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                    549:             $cenv{'internal.autharg'} = $ENV{'form.locarg'};
                    550:         }
                    551:     }
                    552:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                    553:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
                    554:             $r->print('<font color="red" size="+1">'.
                    555:                       '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>');
                    556:         }
1.12      www       557:     }
                    558:     if (($ccdomain) && ($ccuname)) {
                    559:        if ($ENV{'form.setpolicy'}) {
                    560:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
                    561:        }
                    562:        if ($ENV{'form.setcontent'}) {
1.18      www       563:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
                    564:        }
                    565:     }
                    566:     if ($ENV{'form.setkeys'}) {
                    567:        $cenv{'keyaccess'}='yes';
1.16      www       568:     }
                    569:     if ($ENV{'form.disresdis'}) {
                    570:         $cenv{'pch.roles.denied'}='st';
1.26      matthew   571:     }
                    572:     if ($ENV{'form.disablechat'}) {
                    573:         $cenv{'plc.roles.denied'}='st';
1.21      albertel  574:     }
1.23      bowersj2  575: 
1.32      www       576:     # Record we've not yet viewed the Course Initialization Helper for this 
                    577:     # course
1.23      bowersj2  578:     $cenv{'course.helper.not.run'} = 1;
1.21      albertel  579:     #
                    580:     # Use new Randomseed
                    581:     #
1.22      albertel  582:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.25      matthew   583:     #
                    584:     # By default, use standard grading
                    585:     $cenv{'grading'} = 'standard';
1.22      albertel  586: 
1.32      www       587:     $r->print('<br />Setting environment: '.                 
1.12      www       588:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
                    589: #
                    590: # Open all assignments
                    591: #
                    592:     if ($ENV{'form.openall'}) {
                    593:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
1.33      www       594:        my %storecontent = ($storeunder         => time,
                    595:                            $storeunder.'.type' => 'date_start');
1.12      www       596:        
                    597:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
                    598:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
                    599:    }
1.13      www       600: #
                    601: # Set first page
                    602: #
                    603:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
                    604: 	$r->print('Setting first resource: ');
                    605:         my ($errtext,$fatal)=
                    606:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
                    607:         $r->print(($fatal?$errtext:'read ok').' - ');
                    608:         my $title; my $url;
                    609:         if ($ENV{'form.firstres'} eq 'syl') {
                    610: 	    $title='Syllabus';
                    611:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
                    612:         } else {
                    613:             $title='Navigate Contents';
                    614:             $url='/adm/navmaps';
                    615:         }
                    616:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15      albertel  617:         ($errtext,$fatal)=
1.13      www       618:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
                    619:         $r->print(($fatal?$errtext:'write ok').'<br>');
                    620:   }
1.2       www       621: #
                    622: # Make current user course adminstrator
                    623: #
1.12      www       624:     my $end=undef;
                    625:     my $addition='';
                    626:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
                    627:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2       www       628:     &Apache::lonnet::assignrole(
1.12      www       629:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2       www       630: #
                    631: # Make additional user course administrator
                    632: #
1.12      www       633:    if (($ccdomain) && ($ccuname)) {
1.2       www       634:     $r->print('Assigning role of course coordinator to '.
                    635:                $ccuname.' at '.$ccdomain.': '.
1.3       www       636:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12      www       637:    }
1.20      www       638:     if ($ENV{'form.setkeys'}) {
                    639: 	$r->print(
                    640:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
                    641:     }
                    642:     $r->print('<p>Roles will be active at next login.</p></body></html>');
1.2       www       643: }
                    644: 
                    645: # ===================================================================== Handler
1.1       www       646: sub handler {
                    647:     my $r = shift;
                    648: 
                    649:     if ($r->header_only) {
1.38      www       650:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       651:        $r->send_http_header;
                    652:        return OK;
                    653:     }
                    654: 
1.10      matthew   655:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.38      www       656:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       657:        $r->send_http_header;
                    658: 
1.2       www       659:        if ($ENV{'form.phase'} eq 'two') {
1.10      matthew   660:            &create_course($r);
1.2       www       661:        } else {
1.10      matthew   662: 	   &print_course_creation_page($r);
1.2       www       663:        }
1.1       www       664:    } else {
                    665:       $ENV{'user.error.msg'}=
                    666:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    667:       return HTTP_NOT_ACCEPTABLE; 
                    668:    }
                    669:    return OK;
                    670: } 
                    671: 
                    672: 1;
                    673: __END__

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