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