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