1: # The LearningOnline Network
2: # Create a course
3: #
4: # $Id: loncreatecourse.pm,v 1.126 2009/08/27 00:06:18 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: =head1 NAME
31:
32: Apache::loncreatecourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows domain coordinators to create new
37: courses and assign course coordinators.
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42: =head1 SUBROUTINES
43:
44: =over
45:
46: =item handler()
47:
48: =item print_course_creation_page()
49:
50: =item create_course()
51:
52: =item print_intro_page()
53:
54: =item upload_batchfile()
55:
56: =item process_batchfile()
57:
58: =back
59:
60: =cut
61:
62: package Apache::loncreatecourse;
63:
64: use strict;
65: use Apache::Constants qw(:common :http);
66: use Apache::lonnet;
67: use Apache::loncommon;
68: use Apache::londocs;
69: use Apache::lonlocal;
70: use Apache::lonuserutils;
71: use Apache::lonclonecourse;
72: use LONCAPA::batchcreatecourse;
73: use LONCAPA;
74:
75: # ===================================================== Phase one: fill-in form
76:
77: sub print_course_creation_page {
78: my $r=shift;
79: my $crstype = 'Community';
80: if ($env{'form.phase'} eq 'courseone') {
81: $crstype = 'Course';
82: }
83: my $defdom=$env{'request.role.domain'};
84: my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
85: my $course_home = '<select name="course_home" size="1">'."\n";
86: foreach my $server (sort(keys(%host_servers))) {
87: $course_home .= qq{<option value="$server"};
88: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
89: $course_home .= " selected ";
90: }
91: $course_home .= qq{>$server $host_servers{$server}</option>};
92: }
93: $course_home .= "\n</select>\n";
94: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
95: my $cloneform=&Apache::loncommon::select_dom_form
96: ($env{'request.role.domain'},'clonedomain').
97: &Apache::loncommon::selectcourse_link
98: ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
99: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
100: my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform,
101: $javascript_validations);
102: if ($crstype eq 'Course') {
103: my $starttime = time;
104: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
105: $enroll_table = &Apache::lonuserutils::date_setting_table($starttime,
106: $endtime,'create_enrolldates');
107: $access_table = &Apache::lonuserutils::date_setting_table($starttime,
108: $endtime,'create_defaultdates');
109: ($krbdef,$krbdefdom) =
110: &Apache::loncommon::get_kerberos_defaults($defdom);
111: $javascript_validations=&Apache::lonuserutils::javascript_validations(
112: 'createcourse',$krbdefdom);
113: my %param = ( formname => 'document.ccrs',
114: kerb_def_dom => $krbdefdom,
115: kerb_def_auth => $krbdef
116: );
117: $krbform = &Apache::loncommon::authform_kerberos(%param);
118: $intform = &Apache::loncommon::authform_internal(%param);
119: $locform = &Apache::loncommon::authform_local(%param);
120: } else {
121: my $title_alert = &mt('A Community title is required');
122: my $coord_alert = &mt('The username of the Coordinator is required');
123: $javascript_validations = qq|
124: function validate(formname) {
125: if (formname.title == '') {
126: alert("$title_alert");
127: return;
128: }
129: if (formname.ccuname == '') {
130: alert("$coord_alert");
131: }
132: formname.submit();
133: }
134: |;
135: }
136: my %lt=&Apache::lonlocal::texthash(
137: 'cinf' => "Course Information",
138: 'ctit' => "Course Title",
139: 'chsr' => "Course Home Server",
140: 'cidn' => "Course ID/Number",
141: 'opt' => "optional",
142: 'iinf' => "Institutional Information",
143: '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.",
144: 'ccod' => "Course Code",
145: 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
146: 'snid' => "Section Numbers and corresponding LON-CAPA section IDs",
147: '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",
148: 'crcs' => "Crosslisted courses",
149: '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",
150: 'crco' => "Course Content",
151: 'cncr' => "Completely new course",
152: 'cecr' => "Clone an existing course",
153: 'map' => "Map",
154: 'smap' => "Select Map",
155: 'sacr' => "Do NOT generate as standard course",
156: 'ocik' => "only check if you know what you are doing",
157: 'fres' => "First Resource",
158: 'stco' => "standard courses only",
159: 'blnk' => "Blank",
160: 'sllb' => "Syllabus",
161: 'navi' => "Navigate Contents",
162: 'cid' => "Course ID",
163: 'dmn' => "Domain",
164: 'dsh' => "Date Shift",
165: 'asov' => "Additional settings, if specified below, will override cloned settings",
166: 'ncd' => "Do not clone date parameters",
167: 'prd' => 'Clone date parameters as-is',
168: 'shd' => 'Shift date parameters by number of days',
169: 'assp' => "Assessment Parameters",
170: 'oaas' => "Open all assessments",
171: 'mssg' => "Messaging",
172: 'scpf' => "Set course policy feedback to Course Coordinator",
173: 'scfc' => "Set content feedback to Course Coordinator",
174: 'cmmn' => "Communication",
175: 'dsrd' => "Disable student resource discussion",
176: 'dsuc' => "Disable student use of chat rooms",
177: 'acco' => "Access Control",
178: 'snak' => "Students need access key to enter course",
179: 'kaut' =>
180: 'Key authority (<tt>id@domain</tt>) if other than course',
181: 'ow' => "Course Owner",
182: 'cc' => "(will be assigned Course Coordinator role)",
183: 'user' => "Username",
184: 'aens' => "Automated enrollment settings",
185: '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.",
186: 'aadd' => "Automated adds",
187: 'yes' => "Yes",
188: 'no' => "No",
189: 'audr' => "Automated drops",
190: 'dacu' => "Duration of automated classlist updates",
191: 'dads' => 'Default Access Dates for Students',
192: 'dacc' => "Default start and end dates for student access",
193: 'psam' => "Please select the Authentication mechanism",
194: 'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
195: 'nech' => "Notification of enrollment changes",
196: 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
197: 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
198: 'irsp' => "Include retrieval of student photographs?",
199: 'rshm' => 'Resource Space Home',
200: 'cgrs' => "Course Group Settings",
201: 'cgrq' => 'Set a quota for the total disk space available for storage of course group portfolio files',
202: 'opco' => "Open Course",
203: 'ginf' => "Community Information",
204: 'gtit' => "Community Title",
205: 'ghsr' => "Community Home Server",
206: 'gidn' => "Community ID/Number",
207: 'grco' => "Community Content",
208: 'cngr' => "Completely new community",
209: 'cegr' => "Clone an existing community",
210: 'sagr' => "Do NOT generate as standard community",
211: 'stgo' => "standard communities only",
212: 'sgpf' => "Set community policy feedback to Coordinator",
213: 'scfg' => "Set content feedback to Coordinator",
214: 'dmrd' => "Disable member resource discussion",
215: 'dmuc' => "Disable member use of chat rooms",
216: 'mnak' => "Members need access key to enter community",
217: 'kaug' =>
218: 'Key authority (<tt>id@domain</tt>) if other than community',
219: 'co' => "Community Owner",
220: 'gc' => "(will be assigned Coordinator role)",
221: 'gid' => "Community ID",
222: 'crgr' => "Create Community",
223: 'grts' => "Community Group Settings",
224: 'grtq' => "Set a quota for the total disk space available for storage of community group portfolio files.",
225:
226: );
227: my $js = <<END;
228: <script type="text/javascript">
229: var editbrowser = null;
230: function openbrowser(formname,elementname) {
231: var url = '/res/?';
232: if (editbrowser == null) {
233: url += 'launch=1&';
234: }
235: url += 'catalogmode=interactive&';
236: url += 'mode=edit&';
237: url += 'form=' + formname + '&';
238: url += 'element=' + elementname + '&';
239: url += 'only=sequence' + '';
240: var title = 'Browser';
241: var options = 'scrollbars=1,resizable=1,menubar=0';
242: options += ',width=700,height=600';
243: editbrowser = open(url,title,options,'1');
244: editbrowser.focus();
245: }
246: $javascript_validations
247: </script>
248: $coursebrowserjs
249: END
250:
251: my %titles = &Apache::lonlocal::texthash(
252: courseone => 'Create a New Course',
253: groupone => 'Create a New Community',
254: );
255: my $start_page =
256: &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
257: my $end_page =
258: &Apache::loncommon::end_page();
259: my $crumbs =
260: &Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
261: 'Create_Course',undef,
262: 'Create_Courses');
263: $r->print($start_page.$crumbs);
264:
265: if ($crstype eq 'Course') {
266: $r->print('<form action="/adm/createcourse" method="post" name="ccrs"><div class="LC_createcourse">'
267: .&Apache::lonhtmlcommon::start_pick_box()
268:
269: .&Apache::lonhtmlcommon::row_headline()
270: .'<h3>'.$lt{'ow'}.' '.$lt{'cc'}.'</h3>'
271: .&Apache::lonhtmlcommon::row_closure()
272:
273: .&Apache::lonhtmlcommon::row_title($lt{'user'})
274: .'<input type="text" size="15" name="ccuname" />'
275: .&Apache::loncommon::studentbrowser_javascript()
276: .&Apache::loncommon::selectstudent_link('ccrs','ccuname','ccdomain')
277: .&Apache::lonhtmlcommon::row_closure()
278:
279: .&Apache::lonhtmlcommon::row_title($lt{'dmn'},"","LC_odd_row_value")
280: .$domform
281: .&Apache::lonhtmlcommon::row_closure()
282:
283: .&Apache::lonhtmlcommon::row_headline()
284: .'<h3>'.$lt{'cinf'}.'</h3>'
285: .&Apache::lonhtmlcommon::row_closure()
286:
287: .&Apache::lonhtmlcommon::row_title($lt{'ctit'})
288: .'<input type="text" size="50" name="title" />'
289: .&Apache::lonhtmlcommon::row_closure()
290:
291: .&Apache::lonhtmlcommon::row_title($lt{'chsr'})
292: .$course_home
293: .&Apache::lonhtmlcommon::row_closure()
294:
295: .&Apache::lonhtmlcommon::row_title($lt{'cidn'}.' ('.$lt{'opt'}.')')
296: .'<input type="text" size="30" name="crsid" />'
297: .&Apache::lonhtmlcommon::row_closure()
298:
299: .&Apache::lonhtmlcommon::row_headline()
300: .'<h3>'.$lt{'iinf'}.'</h3>'
301: .$lt{'stat'}
302: .&Apache::lonhtmlcommon::row_closure()
303:
304: .&Apache::lonhtmlcommon::row_title($lt{'ccod'})
305: .'<input type="text" size="30" name="crscode" />'
306: .'<br />('.$lt{'toin'}.')'
307: .&Apache::lonhtmlcommon::row_closure()
308:
309: .&Apache::lonhtmlcommon::row_title($lt{'snid'})
310: .'<input type="text" size="30" name="crssections" />'
311: .'<br />('.$lt{'csli'}.')'
312: .&Apache::lonhtmlcommon::row_closure()
313:
314: .&Apache::lonhtmlcommon::row_title($lt{'crcs'})
315: .'<input type="text" size="30" name="crsxlist" />'
316: .'<br />('.$lt{'cscs'}.')'
317: .&Apache::lonhtmlcommon::row_closure()
318: );
319:
320: # Table: New Course / Clone Course
321: $r->print(&Apache::lonhtmlcommon::row_headline()
322: .'<h3>'.$lt{'crco'}.'</h3>'
323: .&Apache::loncommon::start_data_table()
324: .&Apache::loncommon::start_data_table_header_row()
325: .'<th>'.$lt{'cncr'}.'</th>'
326: .'<th> '.&mt('or').' </th>'
327: .'<th>'.$lt{'cecr'}.'</th>'
328: .&Apache::loncommon::end_data_table_header_row()
329: .&Apache::loncommon::start_data_table_row()
330:
331: # New Course:
332: .'<td>'
333: .&Apache::lonhtmlcommon::start_pick_box()
334: .&Apache::lonhtmlcommon::row_title($lt{'map'})
335: .'<input type="text" size="50" name="topmap" />'
336: .'<a href="javascript:openbrowser(\'ccrs\',\'topmap\')">'.$lt{'smap'}.'</a>'
337: .&Apache::lonhtmlcommon::row_closure()
338: .&Apache::lonhtmlcommon::row_title('<label for="nonstd">'.$lt{'sacr'}.'</label>')
339: .'<input id="nonstd" type="checkbox" name="nonstandard" />'
340: .'<br />('.$lt{'ocik'}.')'
341: .&Apache::lonhtmlcommon::row_closure()
342: .&Apache::lonhtmlcommon::row_title($lt{'fres'})
343: .'<label>'
344: .'<input type="radio" name="firstres" value="blank" />'.$lt{'blnk'}
345: .'</label>'
346: .' '
347: .'<label>'
348: .'<input type="radio" name="firstres" value="syl" checked="checked" />'.$lt{'sllb'}
349: .'</label>'
350: .' '
351: .'<label>'
352: .'<input type="radio" name="firstres" value="nav" />'.$lt{'navi'}
353: .'</label>'
354: .'<br />('.$lt{'stco'}.')'
355: .&Apache::lonhtmlcommon::row_closure(1)
356: .&Apache::lonhtmlcommon::end_pick_box()
357:
358: .'<td> </td>'
359:
360: # Clone Course:
361: .'<td>'
362: .&Apache::lonhtmlcommon::start_pick_box()
363: .&Apache::lonhtmlcommon::row_title($lt{'cid'})
364: .'<label>'
365: .'<input type="text" size="25" name="clonecourse" value="" />'
366: .'</label>'
367: .&Apache::lonhtmlcommon::row_closure(1)
368: .&Apache::lonhtmlcommon::row_title($lt{'dmn'})
369: .'<label>'
370: .$cloneform
371: .'</label>'
372: .&Apache::lonhtmlcommon::row_closure()
373: .&Apache::lonhtmlcommon::row_title($lt{'dsh'})
374: .'<label>'
375: .'<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}
376: .'</label><br />'
377: .'<label>'
378: .'<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}
379: .'</label><br />'
380: .'<label>'
381: .'<input type="radio" name="datemode" value="shift" checked="checked" /> '.$lt{'shd'}
382: .'</label>'
383: .' <input type="text" size="5" name="dateshift" value="365" />'
384: .&Apache::lonhtmlcommon::row_closure()
385: .&Apache::lonhtmlcommon::row_headline()
386: .$lt{'asov'}
387: .&Apache::lonhtmlcommon::row_closure(1)
388: .&Apache::lonhtmlcommon::end_pick_box()
389: .'</td>'
390: .&Apache::loncommon::end_data_table_row()
391: .&Apache::loncommon::end_data_table()
392: .&Apache::lonhtmlcommon::row_closure()
393: );
394:
395: $r->print(&Apache::lonhtmlcommon::row_headline()
396: .'<h3>'.$lt{'dads'}.'</h3>'
397: .&Apache::lonhtmlcommon::row_closure()
398: .&Apache::lonhtmlcommon::row_title($lt{'dacc'})
399: .$access_table
400: .&Apache::lonhtmlcommon::row_closure()
401: );
402:
403: $r->print(&Apache::lonhtmlcommon::row_headline()
404: .'<h3>'.$lt{'assp'}.'</h3>'
405: .&Apache::lonhtmlcommon::row_closure()
406:
407: .&Apache::lonhtmlcommon::row_title($lt{'oaas'})
408: .'<input type="checkbox" name="openall" />'
409: .&Apache::lonhtmlcommon::row_closure()
410:
411: .&Apache::lonhtmlcommon::row_headline()
412: .'<h3>'.$lt{'mssg'}.'</h3>'
413: .&Apache::lonhtmlcommon::row_closure()
414:
415: .&Apache::lonhtmlcommon::row_title($lt{'scpf'})
416: .'<input type="checkbox" name="setpolicy" checked="checked" />'
417: .&Apache::lonhtmlcommon::row_closure()
418:
419: .&Apache::lonhtmlcommon::row_title($lt{'scfc'})
420: .'<input type="checkbox" name="setcontent" checked="checked" />'
421: .&Apache::lonhtmlcommon::row_closure()
422:
423: .&Apache::lonhtmlcommon::row_headline()
424: .'<h3>'.$lt{'cmmn'}.'</h3>'
425: .&Apache::lonhtmlcommon::row_closure()
426:
427: .&Apache::lonhtmlcommon::row_title($lt{'dsrd'})
428: .'<input type="checkbox" name="disresdis" />'
429: .&Apache::lonhtmlcommon::row_closure()
430:
431: .&Apache::lonhtmlcommon::row_title($lt{'dsuc'})
432: .'<input type="checkbox" name="disablechat" />'
433: .&Apache::lonhtmlcommon::row_closure()
434:
435: .&Apache::lonhtmlcommon::row_headline()
436: .'<h3>'.$lt{'acco'}.'</h3>'
437: .&Apache::lonhtmlcommon::row_closure()
438:
439: .&Apache::lonhtmlcommon::row_title($lt{'snak'})
440: .'<input type="checkbox" name="setkeys" />'
441: .&Apache::lonhtmlcommon::row_closure()
442:
443: .&Apache::lonhtmlcommon::row_title($lt{'kaut'})
444: .'<input type="text" size="30" name="keyauth" />'
445: .&Apache::lonhtmlcommon::row_closure()
446:
447: .&Apache::lonhtmlcommon::row_headline()
448: .'<h3>'.$lt{'rshm'}.'</h3>'
449: .&Apache::lonhtmlcommon::row_closure()
450:
451: .&Apache::lonhtmlcommon::row_title($lt{'rshm'})
452: .'<input type="text" name="reshome" size="30" value="/res/'.$defdom.'/" />'
453: .&Apache::lonhtmlcommon::row_closure()
454:
455: .&Apache::lonhtmlcommon::row_headline()
456: .'<h3>'.$lt{'aens'}.'</h3>'
457: .&Apache::lonhtmlcommon::row_closure()
458:
459: .&Apache::lonhtmlcommon::row_title($lt{'aadd'})
460: .'<label><input type="radio" name="autoadds" value="1" />'.$lt{'yes'}.'</label>'
461: .'<label><input type="radio" name="autoadds" value="0" checked="checked" />'.$lt{'no'}.'</label>'
462: .&Apache::lonhtmlcommon::row_closure()
463:
464: .&Apache::lonhtmlcommon::row_title($lt{'audr'})
465: .'<label><input type="radio" name="autodrops" value="1" />'.$lt{'yes'}.'</label>'
466: .'<label><input type="radio" name="autodrops" value="0" checked="checked" />'.$lt{'no'}.'</label>'
467: .&Apache::lonhtmlcommon::row_closure()
468:
469: .&Apache::lonhtmlcommon::row_title($lt{'dacu'})
470: .$enroll_table
471: .&Apache::lonhtmlcommon::row_closure()
472:
473: .&Apache::lonhtmlcommon::row_title($lt{'psam'})
474: .$lt{'pcda'}.'<br />'
475: .$krbform.'<br />'
476: .$intform.'<br />'
477: .$locform
478: .&Apache::lonhtmlcommon::row_closure()
479:
480: .&Apache::lonhtmlcommon::row_title($lt{'nech'})
481: .$lt{'nccl'}.'<br/>'
482: .'<label><input type="radio" name="notify_owner" value="1" />'.$lt{'yes'}.'</label>'
483: .'<label><input type="radio" name="notify_owner" value="0" checked="checked" />'.$lt{'no'}.'</label>'
484: .'<br />'
485: .$lt{'ndcl'}.'<br/>'
486: .'<label><input type="radio" name="notify_dc" value="1" />'.$lt{'yes'}.'</label>'
487: .'<label><input type="radio" name="notify_dc" value="0" checked="checked" />'.$lt{'no'}.'</label>'
488: .&Apache::lonhtmlcommon::row_closure()
489:
490: .&Apache::lonhtmlcommon::row_title($lt{'irsp'})
491: .'<label>'
492: .'<input type="radio" name="showphotos" value="1" />'.$lt{'yes'}
493: .'</label> '
494: .'<label>'
495: .'<input type="radio" name="showphotos" value="0" checked="checked" />'.$lt{'no'}
496: .'</label> '
497: .&Apache::lonhtmlcommon::row_closure()
498:
499: .&Apache::lonhtmlcommon::row_headline()
500: .'<h3>'.$lt{'cgrs'}.'</h3>'
501: .&Apache::lonhtmlcommon::row_closure()
502:
503: .&Apache::lonhtmlcommon::row_title($lt{'cgrq'})
504: .'<input type="text" name="crsquota" value="20" size="6" />Mb'
505: .&Apache::lonhtmlcommon::row_closure(1)
506:
507: .&Apache::lonhtmlcommon::end_pick_box()
508: );
509: $r->print(<<ENDDOCUMENT);
510: </div>
511: <p>
512: <input type="hidden" name="prevphase" value="courseone" />
513: <input type="hidden" name="phase" value="coursetwo" />
514: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
515: </p>
516: </form>
517: ENDDOCUMENT
518:
519: } elsif ($crstype eq 'Community') {
520: $r->print(<<ENDDOCUMENT);
521: <form action="/adm/createcourse" method="post" name="ccrs">
522: <h2>$lt{'co'} $lt{'gc'}</h2>
523: <p>
524: <label>
525: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
526: </label>
527: </p><p>
528: <label>
529: <b>$lt{'dmn'}:</b> $domform
530: </label>
531: </p>
532: <h2>$lt{'ginf'}</h2>
533: <p>
534: <label><b>$lt{'gtit'}:</b>
535: <input type="text" size="50" name="title" /></label>
536: </p><p>
537: <label>
538: <b>$lt{'ghsr'}:</b>$course_home
539: </label>
540: </p><p>
541: <label>
542: <b>$lt{'gidn'} ($lt{'opt'})</b>
543: <input type="text" size="30" name="crsid" />
544: </label>
545: </p>
546: <h2>$lt{'grco'}</h2>
547: <table border="2">
548: <tr><th>$lt{'cngr'}</th><th>$lt{'cegr'}</th></tr>
549: <tr><td>
550: <p>
551: <label>
552: <b>$lt{'map'}:</b>
553: <input type="text" size="50" name="topmap" />
554: </label>
555: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
556: </p><p>
557: <label for="nonstd"><b>$lt{'sagr'}</b></label>
558: <br />
559: ($lt{'ocik'}):
560: <input id="nonstd" type="checkbox" name="nonstandard" />
561: </p><p>
562: <b>$lt{'fres'}</b><br />($lt{'stgo'}):
563: <label>
564: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
565: </label>
566:
567: <label>
568: <input type="radio" name="firstres" value="syl" checked="checked" />$lt{'sllb'}
569: </label>
570:
571: <label>
572: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
573: </label>
574: </p>
575: </td><td>
576: <label>
577: $lt{'gid'}: <input type="text" size="25" name="clonecourse" value="" />
578: </label>
579: <br />
580: <label>
581: $lt{'dmn'}: $cloneform
582: </label>
583: <br />
584: <label><input type="radio" name="datemode" value="delete" /> $lt{'ncd'}</label><br />
585: <label><input type="radio" name="datemode" value="preserve" /> $lt{'prd'}</label><br />
586: <label><input type="radio" name="datemode" value="shift" checked="checked" /> $lt{'shd'}</label>
587: <input type="text" size="5" name="dateshift" value="365" /><br /> <br />
588: $lt{'asov'}.
589: </td></tr>
590: </table>
591: </p>
592: <p>
593: <h2>$lt{'mssg'}</h2>
594: <p>
595: <label>
596: <b>$lt{'sgpf'}: </b>
597: <input type="checkbox" name="setpolicy" checked="checked" />
598: </label>
599: <br />
600: <label>
601: <b>$lt{'scfg'}: </b>
602: <input type="checkbox" name="setcontent" checked="checked" />
603: </label>
604: </p>
605: <h2>$lt{'cmmn'}</h2>
606: <p>
607: <label>
608: <b>$lt{'dmrd'}: </b>
609: <input type="checkbox" name="disresdis" />
610: </label>
611: <br />
612: <label>
613: <b>$lt{'dmuc'}: </b>
614: <input type="checkbox" name="disablechat" />
615: </label>
616: </p>
617: <h2>$lt{'acco'}</h2>
618: <p>
619: <label>
620: <b>$lt{'mnak'}: </b>
621: <input type="checkbox" name="setkeys" />
622: </label>
623: <br />
624: <label>
625: <b>$lt{'kaug'}: </b>
626: <input type="text" size="30" name="keyauth" />
627: </label>
628: </p>
629: <h2>$lt{'rshm'}</h2>
630: <p>
631: <label>
632: <b>$lt{'rshm'}: </b>
633: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
634: </label>
635: </p>
636: <h2>$lt{'grts'}</h2>
637: <p>
638: $lt{'grtq'}
639: <input type="text" name="crsquota" value="20" />Mb
640: </p>
641: <hr />
642: <p>
643: <input type="hidden" name="prevphase" value="groupone" />
644: <input type="hidden" name="phase" value="grouptwo" />
645: <input type="button" onClick="validate(this.form)" value="$lt{'crgr'}" />
646: </p>
647: </form>
648: ENDDOCUMENT
649: }
650: $r->print($end_page);
651: }
652:
653: # ====================================================== Phase two: make course
654:
655: sub create_course {
656: my $r=shift;
657: my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
658: my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
659: my $crstype = 'Community';
660: my ($enrollstart,$enrollend,$startaccess,$endaccess);
661:
662: if ($env{'form.phase'} eq 'coursetwo') {
663: $crstype='Course';
664: $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
665: $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
666: }
667: $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
668: $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
669:
670: my $autharg;
671: my $authtype;
672:
673: if ($env{'form.login'} eq 'krb') {
674: $authtype = 'krb';
675: $authtype .=$env{'form.krbver'};
676: $autharg = $env{'form.krbarg'};
677: } elsif ($env{'form.login'} eq 'int') {
678: $authtype ='internal';
679: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
680: $autharg = $env{'form.intarg'};
681: }
682: } elsif ($env{'form.login'} eq 'loc') {
683: $authtype = 'localauth';
684: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
685: $autharg = $env{'form.locarg'};
686: }
687: }
688: my $logmsg;
689: my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
690: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
691:
692: $r->print($start_page.$crumbs);
693:
694: my $args = {
695: crstype => $crstype,
696: ccuname => $ccuname,
697: ccdomain => $ccdomain,
698: cdescr => $env{'form.title'},
699: curl => $env{'form.topmap'},
700: course_domain => $env{'request.role.domain'},
701: course_home => $env{'form.course_home'},
702: nonstandard => $env{'form.nonstandard'},
703: crscode => $env{'form.crscode'},
704: crsquota => $env{'form.crsquota'},
705: clonecourse => $env{'form.clonecourse'},
706: clonedomain => $env{'form.clonedomain'},
707: datemode => $env{'form.datemode'},
708: dateshift => $env{'form.dateshift'},
709: crsid => $env{'form.crsid'},
710: curruser => $env{'user.name'}.':'.$env{'user.domain'},
711: crssections => $env{'form.crssections'},
712: crsxlist => $env{'form.crsxlist'},
713: autoadds => $env{'form.autoadds'},
714: autodrops => $env{'form.autodrops'},
715: notify_owner => $env{'form.notify_owner'},
716: notify_dc => $env{'form.notify_dc'},
717: no_end_date => $env{'form.no_end_date'},
718: showphotos => $env{'form.showphotos'},
719: authtype => $authtype,
720: autharg => $autharg,
721: enrollstart => $enrollstart,
722: enrollend => $enrollend,
723: startaccess => $startaccess,
724: endaccess => $endaccess,
725: setpolicy => $env{'form.setpolicy'},
726: setcontent => $env{'form.setcontent'},
727: reshome => $env{'form.reshome'},
728: setkeys => $env{'form.setkeys'},
729: keyauth => $env{'form.keyauth'},
730: disresdis => $env{'form.disresdis'},
731: disablechat => $env{'form.disablechat'},
732: openall => $env{'form.openall'},
733: firstres => $env{'form.firstres'}
734: };
735:
736: #
737: # Verify data
738: #
739: # Check the veracity of the course coordinator
740: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
741: $r->print('<form action="/adm/createuser" method="post" name="crtuser">');
742: $r->print('<div class="LC_warning">'
743: .&mt('No such user [_1] at domain [_2].','<tt>'.$ccuname.'</tt>','<tt>'.$ccdomain.'</tt>')
744: .'</div>');
745: $r->print(&mt('Please click Back on your browser and select another user, or [_1]Create User[_2]'
746: , '<input type="hidden" name="phase" value="get_user_info" />'
747: .'<input type="hidden" name="ccuname" value="'.$ccuname.'" />'
748: .'<input type="hidden" name="ccdomain" value="'.$ccdomain.'" />'
749: .'<input name="userrole" type="submit" value="'
750: , '" />'
751: )
752: .'</form>'.&Apache::loncommon::end_page()
753: );
754: return;
755: }
756: # Check the proposed home server for the course
757: my %host_servers =
758: &Apache::lonnet::get_servers($env{'request.role.domain'},'library');
759: if (! exists($host_servers{$env{'form.course_home'}})) {
760: $r->print(&mt('Invalid home server for course: [_1]'
761: ,$env{'form.course_home'}.&Apache::loncommon::end_page()));
762: return;
763: }
764: my ($courseid,$crsudom,$crsunum);
765: my ($success,$output) =
766: &Apache::loncommon::construct_course($args,\$logmsg,\$courseid,
767: \$crsudom,\$crsunum,
768: $env{'user.domain'},
769: $env{'user.name'});
770: $r->print($output);
771: if ($success) {
772: #
773: # Make the requested user a course coordinator or group coordinator
774: #
775: if (($ccdomain) && ($ccuname)) {
776: $r->print(&mt('Assigning role of '.$crstype.' Coordinator to [_1]:',
777: ,'<i>'.$ccuname.':'.$ccdomain.'</i>')
778: .&Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
779: 'cc','','','','','createcourse').'<p>');
780: }
781: if ($env{'form.setkeys'}) {
782: $r->print(
783: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
784: }
785: # Flush the course logs so reverse user roles immediately updated
786: &Apache::lonnet::flushcourselogs();
787: $r->print('<p>'.&mt('Roles will be active at next login').'.</p>');
788: }
789: $r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
790: &mt("Create Another $crstype").'</a></p>'.
791: &Apache::loncommon::end_page());
792: }
793:
794: sub print_intro_page {
795: my $r = shift;
796: my $start_page =
797: &Apache::loncommon::start_page('Create a New Course or Community');
798: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
799: my $end_page =
800: &Apache::loncommon::end_page();
801: my $helplink=&Apache::loncommon::help_open_topic('Create_Course_Community',&mt('Help on Creating Courses and Communities'));
802:
803: my @choices = ({ internal_name => 'courseone',
804: name => &mt('Create a single course'),
805: short_description =>
806: &mt('Create a new course by completing an online form.'),
807: },
808: { internal_name => 'groupone',
809: name => &mt('Create a single community'),
810: short_description =>
811: &mt('Create a new collaborative community by completing an online form.'),
812: },
813: { internal_name => 'batchone',
814: name => &mt('Create courses/communities by uploading an attributes file'),
815: short_description =>
816: &mt('Upload an attributes file containing specifications for one or more courses or communities in XML format.'),
817: help => 'Batch_Creation',
818: },
819: { internal_name => 'requestdisplay',
820: name => &mt('Approve or reject course requests'),
821: short_description =>
822: &mt('Display course creation requests submitted by authorized users held pending approval by a Domain Coordinator.'),
823: },
824: );
825: my $options;
826: foreach my $choice (@choices) {
827: $options .=' <h3><a href="/adm/createcourse?phase='.
828: $choice->{'internal_name'}.'" >'.
829: $choice->{'name'}.'</a>';
830: if (exists($choice->{'help'})) {
831: $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
832: }
833: $options .= "</h3>\n".' '.(' 'x8).$choice->{'short_description'}.
834: "\n";
835: }
836:
837: $r->print(<<ENDDOCUMENT);
838: $start_page
839: $crumbs
840: $options
841: $end_page
842: ENDDOCUMENT
843: }
844:
845: sub upload_batchfile {
846: my $r = shift;
847: my $start_page =
848: &Apache::loncommon::start_page('Create a New Course or Community');
849: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Community Attributes File','Create_Course',undef,'Create_Courses');
850: my $end_page =
851: &Apache::loncommon::end_page();
852: $r->print($start_page.$crumbs);
853: $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
854: $r->print('<form name="batchcreate" method="post" '.
855: 'enctype="multipart/form-data" action="/adm/createcourse">'.
856: '<input type="file" name="coursecreatorxml" />'.
857: '<input type="hidden" name="phase" value="batchtwo" /><br /><br />'.
858: '<input type="submit" name="batchsubmit" '.
859: 'value="Create Courses/Communities" /></form>');
860: $r->print($end_page);
861: return;
862: }
863:
864: sub process_batchfile {
865: my $r = shift;
866: my $start_page =
867: &Apache::loncommon::start_page('Create a New Course or Community');
868: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
869: my $end_page =
870: &Apache::loncommon::end_page();
871: my $defdom=$env{'request.role.domain'};
872: my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
873: 'batchupload',undef,undef,
874: undef,undef,$defdom);
875: my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
876: my ($result,$logmsg);
877: if (-e "$batchfilepath") {
878: open(FILE,"<$batchfilepath");
879: my @buffer = <FILE>;
880: close(FILE);
881: if ((defined($filename)) && (defined($batchdir))) {
882: my @requests = ($filename);
883: my %courseids = ();
884: ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
885: \@requests,\%courseids,'web',$defdom,
886: $env{'user.name'},$env{'user.domain'});
887: if ($result) {
888: if (!-e "$batchdir/processed") {
889: mkdir("$batchdir/processed", 0755);
890: open(FILE,">$batchdir/processed/$filename");
891: print FILE @buffer;
892: close(FILE);
893: if (-e "$batchdir/processed/$filename") {
894: unlink("$batchdir/pending/$filename");
895: }
896: }
897: }
898: }
899: }
900: $r->print($start_page.$crumbs.$logmsg.$result.'<br /><a href="/adm/createcourse">'.
901: &mt('Creation options menu').'</a>'.$end_page);
902:
903: }
904:
905: sub courserequestbrowser_javascript {
906: return <<"ENDREQBRW";
907: <script type="text/javascript">
908: // <![CDATA[
909: var steditbrowser;
910: function opencoursereqdisplay(cdom,cnum) {
911: var url = '/adm/requestcourse?action=display';
912: url += '&showdom='+cdom+'&cnum='+cnum;
913: var title = 'Course_Request_Browser';
914: var options = 'scrollbars=1,resizable=1,menubar=0';
915: options += ',width=700,height=600';
916: var stdeditbrowser = open(url,title,options,'1');
917: stdeditbrowser.focus();
918: }
919: // ]]>
920: </script>
921: ENDREQBRW
922: }
923:
924:
925: # ===================================================================== Handler
926: sub handler {
927: my $r = shift;
928:
929: if ($r->header_only) {
930: &Apache::loncommon::content_type($r,'text/html');
931: $r->send_http_header;
932: return OK;
933: }
934:
935: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
936: &Apache::loncommon::content_type($r,'text/html');
937: $r->send_http_header;
938:
939: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
940: ['phase']);
941: &Apache::lonhtmlcommon::clear_breadcrumbs();
942: &Apache::lonhtmlcommon::add_breadcrumb
943: ({href=>"/adm/createcourse",
944: text=>"Creation Options",
945: faq=>79,bug=>'Dom Coord Interface',});
946: if (($env{'form.phase'} eq 'coursetwo') ||
947: ($env{'form.phase'} eq 'grouptwo')) {
948: &Apache::lonhtmlcommon::add_breadcrumb
949: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
950: text=>&mt('[_1] Creation Settings',),
951: faq=>9,bug=>'Dom Coord Interface',});
952: &Apache::lonhtmlcommon::add_breadcrumb
953: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
954: text=>"Creation Outcome",
955: faq=>9,bug=>'Dom Coord Interface',});
956: &create_course($r);
957: } elsif (($env{'form.phase'} eq 'courseone') ||
958: ($env{'form.phase'} eq 'groupone')) {
959: &Apache::lonhtmlcommon::add_breadcrumb
960: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
961: text=>&mt('[_1] Creation Settings',),
962: faq=>9,bug=>'Dom Coord Interface',});
963: &print_course_creation_page($r);
964: } elsif ($env{'form.phase'} eq 'batchone') {
965: &Apache::lonhtmlcommon::add_breadcrumb
966: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
967: text=>"Upload Description File",
968: faq=>9,bug=>'Dom Coord Interface',});
969: &upload_batchfile($r);
970: } elsif ($env{'form.phase'} eq 'batchtwo') {
971: &Apache::lonhtmlcommon::add_breadcrumb
972: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
973: text=>"Upload Description File",
974: faq=>9,bug=>'Dom Coord Interface',});
975: &Apache::lonhtmlcommon::add_breadcrumb
976: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
977: text=>"Creation Outcome",
978: faq=>9,bug=>'Dom Coord Interface',});
979: &process_batchfile($r);
980: } elsif ($env{'form.phase'} eq 'requestdisplay') {
981: &Apache::lonhtmlcommon::add_breadcrumb
982: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
983: text=>&mt('[_1] Display Request Queue',),
984: faq=>9,bug=>'Dom Coord Interface',});
985: my $js = &courserequestbrowser_javascript();
986: my $start_page=&Apache::loncommon::start_page('Display Requests',$js);
987: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Requests','Course_Request',undef,'Course_Request');
988: $r->print($start_page.$crumbs."\n".'<div>'.
989: &Apache::loncoursequeueadmin::display_queued_requests(
990: 'domain',$env{'request.role.domain'}).'</div>'.
991: &Apache::loncommon::end_page());
992: } elsif ($env{'form.phase'} eq 'requestchange') {
993:
994: &Apache::lonhtmlcommon::add_breadcrumb
995: ({href=>"/adm/createcourse?phase=requestdisplay",
996: text=>&mt('[_1] Display Request Queue',),
997: faq=>9,bug=>'Dom Coord Interface',},
998: {href=>"/adm/createcourse?phase=requestchange",
999: text=>&mt('[_1] Requests Updated',),
1000: faq=>9,bug=>'Dom Coord Interface',},);
1001: my $start_page=&Apache::loncommon::start_page('Update Requests Result');
1002: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Requests Updated','Course_Request',undef,'Course_Request');
1003: $r->print($start_page.$crumbs."\n".'<div>'.
1004: &Apache::loncoursequeueadmin::update_request_queue(
1005: 'domain',$env{'request.role.domain'}).'</div>'.
1006: &Apache::loncommon::end_page());
1007: } else {
1008: &print_intro_page($r);
1009: }
1010: } else {
1011: $env{'user.error.msg'}=
1012: "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
1013: return HTTP_NOT_ACCEPTABLE;
1014: }
1015: return OK;
1016: }
1017:
1018: 1;
1019: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>