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