File:  [LON-CAPA] / loncom / interface / loncreatecourse.pm
Revision 1.25: download - view: text, annotated - select for diffs
Thu Jul 17 15:16:45 2003 UTC (20 years, 10 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Added 'grading' parameter to course creation and course parameters.

    1: # The LearningOnline Network
    2: # Create a course
    3: #
    4: # $Id: loncreatecourse.pm,v 1.25 2003/07/17 15:16:45 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:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
   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: $helplink
   95: <form action="/adm/createcourse" method="post" name="ccrs">
   96: <h2>Course Information</h2>
   97: <p>
   98: <b>Course Title:</b>
   99: <input type="text" size="50" name="title">
  100: </p><p>
  101: <b>Course Home Server:</b>$course_home
  102: </p><p>
  103: <b>Course ID/Number (optional)</b>
  104: <input type="text" size="30" name="crsid">
  105: </p>
  106: <h2>Course Content</h2>
  107: <p>
  108: <b>Map:</b>
  109: <input type="text" size="50" name="topmap">
  110: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
  111: </p><p>
  112: <b>Do NOT generate as standard course</b> 
  113: (only check if you know what you are doing):
  114: <input type="checkbox" name="nonstandard">
  115: </p>
  116: <p>
  117: <b>First Resource</b> (standard courses only):
  118: <input type="radio" name="firstres" value="blank">Blank
  119: &nbsp;
  120: <input type="radio" name="firstres" value="syl" checked>Syllabus
  121: &nbsp;
  122: <input type="radio" name="firstres" value="nav">Navigate
  123: </p>
  124: 
  125: <h2>Assessment Parameters</h2>
  126: <p>
  127: <b>Open all assessments: </b>
  128: <input type="checkbox" name="openall" checked>
  129: </p>
  130: <h2>Messaging</h2>
  131: <p>
  132: <b>Set course policy feedback to Course Coordinator: </b>
  133: <input type="checkbox" name="setpolicy" checked>
  134: </p><p>
  135: <b>Set content feedback to Course Coordinator: </b>
  136: <input type="checkbox" name="setcontent" checked>
  137: </p>
  138: <h2>Communication</h2>
  139: <p>
  140: <b>Disable student resource discussion: </b>
  141: <input type="checkbox" name="disresdis" />
  142: </p>
  143: <h2>Access Control</h2>
  144: <p>
  145: <b>Students need access key to enter course: </b>
  146: <input type="checkbox" name="setkeys" />
  147: </p>
  148: <h2>Course Coordinator</h2>
  149: <p>
  150: <b>Username:</b> <input type="text" size="15" name="ccuname" />
  151: </p><p>
  152: <b>Domain:</b> $domform
  153: </p><p>
  154: <b>Immediately expire own role as Course Coordinator:</b>
  155: <input type="checkbox" name="expireown" checked>
  156: </p><p>
  157: <input type="hidden" name="phase" value="two" />
  158: <input type="submit" value="Open Course">
  159: </p>
  160: </form>
  161: </body>
  162: </html>
  163: ENDDOCUMENT
  164: }
  165: 
  166: # ====================================================== Phase two: make course
  167: 
  168: sub create_course {
  169:     my $r=shift;
  170:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
  171:     my $ccuname=$ENV{'form.ccuname'};
  172:     my $ccdomain=$ENV{'form.ccdomain'};
  173:     $ccuname=~s/\W//g;
  174:     $ccdomain=~s/\W//g;
  175:     my $cdescr=$ENV{'form.title'};
  176:     my $curl=$ENV{'form.topmap'};
  177:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
  178:     $r->print(<<ENDENHEAD);
  179: <html>
  180: <head>
  181: <title>The LearningOnline Network with CAPA</title>
  182: </head>
  183: $bodytag
  184: ENDENHEAD
  185:     #
  186:     # Verify data
  187:     #
  188:     # Check the veracity of the course coordinator
  189:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
  190:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
  191: 	return;
  192:     }
  193:     # Check the proposed home server for the course
  194:     my %host_servers = &Apache::loncommon::get_library_servers
  195:         ($ENV{'request.role.domain'});
  196:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
  197:         $r->print('Invalid home server for course: '.
  198:                   $ENV{'form.course_home'}.'</body></html>');
  199:         return;
  200:     }
  201: #
  202: # Open course
  203: #
  204:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
  205:                                                $cdescr,$curl,
  206:                                                $ENV{'form.course_home'},
  207:                                                $ENV{'form.nonstandard'});
  208: 
  209:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
  210: #
  211: # Check if created correctly
  212: #
  213:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
  214:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
  215:     $r->print('Created on: '.$crsuhome.'<br>');
  216: #
  217: # Set environment
  218: #
  219:     my %cenv=();
  220:     my $envflag=0;
  221:     if ($ENV{'form.crsid'}) {
  222: 	$envflag=1;
  223:         $cenv{'courseid'}=$ENV{'form.crsid'};
  224:     }
  225:     if (($ccdomain) && ($ccuname)) {
  226:        if ($ENV{'form.setpolicy'}) {
  227: 	   $envflag=1;
  228:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
  229:        }
  230:        if ($ENV{'form.setcontent'}) {
  231:            $envflag=1;
  232:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
  233:        }
  234:     }
  235:     if ($ENV{'form.setkeys'}) {
  236:        $envflag=1;
  237:        $cenv{'keyaccess'}='yes';
  238:     }
  239:     if ($ENV{'form.disresdis'}) {
  240: 	$envflag=1;
  241:         $cenv{'pch.roles.denied'}='st';
  242:     }
  243: 
  244:     # Record we've not yet viewed the Course Initialization Helper for this course
  245:     $cenv{'course.helper.not.run'} = 1;
  246:     #
  247:     # Use new Randomseed
  248:     #
  249:     $envflag=1;
  250:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
  251:     #
  252:     # By default, use standard grading
  253:     $cenv{'grading'} = 'standard';
  254: 
  255:     if ($envflag) {
  256:        $r->print('Setting environment: '.                 
  257:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
  258:    }
  259: #
  260: # Open all assignments
  261: #
  262:     if ($ENV{'form.openall'}) {
  263:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
  264:        my %storecontent = ($storeunder        => time,
  265:                            $storeunder.'type' => 'date_start');
  266:        
  267:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
  268:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
  269:    }
  270: #
  271: # Set first page
  272: #
  273:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
  274: 	$r->print('Setting first resource: ');
  275:         my ($errtext,$fatal)=
  276:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
  277:         $r->print(($fatal?$errtext:'read ok').' - ');
  278:         my $title; my $url;
  279:         if ($ENV{'form.firstres'} eq 'syl') {
  280: 	    $title='Syllabus';
  281:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
  282:         } else {
  283:             $title='Navigate Contents';
  284:             $url='/adm/navmaps';
  285:         }
  286:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
  287:         ($errtext,$fatal)=
  288:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
  289:         $r->print(($fatal?$errtext:'write ok').'<br>');
  290:   }
  291: #
  292: # Make current user course adminstrator
  293: #
  294:     my $end=undef;
  295:     my $addition='';
  296:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
  297:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
  298:     &Apache::lonnet::assignrole(
  299:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
  300: #
  301: # Make additional user course administrator
  302: #
  303:    if (($ccdomain) && ($ccuname)) {
  304:     $r->print('Assigning role of course coordinator to '.
  305:                $ccuname.' at '.$ccdomain.': '.
  306:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
  307:    }
  308:     if ($ENV{'form.setkeys'}) {
  309: 	$r->print(
  310:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
  311:     }
  312:     $r->print('<p>Roles will be active at next login.</p></body></html>');
  313: }
  314: 
  315: # ===================================================================== Handler
  316: sub handler {
  317:     my $r = shift;
  318: 
  319:     if ($r->header_only) {
  320:        $r->content_type('text/html');
  321:        $r->send_http_header;
  322:        return OK;
  323:     }
  324: 
  325:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
  326:        $r->content_type('text/html');
  327:        $r->send_http_header;
  328: 
  329:        if ($ENV{'form.phase'} eq 'two') {
  330:            &create_course($r);
  331:        } else {
  332: 	   &print_course_creation_page($r);
  333:        }
  334:    } else {
  335:       $ENV{'user.error.msg'}=
  336:         "/adm/createcourse:ccc:0:0:Cannot create courses";
  337:       return HTTP_NOT_ACCEPTABLE; 
  338:    }
  339:    return OK;
  340: } 
  341: 
  342: 1;
  343: __END__

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