--- loncom/interface/loncreatecourse.pm 2008/04/30 23:23:07 1.107 +++ loncom/interface/loncreatecourse.pm 2009/11/04 14:12:19 1.133 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.107 2008/04/30 23:23:07 raeburn Exp $ +# $Id: loncreatecourse.pm,v 1.133 2009/11/04 14:12:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,6 +27,52 @@ # ### +=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; @@ -44,7 +90,7 @@ use LONCAPA; sub print_course_creation_page { my $r=shift; - my $crstype = 'Group'; + my $crstype = 'Community'; if ($env{'form.phase'} eq 'courseone') { $crstype = 'Course'; } @@ -86,14 +132,16 @@ sub print_course_creation_page { $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("A group title is required"); + alert("$title_alert"); return; } if (formname.ccuname == '') { - alert("The username of the group coordinator is required"); + alert("$coord_alert"); } formname.submit(); } @@ -124,9 +172,10 @@ function validate(formname) { 'stco' => "standard courses only", 'blnk' => "Blank", 'sllb' => "Syllabus", - 'navi' => "Navigate", + 'navi' => "Course 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', @@ -138,12 +187,11 @@ function validate(formname) { 'scfc' => "Set content feedback to Course Coordinator", 'cmmn' => "Communication", 'dsrd' => "Disable student resource discussion", - 'dsuc' => "Disable student use of chatrooms", + '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', - 'cc' => "Course Coordinator", + '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.", @@ -152,8 +200,9 @@ function validate(formname) { '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", + '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?", @@ -161,31 +210,37 @@ function validate(formname) { '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' => "Group Information", - 'gtit' => "Group Title", - 'ghsr' => "Group Home Server", - 'gidn' => "Group ID/Number", - 'grco' => "Group Content", - 'cngr' => "Completely new group", - 'cegr' => "Clone an existing group", - 'sagr' => "Do NOT generate as standard group", - 'stgo' => "standard groups only", - 'sgpf' => "Set group policy feedback to Group Coordinator", - 'scfg' => "Set content feedback to Group Coordinator", - 'dmrd' => "Disable member resource discussion", - 'dmuc' => "Disable member use of chatrooms", - 'mnak' => "Members need access key to enter group", - 'kaug' => - 'Key authority (id@domain) if other than group', - 'gc' => "Group Coordinator", - 'gid' => "Group ID", - 'crgr' => "Create Group", - 'grts' => "Group Teams Settings", - 'grtq' => "Set a quota for the total disk space available for storage of group team portfolio files.", - - ); + 'cgrq' => 'Set a quota for the total disk space available for storage of course group portfolio files', + 'opco' => 'Open Course', + 'opcm' => 'Open Community', + ); + $lt{'kaut'} = &mt('Key authority ([_1]id:domain[_2]) if other than course','',''); + + if ($crstype eq 'Community') { + $lt{'cinf'} = &mt('Community Information'); + $lt{'ctit'} = &mt('Community Title'); + $lt{'chsr'} = &mt('Community Home Server'); + $lt{'cidn'} = &mt('Community ID/Number'); + $lt{'crco'} = &mt('Community Content'); + $lt{'cncr'} = &mt('Completely new community'); + $lt{'cecr'} = &mt('Clone an existing community'); + $lt{'sacr'} = &mt('Do NOT generate as standard community'); + $lt{'stco'} = &mt('standard communities only'); + $lt{'navi'} = &mt('Community Contents'); + $lt{'cid'} = &mt('Community ID'); + $lt{'scpf'} = &mt('Set community policy feedback to Coordinator'); + $lt{'scfc'} = &mt('Set content feedback to Coordinator'); + $lt{'dsrd'} = &mt('Disable member resource discussion'); + $lt{'dsuc'} = &mt('Disable member use of chat rooms'); + $lt{'dads'} = &mt('Default Access Dates for Members'); + $lt{'dacc'} = &mt('Default start and end dates for member access'); + $lt{'snak'} = &mt('Members need access key to enter course'); + $lt{'kaut'} = &mt('Key authority ([_1]id:domain[_2]) if other than community','',''); + $lt{'ow'} = &mt('Community Owner'); + $lt{'cc'} = &mt('(will be assigned Coordinator role)'); + $lt{'cgrs'} = &mt('Community Group Settings'); + $lt{'cgrq'} = &mt('Set a quota for the total disk space available for storage of community group portfolio files'); + } my $js = < var editbrowser = null; @@ -212,7 +267,7 @@ END my %titles = &Apache::lonlocal::texthash( courseone => 'Create a New Course', - groupone => 'Create a New Group', + groupone => 'Create a New Community', ); my $start_page = &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js); @@ -223,353 +278,274 @@ END 'Create_Course',undef, 'Create_Courses'); $r->print($start_page.$crumbs); + + $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() + ); if ($crstype eq 'Course') { - $r->print(< -

$lt{'cinf'}

-

- -

- -

- -

-

$lt{'iinf'}

-

-$lt{'stat'} -

- -
-($lt{'toin'}) -

- -
-($lt{'csli'}) -

- -
-($lt{'cscs'}) -

-

$lt{'crco'}

- - - -
$lt{'cncr'}$lt{'cecr'}
-

- -$lt{'smap'} -

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

-$lt{'fres'}
($lt{'stco'}): - -  - -  - -

-
- -
- -
-
-
- -

-$lt{'asov'}. -
-

$lt{'assp'}

-

- -

-

$lt{'mssg'}

-

- -
- -

-

$lt{'cmmn'}

-

- -
- -

-

$lt{'acco'}

-

- -
- -

-

$lt{'rshm'}

-

- -

-

-

$lt{'aens'}

-$lt{'aesc'} -

-

-$lt{'aadd'} - - -

-$lt{'audr'} - - -

-$lt{'dacu'} -$enroll_table -

-$lt{'dacc'} -$access_table -

-$lt{'psam'}.
-$lt{'pcda'}. -

-$krbform -
-$intform -
-$locform -

-$lt{'nech'}
-$lt{'nccl'}
- - -
-$lt{'ndcl'}
- - -

-$lt{'irsp'} - - -

-

-

$lt{'cgrs'}

-$lt{'cgrq'} -Mb -

-
-

$lt{'cc'}

-

- -

- -

+ $r->print(&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() + ); + if ($crstype eq 'Course') { + $r->print(&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() + ); + } + + $r->print(&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() + .'
' + ); + if ($crstype eq 'Course') { + $r->print('

- -

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

$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 -

-
-

$lt{'gc'}

-

- -

- -

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

- -

- -ENDDOCUMENT + +

' + ); } - $r->print($end_page); + $r->print(''. + $end_page); } # ====================================================== Phase two: make course @@ -578,7 +554,7 @@ sub create_course { my $r=shift; my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'}); my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'}); - my $crstype = 'Group'; + my $crstype = 'Community'; my ($enrollstart,$enrollend,$startaccess,$endaccess); if ($env{'form.phase'} eq 'coursetwo') { @@ -661,23 +637,26 @@ sub create_course { # Check the veracity of the course coordinator if (&Apache::lonnet::homeserver($ccuname,$ccdomain) eq 'no_host') { $r->print('
'); - $r->print(&mt('No such user').' '.$ccuname.' '.&mt('at').' '.$ccdomain.'.
'); - $r->print(&mt("Please click Back on your browser and select another user, or ")); - $r->print(' - - - - -
'.&Apache::loncommon::end_page()); + $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').': '. - $env{'form.course_home'}.&Apache::loncommon::end_page()); + $r->print(&mt('Invalid home server for course: [_1]' + ,$env{'form.course_home'}.&Apache::loncommon::end_page())); return; } my ($courseid,$crsudom,$crsunum); @@ -685,17 +664,21 @@ sub create_course { &Apache::loncommon::construct_course($args,\$logmsg,\$courseid, \$crsudom,\$crsunum, $env{'user.domain'}, - $env{'user.name'}); + $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 [_1] Coordinator to [_2] at [_3]: ', - $crstype,$ccuname,$ccdomain). - &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid, - 'cc','','','','','createcourse').'

'); + my $ccrole = 'cc'; + if ($crstype eq 'Community') { + $ccrole = 'co'; + } + $r->print(&mt('Assigning role of '.$crstype.' Coordinator to [_1]:', + ,''.$ccuname.':'.$ccdomain.'') + .&Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid, + $ccrole,'','','','','createcourse').'

'); } if ($env{'form.setkeys'}) { $r->print( @@ -706,18 +689,18 @@ sub create_course { $r->print('

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

'); } $r->print('

'. - &mt('Create Another [_1]',$crstype).'

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

'. &Apache::loncommon::end_page()); } sub print_intro_page { my $r = shift; my $start_page = - &Apache::loncommon::start_page('Create a New Course or Group Space'); + &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_GroupSpace',&mt('Help on Creating Courses and Groups')); + my $helplink=&Apache::loncommon::help_open_topic('Create_Course_Community',&mt('Help on Creating Courses and Communities')); my @choices = ({ internal_name => 'courseone', name => &mt('Create a single course'), @@ -725,16 +708,26 @@ sub print_intro_page { &mt('Create a new course by completing an online form.'), }, { internal_name => 'groupone', - name => &mt('Create a single collaborative group space '), + name => &mt('Create a single community'), short_description => - &mt('Create a new group space for non-course use by completing an online form .'), + &mt('Create a new collaborative community by completing an online form.'), }, { internal_name => 'batchone', - name => &mt('Create courses/groups by uploading an attributes file'), + 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 groups in XML format'), + &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) { @@ -759,18 +752,18 @@ ENDDOCUMENT sub upload_batchfile { my $r = shift; my $start_page = - &Apache::loncommon::start_page('Create a New Course or Group Space'); - my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Group Attributes File','Create_Course',undef,'Create_Courses'); + &Apache::loncommon::start_page('Create a New Course or Community'); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Community Attributes File','Create_Course',undef,'Create_Courses'); my $end_page = &Apache::loncommon::end_page(); $r->print($start_page.$crumbs); - $r->print('

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

'); + $r->print('

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

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

'. + '

'. '
'); + 'value="Create Courses/Communities" />'); $r->print($end_page); return; } @@ -778,7 +771,7 @@ sub upload_batchfile { sub process_batchfile { my $r = shift; my $start_page = - &Apache::loncommon::start_page('Create a New Course or Group Space'); + &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(); @@ -816,6 +809,391 @@ sub process_batchfile { } +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('Owner(s)').''; + if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'any')) { + $tablehdr .= ''.&mt('Institutional Code').''; + } + if ($curr{'type'} eq 'any') { + $tablehdr .= ''.&mt('Course Type').''; + } + if ($curr{'context'} eq 'any') { + $tablehdr .= ''.&mt('Creation Context').''; + } + $tablehdr .= &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'}.''); + } + if ($curr{'type'} eq 'any') { + $r->print(''.$showtype.''); + } + if ($curr{'context'} eq 'any') { + $r->print(''.$showcontext.''); + } + $r->print(''.&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 and communities 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 requestcourses); + my %contextnames = + &Apache::lonlocal::texthash ( + auto => 'Automated creation from batch file', + web => 'Batch creation from uploaded file', + dc_create => 'Course or community created by Dom. Coord.', + requestcourses => '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 sub handler { my $r = shift; @@ -871,12 +1249,52 @@ sub handler { 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/Community Creation Logs',$js); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Created Courses/Communities','Creation_Log',undef,'Creation_Log'); + $r->print($start_page.$crumbs."\n".'
'); + &print_creation_logs($r); + $r->print('
'.&Apache::loncommon::end_page()); } else { &print_intro_page($r); } } else { $env{'user.error.msg'}= - "/adm/createcourse:ccc:0:0:Cannot create courses or groups"; + "/adm/createcourse:ccc:0:0:Cannot create courses or communities"; return HTTP_NOT_ACCEPTABLE; } return OK;