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