File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.6: download - view: text, annotated - select for diffs
Mon Mar 18 14:26:28 2002 UTC (22 years, 3 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Added browse link for map specification.

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

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