Annotation of loncom/interface/loncreatecourse.pm, revision 1.28

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.28    ! www         4: # $Id: loncreatecourse.pm,v 1.27 2003/08/07 14:28:49 bowersj2 Exp $
1.5       albertel    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: #
1.1       www        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: #
1.4       www        40: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
1.1       www        41: #
                     42: package Apache::loncreatecourse;
                     43: 
                     44: use strict;
                     45: use Apache::Constants qw(:common :http);
                     46: use Apache::lonnet;
1.12      www        47: use Apache::loncommon;
1.13      www        48: use Apache::lonratedt;
                     49: use Apache::londocs;
1.28    ! www        50: 
        !            51: # -------------------------------------------- Return path to profile directory
        !            52: 
        !            53: sub propath {
        !            54:     my ($udom,$uname)=@_;
        !            55:     $udom=~s/\W//g;
        !            56:     $uname=~s/\W//g;
        !            57:     my $subdir=$uname.'__';
        !            58:     $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
        !            59:     my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
        !            60:     return $proname;
        !            61: } 
        !            62: 
        !            63: # ================================================ Get course directory listing
        !            64: 
        !            65: sub crsdirlist {
        !            66:     my ($courseid,$which)=@_;
        !            67:     unless ($which) { $which=''; }
        !            68:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
        !            69:     my @listing=&Apache::lonnet::dirlist
        !            70: 	($which,$crsdata{'domain'},$crsdata{'num'},
        !            71: 	 &propath($crsdata{'domain'},$crsdata{'num'}));
        !            72:     my @output=();
        !            73:     foreach (@listing) {
        !            74: 	unless ($_=~/^\./) {
        !            75: 	    push (@output,(split(/\&/,$_))[0]);
        !            76: 	}
        !            77:     }
        !            78:     return @output;
        !            79: }
1.13      www        80: 
1.2       www        81: # ===================================================== Phase one: fill-in form
                     82: 
1.10      matthew    83: sub print_course_creation_page {
1.2       www        84:     my $r=shift;
1.10      matthew    85:     my $defdom=$ENV{'request.role.domain'};
                     86:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
                     87:     my $course_home = '<select name="course_home" size="1">'."\n";
                     88:     foreach my $server (sort(keys(%host_servers))) {
1.14      matthew    89:         $course_home .= qq{<option value="$server"};
                     90:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
                     91:             $course_home .= " selected ";
                     92:         }
                     93:         $course_home .= qq{>$server $host_servers{$server}</option>};
1.10      matthew    94:     }
                     95:     $course_home .= "\n</select>\n";
1.9       matthew    96:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12      www        97:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.17      www        98:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
1.2       www        99:     $r->print(<<ENDDOCUMENT);
                    100: <html>
1.6       matthew   101: <script language="JavaScript" type="text/javascript">
                    102: var editbrowser = null;
                    103: function openbrowser(formname,elementname) {
                    104:     var url = '/res/?';
                    105:     if (editbrowser == null) {
                    106:         url += 'launch=1&';
                    107:     }
                    108:     url += 'catalogmode=interactive&';
                    109:     url += 'mode=edit&';
                    110:     url += 'form=' + formname + '&';
1.7       matthew   111:     url += 'element=' + elementname + '&';
                    112:     url += 'only=sequence' + '';
1.6       matthew   113:     var title = 'Browser';
                    114:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    115:     options += ',width=700,height=600';
                    116:     editbrowser = open(url,title,options,'1');
                    117:     editbrowser.focus();
                    118: }
                    119: </script>
1.2       www       120: <head>
                    121: <title>The LearningOnline Network with CAPA</title>
                    122: </head>
1.12      www       123: $bodytag
1.17      www       124: $helplink
1.6       matthew   125: <form action="/adm/createcourse" method="post" name="ccrs">
1.10      matthew   126: <h2>Course Information</h2>
                    127: <p>
                    128: <b>Course Title:</b>
1.6       matthew   129: <input type="text" size="50" name="title">
1.10      matthew   130: </p><p>
1.13      www       131: <b>Course Home Server:</b>$course_home
                    132: </p><p>
                    133: <b>Course ID/Number (optional)</b>
                    134: <input type="text" size="30" name="crsid">
                    135: </p>
                    136: <h2>Course Content</h2>
                    137: <p>
1.11      www       138: <b>Map:</b>
1.6       matthew   139: <input type="text" size="50" name="topmap">
1.24      www       140: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
1.10      matthew   141: </p><p>
1.11      www       142: <b>Do NOT generate as standard course</b> 
                    143: (only check if you know what you are doing):
                    144: <input type="checkbox" name="nonstandard">
1.13      www       145: </p>
                    146: <p>
                    147: <b>First Resource</b> (standard courses only):
1.17      www       148: <input type="radio" name="firstres" value="blank">Blank
1.13      www       149: &nbsp;
1.17      www       150: <input type="radio" name="firstres" value="syl" checked>Syllabus
1.13      www       151: &nbsp;
                    152: <input type="radio" name="firstres" value="nav">Navigate
                    153: </p>
                    154: 
                    155: <h2>Assessment Parameters</h2>
                    156: <p>
1.11      www       157: <b>Open all assessments: </b>
                    158: <input type="checkbox" name="openall" checked>
1.13      www       159: </p>
                    160: <h2>Messaging</h2>
                    161: <p>
1.11      www       162: <b>Set course policy feedback to Course Coordinator: </b>
                    163: <input type="checkbox" name="setpolicy" checked>
                    164: </p><p>
                    165: <b>Set content feedback to Course Coordinator: </b>
                    166: <input type="checkbox" name="setcontent" checked>
                    167: </p>
1.16      www       168: <h2>Communication</h2>
                    169: <p>
                    170: <b>Disable student resource discussion: </b>
1.26      matthew   171: <input type="checkbox" name="disresdis" /> <br />
                    172: <b>Disable student use of chatrooms: </b>
                    173: <input type="checkbox" name="disablechat" />
1.16      www       174: </p>
1.18      www       175: <h2>Access Control</h2>
                    176: <p>
                    177: <b>Students need access key to enter course: </b>
                    178: <input type="checkbox" name="setkeys" />
                    179: </p>
1.10      matthew   180: <h2>Course Coordinator</h2>
                    181: <p>
1.11      www       182: <b>Username:</b> <input type="text" size="15" name="ccuname" />
                    183: </p><p>
                    184: <b>Domain:</b> $domform
1.10      matthew   185: </p><p>
1.11      www       186: <b>Immediately expire own role as Course Coordinator:</b>
                    187: <input type="checkbox" name="expireown" checked>
1.10      matthew   188: </p><p>
                    189: <input type="hidden" name="phase" value="two" />
1.6       matthew   190: <input type="submit" value="Open Course">
1.10      matthew   191: </p>
1.2       www       192: </form>
                    193: </body>
                    194: </html>
                    195: ENDDOCUMENT
                    196: }
                    197: 
                    198: # ====================================================== Phase two: make course
                    199: 
1.10      matthew   200: sub create_course {
1.2       www       201:     my $r=shift;
                    202:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                    203:     my $ccuname=$ENV{'form.ccuname'};
                    204:     my $ccdomain=$ENV{'form.ccdomain'};
                    205:     $ccuname=~s/\W//g;
                    206:     $ccdomain=~s/\W//g;
                    207:     my $cdescr=$ENV{'form.title'};
                    208:     my $curl=$ENV{'form.topmap'};
1.12      www       209:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2       www       210:     $r->print(<<ENDENHEAD);
                    211: <html>
                    212: <head>
                    213: <title>The LearningOnline Network with CAPA</title>
                    214: </head>
1.12      www       215: $bodytag
1.2       www       216: ENDENHEAD
1.10      matthew   217:     #
                    218:     # Verify data
                    219:     #
                    220:     # Check the veracity of the course coordinator
1.2       www       221:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       222:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       223: 	return;
                    224:     }
1.10      matthew   225:     # Check the proposed home server for the course
                    226:     my %host_servers = &Apache::loncommon::get_library_servers
                    227:         ($ENV{'request.role.domain'});
                    228:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
                    229:         $r->print('Invalid home server for course: '.
                    230:                   $ENV{'form.course_home'}.'</body></html>');
                    231:         return;
                    232:     }
1.2       www       233: #
                    234: # Open course
                    235: #
1.10      matthew   236:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
                    237:                                                $cdescr,$curl,
1.11      www       238:                                                $ENV{'form.course_home'},
                    239:                                                $ENV{'form.nonstandard'});
1.2       www       240: 
1.27      bowersj2  241:     # Note: The testing routines depend on this being output; see 
                    242:     # Utils::Course. This needs to at least be output as a comment
                    243:     # if anyone ever decides to not show this, and Utils::Course::new
                    244:     # will need to be suitably modified.
1.4       www       245:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    246: #
1.12      www       247: # Check if created correctly
1.4       www       248: #
                    249:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    250:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    251:     $r->print('Created on: '.$crsuhome.'<br>');
1.12      www       252: #
                    253: # Set environment
                    254: #
                    255:     my %cenv=();
                    256:     my $envflag=0;
1.4       www       257:     if ($ENV{'form.crsid'}) {
1.12      www       258: 	$envflag=1;
                    259:         $cenv{'courseid'}=$ENV{'form.crsid'};
                    260:     }
                    261:     if (($ccdomain) && ($ccuname)) {
                    262:        if ($ENV{'form.setpolicy'}) {
                    263: 	   $envflag=1;
                    264:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
                    265:        }
                    266:        if ($ENV{'form.setcontent'}) {
1.18      www       267:            $envflag=1;
                    268:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
                    269:        }
                    270:     }
                    271:     if ($ENV{'form.setkeys'}) {
                    272:        $envflag=1;
                    273:        $cenv{'keyaccess'}='yes';
1.16      www       274:     }
                    275:     if ($ENV{'form.disresdis'}) {
                    276: 	$envflag=1;
                    277:         $cenv{'pch.roles.denied'}='st';
1.26      matthew   278:     }
                    279:     if ($ENV{'form.disablechat'}) {
                    280: 	$envflag=1;
                    281:         $cenv{'plc.roles.denied'}='st';
1.21      albertel  282:     }
1.23      bowersj2  283: 
                    284:     # Record we've not yet viewed the Course Initialization Helper for this course
                    285:     $cenv{'course.helper.not.run'} = 1;
1.21      albertel  286:     #
                    287:     # Use new Randomseed
                    288:     #
1.22      albertel  289:     $envflag=1;
                    290:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.25      matthew   291:     #
                    292:     # By default, use standard grading
                    293:     $cenv{'grading'} = 'standard';
1.22      albertel  294: 
1.12      www       295:     if ($envflag) {
                    296:        $r->print('Setting environment: '.                 
                    297:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
                    298:    }
                    299: #
                    300: # Open all assignments
                    301: #
                    302:     if ($ENV{'form.openall'}) {
                    303:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
                    304:        my %storecontent = ($storeunder        => time,
                    305:                            $storeunder.'type' => 'date_start');
                    306:        
                    307:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
                    308:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
                    309:    }
1.13      www       310: #
                    311: # Set first page
                    312: #
                    313:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
                    314: 	$r->print('Setting first resource: ');
                    315:         my ($errtext,$fatal)=
                    316:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
                    317:         $r->print(($fatal?$errtext:'read ok').' - ');
                    318:         my $title; my $url;
                    319:         if ($ENV{'form.firstres'} eq 'syl') {
                    320: 	    $title='Syllabus';
                    321:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
                    322:         } else {
                    323:             $title='Navigate Contents';
                    324:             $url='/adm/navmaps';
                    325:         }
                    326:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15      albertel  327:         ($errtext,$fatal)=
1.13      www       328:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
                    329:         $r->print(($fatal?$errtext:'write ok').'<br>');
                    330:   }
1.2       www       331: #
                    332: # Make current user course adminstrator
                    333: #
1.12      www       334:     my $end=undef;
                    335:     my $addition='';
                    336:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
                    337:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2       www       338:     &Apache::lonnet::assignrole(
1.12      www       339:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2       www       340: #
                    341: # Make additional user course administrator
                    342: #
1.12      www       343:    if (($ccdomain) && ($ccuname)) {
1.2       www       344:     $r->print('Assigning role of course coordinator to '.
                    345:                $ccuname.' at '.$ccdomain.': '.
1.3       www       346:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12      www       347:    }
1.20      www       348:     if ($ENV{'form.setkeys'}) {
                    349: 	$r->print(
                    350:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
                    351:     }
                    352:     $r->print('<p>Roles will be active at next login.</p></body></html>');
1.2       www       353: }
                    354: 
                    355: # ===================================================================== Handler
1.1       www       356: sub handler {
                    357:     my $r = shift;
                    358: 
                    359:     if ($r->header_only) {
                    360:        $r->content_type('text/html');
                    361:        $r->send_http_header;
                    362:        return OK;
                    363:     }
                    364: 
1.10      matthew   365:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.1       www       366:        $r->content_type('text/html');
                    367:        $r->send_http_header;
                    368: 
1.2       www       369:        if ($ENV{'form.phase'} eq 'two') {
1.10      matthew   370:            &create_course($r);
1.2       www       371:        } else {
1.10      matthew   372: 	   &print_course_creation_page($r);
1.2       www       373:        }
1.1       www       374:    } else {
                    375:       $ENV{'user.error.msg'}=
                    376:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    377:       return HTTP_NOT_ACCEPTABLE; 
                    378:    }
                    379:    return OK;
                    380: } 
                    381: 
                    382: 1;
                    383: __END__

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