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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.9     ! matthew     4: # $Id: loncreatecourse.pm,v 1.8 2002/04/08 19:12:25 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: 
                     50: sub phase_one {
                     51:     my $r=shift;
1.3       www        52:     my $defdom=$ENV{'user.domain'};
1.9     ! matthew    53:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.2       www        54:     $r->print(<<ENDDOCUMENT);
                     55: <html>
1.6       matthew    56: <script language="JavaScript" type="text/javascript">
                     57: var editbrowser = null;
                     58: function openbrowser(formname,elementname) {
                     59:     var url = '/res/?';
                     60:     if (editbrowser == null) {
                     61:         url += 'launch=1&';
                     62:     }
                     63:     url += 'catalogmode=interactive&';
                     64:     url += 'mode=edit&';
                     65:     url += 'form=' + formname + '&';
1.7       matthew    66:     url += 'element=' + elementname + '&';
                     67:     url += 'only=sequence' + '';
1.6       matthew    68:     var title = 'Browser';
                     69:     var options = 'scrollbars=1,resizable=1,menubar=0';
                     70:     options += ',width=700,height=600';
                     71:     editbrowser = open(url,title,options,'1');
                     72:     editbrowser.focus();
                     73: }
                     74: </script>
1.2       www        75: <head>
                     76: <title>The LearningOnline Network with CAPA</title>
                     77: </head>
                     78: <body bgcolor="#FFFFFF">
1.6       matthew    79: <img align="right" src="/adm/lonIcons/lonlogos.gif">
1.2       www        80: <h1>Create a new Course</h1>
1.6       matthew    81: <form action="/adm/createcourse" method="post" name="ccrs">
1.2       www        82: <h3>Course Title</h3>
1.6       matthew    83: <input type="text" size="50" name="title">
1.2       www        84: <h3>Top-level Map</h3>
1.6       matthew    85: <input type="text" size="50" name="topmap">
                     86: <a href="javascript:openbrowser('ccrs','topmap')">Browse</a>
1.4       www        87: <h3>Course ID/Number (optional)</h3>
1.6       matthew    88: <input type="text" size="30" name="crsid">
1.8       matthew    89: <h3>Course Coordinator</h3>
1.6       matthew    90: Username: <input type="text" size="15" name="ccuname" /><br>
1.9     ! matthew    91: Domain:   $domform
1.6       matthew    92: <input type="hidden" name="phase" value="two" /><p>
                     93: <input type="submit" value="Open Course">
1.2       www        94: </form>
                     95: </body>
                     96: </html>
                     97: ENDDOCUMENT
                     98: }
                     99: 
                    100: # ====================================================== Phase two: make course
                    101: 
                    102: sub phase_two {
                    103:     my $r=shift;
                    104:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                    105:     my $ccuname=$ENV{'form.ccuname'};
                    106:     my $ccdomain=$ENV{'form.ccdomain'};
                    107:     $ccuname=~s/\W//g;
                    108:     $ccdomain=~s/\W//g;
                    109:     my $cdescr=$ENV{'form.title'};
                    110:     my $curl=$ENV{'form.topmap'};
                    111:     $r->print(<<ENDENHEAD);
                    112: <html>
                    113: <head>
                    114: <title>The LearningOnline Network with CAPA</title>
                    115: </head>
                    116: <body bgcolor="#FFFFFF">
                    117: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    118: <h1>Create a new Course</h1>
                    119: ENDENHEAD
                    120: #
                    121: # Verify data
                    122: #
                    123:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       124:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       125: 	return;
                    126:     }
                    127: 
                    128: #
                    129: # Open course
                    130: #
                    131:     my $courseid=&Apache::lonnet::createcourse($ENV{'user.domain'},
                    132:                                                $cdescr,$curl);
                    133: 
1.4       www       134:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    135: #
                    136: # Set optional courseid
                    137: #
                    138:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    139:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    140:     $r->print('Created on: '.$crsuhome.'<br>');
                    141:     if ($ENV{'form.crsid'}) {
                    142:        $r->print('Setting optional Course ID/Number: '.                 
                    143:            &Apache::lonnet::reply('put:'.$crsudom.':'.
                    144:                                   $crsunum.':environment:courseid='.
                    145:                                   &Apache::lonnet::escape($ENV{'form.crsid'}),
                    146:                                   $crsuhome).'<br>');
                    147:     }
1.2       www       148: #
                    149: # Make current user course adminstrator
                    150: #
                    151:     $r->print('Assigning role of course coordinator to self: '.
                    152:     &Apache::lonnet::assignrole(
                    153:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
                    154: #
                    155: # Make additional user course administrator
                    156: #
                    157:     $r->print('Assigning role of course coordinator to '.
                    158:                $ccuname.' at '.$ccdomain.': '.
1.3       www       159:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
                    160:     $r->print('Roles will be active at next login.</body></html>');
1.2       www       161: }
                    162: 
                    163: # ===================================================================== Handler
1.1       www       164: sub handler {
                    165:     my $r = shift;
                    166: 
                    167:     if ($r->header_only) {
                    168:        $r->content_type('text/html');
                    169:        $r->send_http_header;
                    170:        return OK;
                    171:     }
                    172: 
                    173:     if (&Apache::lonnet::allowed('ccc',$ENV{'user.domain'})) {
                    174:        $r->content_type('text/html');
                    175:        $r->send_http_header;
                    176: 
1.2       www       177:        if ($ENV{'form.phase'} eq 'two') {
                    178:            &phase_two($r);
                    179:        } else {
                    180: 	   &phase_one($r);
                    181:        }
1.1       www       182:    } else {
                    183:       $ENV{'user.error.msg'}=
                    184:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    185:       return HTTP_NOT_ACCEPTABLE; 
                    186:    }
                    187:    return OK;
                    188: } 
                    189: 
                    190: 1;
                    191: __END__

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