File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Dec 19 17:17:46 2001 UTC (22 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: stable_2002_spring, HEAD
- Finished GPLing the code

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.5 2001/12/19 17:17:46 albertel Exp $
    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: #
   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: #
   40: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
   41: #
   42: package Apache::loncreatecourse;
   43: 
   44: use strict;
   45: use Apache::Constants qw(:common :http);
   46: use Apache::lonnet;
   47: 
   48: # ===================================================== Phase one: fill-in form
   49: 
   50: sub phase_one {
   51:     my $r=shift;
   52: 
   53:     my $defdom=$ENV{'user.domain'};
   54:     $r->print(<<ENDDOCUMENT);
   55: <html>
   56: <head>
   57: <title>The LearningOnline Network with CAPA</title>
   58: </head>
   59: <body bgcolor="#FFFFFF">
   60: <img align=right src=/adm/lonIcons/lonlogos.gif>
   61: <h1>Create a new Course</h1>
   62: <form action=/adm/createcourse method=post>
   63: <h3>Course Title</h3>
   64: <input type=text size=50 name=title>
   65: <h3>Top-level Map</h3>
   66: <input type=text size=50 name=topmap>
   67: <h3>Course ID/Number (optional)</h3>
   68: <input type=text size=30 name=crsid>
   69: <h3>Course Cooordinator</h3>
   70: Username: <input type=text size=15 name=ccuname><br>
   71: Domain: <input type=text size=15 name=ccdomain value=$defdom>
   72: <input type=hidden name=phase value=two><p>
   73: <input type=submit value="Open Course">
   74: </form>
   75: </body>
   76: </html>
   77: ENDDOCUMENT
   78: }
   79: 
   80: # ====================================================== Phase two: make course
   81: 
   82: sub phase_two {
   83:     my $r=shift;
   84:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
   85:     my $ccuname=$ENV{'form.ccuname'};
   86:     my $ccdomain=$ENV{'form.ccdomain'};
   87:     $ccuname=~s/\W//g;
   88:     $ccdomain=~s/\W//g;
   89:     my $cdescr=$ENV{'form.title'};
   90:     my $curl=$ENV{'form.topmap'};
   91:     $r->print(<<ENDENHEAD);
   92: <html>
   93: <head>
   94: <title>The LearningOnline Network with CAPA</title>
   95: </head>
   96: <body bgcolor="#FFFFFF">
   97: <img align=right src=/adm/lonIcons/lonlogos.gif>
   98: <h1>Create a new Course</h1>
   99: ENDENHEAD
  100: #
  101: # Verify data
  102: #
  103:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  104:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  105: 	return;
  106:     }
  107: 
  108: #
  109: # Open course
  110: #
  111:     my $courseid=&Apache::lonnet::createcourse($ENV{'user.domain'},
  112:                                                $cdescr,$curl);
  113: 
  114:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  115: #
  116: # Set optional courseid
  117: #
  118:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  119:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  120:     $r->print('Created on: '.$crsuhome.'<br>');
  121:     if ($ENV{'form.crsid'}) {
  122:        $r->print('Setting optional Course ID/Number: '.                 
  123:            &Apache::lonnet::reply('put:'.$crsudom.':'.
  124:                                   $crsunum.':environment:courseid='.
  125:                                   &Apache::lonnet::escape($ENV{'form.crsid'}),
  126:                                   $crsuhome).'<br>');
  127:     }
  128: #
  129: # Make current user course adminstrator
  130: #
  131:     $r->print('Assigning role of course coordinator to self: '.
  132:     &Apache::lonnet::assignrole(
  133:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
  134: #
  135: # Make additional user course administrator
  136: #
  137:     $r->print('Assigning role of course coordinator to '.
  138:                $ccuname.' at '.$ccdomain.': '.
  139:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  140:     $r->print('Roles will be active at next login.</body></html>');
  141: }
  142: 
  143: # ===================================================================== Handler
  144: sub handler {
  145:     my $r = shift;
  146: 
  147:     if ($r->header_only) {
  148:        $r->content_type('text/html');
  149:        $r->send_http_header;
  150:        return OK;
  151:     }
  152: 
  153:     if (&Apache::lonnet::allowed('ccc',$ENV{'user.domain'})) {
  154:        $r->content_type('text/html');
  155:        $r->send_http_header;
  156: 
  157:        if ($ENV{'form.phase'} eq 'two') {
  158:            &phase_two($r);
  159:        } else {
  160: 	   &phase_one($r);
  161:        }
  162:    } else {
  163:       $ENV{'user.error.msg'}=
  164:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  165:       return HTTP_NOT_ACCEPTABLE; 
  166:    }
  167:    return OK;
  168: } 
  169: 
  170: 1;
  171: __END__

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