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