[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmodifycourse.pm lonpickcourse.pm
raeburn
raeburn at source.lon-capa.org
Thu Mar 13 10:46:46 EDT 2014
raeburn Thu Mar 13 14:46:46 2014 EDT
Modified files:
/loncom/interface lonpickcourse.pm lonmodifycourse.pm loncommon.pm
Log:
- Moving &build_filters(), &timebased_select_form, &js_changer()
from lonpickcourse.pm to loncommon.pm to facilitate re-use.
-------------- next part --------------
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.110 loncom/interface/lonpickcourse.pm:1.111
--- loncom/interface/lonpickcourse.pm:1.110 Tue Mar 11 21:42:18 2014
+++ loncom/interface/lonpickcourse.pm Thu Mar 13 14:46:46 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.110 2014/03/11 21:42:18 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.111 2014/03/13 14:46:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -142,7 +142,7 @@
my $action = '/adm/pickcourse';
my ($numtitles,$showroles,$nohost, at codetitles);
if (!$onlyown) {
- my $filterlist = ['domainfilter'];
+ my $filterlist = ['domainfilter','sincefilter'];
# created filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
@@ -154,7 +154,15 @@
}
push(@{$filterlist},('descriptfilter','instcodefilter'));
if ($env{'form.form'} eq 'rules') {
- push(@{$filterlist},'personfilter');
+ push(@{$filterlist},('personfilter','persondomfilter'));
+ if ($env{'form.persondomfilter'} eq '') {
+ unless ($env{'form.gosearch'}) {
+ $filter->{'persondomfilter'} = $env{'request.role.domain'};
+ }
+ } else {
+ $filter->{'persondomfilter'} =
+ &LONCAPA::clean_domain($env{'form.persondomfilter'});
+ }
if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
if (&Apache::lonnet::homeserver($env{'form.personfilter'},
$env{'form.persondomfilter'}) eq 'no_host') {
@@ -164,7 +172,7 @@
}
}
} else {
- push(@{$filterlist},'ownerfilter');
+ push(@{$filterlist},('ownerfilter','ownerdomfilter'));
}
# course ID filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
@@ -174,10 +182,40 @@
if ($cloneruname ne '' && $clonerudom ne '') {
push(@{$filterlist},'cloneableonly');
}
-
- $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
- $filter,$action,\$numtitles,undef,$cloneruname,
- $clonerudom,$typeelement,\@codetitles));
+ if ((ref($filterlist) eq 'ARRAY') && (ref($filter) eq 'HASH')) {
+ foreach my $item (@{$filterlist}) {
+ $filter->{$item} = $env{'form.'.$item};
+ }
+ }
+ if ($env{'form.form'} eq 'portform') {
+ $filter->{'domainfilter'} ||= $env{'user.domain'};
+ } elsif ($env{'form.form'} eq 'studentform') {
+ $filter->{'domainfilter'} ||= $env{'request.role.domain'};
+ }
+ my $codedom;
+ if ($env{'form.fixeddom'}) {
+ $codedom = $env{'request.role.domain'};
+ } else {
+ $codedom = $filter->{'domainfilter'};
+ }
+ my ($clonetext,$clonewarning);
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ (my $coord_cloneable,$clonewarning) =
+ &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
+ if ($env{'form.form'} eq 'ccrs') {
+ $clonetext = '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
+ }
+ if ($coord_cloneable) {
+ $clonetext .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
+ }
+ }
+ $r->print(&Apache::loncommon::build_filters($filterlist,$type,$roleelement,$multelement,
+ $filter,$action,\$numtitles,undef,$cloneruname,
+ $clonerudom,$typeelement,\@codetitles,$codedom,
+ $env{'form.form'},$env{'form.fixeddom'},
+ $env{'form.prevphase'},$env{'form.cnameelement'},
+ $env{'form.cnumelement'},$env{'form.cdomelement'},
+ $env{'form.setroles'},$clonetext,$clonewarning));
}
# ---------------------------------------------------------------- Get the data
@@ -558,294 +596,6 @@
return ($jscript,$multelement);
}
-sub build_filters {
- my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_;
- my ($list,$formname,$fixeddom,$codedom,$jscript);
- $codedom = $env{'request.role.domain'};
- if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
- } else {
- $formname = $caller;
- }
- my $onchange = 'javascript:updateFilters(this)';
- my ($domainselectform,$sincefilterform,$createdfilterform,
- $ownerdomselectform,$persondomselectform,$instcodeform,
- $typeselectform,$instcodetitle);
- foreach my $item (@{$filterlist}) {
- $filter->{$item} = $env{'form.'.$item};
- if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
- if ($item eq 'domainfilter') {
- $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
- } elsif ($item eq 'coursefilter') {
- $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
- } elsif ($item eq 'ownerfilter') {
- $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
- $filter->{'ownerdomfilter'} =
- &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
- $ownerdomselectform =
- &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
- 'ownerdomfilter',1);
- } elsif ($item eq 'personfilter') {
- $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
- if ($env{'form.persondomfilter'} eq '') {
- unless ($env{'form.gosearch'}) {
- $filter->{'persondomfilter'} = $env{'request.role.domain'};
- }
- } else {
- $filter->{'persondomfilter'} =
- &LONCAPA::clean_domain($env{'form.persondomfilter'});
- }
- $persondomselectform =
- &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
- 'persondomfilter',1);
- } else {
- $filter->{$item} =~ s/\W//g;
- }
- if (!$filter->{$item}) {
- $filter->{$item} = '';
- }
- }
- if ($item eq 'domainfilter') {
- my $allow_blank = 1;
- if ($formname eq 'portform') {
- $filter->{$item} ||= $env{'user.domain'};
- $allow_blank=0;
- } elsif ($formname eq 'studentform') {
- $filter->{$item} ||= $env{'request.role.domain'};
- $allow_blank=0;
- }
- if ($env{'form.fixeddom'}) {
- $domainselectform = '<input type="hidden" name="domainfilter"'.
- 'value="'.$env{'request.role.domain'}.'" />'.
- &Apache::lonnet::domain($env{'request.role.domain'},
- 'description');
- $codedom = $env{'request.role.domain'};
- } else {
- $domainselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},
- 'domainfilter',
- $allow_blank,'',$onchange);
- $codedom = $filter->{'domainfilter'};
- }
- } else {
- $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
- }
- }
-
- # last course activity filter and selection
- $sincefilterform = &timebased_select_form('sincefilter',$filter);
-
- # course created filter and selection
- if (exists($filter->{'createdfilter'})) {
- $createdfilterform = &timebased_select_form('createdfilter',$filter);
- }
-
- my %lt = &Apache::lonlocal::texthash(
- 'cac' => "$type Activity",
- 'ccr' => "$type Created",
- 'cde' => "$type Title",
- 'cdo' => "$type Domain",
- 'ins' => 'Institutional Code',
- 'inc' => 'Institutional Categorization',
- 'cow' => "$type Owner/Co-owner",
- 'cop' => "$type Personnel Includes",
- 'cog' => 'Type',
- );
-
- if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
- my $typeval = 'Course';
- if ($type eq 'Community') {
- $typeval = 'Community';
- }
- $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
- } else {
- $typeselectform = '<select name="type" size="1"';
- if ($onchange) {
- $typeselectform .= ' onchange="'.$onchange.'"';
- }
- $typeselectform .= '>'."\n";
- foreach my $posstype ('Course','Community') {
- $typeselectform.='<option value="'.$posstype.'"'.
- ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
- }
- $typeselectform.="</select>";
- }
-
- my ($cloneableonlyform,$cloneabletitle);
- if (exists($filter->{'cloneableonly'})) {
- my $cloneableon = '';
- my $cloneableoff = ' checked="checked"';
- if ($filter->{'cloneableonly'}) {
- $cloneableon = $cloneableoff;
- $cloneableoff = '';
- }
- $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
- if ($env{'form.form'} eq 'ccrs') {
- $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
- } else {
- $cloneabletitle = &mt('Cloneable by you');
- }
- }
- my $officialjs;
- if ($type eq 'Course') {
- if (exists($filter->{'instcodefilter'})) {
- if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
- || ($formname eq 'modifycourse')) {
- $officialjs = 1;
- ($instcodeform,$jscript,$$numtitlesref) =
- &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
- $officialjs,$codetitlesref);
- if ($jscript) {
- $jscript = '<script type="text/javascript" language="Javascript">'.
- $jscript.'</script>'."\n";
- }
- }
- if ($instcodeform eq '') {
- $instcodeform =
- '<input type="text" name="instcodefilter" size="10" value="'.
- $list->{'instcodefilter'}.'" />';
- $instcodetitle = $lt{'ins'};
- } else {
- $instcodetitle = $lt{'inc'};
- }
- if ($env{'form.fixeddom'}) {
- $instcodetitle .= '<br />('.$codedom.')';
- }
- }
- }
-
- my $output = qq|
-<form method="post" name="filterpicker" action="$action">
-<input type="hidden" name="form" value="$formname" />
-|;
- if ($formname eq 'modifycourse') {
- $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
- '<input type="hidden" name="prevphase" value="'.
- $env{'form.prevphase'}.'" />'."\n";
- } else {
- my $name_input;
- if ($env{'form.cnameelement'} ne '') {
- $name_input = '<input type="hidden" name="cnameelement" value="'.
- $env{'form.cnameelement'}.'" />';
- }
- $output .= qq|
-<input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
-<input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
-$name_input
-$roleelement
-$multelement
-$typeelement
-|;
- if ($formname eq 'portform') {
- $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
- }
- }
- if ($env{'form.fixeddom'}) {
- $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
- }
- $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
- if ($sincefilterform) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
- .$sincefilterform
- .&Apache::lonhtmlcommon::row_closure();
- }
- if ($createdfilterform) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
- .$createdfilterform
- .&Apache::lonhtmlcommon::row_closure();
- }
- if ($domainselectform) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
- .$domainselectform
- .&Apache::lonhtmlcommon::row_closure();
- }
- if ($typeselectform) {
- if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
- $output .= $typeselectform;
- } else {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
- .$typeselectform
- .&Apache::lonhtmlcommon::row_closure();
- }
- }
- if ($instcodeform) {
- $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
- .$instcodeform
- .&Apache::lonhtmlcommon::row_closure();
- }
- if (exists($filter->{'ownerfilter'})) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
- '<table><tr><td>'.&mt('Username').'<br />'.
- '<input type="text" name="ownerfilter" size="20" value="'.
- $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
- $ownerdomselectform.'</td></tr></table>'.
- &Apache::lonhtmlcommon::row_closure();
- }
- if (exists($filter->{'personfilter'})) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
- '<table><tr><td>'.&mt('Username').'<br />'.
- '<input type="text" name="personfilter" size="20" value="'.
- $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
- $persondomselectform.'</td></tr></table>'.
- &Apache::lonhtmlcommon::row_closure();
- }
- if (exists($filter->{'coursefilter'})) {
- $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
- .'<input type="text" name="coursefilter" size="25" value="'
- .$list->{'coursefilter'}.'" />'
- .&Apache::lonhtmlcommon::row_closure();
- }
- if ($cloneableonlyform) {
- $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
- $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
- }
- if (exists($filter->{'descriptfilter'})) {
- $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
- .'<input type="text" name="descriptfilter" size="40" value="'
- .$list->{'descriptfilter'}.'" />'
- .&Apache::lonhtmlcommon::row_closure(1);
- }
- $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>';
- my ($coord_cloneable,$warning);
- if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
- ($coord_cloneable,$warning) =
- &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
- if ($env{'form.form'} eq 'ccrs') {
- $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
- }
- if ($coord_cloneable) {
- $output .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
- }
- }
- $output .= '<input type="hidden" name="updater" value="" />'."\n".
- '<input type="submit" name="gosearch" value="'.
- &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
- return $jscript.$warning.$output;
-}
-
-sub timebased_select_form {
- my ($item,$filter) = @_;
- if (ref($filter) eq 'HASH') {
- $filter->{$item} = $env{'form.'.$item};
- $filter->{$item} =~ s/[^\d-]//g;
- if (!$filter->{$item}) { $filter->{$item}=-1; }
- return &Apache::loncommon::select_form(
- $filter->{$item},
- $item,
- { '-1' => '',
- '86400' => &mt('today'),
- '604800' => &mt('last week'),
- '2592000' => &mt('last month'),
- '7776000' => &mt('last three months'),
- '15552000' => &mt('last six months'),
- '31104000' => &mt('last year'),
- 'select_form_order' =>
- ['-1','86400','604800','2592000','7776000',
- '15552000','31104000']});
- }
-}
-
sub get_coordinator_cloneable {
my ($cloneruname,$clonerudom,$type) = @_;
if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
@@ -1206,17 +956,6 @@
Side Effects: None
=item *
-X<build_filters()>
-B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem,$codetitlesref>:
-
-
-Input: 12 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm); username and domain of new course owner who wants to clone, $typeelem; reference to array of titles of components in institutional codes (official courses).
-
-Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
-
-Side Effects: None
-
-=item *
X<search_courses()>
B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,
$domcloner,$codetitles)>:
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.68 loncom/interface/lonmodifycourse.pm:1.69
--- loncom/interface/lonmodifycourse.pm:1.68 Tue Mar 11 00:57:23 2014
+++ loncom/interface/lonmodifycourse.pm Thu Mar 13 14:46:46 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# handler for DC-only modifiable course settings
#
-# $Id: lonmodifycourse.pm,v 1.68 2014/03/11 00:57:23 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.69 2014/03/13 14:46:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -153,10 +153,7 @@
$type = 'Course';
}
&print_header($r,$type);
- my $filterlist = ['descriptfilter',
- 'instcodefilter','ownerfilter',
- 'coursefilter'];
- my $filter = {};
+ my ($filterlist,$filter) = &get_filters();
my ($numtitles,$cctitle,$dctitle, at codetitles);
my $ccrole = 'cc';
if ($type eq 'Community') {
@@ -169,10 +166,10 @@
$r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
} else {
$r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
- }
- $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
- undef,undef,$filter,$action,\$numtitles,'modifycourse',
- undef,undef,undef,\@codetitles));
+ }
+ $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
+ \$numtitles,'modifycourse',undef,undef,undef,
+ \@codetitles,$filter->{'domainfilter'}));
if ($type eq 'Community') {
$r->print(&mt('Actions available after searching for a community:').'<ul>'.
'<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
@@ -184,6 +181,7 @@
'<li>'.&mt('View or modify course settings which only a [_1] may modify.',$dctitle).
'</li>'."\n".'</ul>');
}
+ return;
}
sub print_course_selection_page {
@@ -195,27 +193,41 @@
&print_header($r,$type);
# Criteria for course search
- my $filterlist = ['descriptfilter',
- 'instcodefilter','ownerfilter',
- 'ownerdomfilter','coursefilter'];
- my %filter;
+ my ($filterlist,$filter) = &get_filters();
my $action = '/adm/modifycourse';
my $dctitle = &Apache::lonnet::plaintext('dc');
my ($numtitles, at codetitles);
$r->print(&Apache::lonpickcourse::js_changer());
$r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
- $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
- undef,undef,\%filter,$action,\$numtitles,
- undef,undef,undef,undef,\@codetitles));
- $filter{'domainfilter'} = $dom;
- my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
- \%filter,$numtitles,undef,
- undef,undef,\@codetitles);
+ $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
+ \$numtitles,'modifycourse',undef,undef,undef,
+ \@codetitles,$filter->{'domainfilter'},
+ $env{'form.form'}));
+ if (ref($filter) eq 'HASH') {
+ $filter->{'domainfilter'} = $dom;
+ }
+ my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,$filter,$numtitles,
+ undef,undef,undef,\@codetitles);
&Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
%courses);
return;
}
+sub get_filters {
+ my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
+ 'ownerdomfilter','coursefilter','sincefilter');
+ # created filter
+ my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
+ if ($loncaparev ne 'unknown_cmd') {
+ push(@filterlist,'createdfilter');
+ }
+ my %filter;
+ foreach my $item (@filterlist) {
+ $filter{$item} = $env{'form.'.$item};
+ }
+ return (\@filterlist,\%filter);
+}
+
sub print_modification_menu {
my ($r,$cdesc,$domdesc,$dom,$type) = @_;
&print_header($r,$type);
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1180 loncom/interface/loncommon.pm:1.1181
--- loncom/interface/loncommon.pm:1.1180 Sun Mar 9 15:49:48 2014
+++ loncom/interface/loncommon.pm Thu Mar 13 14:46:46 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1180 2014/03/09 15:49:48 raeburn Exp $
+# $Id: loncommon.pm,v 1.1181 2014/03/13 14:46:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -13663,6 +13663,12 @@
return $text;
}
+=pod
+
+=back
+
+=cut
+
############################################################
############################################################
@@ -14682,6 +14688,396 @@
return ($symb,$enc);
}
+############################################################
+############################################################
+
+=pod
+
+=head1 Routines for building display used to search for courses
+
+
+=over 4
+
+=item * &build_filters()
+
+Create markup for a table used to set filters to use when selecting
+courses in a domain. Used by lonpickcourse.pm and lonmodifycourse.pm
+
+Inputs:
+
+filterlist - anonymous array of fields to include as potential filters
+
+crstype - course type
+
+roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
+ to pop-open a course selector (will contain "extra element").
+
+multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
+
+filter - anonymous hash of criteria and their values
+
+action - form action
+
+numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
+
+caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm
+
+cloneruname - username of owner of new course who wants to clone
+
+clonerudom - domain of owner of new course who wants to clone
+
+typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
+
+codetitlesref - reference to array of titles of components in institutional codes (official courses)
+
+codedom - domain
+
+formname - value of form element named "form".
+
+fixeddom - domain, if fixed.
+
+prevphase - value to assign to form element named "phase" when going back to the previous screen
+
+cnameelement - name of form element in form on opener page which will receive title of selected course
+
+cnumelement - name of form element in form on opener page which will receive courseID of selected course
+
+cdomelement - name of form element in form on opener page which will receive domain of selected course
+
+setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
+
+clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
+
+clonewarning - warning message about missing information for intended course owner when DC creates a course
+
+Returns: $output - HTML for display of search criteria, and hidden form elements.
+
+Side Effects: None
+
+=cut
+
+# ---------------------------------------------- search for courses based on last activity etc.
+
+sub build_filters {
+ my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
+ $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
+ $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
+ $cnameelement,$cnumelement,$cdomelement,$setroles,
+ $clonetext,$clonewarning) = @_;
+ my ($list,$fixeddom,$jscript);
+ my $onchange = 'javascript:updateFilters(this)';
+ my ($domainselectform,$sincefilterform,$createdfilterform,
+ $ownerdomselectform,$persondomselectform,$instcodeform,
+ $typeselectform,$instcodetitle);
+ if ($formname eq '') {
+ $formname = $caller;
+ }
+ foreach my $item (@{$filterlist}) {
+ unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
+ ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
+ if ($item eq 'domainfilter') {
+ $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
+ } elsif ($item eq 'coursefilter') {
+ $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
+ } elsif ($item eq 'ownerfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ } elsif ($item eq 'ownerdomfilter') {
+ $filter->{'ownerdomfilter'} =
+ &LONCAPA::clean_domain($filter->{$item});
+ $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
+ 'ownerdomfilter',1);
+ } elsif ($item eq 'personfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ } elsif ($item eq 'persondomfilter') {
+ $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
+ 'persondomfilter',1);
+ } else {
+ $filter->{$item} =~ s/\W//g;
+ }
+ if (!$filter->{$item}) {
+ $filter->{$item} = '';
+ }
+ }
+ if ($item eq 'domainfilter') {
+ my $allow_blank = 1;
+ if ($formname eq 'portform') {
+ $allow_blank=0;
+ } elsif ($formname eq 'studentform') {
+ $allow_blank=0;
+ }
+ if ($fixeddom) {
+ $domainselectform = '<input type="hidden" name="domainfilter"'.
+ ' value="'.$codedom.'" />'.
+ &Apache::lonnet::domain($codedom,'description');
+ } else {
+ $domainselectform = &select_dom_form($filter->{$item},
+ 'domainfilter',
+ $allow_blank,'',$onchange);
+ }
+ } else {
+ $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
+ }
+ }
+
+ # last course activity filter and selection
+ $sincefilterform = &timebased_select_form('sincefilter',$filter);
+
+ # course created filter and selection
+ if (exists($filter->{'createdfilter'})) {
+ $createdfilterform = &timebased_select_form('createdfilter',$filter);
+ }
+
+ my %lt = &Apache::lonlocal::texthash(
+ 'cac' => "$crstype Activity",
+ 'ccr' => "$crstype Created",
+ 'cde' => "$crstype Title",
+ 'cdo' => "$crstype Domain",
+ 'ins' => 'Institutional Code',
+ 'inc' => 'Institutional Categorization',
+ 'cow' => "$crstype Owner/Co-owner",
+ 'cop' => "$crstype Personnel Includes",
+ 'cog' => 'Type',
+ );
+
+ if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
+ my $typeval = 'Course';
+ if ($crstype eq 'Community') {
+ $typeval = 'Community';
+ }
+ $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
+ } else {
+ $typeselectform = '<select name="type" size="1"';
+ if ($onchange) {
+ $typeselectform .= ' onchange="'.$onchange.'"';
+ }
+ $typeselectform .= '>'."\n";
+ foreach my $posstype ('Course','Community') {
+ $typeselectform.='<option value="'.$posstype.'"'.
+ ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
+ }
+ $typeselectform.="</select>";
+ }
+
+ my ($cloneableonlyform,$cloneabletitle);
+ if (exists($filter->{'cloneableonly'})) {
+ my $cloneableon = '';
+ my $cloneableoff = ' checked="checked"';
+ if ($filter->{'cloneableonly'}) {
+ $cloneableon = $cloneableoff;
+ $cloneableoff = '';
+ }
+ $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
+ if ($formname eq 'ccrs') {
+ $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
+ } else {
+ $cloneabletitle = &mt('Cloneable by you');
+ }
+ }
+ my $officialjs;
+ if ($crstype eq 'Course') {
+ if (exists($filter->{'instcodefilter'})) {
+ if (($fixeddom) || ($formname eq 'requestcrs')
+ || ($formname eq 'modifycourse')) {
+ $officialjs = 1;
+ ($instcodeform,$jscript,$$numtitlesref) =
+ &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
+ $officialjs,$codetitlesref);
+ if ($jscript) {
+ $jscript = '<script type="text/javascript" language="Javascript">'.
+ $jscript.'</script>'."\n";
+ }
+ }
+ if ($instcodeform eq '') {
+ $instcodeform =
+ '<input type="text" name="instcodefilter" size="10" value="'.
+ $list->{'instcodefilter'}.'" />';
+ $instcodetitle = $lt{'ins'};
+ } else {
+ $instcodetitle = $lt{'inc'};
+ }
+ if ($fixeddom) {
+ $instcodetitle .= '<br />('.$codedom.')';
+ }
+ }
+ }
+ my $output = qq|
+<form method="post" name="filterpicker" action="$action">
+<input type="hidden" name="form" value="$formname" />
+|;
+ if ($formname eq 'modifycourse') {
+ $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
+ '<input type="hidden" name="prevphase" value="'.
+ $prevphase.'" />'."\n";
+ } else {
+ my $name_input;
+ if ($cnameelement ne '') {
+ $name_input = '<input type="hidden" name="cnameelement" value="'.
+ $cnameelement.'" />';
+ }
+ $output .= qq|
+<input type="hidden" name="cnumelement" value="$cnumelement.'" />
+<input type="hidden" name="cdomelement" value="$cdomelement.'" />
+$name_input
+$roleelement
+$multelement
+$typeelement
+|;
+ if ($formname eq 'portform') {
+ $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
+ }
+ }
+ if ($fixeddom) {
+ $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
+ }
+ $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
+ if ($sincefilterform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
+ .$sincefilterform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($createdfilterform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
+ .$createdfilterform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($domainselectform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
+ .$domainselectform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($typeselectform) {
+ if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
+ $output .= $typeselectform;
+ } else {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
+ .$typeselectform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ }
+ if ($instcodeform) {
+ $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
+ .$instcodeform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'ownerfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
+ '<table><tr><td>'.&mt('Username').'<br />'.
+ '<input type="text" name="ownerfilter" size="20" value="'.
+ $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
+ $ownerdomselectform.'</td></tr></table>'.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'personfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
+ '<table><tr><td>'.&mt('Username').'<br />'.
+ '<input type="text" name="personfilter" size="20" value="'.
+ $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
+ $persondomselectform.'</td></tr></table>'.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'coursefilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
+ .'<input type="text" name="coursefilter" size="25" value="'
+ .$list->{'coursefilter'}.'" />'
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($cloneableonlyform) {
+ $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
+ $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'descriptfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
+ .'<input type="text" name="descriptfilter" size="40" value="'
+ .$list->{'descriptfilter'}.'" />'
+ .&Apache::lonhtmlcommon::row_closure(1);
+ }
+ $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
+ '<input type="hidden" name="updater" value="" />'."\n".
+ '<input type="submit" name="gosearch" value="'.
+ &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
+ return $jscript.$clonewarning.$output;
+}
+
+=pod
+
+=item * &timebased_select_form()
+
+Create markup for an option response item used to select a time-based
+filter e.g., Course Activity, Course Created, when searching for courses
+or communities
+
+Inputs:
+
+item - name of form element (sincefilter or createdfilter)
+
+filter - anonymous hash of criteria and their values
+
+Returns: HTML for a select box contained a blank, then six time selections,
+ with value set in incoming form variables currently selected.
+
+Side Effects: None
+
+=cut
+
+sub timebased_select_form {
+ my ($item,$filter) = @_;
+ if (ref($filter) eq 'HASH') {
+ $filter->{$item} =~ s/[^\d-]//g;
+ if (!$filter->{$item}) { $filter->{$item}=-1; }
+ return &select_form(
+ $filter->{$item},
+ $item,
+ { '-1' => '',
+ '86400' => &mt('today'),
+ '604800' => &mt('last week'),
+ '2592000' => &mt('last month'),
+ '7776000' => &mt('last three months'),
+ '15552000' => &mt('last six months'),
+ '31104000' => &mt('last year'),
+ 'select_form_order' =>
+ ['-1','86400','604800','2592000','7776000',
+ '15552000','31104000']});
+ }
+}
+
+=pod
+
+=item * &js_changer()
+
+Create script tag containing Javascript used to submit course search form
+when course type or domain is changed.
+
+Inputs: None
+
+Returns: markup containing updateFilters() javascript function.
+
+Side Effects: None
+
+=cut
+
+sub js_changer {
+ return <<ENDJS;
+<script type="text/javascript">
+// <![CDATA[
+function updateFilters(caller) {
+ if (typeof(caller) != "undefined") {
+ document.filterpicker.updater.value = caller.name;
+ }
+ document.filterpicker.submit();
+}
+// ]]>
+</script>
+
+ENDJS
+}
+
+=pod
+
+=back
+
+=cut
+
+
sub build_release_hashes {
my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
@@ -15130,12 +15526,6 @@
return $plaintext;
}
-=pod
-
-=back
-
-=cut
-
1;
__END__;
More information about the LON-CAPA-cvs
mailing list