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