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