Annotation of loncom/interface/loncreatecourse.pm, revision 1.42
1.1 www 1: # The LearningOnline Network
2: # Create a course
1.5 albertel 3: #
1.42 ! albertel 4: # $Id: loncreatecourse.pm,v 1.41 2003/12/05 21:34:48 raeburn 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.1 www 28: # (My Desk
29: #
30: # (Internal Server Error Handler
31: #
32: # (Login Screen
33: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
34: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
35: #
36: # 3/1/1 Gerd Kortemeyer)
37: #
38: # 3/1 Gerd Kortemeyer)
39: #
1.4 www 40: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
1.1 www 41: #
42: package Apache::loncreatecourse;
43:
44: use strict;
45: use Apache::Constants qw(:common :http);
46: use Apache::lonnet;
1.12 www 47: use Apache::loncommon;
1.13 www 48: use Apache::lonratedt;
49: use Apache::londocs;
1.38 www 50: use Apache::lonlocal;
1.41 raeburn 51: use Apache::londropadd;
1.28 www 52:
53: # ================================================ Get course directory listing
54:
55: sub crsdirlist {
56: my ($courseid,$which)=@_;
57: unless ($which) { $which=''; }
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: my @output=();
63: foreach (@listing) {
64: unless ($_=~/^\./) {
65: push (@output,(split(/\&/,$_))[0]);
66: }
67: }
68: return @output;
1.29 www 69: }
70:
71: # ============================================================= Read a userfile
72:
73: sub readfile {
74: my ($courseid,$which)=@_;
75: my %crsdata=&Apache::lonnet::coursedescription($courseid);
76: return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
77: $crsdata{'num'}.'/'.$which);
78: }
79:
80: # ============================================================ Write a userfile
81:
82: sub writefile {
1.30 www 83: (my $courseid, my $which,$ENV{'form.output'})=@_;
1.29 www 84: my %crsdata=&Apache::lonnet::coursedescription($courseid);
85: return &Apache::lonnet::finishuserfileupload(
86: $crsdata{'num'},$crsdata{'domain'},
87: $crsdata{'home'},
88: 'output',$which);
89: }
90:
1.36 www 91: # ===================================================================== Rewrite
92:
93: sub rewritefile {
94: my ($contents,%rewritehash)=@_;
95: foreach (keys %rewritehash) {
96: my $pattern=$_;
97: $pattern=~s/(\W)/\\$1/gs;
98: my $new=$rewritehash{$_};
99: $contents=~s/$pattern/$new/gs;
100: }
101: return $contents;
102: }
103:
1.29 www 104: # ============================================================= Copy a userfile
105:
106: sub copyfile {
107: my ($origcrsid,$newcrsid,$which)=@_;
1.36 www 108: unless ($which=~/\.sequence$/) {
109: return &writefile($newcrsid,$which,
110: &readfile($origcrsid,$which));
111: } else {
112: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
113: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
114: return &writefile($newcrsid,$which,
115: &rewritefile(
116: &readfile($origcrsid,$which),
117: (
118: '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
119: => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
120: )));
121: }
1.30 www 122: }
123:
124: # =============================================================== Copy a dbfile
125:
126: sub copydb {
127: my ($origcrsid,$newcrsid,$which)=@_;
128: $which=~s/\.db$//;
129: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
130: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
131: my %data=&Apache::lonnet::dump
132: ($which,$origcrsdata{'domain'},$origcrsdata{'num'});
133: return &Apache::lonnet::put
134: ($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
135: }
136:
1.35 www 137: # ========================================================== Copy resourcesdata
138:
139: sub copyresourcedb {
140: my ($origcrsid,$newcrsid)=@_;
141: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
142: my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
143: my %data=&Apache::lonnet::dump
144: ('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
145: $origcrsid=~s/^\///;
146: $origcrsid=~s/\//\_/;
147: $newcrsid=~s/^\///;
148: $newcrsid=~s/\//\_/;
149: my %newdata=();
150: undef %newdata;
151: my $startdate=$data{$origcrsid.'.0.opendate'};
152: my $today=time;
153: my $delta=0;
154: if ($startdate) {
155: my $oneday=60*60*24;
156: $delta=$today-$startdate;
157: $delta=int($delta/$oneday)*$oneday;
158: }
159: # ugly retro fix for broken version of types
160: foreach (keys %data) {
161: if ($_=~/\wtype$/) {
162: my $newkey=$_;
163: $newkey=~s/type$/\.type/;
164: $data{$newkey}=$data{$_};
165: delete $data{$_};
166: }
167: }
1.37 www 168: # adjust symbs
169: my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
170: $pattern=~s/(\W)/\\$1/gs;
171: my $new= 'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
172: foreach (keys %data) {
173: if ($_=~/$pattern/) {
174: my $newkey=$_;
175: $newkey=~s/$pattern/$new/;
176: $data{$newkey}=$data{$_};
177: delete $data{$_};
178: }
179: }
1.35 www 180: # adjust dates
181: foreach (keys %data) {
182: my $thiskey=$_;
183: $thiskey=~s/^$origcrsid/$newcrsid/;
184: $newdata{$thiskey}=$data{$_};
185: if ($data{$_.'.type'}=~/^date/) {
186: $newdata{$thiskey}=$newdata{$thiskey}+$delta;
187: }
188: }
189: return &Apache::lonnet::put
190: ('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
191: }
192:
1.30 www 193: # ========================================================== Copy all userfiles
194:
195: sub copyuserfiles {
196: my ($origcrsid,$newcrsid)=@_;
197: foreach (&crsdirlist($origcrsid,'userfiles')) {
198: ©file($origcrsid,$newcrsid,$_);
199: }
200: }
201: # ========================================================== Copy all userfiles
202:
203: sub copydbfiles {
204: my ($origcrsid,$newcrsid)=@_;
205: foreach (&crsdirlist($origcrsid)) {
206: if ($_=~/\.db$/) {
207: unless
1.34 www 208: ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
1.30 www 209: ©db($origcrsid,$newcrsid,$_);
210: }
211: }
212: }
1.31 www 213: }
214:
215: # ======================================================= Copy all course files
216:
217: sub copycoursefiles {
218: my ($origcrsid,$newcrsid)=@_;
219: ©userfiles($origcrsid,$newcrsid);
220: ©dbfiles($origcrsid,$newcrsid);
1.35 www 221: ©resourcedb($origcrsid,$newcrsid);
1.28 www 222: }
1.13 www 223:
1.2 www 224: # ===================================================== Phase one: fill-in form
225:
1.10 matthew 226: sub print_course_creation_page {
1.2 www 227: my $r=shift;
1.10 matthew 228: my $defdom=$ENV{'request.role.domain'};
229: my %host_servers = &Apache::loncommon::get_library_servers($defdom);
230: my $course_home = '<select name="course_home" size="1">'."\n";
231: foreach my $server (sort(keys(%host_servers))) {
1.14 matthew 232: $course_home .= qq{<option value="$server"};
233: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
234: $course_home .= " selected ";
235: }
236: $course_home .= qq{>$server $host_servers{$server}</option>};
1.10 matthew 237: }
238: $course_home .= "\n</select>\n";
1.9 matthew 239: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12 www 240: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.17 www 241: my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
1.32 www 242: my $cloneform=&Apache::loncommon::select_dom_form
243: ($ENV{'request.role.domain'},'clonedomain').
244: &Apache::loncommon::selectcourse_link
245: ('ccrs','clonecourse','clonedomain');
246: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
1.41 raeburn 247: my $date_table = &Apache::londropadd::date_setting_table('','','createcourse');
1.40 raeburn 248: my ($krbdef,$krbdefdom) =
249: &Apache::loncommon::get_kerberos_defaults($defdom);
1.41 raeburn 250: my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
1.40 raeburn 251: my %param = ( formname => 'document.ccrs',
252: kerb_def_dom => $krbdefdom,
253: kerb_def_auth => $krbdef
254: );
255: my $krbform = &Apache::loncommon::authform_kerberos(%param);
256: my $intform = &Apache::loncommon::authform_internal(%param);
257: my $locform = &Apache::loncommon::authform_local(%param);
1.2 www 258: $r->print(<<ENDDOCUMENT);
259: <html>
1.6 matthew 260: <script language="JavaScript" type="text/javascript">
261: var editbrowser = null;
262: function openbrowser(formname,elementname) {
263: var url = '/res/?';
264: if (editbrowser == null) {
265: url += 'launch=1&';
266: }
267: url += 'catalogmode=interactive&';
268: url += 'mode=edit&';
269: url += 'form=' + formname + '&';
1.7 matthew 270: url += 'element=' + elementname + '&';
271: url += 'only=sequence' + '';
1.6 matthew 272: var title = 'Browser';
273: var options = 'scrollbars=1,resizable=1,menubar=0';
274: options += ',width=700,height=600';
275: editbrowser = open(url,title,options,'1');
276: editbrowser.focus();
277: }
1.41 raeburn 278: $javascript_validations
1.6 matthew 279: </script>
1.32 www 280: $coursebrowserjs
1.2 www 281: <head>
282: <title>The LearningOnline Network with CAPA</title>
283: </head>
1.12 www 284: $bodytag
1.17 www 285: $helplink
1.6 matthew 286: <form action="/adm/createcourse" method="post" name="ccrs">
1.10 matthew 287: <h2>Course Information</h2>
288: <p>
289: <b>Course Title:</b>
1.6 matthew 290: <input type="text" size="50" name="title">
1.10 matthew 291: </p><p>
1.13 www 292: <b>Course Home Server:</b>$course_home
293: </p><p>
294: <b>Course ID/Number (optional)</b>
295: <input type="text" size="30" name="crsid">
1.40 raeburn 296: </p><p>
297: <h2>Institutional Information</h2>
298: <p>
299: 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.
300: </p><p>
301: <b>Course Code</b>
302: <input type="text" size="30" name="crscode" /><br/>
303: (to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231)
304: </p><p>
305: <b>Section Numbers and corresponding LON-CAPA section/group IDs</b>
306: <input type="text" size="30" name="crssections" /><br/>
307: (a comma separated list of institutional section numbers, each separated by a colon
308: from the (optional) corresponding section/group ID to be used in LON-CAPA e.g., 001:1,002:2)
309: </p><p>
310: <b>Crosslisted courses</b>
311: <input type="text" size="30" name="crsxlist" /><br/>
312: (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:bot2)
1.13 www 313: </p>
314: <h2>Course Content</h2>
1.32 www 315: <table border="2">
316: <tr><th>Completely new course</th><th>Clone an existing course</th></tr>
317: <tr><td>
1.13 www 318: <p>
1.11 www 319: <b>Map:</b>
1.6 matthew 320: <input type="text" size="50" name="topmap">
1.24 www 321: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
1.10 matthew 322: </p><p>
1.32 www 323: <b>Do NOT generate as standard course</b><br />
1.11 www 324: (only check if you know what you are doing):
325: <input type="checkbox" name="nonstandard">
1.13 www 326: </p>
327: <p>
1.32 www 328: <b>First Resource</b><br />(standard courses only):
1.17 www 329: <input type="radio" name="firstres" value="blank">Blank
1.13 www 330:
1.17 www 331: <input type="radio" name="firstres" value="syl" checked>Syllabus
1.13 www 332:
333: <input type="radio" name="firstres" value="nav">Navigate
334: </p>
1.32 www 335: </td><td>
336: Course ID: <input input type="text" size="25" name="clonecourse" value="" />
337: <br />
338: Domain:
339: $cloneform<br /> <br />
340: Additional settings, if specified below, will override cloned settings.
341: </td></tr>
342: </table>
1.13 www 343: <h2>Assessment Parameters</h2>
344: <p>
1.11 www 345: <b>Open all assessments: </b>
346: <input type="checkbox" name="openall" checked>
1.13 www 347: </p>
348: <h2>Messaging</h2>
349: <p>
1.11 www 350: <b>Set course policy feedback to Course Coordinator: </b>
351: <input type="checkbox" name="setpolicy" checked>
352: </p><p>
353: <b>Set content feedback to Course Coordinator: </b>
354: <input type="checkbox" name="setcontent" checked>
355: </p>
1.16 www 356: <h2>Communication</h2>
357: <p>
358: <b>Disable student resource discussion: </b>
1.26 matthew 359: <input type="checkbox" name="disresdis" /> <br />
360: <b>Disable student use of chatrooms: </b>
361: <input type="checkbox" name="disablechat" />
1.16 www 362: </p>
1.18 www 363: <h2>Access Control</h2>
364: <p>
365: <b>Students need access key to enter course: </b>
366: <input type="checkbox" name="setkeys" />
367: </p>
1.10 matthew 368: <h2>Course Coordinator</h2>
369: <p>
1.11 www 370: <b>Username:</b> <input type="text" size="15" name="ccuname" />
371: </p><p>
372: <b>Domain:</b> $domform
1.10 matthew 373: </p><p>
1.11 www 374: <b>Immediately expire own role as Course Coordinator:</b>
375: <input type="checkbox" name="expireown" checked>
1.10 matthew 376: </p><p>
1.40 raeburn 377: <h2>Automated enrollment settings</h2>
378: The following settings control automatic enrollment of students in this class based
379: on information available for this specific course from your institution's official classlists.
380: </p>
381: <p>
382: <b>Automated adds</b>
383: <input type="radio" name="autoadds" value="1" checked="true" />Yes <input type="radio" name="autoadds" value="0" />No
384: </p><p>
385: <b>Automated drops</b>
386: <input type="radio" name="autodrops" value="1" checked="true" />Yes <input type="radio" name="autodrops" value="0" />No
387: </p><p>
388: <b>Duration of automated classlist updates</b>
389: $date_table
390: </p><p>
391: <b>Please select the authentication mechanism.</b><br />
392: Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process.
393: </p><p>
394: $krbform
395: <br />
396: $intform
397: <br />
398: $locform
399: </p><p>
400: <b>Notification of enrollment changes</b><br />
401: Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?<br/>
402: <input type="radio" name="notify" value="1" />Yes <input type="radio" name="notify"
403: value="0" />No
404: </p><p>
405: <b>Include retrieval of student photographs?</b> <input type="radio" name="showphotos" value="1" />Yes <input type="radio" name="showphotos" value="0" checked="true" />No
406: </p><p>
1.10 matthew 407: <input type="hidden" name="phase" value="two" />
1.41 raeburn 408: <input type="button" onClick="verify_message(this.form)" value="Open Course">
1.10 matthew 409: </p>
1.2 www 410: </form>
411: </body>
412: </html>
413: ENDDOCUMENT
1.40 raeburn 414: }
415:
1.2 www 416: # ====================================================== Phase two: make course
417:
1.10 matthew 418: sub create_course {
1.2 www 419: my $r=shift;
420: my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
421: my $ccuname=$ENV{'form.ccuname'};
422: my $ccdomain=$ENV{'form.ccdomain'};
423: $ccuname=~s/\W//g;
424: $ccdomain=~s/\W//g;
425: my $cdescr=$ENV{'form.title'};
426: my $curl=$ENV{'form.topmap'};
1.12 www 427: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2 www 428: $r->print(<<ENDENHEAD);
429: <html>
430: <head>
431: <title>The LearningOnline Network with CAPA</title>
432: </head>
1.12 www 433: $bodytag
1.2 www 434: ENDENHEAD
1.10 matthew 435: #
436: # Verify data
437: #
438: # Check the veracity of the course coordinator
1.2 www 439: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3 www 440: $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2 www 441: return;
442: }
1.10 matthew 443: # Check the proposed home server for the course
444: my %host_servers = &Apache::loncommon::get_library_servers
445: ($ENV{'request.role.domain'});
446: if (! exists($host_servers{$ENV{'form.course_home'}})) {
447: $r->print('Invalid home server for course: '.
448: $ENV{'form.course_home'}.'</body></html>');
449: return;
450: }
1.2 www 451: #
452: # Open course
453: #
1.32 www 454: my %cenv=();
1.10 matthew 455: my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
456: $cdescr,$curl,
1.11 www 457: $ENV{'form.course_home'},
458: $ENV{'form.nonstandard'});
1.2 www 459:
1.27 bowersj2 460: # Note: The testing routines depend on this being output; see
461: # Utils::Course. This needs to at least be output as a comment
462: # if anyone ever decides to not show this, and Utils::Course::new
463: # will need to be suitably modified.
1.4 www 464: $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
465: #
1.12 www 466: # Check if created correctly
1.4 www 467: #
468: my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
469: my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
470: $r->print('Created on: '.$crsuhome.'<br>');
1.12 www 471: #
1.32 www 472: # Are we cloning?
473: #
474: my $cloneid='';
475: if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
476: $cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
477: my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
478: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
479: if ($clonehome eq 'no_host') {
480: $r->print(
481: '<br /><font color="red">Attempting to clone non-existing course '.$cloneid.'</font>');
482: } else {
483: $r->print(
484: '<br /><font color="green">Cloning course from '.$clonehome.'</font>');
1.37 www 485: my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
1.32 www 486: # Copy all files
487: ©coursefiles($cloneid,$courseid);
1.37 www 488: # Restore URL
489: $cenv{'url'}=$oldcenv{'url'};
1.32 www 490: # Restore title
1.37 www 491: $cenv{'description'}=$oldcenv{'description'};
492: # Mark as cloned
1.35 www 493: $cenv{'clonedfrom'}=$cloneid;
1.32 www 494: }
495: }
496: #
497: # Set environment (will override cloned, if existing)
1.12 www 498: #
1.4 www 499: if ($ENV{'form.crsid'}) {
1.12 www 500: $cenv{'courseid'}=$ENV{'form.crsid'};
1.40 raeburn 501: }
502: if ($ENV{'form.crscode'}) {
503: $cenv{'internal.coursecode'}=$ENV{'form.crscode'};
504: }
505: if ($ENV{'form.crssections'}) {
506: $cenv{'internal.sectionnums'}=$ENV{'form.crssections'};
507: }
508: if ($ENV{'form.crsxlist'}) {
509: $cenv{'internal.crosslistings'}=$ENV{'form.crsxlist'};
510: }
511: if ($ENV{'form.autoadds'}) {
512: $cenv{'internal.autoadds'}=$ENV{'form.autoadds'};
513: }
514: if ($ENV{'form.autodrops'}) {
515: $cenv{'internal.autodrops'}=$ENV{'form.autodrops'};
516: }
517: if ($ENV{'form.notify'}) {
518: if ($ccuname) {
519: $cenv{'internal.notifylist'} = $ccuname;
520: }
521: }
522: if ($ccuname) {
523: $cenv{'internal.courseowner'} = $ccuname;
524: }
525: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
526: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
527: if ($ENV{'form.no_end_date'}) {
528: $enddate = 0;
529: }
530: $cenv{'internal.autostart'}=$startdate;
531: $cenv{'internal.autoend'}=$enddate;
532: if ($ENV{'form.showphotos'}) {
533: $cenv{'internal.showphotos'}=$ENV{'form.showphotos'};
534: }
535: if ($ENV{'form.login'} eq 'krb') {
536: $cenv{'internal.authtype'} = 'krb';
537: $cenv{'internal.authtype'} .=$ENV{'form.krbver'};
538: $cenv{'internal.autharg'} = $ENV{'form.krbarg'};
539: } elsif ($ENV{'form.login'} eq 'int') {
540: $cenv{'internal.authtype'} ='internal';
541: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
542: $cenv{'internal.autharg'} = $ENV{'form.intarg'};
543: }
544: } elsif ($ENV{'form.login'} eq 'loc') {
545: $cenv{'internal.authtype'} = 'localauth';
546: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
547: $cenv{'internal.autharg'} = $ENV{'form.locarg'};
548: }
549: }
550: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
551: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
552: $r->print('<font color="red" size="+1">'.
553: '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>');
554: }
1.12 www 555: }
556: if (($ccdomain) && ($ccuname)) {
557: if ($ENV{'form.setpolicy'}) {
558: $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
559: }
560: if ($ENV{'form.setcontent'}) {
1.18 www 561: $cenv{'question.email'}=$ccuname.':'.$ccdomain;
562: }
563: }
564: if ($ENV{'form.setkeys'}) {
565: $cenv{'keyaccess'}='yes';
1.16 www 566: }
567: if ($ENV{'form.disresdis'}) {
568: $cenv{'pch.roles.denied'}='st';
1.26 matthew 569: }
570: if ($ENV{'form.disablechat'}) {
571: $cenv{'plc.roles.denied'}='st';
1.21 albertel 572: }
1.23 bowersj2 573:
1.32 www 574: # Record we've not yet viewed the Course Initialization Helper for this
575: # course
1.23 bowersj2 576: $cenv{'course.helper.not.run'} = 1;
1.21 albertel 577: #
578: # Use new Randomseed
579: #
1.22 albertel 580: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.25 matthew 581: #
582: # By default, use standard grading
583: $cenv{'grading'} = 'standard';
1.22 albertel 584:
1.32 www 585: $r->print('<br />Setting environment: '.
1.12 www 586: &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
587: #
588: # Open all assignments
589: #
590: if ($ENV{'form.openall'}) {
591: my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
1.33 www 592: my %storecontent = ($storeunder => time,
593: $storeunder.'.type' => 'date_start');
1.12 www 594:
595: $r->print('Opening all assignments: '.&Apache::lonnet::cput
596: ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
597: }
1.13 www 598: #
599: # Set first page
600: #
601: unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
602: $r->print('Setting first resource: ');
603: my ($errtext,$fatal)=
604: &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
605: $r->print(($fatal?$errtext:'read ok').' - ');
606: my $title; my $url;
607: if ($ENV{'form.firstres'} eq 'syl') {
608: $title='Syllabus';
609: $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
610: } else {
611: $title='Navigate Contents';
612: $url='/adm/navmaps';
613: }
614: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15 albertel 615: ($errtext,$fatal)=
1.13 www 616: &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
617: $r->print(($fatal?$errtext:'write ok').'<br>');
618: }
1.2 www 619: #
620: # Make current user course adminstrator
621: #
1.12 www 622: my $end=undef;
623: my $addition='';
624: if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
625: $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2 www 626: &Apache::lonnet::assignrole(
1.12 www 627: $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2 www 628: #
629: # Make additional user course administrator
630: #
1.12 www 631: if (($ccdomain) && ($ccuname)) {
1.2 www 632: $r->print('Assigning role of course coordinator to '.
633: $ccuname.' at '.$ccdomain.': '.
1.3 www 634: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12 www 635: }
1.20 www 636: if ($ENV{'form.setkeys'}) {
637: $r->print(
638: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
639: }
640: $r->print('<p>Roles will be active at next login.</p></body></html>');
1.2 www 641: }
642:
643: # ===================================================================== Handler
1.1 www 644: sub handler {
645: my $r = shift;
646:
647: if ($r->header_only) {
1.38 www 648: &Apache::loncommon::content_type($r,'text/html');
1.1 www 649: $r->send_http_header;
650: return OK;
651: }
652:
1.10 matthew 653: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.38 www 654: &Apache::loncommon::content_type($r,'text/html');
1.1 www 655: $r->send_http_header;
656:
1.2 www 657: if ($ENV{'form.phase'} eq 'two') {
1.10 matthew 658: &create_course($r);
1.2 www 659: } else {
1.10 matthew 660: &print_course_creation_page($r);
1.2 www 661: }
1.1 www 662: } else {
663: $ENV{'user.error.msg'}=
664: "/adm/createcourse:ccc:0:0:Cannot create courses";
665: return HTTP_NOT_ACCEPTABLE;
666: }
667: return OK;
668: }
669:
670: 1;
671: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>