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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
1.5       albertel    3: #
1.39    ! albertel    4: # $Id: loncreatecourse.pm,v 1.38 2003/09/21 21:40:06 www 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.38      www        50: use Apache::lonlocal;
1.28      www        51: 
                     52: # ================================================ Get course directory listing
                     53: 
                     54: sub crsdirlist {
                     55:     my ($courseid,$which)=@_;
                     56:     unless ($which) { $which=''; }
                     57:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     58:     my @listing=&Apache::lonnet::dirlist
                     59: 	($which,$crsdata{'domain'},$crsdata{'num'},
1.39    ! albertel   60: 	 &Apache::loncommon::propath($crsdata{'domain'},$crsdata{'num'}));
1.28      www        61:     my @output=();
                     62:     foreach (@listing) {
                     63: 	unless ($_=~/^\./) {
                     64: 	    push (@output,(split(/\&/,$_))[0]);
                     65: 	}
                     66:     }
                     67:     return @output;
1.29      www        68: }
                     69: 
                     70: # ============================================================= Read a userfile
                     71: 
                     72: sub readfile {
                     73:     my ($courseid,$which)=@_;
                     74:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     75:     return &Apache::lonnet::getfile('/uploaded/'.$crsdata{'domain'}.'/'.
                     76: 				    $crsdata{'num'}.'/'.$which);
                     77: }
                     78: 
                     79: # ============================================================ Write a userfile
                     80: 
                     81: sub writefile {
1.30      www        82:     (my $courseid, my $which,$ENV{'form.output'})=@_;
1.29      www        83:     my %crsdata=&Apache::lonnet::coursedescription($courseid);
                     84:     return &Apache::lonnet::finishuserfileupload(
                     85: 					  $crsdata{'num'},$crsdata{'domain'},
                     86: 					  $crsdata{'home'},
                     87: 					  'output',$which);
                     88: }
                     89: 
1.36      www        90: # ===================================================================== Rewrite
                     91: 
                     92: sub rewritefile {
                     93:     my ($contents,%rewritehash)=@_;
                     94:     foreach (keys %rewritehash) {
                     95: 	my $pattern=$_;
                     96: 	$pattern=~s/(\W)/\\$1/gs;
                     97: 	my $new=$rewritehash{$_};
                     98: 	$contents=~s/$pattern/$new/gs;
                     99:     }
                    100:     return $contents;
                    101: }
                    102: 
1.29      www       103: # ============================================================= Copy a userfile
                    104: 
                    105: sub copyfile {
                    106:     my ($origcrsid,$newcrsid,$which)=@_;
1.36      www       107:     unless ($which=~/\.sequence$/) {
                    108: 	return &writefile($newcrsid,$which,
                    109: 		      &readfile($origcrsid,$which));
                    110:     } else {
                    111: 	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    112: 	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    113: 	return &writefile($newcrsid,$which,
                    114: 		 &rewritefile(
                    115:                      &readfile($origcrsid,$which),
                    116: 	    (
                    117:        '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
                    118:     => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
                    119:             )));
                    120:     }
1.30      www       121: }
                    122: 
                    123: # =============================================================== Copy a dbfile
                    124: 
                    125: sub copydb {
                    126:     my ($origcrsid,$newcrsid,$which)=@_;
                    127:     $which=~s/\.db$//;
                    128:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    129:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    130:     my %data=&Apache::lonnet::dump
                    131: 	($which,$origcrsdata{'domain'},$origcrsdata{'num'});
                    132:     return &Apache::lonnet::put
                    133: 	($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'});
                    134: }
                    135: 
1.35      www       136: # ========================================================== Copy resourcesdata
                    137: 
                    138: sub copyresourcedb {
                    139:     my ($origcrsid,$newcrsid)=@_;
                    140:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    141:     my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
                    142:     my %data=&Apache::lonnet::dump
                    143: 	('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
                    144:     $origcrsid=~s/^\///;
                    145:     $origcrsid=~s/\//\_/;
                    146:     $newcrsid=~s/^\///;
                    147:     $newcrsid=~s/\//\_/;
                    148:     my %newdata=();
                    149:     undef %newdata;
                    150:     my $startdate=$data{$origcrsid.'.0.opendate'};
                    151:     my $today=time;
                    152:     my $delta=0;
                    153:     if ($startdate) {
                    154: 	my $oneday=60*60*24;
                    155: 	$delta=$today-$startdate;
                    156: 	$delta=int($delta/$oneday)*$oneday;
                    157:     }
                    158: # ugly retro fix for broken version of types
                    159:     foreach (keys %data) {
                    160: 	if ($_=~/\wtype$/) {
                    161: 	    my $newkey=$_;
                    162: 	    $newkey=~s/type$/\.type/;
                    163: 	    $data{$newkey}=$data{$_};
                    164: 	    delete $data{$_};
                    165: 	}
                    166:     }
1.37      www       167: # adjust symbs
                    168:     my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
                    169:     $pattern=~s/(\W)/\\$1/gs;
                    170:     my $new=    'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
                    171:     foreach (keys %data) {
                    172: 	if ($_=~/$pattern/) {
                    173: 	    my $newkey=$_;
                    174: 	    $newkey=~s/$pattern/$new/;
                    175: 	    $data{$newkey}=$data{$_};
                    176: 	    delete $data{$_};
                    177: 	}
                    178:     }
1.35      www       179: # adjust dates
                    180:     foreach (keys %data) {
                    181: 	my $thiskey=$_;
                    182: 	$thiskey=~s/^$origcrsid/$newcrsid/;
                    183: 	$newdata{$thiskey}=$data{$_};
                    184: 	if ($data{$_.'.type'}=~/^date/) {
                    185: 	    $newdata{$thiskey}=$newdata{$thiskey}+$delta;
                    186: 	}
                    187:     }
                    188:     return &Apache::lonnet::put
                    189: 	('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
                    190: }
                    191: 
1.30      www       192: # ========================================================== Copy all userfiles
                    193: 
                    194: sub copyuserfiles {
                    195:     my ($origcrsid,$newcrsid)=@_;
                    196:     foreach (&crsdirlist($origcrsid,'userfiles')) {
                    197: 	&copyfile($origcrsid,$newcrsid,$_);
                    198:     }
                    199: }
                    200: # ========================================================== Copy all userfiles
                    201: 
                    202: sub copydbfiles {
                    203:     my ($origcrsid,$newcrsid)=@_;
                    204:     foreach (&crsdirlist($origcrsid)) {
                    205: 	if ($_=~/\.db$/) {
                    206: 	    unless 
1.34      www       207:              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {
1.30      www       208: 		 &copydb($origcrsid,$newcrsid,$_);
                    209: 	     }
                    210: 	}
                    211:     }
1.31      www       212: }
                    213: 
                    214: # ======================================================= Copy all course files
                    215: 
                    216: sub copycoursefiles {
                    217:     my ($origcrsid,$newcrsid)=@_;
                    218:     &copyuserfiles($origcrsid,$newcrsid);
                    219:     &copydbfiles($origcrsid,$newcrsid);
1.35      www       220:     &copyresourcedb($origcrsid,$newcrsid);
1.28      www       221: }
1.13      www       222: 
1.2       www       223: # ===================================================== Phase one: fill-in form
                    224: 
1.10      matthew   225: sub print_course_creation_page {
1.2       www       226:     my $r=shift;
1.10      matthew   227:     my $defdom=$ENV{'request.role.domain'};
                    228:     my %host_servers = &Apache::loncommon::get_library_servers($defdom);
                    229:     my $course_home = '<select name="course_home" size="1">'."\n";
                    230:     foreach my $server (sort(keys(%host_servers))) {
1.14      matthew   231:         $course_home .= qq{<option value="$server"};
                    232:         if ($server eq $Apache::lonnet::perlvar{'lonHostID'}) {
                    233:             $course_home .= " selected ";
                    234:         }
                    235:         $course_home .= qq{>$server $host_servers{$server}</option>};
1.10      matthew   236:     }
                    237:     $course_home .= "\n</select>\n";
1.9       matthew   238:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.12      www       239:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.17      www       240:     my $helplink=&Apache::loncommon::help_open_topic('Create_Course','Help on Creating Courses');
1.32      www       241:     my $cloneform=&Apache::loncommon::select_dom_form
                    242: 	($ENV{'request.role.domain'},'clonedomain').
                    243: 		     &Apache::loncommon::selectcourse_link
                    244: 		     ('ccrs','clonecourse','clonedomain');
                    245:     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript();
1.2       www       246:     $r->print(<<ENDDOCUMENT);
                    247: <html>
1.6       matthew   248: <script language="JavaScript" type="text/javascript">
                    249: var editbrowser = null;
                    250: function openbrowser(formname,elementname) {
                    251:     var url = '/res/?';
                    252:     if (editbrowser == null) {
                    253:         url += 'launch=1&';
                    254:     }
                    255:     url += 'catalogmode=interactive&';
                    256:     url += 'mode=edit&';
                    257:     url += 'form=' + formname + '&';
1.7       matthew   258:     url += 'element=' + elementname + '&';
                    259:     url += 'only=sequence' + '';
1.6       matthew   260:     var title = 'Browser';
                    261:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    262:     options += ',width=700,height=600';
                    263:     editbrowser = open(url,title,options,'1');
                    264:     editbrowser.focus();
                    265: }
                    266: </script>
1.32      www       267: $coursebrowserjs
1.2       www       268: <head>
                    269: <title>The LearningOnline Network with CAPA</title>
                    270: </head>
1.12      www       271: $bodytag
1.17      www       272: $helplink
1.6       matthew   273: <form action="/adm/createcourse" method="post" name="ccrs">
1.10      matthew   274: <h2>Course Information</h2>
                    275: <p>
                    276: <b>Course Title:</b>
1.6       matthew   277: <input type="text" size="50" name="title">
1.10      matthew   278: </p><p>
1.13      www       279: <b>Course Home Server:</b>$course_home
                    280: </p><p>
                    281: <b>Course ID/Number (optional)</b>
                    282: <input type="text" size="30" name="crsid">
                    283: </p>
                    284: <h2>Course Content</h2>
1.32      www       285: <table border="2">
                    286: <tr><th>Completely new course</th><th>Clone an existing course</th></tr>
                    287: <tr><td>
1.13      www       288: <p>
1.11      www       289: <b>Map:</b>
1.6       matthew   290: <input type="text" size="50" name="topmap">
1.24      www       291: <a href="javascript:openbrowser('ccrs','topmap')">Select Map</a>
1.10      matthew   292: </p><p>
1.32      www       293: <b>Do NOT generate as standard course</b><br /> 
1.11      www       294: (only check if you know what you are doing):
                    295: <input type="checkbox" name="nonstandard">
1.13      www       296: </p>
                    297: <p>
1.32      www       298: <b>First Resource</b><br />(standard courses only):
1.17      www       299: <input type="radio" name="firstres" value="blank">Blank
1.13      www       300: &nbsp;
1.17      www       301: <input type="radio" name="firstres" value="syl" checked>Syllabus
1.13      www       302: &nbsp;
                    303: <input type="radio" name="firstres" value="nav">Navigate
                    304: </p>
1.32      www       305: </td><td>
                    306: Course ID: <input input type="text" size="25" name="clonecourse" value="" />
                    307: <br />
                    308: Domain: 
                    309: $cloneform<br />&nbsp;<br />
                    310: Additional settings, if specified below, will override cloned settings.
                    311: </td></tr>
                    312: </table>
1.13      www       313: <h2>Assessment Parameters</h2>
                    314: <p>
1.11      www       315: <b>Open all assessments: </b>
                    316: <input type="checkbox" name="openall" checked>
1.13      www       317: </p>
                    318: <h2>Messaging</h2>
                    319: <p>
1.11      www       320: <b>Set course policy feedback to Course Coordinator: </b>
                    321: <input type="checkbox" name="setpolicy" checked>
                    322: </p><p>
                    323: <b>Set content feedback to Course Coordinator: </b>
                    324: <input type="checkbox" name="setcontent" checked>
                    325: </p>
1.16      www       326: <h2>Communication</h2>
                    327: <p>
                    328: <b>Disable student resource discussion: </b>
1.26      matthew   329: <input type="checkbox" name="disresdis" /> <br />
                    330: <b>Disable student use of chatrooms: </b>
                    331: <input type="checkbox" name="disablechat" />
1.16      www       332: </p>
1.18      www       333: <h2>Access Control</h2>
                    334: <p>
                    335: <b>Students need access key to enter course: </b>
                    336: <input type="checkbox" name="setkeys" />
                    337: </p>
1.10      matthew   338: <h2>Course Coordinator</h2>
                    339: <p>
1.11      www       340: <b>Username:</b> <input type="text" size="15" name="ccuname" />
                    341: </p><p>
                    342: <b>Domain:</b> $domform
1.10      matthew   343: </p><p>
1.11      www       344: <b>Immediately expire own role as Course Coordinator:</b>
                    345: <input type="checkbox" name="expireown" checked>
1.10      matthew   346: </p><p>
                    347: <input type="hidden" name="phase" value="two" />
1.6       matthew   348: <input type="submit" value="Open Course">
1.10      matthew   349: </p>
1.2       www       350: </form>
                    351: </body>
                    352: </html>
                    353: ENDDOCUMENT
                    354: }
                    355: 
                    356: # ====================================================== Phase two: make course
                    357: 
1.10      matthew   358: sub create_course {
1.2       www       359:     my $r=shift;
                    360:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                    361:     my $ccuname=$ENV{'form.ccuname'};
                    362:     my $ccdomain=$ENV{'form.ccdomain'};
                    363:     $ccuname=~s/\W//g;
                    364:     $ccdomain=~s/\W//g;
                    365:     my $cdescr=$ENV{'form.title'};
                    366:     my $curl=$ENV{'form.topmap'};
1.12      www       367:     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
1.2       www       368:     $r->print(<<ENDENHEAD);
                    369: <html>
                    370: <head>
                    371: <title>The LearningOnline Network with CAPA</title>
                    372: </head>
1.12      www       373: $bodytag
1.2       www       374: ENDENHEAD
1.10      matthew   375:     #
                    376:     # Verify data
                    377:     #
                    378:     # Check the veracity of the course coordinator
1.2       www       379:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www       380:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www       381: 	return;
                    382:     }
1.10      matthew   383:     # Check the proposed home server for the course
                    384:     my %host_servers = &Apache::loncommon::get_library_servers
                    385:         ($ENV{'request.role.domain'});
                    386:     if (! exists($host_servers{$ENV{'form.course_home'}})) {
                    387:         $r->print('Invalid home server for course: '.
                    388:                   $ENV{'form.course_home'}.'</body></html>');
                    389:         return;
                    390:     }
1.2       www       391: #
                    392: # Open course
                    393: #
1.32      www       394:     my %cenv=();
1.10      matthew   395:     my $courseid=&Apache::lonnet::createcourse($ENV{'request.role.domain'},
                    396:                                                $cdescr,$curl,
1.11      www       397:                                                $ENV{'form.course_home'},
                    398:                                                $ENV{'form.nonstandard'});
1.2       www       399: 
1.27      bowersj2  400:     # Note: The testing routines depend on this being output; see 
                    401:     # Utils::Course. This needs to at least be output as a comment
                    402:     # if anyone ever decides to not show this, and Utils::Course::new
                    403:     # will need to be suitably modified.
1.4       www       404:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
                    405: #
1.12      www       406: # Check if created correctly
1.4       www       407: #
                    408:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
                    409:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
                    410:     $r->print('Created on: '.$crsuhome.'<br>');
1.12      www       411: #
1.32      www       412: # Are we cloning?
                    413: #
                    414:     my $cloneid='';
                    415:     if (($ENV{'form.clonecourse'}) && ($ENV{'form.clonedomain'})) {
                    416: 	$cloneid='/'.$ENV{'form.clonedomain'}.'/'.$ENV{'form.clonecourse'};
                    417:         my ($clonecrsudom,$clonecrsunum)=($cloneid=~/^\/(\w+)\/(\w+)$/);
                    418: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                    419: 	if ($clonehome eq 'no_host') {
                    420: 	    $r->print(
                    421:     '<br /><font color="red">Attempting to clone non-existing course '.$cloneid.'</font>');
                    422: 	} else {
                    423: 	    $r->print(
                    424:     '<br /><font color="green">Cloning course from '.$clonehome.'</font>');
1.37      www       425: 	    my %oldcenv=&Apache::lonnet::dump('environment',$crsudom,$crsunum);
1.32      www       426: # Copy all files
                    427: 	    &copycoursefiles($cloneid,$courseid);
1.37      www       428: # Restore URL
                    429: 	    $cenv{'url'}=$oldcenv{'url'};
1.32      www       430: # Restore title
1.37      www       431: 	    $cenv{'description'}=$oldcenv{'description'};
                    432: # Mark as cloned
1.35      www       433: 	    $cenv{'clonedfrom'}=$cloneid;
1.32      www       434: 	}
                    435:     }
                    436: #
                    437: # Set environment (will override cloned, if existing)
1.12      www       438: #
1.4       www       439:     if ($ENV{'form.crsid'}) {
1.12      www       440:         $cenv{'courseid'}=$ENV{'form.crsid'};
                    441:     }
                    442:     if (($ccdomain) && ($ccuname)) {
                    443:        if ($ENV{'form.setpolicy'}) {
                    444:            $cenv{'policy.email'}=$ccuname.':'.$ccdomain;
                    445:        }
                    446:        if ($ENV{'form.setcontent'}) {
1.18      www       447:            $cenv{'question.email'}=$ccuname.':'.$ccdomain;
                    448:        }
                    449:     }
                    450:     if ($ENV{'form.setkeys'}) {
                    451:        $cenv{'keyaccess'}='yes';
1.16      www       452:     }
                    453:     if ($ENV{'form.disresdis'}) {
                    454:         $cenv{'pch.roles.denied'}='st';
1.26      matthew   455:     }
                    456:     if ($ENV{'form.disablechat'}) {
                    457:         $cenv{'plc.roles.denied'}='st';
1.21      albertel  458:     }
1.23      bowersj2  459: 
1.32      www       460:     # Record we've not yet viewed the Course Initialization Helper for this 
                    461:     # course
1.23      bowersj2  462:     $cenv{'course.helper.not.run'} = 1;
1.21      albertel  463:     #
                    464:     # Use new Randomseed
                    465:     #
1.22      albertel  466:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
1.25      matthew   467:     #
                    468:     # By default, use standard grading
                    469:     $cenv{'grading'} = 'standard';
1.22      albertel  470: 
1.32      www       471:     $r->print('<br />Setting environment: '.                 
1.12      www       472:           &Apache::lonnet::put('environment',\%cenv,$crsudom,$crsunum).'<br>');
                    473: #
                    474: # Open all assignments
                    475: #
                    476:     if ($ENV{'form.openall'}) {
                    477:        my $storeunder=$crsudom.'_'.$crsunum.'.0.opendate';
1.33      www       478:        my %storecontent = ($storeunder         => time,
                    479:                            $storeunder.'.type' => 'date_start');
1.12      www       480:        
                    481:        $r->print('Opening all assignments: '.&Apache::lonnet::cput
                    482:                  ('resourcedata',\%storecontent,$crsudom,$crsunum).'<br>');
                    483:    }
1.13      www       484: #
                    485: # Set first page
                    486: #
                    487:     unless (($ENV{'form.nonstandard'}) || ($ENV{'form.firstres'} eq 'blank')) {
                    488: 	$r->print('Setting first resource: ');
                    489:         my ($errtext,$fatal)=
                    490:            &Apache::londocs::mapread($crsunum,$crsudom,'default.sequence');
                    491:         $r->print(($fatal?$errtext:'read ok').' - ');
                    492:         my $title; my $url;
                    493:         if ($ENV{'form.firstres'} eq 'syl') {
                    494: 	    $title='Syllabus';
                    495:             $url='/public/'.$crsudom.'/'.$crsunum.'/syllabus';
                    496:         } else {
                    497:             $title='Navigate Contents';
                    498:             $url='/adm/navmaps';
                    499:         }
                    500:         $Apache::lonratedt::resources[1]=$title.':'.$url.':false:start:res';
1.15      albertel  501:         ($errtext,$fatal)=
1.13      www       502:            &Apache::londocs::storemap($crsunum,$crsudom,'default.sequence');
                    503:         $r->print(($fatal?$errtext:'write ok').'<br>');
                    504:   }
1.2       www       505: #
                    506: # Make current user course adminstrator
                    507: #
1.12      www       508:     my $end=undef;
                    509:     my $addition='';
                    510:     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }
                    511:     $r->print('Assigning '.$addition.' role of course coordinator to self: '.
1.2       www       512:     &Apache::lonnet::assignrole(
1.12      www       513:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');
1.2       www       514: #
                    515: # Make additional user course administrator
                    516: #
1.12      www       517:    if (($ccdomain) && ($ccuname)) {
1.2       www       518:     $r->print('Assigning role of course coordinator to '.
                    519:                $ccuname.' at '.$ccdomain.': '.
1.3       www       520:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
1.12      www       521:    }
1.20      www       522:     if ($ENV{'form.setkeys'}) {
                    523: 	$r->print(
                    524:  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">Manage Access Keys</a></p>');
                    525:     }
                    526:     $r->print('<p>Roles will be active at next login.</p></body></html>');
1.2       www       527: }
                    528: 
                    529: # ===================================================================== Handler
1.1       www       530: sub handler {
                    531:     my $r = shift;
                    532: 
                    533:     if ($r->header_only) {
1.38      www       534:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       535:        $r->send_http_header;
                    536:        return OK;
                    537:     }
                    538: 
1.10      matthew   539:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
1.38      www       540:        &Apache::loncommon::content_type($r,'text/html');
1.1       www       541:        $r->send_http_header;
                    542: 
1.2       www       543:        if ($ENV{'form.phase'} eq 'two') {
1.10      matthew   544:            &create_course($r);
1.2       www       545:        } else {
1.10      matthew   546: 	   &print_course_creation_page($r);
1.2       www       547:        }
1.1       www       548:    } else {
                    549:       $ENV{'user.error.msg'}=
                    550:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    551:       return HTTP_NOT_ACCEPTABLE; 
                    552:    }
                    553:    return OK;
                    554: } 
                    555: 
                    556: 1;
                    557: __END__

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