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

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

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