File:
[LON-CAPA] /
loncom /
interface /
loncreatecourse.pm
Revision
1.74:
download - view:
text,
annotated -
select for diffs
Wed Dec 8 23:27:29 2004 UTC (19 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Most functionality in create_course() now moved to new subroutine - construct_course(), so that loncreatecourse::construct_course() can be called by a batch process to create course(s) based on an XML file(s) describing course attributes. See bug #1273.
1: # The LearningOnline Network
2: # Create a course
3: #
4: # $Id: loncreatecourse.pm,v 1.74 2004/12/08 23:27:29 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/) {
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: 'irsp' => "Include retrieval of student photographs?",
331: 'rshm' => 'Resource Space Home',
332: 'opco' => "Open Course"
333: );
334: $r->print(<<ENDDOCUMENT);
335: <html>
336: <script language="JavaScript" type="text/javascript">
337: var editbrowser = null;
338: function openbrowser(formname,elementname) {
339: var url = '/res/?';
340: if (editbrowser == null) {
341: url += 'launch=1&';
342: }
343: url += 'catalogmode=interactive&';
344: url += 'mode=edit&';
345: url += 'form=' + formname + '&';
346: url += 'element=' + elementname + '&';
347: url += 'only=sequence' + '';
348: var title = 'Browser';
349: var options = 'scrollbars=1,resizable=1,menubar=0';
350: options += ',width=700,height=600';
351: editbrowser = open(url,title,options,'1');
352: editbrowser.focus();
353: }
354: $javascript_validations
355: </script>
356: $coursebrowserjs
357: <head>
358: <title>The LearningOnline Network with CAPA</title>
359: </head>
360: $bodytag
361: $helplink
362: <form action="/adm/createcourse" method="post" name="ccrs">
363: <h2>$lt{'cinf'}</h2>
364: <p>
365: <label><b>$lt{'ctit'}:</b>
366: <input type="text" size="50" name="title" /></label>
367: </p><p>
368: <label>
369: <b>$lt{'chsr'}:</b>$course_home
370: </label>
371: </p><p>
372: <label>
373: <b>$lt{'cidn'} ($lt{'opt'})</b>
374: <input type="text" size="30" name="crsid" />
375: </label>
376: </p><p>
377: <h2>$lt{'iinf'}</h2>
378: <p>
379: $lt{'stat'}
380: </p><p>
381: <label>
382: <b>$lt{'ccod'}</b>
383: <input type="text" size="30" name="crscode" />
384: </label>
385: <br/>
386: ($lt{'toin'})
387: </p><p>
388: <label>
389: <b>$lt{'snid'}</b>
390: <input type="text" size="30" name="crssections" />
391: </label>
392: <br/>
393: ($lt{'csli'})
394: </p><p>
395: <label>
396: <b>$lt{'crcs'}</b>
397: <input type="text" size="30" name="crsxlist" />
398: </label>
399: <br/>
400: ($lt{'cscs'})
401: </p>
402: <h2>$lt{'crco'}</h2>
403: <table border="2">
404: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
405: <tr><td>
406: <p>
407: <label>
408: <b>$lt{'map'}:</b>
409: <input type="text" size="50" name="topmap" />
410: </label>
411: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
412: </p><p>
413: <label for="nonstd"><b>$lt{'sacr'}</b></label>
414: <br />
415: ($lt{'ocik'}):
416: <input id="nonstd" type="checkbox" name="nonstandard" />
417: </p><p>
418: <b>$lt{'fres'}</b><br />($lt{'stco'}):
419: <label>
420: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
421: </label>
422:
423: <label>
424: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
425: </label>
426:
427: <label>
428: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
429: </label>
430: </p>
431: </td><td>
432: <label>
433: $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
434: </label>
435: <br />
436: <label>
437: $lt{'dmn'}: $cloneform
438: </label>
439: <br />
440: <br />
441: $lt{'asov'}.
442: </td></tr>
443: </table>
444: <h2>$lt{'assp'}</h2>
445: <p>
446: <label>
447: <b>$lt{'oaas'}: </b>
448: <input type="checkbox" name="openall" />
449: </label>
450: </p>
451: <h2>$lt{'mssg'}</h2>
452: <p>
453: <label>
454: <b>$lt{'scpf'}: </b>
455: <input type="checkbox" name="setpolicy" checked />
456: </label>
457: <br />
458: <label>
459: <b>$lt{'scfc'}: </b>
460: <input type="checkbox" name="setcontent" checked />
461: </label>
462: </p>
463: <h2>$lt{'cmmn'}</h2>
464: <p>
465: <label>
466: <b>$lt{'dsrd'}: </b>
467: <input type="checkbox" name="disresdis" />
468: </label>
469: <br />
470: <label>
471: <b>$lt{'dsuc'}: </b>
472: <input type="checkbox" name="disablechat" />
473: </label>
474: </p>
475: <h2>$lt{'acco'}</h2>
476: <p>
477: <label>
478: <b>$lt{'snak'}: </b>
479: <input type="checkbox" name="setkeys" />
480: </label>
481: <br />
482: <label>
483: <b>$lt{'kaut'}: </b>
484: <input type="text" size="30" name="keyauth" />
485: </label>
486: </p>
487: <h2>$lt{'rshm'}</h2>
488: <p>
489: <label>
490: <b>$lt{'rshm'}: </b>
491: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
492: </label>
493: </p>
494: <p>
495: <h2>$lt{'aens'}</h2>
496: $lt{'aesc'}
497: </p>
498: <p>
499: <b>$lt{'aadd'}</b>
500: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label>
501: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
502: </label>
503: </p><p>
504: <b>$lt{'audr'}</b>
505: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label>
506: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
507: </p><p>
508: <b>$lt{'dacu'}</b>
509: $enroll_table
510: </p><p>
511: <b>$lt{'dacc'}</b>
512: $access_table
513: <p></p>
514: <b>$lt{'psam'}.</b><br />
515: $lt{'pcda'}.
516: </p><p>
517: $krbform
518: <br />
519: $intform
520: <br />
521: $locform
522: </p><p>
523: <b>$lt{'nech'}</b><br />
524: $lt{'nccl'}<br/>
525: <label>
526: <input type="radio" name="notify" value="1" />$lt{'yes'}
527: </label>
528: <label>
529: <input type="radio" name="notify" value="0" checked="true" />$lt{'no'}
530: </label>
531: </p><p>
532: <b>$lt{'irsp'}</b>
533: <label>
534: <input type="radio" name="showphotos" value="1" />$lt{'yes'}
535: </label>
536: <label>
537: <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
538: </label>
539: </p>
540: <hr />
541: <h2>$lt{'cc'}</h2>
542: <p>
543: <label>
544: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
545: </label>
546: </p><p>
547: <label>
548: <b>$lt{'dmn'}:</b> $domform
549: </label>
550: </p><p>
551: <label>
552: <b>$lt{'ierc'}:</b>
553: <input type="checkbox" name="expireown" checked />
554: </label>
555: </p>
556: <p>
557: <input type="hidden" name="phase" value="two" />
558: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
559: </p>
560: </form>
561: </body>
562: </html>
563: ENDDOCUMENT
564: }
565:
566: # ====================================================== Phase two: make course
567:
568: sub create_course {
569: my $r=shift;
570: my $ccuname=$ENV{'form.ccuname'};
571: my $ccdomain=$ENV{'form.ccdomain'};
572: $ccuname=~s/\W//g;
573: $ccdomain=~s/\W//g;
574:
575: my $enrollstart = &Apache::lonhtmlcommon::get_date_from_form('startenroll');
576: my $enrollend = &Apache::lonhtmlcommon::get_date_from_form('endenroll');
577: my $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
578: my $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
579:
580: my $autharg;
581: my $authtype;
582:
583: if ($ENV{'form.login'} eq 'krb') {
584: $authtype = 'krb';
585: $authtype .=$ENV{'form.krbver'};
586: $autharg = $ENV{'form.krbarg'};
587: } elsif ($ENV{'form.login'} eq 'int') {
588: $authtype ='internal';
589: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
590: $autharg = $ENV{'form.intarg'};
591: }
592: } elsif ($ENV{'form.login'} eq 'loc') {
593: $authtype = 'localauth';
594: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
595: $autharg = $ENV{'form.locarg'};
596: }
597: }
598:
599: my $logmsg;
600: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
601: $r->print(<<ENDENHEAD);
602: <html>
603: <head>
604: <title>The LearningOnline Network with CAPA</title>
605: </head>
606: $bodytag
607: ENDENHEAD
608:
609: my $args = {
610: ccuname => $ccuname,
611: ccdomain => $ccdomain,
612: cdescr => $ENV{'form.title'},
613: curl => $ENV{'form.topmap'},
614: course_domain => $ENV{'request.role.domain'},
615: course_home => $ENV{'form.course_home'},
616: nonstandard => $ENV{'form.nonstandard'},
617: crscode => $ENV{'form.crscode'},
618: clonecourse => $ENV{'form.clonecourse'},
619: clonedomain => $ENV{'form.clonedomain'},
620: crsid => $ENV{'form.crsid'},
621: curruser => $ENV{'user.name'},
622: crssections => $ENV{'form.crssections'},
623: crsxlist => $ENV{'form.crsxlist'},
624: autoadds => $ENV{'form.autoadds'},
625: autodrops => $ENV{'form.autodrops'},
626: notify => $ENV{'form.notify'},
627: no_end_date => $ENV{'form.no_end_date'},
628: showphotos => $ENV{'form.showphotos'},
629: authtype => $authtype,
630: autharg => $autharg,
631: enrollstart => $enrollstart,
632: enrollend => $enrollend,
633: startaccess => $startaccess,
634: endaccess => $endaccess,
635: setpolicy => $ENV{'form.setpolicy'},
636: setcontent => $ENV{'form.setcontent'},
637: reshome => $ENV{'form.reshome'},
638: setkeys => $ENV{'form.setkeys'},
639: keyauth => $ENV{'form.keyauth'},
640: disresdis => $ENV{'form.disresdis'},
641: disablechat => $ENV{'form.disablechat'},
642: openall => $ENV{'form.openall'},
643: firstres => $ENV{'form.firstres'}
644: };
645:
646: #
647: # Verify data
648: #
649: # Check the veracity of the course coordinator
650: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
651: $r->print('<form action="/adm/createuser" method="post" name="crtuser">');
652: $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
653: $r->print(&mt("Please click Back on your browser and select another user, or "));
654: $r->print('
655: <input type="hidden" name="phase" value="get_user_info" />
656: <input type="hidden" name="ccuname" value="'.$ccuname.'" />
657: <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
658: <input name="userrole" type="submit" value="'.
659: &mt('Create User').'" />
660: </form></body></html>');
661: return;
662: }
663: # Check the proposed home server for the course
664: my %host_servers = &Apache::loncommon::get_library_servers
665: ($ENV{'request.role.domain'});
666: if (! exists($host_servers{$ENV{'form.course_home'}})) {
667: $r->print(&mt('Invalid home server for course').': '.
668: $ENV{'form.course_home'}.'</body></html>');
669: return;
670: }
671: my ($courseid,$crsudom,$crsunum);
672: $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum));
673:
674: #
675: # Make current user course adminstrator
676: #
677: my $end=undef;
678: my $addition='';
679: if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
680: $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.
681: &Apache::lonnet::assignrole(
682: $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
683: #
684: # Make additional user course administrator
685: #
686: if (($ccdomain) && ($ccuname)) {
687: $r->print(&mt('Assigning role of course coordinator to').' '.
688: $ccuname.' at '.$ccdomain.': '.
689: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
690: }
691: if ($ENV{'form.setkeys'}) {
692: $r->print(
693: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
694: }
695: # Flush the course logs so reverse user roles immediately updated
696: &Apache::lonnet::flushcourselogs();
697: $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
698: }
699:
700: sub construct_course {
701: my ($args,$logmsg,$courseid,$crsudom,$crsunum) = @_;
702: my $outcome;
703:
704: #
705: # Open course
706: #
707: my %cenv=();
708: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
709: $args->{'cdescr'},
710: $args->{'curl'},
711: $args->{'course_home'},
712: $args->{'nonstandard'},
713: $args->{'crscode'},
714: $args->{'ccuname'});
715:
716: # Note: The testing routines depend on this being output; see
717: # Utils::Course. This needs to at least be output as a comment
718: # if anyone ever decides to not show this, and Utils::Course::new
719: # will need to be suitably modified.
720: $outcome .= 'New LON-CAPA Course ID: '.$$courseid.'<br>';
721: #
722: # Check if created correctly
723: #
724: ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);
725: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
726: $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
727: #
728: # Are we cloning?
729: #
730: my $cloneid='';
731: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
732: $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
733: my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
734: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
735: if ($clonehome eq 'no_host') {
736: $outcome .=
737: '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>';
738: } else {
739: $outcome .=
740: '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>';
741: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
742: # Copy all files
743: ©coursefiles($cloneid,$$courseid);
744: # Restore URL
745: $cenv{'url'}=$oldcenv{'url'};
746: # Restore title
747: $cenv{'description'}=$oldcenv{'description'};
748: # restore grading mode
749: if (defined($oldcenv{'grading'})) {
750: $cenv{'grading'}=$oldcenv{'grading'};
751: }
752: # Mark as cloned
753: $cenv{'clonedfrom'}=$cloneid;
754: delete($cenv{'default_enrollment_start_date'});
755: delete($cenv{'default_enrollment_end_date'});
756: }
757: }
758: #
759: # Set environment (will override cloned, if existing)
760: #
761: my @sections = ();
762: my @xlists = ();
763: if ($args->{'crsid'}) {
764: $cenv{'courseid'}=$args->{'crsid'};
765: }
766: if ($args->{'crscode'}) {
767: $cenv{'internal.coursecode'}=$args->{'crscode'};
768: }
769: if ($args->{'ccuname'}) {
770: $cenv{'internal.courseowner'} = $args->{'ccuname'};
771: } else {
772: $cenv{'internal.courseowner'} = $args->{'curruser'};
773: }
774:
775: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
776: if ($args->{'crssections'}) {
777: $cenv{'internal.sectionnums'} = '';
778: if ($args->{'crssections'} =~ m/,/) {
779: @sections = split/,/,$args->{'crssections'};
780: } else {
781: $sections[0] = $args->{'crssections'};
782: }
783: if (@sections > 0) {
784: foreach my $item (@sections) {
785: my ($sec,$gp) = split/:/,$item;
786: my $class = $args->{'crscode'}.$sec;
787: my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$class,$cenv{'internal.courseowner'});
788: $cenv{'internal.sectionnums'} .= $item.',';
789: unless ($addcheck eq 'ok') {
790: push @badclasses, $class;
791: }
792: }
793: $cenv{'internal.sectionnums'} =~ s/,$//;
794: }
795: }
796: # do not hide course coordinator from staff listing,
797: # even if privileged
798: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
799: # add crosslistings
800: if ($args->{'crsxlist'}) {
801: $cenv{'internal.crosslistings'}='';
802: if ($args->{'crsxlist'} =~ m/,/) {
803: @xlists = split/,/,$args->{'crsxlist'};
804: } else {
805: $xlists[0] = $args->{'crsxlist'};
806: }
807: if (@xlists > 0) {
808: foreach my $item (@xlists) {
809: my ($xl,$gp) = split/:/,$item;
810: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
811: $cenv{'internal.crosslistings'} .= $item.',';
812: unless ($addcheck eq 'ok') {
813: push @badclasses, $xl;
814: }
815: }
816: $cenv{'internal.crosslistings'} =~ s/,$//;
817: }
818: }
819: if ($args->{'autoadds'}) {
820: $cenv{'internal.autoadds'}=$args->{'autoadds'};
821: }
822: if ($args->{'autodrops'}) {
823: $cenv{'internal.autodrops'}=$args->{'autodrops'};
824: }
825: if ($args->{'notify'}) {
826: if ($args->{'ccuname'}) {
827: $cenv{'internal.notifylist'} = $args->{'ccuname'}.'@'.$args->{'ccdomain'};
828: }
829: }
830: if (@badclasses > 0) {
831: my %lt=&Apache::lonlocal::texthash(
832: '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',
833: 'dnhr' => 'does not have rights to access enrollment in these classes',
834: 'adby' => 'as determined by the policies of your institution on access to official classlists'
835: );
836: $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
837: foreach (@badclasses) {
838: $outcome .= "<li>$_</li>\n";
839: }
840: $outcome .= "</ul><br /><br /></font>\n";
841: }
842: if ($args->{'no_end_date'}) {
843: $args->{'endaccess'} = 0;
844: }
845: $cenv{'internal.autostart'}=$args->{'enrollstart'};
846: $cenv{'internal.autoend'}=$args->{'enrollend'};
847: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
848: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
849: if ($args->{'showphotos'}) {
850: $cenv{'internal.showphotos'}=$args->{'showphotos'};
851: }
852: $cenv{'internal.authtype'} = $args->{'authtype'};
853: $cenv{'internal.autharg'} = $args->{'autharg'};
854: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
855: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
856: $outcome .= '<font color="red" size="+1">'.
857: &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>';
858: }
859: }
860: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
861: if ($args->{'setpolicy'}) {
862: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
863: }
864: if ($args->{'setcontent'}) {
865: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
866: }
867: }
868: if ($args->{'reshome'}) {
869: $cenv{'reshome'}=$args->{'reshome'}.'/';
870: $cenv{'reshome'}=~s/\/+$/\//;
871: }
872: #
873: # course has keyed access
874: #
875: if ($args->{'setkeys'}) {
876: $cenv{'keyaccess'}='yes';
877: }
878: # if specified, key authority is not course, but user
879: # only active if keyaccess is yes
880: if ($args->{'keyauth'}) {
881: $args->{'keyauth'}=~s/[^\w\@]//g;
882: if ($args->{'keyauth'}) {
883: $cenv{'keyauth'}=$args->{'keyauth'};
884: }
885: }
886:
887: if ($args->{'disresdis'}) {
888: $cenv{'pch.roles.denied'}='st';
889: }
890: if ($args->{'disablechat'}) {
891: $cenv{'plc.roles.denied'}='st';
892: }
893:
894: # Record we've not yet viewed the Course Initialization Helper for this
895: # course
896: $cenv{'course.helper.not.run'} = 1;
897: #
898: # Use new Randomseed
899: #
900: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
901: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
902: #
903: # The encryption code and receipt prefix for this course
904: #
905: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
906: $cenv{'internal.encpref'}=100+int(9*rand(99));
907: #
908: # By default, use standard grading
909: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
910:
911: $outcome .= ('<br />'.&mt('Setting environment').': '.
912: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
913: #
914: # Open all assignments
915: #
916: if ($args->{'openall'}) {
917: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
918: my %storecontent = ($storeunder => time,
919: $storeunder.'.type' => 'date_start');
920:
921: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
922: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
923: }
924: #
925: # Set first page
926: #
927: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
928: || ($cloneid)) {
929: $outcome .= &mt('Setting first resource').': ';
930: my ($errtext,$fatal)=
931: &Apache::londocs::mapread($$crsunum,$$crsudom,'default.sequence');
932: $outcome .= ($fatal?$errtext:'read ok').' - ';
933: my $title; my $url;
934: if ($args->{'firstres'} eq 'syl') {
935: $title='Syllabus';
936: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
937: } else {
938: $title='Navigate Contents';
939: $url='/adm/navmaps';
940: }
941: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
942: ($errtext,$fatal)=
943: &Apache::londocs::storemap($$crsunum,$$crsudom,'default.sequence');
944: $outcome .= ($fatal?$errtext:'write ok').'<br>';
945: }
946: return $outcome;
947: }
948:
949: # ===================================================================== Handler
950: sub handler {
951: my $r = shift;
952:
953: if ($r->header_only) {
954: &Apache::loncommon::content_type($r,'text/html');
955: $r->send_http_header;
956: return OK;
957: }
958:
959: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
960: &Apache::loncommon::content_type($r,'text/html');
961: $r->send_http_header;
962:
963: if ($ENV{'form.phase'} eq 'two') {
964: &create_course($r);
965: } else {
966: &print_course_creation_page($r);
967: }
968: } else {
969: $ENV{'user.error.msg'}=
970: "/adm/createcourse:ccc:0:0:Cannot create courses";
971: return HTTP_NOT_ACCEPTABLE;
972: }
973: return OK;
974: }
975:
976: 1;
977: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>