Annotation of loncom/interface/loncreatecourse.pm, revision 1.26

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>