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