[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmodifycourse.pm lonpickcourse.pm
raeburn
raeburn at source.lon-capa.org
Sun Mar 16 22:45:26 EDT 2014
raeburn Mon Mar 17 02:45:26 2014 EDT
Modified files:
/loncom/interface loncommon.pm lonpickcourse.pm lonmodifycourse.pm
Log:
- &search_courses() and &js_changer() moved from lonpickcourse.pm to
loncommon.pm to facilitate reuse.
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1181 loncom/interface/loncommon.pm:1.1182
--- loncom/interface/loncommon.pm:1.1181 Thu Mar 13 14:46:46 2014
+++ loncom/interface/loncommon.pm Mon Mar 17 02:45:25 2014
@@ -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.1182 2014/03/17 02:45:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -69,6 +69,7 @@
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 @@
=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 @@
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 @@
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 @@
$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 @@
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 = '<script type="text/javascript" language="Javascript">'.
- $jscript.'</script>'."\n";
+ $jscript = '<script type="text/javascript">'."\n".
+ '// <![CDATA['."\n".
+ $jscript."\n".
+ '// ]]>'."\n".
+ '</script>'."\n";
}
}
if ($instcodeform eq '') {
@@ -14908,15 +14917,15 @@
$output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
'<input type="hidden" name="prevphase" value="'.
$prevphase.'" />'."\n";
- } else {
+ } elsif ($formname ne 'quotacheck') {
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.'" />
+<input type="hidden" name="cnumelement" value="$cnumelement" />
+<input type="hidden" name="cdomelement" value="$cdomelement" />
$name_input
$roleelement
$multelement
@@ -15002,7 +15011,7 @@
=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
@@ -15073,6 +15082,128 @@
=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
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.111 loncom/interface/lonpickcourse.pm:1.112
--- loncom/interface/lonpickcourse.pm:1.111 Thu Mar 13 14:46:46 2014
+++ loncom/interface/lonpickcourse.pm Mon Mar 17 02:45:25 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.111 2014/03/13 14:46:46 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.112 2014/03/17 02:45:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,7 +36,6 @@
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use Apache::courseclassifier;
use LONCAPA qw(:DEFAULT :match);
sub handler {
@@ -108,7 +107,7 @@
($env{'form.pickedcourse'})) {
$loaditem{'onload'} .= 'setDefaultCredits();setRoles();setSections();';
}
- my $js = &js_changer();
+ my $js = &Apache::loncommon::js_changer();
$r->print(&Apache::loncommon::start_page($title,$js,
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -141,7 +140,7 @@
my $filter = {};
my $action = '/adm/pickcourse';
my ($numtitles,$showroles,$nohost, at codetitles);
- if (!$onlyown) {
+ unless ($onlyown) {
my $filterlist = ['domainfilter','sincefilter'];
# created filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
@@ -228,8 +227,21 @@
$domcloner = 1;
}
}
- my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
- $cloneruname,$clonerudom,$domcloner,\@codetitles);
+ my %courses;
+ if (!$onlyown) {
+ $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
+ $r->rflush();
+ my $srchdom = $filter->{'domainfilter'};
+ %courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
+ $cloneruname,$clonerudom,$domcloner,
+ \@codetitles,$env{'form.cc_clone'});
+ } else {
+ $r->print('<br />');
+ my %coursehash = &Apache::loncommon::findallcourses();
+ foreach my $cid (sort(keys(%coursehash))) {
+ $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
+ }
+ }
if ($nohost) {
$r->print ('<span class="LC_warning">'.
&mt('User does not exist - username: [_1], domain: [_2].',
@@ -244,22 +256,6 @@
return OK;
}
-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
-}
-
sub processpick {
my $openerform = 'rolechoice';
if ($env{'form.form'} eq 'studentform') {
@@ -624,102 +620,6 @@
}
}
-sub search_courses {
- my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
- my (%courses,%showcourses,$cloner,$ccrole);
- if ($type eq 'Community') {
- $ccrole = 'co';
- } else {
- $ccrole = 'cc';
- }
- if (!$onlyown) {
- $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
- $r->rflush();
- 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($filter->{'domainfilter'},$numtitles,$codetitles);
- $regexpok = 1;
- } elsif ($env{'form.official'} eq 'off') {
- $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$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($filter->{'domainfilter'},
- $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 %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
- $filter->{'persondomfilter'},
- 'userroles',undef,
- [$ccrole,'in','ad','ep','ta','cr'],
- $filter->{'domainfilter'});
- 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;
- }
- } else {
- $r->print('<br />');
- my %coursehash = &Apache::loncommon::findallcourses();
- foreach my $cid (sort(keys(%coursehash))) {
- $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
- }
- }
- return %courses;
-}
-
sub course_chooser {
my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
my $output;
@@ -955,19 +855,6 @@
Side Effects: None
-=item *
-X<search_courses()>
-B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,
- $domcloner,$codetitles)>:
-
-
-Input: 9 - request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Seventh and eighth needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in
-domain being filtered by (used when DC is using course creation form). Ninth is reference to array of titles of components in institutional codes (official courses).
-
-Output: 1 - %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
-
=item *
X<course_chooser()>
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.69 loncom/interface/lonmodifycourse.pm:1.70
--- loncom/interface/lonmodifycourse.pm:1.69 Thu Mar 13 14:46:46 2014
+++ loncom/interface/lonmodifycourse.pm Mon Mar 17 02:45:25 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# handler for DC-only modifiable course settings
#
-# $Id: lonmodifycourse.pm,v 1.69 2014/03/13 14:46:46 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.70 2014/03/17 02:45:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -153,7 +153,7 @@
$type = 'Course';
}
&print_header($r,$type);
- my ($filterlist,$filter) = &get_filters();
+ my ($filterlist,$filter) = &get_filters($dom);
my ($numtitles,$cctitle,$dctitle, at codetitles);
my $ccrole = 'cc';
if ($type eq 'Community') {
@@ -161,7 +161,7 @@
}
$cctitle = &Apache::lonnet::plaintext($ccrole,$type);
$dctitle = &Apache::lonnet::plaintext('dc');
- $r->print(&Apache::lonpickcourse::js_changer());
+ $r->print(&Apache::loncommon::js_changer());
if ($type eq 'Community') {
$r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
} else {
@@ -169,7 +169,7 @@
}
$r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
\$numtitles,'modifycourse',undef,undef,undef,
- \@codetitles,$filter->{'domainfilter'}));
+ \@codetitles,$dom));
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".
@@ -197,27 +197,24 @@
my $action = '/adm/modifycourse';
my $dctitle = &Apache::lonnet::plaintext('dc');
my ($numtitles, at codetitles);
- $r->print(&Apache::lonpickcourse::js_changer());
+ $r->print(&Apache::loncommon::js_changer());
$r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
$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);
+ \@codetitles,$dom,$env{'form.form'}));
+ my %courses = &Apache::loncommon::search_courses($dom,$type,$filter,$numtitles,
+ undef,undef,undef,\@codetitles);
&Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
%courses);
return;
}
sub get_filters {
+ my ($dom) = @_;
my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
'ownerdomfilter','coursefilter','sincefilter');
# created filter
- my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
+ my $loncaparev = &Apache::lonnet::get_server_loncaparev($dom);
if ($loncaparev ne 'unknown_cmd') {
push(@filterlist,'createdfilter');
}
More information about the LON-CAPA-cvs
mailing list