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