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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.11    ! www         4: # $Id: loncreatecourse.pm,v 1.10 2002/08/08 20:37:37 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;
                     47: 
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.2       www        61:     $r->print(<<ENDDOCUMENT);
                     62: <html>
1.6       matthew    63: <script language="JavaScript" type="text/javascript">
                     64: var editbrowser = null;
                     65: function openbrowser(formname,elementname) {
                     66:     var url = '/res/?';
                     67:     if (editbrowser == null) {
                     68:         url += 'launch=1&';
                     69:     }
                     70:     url += 'catalogmode=interactive&';
                     71:     url += 'mode=edit&';
                     72:     url += 'form=' + formname + '&';
1.7       matthew    73:     url += 'element=' + elementname + '&';
                     74:     url += 'only=sequence' + '';
1.6       matthew    75:     var title = 'Browser';
                     76:     var options = 'scrollbars=1,resizable=1,menubar=0';
                     77:     options += ',width=700,height=600';
                     78:     editbrowser = open(url,title,options,'1');
                     79:     editbrowser.focus();
                     80: }
                     81: </script>
1.2       www        82: <head>
                     83: <title>The LearningOnline Network with CAPA</title>
                     84: </head>
                     85: <body bgcolor="#FFFFFF">
1.6       matthew    86: <img align="right" src="/adm/lonIcons/lonlogos.gif">
1.2       www        87: <h1>Create a new Course</h1>
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'};
                    146:     $r->print(<<ENDENHEAD);
                    147: <html>
                    148: <head>
                    149: <title>The LearningOnline Network with CAPA</title>
                    150: </head>
                    151: <body bgcolor="#FFFFFF">
                    152: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    153: <h1>Create a new Course</h1>
                    154: ENDENHEAD
1.10      matthew   155:     #
                    156:     # Verify data
                    157:     #
                    158:     # Check the veracity of the course coordinator
1.2       www       159:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       160:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       161: 	return;
                    162:     }
1.10      matthew   163:     # Check the proposed home server for the course
                    164:     my %host_servers = &Apache::loncommon::get_library_servers
                    165:         ($ENV{'request.role.domain'});
                    166:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
                    167:         $r->print('Invalid home server for course: '.
                    168:                   $ENV{'form.course_home'}.'</body></html>');
                    169:         return;
                    170:     }
1.2       www       171: #
                    172: # Open course
                    173: #
1.10      matthew   174:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
                    175:                                                $cdescr,$curl,
1.11    ! www       176:                                                $ENV{'form.course_home'},
        !           177:                                                $ENV{'form.nonstandard'});
1.2       www       178: 
1.4       www       179:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    180: #
                    181: # Set optional courseid
                    182: #
                    183:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    184:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    185:     $r->print('Created on: '.$crsuhome.'<br>');
                    186:     if ($ENV{'form.crsid'}) {
                    187:        $r->print('Setting optional Course ID/Number: '.                 
                    188:            &Apache::lonnet::reply('put:'.$crsudom.':'.
                    189:                                   $crsunum.':environment:courseid='.
                    190:                                   &Apache::lonnet::escape($ENV{'form.crsid'}),
                    191:                                   $crsuhome).'<br>');
                    192:     }
1.2       www       193: #
                    194: # Make current user course adminstrator
                    195: #
                    196:     $r->print('Assigning role of course coordinator to self: '.
                    197:     &Apache::lonnet::assignrole(
                    198:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
                    199: #
                    200: # Make additional user course administrator
                    201: #
                    202:     $r->print('Assigning role of course coordinator to '.
                    203:                $ccuname.' at '.$ccdomain.': '.
1.3       www       204:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
                    205:     $r->print('Roles will be active at next login.</body></html>');
1.2       www       206: }
                    207: 
                    208: # ===================================================================== Handler
1.1       www       209: sub handler {
                    210:     my $r = shift;
                    211: 
                    212:     if ($r->header_only) {
                    213:        $r->content_type('text/html');
                    214:        $r->send_http_header;
                    215:        return OK;
                    216:     }
                    217: 
1.10      matthew   218:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.1       www       219:        $r->content_type('text/html');
                    220:        $r->send_http_header;
                    221: 
1.2       www       222:        if ($ENV{'form.phase'} eq 'two') {
1.10      matthew   223:            &create_course($r);
1.2       www       224:        } else {
1.10      matthew   225: 	   &print_course_creation_page($r);
1.2       www       226:        }
1.1       www       227:    } else {
                    228:       $ENV{'user.error.msg'}=
                    229:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    230:       return HTTP_NOT_ACCEPTABLE; 
                    231:    }
                    232:    return OK;
                    233: } 
                    234: 
                    235: 1;
                    236: __END__

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