--- loncom/interface/loncreatecourse.pm 2009/08/27 00:06:18 1.126 +++ 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.126 2009/08/27 00:06:18 raeburn Exp $ +# $Id: loncreatecourse.pm,v 1.127 2009/09/28 19:21:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -55,6 +55,20 @@ described at http://www.lon-capa.org. =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 @@ -766,7 +780,7 @@ 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) { # @@ -819,7 +833,12 @@ sub print_intro_page { { 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.'), + &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; @@ -850,7 +869,7 @@ sub upload_batchfile { 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('
'. ''. @@ -921,6 +940,361 @@ function opencoursereqdisplay(cdom,cnum) 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 sub handler { @@ -990,7 +1364,6 @@ sub handler { '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',), @@ -1004,12 +1377,26 @@ sub handler { &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 { &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;