[LON-CAPA-cvs] cvs: loncom / lonsql /interface loncommon.pm loncreateuser.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Sat, 25 Aug 2007 19:52:29 -0000
raeburn Sat Aug 25 15:52:29 2007 EDT
Modified files:
/loncom lonsql
/loncom/interface loncommon.pm loncreateuser.pm
Log:
Add "begins with" type searches - matched where target (uname, lastname, etc.) begins with search term.
Index: loncom/lonsql
diff -u loncom/lonsql:1.85 loncom/lonsql:1.86
--- loncom/lonsql:1.85 Sat Aug 25 09:45:56 2007
+++ loncom/lonsql Sat Aug 25 15:52:11 2007
@@ -3,7 +3,7 @@
# The LearningOnline Network
# lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
#
-# $Id: lonsql,v 1.85 2007/08/25 13:45:56 raeburn Exp $
+# $Id: lonsql,v 1.86 2007/08/25 19:52:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -462,6 +462,8 @@
if ($srchtype eq 'exact') {
$query .= 'lastname = '.$dbh->quote($fraglast).
' AND firstname = '.$dbh->quote($fragfirst);
+ } elsif ($srchtype eq 'begins') {
+ $query .= 'lastname LIKE '.$dbh->quote($fraglast.'%').' AND firstname LIKE '.$dbh->quote($fragfirst.'%');
} else {
$query .= 'lastname LIKE '.$dbh->quote('%'.$fraglast.'%').' AND firstname LIKE '.$dbh->quote('%'.$fragfirst.'%');
}
@@ -472,6 +474,8 @@
);
if ($srchtype eq 'exact') {
$query .= $srchfield{$srchby}.' = '.$dbh->quote($srchterm);
+ } elsif ($srchtype eq 'begins') {
+ $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote($srchterm.'%');
} else {
$query .= $srchfield{$srchby}.' LIKE '.$dbh->quote('%'.$srchterm.'%');
}
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.568 loncom/interface/loncommon.pm:1.569
--- loncom/interface/loncommon.pm:1.568 Fri Aug 24 14:41:06 2007
+++ loncom/interface/loncommon.pm Sat Aug 25 15:52:29 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.568 2007/08/24 18:41:06 albertel Exp $
+# $Id: loncommon.pm,v 1.569 2007/08/25 19:52:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -5642,6 +5642,7 @@
'instd' => 'in institutional directory',
'exact' => 'is',
'contains' => 'contains',
+ 'begins' => 'begins with',
);
my $domform = &select_dom_form($currdom,'srchdomain',1,1);
my $srchinsel = ' <select name="srchin">';
@@ -5677,7 +5678,7 @@
$srchbysel .= "\n </select>\n";
my $srchtypesel = ' <select name="srchtype">';
- foreach my $option ('exact','contains') {
+ foreach my $option ('exact','begins','contains') {
if ($curr_selected{'srchtype'} eq $option) {
$srchtypesel .= '
<option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
@@ -5746,6 +5747,13 @@
msg += "You must include some text to search for.\\n";
}
+ if (srchtype== 'begins') {
+ if (srchterm.length < 2) {
+ checkok = 0;
+ msg += "The text you are searching for must contain at least two characters when using a 'begins' type search.\\n";
+ }
+ }
+
if (srchtype== 'contains') {
if (srchterm.length < 3) {
checkok = 0;
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.176 loncom/interface/loncreateuser.pm:1.177
--- loncom/interface/loncreateuser.pm:1.176 Sat Aug 25 13:46:24 2007
+++ loncom/interface/loncreateuser.pm Sat Aug 25 15:52:29 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.176 2007/08/25 17:46:24 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.177 2007/08/25 19:52:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2203,7 +2203,7 @@
if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
$response = &mt('Invalid search.');
}
- if ($srch->{'srchtype'} !~ /^(exact|contains)$/) {
+ if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
$response = &mt('Invalid search.');
}
if ($srch->{'srchterm'} eq '') {
@@ -2274,7 +2274,17 @@
foreach my $user (keys(%$courseusers)) {
my ($cuname,$cudomain) = split(/:/,$user);
if ($cudomain eq $srch->{'srchdomain'}) {
- if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+ my $matched = 0;
+ if ($srch->{'srchtype'} eq 'begins') {
+ if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ } else {
+ if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ }
+ if ($matched) {
$srch_results{$user} =
{&Apache::lonnet::get('environment',
['firstname',
@@ -2309,6 +2319,8 @@
if ($srch->{'srchby'} eq 'lastname') {
if ((($srch->{'srchtype'} eq 'exact') &&
($names{'lastname'} eq $srch->{'srchterm'})) ||
+ (($srch->{'srchtype'} eq 'begins') &&
+ ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
(($srch->{'srchtype'} eq 'contains') &&
($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
$srch_results{$user} = {firstname => $names{'firstname'},
@@ -2318,6 +2330,8 @@
}
} elsif ($srch->{'srchby'} eq 'lastfirst') {
my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
+ $srchlast =~ s/\s+$//;
+ $srchfirst =~ s/^\s+//;
if ($srch->{'srchtype'} eq 'exact') {
if (($names{'lastname'} eq $srchlast) &&
($names{'firstname'} eq $srchfirst)) {
@@ -2327,7 +2341,15 @@
};
}
- } elsif ($srch->{'srchtype'} eq 'contains') {
+ } elsif ($srch->{'srchtype'} eq 'begins') {
+ if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
+ ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
+ $srch_results{$user} = {firstname => $names{'firstname'},
+ lastname => $names{'lastname'},
+ permanentemail => $emails{'permanentemail'},
+ };
+ }
+ } else {
if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
$srch_results{$user} = {firstname => $names{'firstname'},