1: # The LearningOnline Network
2: # Create a course
3: #
4: # $Id: loncreatecourse.pm,v 1.104 2007/08/23 21:54:40 albertel 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::londocs;
37: use Apache::lonlocal;
38: use Apache::londropadd;
39: use Apache::lonclonecourse;
40: use LONCAPA::batchcreatecourse;
41: use LONCAPA;
42:
43: # ===================================================== Phase one: fill-in form
44:
45: sub print_course_creation_page {
46: my $r=shift;
47: my $crstype = 'Group';
48: if ($env{'form.phase'} eq 'courseone') {
49: $crstype = 'Course';
50: }
51: my $defdom=$env{'request.role.domain'};
52: my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
53: my $course_home = '<select name="course_home" size="1">'."\n";
54: foreach my $server (sort(keys(%host_servers))) {
55: $course_home .= qq{<option value="$server"};
56: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
57: $course_home .= " selected ";
58: }
59: $course_home .= qq{>$server $host_servers{$server}</option>};
60: }
61: $course_home .= "\n</select>\n";
62: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
63: my $cloneform=&Apache::loncommon::select_dom_form
64: ($env{'request.role.domain'},'clonedomain').
65: &Apache::loncommon::selectcourse_link
66: ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
67: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
68: my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform,
69: $javascript_validations);
70: if ($crstype eq 'Course') {
71: my $starttime = time;
72: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
73: $enroll_table = &Apache::londropadd::date_setting_table($starttime,
74: $endtime,'create_enrolldates');
75: $access_table = &Apache::londropadd::date_setting_table($starttime,
76: $endtime,'create_defaultdates');
77: ($krbdef,$krbdefdom) =
78: &Apache::loncommon::get_kerberos_defaults($defdom);
79: $javascript_validations=&Apache::londropadd::javascript_validations(
80: 'createcourse',$krbdefdom);
81: my %param = ( formname => 'document.ccrs',
82: kerb_def_dom => $krbdefdom,
83: kerb_def_auth => $krbdef
84: );
85: $krbform = &Apache::loncommon::authform_kerberos(%param);
86: $intform = &Apache::loncommon::authform_internal(%param);
87: $locform = &Apache::loncommon::authform_local(%param);
88: } else {
89: $javascript_validations = qq|
90: function validate(formname) {
91: if (formname.title == '') {
92: alert("A group title is required");
93: return;
94: }
95: if (formname.ccuname == '') {
96: alert("The username of the group coordinator is required");
97: }
98: formname.submit();
99: }
100: |;
101: }
102: my %lt=&Apache::lonlocal::texthash(
103: 'cinf' => "Course Information",
104: 'ctit' => "Course Title",
105: 'chsr' => "Course Home Server",
106: 'cidn' => "Course ID/Number",
107: 'opt' => "optional",
108: 'iinf' => "Institutional Information",
109: '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.",
110: 'ccod' => "Course Code",
111: 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
112: 'snid' => "Section Numbers and corresponding LON-CAPA section IDs",
113: 'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section ID to be used in LON-CAPA e.g., 001:1,002:2",
114: 'crcs' => "Crosslisted courses",
115: '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) sectionID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2",
116: 'crco' => "Course Content",
117: 'cncr' => "Completely new course",
118: 'cecr' => "Clone an existing course",
119: 'map' => "Map",
120: 'smap' => "Select Map",
121: 'sacr' => "Do NOT generate as standard course",
122: 'ocik' => "only check if you know what you are doing",
123: 'fres' => "First Resource",
124: 'stco' => "standard courses only",
125: 'blnk' => "Blank",
126: 'sllb' => "Syllabus",
127: 'navi' => "Navigate",
128: 'cid' => "Course ID",
129: 'dmn' => "Domain",
130: 'asov' => "Additional settings, if specified below, will override cloned settings",
131: 'assp' => "Assessment Parameters",
132: 'oaas' => "Open all assessments",
133: 'mssg' => "Messaging",
134: 'scpf' => "Set course policy feedback to Course Coordinator",
135: 'scfc' => "Set content feedback to Course Coordinator",
136: 'cmmn' => "Communication",
137: 'dsrd' => "Disable student resource discussion",
138: 'dsuc' => "Disable student use of chatrooms",
139: 'acco' => "Access Control",
140: 'snak' => "Students need access key to enter course",
141: 'kaut' =>
142: 'Key authority (<tt>id@domain</tt>) if other than course',
143: 'cc' => "Course Coordinator",
144: 'user' => "Username",
145: 'aens' => "Automated enrollment settings",
146: '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.",
147: 'aadd' => "Automated adds",
148: 'yes' => "Yes",
149: 'no' => "No",
150: 'audr' => "Automated drops",
151: 'dacu' => "Duration of automated classlist updates",
152: 'dacc' => "Default start and end dates for student access",
153: 'psam' => "Please select the authentication mechanism",
154: 'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
155: 'nech' => "Notification of enrollment changes",
156: 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
157: 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
158: 'irsp' => "Include retrieval of student photographs?",
159: 'rshm' => 'Resource Space Home',
160: 'cgrs' => "Course Group Settings",
161: 'cgrq' => "Set a quota for the total disk space available for storage of course group portfolio files.",
162: 'opco' => "Open Course",
163: 'ginf' => "Group Information",
164: 'gtit' => "Group Title",
165: 'ghsr' => "Group Home Server",
166: 'gidn' => "Group ID/Number",
167: 'grco' => "Group Content",
168: 'cngr' => "Completely new group",
169: 'cegr' => "Clone an existing group",
170: 'sagr' => "Do NOT generate as standard group",
171: 'stgo' => "standard groups only",
172: 'sgpf' => "Set group policy feedback to Group Coordinator",
173: 'scfg' => "Set content feedback to Group Coordinator",
174: 'dmrd' => "Disable member resource discussion",
175: 'dmuc' => "Disable member use of chatrooms",
176: 'mnak' => "Members need access key to enter group",
177: 'kaug' =>
178: 'Key authority (<tt>id@domain</tt>) if other than group',
179: 'gc' => "Group Coordinator",
180: 'gid' => "Group ID",
181: 'crgr' => "Create Group",
182: 'grts' => "Group Teams Settings",
183: 'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.",
184:
185: );
186: my $js = <<END;
187: <script type="text/javascript">
188: var editbrowser = null;
189: function openbrowser(formname,elementname) {
190: var url = '/res/?';
191: if (editbrowser == null) {
192: url += 'launch=1&';
193: }
194: url += 'catalogmode=interactive&';
195: url += 'mode=edit&';
196: url += 'form=' + formname + '&';
197: url += 'element=' + elementname + '&';
198: url += 'only=sequence' + '';
199: var title = 'Browser';
200: var options = 'scrollbars=1,resizable=1,menubar=0';
201: options += ',width=700,height=600';
202: editbrowser = open(url,title,options,'1');
203: editbrowser.focus();
204: }
205: $javascript_validations
206: </script>
207: $coursebrowserjs
208: END
209:
210: my %titles = &Apache::lonlocal::texthash(
211: courseone => 'Create a New Course',
212: groupone => 'Create a New Group',
213: );
214: my $start_page =
215: &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
216: my $end_page =
217: &Apache::loncommon::end_page();
218: my $crumbs =
219: &Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
220: 'Create_Course',undef,
221: 'Create_Courses');
222: $r->print($start_page.$crumbs);
223: if ($crstype eq 'Course') {
224: $r->print(<<ENDDOCUMENT);
225: <form action="/adm/createcourse" method="post" name="ccrs">
226: <h2>$lt{'cinf'}</h2>
227: <p>
228: <label><b>$lt{'ctit'}:</b>
229: <input type="text" size="50" name="title" /></label>
230: </p><p>
231: <label>
232: <b>$lt{'chsr'}:</b>$course_home
233: </label>
234: </p><p>
235: <label>
236: <b>$lt{'cidn'} ($lt{'opt'})</b>
237: <input type="text" size="30" name="crsid" />
238: </label>
239: </p><p>
240: <h2>$lt{'iinf'}</h2>
241: <p>
242: $lt{'stat'}
243: </p><p>
244: <label>
245: <b>$lt{'ccod'}</b>
246: <input type="text" size="30" name="crscode" />
247: </label>
248: <br/>
249: ($lt{'toin'})
250: </p><p>
251: <label>
252: <b>$lt{'snid'}</b>
253: <input type="text" size="30" name="crssections" />
254: </label>
255: <br/>
256: ($lt{'csli'})
257: </p><p>
258: <label>
259: <b>$lt{'crcs'}</b>
260: <input type="text" size="30" name="crsxlist" />
261: </label>
262: <br/>
263: ($lt{'cscs'})
264: </p>
265: <h2>$lt{'crco'}</h2>
266: <table border="2">
267: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
268: <tr><td>
269: <p>
270: <label>
271: <b>$lt{'map'}:</b>
272: <input type="text" size="50" name="topmap" />
273: </label>
274: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
275: </p><p>
276: <label for="nonstd"><b>$lt{'sacr'}</b></label>
277: <br />
278: ($lt{'ocik'}):
279: <input id="nonstd" type="checkbox" name="nonstandard" />
280: </p><p>
281: <b>$lt{'fres'}</b><br />($lt{'stco'}):
282: <label>
283: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
284: </label>
285:
286: <label>
287: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
288: </label>
289:
290: <label>
291: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
292: </label>
293: </p>
294: </td><td>
295: <label>
296: $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
297: </label>
298: <br />
299: <label>
300: $lt{'dmn'}: $cloneform
301: </label>
302: <br />
303: <br />
304: $lt{'asov'}.
305: </td></tr>
306: </table>
307: <h2>$lt{'assp'}</h2>
308: <p>
309: <label>
310: <b>$lt{'oaas'}: </b>
311: <input type="checkbox" name="openall" />
312: </label>
313: </p>
314: <h2>$lt{'mssg'}</h2>
315: <p>
316: <label>
317: <b>$lt{'scpf'}: </b>
318: <input type="checkbox" name="setpolicy" checked />
319: </label>
320: <br />
321: <label>
322: <b>$lt{'scfc'}: </b>
323: <input type="checkbox" name="setcontent" checked />
324: </label>
325: </p>
326: <h2>$lt{'cmmn'}</h2>
327: <p>
328: <label>
329: <b>$lt{'dsrd'}: </b>
330: <input type="checkbox" name="disresdis" />
331: </label>
332: <br />
333: <label>
334: <b>$lt{'dsuc'}: </b>
335: <input type="checkbox" name="disablechat" />
336: </label>
337: </p>
338: <h2>$lt{'acco'}</h2>
339: <p>
340: <label>
341: <b>$lt{'snak'}: </b>
342: <input type="checkbox" name="setkeys" />
343: </label>
344: <br />
345: <label>
346: <b>$lt{'kaut'}: </b>
347: <input type="text" size="30" name="keyauth" />
348: </label>
349: </p>
350: <h2>$lt{'rshm'}</h2>
351: <p>
352: <label>
353: <b>$lt{'rshm'}: </b>
354: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
355: </label>
356: </p>
357: <p>
358: <h2>$lt{'aens'}</h2>
359: $lt{'aesc'}
360: </p>
361: <p>
362: <b>$lt{'aadd'}</b>
363: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label>
364: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
365: </label>
366: </p><p>
367: <b>$lt{'audr'}</b>
368: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label>
369: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
370: </p><p>
371: <b>$lt{'dacu'}</b>
372: $enroll_table
373: </p><p>
374: <b>$lt{'dacc'}</b>
375: $access_table
376: <p></p>
377: <b>$lt{'psam'}.</b><br />
378: $lt{'pcda'}.
379: </p><p>
380: $krbform
381: <br />
382: $intform
383: <br />
384: $locform
385: </p><p>
386: <b>$lt{'nech'}</b><br />
387: $lt{'nccl'}<br/>
388: <label>
389: <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
390: </label>
391: <label>
392: <input type="radio" name="notify_owner" value="0" checked="true" />$lt{'no'}
393: </label>
394: <br />
395: $lt{'ndcl'}<br/>
396: <label>
397: <input type="radio" name="notify_dc" value="1" />$lt{'yes'}
398: </label>
399: <label>
400: <input type="radio" name="notify_dc" value="0" checked="true" />$lt{'no'}
401: </label>
402: </p><p>
403: <b>$lt{'irsp'}</b>
404: <label>
405: <input type="radio" name="showphotos" value="1" />$lt{'yes'}
406: </label>
407: <label>
408: <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
409: </label>
410: </p>
411: <p>
412: <h2>$lt{'cgrs'}</h2>
413: $lt{'cgrq'}
414: <input type="text" name="crsquota" value="20" size="6" />Mb
415: </p>
416: <hr />
417: <h2>$lt{'cc'}</h2>
418: <p>
419: <label>
420: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
421: </label>
422: </p><p>
423: <label>
424: <b>$lt{'dmn'}:</b> $domform
425: </label>
426: </p>
427: <p>
428: <input type="hidden" name="prevphase" value="courseone" />
429: <input type="hidden" name="phase" value="coursetwo" />
430: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
431: </p>
432: </form>
433: ENDDOCUMENT
434: } elsif ($crstype eq 'Group') {
435: $r->print(<<ENDDOCUMENT);
436: <form action="/adm/createcourse" method="post" name="ccrs">
437: <h2>$lt{'ginf'}</h2>
438: <p>
439: <label><b>$lt{'gtit'}:</b>
440: <input type="text" size="50" name="title" /></label>
441: </p><p>
442: <label>
443: <b>$lt{'ghsr'}:</b>$course_home
444: </label>
445: </p><p>
446: <label>
447: <b>$lt{'gidn'} ($lt{'opt'})</b>
448: <input type="text" size="30" name="crsid" />
449: </label>
450: </p>
451: <h2>$lt{'grco'}</h2>
452: <table border="2">
453: <tr><th>$lt{'cngr'}</th><th>$lt{'cegr'}</th></tr>
454: <tr><td>
455: <p>
456: <label>
457: <b>$lt{'map'}:</b>
458: <input type="text" size="50" name="topmap" />
459: </label>
460: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
461: </p><p>
462: <label for="nonstd"><b>$lt{'sagr'}</b></label>
463: <br />
464: ($lt{'ocik'}):
465: <input id="nonstd" type="checkbox" name="nonstandard" />
466: </p><p>
467: <b>$lt{'fres'}</b><br />($lt{'stgo'}):
468: <label>
469: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
470: </label>
471:
472: <label>
473: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
474: </label>
475:
476: <label>
477: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
478: </label>
479: </p>
480: </td><td>
481: <label>
482: $lt{'gid'}: <input type="text" size="25" name="clonecourse" value="" />
483: </label>
484: <br />
485: <label>
486: $lt{'dmn'}: $cloneform
487: </label>
488: <br />
489: <br />
490: $lt{'asov'}.
491: </td></tr>
492: </table>
493: </p>
494: <p>
495: <h2>$lt{'mssg'}</h2>
496: <p>
497: <label>
498: <b>$lt{'sgpf'}: </b>
499: <input type="checkbox" name="setpolicy" checked />
500: </label>
501: <br />
502: <label>
503: <b>$lt{'scfg'}: </b>
504: <input type="checkbox" name="setcontent" checked />
505: </label>
506: </p>
507: <h2>$lt{'cmmn'}</h2>
508: <p>
509: <label>
510: <b>$lt{'dmrd'}: </b>
511: <input type="checkbox" name="disresdis" />
512: </label>
513: <br />
514: <label>
515: <b>$lt{'dmuc'}: </b>
516: <input type="checkbox" name="disablechat" />
517: </label>
518: </p>
519: <h2>$lt{'acco'}</h2>
520: <p>
521: <label>
522: <b>$lt{'mnak'}: </b>
523: <input type="checkbox" name="setkeys" />
524: </label>
525: <br />
526: <label>
527: <b>$lt{'kaug'}: </b>
528: <input type="text" size="30" name="keyauth" />
529: </label>
530: </p>
531: <h2>$lt{'rshm'}</h2>
532: <p>
533: <label>
534: <b>$lt{'rshm'}: </b>
535: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
536: </label>
537: </p>
538: <p>
539: <h2>$lt{'grts'}</h2>
540: $lt{'grtq'}
541: <input type="text" name="crsquota" value="20" />Mb
542: </p>
543: <hr />
544: <h2>$lt{'gc'}</h2>
545: <p>
546: <label>
547: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
548: </label>
549: </p><p>
550: <label>
551: <b>$lt{'dmn'}:</b> $domform
552: </label>
553: </p>
554: <p>
555: <input type="hidden" name="prevphase" value="groupone" />
556: <input type="hidden" name="phase" value="grouptwo" />
557: <input type="button" onClick="validate(this.form)" value="$lt{'crgr'}" />
558: </p>
559: </form>
560: ENDDOCUMENT
561: }
562: $r->print($end_page);
563: }
564:
565: # ====================================================== Phase two: make course
566:
567: sub create_course {
568: my $r=shift;
569: my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
570: my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
571: my $crstype = 'Group';
572: my ($enrollstart,$enrollend,$startaccess,$endaccess);
573:
574: if ($env{'form.phase'} eq 'coursetwo') {
575: $crstype='Course';
576: $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
577: $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
578: }
579: $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
580: $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
581:
582: my $autharg;
583: my $authtype;
584:
585: if ($env{'form.login'} eq 'krb') {
586: $authtype = 'krb';
587: $authtype .=$env{'form.krbver'};
588: $autharg = $env{'form.krbarg'};
589: } elsif ($env{'form.login'} eq 'int') {
590: $authtype ='internal';
591: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
592: $autharg = $env{'form.intarg'};
593: }
594: } elsif ($env{'form.login'} eq 'loc') {
595: $authtype = 'localauth';
596: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
597: $autharg = $env{'form.locarg'};
598: }
599: }
600: my $logmsg;
601: my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
602: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
603:
604: $r->print($start_page.$crumbs);
605:
606: my $args = {
607: crstype => $crstype,
608: ccuname => $ccuname,
609: ccdomain => $ccdomain,
610: cdescr => $env{'form.title'},
611: curl => $env{'form.topmap'},
612: course_domain => $env{'request.role.domain'},
613: course_home => $env{'form.course_home'},
614: nonstandard => $env{'form.nonstandard'},
615: crscode => $env{'form.crscode'},
616: crsquota => $env{'form.crsquota'},
617: clonecourse => $env{'form.clonecourse'},
618: clonedomain => $env{'form.clonedomain'},
619: crsid => $env{'form.crsid'},
620: curruser => $env{'user.name'}.':'.$env{'user.domain'},
621: crssections => $env{'form.crssections'},
622: crsxlist => $env{'form.crsxlist'},
623: autoadds => $env{'form.autoadds'},
624: autodrops => $env{'form.autodrops'},
625: notify_owner => $env{'form.notify_owner'},
626: notify_dc => $env{'form.notify_dc'},
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>'.&Apache::loncommon::end_page());
661: return;
662: }
663: # Check the proposed home server for the course
664: my %host_servers =
665: &Apache::lonnet::get_servers($env{'request.role.domain'},'library');
666: if (! exists($host_servers{$env{'form.course_home'}})) {
667: $r->print(&mt('Invalid home server for course').': '.
668: $env{'form.course_home'}.&Apache::loncommon::end_page());
669: return;
670: }
671: my ($courseid,$crsudom,$crsunum);
672: my ($success,$output) =
673: &Apache::loncommon::construct_course($args,\$logmsg,\$courseid,
674: \$crsudom,\$crsunum,
675: $env{'user.domain'},
676: $env{'user.name'});
677: $r->print($output);
678: if ($success) {
679: #
680: # Make the requested user a course coordinator or group coordinator
681: #
682: if (($ccdomain) && ($ccuname)) {
683: $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]: ',
684: $crstype,$ccuname,$ccdomain).
685: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
686: '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>');
695: }
696: $r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
697: &mt('Create Another [_1]',$crstype).'</a></p>'.
698: &Apache::loncommon::end_page());
699: }
700:
701: sub print_intro_page {
702: my $r = shift;
703: my $start_page =
704: &Apache::loncommon::start_page('Create a New Course or Group Space');
705: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
706: my $end_page =
707: &Apache::loncommon::end_page();
708: my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
709:
710: my @choices = ({ internal_name => 'courseone',
711: name => &mt('Create a single course'),
712: short_description =>
713: &mt('Create a new course by completing an online form.'),
714: },
715: { internal_name => 'groupone',
716: name => &mt('Create a single collaborative group space '),
717: short_description =>
718: &mt('Create a new group space for non-course use by completing an online form .'),
719: },
720: { internal_name => 'batchone',
721: name => &mt('Create courses/groups by uploading an attributes file'),
722: short_description =>
723: &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
724: help => 'Batch_Creation',
725: },
726: );
727: my $options;
728: foreach my $choice (@choices) {
729: $options .=' <h3><a href="/adm/createcourse?phase='.
730: $choice->{'internal_name'}.'" >'.
731: $choice->{'name'}.'</a>';
732: if (exists($choice->{'help'})) {
733: $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
734: }
735: $options .= "</h3>\n".' '.(' 'x8).$choice->{'short_description'}.
736: "\n";
737: }
738:
739: $r->print(<<ENDDOCUMENT);
740: $start_page
741: $crumbs
742: $options
743: $end_page
744: ENDDOCUMENT
745: }
746:
747: sub upload_batchfile {
748: my $r = shift;
749: my $start_page =
750: &Apache::loncommon::start_page('Create a New Course or Group Space');
751: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
752: my $end_page =
753: &Apache::loncommon::end_page();
754: $r->print($start_page.$crumbs);
755: $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
756: $r->print('<form name="batchcreate" method="post" '.
757: 'enctype="multipart/form-data" action="/adm/createcourse">'.
758: '<input type="file" name="coursecreatorxml" />'.
759: '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
760: '<input type="submit" name="batchsubmit" '.
761: 'value="Create Courses/Groups" /></form>');
762: $r->print($end_page);
763: return;
764: }
765:
766: sub process_batchfile {
767: my $r = shift;
768: my $start_page =
769: &Apache::loncommon::start_page('Create a New Course or Group Space');
770: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
771: my $end_page =
772: &Apache::loncommon::end_page();
773: my $defdom=$env{'request.role.domain'};
774: my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
775: 'batchupload',undef,undef,
776: undef,undef,$defdom);
777: my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
778: my ($result,$logmsg);
779: if (-e "$batchfilepath") {
780: open(FILE,"<$batchfilepath");
781: my @buffer = <FILE>;
782: close(FILE);
783: if ((defined($filename)) && (defined($batchdir))) {
784: my @requests = ($filename);
785: my %courseids = ();
786: ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
787: \@requests,\%courseids,'web',$defdom,
788: $env{'user.name'},$env{'user.domain'});
789: if ($result) {
790: if (!-e "$batchdir/processed") {
791: mkdir("$batchdir/processed", 0755);
792: open(FILE,">$batchdir/processed/$filename");
793: print FILE @buffer;
794: close(FILE);
795: if (-e "$batchdir/processed/$filename") {
796: unlink("$batchdir/pending/$filename");
797: }
798: }
799: }
800: }
801: }
802: $r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'.
803: &mt('Creation options menu').'</a>'.$end_page);
804:
805: }
806:
807: # ===================================================================== Handler
808: sub handler {
809: my $r = shift;
810:
811: if ($r->header_only) {
812: &Apache::loncommon::content_type($r,'text/html');
813: $r->send_http_header;
814: return OK;
815: }
816:
817: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
818: &Apache::loncommon::content_type($r,'text/html');
819: $r->send_http_header;
820:
821: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
822: ['phase']);
823: &Apache::lonhtmlcommon::clear_breadcrumbs();
824: &Apache::lonhtmlcommon::add_breadcrumb
825: ({href=>"/adm/createcourse",
826: text=>"Creation Options",
827: faq=>79,bug=>'Dom Coord Interface',});
828: if (($env{'form.phase'} eq 'coursetwo') ||
829: ($env{'form.phase'} eq 'grouptwo')) {
830: &Apache::lonhtmlcommon::add_breadcrumb
831: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
832: text=>&mt('[_1] Creation Settings',),
833: faq=>9,bug=>'Dom Coord Interface',});
834: &Apache::lonhtmlcommon::add_breadcrumb
835: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
836: text=>"Creation Outcome",
837: faq=>9,bug=>'Dom Coord Interface',});
838: &create_course($r);
839: } elsif (($env{'form.phase'} eq 'courseone') ||
840: ($env{'form.phase'} eq 'groupone')) {
841: &Apache::lonhtmlcommon::add_breadcrumb
842: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
843: text=>&mt('[_1] Creation Settings',),
844: faq=>9,bug=>'Dom Coord Interface',});
845: &print_course_creation_page($r);
846: } elsif ($env{'form.phase'} eq 'batchone') {
847: &Apache::lonhtmlcommon::add_breadcrumb
848: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
849: text=>"Upload Description File",
850: faq=>9,bug=>'Dom Coord Interface',});
851: &upload_batchfile($r);
852: } elsif ($env{'form.phase'} eq 'batchtwo') {
853: &Apache::lonhtmlcommon::add_breadcrumb
854: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
855: text=>"Upload Description File",
856: faq=>9,bug=>'Dom Coord Interface',});
857: &Apache::lonhtmlcommon::add_breadcrumb
858: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
859: text=>"Creation Outcome",
860: faq=>9,bug=>'Dom Coord Interface',});
861: &process_batchfile($r);
862: } else {
863: &print_intro_page($r);
864: }
865: } else {
866: $env{'user.error.msg'}=
867: "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
868: return HTTP_NOT_ACCEPTABLE;
869: }
870: return OK;
871: }
872:
873: 1;
874: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>