File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.14: download - view: text, annotated - select for diffs
Thu Sep 26 15:19:39 2002 UTC (21 years, 8 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Fixes Bug 690 - default server for the course is now set to current server
if the user is logged into a library.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.14 2002/09/26 15:19:39 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: use Apache::loncommon;
   48: use Apache::lonratedt;
   49: use Apache::londocs;
   50: 
   51: # ===================================================== Phase one: fill-in form
   52: 
   53: sub print_course_creation_page {
   54:     my $r=shift;
   55:     my $defdom=$ENV{'request.role.domain'};
   56:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
   57:     my $course_home = '<select name="course_home" size="1">'."\n";
   58:     foreach my $server (sort(keys(%host_servers))) {
   59:         $course_home .= qq{<option value="$server"};
   60:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
   61:             $course_home .= " selected ";
   62:         }
   63:         $course_home .= qq{>$server $host_servers{$server}</option>};
   64:     }
   65:     $course_home .= "\n</select>\n";
   66:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
   67:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
   68: 
   69:     $r->print(<<ENDDOCUMENT);
   70: <html>
   71: <script language="JavaScript" type="text/javascript">
   72: var editbrowser = null;
   73: function openbrowser(formname,elementname) {
   74:     var url = '/res/?';
   75:     if (editbrowser == null) {
   76:         url += 'launch=1&';
   77:     }
   78:     url += 'catalogmode=interactive&';
   79:     url += 'mode=edit&';
   80:     url += 'form=' + formname + '&';
   81:     url += 'element=' + elementname + '&';
   82:     url += 'only=sequence' + '';
   83:     var title = 'Browser';
   84:     var options = 'scrollbars=1,resizable=1,menubar=0';
   85:     options += ',width=700,height=600';
   86:     editbrowser = open(url,title,options,'1');
   87:     editbrowser.focus();
   88: }
   89: </script>
   90: <head>
   91: <title>The LearningOnline Network with CAPA</title>
   92: </head>
   93: $bodytag
   94: <form action="/adm/createcourse" method="post" name="ccrs">
   95: <h2>Course Information</h2>
   96: <p>
   97: <b>Course Title:</b>
   98: <input type="text" size="50" name="title">
   99: </p><p>
  100: <b>Course Home Server:</b>$course_home
  101: </p><p>
  102: <b>Course ID/Number (optional)</b>
  103: <input type="text" size="30" name="crsid">
  104: </p>
  105: <h2>Course Content</h2>
  106: <p>
  107: <b>Map:</b>
  108: <input type="text" size="50" name="topmap">
  109: <a href="javascript:openbrowser('ccrs','topmap')">Browse</a>
  110: </p><p>
  111: <b>Do NOT generate as standard course</b> 
  112: (only check if you know what you are doing):
  113: <input type="checkbox" name="nonstandard">
  114: </p>
  115: <p>
  116: <b>First Resource</b> (standard courses only):
  117: <input type="radio" name="firstres" value="blank" checked>Blank
  118: &nbsp;
  119: <input type="radio" name="firstres" value="syl">Syllabus
  120: &nbsp;
  121: <input type="radio" name="firstres" value="nav">Navigate
  122: </p>
  123: 
  124: <h2>Assessment Parameters</h2>
  125: <p>
  126: <b>Open all assessments: </b>
  127: <input type="checkbox" name="openall" checked>
  128: </p>
  129: <h2>Messaging</h2>
  130: <p>
  131: <b>Set course policy feedback to Course Coordinator: </b>
  132: <input type="checkbox" name="setpolicy" checked>
  133: </p><p>
  134: <b>Set content feedback to Course Coordinator: </b>
  135: <input type="checkbox" name="setcontent" checked>
  136: </p>
  137: 
  138: <h2>Course Coordinator</h2>
  139: <p>
  140: <b>Username:</b> <input type="text" size="15" name="ccuname" />
  141: </p><p>
  142: <b>Domain:</b> $domform
  143: </p><p>
  144: <b>Immediately expire own role as Course Coordinator:</b>
  145: <input type="checkbox" name="expireown" checked>
  146: </p><p>
  147: <input type="hidden" name="phase" value="two" />
  148: <input type="submit" value="Open Course">
  149: </p>
  150: </form>
  151: </body>
  152: </html>
  153: ENDDOCUMENT
  154: }
  155: 
  156: # ====================================================== Phase two: make course
  157: 
  158: sub create_course {
  159:     my $r=shift;
  160:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  161:     my $ccuname=$ENV{'form.ccuname'};
  162:     my $ccdomain=$ENV{'form.ccdomain'};
  163:     $ccuname=~s/\W//g;
  164:     $ccdomain=~s/\W//g;
  165:     my $cdescr=$ENV{'form.title'};
  166:     my $curl=$ENV{'form.topmap'};
  167:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  168:     $r->print(<<ENDENHEAD);
  169: <html>
  170: <head>
  171: <title>The LearningOnline Network with CAPA</title>
  172: </head>
  173: $bodytag
  174: ENDENHEAD
  175:     #
  176:     # Verify data
  177:     #
  178:     # Check the veracity of the course coordinator
  179:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  180:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  181: 	return;
  182:     }
  183:     # Check the proposed home server for the course
  184:     my %host_servers = &Apache::loncommon::get_library_servers
  185:         ($ENV{'request.role.domain'});
  186:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  187:         $r->print('Invalid home server for course: '.
  188:                   $ENV{'form.course_home'}.'</body></html>');
  189:         return;
  190:     }
  191: #
  192: # Open course
  193: #
  194:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  195:                                                $cdescr,$curl,
  196:                                                $ENV{'form.course_home'},
  197:                                                $ENV{'form.nonstandard'});
  198: 
  199:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  200: #
  201: # Check if created correctly
  202: #
  203:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  204:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  205:     $r->print('Created on: '.$crsuhome.'<br>');
  206: #
  207: # Set environment
  208: #
  209:     my %cenv=();
  210:     my $envflag=0;
  211:     if ($ENV{'form.crsid'}) {
  212: 	$envflag=1;
  213:         $cenv{'courseid'}=$ENV{'form.crsid'};
  214:     }
  215:     if (($ccdomain) && ($ccuname)) {
  216:        if ($ENV{'form.setpolicy'}) {
  217: 	   $envflag=1;
  218:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  219:        }
  220:        if ($ENV{'form.setcontent'}) {
  221:            $envflag=1;
  222:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  223:        }
  224:     }
  225:     if ($envflag) {
  226:        $r->print('Setting environment: '.                 
  227:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  228:    }
  229: #
  230: # Open all assignments
  231: #
  232:     if ($ENV{'form.openall'}) {
  233:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  234:        my %storecontent = ($storeunder        => time,
  235:                            $storeunder.'type' => 'date_start');
  236:        
  237:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
  238:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  239:    }
  240: #
  241: # Set first page
  242: #
  243:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
  244: 	$r->print('Setting first resource: ');
  245:         my ($errtext,$fatal)=
  246:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  247:         $r->print(($fatal?$errtext:'read ok').' - ');
  248:         my $title; my $url;
  249:         if ($ENV{'form.firstres'} eq 'syl') {
  250: 	    $title='Syllabus';
  251:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  252:         } else {
  253:             $title='Navigate Contents';
  254:             $url='/adm/navmaps';
  255:         }
  256:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  257:         my ($errtext,$fatal)=
  258:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  259:         $r->print(($fatal?$errtext:'write ok').'<br>');
  260:   }
  261: #
  262: # Make current user course adminstrator
  263: #
  264:     my $end=undef;
  265:     my $addition='';
  266:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  267:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
  268:     &Apache::lonnet::assignrole(
  269:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  270: #
  271: # Make additional user course administrator
  272: #
  273:    if (($ccdomain) && ($ccuname)) {
  274:     $r->print('Assigning role of course coordinator to '.
  275:                $ccuname.' at '.$ccdomain.': '.
  276:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  277:    }
  278:     $r->print('Roles will be active at next login.</body></html>');
  279: }
  280: 
  281: # ===================================================================== Handler
  282: sub handler {
  283:     my $r = shift;
  284: 
  285:     if ($r->header_only) {
  286:        $r->content_type('text/html');
  287:        $r->send_http_header;
  288:        return OK;
  289:     }
  290: 
  291:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  292:        $r->content_type('text/html');
  293:        $r->send_http_header;
  294: 
  295:        if ($ENV{'form.phase'} eq 'two') {
  296:            &create_course($r);
  297:        } else {
  298: 	   &print_course_creation_page($r);
  299:        }
  300:    } else {
  301:       $ENV{'user.error.msg'}=
  302:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  303:       return HTTP_NOT_ACCEPTABLE; 
  304:    }
  305:    return OK;
  306: } 
  307: 
  308: 1;
  309: __END__

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