Annotation of loncom/interface/loncreatecourse.pm, revision 1.93
1.65 raeburn 1: # The LearningOnline Network
1.1 www 2: # Create a course
1.5 albertel 3: #
1.93 ! raeburn 4: # $Id: loncreatecourse.pm,v 1.92 2006/06/22 11:25:56 www 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.90 raeburn 40: use LONCAPA::batchcreatecourse;
1.44 raeburn 41: use lib '/home/httpd/lib/perl';
1.89 www 42: use LONCAPA;
1.28 www 43:
44: # ================================================ Get course directory listing
45:
1.62 www 46: my @output=();
47:
1.28 www 48: sub crsdirlist {
49: my ($courseid,$which)=@_;
1.62 www 50: @output=();
51: return &innercrsdirlist($courseid,$which);
52: }
53:
54: sub innercrsdirlist {
55: my ($courseid,$which,$path)=@_;
56: my $dirptr=16384;
1.63 www 57: unless ($which) { $which=''; } else { $which.='/'; }
58: unless ($path) { $path=''; } else { $path.='/'; }
1.28 www 59: my %crsdata=&Apache::lonnet::coursedescription($courseid);
60: my @listing=&Apache::lonnet::dirlist
61: ($which,$crsdata{'domain'},$crsdata{'num'},
1.89 www 62: &propath($crsdata{'domain'},$crsdata{'num'}));
1.28 www 63: foreach (@listing) {
64: unless ($_=~/^\./) {
1.62 www 65: my @unpackline = split (/\&/,$_);
66: if ($unpackline[3]&$dirptr) {
67: # is a directory, recurse
1.63 www 68: &innercrsdirlist($courseid,$which.$unpackline[0],
69: $path.$unpackline[0]);
1.62 www 70: } else {
71: # is a file, put into output
1.63 www 72: push (@output,$path.$unpackline[0]);
1.62 www 73: }
1.28 www 74: }
75: }
76: return @output;
1.29 www 77: }
78:
79: # ============================================================= Read a userfile
80:
81: sub readfile {
82: my ($courseid,$which)=@_;
83: my %crsdata=&Apache::lonnet::coursedescription($courseid);
84: return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
85: $crsdata{'num'}.'/'.$which);
86: }
87:
88: # ============================================================ Write a userfile
89:
90: sub writefile {
1.78 albertel 91: (my $courseid, my $which,$env{'form.output'})=@_;
1.29 www 92: my %crsdata=&Apache::lonnet::coursedescription($courseid);
93: return &Apache::lonnet::finishuserfileupload(
94: $crsdata{'num'},$crsdata{'domain'},
95: 'output',$which);
96: }
97:
1.36 www 98: # ===================================================================== Rewrite
99:
100: sub rewritefile {
101: my ($contents,%rewritehash)=@_;
102: foreach (keys %rewritehash) {
103: my $pattern=$_;
104: $pattern=~s/(\W)/\\$1/gs;
105: my $new=$rewritehash{$_};
106: $contents=~s/$pattern/$new/gs;
107: }
108: return $contents;
109: }
110:
1.29 www 111: # ============================================================= Copy a userfile
112:
113: sub copyfile {
114: my ($origcrsid,$newcrsid,$which)=@_;
1.36 www 115: unless ($which=~/\.sequence$/) {
116: return &writefile($newcrsid,$which,
117: &readfile($origcrsid,$which));
118: } else {
119: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
120: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
121: return &writefile($newcrsid,$which,
122: &rewritefile(
123: &readfile($origcrsid,$which),
124: (
125: '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
1.66 albertel 126: => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/',
127: '/public/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
128: => '/public/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
1.36 www 129: )));
130: }
1.30 www 131: }
132:
133: # =============================================================== Copy a dbfile
134:
135: sub copydb {
136: my ($origcrsid,$newcrsid,$which)=@_;
137: $which=~s/\.db$//;
138: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
139: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
140: my %data=&Apache::lonnet::dump
141: ($which,$origcrsdata{'domain'},$origcrsdata{'num'});
1.72 albertel 142: foreach my $key (keys(%data)) {
143: if ($key=~/^internal./) { delete($data{$key}); }
144: }
1.30 www 145: return &Apache::lonnet::put
146: ($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
147: }
148:
1.35 www 149: # ========================================================== Copy resourcesdata
150:
151: sub copyresourcedb {
152: my ($origcrsid,$newcrsid)=@_;
153: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
154: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
155: my %data=&Apache::lonnet::dump
156: ('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
157: $origcrsid=~s/^\///;
158: $origcrsid=~s/\//\_/;
159: $newcrsid=~s/^\///;
160: $newcrsid=~s/\//\_/;
161: my %newdata=();
162: undef %newdata;
163: my $startdate=$data{$origcrsid.'.0.opendate'};
1.85 albertel 164: if (!$startdate) {
165: # now global start date for assements try the enrollment start
166: my %start=&Apache::lonnet::get('environment',
167: ['default_enrollment_start_date'],
168: $origcrsdata{'domain'},$origcrsdata{'num'});
169:
170: $startdate = $start{'default_enrollment_start_date'};
171: }
1.35 www 172: my $today=time;
173: my $delta=0;
174: if ($startdate) {
175: my $oneday=60*60*24;
176: $delta=$today-$startdate;
177: $delta=int($delta/$oneday)*$oneday;
178: }
179: # ugly retro fix for broken version of types
180: foreach (keys %data) {
181: if ($_=~/\wtype$/) {
182: my $newkey=$_;
183: $newkey=~s/type$/\.type/;
184: $data{$newkey}=$data{$_};
185: delete $data{$_};
186: }
187: }
1.37 www 188: # adjust symbs
189: my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
190: $pattern=~s/(\W)/\\$1/gs;
191: my $new= 'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
192: foreach (keys %data) {
193: if ($_=~/$pattern/) {
194: my $newkey=$_;
195: $newkey=~s/$pattern/$new/;
196: $data{$newkey}=$data{$_};
197: delete $data{$_};
198: }
199: }
1.35 www 200: # adjust dates
201: foreach (keys %data) {
202: my $thiskey=$_;
203: $thiskey=~s/^$origcrsid/$newcrsid/;
204: $newdata{$thiskey}=$data{$_};
1.75 albertel 205: if ($data{$_.'.type'}=~/^date_(start|end)$/) {
1.85 albertel 206: if ($delta > 0) {
207: $newdata{$thiskey}=$newdata{$thiskey}+$delta;
208: } else {
209: # no delta, it's unlikely we want the old dates and times
210: delete($newdata{$thiskey});
211: delete($newdata{$thiskey.'.type'});
212: }
1.35 www 213: }
214: }
215: return &Apache::lonnet::put
216: ('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
217: }
218:
1.30 www 219: # ========================================================== Copy all userfiles
220:
221: sub copyuserfiles {
222: my ($origcrsid,$newcrsid)=@_;
223: foreach (&crsdirlist($origcrsid,'userfiles')) {
1.69 albertel 224: if ($_ !~m|^scantron_|) {
225: ©file($origcrsid,$newcrsid,$_);
226: }
1.30 www 227: }
228: }
229: # ========================================================== Copy all userfiles
230:
231: sub copydbfiles {
232: my ($origcrsid,$newcrsid)=@_;
1.82 albertel 233:
234: my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|);
235: $origcrs_discussion=~s|/|_|g;
1.30 www 236: foreach (&crsdirlist($origcrsid)) {
237: if ($_=~/\.db$/) {
238: unless
1.88 albertel 239: ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|gradingqueue|reviewqueue|CODEs)/) {
1.30 www 240: ©db($origcrsid,$newcrsid,$_);
241: }
242: }
243: }
1.31 www 244: }
245:
246: # ======================================================= Copy all course files
247:
248: sub copycoursefiles {
249: my ($origcrsid,$newcrsid)=@_;
250: ©userfiles($origcrsid,$newcrsid);
251: ©dbfiles($origcrsid,$newcrsid);
1.35 www 252: ©resourcedb($origcrsid,$newcrsid);
1.28 www 253: }
1.13 www 254:
1.2 www 255: # ===================================================== Phase one: fill-in form
256:
1.10 matthew 257: sub print_course_creation_page {
1.2 www 258: my $r=shift;
1.90 raeburn 259: my $crstype = 'Group';
260: if ($env{'form.phase'} eq 'courseone') {
261: $crstype = 'Course';
262: }
1.78 albertel 263: my $defdom=$env{'request.role.domain'};
1.10 matthew 264: my %host_servers = &Apache::loncommon::get_library_servers($defdom);
265: my $course_home = '<select name="course_home" size="1">'."\n";
266: foreach my $server (sort(keys(%host_servers))) {
1.14 matthew 267: $course_home .= qq{<option value="$server"};
268: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
269: $course_home .= " selected ";
270: }
271: $course_home .= qq{>$server $host_servers{$server}</option>};
1.10 matthew 272: }
273: $course_home .= "\n</select>\n";
1.9 matthew 274: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.32 www 275: my $cloneform=&Apache::loncommon::select_dom_form
1.78 albertel 276: ($env{'request.role.domain'},'clonedomain').
1.32 www 277: &Apache::loncommon::selectcourse_link
1.90 raeburn 278: ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype);
1.78 albertel 279: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.90 raeburn 280: my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform,
281: $javascript_validations);
282: if ($crstype eq 'Course') {
283: my $starttime = time;
284: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
285: $enroll_table = &Apache::londropadd::date_setting_table($starttime,
286: $endtime,'create_enrolldates');
287: $access_table = &Apache::londropadd::date_setting_table($starttime,
288: $endtime,'create_defaultdates');
289: ($krbdef,$krbdefdom) =
290: &Apache::loncommon::get_kerberos_defaults($defdom);
291: $javascript_validations=&Apache::londropadd::javascript_validations(
292: 'createcourse',$krbdefdom);
293: my %param = ( formname => 'document.ccrs',
294: kerb_def_dom => $krbdefdom,
295: kerb_def_auth => $krbdef
296: );
297: $krbform = &Apache::loncommon::authform_kerberos(%param);
298: $intform = &Apache::loncommon::authform_internal(%param);
299: $locform = &Apache::loncommon::authform_local(%param);
300: } else {
301: $javascript_validations = qq|
302: function validate(formname) {
303: if (formname.title == '') {
304: alert("A group title is required");
305: return;
306: }
307: if (formname.ccuname == '') {
308: alert("The username of the group coordinator is required");
309: }
310: formname.submit();
311: }
312: |;
313: }
1.46 sakharuk 314: my %lt=&Apache::lonlocal::texthash(
315: 'cinf' => "Course Information",
316: 'ctit' => "Course Title",
317: 'chsr' => "Course Home Server",
318: 'cidn' => "Course ID/Number",
319: 'opt' => "optional",
320: 'iinf' => "Institutional Information",
321: '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.",
322: 'ccod' => "Course Code",
323: 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
1.90 raeburn 324: 'snid' => "Section Numbers and corresponding LON-CAPA section IDs",
325: '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 326: 'crcs' => "Crosslisted courses",
1.90 raeburn 327: '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 328: 'crco' => "Course Content",
329: 'cncr' => "Completely new course",
330: 'cecr' => "Clone an existing course",
331: 'map' => "Map",
332: 'smap' => "Select Map",
333: 'sacr' => "Do NOT generate as standard course",
334: 'ocik' => "only check if you know what you are doing",
335: 'fres' => "First Resource",
336: 'stco' => "standard courses only",
337: 'blnk' => "Blank",
338: 'sllb' => "Syllabus",
339: 'navi' => "Navigate",
340: 'cid' => "Course ID",
341: 'dmn' => "Domain",
342: 'asov' => "Additional settings, if specified below, will override cloned settings",
343: 'assp' => "Assessment Parameters",
344: 'oaas' => "Open all assessments",
345: 'mssg' => "Messaging",
346: 'scpf' => "Set course policy feedback to Course Coordinator",
347: 'scfc' => "Set content feedback to Course Coordinator",
348: 'cmmn' => "Communication",
349: 'dsrd' => "Disable student resource discussion",
350: 'dsuc' => "Disable student use of chatrooms",
351: 'acco' => "Access Control",
352: 'snak' => "Students need access key to enter course",
1.56 www 353: 'kaut' =>
354: 'Key authority (<tt>id@domain</tt>) if other than course',
1.46 sakharuk 355: 'cc' => "Course Coordinator",
356: 'user' => "Username",
357: 'aens' => "Automated enrollment settings",
358: '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.",
359: 'aadd' => "Automated adds",
360: 'yes' => "Yes",
361: 'no' => "No",
362: 'audr' => "Automated drops",
363: 'dacu' => "Duration of automated classlist updates",
1.60 raeburn 364: 'dacc' => "Default start and end dates for student access",
1.46 sakharuk 365: 'psam' => "Please select the authentication mechanism",
366: 'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
367: 'nech' => "Notification of enrollment changes",
368: 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
1.77 raeburn 369: 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
1.46 sakharuk 370: 'irsp' => "Include retrieval of student photographs?",
1.55 www 371: 'rshm' => 'Resource Space Home',
1.93 ! raeburn 372: 'cgrs' => "Course Group Settings",
! 373: 'cgrq' => "Set a quota for the total disk space available for storage of course group portfolio files.",
1.90 raeburn 374: 'opco' => "Open Course",
375: 'ginf' => "Group Information",
376: 'gtit' => "Group Title",
377: 'ghsr' => "Group Home Server",
378: 'gidn' => "Group ID/Number",
379: 'grco' => "Group Content",
380: 'cngr' => "Completely new group",
381: 'cegr' => "Clone an existing group",
382: 'sagr' => "Do NOT generate as standard group",
383: 'stgo' => "standard groups only",
384: 'sgpf' => "Set group policy feedback to Group Coordinator",
385: 'scfg' => "Set content feedback to Group Coordinator",
386: 'dmrd' => "Disable member resource discussion",
387: 'dmuc' => "Disable member use of chatrooms",
388: 'mnak' => "Members need access key to enter group",
389: 'kaug' =>
390: 'Key authority (<tt>id@domain</tt>) if other than group',
391: 'gc' => "Group Coordinator",
392: 'gid' => "Group ID",
393: 'crgr' => "Create Group",
1.93 ! raeburn 394: 'grts' => "Group Teams Settings",
! 395: 'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.",
! 396:
1.46 sakharuk 397: );
1.86 albertel 398: my $js = <<END;
399: <script type="text/javascript">
1.6 matthew 400: var editbrowser = null;
401: function openbrowser(formname,elementname) {
402: var url = '/res/?';
403: if (editbrowser == null) {
404: url += 'launch=1&';
405: }
406: url += 'catalogmode=interactive&';
407: url += 'mode=edit&';
408: url += 'form=' + formname + '&';
1.7 matthew 409: url += 'element=' + elementname + '&';
410: url += 'only=sequence' + '';
1.6 matthew 411: var title = 'Browser';
412: var options = 'scrollbars=1,resizable=1,menubar=0';
413: options += ',width=700,height=600';
414: editbrowser = open(url,title,options,'1');
415: editbrowser.focus();
416: }
1.41 raeburn 417: $javascript_validations
1.6 matthew 418: </script>
1.32 www 419: $coursebrowserjs
1.86 albertel 420: END
421:
1.90 raeburn 422: my %titles = &Apache::lonlocal::texthash(
423: courseone => 'Create a New Course',
424: groupone => 'Create a New Group',
425: );
1.86 albertel 426: my $start_page =
1.90 raeburn 427: &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js);
1.86 albertel 428: my $end_page =
429: &Apache::loncommon::end_page();
1.91 albertel 430: my $crumbs =
431: &Apache::lonhtmlcommon::breadcrumbs($crstype.' Information',
432: 'Create_Course',undef,
433: 'Create_Courses');
1.90 raeburn 434: $r->print($start_page.$crumbs);
435: if ($crstype eq 'Course') {
436: $r->print(<<ENDDOCUMENT);
1.6 matthew 437: <form action="/adm/createcourse" method="post" name="ccrs">
1.46 sakharuk 438: <h2>$lt{'cinf'}</h2>
1.10 matthew 439: <p>
1.68 matthew 440: <label><b>$lt{'ctit'}:</b>
441: <input type="text" size="50" name="title" /></label>
1.10 matthew 442: </p><p>
1.68 matthew 443: <label>
444: <b>$lt{'chsr'}:</b>$course_home
445: </label>
446: </p><p>
447: <label>
448: <b>$lt{'cidn'} ($lt{'opt'})</b>
449: <input type="text" size="30" name="crsid" />
450: </label>
1.40 raeburn 451: </p><p>
1.46 sakharuk 452: <h2>$lt{'iinf'}</h2>
1.40 raeburn 453: <p>
1.46 sakharuk 454: $lt{'stat'}
1.40 raeburn 455: </p><p>
1.68 matthew 456: <label>
457: <b>$lt{'ccod'}</b>
458: <input type="text" size="30" name="crscode" />
459: </label>
460: <br/>
1.46 sakharuk 461: ($lt{'toin'})
1.40 raeburn 462: </p><p>
1.68 matthew 463: <label>
464: <b>$lt{'snid'}</b>
465: <input type="text" size="30" name="crssections" />
466: </label>
467: <br/>
1.46 sakharuk 468: ($lt{'csli'})
1.40 raeburn 469: </p><p>
1.68 matthew 470: <label>
471: <b>$lt{'crcs'}</b>
472: <input type="text" size="30" name="crsxlist" />
473: </label>
474: <br/>
1.46 sakharuk 475: ($lt{'cscs'})
1.13 www 476: </p>
1.46 sakharuk 477: <h2>$lt{'crco'}</h2>
1.32 www 478: <table border="2">
1.46 sakharuk 479: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
1.32 www 480: <tr><td>
1.13 www 481: <p>
1.68 matthew 482: <label>
483: <b>$lt{'map'}:</b>
484: <input type="text" size="50" name="topmap" />
485: </label>
1.46 sakharuk 486: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
1.10 matthew 487: </p><p>
1.68 matthew 488: <label for="nonstd"><b>$lt{'sacr'}</b></label>
489: <br />
1.46 sakharuk 490: ($lt{'ocik'}):
1.68 matthew 491: <input id="nonstd" type="checkbox" name="nonstandard" />
492: </p><p>
1.46 sakharuk 493: <b>$lt{'fres'}</b><br />($lt{'stco'}):
1.68 matthew 494: <label>
495: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
496: </label>
1.13 www 497:
1.68 matthew 498: <label>
499: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
500: </label>
1.13 www 501:
1.68 matthew 502: <label>
503: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
504: </label>
1.13 www 505: </p>
1.32 www 506: </td><td>
1.68 matthew 507: <label>
508: $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
509: </label>
510: <br />
511: <label>
512: $lt{'dmn'}: $cloneform
513: </label>
1.32 www 514: <br />
1.68 matthew 515: <br />
1.46 sakharuk 516: $lt{'asov'}.
1.32 www 517: </td></tr>
518: </table>
1.46 sakharuk 519: <h2>$lt{'assp'}</h2>
1.13 www 520: <p>
1.68 matthew 521: <label>
522: <b>$lt{'oaas'}: </b>
523: <input type="checkbox" name="openall" />
524: </label>
1.13 www 525: </p>
1.46 sakharuk 526: <h2>$lt{'mssg'}</h2>
1.13 www 527: <p>
1.68 matthew 528: <label>
529: <b>$lt{'scpf'}: </b>
530: <input type="checkbox" name="setpolicy" checked />
531: </label>
1.55 www 532: <br />
1.68 matthew 533: <label>
534: <b>$lt{'scfc'}: </b>
535: <input type="checkbox" name="setcontent" checked />
536: </label>
1.11 www 537: </p>
1.46 sakharuk 538: <h2>$lt{'cmmn'}</h2>
1.16 www 539: <p>
1.68 matthew 540: <label>
541: <b>$lt{'dsrd'}: </b>
542: <input type="checkbox" name="disresdis" />
543: </label>
544: <br />
545: <label>
546: <b>$lt{'dsuc'}: </b>
547: <input type="checkbox" name="disablechat" />
548: </label>
1.16 www 549: </p>
1.46 sakharuk 550: <h2>$lt{'acco'}</h2>
1.18 www 551: <p>
1.68 matthew 552: <label>
553: <b>$lt{'snak'}: </b>
554: <input type="checkbox" name="setkeys" />
555: </label>
556: <br />
557: <label>
558: <b>$lt{'kaut'}: </b>
559: <input type="text" size="30" name="keyauth" />
560: </label>
1.18 www 561: </p>
1.55 www 562: <h2>$lt{'rshm'}</h2>
563: <p>
1.68 matthew 564: <label>
565: <b>$lt{'rshm'}: </b>
566: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
567: </label>
1.55 www 568: </p>
1.10 matthew 569: <p>
1.46 sakharuk 570: <h2>$lt{'aens'}</h2>
571: $lt{'aesc'}
1.40 raeburn 572: </p>
573: <p>
1.46 sakharuk 574: <b>$lt{'aadd'}</b>
1.68 matthew 575: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label>
576: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
577: </label>
1.40 raeburn 578: </p><p>
1.46 sakharuk 579: <b>$lt{'audr'}</b>
1.68 matthew 580: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label>
581: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
1.40 raeburn 582: </p><p>
1.46 sakharuk 583: <b>$lt{'dacu'}</b>
1.60 raeburn 584: $enroll_table
1.40 raeburn 585: </p><p>
1.60 raeburn 586: <b>$lt{'dacc'}</b>
587: $access_table
588: <p></p>
1.46 sakharuk 589: <b>$lt{'psam'}.</b><br />
590: $lt{'pcda'}.
1.40 raeburn 591: </p><p>
592: $krbform
593: <br />
594: $intform
595: <br />
596: $locform
597: </p><p>
1.46 sakharuk 598: <b>$lt{'nech'}</b><br />
599: $lt{'nccl'}<br/>
1.68 matthew 600: <label>
1.77 raeburn 601: <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
1.68 matthew 602: </label>
603: <label>
1.77 raeburn 604: <input type="radio" name="notify_owner" value="0" checked="true" />$lt{'no'}
605: </label>
606: <br />
607: $lt{'ndcl'}<br/>
608: <label>
609: <input type="radio" name="notify_dc" value="1" />$lt{'yes'}
610: </label>
611: <label>
612: <input type="radio" name="notify_dc" value="0" checked="true" />$lt{'no'}
1.68 matthew 613: </label>
614: </p><p>
615: <b>$lt{'irsp'}</b>
616: <label>
617: <input type="radio" name="showphotos" value="1" />$lt{'yes'}
618: </label>
619: <label>
620: <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
621: </label>
1.55 www 622: </p>
1.93 ! raeburn 623: <p>
! 624: <h2>$lt{'cgrs'}</h2>
! 625: $lt{'cgrq'}
! 626: <input type="text" name="crsquota" value="20" size="6" />Mb
! 627: </p>
1.55 www 628: <hr />
629: <h2>$lt{'cc'}</h2>
630: <p>
1.68 matthew 631: <label>
632: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
633: </label>
634: </p><p>
635: <label>
636: <b>$lt{'dmn'}:</b> $domform
637: </label>
1.55 www 638: </p>
639: <p>
1.90 raeburn 640: <input type="hidden" name="prevphase" value="courseone" />
641: <input type="hidden" name="phase" value="coursetwo" />
1.68 matthew 642: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
1.10 matthew 643: </p>
1.2 www 644: </form>
645: ENDDOCUMENT
1.90 raeburn 646: } elsif ($crstype eq 'Group') {
647: $r->print(<<ENDDOCUMENT);
648: <form action="/adm/createcourse" method="post" name="ccrs">
649: <h2>$lt{'ginf'}</h2>
650: <p>
651: <label><b>$lt{'gtit'}:</b>
652: <input type="text" size="50" name="title" /></label>
653: </p><p>
654: <label>
655: <b>$lt{'ghsr'}:</b>$course_home
656: </label>
657: </p><p>
658: <label>
659: <b>$lt{'gidn'} ($lt{'opt'})</b>
660: <input type="text" size="30" name="crsid" />
661: </label>
662: </p>
663: <h2>$lt{'grco'}</h2>
664: <table border="2">
665: <tr><th>$lt{'cngr'}</th><th>$lt{'cegr'}</th></tr>
666: <tr><td>
667: <p>
668: <label>
669: <b>$lt{'map'}:</b>
670: <input type="text" size="50" name="topmap" />
671: </label>
672: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
673: </p><p>
674: <label for="nonstd"><b>$lt{'sagr'}</b></label>
675: <br />
676: ($lt{'ocik'}):
677: <input id="nonstd" type="checkbox" name="nonstandard" />
678: </p><p>
679: <b>$lt{'fres'}</b><br />($lt{'stgo'}):
680: <label>
681: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
682: </label>
683:
684: <label>
685: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
686: </label>
687:
688: <label>
689: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
690: </label>
691: </p>
692: </td><td>
693: <label>
694: $lt{'gid'}: <input type="text" size="25" name="clonecourse" value="" />
695: </label>
696: <br />
697: <label>
698: $lt{'dmn'}: $cloneform
699: </label>
700: <br />
701: <br />
702: $lt{'asov'}.
703: </td></tr>
704: </table>
705: </p>
706: <p>
707: <h2>$lt{'mssg'}</h2>
708: <p>
709: <label>
710: <b>$lt{'sgpf'}: </b>
711: <input type="checkbox" name="setpolicy" checked />
712: </label>
713: <br />
714: <label>
715: <b>$lt{'scfg'}: </b>
716: <input type="checkbox" name="setcontent" checked />
717: </label>
718: </p>
719: <h2>$lt{'cmmn'}</h2>
720: <p>
721: <label>
722: <b>$lt{'dmrd'}: </b>
723: <input type="checkbox" name="disresdis" />
724: </label>
725: <br />
726: <label>
727: <b>$lt{'dmuc'}: </b>
728: <input type="checkbox" name="disablechat" />
729: </label>
730: </p>
731: <h2>$lt{'acco'}</h2>
732: <p>
733: <label>
734: <b>$lt{'mnak'}: </b>
735: <input type="checkbox" name="setkeys" />
736: </label>
737: <br />
738: <label>
739: <b>$lt{'kaug'}: </b>
740: <input type="text" size="30" name="keyauth" />
741: </label>
742: </p>
743: <h2>$lt{'rshm'}</h2>
744: <p>
745: <label>
746: <b>$lt{'rshm'}: </b>
747: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
748: </label>
749: </p>
1.93 ! raeburn 750: <p>
! 751: <h2>$lt{'grts'}</h2>
! 752: $lt{'grtq'}
! 753: <input type="text" name="crsquota" value="20" />Mb
! 754: </p>
1.90 raeburn 755: <hr />
756: <h2>$lt{'gc'}</h2>
757: <p>
758: <label>
759: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
760: </label>
761: </p><p>
762: <label>
763: <b>$lt{'dmn'}:</b> $domform
764: </label>
765: </p>
766: <p>
767: <input type="hidden" name="prevphase" value="groupone" />
768: <input type="hidden" name="phase" value="grouptwo" />
769: <input type="button" onClick="validate(this.form)" value="$lt{'crgr'}" />
770: </p>
771: </form>
772: ENDDOCUMENT
773: }
774: $r->print($end_page);
1.40 raeburn 775: }
776:
1.2 www 777: # ====================================================== Phase two: make course
778:
1.10 matthew 779: sub create_course {
1.2 www 780: my $r=shift;
1.78 albertel 781: my $ccuname=$env{'form.ccuname'};
782: my $ccdomain=$env{'form.ccdomain'};
1.2 www 783: $ccuname=~s/\W//g;
784: $ccdomain=~s/\W//g;
1.90 raeburn 785: my $crstype = 'Group';
786: my ($enrollstart,$enrollend,$startaccess,$endaccess);
1.74 raeburn 787:
1.90 raeburn 788: if ($env{'form.phase'} eq 'coursetwo') {
789: $crstype='Course';
790: $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll');
791: $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll');
792:
793: }
794: $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
795: $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
1.74 raeburn 796:
797: my $autharg;
798: my $authtype;
799:
1.78 albertel 800: if ($env{'form.login'} eq 'krb') {
1.74 raeburn 801: $authtype = 'krb';
1.78 albertel 802: $authtype .=$env{'form.krbver'};
803: $autharg = $env{'form.krbarg'};
804: } elsif ($env{'form.login'} eq 'int') {
1.74 raeburn 805: $authtype ='internal';
1.78 albertel 806: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
807: $autharg = $env{'form.intarg'};
1.74 raeburn 808: }
1.78 albertel 809: } elsif ($env{'form.login'} eq 'loc') {
1.74 raeburn 810: $authtype = 'localauth';
1.78 albertel 811: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
812: $autharg = $env{'form.locarg'};
1.74 raeburn 813: }
814: }
1.90 raeburn 815: my $logmsg;
1.91 albertel 816: my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype);
1.90 raeburn 817: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
1.74 raeburn 818:
1.90 raeburn 819: $r->print($start_page.$crumbs);
1.74 raeburn 820:
821: my $args = {
1.90 raeburn 822: crstype => $crstype,
1.74 raeburn 823: ccuname => $ccuname,
824: ccdomain => $ccdomain,
1.78 albertel 825: cdescr => $env{'form.title'},
826: curl => $env{'form.topmap'},
827: course_domain => $env{'request.role.domain'},
828: course_home => $env{'form.course_home'},
829: nonstandard => $env{'form.nonstandard'},
830: crscode => $env{'form.crscode'},
1.93 ! raeburn 831: crsquota => $env{'form.crsquota'},
1.78 albertel 832: clonecourse => $env{'form.clonecourse'},
833: clonedomain => $env{'form.clonedomain'},
834: crsid => $env{'form.crsid'},
835: curruser => $env{'user.name'},
836: crssections => $env{'form.crssections'},
837: crsxlist => $env{'form.crsxlist'},
838: autoadds => $env{'form.autoadds'},
839: autodrops => $env{'form.autodrops'},
840: notify_owner => $env{'form.notify_owner'},
841: notify_dc => $env{'form.notify_dc'},
842: no_end_date => $env{'form.no_end_date'},
843: showphotos => $env{'form.showphotos'},
1.74 raeburn 844: authtype => $authtype,
845: autharg => $autharg,
846: enrollstart => $enrollstart,
847: enrollend => $enrollend,
848: startaccess => $startaccess,
849: endaccess => $endaccess,
1.78 albertel 850: setpolicy => $env{'form.setpolicy'},
851: setcontent => $env{'form.setcontent'},
852: reshome => $env{'form.reshome'},
853: setkeys => $env{'form.setkeys'},
854: keyauth => $env{'form.keyauth'},
855: disresdis => $env{'form.disresdis'},
856: disablechat => $env{'form.disablechat'},
857: openall => $env{'form.openall'},
858: firstres => $env{'form.firstres'}
1.74 raeburn 859: };
860:
1.10 matthew 861: #
862: # Verify data
863: #
864: # Check the veracity of the course coordinator
1.2 www 865: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52 albertel 866: $r->print('<form action="/adm/createuser" method="post" name="crtuser">');
867: $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
868: $r->print(&mt("Please click Back on your browser and select another user, or "));
869: $r->print('
870: <input type="hidden" name="phase" value="get_user_info" />
871: <input type="hidden" name="ccuname" value="'.$ccuname.'" />
872: <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
873: <input name="userrole" type="submit" value="'.
874: &mt('Create User').'" />
1.86 albertel 875: </form>'.&Apache::loncommon::end_page());
1.2 www 876: return;
877: }
1.10 matthew 878: # Check the proposed home server for the course
879: my %host_servers = &Apache::loncommon::get_library_servers
1.78 albertel 880: ($env{'request.role.domain'});
881: if (! exists($host_servers{$env{'form.course_home'}})) {
1.46 sakharuk 882: $r->print(&mt('Invalid home server for course').': '.
1.86 albertel 883: $env{'form.course_home'}.&Apache::loncommon::end_page());
1.10 matthew 884: return;
885: }
1.74 raeburn 886: my ($courseid,$crsudom,$crsunum);
1.78 albertel 887: $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
1.74 raeburn 888:
889: #
1.90 raeburn 890: # Make the requested user a course coordinator or group coordinator
1.74 raeburn 891: #
1.90 raeburn 892: if (($ccdomain) && ($ccuname)) {
893: $r->print(&mt('Assigning role of [_1] Coordinator to [_2] at [_3]:',
894: $crstype,$ccuname,$ccdomain).
895: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,
896: 'cc').'<p>');
897: }
1.78 albertel 898: if ($env{'form.setkeys'}) {
1.74 raeburn 899: $r->print(
900: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
901: }
902: # Flush the course logs so reverse user roles immediately updated
903: &Apache::lonnet::flushcourselogs();
1.86 albertel 904: $r->print('<p>'.&mt('Roles will be active at next login').'.</p>'.
1.87 www 905: '<p><a href="/adm/createcourse">'.
1.90 raeburn 906: &mt('Create Another [_1]',$crstype).'</a></p>'.
1.86 albertel 907: &Apache::loncommon::end_page());
1.74 raeburn 908: }
909:
910: sub construct_course {
1.77 raeburn 911: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
1.74 raeburn 912: my $outcome;
913:
1.2 www 914: #
915: # Open course
916: #
1.90 raeburn 917: my $crstype = lc($args->{'crstype'});
1.32 www 918: my %cenv=();
1.74 raeburn 919: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
920: $args->{'cdescr'},
921: $args->{'curl'},
922: $args->{'course_home'},
923: $args->{'nonstandard'},
924: $args->{'crscode'},
1.90 raeburn 925: $args->{'ccuname'},
926: $args->{'crstype'});
1.2 www 927:
1.27 bowersj2 928: # Note: The testing routines depend on this being output; see
929: # Utils::Course. This needs to at least be output as a comment
930: # if anyone ever decides to not show this, and Utils::Course::new
931: # will need to be suitably modified.
1.90 raeburn 932: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]<br />',$crstype,$$courseid);
1.4 www 933: #
1.12 www 934: # Check if created correctly
1.4 www 935: #
1.74 raeburn 936: ($$crsudom,$$crsunum)=($$courseid=~/^\/(\w+)\/(\w+)$/);
937: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
938: $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
1.12 www 939: #
1.32 www 940: # Are we cloning?
941: #
942: my $cloneid='';
1.74 raeburn 943: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
944: $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
1.32 www 945: my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
946: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
947: if ($clonehome eq 'no_host') {
1.74 raeburn 948: $outcome .=
1.90 raeburn 949: '<br /><font color="red">'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.'</font>';
1.32 www 950: } else {
1.74 raeburn 951: $outcome .=
1.90 raeburn 952: '<br /><font color="green">'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).'</font>';
1.74 raeburn 953: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.32 www 954: # Copy all files
1.74 raeburn 955: ©coursefiles($cloneid,$$courseid);
1.37 www 956: # Restore URL
957: $cenv{'url'}=$oldcenv{'url'};
1.32 www 958: # Restore title
1.37 www 959: $cenv{'description'}=$oldcenv{'description'};
1.67 albertel 960: # restore grading mode
961: if (defined($oldcenv{'grading'})) {
962: $cenv{'grading'}=$oldcenv{'grading'};
963: }
1.37 www 964: # Mark as cloned
1.35 www 965: $cenv{'clonedfrom'}=$cloneid;
1.54 albertel 966: delete($cenv{'default_enrollment_start_date'});
967: delete($cenv{'default_enrollment_end_date'});
1.32 www 968: }
969: }
970: #
971: # Set environment (will override cloned, if existing)
1.12 www 972: #
1.64 raeburn 973: my @sections = ();
974: my @xlists = ();
1.90 raeburn 975: if ($args->{'crstype'}) {
976: $cenv{'type'}=$args->{'crstype'};
977: }
1.74 raeburn 978: if ($args->{'crsid'}) {
979: $cenv{'courseid'}=$args->{'crsid'};
1.40 raeburn 980: }
1.74 raeburn 981: if ($args->{'crscode'}) {
982: $cenv{'internal.coursecode'}=$args->{'crscode'};
1.40 raeburn 983: }
1.93 ! raeburn 984: if ($args->{'crsquota'} ne '') {
! 985: $cenv{'internal.coursequota'}=$args->{'crsquota'};
! 986: } else {
! 987: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
! 988: }
1.74 raeburn 989: if ($args->{'ccuname'}) {
990: $cenv{'internal.courseowner'} = $args->{'ccuname'};
1.64 raeburn 991: } else {
1.74 raeburn 992: $cenv{'internal.courseowner'} = $args->{'curruser'};
1.64 raeburn 993: }
994:
995: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.74 raeburn 996: if ($args->{'crssections'}) {
1.64 raeburn 997: $cenv{'internal.sectionnums'} = '';
1.74 raeburn 998: if ($args->{'crssections'} =~ m/,/) {
999: @sections = split/,/,$args->{'crssections'};
1.44 raeburn 1000: } else {
1.74 raeburn 1001: $sections[0] = $args->{'crssections'};
1.44 raeburn 1002: }
1003: if (@sections > 0) {
1.64 raeburn 1004: foreach my $item (@sections) {
1005: my ($sec,$gp) = split/:/,$item;
1.74 raeburn 1006: my $class = $args->{'crscode'}.$sec;
1.81 raeburn 1007: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
1.73 raeburn 1008: $cenv{'internal.sectionnums'} .= $item.',';
1009: unless ($addcheck eq 'ok') {
1.64 raeburn 1010: push @badclasses, $class;
1011: }
1.44 raeburn 1012: }
1.64 raeburn 1013: $cenv{'internal.sectionnums'} =~ s/,$//;
1.44 raeburn 1014: }
1.40 raeburn 1015: }
1.49 www 1016: # do not hide course coordinator from staff listing,
1017: # even if privileged
1.74 raeburn 1018: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1019: # add crosslistings
1020: if ($args->{'crsxlist'}) {
1.64 raeburn 1021: $cenv{'internal.crosslistings'}='';
1.74 raeburn 1022: if ($args->{'crsxlist'} =~ m/,/) {
1023: @xlists = split/,/,$args->{'crsxlist'};
1.44 raeburn 1024: } else {
1.74 raeburn 1025: $xlists[0] = $args->{'crsxlist'};
1.44 raeburn 1026: }
1027: if (@xlists > 0) {
1.64 raeburn 1028: foreach my $item (@xlists) {
1029: my ($xl,$gp) = split/:/,$item;
1.74 raeburn 1030: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
1.73 raeburn 1031: $cenv{'internal.crosslistings'} .= $item.',';
1032: unless ($addcheck eq 'ok') {
1.64 raeburn 1033: push @badclasses, $xl;
1034: }
1.44 raeburn 1035: }
1.64 raeburn 1036: $cenv{'internal.crosslistings'} =~ s/,$//;
1.44 raeburn 1037: }
1.40 raeburn 1038: }
1.74 raeburn 1039: if ($args->{'autoadds'}) {
1040: $cenv{'internal.autoadds'}=$args->{'autoadds'};
1.40 raeburn 1041: }
1.74 raeburn 1042: if ($args->{'autodrops'}) {
1043: $cenv{'internal.autodrops'}=$args->{'autodrops'};
1.40 raeburn 1044: }
1.77 raeburn 1045: # check for notification of enrollment changes
1046: my @notified = ();
1047: if ($args->{'notify_owner'}) {
1048: if ($args->{'ccuname'} ne '') {
1049: push(@notified,$args->{'ccuname'}.'@'.$args->{'ccdomain'});
1050: }
1051: }
1052: if ($args->{'notify_dc'}) {
1053: if ($uname ne '') {
1054: push(@notified,$uname.'@'.$udom);
1055: }
1056: }
1057: if (@notified > 0) {
1058: my $notifylist;
1059: if (@notified > 1) {
1060: $notifylist = join(',',@notified);
1061: } else {
1062: $notifylist = $notified[0];
1063: }
1064: $cenv{'internal.notifylist'} = $notifylist;
1.40 raeburn 1065: }
1.64 raeburn 1066: if (@badclasses > 0) {
1067: my %lt=&Apache::lonlocal::texthash(
1.73 raeburn 1068: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
1.64 raeburn 1069: 'dnhr' => 'does not have rights to access enrollment in these classes',
1070: 'adby' => 'as determined by the policies of your institution on access to official classlists'
1071: );
1.74 raeburn 1072: $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
1.64 raeburn 1073: foreach (@badclasses) {
1.74 raeburn 1074: $outcome .= "<li>$_</li>\n";
1.44 raeburn 1075: }
1.74 raeburn 1076: $outcome .= "</ul><br /><br /></font>\n";
1.40 raeburn 1077: }
1.74 raeburn 1078: if ($args->{'no_end_date'}) {
1079: $args->{'endaccess'} = 0;
1.40 raeburn 1080: }
1.74 raeburn 1081: $cenv{'internal.autostart'}=$args->{'enrollstart'};
1082: $cenv{'internal.autoend'}=$args->{'enrollend'};
1083: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
1084: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
1085: if ($args->{'showphotos'}) {
1086: $cenv{'internal.showphotos'}=$args->{'showphotos'};
1.40 raeburn 1087: }
1.74 raeburn 1088: $cenv{'internal.authtype'} = $args->{'authtype'};
1089: $cenv{'internal.autharg'} = $args->{'autharg'};
1.40 raeburn 1090: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
1091: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.74 raeburn 1092: $outcome .= '<font color="red" size="+1">'.
1093: &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student').'</font></p>';
1.40 raeburn 1094: }
1.12 www 1095: }
1.74 raeburn 1096: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
1097: if ($args->{'setpolicy'}) {
1098: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.12 www 1099: }
1.74 raeburn 1100: if ($args->{'setcontent'}) {
1101: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.18 www 1102: }
1.55 www 1103: }
1.74 raeburn 1104: if ($args->{'reshome'}) {
1105: $cenv{'reshome'}=$args->{'reshome'}.'/';
1.55 www 1106: $cenv{'reshome'}=~s/\/+$/\//;
1.18 www 1107: }
1.56 www 1108: #
1109: # course has keyed access
1110: #
1.74 raeburn 1111: if ($args->{'setkeys'}) {
1.18 www 1112: $cenv{'keyaccess'}='yes';
1.16 www 1113: }
1.56 www 1114: # if specified, key authority is not course, but user
1115: # only active if keyaccess is yes
1.74 raeburn 1116: if ($args->{'keyauth'}) {
1117: $args->{'keyauth'}=~s/[^\w\@]//g;
1118: if ($args->{'keyauth'}) {
1119: $cenv{'keyauth'}=$args->{'keyauth'};
1.56 www 1120: }
1121: }
1122:
1.74 raeburn 1123: if ($args->{'disresdis'}) {
1.16 www 1124: $cenv{'pch.roles.denied'}='st';
1.26 matthew 1125: }
1.74 raeburn 1126: if ($args->{'disablechat'}) {
1.26 matthew 1127: $cenv{'plc.roles.denied'}='st';
1.21 albertel 1128: }
1.23 bowersj2 1129:
1.32 www 1130: # Record we've not yet viewed the Course Initialization Helper for this
1131: # course
1.23 bowersj2 1132: $cenv{'course.helper.not.run'} = 1;
1.21 albertel 1133: #
1134: # Use new Randomseed
1135: #
1.22 albertel 1136: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.51 albertel 1137: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
1.53 www 1138: #
1139: # The encryption code and receipt prefix for this course
1140: #
1141: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
1142: $cenv{'internal.encpref'}=100+int(9*rand(99));
1.25 matthew 1143: #
1144: # By default, use standard grading
1.67 albertel 1145: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
1.22 albertel 1146:
1.74 raeburn 1147: $outcome .= ('<br />'.&mt('Setting environment').': '.
1148: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
1.12 www 1149: #
1150: # Open all assignments
1151: #
1.74 raeburn 1152: if ($args->{'openall'}) {
1153: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.33 www 1154: my %storecontent = ($storeunder => time,
1155: $storeunder.'.type' => 'date_start');
1.12 www 1156:
1.74 raeburn 1157: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1158: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
1.12 www 1159: }
1.13 www 1160: #
1161: # Set first page
1162: #
1.74 raeburn 1163: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
1.48 www 1164: || ($cloneid)) {
1.74 raeburn 1165: $outcome .= &mt('Setting first resource').': ';
1.13 www 1166: my ($errtext,$fatal)=
1.74 raeburn 1167: &Apache::londocs::mapread($$crsunum,$$crsudom,'default.sequence');
1168: $outcome .= ($fatal?$errtext:'read ok').' - ';
1.13 www 1169: my $title; my $url;
1.74 raeburn 1170: if ($args->{'firstres'} eq 'syl') {
1.13 www 1171: $title='Syllabus';
1.74 raeburn 1172: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
1.13 www 1173: } else {
1174: $title='Navigate Contents';
1175: $url='/adm/navmaps';
1176: }
1177: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15 albertel 1178: ($errtext,$fatal)=
1.74 raeburn 1179: &Apache::londocs::storemap($$crsunum,$$crsudom,'default.sequence');
1180: $outcome .= ($fatal?$errtext:'write ok').'<br>';
1.20 www 1181: }
1.74 raeburn 1182: return $outcome;
1.2 www 1183: }
1184:
1.90 raeburn 1185: sub print_intro_page {
1186: my $r = shift;
1187: my $start_page =
1188: &Apache::loncommon::start_page('Create a New Course or Group Space');
1189: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
1190: my $end_page =
1191: &Apache::loncommon::end_page();
1192: my $helplink=&Apache::loncommon::help_open_topic('Create_Course_GroupSpace',&mt('Help on Creating Courses and Groups'));
1193:
1194: my @choices = ({ internal_name => 'courseone',
1195: name => &mt('Create a single course'),
1196: short_description =>
1197: &mt('Create a new course by completing an online form.'),
1198: },
1199: { internal_name => 'groupone',
1200: name => &mt('Create a single collaborative group space '),
1201: short_description =>
1202: &mt('Create a new group space for non-course use by completing an online form .'),
1203: },
1204: { internal_name => 'batchone',
1205: name => &mt('Create courses/groups by uploading an attributes file'),
1206: short_description =>
1207: &mt('Upload an attributes file containing specifications for one or more courses or groups in XML format'),
1208: },
1209: );
1210: my $options;
1211: foreach my $choice (@choices) {
1212: $options .=' <h3><a href="/adm/createcourse?phase='.
1213: $choice->{'internal_name'}.'" >'.
1214: $choice->{'name'}."</a></h3>\n";
1215: $options .= ' '.(' 'x8).$choice->{'short_description'}.
1216: "\n";
1217: }
1218:
1219: $r->print(<<ENDDOCUMENT);
1220: $start_page
1221: $crumbs
1222: $options
1223: $end_page
1224: ENDDOCUMENT
1225: }
1226:
1227: sub upload_batchfile {
1228: my $r = shift;
1229: my $start_page =
1230: &Apache::loncommon::start_page('Create a New Course or Group Space');
1231: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses');
1232: my $end_page =
1233: &Apache::loncommon::end_page();
1234: $r->print($start_page.$crumbs);
1235: $r->print('<h3>'.&mt('Upload a courses or groups attributes file').'</h3>');
1236: $r->print('<form name="batchcreate" method="post" '.
1237: 'enctype="multipart/form-data" action="/adm/createcourse">'.
1238: '<input type="file" name="coursecreatorxml" />'.
1239: '<input type="hidden" name="phase" value="batchtwo"><br /><br />'.
1240: '<input type="submit" name="batchsubmit" '.
1241: 'value="Create Courses/Groups" /></form>');
1242: $r->print($end_page);
1243: return;
1244: }
1245:
1246: sub process_batchfile {
1247: my $r = shift;
1248: my $start_page =
1249: &Apache::loncommon::start_page('Create a New Course or Group Space');
1250: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
1251: my $end_page =
1252: &Apache::loncommon::end_page();
1253: my $defdom=$env{'request.role.domain'};
1254: my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
1255: 'batchupload',undef,undef,
1256: undef,undef,$defdom);
1257: my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
1258: my ($result,$logmsg);
1259: if (-e "$batchfilepath") {
1260: open(FILE,"<$batchfilepath");
1261: my @buffer = <FILE>;
1262: close(FILE);
1263: if ((defined($filename)) && (defined($batchdir))) {
1264: my @requests = ($filename);
1265: my %courseids = ();
1266: ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
1267: \@requests,\%courseids,'web',$defdom,
1268: $env{'user.name'},$env{'user.domain'});
1269: if ($result) {
1270: if (!-e "$batchdir/processed") {
1271: mkdir("$batchdir/processed", 0755);
1272: open(FILE,">$batchdir/processed/$filename");
1273: print FILE @buffer;
1274: close(FILE);
1275: if (-e "$batchdir/processed/$filename") {
1276: unlink("$batchdir/pending/$filename");
1277: }
1278: }
1279: }
1280: }
1281: }
1282: $r->print($start_page.$crumbs.$result.$end_page);
1283:
1284: }
1285:
1.2 www 1286: # ===================================================================== Handler
1.1 www 1287: sub handler {
1288: my $r = shift;
1289:
1290: if ($r->header_only) {
1.38 www 1291: &Apache::loncommon::content_type($r,'text/html');
1.1 www 1292: $r->send_http_header;
1293: return OK;
1294: }
1295:
1.78 albertel 1296: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.38 www 1297: &Apache::loncommon::content_type($r,'text/html');
1.1 www 1298: $r->send_http_header;
1299:
1.90 raeburn 1300: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1301: ['phase']);
1302: &Apache::lonhtmlcommon::clear_breadcrumbs();
1303: &Apache::lonhtmlcommon::add_breadcrumb
1304: ({href=>"/adm/createcourse",
1305: text=>"Creation Options",
1306: faq=>79,bug=>'Dom Coord Interface',});
1307: if (($env{'form.phase'} eq 'coursetwo') ||
1308: ($env{'form.phase'} eq 'grouptwo')) {
1309: &Apache::lonhtmlcommon::add_breadcrumb
1310: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
1311: text=>&mt('[_1] Creation Settings',),
1312: faq=>9,bug=>'Dom Coord Interface',});
1313: &Apache::lonhtmlcommon::add_breadcrumb
1314: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
1315: text=>"Creation Outcome",
1316: faq=>9,bug=>'Dom Coord Interface',});
1.10 matthew 1317: &create_course($r);
1.90 raeburn 1318: } elsif (($env{'form.phase'} eq 'courseone') ||
1319: ($env{'form.phase'} eq 'groupone')) {
1320: &Apache::lonhtmlcommon::add_breadcrumb
1321: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
1322: text=>&mt('[_1] Creation Settings',),
1323: faq=>9,bug=>'Dom Coord Interface',});
1324: &print_course_creation_page($r);
1325: } elsif ($env{'form.phase'} eq 'batchone') {
1326: &Apache::lonhtmlcommon::add_breadcrumb
1327: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
1328: text=>"Upload Description File",
1329: faq=>9,bug=>'Dom Coord Interface',});
1330: &upload_batchfile($r);
1331: } elsif ($env{'form.phase'} eq 'batchtwo') {
1332: &Apache::lonhtmlcommon::add_breadcrumb
1333: ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
1334: text=>"Upload Description File",
1335: faq=>9,bug=>'Dom Coord Interface',});
1336: &Apache::lonhtmlcommon::add_breadcrumb
1337: ({href=>"/adm/createcourse?phase=$env{'form.phase'}",
1338: text=>"Creation Outcome",
1339: faq=>9,bug=>'Dom Coord Interface',});
1340: &process_batchfile($r);
1.2 www 1341: } else {
1.90 raeburn 1342: &print_intro_page($r);
1.2 www 1343: }
1.1 www 1344: } else {
1.78 albertel 1345: $env{'user.error.msg'}=
1.90 raeburn 1346: "/adm/createcourse:ccc:0:0:Cannot create courses or groups";
1.1 www 1347: return HTTP_NOT_ACCEPTABLE;
1348: }
1349: return OK;
1.90 raeburn 1350: }
1.1 www 1351:
1352: 1;
1353: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>