Annotation of loncom/interface/loncreatecourse.pm, revision 1.29
1.1 www 1: # The LearningOnline Network
2: # Create a course
1.5 albertel 3: #
1.29 ! www 4: # $Id: loncreatecourse.pm,v 1.28 2003/08/30 14:36:24 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.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.28 www 50:
51: # -------------------------------------------- Return path to profile directory
52:
53: sub propath {
54: my ($udom,$uname)=@_;
55: $udom=~s/\W//g;
56: $uname=~s/\W//g;
57: my $subdir=$uname.'__';
58: $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
59: my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
60: return $proname;
61: }
62:
63: # ================================================ Get course directory listing
64:
65: sub crsdirlist {
66: my ($courseid,$which)=@_;
67: unless ($which) { $which=''; }
68: my %crsdata=&Apache::lonnet::coursedescription($courseid);
69: my @listing=&Apache::lonnet::dirlist
70: ($which,$crsdata{'domain'},$crsdata{'num'},
71: &propath($crsdata{'domain'},$crsdata{'num'}));
72: my @output=();
73: foreach (@listing) {
74: unless ($_=~/^\./) {
75: push (@output,(split(/\&/,$_))[0]);
76: }
77: }
78: return @output;
1.29 ! www 79: }
! 80:
! 81: # ============================================================= Read a userfile
! 82:
! 83: sub readfile {
! 84: my ($courseid,$which)=@_;
! 85: my %crsdata=&Apache::lonnet::coursedescription($courseid);
! 86: return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
! 87: $crsdata{'num'}.'/'.$which);
! 88: }
! 89:
! 90: # ============================================================ Write a userfile
! 91:
! 92: sub writefile {
! 93: my ($courseid,$which,$data)=@_;
! 94: my %crsdata=&Apache::lonnet::coursedescription($courseid);
! 95: $ENV{'form.output'}=$data;
! 96: return &Apache::lonnet::finishuserfileupload(
! 97: $crsdata{'num'},$crsdata{'domain'},
! 98: $crsdata{'home'},
! 99: 'output',$which);
! 100: }
! 101:
! 102: # ============================================================= Copy a userfile
! 103:
! 104: sub copyfile {
! 105: my ($origcrsid,$newcrsid,$which)=@_;
! 106: return &writefile($newcrsid,$which,&readfile($origcrsid,$which));
1.28 www 107: }
1.13 www 108:
1.2 www 109: # ===================================================== Phase one: fill-in form
110:
1.10 matthew 111: sub print_course_creation_page {
1.2 www 112: my $r=shift;
1.10 matthew 113: my $defdom=$ENV{'request.role.domain'};
114: my %host_servers = &Apache::loncommon::get_library_servers($defdom);
115: my $course_home = '<select name="course_home" size="1">'."\n";
116: foreach my $server (sort(keys(%host_servers))) {
1.14 matthew 117: $course_home .= qq{<option value="$server"};
118: if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
119: $course_home .= " selected ";
120: }
121: $course_home .= qq{>$server $host_servers{$server}</option>};
1.10 matthew 122: }
123: $course_home .= "\n</select>\n";
1.9 matthew 124: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12 www 125: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.17 www 126: my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
1.2 www 127: $r->print(<<ENDDOCUMENT);
128: <html>
1.6 matthew 129: <script language="JavaScript" type="text/javascript">
130: var editbrowser = null;
131: function openbrowser(formname,elementname) {
132: var url = '/res/?';
133: if (editbrowser == null) {
134: url += 'launch=1&';
135: }
136: url += 'catalogmode=interactive&';
137: url += 'mode=edit&';
138: url += 'form=' + formname + '&';
1.7 matthew 139: url += 'element=' + elementname + '&';
140: url += 'only=sequence' + '';
1.6 matthew 141: var title = 'Browser';
142: var options = 'scrollbars=1,resizable=1,menubar=0';
143: options += ',width=700,height=600';
144: editbrowser = open(url,title,options,'1');
145: editbrowser.focus();
146: }
147: </script>
1.2 www 148: <head>
149: <title>The LearningOnline Network with CAPA</title>
150: </head>
1.12 www 151: $bodytag
1.17 www 152: $helplink
1.6 matthew 153: <form action="/adm/createcourse" method="post" name="ccrs">
1.10 matthew 154: <h2>Course Information</h2>
155: <p>
156: <b>Course Title:</b>
1.6 matthew 157: <input type="text" size="50" name="title">
1.10 matthew 158: </p><p>
1.13 www 159: <b>Course Home Server:</b>$course_home
160: </p><p>
161: <b>Course ID/Number (optional)</b>
162: <input type="text" size="30" name="crsid">
163: </p>
164: <h2>Course Content</h2>
165: <p>
1.11 www 166: <b>Map:</b>
1.6 matthew 167: <input type="text" size="50" name="topmap">
1.24 www 168: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
1.10 matthew 169: </p><p>
1.11 www 170: <b>Do NOT generate as standard course</b>
171: (only check if you know what you are doing):
172: <input type="checkbox" name="nonstandard">
1.13 www 173: </p>
174: <p>
175: <b>First Resource</b> (standard courses only):
1.17 www 176: <input type="radio" name="firstres" value="blank">Blank
1.13 www 177:
1.17 www 178: <input type="radio" name="firstres" value="syl" checked>Syllabus
1.13 www 179:
180: <input type="radio" name="firstres" value="nav">Navigate
181: </p>
182:
183: <h2>Assessment Parameters</h2>
184: <p>
1.11 www 185: <b>Open all assessments: </b>
186: <input type="checkbox" name="openall" checked>
1.13 www 187: </p>
188: <h2>Messaging</h2>
189: <p>
1.11 www 190: <b>Set course policy feedback to Course Coordinator: </b>
191: <input type="checkbox" name="setpolicy" checked>
192: </p><p>
193: <b>Set content feedback to Course Coordinator: </b>
194: <input type="checkbox" name="setcontent" checked>
195: </p>
1.16 www 196: <h2>Communication</h2>
197: <p>
198: <b>Disable student resource discussion: </b>
1.26 matthew 199: <input type="checkbox" name="disresdis" /> <br />
200: <b>Disable student use of chatrooms: </b>
201: <input type="checkbox" name="disablechat" />
1.16 www 202: </p>
1.18 www 203: <h2>Access Control</h2>
204: <p>
205: <b>Students need access key to enter course: </b>
206: <input type="checkbox" name="setkeys" />
207: </p>
1.10 matthew 208: <h2>Course Coordinator</h2>
209: <p>
1.11 www 210: <b>Username:</b> <input type="text" size="15" name="ccuname" />
211: </p><p>
212: <b>Domain:</b> $domform
1.10 matthew 213: </p><p>
1.11 www 214: <b>Immediately expire own role as Course Coordinator:</b>
215: <input type="checkbox" name="expireown" checked>
1.10 matthew 216: </p><p>
217: <input type="hidden" name="phase" value="two" />
1.6 matthew 218: <input type="submit" value="Open Course">
1.10 matthew 219: </p>
1.2 www 220: </form>
221: </body>
222: </html>
223: ENDDOCUMENT
224: }
225:
226: # ====================================================== Phase two: make course
227:
1.10 matthew 228: sub create_course {
1.2 www 229: my $r=shift;
230: my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
231: my $ccuname=$ENV{'form.ccuname'};
232: my $ccdomain=$ENV{'form.ccdomain'};
233: $ccuname=~s/\W//g;
234: $ccdomain=~s/\W//g;
235: my $cdescr=$ENV{'form.title'};
236: my $curl=$ENV{'form.topmap'};
1.12 www 237: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2 www 238: $r->print(<<ENDENHEAD);
239: <html>
240: <head>
241: <title>The LearningOnline Network with CAPA</title>
242: </head>
1.12 www 243: $bodytag
1.2 www 244: ENDENHEAD
1.10 matthew 245: #
246: # Verify data
247: #
248: # Check the veracity of the course coordinator
1.2 www 249: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3 www 250: $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2 www 251: return;
252: }
1.10 matthew 253: # Check the proposed home server for the course
254: my %host_servers = &Apache::loncommon::get_library_servers
255: ($ENV{'request.role.domain'});
256: if (! exists($host_servers{$ENV{'form.course_home'}})) {
257: $r->print('Invalid home server for course: '.
258: $ENV{'form.course_home'}.'</body></html>');
259: return;
260: }
1.2 www 261: #
262: # Open course
263: #
1.10 matthew 264: my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
265: $cdescr,$curl,
1.11 www 266: $ENV{'form.course_home'},
267: $ENV{'form.nonstandard'});
1.2 www 268:
1.27 bowersj2 269: # Note: The testing routines depend on this being output; see
270: # Utils::Course. This needs to at least be output as a comment
271: # if anyone ever decides to not show this, and Utils::Course::new
272: # will need to be suitably modified.
1.4 www 273: $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
274: #
1.12 www 275: # Check if created correctly
1.4 www 276: #
277: my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
278: my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
279: $r->print('Created on: '.$crsuhome.'<br>');
1.12 www 280: #
281: # Set environment
282: #
283: my %cenv=();
284: my $envflag=0;
1.4 www 285: if ($ENV{'form.crsid'}) {
1.12 www 286: $envflag=1;
287: $cenv{'courseid'}=$ENV{'form.crsid'};
288: }
289: if (($ccdomain) && ($ccuname)) {
290: if ($ENV{'form.setpolicy'}) {
291: $envflag=1;
292: $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
293: }
294: if ($ENV{'form.setcontent'}) {
1.18 www 295: $envflag=1;
296: $cenv{'question.email'}=$ccuname.':'.$ccdomain;
297: }
298: }
299: if ($ENV{'form.setkeys'}) {
300: $envflag=1;
301: $cenv{'keyaccess'}='yes';
1.16 www 302: }
303: if ($ENV{'form.disresdis'}) {
304: $envflag=1;
305: $cenv{'pch.roles.denied'}='st';
1.26 matthew 306: }
307: if ($ENV{'form.disablechat'}) {
308: $envflag=1;
309: $cenv{'plc.roles.denied'}='st';
1.21 albertel 310: }
1.23 bowersj2 311:
312: # Record we've not yet viewed the Course Initialization Helper for this course
313: $cenv{'course.helper.not.run'} = 1;
1.21 albertel 314: #
315: # Use new Randomseed
316: #
1.22 albertel 317: $envflag=1;
318: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.25 matthew 319: #
320: # By default, use standard grading
321: $cenv{'grading'} = 'standard';
1.22 albertel 322:
1.12 www 323: if ($envflag) {
324: $r->print('Setting environment: '.
325: &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
326: }
327: #
328: # Open all assignments
329: #
330: if ($ENV{'form.openall'}) {
331: my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
332: my %storecontent = ($storeunder => time,
333: $storeunder.'type' => 'date_start');
334:
335: $r->print('Opening all assignments: '.&Apache::lonnet::cput
336: ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
337: }
1.13 www 338: #
339: # Set first page
340: #
341: unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
342: $r->print('Setting first resource: ');
343: my ($errtext,$fatal)=
344: &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
345: $r->print(($fatal?$errtext:'read ok').' - ');
346: my $title; my $url;
347: if ($ENV{'form.firstres'} eq 'syl') {
348: $title='Syllabus';
349: $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
350: } else {
351: $title='Navigate Contents';
352: $url='/adm/navmaps';
353: }
354: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15 albertel 355: ($errtext,$fatal)=
1.13 www 356: &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
357: $r->print(($fatal?$errtext:'write ok').'<br>');
358: }
1.2 www 359: #
360: # Make current user course adminstrator
361: #
1.12 www 362: my $end=undef;
363: my $addition='';
364: if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
365: $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2 www 366: &Apache::lonnet::assignrole(
1.12 www 367: $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2 www 368: #
369: # Make additional user course administrator
370: #
1.12 www 371: if (($ccdomain) && ($ccuname)) {
1.2 www 372: $r->print('Assigning role of course coordinator to '.
373: $ccuname.' at '.$ccdomain.': '.
1.3 www 374: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12 www 375: }
1.20 www 376: if ($ENV{'form.setkeys'}) {
377: $r->print(
378: '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
379: }
380: $r->print('<p>Roles will be active at next login.</p></body></html>');
1.2 www 381: }
382:
383: # ===================================================================== Handler
1.1 www 384: sub handler {
385: my $r = shift;
386:
387: if ($r->header_only) {
388: $r->content_type('text/html');
389: $r->send_http_header;
390: return OK;
391: }
392:
1.10 matthew 393: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.1 www 394: $r->content_type('text/html');
395: $r->send_http_header;
396:
1.2 www 397: if ($ENV{'form.phase'} eq 'two') {
1.10 matthew 398: &create_course($r);
1.2 www 399: } else {
1.10 matthew 400: &print_course_creation_page($r);
1.2 www 401: }
1.1 www 402: } else {
403: $ENV{'user.error.msg'}=
404: "/adm/createcourse:ccc:0:0:Cannot create courses";
405: return HTTP_NOT_ACCEPTABLE;
406: }
407: return OK;
408: }
409:
410: 1;
411: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>