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

1.1       www         1: # The LearningOnline Network
                      2: # Create a course
                      3: # (My Desk
                      4: #
                      5: # (Internal Server Error Handler
                      6: #
                      7: # (Login Screen
                      8: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                      9: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     10: #
                     11: # 3/1/1 Gerd Kortemeyer)
                     12: #
                     13: # 3/1 Gerd Kortemeyer)
                     14: #
1.4     ! www        15: # 2/14,2/16,2/17,7/6 Gerd Kortemeyer
1.1       www        16: #
                     17: package Apache::loncreatecourse;
                     18: 
                     19: use strict;
                     20: use Apache::Constants qw(:common :http);
                     21: use Apache::lonnet;
                     22: 
1.2       www        23: # ===================================================== Phase one: fill-in form
                     24: 
                     25: sub phase_one {
                     26:     my $r=shift;
                     27: 
1.3       www        28:     my $defdom=$ENV{'user.domain'};
1.2       www        29:     $r->print(<<ENDDOCUMENT);
                     30: <html>
                     31: <head>
                     32: <title>The LearningOnline Network with CAPA</title>
                     33: </head>
                     34: <body bgcolor="#FFFFFF">
                     35: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     36: <h1>Create a new Course</h1>
                     37: <form action=/adm/createcourse method=post>
                     38: <h3>Course Title</h3>
1.3       www        39: <input type=text size=50 name=title>
1.2       www        40: <h3>Top-level Map</h3>
1.3       www        41: <input type=text size=50 name=topmap>
1.4     ! www        42: <h3>Course ID/Number (optional)</h3>
        !            43: <input type=text size=30 name=crsid>
1.2       www        44: <h3>Course Cooordinator</h3>
                     45: Username: <input type=text size=15 name=ccuname><br>
1.3       www        46: Domain: <input type=text size=15 name=ccdomain value=$defdom>
1.2       www        47: <input type=hidden name=phase value=two><p>
                     48: <input type=submit value="Open Course">
                     49: </form>
                     50: </body>
                     51: </html>
                     52: ENDDOCUMENT
                     53: }
                     54: 
                     55: # ====================================================== Phase two: make course
                     56: 
                     57: sub phase_two {
                     58:     my $r=shift;
                     59:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                     60:     my $ccuname=$ENV{'form.ccuname'};
                     61:     my $ccdomain=$ENV{'form.ccdomain'};
                     62:     $ccuname=~s/\W//g;
                     63:     $ccdomain=~s/\W//g;
                     64:     my $cdescr=$ENV{'form.title'};
                     65:     my $curl=$ENV{'form.topmap'};
                     66:     $r->print(<<ENDENHEAD);
                     67: <html>
                     68: <head>
                     69: <title>The LearningOnline Network with CAPA</title>
                     70: </head>
                     71: <body bgcolor="#FFFFFF">
                     72: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     73: <h1>Create a new Course</h1>
                     74: ENDENHEAD
                     75: #
                     76: # Verify data
                     77: #
                     78:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3       www        79:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www        80: 	return;
                     81:     }
                     82: 
                     83: #
                     84: # Open course
                     85: #
                     86:     my $courseid=&Apache::lonnet::createcourse($ENV{'user.domain'},
                     87:                                                $cdescr,$curl);
                     88: 
1.4     ! www        89:     $r->print('New LON-CAPA Course ID: '.$courseid.'<br>');
        !            90: #
        !            91: # Set optional courseid
        !            92: #
        !            93:     my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/);
        !            94:     my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom);
        !            95:     $r->print('Created on: '.$crsuhome.'<br>');
        !            96:     if ($ENV{'form.crsid'}) {
        !            97:        $r->print('Setting optional Course ID/Number: '.                 
        !            98:            &Apache::lonnet::reply('put:'.$crsudom.':'.
        !            99:                                   $crsunum.':environment:courseid='.
        !           100:                                   &Apache::lonnet::escape($ENV{'form.crsid'}),
        !           101:                                   $crsuhome).'<br>');
        !           102:     }
1.2       www       103: #
                    104: # Make current user course adminstrator
                    105: #
                    106:     $r->print('Assigning role of course coordinator to self: '.
                    107:     &Apache::lonnet::assignrole(
                    108:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
                    109: #
                    110: # Make additional user course administrator
                    111: #
                    112:     $r->print('Assigning role of course coordinator to '.
                    113:                $ccuname.' at '.$ccdomain.': '.
1.3       www       114:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
                    115:     $r->print('Roles will be active at next login.</body></html>');
1.2       www       116: }
                    117: 
                    118: # ===================================================================== Handler
1.1       www       119: sub handler {
                    120:     my $r = shift;
                    121: 
                    122:     if ($r->header_only) {
                    123:        $r->content_type('text/html');
                    124:        $r->send_http_header;
                    125:        return OK;
                    126:     }
                    127: 
                    128:     if (&Apache::lonnet::allowed('ccc',$ENV{'user.domain'})) {
                    129:        $r->content_type('text/html');
                    130:        $r->send_http_header;
                    131: 
1.2       www       132:        if ($ENV{'form.phase'} eq 'two') {
                    133:            &phase_two($r);
                    134:        } else {
                    135: 	   &phase_one($r);
                    136:        }
1.1       www       137:    } else {
                    138:       $ENV{'user.error.msg'}=
                    139:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    140:       return HTTP_NOT_ACCEPTABLE; 
                    141:    }
                    142:    return OK;
                    143: } 
                    144: 
                    145: 1;
                    146: __END__

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