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