Annotation of loncom/interface/loncreatecourse.pm, revision 1.102
1.65 raeburn 1: # The LearningOnline Network
1.1 www 2: # Create a course
1.5 albertel 3: #
1.102 ! raeburn 4: # $Id: loncreatecourse.pm,v 1.101 2007/03/03 01:40:28 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::londocs;
1.38 www 37: use Apache::lonlocal;
1.41 raeburn 38: use Apache::londropadd;
1.96 albertel 39: use Apache::lonclonecourse;
1.90 raeburn 40: use LONCAPA::batchcreatecourse;
1.89 www 41: use LONCAPA;
1.28 www 42:
1.2 www 43: # ===================================================== Phase one: fill-in form
44:
1.10 matthew 45: sub print_course_creation_page {
1.2 www 46: my $r=shift;
1.90 raeburn 47: my $crstype = 'Group';
48: if ($env{'form.phase'} eq 'courseone') {
49: $crstype = 'Course';
50: }
1.78 albertel 51: my $defdom=$env{'request.role.domain'};
1.101 albertel 52: my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
1.10 matthew 53: my $course_home = '<select name="course_home" size="1">'."\n";
54: foreach my $server (sort(keys(%host_servers))) {
1.14 matthew 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>};
1.10 matthew 60: }
61: $course_home .= "\n</select>\n";
1.9 matthew 62: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.32 www 63: my $cloneform=&Apache::loncommon::select_dom_form
1.78 albertel 64: ($env{'request.role.domain'},'clonedomain').
1.32 www 65: &Apache::loncommon::selectcourse_link
1.90 raeburn 66: ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
1.78 albertel 67: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.90 raeburn 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: }
1.46 sakharuk 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",
1.90 raeburn 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",
1.46 sakharuk 114: 'crcs' => "Crosslisted courses",
1.90 raeburn 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",
1.46 sakharuk 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",
1.56 www 141: 'kaut' =>
142: 'Key authority (<tt>id@domain</tt>) if other than course',
1.46 sakharuk 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",
1.60 raeburn 152: 'dacc' => "Default start and end dates for student access",
1.46 sakharuk 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?",
1.77 raeburn 157: 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
1.46 sakharuk 158: 'irsp' => "Include retrieval of student photographs?",
1.55 www 159: 'rshm' => 'Resource Space Home',
1.93 raeburn 160: 'cgrs' => "Course Group Settings",
161: 'cgrq' => "Set a quota for the total disk space available for storage of course group portfolio files.",
1.90 raeburn 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",
1.93 raeburn 182: 'grts' => "Group Teams Settings",
183: 'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.",
184:
1.46 sakharuk 185: );
1.86 albertel 186: my $js = <<END;
187: <script type="text/javascript">
1.6 matthew 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 + '&';
1.7 matthew 197: url += 'element=' + elementname + '&';
198: url += 'only=sequence' + '';
1.6 matthew 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: }
1.41 raeburn 205: $javascript_validations
1.6 matthew 206: </script>
1.32 www 207: $coursebrowserjs
1.86 albertel 208: END
209:
1.90 raeburn 210: my %titles = &Apache::lonlocal::texthash(
211: courseone => 'Create a New Course',
212: groupone => 'Create a New Group',
213: );
1.86 albertel 214: my $start_page =
1.90 raeburn 215: &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
1.86 albertel 216: my $end_page =
217: &Apache::loncommon::end_page();
1.91 albertel 218: my $crumbs =
219: &Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
220: 'Create_Course',undef,
221: 'Create_Courses');
1.90 raeburn 222: $r->print($start_page.$crumbs);
223: if ($crstype eq 'Course') {
224: $r->print(<<ENDDOCUMENT);
1.6 matthew 225: <form action="/adm/createcourse" method="post" name="ccrs">
1.46 sakharuk 226: <h2>$lt{'cinf'}</h2>
1.10 matthew 227: <p>
1.68 matthew 228: <label><b>$lt{'ctit'}:</b>
229: <input type="text" size="50" name="title" /></label>
1.10 matthew 230: </p><p>
1.68 matthew 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>
1.40 raeburn 239: </p><p>
1.46 sakharuk 240: <h2>$lt{'iinf'}</h2>
1.40 raeburn 241: <p>
1.46 sakharuk 242: $lt{'stat'}
1.40 raeburn 243: </p><p>
1.68 matthew 244: <label>
245: <b>$lt{'ccod'}</b>
246: <input type="text" size="30" name="crscode" />
247: </label>
248: <br/>
1.46 sakharuk 249: ($lt{'toin'})
1.40 raeburn 250: </p><p>
1.68 matthew 251: <label>
252: <b>$lt{'snid'}</b>
253: <input type="text" size="30" name="crssections" />
254: </label>
255: <br/>
1.46 sakharuk 256: ($lt{'csli'})
1.40 raeburn 257: </p><p>
1.68 matthew 258: <label>
259: <b>$lt{'crcs'}</b>
260: <input type="text" size="30" name="crsxlist" />
261: </label>
262: <br/>
1.46 sakharuk 263: ($lt{'cscs'})
1.13 www 264: </p>
1.46 sakharuk 265: <h2>$lt{'crco'}</h2>
1.32 www 266: <table border="2">
1.46 sakharuk 267: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
1.32 www 268: <tr><td>
1.13 www 269: <p>
1.68 matthew 270: <label>
271: <b>$lt{'map'}:</b>
272: <input type="text" size="50" name="topmap" />
273: </label>
1.46 sakharuk 274: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
1.10 matthew 275: </p><p>
1.68 matthew 276: <label for="nonstd"><b>$lt{'sacr'}</b></label>
277: <br />
1.46 sakharuk 278: ($lt{'ocik'}):
1.68 matthew 279: <input id="nonstd" type="checkbox" name="nonstandard" />
280: </p><p>
1.46 sakharuk 281: <b>$lt{'fres'}</b><br />($lt{'stco'}):
1.68 matthew 282: <label>
283: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
284: </label>
1.13 www 285:
1.68 matthew 286: <label>
287: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
288: </label>
1.13 www 289:
1.68 matthew 290: <label>
291: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
292: </label>
1.13 www 293: </p>
1.32 www 294: </td><td>
1.68 matthew 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>
1.32 www 302: <br />
1.68 matthew 303: <br />
1.46 sakharuk 304: $lt{'asov'}.
1.32 www 305: </td></tr>
306: </table>
1.46 sakharuk 307: <h2>$lt{'assp'}</h2>
1.13 www 308: <p>
1.68 matthew 309: <label>
310: <b>$lt{'oaas'}: </b>
311: <input type="checkbox" name="openall" />
312: </label>
1.13 www 313: </p>
1.46 sakharuk 314: <h2>$lt{'mssg'}</h2>
1.13 www 315: <p>
1.68 matthew 316: <label>
317: <b>$lt{'scpf'}: </b>
318: <input type="checkbox" name="setpolicy" checked />
319: </label>
1.55 www 320: <br />
1.68 matthew 321: <label>
322: <b>$lt{'scfc'}: </b>
323: <input type="checkbox" name="setcontent" checked />
324: </label>
1.11 www 325: </p>
1.46 sakharuk 326: <h2>$lt{'cmmn'}</h2>
1.16 www 327: <p>
1.68 matthew 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>
1.16 www 337: </p>
1.46 sakharuk 338: <h2>$lt{'acco'}</h2>
1.18 www 339: <p>
1.68 matthew 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>
1.18 www 349: </p>
1.55 www 350: <h2>$lt{'rshm'}</h2>
351: <p>
1.68 matthew 352: <label>
353: <b>$lt{'rshm'}: </b>
354: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
355: </label>
1.55 www 356: </p>
1.10 matthew 357: <p>
1.46 sakharuk 358: <h2>$lt{'aens'}</h2>
359: $lt{'aesc'}
1.40 raeburn 360: </p>
361: <p>
1.46 sakharuk 362: <b>$lt{'aadd'}</b>
1.68 matthew 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>
1.40 raeburn 366: </p><p>
1.46 sakharuk 367: <b>$lt{'audr'}</b>
1.68 matthew 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>
1.40 raeburn 370: </p><p>
1.46 sakharuk 371: <b>$lt{'dacu'}</b>
1.60 raeburn 372: $enroll_table
1.40 raeburn 373: </p><p>
1.60 raeburn 374: <b>$lt{'dacc'}</b>
375: $access_table
376: <p></p>
1.46 sakharuk 377: <b>$lt{'psam'}.</b><br />
378: $lt{'pcda'}.
1.40 raeburn 379: </p><p>
380: $krbform
381: <br />
382: $intform
383: <br />
384: $locform
385: </p><p>
1.46 sakharuk 386: <b>$lt{'nech'}</b><br />
387: $lt{'nccl'}<br/>
1.68 matthew 388: <label>
1.77 raeburn 389: <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
1.68 matthew 390: </label>
391: <label>
1.77 raeburn 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'}
1.68 matthew 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>
1.55 www 410: </p>
1.93 raeburn 411: <p>
412: <h2>$lt{'cgrs'}</h2>
413: $lt{'cgrq'}
414: <input type="text" name="crsquota" value="20" size="6" />Mb
415: </p>
1.55 www 416: <hr />
417: <h2>$lt{'cc'}</h2>
418: <p>
1.68 matthew 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>
1.55 www 426: </p>
427: <p>
1.90 raeburn 428: <input type="hidden" name="prevphase" value="courseone" />
429: <input type="hidden" name="phase" value="coursetwo" />
1.68 matthew 430: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
1.10 matthew 431: </p>
1.2 www 432: </form>
433: ENDDOCUMENT
1.90 raeburn 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>
1.93 raeburn 538: <p>
539: <h2>$lt{'grts'}</h2>
540: $lt{'grtq'}
541: <input type="text" name="crsquota" value="20" />Mb
542: </p>
1.90 raeburn 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);
1.40 raeburn 563: }
564:
1.2 www 565: # ====================================================== Phase two: make course
566:
1.10 matthew 567: sub create_course {
1.2 www 568: my $r=shift;
1.99 albertel 569: my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
570: my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
1.90 raeburn 571: my $crstype = 'Group';
572: my ($enrollstart,$enrollend,$startaccess,$endaccess);
1.74 raeburn 573:
1.90 raeburn 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');
1.74 raeburn 581:
582: my $autharg;
583: my $authtype;
1.102 ! raeburn 584: my ($clonecourse,$clonedomain,$clonemsg);
! 585:
! 586: if (($env{'form.clonecourse'} ne '') && ($env{'form.clonedomain'} ne '')) {
! 587: my $clonehome=&Apache::lonnet::homeserver($env{'form.clonecourse'},$env{'form.clonedomain'});
! 588: if ($clonehome eq 'no_host') {
! 589: $clonemsg = &mt('The new course was not cloned from an existing course because the requested course from which to create the clone does not appear to be a valid course.');
! 590: } else {
! 591: my %clonedesc = &Apache::lonnet::coursedescription($env{'form.clonedomain'}.'_'.$env{'form.clonecourse'},{'one_time' => 1});
! 592: if ($env{'request.role.domain'} eq $env{'form.clonedomain'}) {
! 593: $clonecourse = $env{'form.clonecourse'};
! 594: $clonedomain = $env{'form.clonedomain'};
! 595: } else {
! 596: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
! 597: $env{'form.clonedomain'},$env{'form.clonecourse'});
! 598: my @cloners = split(/,/,$clonehash{'cloners'});
! 599: my %roleshash =
! 600: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
! 601: ['active'],['cc'],[$env{'form.clonedomain'}]);
! 602: if (($roleshash{$env{'form.clonecourse'}.':'.$env{'form.clonedomain'}.':cc'}) || (grep(/^\Q$ccuname\E:\Q$ccdomain\E$/,@cloners))) {
! 603: $clonecourse = $env{'form.clonecourse'};
! 604: $clonedomain = $env{'form.clonedomain'};
! 605: } else {
! 606: $clonemsg = &mt('The new course was not cloned from an existing course because the course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$ccuname.':'.$ccdomain,$clonedesc{'description'});
! 607: }
! 608: }
! 609: }
! 610: }
1.74 raeburn 611:
1.78 albertel 612: if ($env{'form.login'} eq 'krb') {
1.74 raeburn 613: $authtype = 'krb';
1.78 albertel 614: $authtype .=$env{'form.krbver'};
615: $autharg = $env{'form.krbarg'};
616: } elsif ($env{'form.login'} eq 'int') {
1.74 raeburn 617: $authtype ='internal';
1.78 albertel 618: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
619: $autharg = $env{'form.intarg'};
1.74 raeburn 620: }
1.78 albertel 621: } elsif ($env{'form.login'} eq 'loc') {
1.74 raeburn 622: $authtype = 'localauth';
1.78 albertel 623: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
624: $autharg = $env{'form.locarg'};
1.74 raeburn 625: }
626: }
1.90 raeburn 627: my $logmsg;
1.91 albertel 628: my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
1.90 raeburn 629: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
1.74 raeburn 630:
1.90 raeburn 631: $r->print($start_page.$crumbs);
1.74 raeburn 632:
633: my $args = {
1.90 raeburn 634: crstype => $crstype,
1.74 raeburn 635: ccuname => $ccuname,
636: ccdomain => $ccdomain,
1.78 albertel 637: cdescr => $env{'form.title'},
638: curl => $env{'form.topmap'},
639: course_domain => $env{'request.role.domain'},
640: course_home => $env{'form.course_home'},
641: nonstandard => $env{'form.nonstandard'},
642: crscode => $env{'form.crscode'},
1.93 raeburn 643: crsquota => $env{'form.crsquota'},
1.102 ! raeburn 644: clonecourse => $clonecourse,
! 645: clonedomain => $clonedomain,
1.78 albertel 646: crsid => $env{'form.crsid'},
1.94 raeburn 647: curruser => $env{'user.name'}.':'.$env{'user.domain'},
1.78 albertel 648: crssections => $env{'form.crssections'},
649: crsxlist => $env{'form.crsxlist'},
650: autoadds => $env{'form.autoadds'},
651: autodrops => $env{'form.autodrops'},
652: notify_owner => $env{'form.notify_owner'},
653: notify_dc => $env{'form.notify_dc'},
654: no_end_date => $env{'form.no_end_date'},
655: showphotos => $env{'form.showphotos'},
1.74 raeburn 656: authtype => $authtype,
657: autharg => $autharg,
658: enrollstart => $enrollstart,
659: enrollend => $enrollend,
660: startaccess => $startaccess,
661: endaccess => $endaccess,
1.78 albertel 662: setpolicy => $env{'form.setpolicy'},
663: setcontent => $env{'form.setcontent'},
664: reshome => $env{'form.reshome'},
665: setkeys => $env{'form.setkeys'},
666: keyauth => $env{'form.keyauth'},
667: disresdis => $env{'form.disresdis'},
668: disablechat => $env{'form.disablechat'},
669: openall => $env{'form.openall'},
670: firstres => $env{'form.firstres'}
1.74 raeburn 671: };
672:
1.10 matthew 673: #
674: # Verify data
675: #
676: # Check the veracity of the course coordinator
1.2 www 677: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52 albertel 678: $r->print('<form action="/adm/createuser" method="post" name="crtuser">');
679: $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
680: $r->print(&mt("Please click Back on your browser and select another user, or "));
681: $r->print('
682: <input type="hidden" name="phase" value="get_user_info" />
683: <input type="hidden" name="ccuname" value="'.$ccuname.'" />
684: <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
685: <input name="userrole" type="submit" value="'.
686: &mt('Create User').'" />
1.86 albertel 687: </form>'.&Apache::loncommon::end_page());
1.2 www 688: return;
689: }
1.10 matthew 690: # Check the proposed home server for the course
1.101 albertel 691: my %host_servers =
692: &Apache::lonnet::get_servers($env{'request.role.domain'},'library');
1.78 albertel 693: if (! exists($host_servers{$env{'form.course_home'}})) {
1.46 sakharuk 694: $r->print(&mt('Invalid home server for course').': '.
1.86 albertel 695: $env{'form.course_home'}.&Apache::loncommon::end_page());
1.10 matthew 696: return;
697: }
1.102 ! raeburn 698: if ($clonemsg ne '') {
! 699: $r->print('<p>'.$clonemsg.'</p>');
! 700: }
1.74 raeburn 701: my ($courseid,$crsudom,$crsunum);
1.96 albertel 702: $r->print(&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
1.74 raeburn 703:
704: #
1.90 raeburn 705: # Make the requested user a course coordinator or group coordinator
1.74 raeburn 706: #
1.90 raeburn 707: if (($ccdomain) && ($ccuname)) {
708: $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]:',
709: $crstype,$ccuname,$ccdomain).
710: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
711: 'cc').'<p>');
712: }
1.78 albertel 713: if ($env{'form.setkeys'}) {
1.74 raeburn 714: $r->print(
715: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
716: }
717: # Flush the course logs so reverse user roles immediately updated
718: &Apache::lonnet::flushcourselogs();
1.86 albertel 719: $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
1.100 www 720: '<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
1.90 raeburn 721: &mt('Create Another [_1]',$crstype).'</a></p>'.
1.86 albertel 722: &Apache::loncommon::end_page());
1.74 raeburn 723: }
724:
1.90 raeburn 725: sub print_intro_page {
726: my $r = shift;
727: my $start_page =
728: &Apache::loncommon::start_page('Create a New Course or Group Space');
729: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
730: my $end_page =
731: &Apache::loncommon::end_page();
732: my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
733:
734: my @choices = ({ internal_name => 'courseone',
735: name => &mt('Create a single course'),
736: short_description =>
737: &mt('Create a new course by completing an online form.'),
738: },
739: { internal_name => 'groupone',
740: name => &mt('Create a single collaborative group space '),
741: short_description =>
742: &mt('Create a new group space for non-course use by completing an online form .'),
743: },
744: { internal_name => 'batchone',
745: name => &mt('Create courses/groups by uploading an attributes file'),
746: short_description =>
747: &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
1.97 raeburn 748: help => 'Batch_Creation',
1.90 raeburn 749: },
750: );
751: my $options;
752: foreach my $choice (@choices) {
753: $options .=' <h3><a href="/adm/createcourse?phase='.
754: $choice->{'internal_name'}.'" >'.
1.97 raeburn 755: $choice->{'name'}.'</a>';
756: if (exists($choice->{'help'})) {
757: $options .= &Apache::loncommon::help_open_topic($choice->{'help'});
758: }
759: $options .= "</h3>\n".' '.(' 'x8).$choice->{'short_description'}.
1.90 raeburn 760: "\n";
761: }
762:
763: $r->print(<<ENDDOCUMENT);
764: $start_page
765: $crumbs
766: $options
767: $end_page
768: ENDDOCUMENT
769: }
770:
771: sub upload_batchfile {
772: my $r = shift;
773: my $start_page =
774: &Apache::loncommon::start_page('Create a New Course or Group Space');
775: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
776: my $end_page =
777: &Apache::loncommon::end_page();
778: $r->print($start_page.$crumbs);
779: $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
780: $r->print('<form name="batchcreate" method="post" '.
781: 'enctype="multipart/form-data" action="/adm/createcourse">'.
782: '<input type="file" name="coursecreatorxml" />'.
783: '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
784: '<input type="submit" name="batchsubmit" '.
785: 'value="Create Courses/Groups" /></form>');
786: $r->print($end_page);
787: return;
788: }
789:
790: sub process_batchfile {
791: my $r = shift;
792: my $start_page =
793: &Apache::loncommon::start_page('Create a New Course or Group Space');
794: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
795: my $end_page =
796: &Apache::loncommon::end_page();
797: my $defdom=$env{'request.role.domain'};
798: my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
799: 'batchupload',undef,undef,
800: undef,undef,$defdom);
801: my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
802: my ($result,$logmsg);
803: if (-e "$batchfilepath") {
804: open(FILE,"<$batchfilepath");
805: my @buffer = <FILE>;
806: close(FILE);
807: if ((defined($filename)) && (defined($batchdir))) {
808: my @requests = ($filename);
809: my %courseids = ();
810: ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
811: \@requests,\%courseids,'web',$defdom,
812: $env{'user.name'},$env{'user.domain'});
813: if ($result) {
814: if (!-e "$batchdir/processed") {
815: mkdir("$batchdir/processed", 0755);
816: open(FILE,">$batchdir/processed/$filename");
817: print FILE @buffer;
818: close(FILE);
819: if (-e "$batchdir/processed/$filename") {
820: unlink("$batchdir/pending/$filename");
821: }
822: }
823: }
824: }
825: }
826: $r->print($start_page.$crumbs.$result.$end_page);
827:
828: }
829:
1.2 www 830: # ===================================================================== Handler
1.1 www 831: sub handler {
832: my $r = shift;
833:
834: if ($r->header_only) {
1.38 www 835: &Apache::loncommon::content_type($r,'text/html');
1.1 www 836: $r->send_http_header;
837: return OK;
838: }
839:
1.78 albertel 840: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.38 www 841: &Apache::loncommon::content_type($r,'text/html');
1.1 www 842: $r->send_http_header;
843:
1.90 raeburn 844: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
845: ['phase']);
846: &Apache::lonhtmlcommon::clear_breadcrumbs();
847: &Apache::lonhtmlcommon::add_breadcrumb
848: ({href=>"/adm/createcourse",
849: text=>"Creation Options",
850: faq=>79,bug=>'Dom Coord Interface',});
851: if (($env{'form.phase'} eq 'coursetwo') ||
852: ($env{'form.phase'} eq 'grouptwo')) {
853: &Apache::lonhtmlcommon::add_breadcrumb
854: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
855: text=>&mt('[_1] Creation Settings',),
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',});
1.10 matthew 861: &create_course($r);
1.90 raeburn 862: } elsif (($env{'form.phase'} eq 'courseone') ||
863: ($env{'form.phase'} eq 'groupone')) {
864: &Apache::lonhtmlcommon::add_breadcrumb
865: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
866: text=>&mt('[_1] Creation Settings',),
867: faq=>9,bug=>'Dom Coord Interface',});
868: &print_course_creation_page($r);
869: } elsif ($env{'form.phase'} eq 'batchone') {
870: &Apache::lonhtmlcommon::add_breadcrumb
871: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
872: text=>"Upload Description File",
873: faq=>9,bug=>'Dom Coord Interface',});
874: &upload_batchfile($r);
875: } elsif ($env{'form.phase'} eq 'batchtwo') {
876: &Apache::lonhtmlcommon::add_breadcrumb
877: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
878: text=>"Upload Description File",
879: faq=>9,bug=>'Dom Coord Interface',});
880: &Apache::lonhtmlcommon::add_breadcrumb
881: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
882: text=>"Creation Outcome",
883: faq=>9,bug=>'Dom Coord Interface',});
884: &process_batchfile($r);
1.2 www 885: } else {
1.90 raeburn 886: &print_intro_page($r);
1.2 www 887: }
1.1 www 888: } else {
1.78 albertel 889: $env{'user.error.msg'}=
1.90 raeburn 890: "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
1.1 www 891: return HTTP_NOT_ACCEPTABLE;
892: }
893: return OK;
1.90 raeburn 894: }
1.1 www 895:
896: 1;
897: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>