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

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.2       www        15: # 2/14,2/16,2/17 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.2       www        42: <h3>Course Cooordinator</h3>
                     43: Username: <input type=text size=15 name=ccuname><br>
1.3     ! www        44: Domain: <input type=text size=15 name=ccdomain value=$defdom>
1.2       www        45: <input type=hidden name=phase value=two><p>
                     46: <input type=submit value="Open Course">
                     47: </form>
                     48: </body>
                     49: </html>
                     50: ENDDOCUMENT
                     51: }
                     52: 
                     53: # ====================================================== Phase two: make course
                     54: 
                     55: sub phase_two {
                     56:     my $r=shift;
                     57:     my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'});
                     58:     my $ccuname=$ENV{'form.ccuname'};
                     59:     my $ccdomain=$ENV{'form.ccdomain'};
                     60:     $ccuname=~s/\W//g;
                     61:     $ccdomain=~s/\W//g;
                     62:     my $cdescr=$ENV{'form.title'};
                     63:     my $curl=$ENV{'form.topmap'};
                     64:     $r->print(<<ENDENHEAD);
                     65: <html>
                     66: <head>
                     67: <title>The LearningOnline Network with CAPA</title>
                     68: </head>
                     69: <body bgcolor="#FFFFFF">
                     70: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     71: <h1>Create a new Course</h1>
                     72: ENDENHEAD
                     73: #
                     74: # Verify data
                     75: #
                     76:     if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') {
1.3     ! www        77:         $r->print('No such user '.$ccuname.' at '.$ccdomain.'</body></html>');
1.2       www        78: 	return;
                     79:     }
                     80: 
                     81: #
                     82: # Open course
                     83: #
                     84:     my $courseid=&Apache::lonnet::createcourse($ENV{'user.domain'},
                     85:                                                $cdescr,$curl);
                     86: 
                     87:     $r->print('New Course ID: '.$courseid.'<br>');
                     88: #
                     89: # Make current user course adminstrator
                     90: #
                     91:     $r->print('Assigning role of course coordinator to self: '.
                     92:     &Apache::lonnet::assignrole(
                     93:      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'<br>');
                     94: #
                     95: # Make additional user course administrator
                     96: #
                     97:     $r->print('Assigning role of course coordinator to '.
                     98:                $ccuname.' at '.$ccdomain.': '.
1.3     ! www        99:     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
        !           100:     $r->print('Roles will be active at next login.</body></html>');
1.2       www       101: }
                    102: 
                    103: # ===================================================================== Handler
1.1       www       104: sub handler {
                    105:     my $r = shift;
                    106: 
                    107:     if ($r->header_only) {
                    108:        $r->content_type('text/html');
                    109:        $r->send_http_header;
                    110:        return OK;
                    111:     }
                    112: 
                    113:     if (&Apache::lonnet::allowed('ccc',$ENV{'user.domain'})) {
                    114:        $r->content_type('text/html');
                    115:        $r->send_http_header;
                    116: 
1.2       www       117:        if ($ENV{'form.phase'} eq 'two') {
                    118:            &phase_two($r);
                    119:        } else {
                    120: 	   &phase_one($r);
                    121:        }
1.1       www       122:    } else {
                    123:       $ENV{'user.error.msg'}=
                    124:         "/adm/createcourse:ccc:0:0:Cannot create courses";
                    125:       return HTTP_NOT_ACCEPTABLE; 
                    126:    }
                    127:    return OK;
                    128: } 
                    129: 
                    130: 1;
                    131: __END__

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