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

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

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