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

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

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