File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.10: download - view: text, annotated - select for diffs
Thu Aug 8 20:37:37 2002 UTC (21 years, 9 months ago) by matthew
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, HEAD
Bug 263.
Changed oh-so descriptive function names of 'phase_one' and 'phase_two' to
'print_course_creation_page' and 'create_course'.
Rewrote html for course creation page.  Now user must specify a home server
for a course.  Suggestions on determining a default server would be appreciated.
When creating a course, now deal with course_home form parameter and pass it
to lonnet.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.10 2002/08/08 20:37:37 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 print_course_creation_page {
   51:     my $r=shift;
   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";
   60:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
   61:     $r->print(<<ENDDOCUMENT);
   62: <html>
   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 + '&';
   73:     url += 'element=' + elementname + '&';
   74:     url += 'only=sequence' + '';
   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>
   82: <head>
   83: <title>The LearningOnline Network with CAPA</title>
   84: </head>
   85: <body bgcolor="#FFFFFF">
   86: <img align="right" src="/adm/lonIcons/lonlogos.gif">
   87: <h1>Create a new Course</h1>
   88: <form action="/adm/createcourse" method="post" name="ccrs">
   89: <h2>Course Information</h2>
   90: <p>
   91: <b>Course Title:</b>
   92: <input type="text" size="50" name="title">
   93: </p><p>
   94: <b>Top-level Map:</b>
   95: <input type="text" size="50" name="topmap">
   96: <a href="javascript:openbrowser('ccrs','topmap')">Browse</a>
   97: </p><p>
   98: <b>Course Home Server:</b>$course_home
   99: </p><p>
  100: <b>Course ID/Number (optional)</b>
  101: <input type="text" size="30" name="crsid">
  102: </p><p>
  103: <h2>Course Coordinator</h2>
  104: <p>
  105: Username: <input type="text" size="15" name="ccuname" />
  106: </p><p>
  107: Domain:   $domform
  108: </p><p>
  109: <input type="hidden" name="phase" value="two" />
  110: <input type="submit" value="Open Course">
  111: </p>
  112: </form>
  113: </body>
  114: </html>
  115: ENDDOCUMENT
  116: }
  117: 
  118: # ====================================================== Phase two: make course
  119: 
  120: sub create_course {
  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
  138:     #
  139:     # Verify data
  140:     #
  141:     # Check the veracity of the course coordinator
  142:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  143:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  144: 	return;
  145:     }
  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:     }
  154: #
  155: # Open course
  156: #
  157:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  158:                                                $cdescr,$curl,
  159:                                                $ENV{'form.course_home'});
  160: 
  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:     }
  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.': '.
  186:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  187:     $r->print('Roles will be active at next login.</body></html>');
  188: }
  189: 
  190: # ===================================================================== Handler
  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: 
  200:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  201:        $r->content_type('text/html');
  202:        $r->send_http_header;
  203: 
  204:        if ($ENV{'form.phase'} eq 'two') {
  205:            &create_course($r);
  206:        } else {
  207: 	   &print_course_creation_page($r);
  208:        }
  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>