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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.10    ! matthew     4: # $Id: loncreatecourse.pm,v 1.9 2002/04/23 21:05: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;
                     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>
        !            94: <b>Top-level 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>
        !            98: <b>Course Home Server:</b>$course_home
        !            99: </p><p>
        !           100: <b>Course ID/Number (optional)</b>
1.6       matthew   101: <input type="text" size="30" name="crsid">
1.10    ! matthew   102: </p><p>
        !           103: <h2>Course Coordinator</h2>
        !           104: <p>
        !           105: Username: <input type="text" size="15" name="ccuname" />
        !           106: </p><p>
1.9       matthew   107: Domain:   $domform
1.10    ! matthew   108: </p><p>
        !           109: <input type="hidden" name="phase" value="two" />
1.6       matthew   110: <input type="submit" value="Open Course">
1.10    ! matthew   111: </p>
1.2       www       112: </form>
                    113: </body>
                    114: </html>
                    115: ENDDOCUMENT
                    116: }
                    117: 
                    118: # ====================================================== Phase two: make course
                    119: 
1.10    ! matthew   120: sub create_course {
1.2       www       121:     my $r=shift;
                    122:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                    123:     my $ccuname=$ENV{'form.ccuname'};
                    124:     my $ccdomain=$ENV{'form.ccdomain'};
                    125:     $ccuname=~s/\W//g;
                    126:     $ccdomain=~s/\W//g;
                    127:     my $cdescr=$ENV{'form.title'};
                    128:     my $curl=$ENV{'form.topmap'};
                    129:     $r->print(<<ENDENHEAD);
                    130: <html>
                    131: <head>
                    132: <title>The LearningOnline Network with CAPA</title>
                    133: </head>
                    134: <body bgcolor="#FFFFFF">
                    135: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    136: <h1>Create a new Course</h1>
                    137: ENDENHEAD
1.10    ! matthew   138:     #
        !           139:     # Verify data
        !           140:     #
        !           141:     # Check the veracity of the course coordinator
1.2       www       142:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       143:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       144: 	return;
                    145:     }
1.10    ! matthew   146:     # Check the proposed home server for the course
        !           147:     my %host_servers = &Apache::loncommon::get_library_servers
        !           148:         ($ENV{'request.role.domain'});
        !           149:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
        !           150:         $r->print('Invalid home server for course: '.
        !           151:                   $ENV{'form.course_home'}.'</body></html>');
        !           152:         return;
        !           153:     }
1.2       www       154: #
                    155: # Open course
                    156: #
1.10    ! matthew   157:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
        !           158:                                                $cdescr,$curl,
        !           159:                                                $ENV{'form.course_home'});
1.2       www       160: 
1.4       www       161:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    162: #
                    163: # Set optional courseid
                    164: #
                    165:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    166:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    167:     $r->print('Created on: '.$crsuhome.'<br>');
                    168:     if ($ENV{'form.crsid'}) {
                    169:        $r->print('Setting optional Course ID/Number: '.                 
                    170:            &Apache::lonnet::reply('put:'.$crsudom.':'.
                    171:                                   $crsunum.':environment:courseid='.
                    172:                                   &Apache::lonnet::escape($ENV{'form.crsid'}),
                    173:                                   $crsuhome).'<br>');
                    174:     }
1.2       www       175: #
                    176: # Make current user course adminstrator
                    177: #
                    178:     $r->print('Assigning role of course coordinator to self: '.
                    179:     &Apache::lonnet::assignrole(
                    180:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
                    181: #
                    182: # Make additional user course administrator
                    183: #
                    184:     $r->print('Assigning role of course coordinator to '.
                    185:                $ccuname.' at '.$ccdomain.': '.
1.3       www       186:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
                    187:     $r->print('Roles will be active at next login.</body></html>');
1.2       www       188: }
                    189: 
                    190: # ===================================================================== Handler
1.1       www       191: sub handler {
                    192:     my $r = shift;
                    193: 
                    194:     if ($r->header_only) {
                    195:        $r->content_type('text/html');
                    196:        $r->send_http_header;
                    197:        return OK;
                    198:     }
                    199: 
1.10    ! matthew   200:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.1       www       201:        $r->content_type('text/html');
                    202:        $r->send_http_header;
                    203: 
1.2       www       204:        if ($ENV{'form.phase'} eq 'two') {
1.10    ! matthew   205:            &create_course($r);
1.2       www       206:        } else {
1.10    ! matthew   207: 	   &print_course_creation_page($r);
1.2       www       208:        }
1.1       www       209:    } else {
                    210:       $ENV{'user.error.msg'}=
                    211:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    212:       return HTTP_NOT_ACCEPTABLE; 
                    213:    }
                    214:    return OK;
                    215: } 
                    216: 
                    217: 1;
                    218: __END__

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