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

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

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