--- loncom/interface/loncommon.pm 2014/03/13 14:46:46 1.1181
+++ loncom/interface/loncommon.pm 2014/03/17 13:38:57 1.1183
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1181 2014/03/13 14:46:46 raeburn Exp $
+# $Id: loncommon.pm,v 1.1183 2014/03/17 13:38:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -69,6 +69,7 @@ use Apache::lontexconvert();
use Apache::lonclonecourse();
use Apache::lonuserutils();
use Apache::lonuserstate();
+use Apache::courseclassifier();
use LONCAPA qw(:DEFAULT :match);
use DateTime::TimeZone;
use DateTime::Locale::Catalog;
@@ -14701,7 +14702,9 @@ sub clean_symb {
=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
+courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
+and quotacheck.pl
+
Inputs:
@@ -14720,7 +14723,7 @@ 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
+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
@@ -14750,8 +14753,10 @@ clonetext - hidden form elements contain
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
@@ -14764,7 +14769,7 @@ sub build_filters {
$codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
$cnameelement,$cnumelement,$cdomelement,$setroles,
$clonetext,$clonewarning) = @_;
- my ($list,$fixeddom,$jscript);
+ my ($list,$jscript);
my $onchange = 'javascript:updateFilters(this)';
my ($domainselectform,$sincefilterform,$createdfilterform,
$ownerdomselectform,$persondomselectform,$instcodeform,
@@ -14876,15 +14881,19 @@ sub build_filters {
my $officialjs;
if ($crstype eq 'Course') {
if (exists($filter->{'instcodefilter'})) {
- if (($fixeddom) || ($formname eq 'requestcrs')
- || ($formname eq 'modifycourse')) {
+# if (($fixeddom) || ($formname eq 'requestcrs') ||
+# ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
+ if ($codedom) {
$officialjs = 1;
($instcodeform,$jscript,$$numtitlesref) =
&Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
$officialjs,$codetitlesref);
if ($jscript) {
- $jscript = ''."\n";
+ $jscript = ''."\n";
}
}
if ($instcodeform eq '') {
@@ -14908,15 +14917,15 @@ sub build_filters {
$output .= ''."\n".
''."\n";
- } else {
+ } elsif ($formname ne 'quotacheck') {
my $name_input;
if ($cnameelement ne '') {
$name_input = '';
}
$output .= qq|
-
-
+
+
$name_input
$roleelement
$multelement
@@ -15002,7 +15011,7 @@ $typeelement
=item * &timebased_select_form()
-Create markup for an option response item used to select a time-based
+Create markup for a dropdown list used to select a time-based
filter e.g., Course Activity, Course Created, when searching for courses
or communities
@@ -15045,11 +15054,12 @@ sub timebased_select_form {
=item * &js_changer()
Create script tag containing Javascript used to submit course search form
-when course type or domain is changed.
+when course type or domain is changed, and also to hide 'Searching ...' on
+page load completion for page showing search result.
Inputs: None
-Returns: markup containing updateFilters() javascript function.
+Returns: markup containing updateFilters() and hideSearching() javascript functions.
Side Effects: None
@@ -15065,6 +15075,14 @@ function updateFilters(caller) {
}
document.filterpicker.submit();
}
+
+function hideSearching() {
+ if (document.getElementById('searching')) {
+ document.getElementById('searching').style.display = 'none';
+ }
+ return;
+}
+
// ]]>
@@ -15073,6 +15091,128 @@ ENDJS
=pod
+=item * &search_courses()
+
+Process selected filters form course search form and pass to lonnet::courseiddump
+to retrieve a hash for which keys are courseIDs which match the selected filters.
+
+Inputs:
+
+dom - domain being searched
+
+type - course type ('Course' or 'Community' or '.' if any).
+
+filter - anonymous hash of criteria and their values
+
+numtitles - for institutional codes - number of categories
+
+cloneruname - optional username of new course owner
+
+clonerudom - optional domain of new course owner
+
+domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
+ (used when DC is using course creation form)
+
+codetitles - reference to array of titles of components in institutional codes (official courses).
+
+
+Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
+
+
+Side Effects: None
+
+=cut
+
+
+sub search_courses {
+ my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
+ my (%courses,%showcourses,$cloner);
+ if (($filter->{'ownerfilter'} ne '') ||
+ ($filter->{'ownerdomfilter'} ne '')) {
+ $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
+ $filter->{'ownerdomfilter'};
+ }
+ foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
+ if (!$filter->{$item}) {
+ $filter->{$item}='.';
+ }
+ }
+ my $now = time;
+ my $timefilter =
+ ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
+ my ($createdbefore,$createdafter);
+ if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
+ $createdbefore = $now;
+ $createdafter = $now-$filter->{'createdfilter'};
+ }
+ my ($instcodefilter,$regexpok);
+ if ($numtitles) {
+ if ($env{'form.official'} eq 'on') {
+ $instcodefilter =
+ &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
+ $regexpok = 1;
+ } elsif ($env{'form.official'} eq 'off') {
+ $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
+ unless ($instcodefilter eq '') {
+ $regexpok = -1;
+ }
+ }
+ } else {
+ $instcodefilter = $filter->{'instcodefilter'};
+ }
+ if ($instcodefilter eq '') { $instcodefilter = '.'; }
+ if ($type eq '') { $type = '.'; }
+
+ if (($clonerudom ne '') && ($cloneruname ne '')) {
+ $cloner = $cloneruname.':'.$clonerudom;
+ }
+ %courses = &Apache::lonnet::courseiddump($dom,
+ $filter->{'descriptfilter'},
+ $timefilter,
+ $instcodefilter,
+ $filter->{'combownerfilter'},
+ $filter->{'coursefilter'},
+ undef,undef,$type,$regexpok,undef,undef,
+ undef,undef,$cloner,$env{'form.cc_clone'},
+ $filter->{'cloneableonly'},
+ $createdbefore,$createdafter,undef,
+ $domcloner);
+ if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
+ my $ccrole;
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } else {
+ $ccrole = 'cc';
+ }
+ my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
+ $filter->{'persondomfilter'},
+ 'userroles',undef,
+ [$ccrole,'in','ad','ep','ta','cr'],
+ $dom);
+ foreach my $role (keys(%rolehash)) {
+ my ($cnum,$cdom,$courserole) = split(':',$role);
+ my $cid = $cdom.'_'.$cnum;
+ if (exists($courses{$cid})) {
+ if (ref($courses{$cid}) eq 'HASH') {
+ if (ref($courses{$cid}{roles}) eq 'ARRAY') {
+ if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
+ push (@{$courses{$cid}{roles}},$courserole);
+ }
+ } else {
+ $courses{$cid}{roles} = [$courserole];
+ }
+ $showcourses{$cid} = $courses{$cid};
+ }
+ }
+ }
+ %courses = %showcourses;
+ }
+ return %courses;
+}
+
+
+=pod
+
=back
=cut