Annotation of loncom/interface/loncreatecourse.pm, revision 1.13
1.1 www 1: # The LearningOnline Network
2: # Create a course
1.5 albertel 3: #
1.13 ! www 4: # $Id: loncreatecourse.pm,v 1.12 2002/08/31 00:43:12 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;
! 50:
1.2 www 51: # ===================================================== Phase one: fill-in form
52:
1.10 matthew 53: sub print_course_creation_page {
1.2 www 54: my $r=shift;
1.10 matthew 55: my $defdom=$ENV{'request.role.domain'};
56: my %host_servers = &Apache::loncommon::get_library_servers($defdom);
57: my $course_home = '<select name="course_home" size="1">'."\n";
58: foreach my $server (sort(keys(%host_servers))) {
59: $course_home .=
60: qq{<option value="$server">$server $host_servers{$server}</option>};
61: }
62: $course_home .= "\n</select>\n";
1.9 matthew 63: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12 www 64: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
65:
1.2 www 66: $r->print(<<ENDDOCUMENT);
67: <html>
1.6 matthew 68: <script language="JavaScript" type="text/javascript">
69: var editbrowser = null;
70: function openbrowser(formname,elementname) {
71: var url = '/res/?';
72: if (editbrowser == null) {
73: url += 'launch=1&';
74: }
75: url += 'catalogmode=interactive&';
76: url += 'mode=edit&';
77: url += 'form=' + formname + '&';
1.7 matthew 78: url += 'element=' + elementname + '&';
79: url += 'only=sequence' + '';
1.6 matthew 80: var title = 'Browser';
81: var options = 'scrollbars=1,resizable=1,menubar=0';
82: options += ',width=700,height=600';
83: editbrowser = open(url,title,options,'1');
84: editbrowser.focus();
85: }
86: </script>
1.2 www 87: <head>
88: <title>The LearningOnline Network with CAPA</title>
89: </head>
1.12 www 90: $bodytag
1.6 matthew 91: <form action="/adm/createcourse" method="post" name="ccrs">
1.10 matthew 92: <h2>Course Information</h2>
93: <p>
94: <b>Course Title:</b>
1.6 matthew 95: <input type="text" size="50" name="title">
1.10 matthew 96: </p><p>
1.13 ! www 97: <b>Course Home Server:</b>$course_home
! 98: </p><p>
! 99: <b>Course ID/Number (optional)</b>
! 100: <input type="text" size="30" name="crsid">
! 101: </p>
! 102: <h2>Course Content</h2>
! 103: <p>
1.11 www 104: <b>Map:</b>
1.6 matthew 105: <input type="text" size="50" name="topmap">
106: <a href="javascript:openbrowser('ccrs','topmap')">Browse</a>
1.10 matthew 107: </p><p>
1.11 www 108: <b>Do NOT generate as standard course</b>
109: (only check if you know what you are doing):
110: <input type="checkbox" name="nonstandard">
1.13 ! www 111: </p>
! 112: <p>
! 113: <b>First Resource</b> (standard courses only):
! 114: <input type="radio" name="firstres" value="blank" checked>Blank
! 115:
! 116: <input type="radio" name="firstres" value="syl">Syllabus
! 117:
! 118: <input type="radio" name="firstres" value="nav">Navigate
! 119: </p>
! 120:
! 121: <h2>Assessment Parameters</h2>
! 122: <p>
1.11 www 123: <b>Open all assessments: </b>
124: <input type="checkbox" name="openall" checked>
1.13 ! www 125: </p>
! 126: <h2>Messaging</h2>
! 127: <p>
1.11 www 128: <b>Set course policy feedback to Course Coordinator: </b>
129: <input type="checkbox" name="setpolicy" checked>
130: </p><p>
131: <b>Set content feedback to Course Coordinator: </b>
132: <input type="checkbox" name="setcontent" checked>
133: </p>
134:
1.10 matthew 135: <h2>Course Coordinator</h2>
136: <p>
1.11 www 137: <b>Username:</b> <input type="text" size="15" name="ccuname" />
138: </p><p>
139: <b>Domain:</b> $domform
1.10 matthew 140: </p><p>
1.11 www 141: <b>Immediately expire own role as Course Coordinator:</b>
142: <input type="checkbox" name="expireown" checked>
1.10 matthew 143: </p><p>
144: <input type="hidden" name="phase" value="two" />
1.6 matthew 145: <input type="submit" value="Open Course">
1.10 matthew 146: </p>
1.2 www 147: </form>
148: </body>
149: </html>
150: ENDDOCUMENT
151: }
152:
153: # ====================================================== Phase two: make course
154:
1.10 matthew 155: sub create_course {
1.2 www 156: my $r=shift;
157: my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
158: my $ccuname=$ENV{'form.ccuname'};
159: my $ccdomain=$ENV{'form.ccdomain'};
160: $ccuname=~s/\W//g;
161: $ccdomain=~s/\W//g;
162: my $cdescr=$ENV{'form.title'};
163: my $curl=$ENV{'form.topmap'};
1.12 www 164: my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2 www 165: $r->print(<<ENDENHEAD);
166: <html>
167: <head>
168: <title>The LearningOnline Network with CAPA</title>
169: </head>
1.12 www 170: $bodytag
1.2 www 171: ENDENHEAD
1.10 matthew 172: #
173: # Verify data
174: #
175: # Check the veracity of the course coordinator
1.2 www 176: if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3 www 177: $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2 www 178: return;
179: }
1.10 matthew 180: # Check the proposed home server for the course
181: my %host_servers = &Apache::loncommon::get_library_servers
182: ($ENV{'request.role.domain'});
183: if (! exists($host_servers{$ENV{'form.course_home'}})) {
184: $r->print('Invalid home server for course: '.
185: $ENV{'form.course_home'}.'</body></html>');
186: return;
187: }
1.2 www 188: #
189: # Open course
190: #
1.10 matthew 191: my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
192: $cdescr,$curl,
1.11 www 193: $ENV{'form.course_home'},
194: $ENV{'form.nonstandard'});
1.2 www 195:
1.4 www 196: $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
197: #
1.12 www 198: # Check if created correctly
1.4 www 199: #
200: my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
201: my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
202: $r->print('Created on: '.$crsuhome.'<br>');
1.12 www 203: #
204: # Set environment
205: #
206: my %cenv=();
207: my $envflag=0;
1.4 www 208: if ($ENV{'form.crsid'}) {
1.12 www 209: $envflag=1;
210: $cenv{'courseid'}=$ENV{'form.crsid'};
211: }
212: if (($ccdomain) && ($ccuname)) {
213: if ($ENV{'form.setpolicy'}) {
214: $envflag=1;
215: $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
216: }
217: if ($ENV{'form.setcontent'}) {
218: $envflag=1;
219: $cenv{'question.email'}=$ccuname.':'.$ccdomain;
220: }
1.4 www 221: }
1.12 www 222: if ($envflag) {
223: $r->print('Setting environment: '.
224: &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
225: }
226: #
227: # Open all assignments
228: #
229: if ($ENV{'form.openall'}) {
230: my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
231: my %storecontent = ($storeunder => time,
232: $storeunder.'type' => 'date_start');
233:
234: $r->print('Opening all assignments: '.&Apache::lonnet::cput
235: ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
236: }
1.13 ! www 237: #
! 238: # Set first page
! 239: #
! 240: unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
! 241: $r->print('Setting first resource: ');
! 242: my ($errtext,$fatal)=
! 243: &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
! 244: $r->print(($fatal?$errtext:'read ok').' - ');
! 245: my $title; my $url;
! 246: if ($ENV{'form.firstres'} eq 'syl') {
! 247: $title='Syllabus';
! 248: $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
! 249: } else {
! 250: $title='Navigate Contents';
! 251: $url='/adm/navmaps';
! 252: }
! 253: $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
! 254: my ($errtext,$fatal)=
! 255: &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
! 256: $r->print(($fatal?$errtext:'write ok').'<br>');
! 257: }
1.2 www 258: #
259: # Make current user course adminstrator
260: #
1.12 www 261: my $end=undef;
262: my $addition='';
263: if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
264: $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2 www 265: &Apache::lonnet::assignrole(
1.12 www 266: $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2 www 267: #
268: # Make additional user course administrator
269: #
1.12 www 270: if (($ccdomain) && ($ccuname)) {
1.2 www 271: $r->print('Assigning role of course coordinator to '.
272: $ccuname.' at '.$ccdomain.': '.
1.3 www 273: &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12 www 274: }
1.3 www 275: $r->print('Roles will be active at next login.</body></html>');
1.2 www 276: }
277:
278: # ===================================================================== Handler
1.1 www 279: sub handler {
280: my $r = shift;
281:
282: if ($r->header_only) {
283: $r->content_type('text/html');
284: $r->send_http_header;
285: return OK;
286: }
287:
1.10 matthew 288: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.1 www 289: $r->content_type('text/html');
290: $r->send_http_header;
291:
1.2 www 292: if ($ENV{'form.phase'} eq 'two') {
1.10 matthew 293: &create_course($r);
1.2 www 294: } else {
1.10 matthew 295: &print_course_creation_page($r);
1.2 www 296: }
1.1 www 297: } else {
298: $ENV{'user.error.msg'}=
299: "/adm/createcourse:ccc:0:0:Cannot create courses";
300: return HTTP_NOT_ACCEPTABLE;
301: }
302: return OK;
303: }
304:
305: 1;
306: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>