File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.11: download - view: text, annotated - select for diffs
Sun Aug 18 21:43:59 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Now offers more options - not all of them implemented yet.

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

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