--- loncom/interface/loncreatecourse.pm 2002/03/18 14:26:28 1.6 +++ loncom/interface/loncreatecourse.pm 2009/09/28 19:21:38 1.127 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.6 2002/03/18 14:26:28 matthew Exp $ +# $Id: loncreatecourse.pm,v 1.127 2009/09/28 19:21:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,35 +25,221 @@ # # http://www.lon-capa.org/ # -# (My Desk -# -# (Internal Server Error Handler -# -# (Login Screen -# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14, -# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer) -# -# 3/1/1 Gerd Kortemeyer) -# -# 3/1 Gerd Kortemeyer) -# -# 2/14,2/16,2/17,7/6 Gerd Kortemeyer -# +### + +=head1 NAME + +Apache::loncreatecourse.pm + +=head1 SYNOPSIS + +Allows domain coordinators to create new +courses and assign course coordinators. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 SUBROUTINES + +=over + +=item handler() + +=item print_course_creation_page() + +=item create_course() + +=item print_intro_page() + +=item upload_batchfile() + +=item process_batchfile() + +=item courserequestbrowser_javascript() + +=item print_creation_logs() + +=item creation_display_filter() + +=item course_types() + +=item context_names() + +=item instcode_srchstr() + +=item syllabuslink_javascript() + +=back + +=cut + package Apache::loncreatecourse; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; +use Apache::loncommon; +use Apache::londocs; +use Apache::lonlocal; +use Apache::lonuserutils; +use Apache::lonclonecourse; +use LONCAPA::batchcreatecourse; +use LONCAPA; # ===================================================== Phase one: fill-in form -sub phase_one { +sub print_course_creation_page { my $r=shift; + my $crstype = 'Community'; + if ($env{'form.phase'} eq 'courseone') { + $crstype = 'Course'; + } + my $defdom=$env{'request.role.domain'}; + my %host_servers = &Apache::lonnet::get_servers($defdom,'library'); + my $course_home = '\n"; + my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain'); + my $cloneform=&Apache::loncommon::select_dom_form + ($env{'request.role.domain'},'clonedomain'). + &Apache::loncommon::selectcourse_link + ('ccrs','clonecourse','clonedomain',undef,undef,undef,$crstype); + my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); + my ($enroll_table,$access_table,$krbdef,$krbdefdom,$krbform,$intform,$locform, + $javascript_validations); + if ($crstype eq 'Course') { + my $starttime = time; + my $endtime = time+(6*30*24*60*60); # 6 months from now, approx + $enroll_table = &Apache::lonuserutils::date_setting_table($starttime, + $endtime,'create_enrolldates'); + $access_table = &Apache::lonuserutils::date_setting_table($starttime, + $endtime,'create_defaultdates'); + ($krbdef,$krbdefdom) = + &Apache::loncommon::get_kerberos_defaults($defdom); + $javascript_validations=&Apache::lonuserutils::javascript_validations( + 'createcourse',$krbdefdom); + my %param = ( formname => 'document.ccrs', + kerb_def_dom => $krbdefdom, + kerb_def_auth => $krbdef + ); + $krbform = &Apache::loncommon::authform_kerberos(%param); + $intform = &Apache::loncommon::authform_internal(%param); + $locform = &Apache::loncommon::authform_local(%param); + } else { + my $title_alert = &mt('A Community title is required'); + my $coord_alert = &mt('The username of the Coordinator is required'); + $javascript_validations = qq| +function validate(formname) { + if (formname.title == '') { + alert("$title_alert"); + return; + } + if (formname.ccuname == '') { + alert("$coord_alert"); + } + formname.submit(); +} + |; + } + my %lt=&Apache::lonlocal::texthash( + 'cinf' => "Course Information", + 'ctit' => "Course Title", + 'chsr' => "Course Home Server", + 'cidn' => "Course ID/Number", + 'opt' => "optional", + 'iinf' => "Institutional Information", + 'stat' => "The following entries will be used to identify the course according to the naming scheme adopted by your institution. Your choices will be used to map an internal LON-CAPA course ID to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution. This mapping is required if you choose to employ automatic population of class lists.", + 'ccod' => "Course Code", + 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231", + 'snid' => "Section Numbers and corresponding LON-CAPA section IDs", + 'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section ID to be used in LON-CAPA e.g., 001:1,002:2", + 'crcs' => "Crosslisted courses", + 'cscs' => "a comma separated list of course sections crosslisted with the current course, with each entry including the institutional course section name followed by a colon and then the (optional) sectionID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2", + 'crco' => "Course Content", + 'cncr' => "Completely new course", + 'cecr' => "Clone an existing course", + 'map' => "Map", + 'smap' => "Select Map", + 'sacr' => "Do NOT generate as standard course", + 'ocik' => "only check if you know what you are doing", + 'fres' => "First Resource", + 'stco' => "standard courses only", + 'blnk' => "Blank", + 'sllb' => "Syllabus", + 'navi' => "Navigate Contents", + 'cid' => "Course ID", + 'dmn' => "Domain", + 'dsh' => "Date Shift", + 'asov' => "Additional settings, if specified below, will override cloned settings", + 'ncd' => "Do not clone date parameters", + 'prd' => 'Clone date parameters as-is', + 'shd' => 'Shift date parameters by number of days', + 'assp' => "Assessment Parameters", + 'oaas' => "Open all assessments", + 'mssg' => "Messaging", + 'scpf' => "Set course policy feedback to Course Coordinator", + 'scfc' => "Set content feedback to Course Coordinator", + 'cmmn' => "Communication", + 'dsrd' => "Disable student resource discussion", + 'dsuc' => "Disable student use of chat rooms", + 'acco' => "Access Control", + 'snak' => "Students need access key to enter course", + 'kaut' => + 'Key authority (id@domain) if other than course', + 'ow' => "Course Owner", + 'cc' => "(will be assigned Course Coordinator role)", + 'user' => "Username", + 'aens' => "Automated enrollment settings", + 'aesc' => "The following settings control automatic enrollment of students in this class based on information available for this specific course from your institution's official classlists.", + 'aadd' => "Automated adds", + 'yes' => "Yes", + 'no' => "No", + 'audr' => "Automated drops", + 'dacu' => "Duration of automated classlist updates", + 'dads' => 'Default Access Dates for Students', + 'dacc' => "Default start and end dates for student access", + 'psam' => "Please select the Authentication mechanism", + 'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process", + 'nech' => "Notification of enrollment changes", + 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?", + 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?", + 'irsp' => "Include retrieval of student photographs?", + 'rshm' => 'Resource Space Home', + 'cgrs' => "Course Group Settings", + 'cgrq' => 'Set a quota for the total disk space available for storage of course group portfolio files', + 'opco' => "Open Course", + 'ginf' => "Community Information", + 'gtit' => "Community Title", + 'ghsr' => "Community Home Server", + 'gidn' => "Community ID/Number", + 'grco' => "Community Content", + 'cngr' => "Completely new community", + 'cegr' => "Clone an existing community", + 'sagr' => "Do NOT generate as standard community", + 'stgo' => "standard communities only", + 'sgpf' => "Set community policy feedback to Coordinator", + 'scfg' => "Set content feedback to Coordinator", + 'dmrd' => "Disable member resource discussion", + 'dmuc' => "Disable member use of chat rooms", + 'mnak' => "Members need access key to enter community", + 'kaug' => + 'Key authority (id@domain) if other than community', + 'co' => "Community Owner", + 'gc' => "(will be assigned Coordinator role)", + 'gid' => "Community ID", + 'crgr' => "Create Community", + 'grts' => "Community Group Settings", + 'grtq' => "Set a quota for the total disk space available for storage of community group portfolio files.", - my $defdom=$ENV{'user.domain'}; - $r->print(< - - -The LearningOnline Network with CAPA - - - -

Create a new Course

+$coursebrowserjs +END + + my %titles = &Apache::lonlocal::texthash( + courseone => 'Create a New Course', + groupone => 'Create a New Community', + ); + my $start_page = + &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js); + my $end_page = + &Apache::loncommon::end_page(); + my $crumbs = + &Apache::lonhtmlcommon::breadcrumbs($crstype.' Information', + 'Create_Course',undef, + 'Create_Courses'); + $r->print($start_page.$crumbs); + + if ($crstype eq 'Course') { + $r->print('
' + .&Apache::lonhtmlcommon::start_pick_box() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'ow'}.' '.$lt{'cc'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'user'}) + .'' + .&Apache::loncommon::studentbrowser_javascript() + .&Apache::loncommon::selectstudent_link('ccrs','ccuname','ccdomain') + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'dmn'},"","LC_odd_row_value") + .$domform + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'cinf'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'ctit'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'chsr'}) + .$course_home + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'cidn'}.' ('.$lt{'opt'}.')') + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'iinf'}.'

' + .$lt{'stat'} + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'ccod'}) + .'' + .'
('.$lt{'toin'}.')' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'snid'}) + .'' + .'
('.$lt{'csli'}.')' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'crcs'}) + .'' + .'
('.$lt{'cscs'}.')' + .&Apache::lonhtmlcommon::row_closure() + ); + + # Table: New Course / Clone Course + $r->print(&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'crco'}.'

' + .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .''.$lt{'cncr'}.'' + .' '.&mt('or').' ' + .''.$lt{'cecr'}.'' + .&Apache::loncommon::end_data_table_header_row() + .&Apache::loncommon::start_data_table_row() + + # New Course: + .'' + .&Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title($lt{'map'}) + .'' + .''.$lt{'smap'}.'' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title('') + .'' + .'
('.$lt{'ocik'}.')' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($lt{'fres'}) + .'' + .' ' + .'' + .' ' + .'' + .'
('.$lt{'stco'}.')' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + + .' ' + + # Clone Course: + .'' + .&Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title($lt{'cid'}) + .'' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::row_title($lt{'dmn'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($lt{'dsh'}) + .'
' + .'
' + .'' + .' ' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_headline() + .$lt{'asov'} + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + .'' + .&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table() + .&Apache::lonhtmlcommon::row_closure() + ); + + $r->print(&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'dads'}.'

' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($lt{'dacc'}) + .$access_table + .&Apache::lonhtmlcommon::row_closure() + ); + + $r->print(&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'assp'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'oaas'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'mssg'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'scpf'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'scfc'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'cmmn'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'dsrd'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'dsuc'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'acco'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'snak'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'kaut'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'rshm'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'rshm'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'aens'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'aadd'}) + .'' + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'audr'}) + .'' + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'dacu'}) + .$enroll_table + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'psam'}) + .$lt{'pcda'}.'
' + .$krbform.'
' + .$intform.'
' + .$locform + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'nech'}) + .$lt{'nccl'}.'
' + .'' + .'' + .'
' + .$lt{'ndcl'}.'
' + .'' + .'' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'irsp'}) + .' ' + .' ' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_headline() + .'

'.$lt{'cgrs'}.'

' + .&Apache::lonhtmlcommon::row_closure() + + .&Apache::lonhtmlcommon::row_title($lt{'cgrq'}) + .'Mb' + .&Apache::lonhtmlcommon::row_closure(1) + + .&Apache::lonhtmlcommon::end_pick_box() + ); + $r->print(< +

+ + + +

+ +ENDDOCUMENT + + } elsif ($crstype eq 'Community') { + $r->print(< -

Course Title

- -

Top-level Map

- -Browse -

Course ID/Number (optional)

- -

Course Cooordinator

-Username:
-Domain: -

- +

$lt{'co'} $lt{'gc'}

+

+ +

+ +

+

$lt{'ginf'}

+

+ +

+ +

+ +

+

$lt{'grco'}

+ + + +
$lt{'cngr'}$lt{'cegr'}
+

+ +$lt{'smap'} +

+ +
+($lt{'ocik'}): + +

+$lt{'fres'}
($lt{'stgo'}): + +  + +  + +

+
+ +
+ +
+
+
+ +
 
+$lt{'asov'}. +
+

+

+

$lt{'mssg'}

+

+ +
+ +

+

$lt{'cmmn'}

+

+ +
+ +

+

$lt{'acco'}

+

+ +
+ +

+

$lt{'rshm'}

+

+ +

+

$lt{'grts'}

+

+$lt{'grtq'} +Mb +

+
+

+ + + +

- - ENDDOCUMENT + } + $r->print($end_page); } # ====================================================== Phase two: make course -sub phase_two { +sub create_course { my $r=shift; - my $topurl='/res/'.&Apache::lonnet::declutter($ENV{'form.topmap'}); - my $ccuname=$ENV{'form.ccuname'}; - my $ccdomain=$ENV{'form.ccdomain'}; - $ccuname=~s/\W//g; - $ccdomain=~s/\W//g; - my $cdescr=$ENV{'form.title'}; - my $curl=$ENV{'form.topmap'}; - $r->print(< - -The LearningOnline Network with CAPA - - - -

Create a new Course

-ENDENHEAD -# -# Verify data -# + my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'}); + my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'}); + my $crstype = 'Community'; + my ($enrollstart,$enrollend,$startaccess,$endaccess); + + if ($env{'form.phase'} eq 'coursetwo') { + $crstype='Course'; + $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll'); + $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll'); + } + $startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess'); + $endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess'); + + my $autharg; + my $authtype; + + if ($env{'form.login'} eq 'krb') { + $authtype = 'krb'; + $authtype .=$env{'form.krbver'}; + $autharg = $env{'form.krbarg'}; + } elsif ($env{'form.login'} eq 'int') { + $authtype ='internal'; + if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) { + $autharg = $env{'form.intarg'}; + } + } elsif ($env{'form.login'} eq 'loc') { + $authtype = 'localauth'; + if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) { + $autharg = $env{'form.locarg'}; + } + } + my $logmsg; + my $start_page=&Apache::loncommon::start_page('Create a New '.$crstype); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses'); + + $r->print($start_page.$crumbs); + + my $args = { + crstype => $crstype, + ccuname => $ccuname, + ccdomain => $ccdomain, + cdescr => $env{'form.title'}, + curl => $env{'form.topmap'}, + course_domain => $env{'request.role.domain'}, + course_home => $env{'form.course_home'}, + nonstandard => $env{'form.nonstandard'}, + crscode => $env{'form.crscode'}, + crsquota => $env{'form.crsquota'}, + clonecourse => $env{'form.clonecourse'}, + clonedomain => $env{'form.clonedomain'}, + datemode => $env{'form.datemode'}, + dateshift => $env{'form.dateshift'}, + crsid => $env{'form.crsid'}, + curruser => $env{'user.name'}.':'.$env{'user.domain'}, + crssections => $env{'form.crssections'}, + crsxlist => $env{'form.crsxlist'}, + autoadds => $env{'form.autoadds'}, + autodrops => $env{'form.autodrops'}, + notify_owner => $env{'form.notify_owner'}, + notify_dc => $env{'form.notify_dc'}, + no_end_date => $env{'form.no_end_date'}, + showphotos => $env{'form.showphotos'}, + authtype => $authtype, + autharg => $autharg, + enrollstart => $enrollstart, + enrollend => $enrollend, + startaccess => $startaccess, + endaccess => $endaccess, + setpolicy => $env{'form.setpolicy'}, + setcontent => $env{'form.setcontent'}, + reshome => $env{'form.reshome'}, + setkeys => $env{'form.setkeys'}, + keyauth => $env{'form.keyauth'}, + disresdis => $env{'form.disresdis'}, + disablechat => $env{'form.disablechat'}, + openall => $env{'form.openall'}, + firstres => $env{'form.firstres'} + }; + + # + # Verify data + # + # Check the veracity of the course coordinator if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') { - $r->print('No such user '.$ccuname.' at '.$ccdomain.''); + $r->print('
'); + $r->print('
' + .&mt('No such user [_1] at domain [_2].',''.$ccuname.'',''.$ccdomain.'') + .'
'); + $r->print(&mt('Please click Back on your browser and select another user, or [_1]Create User[_2]' + , '' + .'' + .'' + .'' + ) + .'
'.&Apache::loncommon::end_page() + ); return; } + # Check the proposed home server for the course + my %host_servers = + &Apache::lonnet::get_servers($env{'request.role.domain'},'library'); + if (! exists($host_servers{$env{'form.course_home'}})) { + $r->print(&mt('Invalid home server for course: [_1]' + ,$env{'form.course_home'}.&Apache::loncommon::end_page())); + return; + } + my ($courseid,$crsudom,$crsunum); + my ($success,$output) = + &Apache::loncommon::construct_course($args,\$logmsg,\$courseid, + \$crsudom,\$crsunum, + $env{'user.domain'}, + $env{'user.name'},'dc_create'); + $r->print($output); + if ($success) { + # + # Make the requested user a course coordinator or group coordinator + # + if (($ccdomain) && ($ccuname)) { + $r->print(&mt('Assigning role of '.$crstype.' Coordinator to [_1]:', + ,''.$ccuname.':'.$ccdomain.'') + .&Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid, + 'cc','','','','','createcourse').'

'); + } + if ($env{'form.setkeys'}) { + $r->print( + '

'.&mt('Manage Access Keys').'

'); + } + # Flush the course logs so reverse user roles immediately updated + &Apache::lonnet::flushcourselogs(); + $r->print('

'.&mt('Roles will be active at next login').'.

'); + } + $r->print('

'. + &mt("Create Another $crstype").'

'. + &Apache::loncommon::end_page()); +} -# -# Open course -# - my $courseid=&Apache::lonnet::createcourse($ENV{'user.domain'}, - $cdescr,$curl); +sub print_intro_page { + my $r = shift; + my $start_page = + &Apache::loncommon::start_page('Create a New Course or Community'); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses'); + my $end_page = + &Apache::loncommon::end_page(); + my $helplink=&Apache::loncommon::help_open_topic('Create_Course_Community',&mt('Help on Creating Courses and Communities')); - $r->print('New LON-CAPA Course ID: '.$courseid.'
'); -# -# Set optional courseid -# - my ($crsudom,$crsunum)=($courseid=~/^\/(\w+)\/(\w+)$/); - my $crsuhome=&Apache::lonnet::homeserver($crsunum,$crsudom); - $r->print('Created on: '.$crsuhome.'
'); - if ($ENV{'form.crsid'}) { - $r->print('Setting optional Course ID/Number: '. - &Apache::lonnet::reply('put:'.$crsudom.':'. - $crsunum.':environment:courseid='. - &Apache::lonnet::escape($ENV{'form.crsid'}), - $crsuhome).'
'); + my @choices = ({ internal_name => 'courseone', + name => &mt('Create a single course'), + short_description => + &mt('Create a new course by completing an online form.'), + }, + { internal_name => 'groupone', + name => &mt('Create a single community'), + short_description => + &mt('Create a new collaborative community by completing an online form.'), + }, + { internal_name => 'batchone', + name => &mt('Create courses/communities by uploading an attributes file'), + short_description => + &mt('Upload an attributes file containing specifications for one or more courses or communities in XML format.'), + help => 'Batch_Creation', + }, + { internal_name => 'requestdisplay', + name => &mt('Approve or reject course requests'), + short_description => + &mt('Display course creation requests submitted by authorized users, held pending approval by a Domain Coordinator.'), + }, + { internal_name => 'creationlog', + name => &mt('View course creation log'), + short_description => + &mt('Display information about when, how and by whom courses were created in this domain.'), + }, + ); + my $options; + foreach my $choice (@choices) { + $options .='

'. + $choice->{'name'}.''; + if (exists($choice->{'help'})) { + $options .= &Apache::loncommon::help_open_topic($choice->{'help'}); + } + $options .= "

\n".' '.(' 'x8).$choice->{'short_description'}. + "\n"; } -# -# Make current user course adminstrator -# - $r->print('Assigning role of course coordinator to self: '. - &Apache::lonnet::assignrole( - $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc').'
'); -# -# Make additional user course administrator -# - $r->print('Assigning role of course coordinator to '. - $ccuname.' at '.$ccdomain.': '. - &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'

'); - $r->print('Roles will be active at next login.'); + + $r->print(<print($start_page.$crumbs); + $r->print('

'.&mt('Upload a courses or communities attributes file').'

'); + $r->print('
'. + ''. + '

'. + '
'); + $r->print($end_page); + return; +} + +sub process_batchfile { + my $r = shift; + my $start_page = + &Apache::loncommon::start_page('Create a New Course or Community'); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses'); + my $end_page = + &Apache::loncommon::end_page(); + my $defdom=$env{'request.role.domain'}; + my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef, + 'batchupload',undef,undef, + undef,undef,$defdom); + my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-); + my ($result,$logmsg); + if (-e "$batchfilepath") { + open(FILE,"<$batchfilepath"); + my @buffer = ; + close(FILE); + if ((defined($filename)) && (defined($batchdir))) { + my @requests = ($filename); + my %courseids = (); + ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses( + \@requests,\%courseids,'web',$defdom, + $env{'user.name'},$env{'user.domain'}); + if ($result) { + if (!-e "$batchdir/processed") { + mkdir("$batchdir/processed", 0755); + open(FILE,">$batchdir/processed/$filename"); + print FILE @buffer; + close(FILE); + if (-e "$batchdir/processed/$filename") { + unlink("$batchdir/pending/$filename"); + } + } + } + } + } + $r->print($start_page.$crumbs.$logmsg.$result.'
'. + &mt('Creation options menu').''.$end_page); + +} + +sub courserequestbrowser_javascript { + return <<"ENDREQBRW"; + +ENDREQBRW +} + +sub print_creation_logs { + my ($r) = @_; + my $formname = 'creationlog'; + my $dom = $env{'request.role.domain'}; + $r->print('
'); + # set defaults + my $now = time(); + my $defstart = $now - (7*24*3600); #7 days ago + my %defaults = ( + page => '1', + show => '10', + type => 'any', + context => 'any', + created_before_date => $now, + created_after_date => $defstart, + ); + my ($contexts,$contextnames) = &context_names(); + my $more_records = 0; + my %curr; + foreach my $item ('show','page','type','context') { + $curr{$item} = $env{'form.'.$item}; + } + my $createdafter = &Apache::lonhtmlcommon::get_date_from_form('created_after_date'); + my $createdbefore = &Apache::lonhtmlcommon::get_date_from_form('created_before_date'); + $curr{'created_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('created_after_date'); + $curr{'created_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('created_before_date'); + foreach my $key (keys(%defaults)) { + if ($curr{$key} eq '') { + $curr{$key} = $defaults{$key}; + } + } + my (%whodunit,$version); + ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/); + $r->print(&creation_display_filter($formname,\%curr,$version)); + my $showntablehdr = 0; + my $tablehdr = &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ' '.&mt('Creation Date').''. + ''.&mt('Creator').''.&mt('Description').''. + ''.&mt('Course Owner(s)').''; + if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'any')) { + $tablehdr .= ''.&mt('Institutional Code').''; + } + $tablehdr .= ''.&mt('Course Type').''. + ''.&mt('Creation Context').''. + &Apache::loncommon::end_data_table_header_row(); + my ($minshown,$maxshown); + $minshown = 1; + my $count = 0; + if ($curr{'show'} ne &mt('all')) { + $maxshown = $curr{'page'} * $curr{'show'}; + if ($curr{'page'} > 1) { + $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'}; + } + } + my $crstype = 'Course'; + if ($curr{'type'} eq 'any') { + $crstype = '.'; + } elsif ($curr{'type'} eq 'community') { + $crstype = 'Community'; + } + + my ($instcodefilter,$regexpok); + my (@codetitles,%cat_titles,%cat_order,%cat_items,$officialjs); + my ($jscript,$totcodes,$numtitles,$lasttitle) = + &Apache::courseclassifier::instcode_selectors_data($dom,$formname, + \%cat_items,\@codetitles,\%cat_titles,\%cat_order, + $officialjs); + if ($numtitles) { + if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'unofficial')) { + $instcodefilter = &instcode_srchstr($dom,$numtitles); + &Apache::courseclassifier::instcode_search_str($dom,$numtitles); + if ($curr{'type'} eq 'official') { + $regexpok = 1; + } else { + unless ($instcodefilter eq '') { + $regexpok = -1; + } + } + } + } + if ($instcodefilter eq '') { $instcodefilter = '.'; } + + my $creationcontext = '.'; + my $context_regexp = join('|',@{$contexts}); + if ($curr{'context'} =~ /^($context_regexp)$/) { + $creationcontext = $curr{'context'}; + } + my %courses = + &Apache::lonnet::courseiddump($dom,'.',1,$instcodefilter,'.','.',undef,undef, + $crstype,$regexpok,undef,undef,'1','creationlog', + undef,undef,undef,$curr{'created_before_date'}, + $curr{'created_after_date'},$creationcontext); + foreach my $cid (sort { $courses{$b}{'created'}<=>$courses{$a}{'created'} } (keys(%courses))) { + $count ++; + next if ($count < $minshown); + if (!$showntablehdr) { + $r->print($tablehdr); + $showntablehdr = 1; + } + if ($courses{$cid}{'creator'} ne '') { + if ($whodunit{$courses{$cid}{'creator'}} eq '') { + my ($uname,$udom) = split(':',$courses{$cid}{'creator'}); + $whodunit{$courses{$cid}{'creator'}} = + &Apache::loncommon::plainname($uname,$udom); + } + } + my $description = $courses{$cid}{'description'}; + my @owners; + my $singleowner = $courses{$cid}{'owner'}; + push(@owners,$singleowner); + if (ref($courses{$cid}{'co-owners'}) eq 'ARRAY') { + foreach my $item (@{$courses{$cid}{'co-owners'}}) { + push(@owners,$item); + } + } + my %ownernames; + foreach my $owner (@owners) { + my ($ownername,$ownerdom); + if ($owner =~ /:/) { + ($ownername,$ownerdom) = split(/:/,$owner); + } else { + $ownername = $owner; + if ($owner ne '') { + $ownerdom = $dom; + } + } + if ($ownername ne '' && $ownerdom ne '') { + unless (ref($ownernames{$ownername.':'.$ownerdom}) eq 'HASH') { + my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom); + $ownernames{$ownername.':'.$ownerdom} = \%namehash; + } + } + } + my @lastnames; + foreach my $owner (keys(%ownernames)) { + if (ref($ownernames{$owner}) eq 'HASH') { + push(@lastnames,$ownernames{$owner}{'lastname'}); + } + } + my $ownerlastnames = join(', ',sort(@lastnames)); + my $showtype; + if ($courses{$cid}{type} eq 'Community') { + $showtype = &mt('community'); + } else { + my $instcode = $courses{$cid}{inst_code}; + if ($instcode ne '') { + $showtype = &mt('official'); + } else { + $showtype = &mt('unofficial'); + } + } + my $showcontext; + + if ($courses{$cid}{context} =~ /^($context_regexp)$/) { + $showcontext = $contextnames->{$courses{$cid}{context}}; + } + my $created = &Apache::lonlocal::locallocaltime($courses{$cid}{'created'}); + my ($cdom,$cnum) = split('_',$cid); + $r->print(&Apache::loncommon::start_data_table_row()."\n". + ''.$count.''.$created.''."\n". + ''.$whodunit{$courses{$cid}{creator}}.''."\n". + ''.$description.' '.&mt('Syllabus').''.$ownerlastnames.''); + if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'any')) { + $r->print(''.$courses{$cid}{'inst_code'}.''); + } + $r->print(''.$showtype.''.$showcontext.''.&Apache::loncommon::end_data_table_row()."\n"); + } + if ($showntablehdr) { + $r->print(&Apache::loncommon::end_data_table().'
'); + if (($curr{'page'} > 1) || ($more_records)) { + $r->print(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'.&mt('Previous [_1] changes',$curr{'show'}).''.&mt('Next [_1] changes',$curr{'show'}).'
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $r->print('

'. + &mt('There are no records to display'). + '

'); + } + $r->print(''. + '
'); + return; +} + +sub creation_display_filter { + my ($formname,$curr,$version) = @_; + my $nolink = 1; + my ($contexts,$contextnames) = &context_names(); + my $output = ''; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'created_after_date', + $curr->{'created_after_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'created_before_date', + $curr->{'created_before_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + $output .= ''. + ''; + my ($types,$typenames) = &course_types(); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 1) { + $output .= ''; + } + } + $output .= ''. + ''. + '
'. + ''.&mt('Records/page:').'
'. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + '
  '.&mt('Window during which course was created:').'
'. + ''. + ''. + '
'.&mt('After:'). + ''.$startform.'
'.&mt('Before:').''.$endform.'
'. + '
  '. + &mt('Course Type:').'
  '. + &mt('Creation Context:').'
'; + + # Update Display button + $output .= '

'. + ''. + '

'; + + # Server version info + $output .= '

'. + &mt('Only courses created from servers running LON-CAPA [_1] or later are displayed.','2.9.0'); + if ($version) { + $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version); + } + $output .= '


'; + return $output; +} + +sub course_types { + my @types = qw(official unofficial community); + my %typename = ( + official => 'Official course', + unofficial => 'Unofficial course', + community => 'Community', + ); + return (\@types,\%typename); +} + +sub context_names { + my @contexts = qw(auto web dc_create requestcrs); + my %contextnames = + &Apache::lonlocal::texthash ( + auto => 'Automated creation from batch file', + web => 'Batch creation from uploaded file', + dc_create => 'Single course created by Domain Coordinator', + requestcrs => 'Processing of submitted course request', + ); + return (\@contexts,\%contextnames); +} + +sub instcode_srchstr { + my ($domain,$numtitles) = @_; + my $instcode; + if (defined($numtitles) && $numtitles == 0) { + $instcode = '.+'; + } else { + my (%codedefaults,@code_order); + my $defaults_result = + &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults, + \@code_order); + if ($defaults_result eq 'ok') { + $instcode ='^'; + foreach my $item (@code_order) { + $instcode .= $codedefaults{$item}; + } + $instcode .= '$'; + } else { + $instcode = '.+'; + } + } + return $instcode; +} + +sub syllabuslink_javascript { + return <<"ENDJS"; + +function ToSyllabus(cdom,cnum) { + if (cdom == '' || cdom == null) { + return; + } + if (cnum == '' || cnum == null) { + return; + } + var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'; + var url = "/public/"+cdom+"/"+cnum+"/syllabus"; + syllwin = window.open(url,'',options,1); + syllwin.focus(); + return; +} + +ENDJS + } # ===================================================================== Handler @@ -164,27 +1301,106 @@ sub handler { my $r = shift; if ($r->header_only) { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } - if (&Apache::lonnet::allowed('ccc',$ENV{'user.domain'})) { - $r->content_type('text/html'); + if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - if ($ENV{'form.phase'} eq 'two') { - &phase_two($r); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['phase']); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse", + text=>"Creation Options", + faq=>79,bug=>'Dom Coord Interface',}); + if (($env{'form.phase'} eq 'coursetwo') || + ($env{'form.phase'} eq 'grouptwo')) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}", + text=>&mt('[_1] Creation Settings',), + faq=>9,bug=>'Dom Coord Interface',}); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.phase'}", + text=>"Creation Outcome", + faq=>9,bug=>'Dom Coord Interface',}); + &create_course($r); + } elsif (($env{'form.phase'} eq 'courseone') || + ($env{'form.phase'} eq 'groupone')) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.phase'}", + text=>&mt('[_1] Creation Settings',), + faq=>9,bug=>'Dom Coord Interface',}); + &print_course_creation_page($r); + } elsif ($env{'form.phase'} eq 'batchone') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.phase'}", + text=>"Upload Description File", + faq=>9,bug=>'Dom Coord Interface',}); + &upload_batchfile($r); + } elsif ($env{'form.phase'} eq 'batchtwo') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}", + text=>"Upload Description File", + faq=>9,bug=>'Dom Coord Interface',}); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.phase'}", + text=>"Creation Outcome", + faq=>9,bug=>'Dom Coord Interface',}); + &process_batchfile($r); + } elsif ($env{'form.phase'} eq 'requestdisplay') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=$env{'form.phase'}", + text=>&mt('[_1] Display Request Queue',), + faq=>9,bug=>'Dom Coord Interface',}); + my $js = &courserequestbrowser_javascript(); + my $start_page=&Apache::loncommon::start_page('Display Requests',$js); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Requests','Course_Request',undef,'Course_Request'); + $r->print($start_page.$crumbs."\n".'
'. + &Apache::loncoursequeueadmin::display_queued_requests( + 'domain',$env{'request.role.domain'}).'
'. + &Apache::loncommon::end_page()); + } elsif ($env{'form.phase'} eq 'requestchange') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=requestdisplay", + text=>&mt('[_1] Display Request Queue',), + faq=>9,bug=>'Dom Coord Interface',}, + {href=>"/adm/createcourse?phase=requestchange", + text=>&mt('[_1] Requests Updated',), + faq=>9,bug=>'Dom Coord Interface',},); + my $start_page=&Apache::loncommon::start_page('Update Requests Result'); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Requests Updated','Course_Request',undef,'Course_Request'); + $r->print($start_page.$crumbs."\n".'
'. + &Apache::loncoursequeueadmin::update_request_queue( + 'domain',$env{'request.role.domain'}).'
'. + &Apache::loncommon::end_page()); + } elsif ($env{'form.phase'} eq 'creationlog') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/createcourse?phase=creationlog", + text=>&mt('[_1] Display Creation History',),}); + my $js = ''; + my $start_page=&Apache::loncommon::start_page('Course Creation Logs',$js); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Created Courses','Creation_Log',undef,'Creation_Log'); + $r->print($start_page.$crumbs."\n".'
'); + &print_creation_logs($r); + $r->print('
'.&Apache::loncommon::end_page()); } else { - &phase_one($r); + &print_intro_page($r); } } else { - $ENV{'user.error.msg'}= - "/adm/createcourse:ccc:0:0:Cannot create courses"; + $env{'user.error.msg'}= + "/adm/createcourse:ccc:0:0:Cannot create courses or communities"; return HTTP_NOT_ACCEPTABLE; } return OK; -} +} 1; __END__