Annotation of loncom/interface/loncreatecourse.pm, revision 1.69
1.65 raeburn 1: # The LearningOnline Network
1.1 www 2: # Create a course
1.5 albertel 3: #
1.69 ! albertel 4: # $Id: loncreatecourse.pm,v 1.68 2004/09/25 17:52:03 matthew 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.44 raeburn 40: use lib '/home/httpd/lib/perl';
41: use localenroll;
1.28 www 42:
43: # ================================================ Get course directory listing
44:
1.62 www 45: my @output=();
46:
1.28 www 47: sub crsdirlist {
48: my ($courseid,$which)=@_;
1.62 www 49: @output=();
50: return &innercrsdirlist($courseid,$which);
51: }
52:
53: sub innercrsdirlist {
54: my ($courseid,$which,$path)=@_;
55: my $dirptr=16384;
1.63 www 56: unless ($which) { $which=''; } else { $which.='/'; }
57: unless ($path) { $path=''; } else { $path.='/'; }
1.28 www 58: my %crsdata=&Apache::lonnet::coursedescription($courseid);
59: my @listing=&Apache::lonnet::dirlist
60: ($which,$crsdata{'domain'},$crsdata{'num'},
1.39 albertel 61: &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
1.28 www 62: foreach (@listing) {
63: unless ($_=~/^\./) {
1.62 www 64: my @unpackline = split (/\&/,$_);
65: if ($unpackline[3]&$dirptr) {
66: # is a directory, recurse
1.63 www 67: &innercrsdirlist($courseid,$which.$unpackline[0],
68: $path.$unpackline[0]);
1.62 www 69: } else {
70: # is a file, put into output
1.63 www 71: push (@output,$path.$unpackline[0]);
1.62 www 72: }
1.28 www 73: }
74: }
75: return @output;
1.29 www 76: }
77:
78: # ============================================================= Read a userfile
79:
80: sub readfile {
81: my ($courseid,$which)=@_;
82: my %crsdata=&Apache::lonnet::coursedescription($courseid);
83: return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
84: $crsdata{'num'}.'/'.$which);
85: }
86:
87: # ============================================================ Write a userfile
88:
89: sub writefile {
1.30 www 90: (my $courseid, my $which,$ENV{'form.output'})=@_;
1.29 www 91: my %crsdata=&Apache::lonnet::coursedescription($courseid);
92: return &Apache::lonnet::finishuserfileupload(
93: $crsdata{'num'},$crsdata{'domain'},
94: $crsdata{'home'},
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'});
142: return &Apache::lonnet::put
143: ($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
144: }
145:
1.35 www 146: # ========================================================== Copy resourcesdata
147:
148: sub copyresourcedb {
149: my ($origcrsid,$newcrsid)=@_;
150: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
151: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
152: my %data=&Apache::lonnet::dump
153: ('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
154: $origcrsid=~s/^\///;
155: $origcrsid=~s/\//\_/;
156: $newcrsid=~s/^\///;
157: $newcrsid=~s/\//\_/;
158: my %newdata=();
159: undef %newdata;
160: my $startdate=$data{$origcrsid.'.0.opendate'};
161: my $today=time;
162: my $delta=0;
163: if ($startdate) {
164: my $oneday=60*60*24;
165: $delta=$today-$startdate;
166: $delta=int($delta/$oneday)*$oneday;
167: }
168: # ugly retro fix for broken version of types
169: foreach (keys %data) {
170: if ($_=~/\wtype$/) {
171: my $newkey=$_;
172: $newkey=~s/type$/\.type/;
173: $data{$newkey}=$data{$_};
174: delete $data{$_};
175: }
176: }
1.37 www 177: # adjust symbs
178: my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
179: $pattern=~s/(\W)/\\$1/gs;
180: my $new= 'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
181: foreach (keys %data) {
182: if ($_=~/$pattern/) {
183: my $newkey=$_;
184: $newkey=~s/$pattern/$new/;
185: $data{$newkey}=$data{$_};
186: delete $data{$_};
187: }
188: }
1.35 www 189: # adjust dates
190: foreach (keys %data) {
191: my $thiskey=$_;
192: $thiskey=~s/^$origcrsid/$newcrsid/;
193: $newdata{$thiskey}=$data{$_};
194: if ($data{$_.'.type'}=~/^date/) {
195: $newdata{$thiskey}=$newdata{$thiskey}+$delta;
196: }
197: }
198: return &Apache::lonnet::put
199: ('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
200: }
201:
1.30 www 202: # ========================================================== Copy all userfiles
203:
204: sub copyuserfiles {
205: my ($origcrsid,$newcrsid)=@_;
206: foreach (&crsdirlist($origcrsid,'userfiles')) {
1.69 ! albertel 207: if ($_ !~m|^scantron_|) {
! 208: ©file($origcrsid,$newcrsid,$_);
! 209: }
1.30 www 210: }
211: }
212: # ========================================================== Copy all userfiles
213:
214: sub copydbfiles {
215: my ($origcrsid,$newcrsid)=@_;
216: foreach (&crsdirlist($origcrsid)) {
217: if ($_=~/\.db$/) {
218: unless
1.34 www 219: ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
1.30 www 220: ©db($origcrsid,$newcrsid,$_);
221: }
222: }
223: }
1.31 www 224: }
225:
226: # ======================================================= Copy all course files
227:
228: sub copycoursefiles {
229: my ($origcrsid,$newcrsid)=@_;
230: ©userfiles($origcrsid,$newcrsid);
231: ©dbfiles($origcrsid,$newcrsid);
1.35 www 232: ©resourcedb($origcrsid,$newcrsid);
1.28 www 233: }
1.13 www 234:
1.2 www 235: # ===================================================== Phase one: fill-in form
236:
1.10 matthew 237: sub print_course_creation_page {
1.2 www 238: my $r=shift;
1.10 matthew 239: my $defdom=$ENV{'request.role.domain'};
240: my %host_servers = &Apache::loncommon::get_library_servers($defdom);
241: my $course_home = '<select name="course_home" size="1">'."\n";
242: foreach my $server (sort(keys(%host_servers))) {
1.14 matthew 243: $course_home .= qq{<option value="$server"};
244: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
245: $course_home .= " selected ";
246: }
247: $course_home .= qq{>$server $host_servers{$server}</option>};
1.10 matthew 248: }
249: $course_home .= "\n</select>\n";
1.9 matthew 250: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12 www 251: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.46 sakharuk 252: my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
1.32 www 253: my $cloneform=&Apache::loncommon::select_dom_form
254: ($ENV{'request.role.domain'},'clonedomain').
255: &Apache::loncommon::selectcourse_link
256: ('ccrs','clonecourse','clonedomain');
257: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
1.43 raeburn 258: my $starttime = time;
259: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.60 raeburn 260: my $enroll_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_enrolldates');
261: my $access_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_defaultdates');
1.40 raeburn 262: my ($krbdef,$krbdefdom) =
263: &Apache::loncommon::get_kerberos_defaults($defdom);
1.41 raeburn 264: my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
1.40 raeburn 265: my %param = ( formname => 'document.ccrs',
266: kerb_def_dom => $krbdefdom,
267: kerb_def_auth => $krbdef
268: );
269: my $krbform = &Apache::loncommon::authform_kerberos(%param);
270: my $intform = &Apache::loncommon::authform_internal(%param);
271: my $locform = &Apache::loncommon::authform_local(%param);
1.46 sakharuk 272: my %lt=&Apache::lonlocal::texthash(
273: 'cinf' => "Course Information",
274: 'ctit' => "Course Title",
275: 'chsr' => "Course Home Server",
276: 'cidn' => "Course ID/Number",
277: 'opt' => "optional",
278: 'iinf' => "Institutional Information",
279: '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.",
280: 'ccod' => "Course Code",
281: 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231",
282: 'snid' => "Section Numbers and corresponding LON-CAPA section/group IDs",
283: 'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2",
284: 'crcs' => "Crosslisted courses",
1.65 raeburn 285: '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) groupID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2",
1.46 sakharuk 286: 'crco' => "Course Content",
287: 'cncr' => "Completely new course",
288: 'cecr' => "Clone an existing course",
289: 'map' => "Map",
290: 'smap' => "Select Map",
291: 'sacr' => "Do NOT generate as standard course",
292: 'ocik' => "only check if you know what you are doing",
293: 'fres' => "First Resource",
294: 'stco' => "standard courses only",
295: 'blnk' => "Blank",
296: 'sllb' => "Syllabus",
297: 'navi' => "Navigate",
298: 'cid' => "Course ID",
299: 'dmn' => "Domain",
300: 'asov' => "Additional settings, if specified below, will override cloned settings",
301: 'assp' => "Assessment Parameters",
302: 'oaas' => "Open all assessments",
303: 'mssg' => "Messaging",
304: 'scpf' => "Set course policy feedback to Course Coordinator",
305: 'scfc' => "Set content feedback to Course Coordinator",
306: 'cmmn' => "Communication",
307: 'dsrd' => "Disable student resource discussion",
308: 'dsuc' => "Disable student use of chatrooms",
309: 'acco' => "Access Control",
310: 'snak' => "Students need access key to enter course",
1.56 www 311: 'kaut' =>
312: 'Key authority (<tt>id@domain</tt>) if other than course',
1.46 sakharuk 313: 'cc' => "Course Coordinator",
314: 'user' => "Username",
315: 'ierc' => "Immediately expire own role as Course Coordinator",
316: 'aens' => "Automated enrollment settings",
317: '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.",
318: 'aadd' => "Automated adds",
319: 'yes' => "Yes",
320: 'no' => "No",
321: 'audr' => "Automated drops",
322: 'dacu' => "Duration of automated classlist updates",
1.60 raeburn 323: 'dacc' => "Default start and end dates for student access",
1.46 sakharuk 324: 'psam' => "Please select the authentication mechanism",
325: 'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
326: 'nech' => "Notification of enrollment changes",
327: 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
328: 'irsp' => "Include retrieval of student photographs?",
1.55 www 329: 'rshm' => 'Resource Space Home',
1.46 sakharuk 330: 'opco' => "Open Course"
331: );
1.2 www 332: $r->print(<<ENDDOCUMENT);
333: <html>
1.6 matthew 334: <script language="JavaScript" type="text/javascript">
335: var editbrowser = null;
336: function openbrowser(formname,elementname) {
337: var url = '/res/?';
338: if (editbrowser == null) {
339: url += 'launch=1&';
340: }
341: url += 'catalogmode=interactive&';
342: url += 'mode=edit&';
343: url += 'form=' + formname + '&';
1.7 matthew 344: url += 'element=' + elementname + '&';
345: url += 'only=sequence' + '';
1.6 matthew 346: var title = 'Browser';
347: var options = 'scrollbars=1,resizable=1,menubar=0';
348: options += ',width=700,height=600';
349: editbrowser = open(url,title,options,'1');
350: editbrowser.focus();
351: }
1.41 raeburn 352: $javascript_validations
1.6 matthew 353: </script>
1.32 www 354: $coursebrowserjs
1.2 www 355: <head>
356: <title>The LearningOnline Network with CAPA</title>
357: </head>
1.12 www 358: $bodytag
1.17 www 359: $helplink
1.6 matthew 360: <form action="/adm/createcourse" method="post" name="ccrs">
1.46 sakharuk 361: <h2>$lt{'cinf'}</h2>
1.10 matthew 362: <p>
1.68 matthew 363: <label><b>$lt{'ctit'}:</b>
364: <input type="text" size="50" name="title" /></label>
1.10 matthew 365: </p><p>
1.68 matthew 366: <label>
367: <b>$lt{'chsr'}:</b>$course_home
368: </label>
369: </p><p>
370: <label>
371: <b>$lt{'cidn'} ($lt{'opt'})</b>
372: <input type="text" size="30" name="crsid" />
373: </label>
1.40 raeburn 374: </p><p>
1.46 sakharuk 375: <h2>$lt{'iinf'}</h2>
1.40 raeburn 376: <p>
1.46 sakharuk 377: $lt{'stat'}
1.40 raeburn 378: </p><p>
1.68 matthew 379: <label>
380: <b>$lt{'ccod'}</b>
381: <input type="text" size="30" name="crscode" />
382: </label>
383: <br/>
1.46 sakharuk 384: ($lt{'toin'})
1.40 raeburn 385: </p><p>
1.68 matthew 386: <label>
387: <b>$lt{'snid'}</b>
388: <input type="text" size="30" name="crssections" />
389: </label>
390: <br/>
1.46 sakharuk 391: ($lt{'csli'})
1.40 raeburn 392: </p><p>
1.68 matthew 393: <label>
394: <b>$lt{'crcs'}</b>
395: <input type="text" size="30" name="crsxlist" />
396: </label>
397: <br/>
1.46 sakharuk 398: ($lt{'cscs'})
1.13 www 399: </p>
1.46 sakharuk 400: <h2>$lt{'crco'}</h2>
1.32 www 401: <table border="2">
1.46 sakharuk 402: <tr><th>$lt{'cncr'}</th><th>$lt{'cecr'}</th></tr>
1.32 www 403: <tr><td>
1.13 www 404: <p>
1.68 matthew 405: <label>
406: <b>$lt{'map'}:</b>
407: <input type="text" size="50" name="topmap" />
408: </label>
1.46 sakharuk 409: <a href="javascript:openbrowser('ccrs','topmap')">$lt{'smap'}</a>
1.10 matthew 410: </p><p>
1.68 matthew 411: <label for="nonstd"><b>$lt{'sacr'}</b></label>
412: <br />
1.46 sakharuk 413: ($lt{'ocik'}):
1.68 matthew 414: <input id="nonstd" type="checkbox" name="nonstandard" />
415: </p><p>
1.46 sakharuk 416: <b>$lt{'fres'}</b><br />($lt{'stco'}):
1.68 matthew 417: <label>
418: <input type="radio" name="firstres" value="blank" />$lt{'blnk'}
419: </label>
1.13 www 420:
1.68 matthew 421: <label>
422: <input type="radio" name="firstres" value="syl" checked />$lt{'sllb'}
423: </label>
1.13 www 424:
1.68 matthew 425: <label>
426: <input type="radio" name="firstres" value="nav" />$lt{'navi'}
427: </label>
1.13 www 428: </p>
1.32 www 429: </td><td>
1.68 matthew 430: <label>
431: $lt{'cid'}: <input type="text" size="25" name="clonecourse" value="" />
432: </label>
433: <br />
434: <label>
435: $lt{'dmn'}: $cloneform
436: </label>
1.32 www 437: <br />
1.68 matthew 438: <br />
1.46 sakharuk 439: $lt{'asov'}.
1.32 www 440: </td></tr>
441: </table>
1.46 sakharuk 442: <h2>$lt{'assp'}</h2>
1.13 www 443: <p>
1.68 matthew 444: <label>
445: <b>$lt{'oaas'}: </b>
446: <input type="checkbox" name="openall" />
447: </label>
1.13 www 448: </p>
1.46 sakharuk 449: <h2>$lt{'mssg'}</h2>
1.13 www 450: <p>
1.68 matthew 451: <label>
452: <b>$lt{'scpf'}: </b>
453: <input type="checkbox" name="setpolicy" checked />
454: </label>
1.55 www 455: <br />
1.68 matthew 456: <label>
457: <b>$lt{'scfc'}: </b>
458: <input type="checkbox" name="setcontent" checked />
459: </label>
1.11 www 460: </p>
1.46 sakharuk 461: <h2>$lt{'cmmn'}</h2>
1.16 www 462: <p>
1.68 matthew 463: <label>
464: <b>$lt{'dsrd'}: </b>
465: <input type="checkbox" name="disresdis" />
466: </label>
467: <br />
468: <label>
469: <b>$lt{'dsuc'}: </b>
470: <input type="checkbox" name="disablechat" />
471: </label>
1.16 www 472: </p>
1.46 sakharuk 473: <h2>$lt{'acco'}</h2>
1.18 www 474: <p>
1.68 matthew 475: <label>
476: <b>$lt{'snak'}: </b>
477: <input type="checkbox" name="setkeys" />
478: </label>
479: <br />
480: <label>
481: <b>$lt{'kaut'}: </b>
482: <input type="text" size="30" name="keyauth" />
483: </label>
1.18 www 484: </p>
1.55 www 485: <h2>$lt{'rshm'}</h2>
486: <p>
1.68 matthew 487: <label>
488: <b>$lt{'rshm'}: </b>
489: <input type="text" name="reshome" size="30" value="/res/$defdom/" />
490: </label>
1.55 www 491: </p>
1.10 matthew 492: <p>
1.46 sakharuk 493: <h2>$lt{'aens'}</h2>
494: $lt{'aesc'}
1.40 raeburn 495: </p>
496: <p>
1.46 sakharuk 497: <b>$lt{'aadd'}</b>
1.68 matthew 498: <label><input type="radio" name="autoadds" value="1" />$lt{'yes'}</label>
499: <label><input type="radio" name="autoadds" value="0" checked="true" />$lt{'no'}
500: </label>
1.40 raeburn 501: </p><p>
1.46 sakharuk 502: <b>$lt{'audr'}</b>
1.68 matthew 503: <label><input type="radio" name="autodrops" value="1" />$lt{'yes'}</label>
504: <label><input type="radio" name="autodrops" value="0" checked="true" />$lt{'no'}</label>
1.40 raeburn 505: </p><p>
1.46 sakharuk 506: <b>$lt{'dacu'}</b>
1.60 raeburn 507: $enroll_table
1.40 raeburn 508: </p><p>
1.60 raeburn 509: <b>$lt{'dacc'}</b>
510: $access_table
511: <p></p>
1.46 sakharuk 512: <b>$lt{'psam'}.</b><br />
513: $lt{'pcda'}.
1.40 raeburn 514: </p><p>
515: $krbform
516: <br />
517: $intform
518: <br />
519: $locform
520: </p><p>
1.46 sakharuk 521: <b>$lt{'nech'}</b><br />
522: $lt{'nccl'}<br/>
1.68 matthew 523: <label>
524: <input type="radio" name="notify" value="1" />$lt{'yes'}
525: </label>
526: <label>
527: <input type="radio" name="notify" value="0" checked="true" />$lt{'no'}
528: </label>
529: </p><p>
530: <b>$lt{'irsp'}</b>
531: <label>
532: <input type="radio" name="showphotos" value="1" />$lt{'yes'}
533: </label>
534: <label>
535: <input type="radio" name="showphotos" value="0" checked="true" />$lt{'no'}
536: </label>
1.55 www 537: </p>
538: <hr />
539: <h2>$lt{'cc'}</h2>
540: <p>
1.68 matthew 541: <label>
542: <b>$lt{'user'}:</b> <input type="text" size="15" name="ccuname" />
543: </label>
544: </p><p>
545: <label>
546: <b>$lt{'dmn'}:</b> $domform
547: </label>
548: </p><p>
549: <label>
550: <b>$lt{'ierc'}:</b>
551: <input type="checkbox" name="expireown" checked />
552: </label>
1.55 www 553: </p>
554: <p>
1.10 matthew 555: <input type="hidden" name="phase" value="two" />
1.68 matthew 556: <input type="button" onClick="verify_message(this.form)" value="$lt{'opco'}" />
1.10 matthew 557: </p>
1.2 www 558: </form>
559: </body>
560: </html>
561: ENDDOCUMENT
1.40 raeburn 562: }
563:
1.2 www 564: # ====================================================== Phase two: make course
565:
1.10 matthew 566: sub create_course {
1.2 www 567: my $r=shift;
568: my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
1.58 raeburn 569: my $this_server = $Apache::lonnet::perlvar{'lonHostID'};
1.2 www 570: my $ccuname=$ENV{'form.ccuname'};
571: my $ccdomain=$ENV{'form.ccdomain'};
572: $ccuname=~s/\W//g;
573: $ccdomain=~s/\W//g;
574: my $cdescr=$ENV{'form.title'};
575: my $curl=$ENV{'form.topmap'};
1.12 www 576: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2 www 577: $r->print(<<ENDENHEAD);
578: <html>
579: <head>
580: <title>The LearningOnline Network with CAPA</title>
581: </head>
1.12 www 582: $bodytag
1.2 www 583: ENDENHEAD
1.10 matthew 584: #
585: # Verify data
586: #
587: # Check the veracity of the course coordinator
1.2 www 588: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.52 albertel 589: $r->print('<form action="/adm/createuser" method="post" name="crtuser">');
590: $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.<br />');
591: $r->print(&mt("Please click Back on your browser and select another user, or "));
592: $r->print('
593: <input type="hidden" name="phase" value="get_user_info" />
594: <input type="hidden" name="ccuname" value="'.$ccuname.'" />
595: <input type="hidden" name="ccdomain" value="'.$ccdomain.'" />
596: <input name="userrole" type="submit" value="'.
597: &mt('Create User').'" />
598: </form></body></html>');
1.2 www 599: return;
600: }
1.10 matthew 601: # Check the proposed home server for the course
602: my %host_servers = &Apache::loncommon::get_library_servers
603: ($ENV{'request.role.domain'});
604: if (! exists($host_servers{$ENV{'form.course_home'}})) {
1.46 sakharuk 605: $r->print(&mt('Invalid home server for course').': '.
1.10 matthew 606: $ENV{'form.course_home'}.'</body></html>');
607: return;
608: }
1.2 www 609: #
610: # Open course
611: #
1.32 www 612: my %cenv=();
1.10 matthew 613: my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
614: $cdescr,$curl,
1.11 www 615: $ENV{'form.course_home'},
1.61 raeburn 616: $ENV{'form.nonstandard'},
617: $ENV{'form.crscode'});
1.2 www 618:
1.27 bowersj2 619: # Note: The testing routines depend on this being output; see
620: # Utils::Course. This needs to at least be output as a comment
621: # if anyone ever decides to not show this, and Utils::Course::new
622: # will need to be suitably modified.
1.4 www 623: $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
624: #
1.12 www 625: # Check if created correctly
1.4 www 626: #
627: my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
628: my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
1.46 sakharuk 629: $r->print(&mt('Created on').': '.$crsuhome.'<br>');
1.12 www 630: #
1.32 www 631: # Are we cloning?
632: #
633: my $cloneid='';
634: if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
635: $cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
636: my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
637: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
638: if ($clonehome eq 'no_host') {
639: $r->print(
1.46 sakharuk 640: '<br /><font color="red">'.&mt('Attempting to clone non-existing course').' '.$cloneid.'</font>');
1.32 www 641: } else {
642: $r->print(
1.46 sakharuk 643: '<br /><font color="green">'.&mt('Cloning course from').' '.$clonehome.'</font>');
1.37 www 644: my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
1.32 www 645: # Copy all files
646: ©coursefiles($cloneid,$courseid);
1.37 www 647: # Restore URL
648: $cenv{'url'}=$oldcenv{'url'};
1.32 www 649: # Restore title
1.37 www 650: $cenv{'description'}=$oldcenv{'description'};
1.67 albertel 651: # restore grading mode
652: if (defined($oldcenv{'grading'})) {
653: $cenv{'grading'}=$oldcenv{'grading'};
654: }
1.37 www 655: # Mark as cloned
1.35 www 656: $cenv{'clonedfrom'}=$cloneid;
1.54 albertel 657: delete($cenv{'default_enrollment_start_date'});
658: delete($cenv{'default_enrollment_end_date'});
1.32 www 659: }
660: }
661: #
662: # Set environment (will override cloned, if existing)
1.12 www 663: #
1.64 raeburn 664: my @sections = ();
665: my @xlists = ();
1.4 www 666: if ($ENV{'form.crsid'}) {
1.12 www 667: $cenv{'courseid'}=$ENV{'form.crsid'};
1.40 raeburn 668: }
669: if ($ENV{'form.crscode'}) {
670: $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
671: }
1.64 raeburn 672: if ($ccuname) {
673: $cenv{'internal.courseowner'} = $ccuname;
674: } else {
675: $cenv{'internal.courseowner'} = $ENV{'user.name'};
676: }
677:
678: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.40 raeburn 679: if ($ENV{'form.crssections'}) {
1.64 raeburn 680: $cenv{'internal.sectionnums'} = '';
681: if ($ENV{'form.crssections'} =~ m/,/) {
682: @sections = split/,/,$ENV{'form.crssections'};
1.44 raeburn 683: } else {
1.64 raeburn 684: $sections[0] = $ENV{'form.crssections'};
1.44 raeburn 685: }
686: if (@sections > 0) {
1.64 raeburn 687: foreach my $item (@sections) {
688: my ($sec,$gp) = split/:/,$item;
689: my $class = $ENV{'form.crscode'}.$sec;
690: my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$class,$cenv{'internal.courseowner'});
691: if ($addcheck eq 'ok') {
692: $cenv{'internal.sectionnums'} .= $item.',';
693: } else {
694: push @badclasses, $class;
695: }
1.44 raeburn 696: }
1.64 raeburn 697: $cenv{'internal.sectionnums'} =~ s/,$//;
1.44 raeburn 698: }
1.40 raeburn 699: }
1.49 www 700: # do not hide course coordinator from staff listing,
701: # even if privileged
702: $cenv{'nothideprivileged'}=$ccuname.':'.$ccdomain;
1.40 raeburn 703: if ($ENV{'form.crsxlist'}) {
1.64 raeburn 704: $cenv{'internal.crosslistings'}='';
705: if ($ENV{'form.crsxlist'} =~ m/,/) {
706: @xlists = split/,/,$ENV{'form.crsxlist'};
1.44 raeburn 707: } else {
1.64 raeburn 708: $xlists[0] = $ENV{'form.crsxlist'};
1.44 raeburn 709: }
710: if (@xlists > 0) {
1.64 raeburn 711: foreach my $item (@xlists) {
712: my ($xl,$gp) = split/:/,$item;
713: my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$xl,$cenv{'internal.courseowner'});
714: if ($addcheck eq 'ok') {
715: $cenv{'internal.crosslistings'} .= $item.',';
716: } else {
717: push @badclasses, $xl;
718: }
1.44 raeburn 719: }
1.64 raeburn 720: $cenv{'internal.crosslistings'} =~ s/,$//;
1.44 raeburn 721: }
1.40 raeburn 722: }
723: if ($ENV{'form.autoadds'}) {
724: $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
725: }
726: if ($ENV{'form.autodrops'}) {
727: $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
728: }
729: if ($ENV{'form.notify'}) {
730: if ($ccuname) {
1.65 raeburn 731: $cenv{'internal.notifylist'} = $ccuname.'@'.$ccdomain;
1.40 raeburn 732: }
733: }
1.64 raeburn 734: if (@badclasses > 0) {
735: my %lt=&Apache::lonlocal::texthash(
736: 'tclb' => 'The courses listed below have not been included as sections or crosslistings affiliated with your new LON-CAPA course. 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',
737: 'dnhr' => 'does not have rights to access enrollment in these classes',
738: 'adby' => 'as determined by the policies of your institution on access to official classlists'
739: );
740: $r->print('<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n");
741: foreach (@badclasses) {
742: $r->print("<li>$_</li>\n");
1.44 raeburn 743: }
1.64 raeburn 744: $r->print ("</ul><br /><br /></font>\n");
1.40 raeburn 745: }
1.60 raeburn 746: my $enrollstart = &Apache::lonhtmlcommon::get_date_from_form('startenroll');
747: my $enrollend = &Apache::lonhtmlcommon::get_date_from_form('endenroll');
748: my $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
749: my $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
1.40 raeburn 750: if ($ENV{'form.no_end_date'}) {
1.60 raeburn 751: $endaccess = 0;
1.40 raeburn 752: }
1.60 raeburn 753: $cenv{'internal.autostart'}=$enrollstart;
754: $cenv{'internal.autoend'}=$enrollend;
755: $cenv{'default_enrollment_start_date'}=$startaccess;
756: $cenv{'default_enrollment_end_date'}=$endaccess;
1.40 raeburn 757: if ($ENV{'form.showphotos'}) {
758: $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
759: }
760: if ($ENV{'form.login'} eq 'krb') {
761: $cenv{'internal.authtype'} = 'krb';
762: $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
763: $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
764: } elsif ($ENV{'form.login'} eq 'int') {
765: $cenv{'internal.authtype'} ='internal';
766: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
767: $cenv{'internal.autharg'} = $ENV{'form.intarg'};
768: }
769: } elsif ($ENV{'form.login'} eq 'loc') {
770: $cenv{'internal.authtype'} = 'localauth';
771: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
772: $cenv{'internal.autharg'} = $ENV{'form.locarg'};
773: }
774: }
775: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
776: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
777: $r->print('<font color="red" size="+1">'.
1.46 sakharuk 778: &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 779: }
1.12 www 780: }
781: if (($ccdomain) && ($ccuname)) {
782: if ($ENV{'form.setpolicy'}) {
783: $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
784: }
785: if ($ENV{'form.setcontent'}) {
1.18 www 786: $cenv{'question.email'}=$ccuname.':'.$ccdomain;
787: }
1.55 www 788: }
789: if ($ENV{'form.reshome'}) {
790: $cenv{'reshome'}=$ENV{'form.reshome'}.'/';
791: $cenv{'reshome'}=~s/\/+$/\//;
1.18 www 792: }
1.56 www 793: #
794: # course has keyed access
795: #
1.18 www 796: if ($ENV{'form.setkeys'}) {
797: $cenv{'keyaccess'}='yes';
1.16 www 798: }
1.56 www 799: # if specified, key authority is not course, but user
800: # only active if keyaccess is yes
801: if ($ENV{'form.keyauth'}) {
802: $ENV{'form.keyauth'}=~s/[^\w\@]//g;
803: if ($ENV{'form.keyauth'}) {
804: $cenv{'keyauth'}=$ENV{'form.keyauth'};
805: }
806: }
807:
1.16 www 808: if ($ENV{'form.disresdis'}) {
809: $cenv{'pch.roles.denied'}='st';
1.26 matthew 810: }
811: if ($ENV{'form.disablechat'}) {
812: $cenv{'plc.roles.denied'}='st';
1.21 albertel 813: }
1.23 bowersj2 814:
1.32 www 815: # Record we've not yet viewed the Course Initialization Helper for this
816: # course
1.23 bowersj2 817: $cenv{'course.helper.not.run'} = 1;
1.21 albertel 818: #
819: # Use new Randomseed
820: #
1.22 albertel 821: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.51 albertel 822: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
1.53 www 823: #
824: # The encryption code and receipt prefix for this course
825: #
826: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
827: $cenv{'internal.encpref'}=100+int(9*rand(99));
1.25 matthew 828: #
829: # By default, use standard grading
1.67 albertel 830: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
1.22 albertel 831:
1.46 sakharuk 832: $r->print('<br />'.&mt('Setting environment').': '.
1.12 www 833: &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
834: #
835: # Open all assignments
836: #
837: if ($ENV{'form.openall'}) {
838: my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
1.33 www 839: my %storecontent = ($storeunder => time,
840: $storeunder.'.type' => 'date_start');
1.12 www 841:
1.46 sakharuk 842: $r->print(&mt('Opening all assignments').': '.&Apache::lonnet::cput
1.12 www 843: ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
844: }
1.13 www 845: #
846: # Set first page
847: #
1.48 www 848: unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')
849: || ($cloneid)) {
1.46 sakharuk 850: $r->print(&mt('Setting first resource').': ');
1.13 www 851: my ($errtext,$fatal)=
852: &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
853: $r->print(($fatal?$errtext:'read ok').' - ');
854: my $title; my $url;
855: if ($ENV{'form.firstres'} eq 'syl') {
856: $title='Syllabus';
857: $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
858: } else {
859: $title='Navigate Contents';
860: $url='/adm/navmaps';
861: }
862: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15 albertel 863: ($errtext,$fatal)=
1.13 www 864: &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
865: $r->print(($fatal?$errtext:'write ok').'<br>');
866: }
1.2 www 867: #
868: # Make current user course adminstrator
869: #
1.12 www 870: my $end=undef;
871: my $addition='';
872: if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
1.46 sakharuk 873: $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.
1.2 www 874: &Apache::lonnet::assignrole(
1.12 www 875: $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2 www 876: #
877: # Make additional user course administrator
878: #
1.12 www 879: if (($ccdomain) && ($ccuname)) {
1.46 sakharuk 880: $r->print(&mt('Assigning role of course coordinator to').' '.
1.2 www 881: $ccuname.' at '.$ccdomain.': '.
1.3 www 882: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12 www 883: }
1.20 www 884: if ($ENV{'form.setkeys'}) {
885: $r->print(
1.46 sakharuk 886: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
1.20 www 887: }
1.47 www 888: # Flush the course logs so reverse user roles immediately updated
889: &Apache::lonnet::flushcourselogs();
1.46 sakharuk 890: $r->print('<p>'.&mt('Roles will be active at next login').'.</p></body></html>');
1.2 www 891: }
892:
893: # ===================================================================== Handler
1.1 www 894: sub handler {
895: my $r = shift;
896:
897: if ($r->header_only) {
1.38 www 898: &Apache::loncommon::content_type($r,'text/html');
1.1 www 899: $r->send_http_header;
900: return OK;
901: }
902:
1.10 matthew 903: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.38 www 904: &Apache::loncommon::content_type($r,'text/html');
1.1 www 905: $r->send_http_header;
906:
1.2 www 907: if ($ENV{'form.phase'} eq 'two') {
1.10 matthew 908: &create_course($r);
1.2 www 909: } else {
1.10 matthew 910: &print_course_creation_page($r);
1.2 www 911: }
1.1 www 912: } else {
913: $ENV{'user.error.msg'}=
914: "/adm/createcourse:ccc:0:0:Cannot create courses";
915: return HTTP_NOT_ACCEPTABLE;
916: }
917: return OK;
918: }
919:
920: 1;
921: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>