version 1.85, 2007/08/25 13:45:56
|
version 1.90, 2008/03/11 01:45:47
|
Line 442 sub make_new_child {
|
Line 442 sub make_new_child {
|
$result .= &escape(join(':',map{$_.'='.$replies{$_}} keys %replies)); |
$result .= &escape(join(':',map{$_.'='.$replies{$_}} keys %replies)); |
} |
} |
} elsif ($query eq 'usersearch') { |
} elsif ($query eq 'usersearch') { |
my $srchdomain = &unescape($arg1); |
my ($srchby,$srchtype,$srchterm); |
my @items = split(/%%/,$arg2); |
if ((&unescape($arg1) eq $searchdomain) && |
my ($srchby,$srchtype) = map {&unescape($_)} @items; |
($arg2 =~ /\%\%/)) { |
my $srchterm = &unescape($arg3); |
($srchby,$srchtype) = |
my $quoted_dom = $dbh->quote( $srchdomain ); |
map {&unescape($_);} (split(/\%\%/,$arg2)); |
my ($query,$quoted_srchterm,@fields); |
$srchterm = &unescape($arg3); |
my ($table_columns,$table_indices) = |
|
&LONCAPA::lonmetadata::describe_metadata_storage('allusers'); |
|
foreach my $coldata (@{$table_columns}) { |
|
push(@fields,$coldata->{'name'}); |
|
} |
|
my $fieldlist = join(',',@fields); |
|
$query = "SELECT $fieldlist FROM allusers WHERE (domain = $quoted_dom AND "; |
|
if ($srchby eq 'lastfirst') { |
|
my ($fraglast,$fragfirst) = split(/,/,$srchterm); |
|
$fragfirst =~ s/^\s+//; |
|
$fraglast =~ s/\s+$//; |
|
if ($srchtype eq 'exact') { |
|
$query .= 'lastname = '.$dbh->quote($fraglast). |
|
' AND firstname = '.$dbh->quote($fragfirst); |
|
} else { |
|
$query .= 'lastname LIKE '.$dbh->quote('%'.$fraglast.'%').' AND firstname LIKE '.$dbh->quote('%'.$fragfirst.'%'); |
|
} |
|
} else { |
} else { |
my %srchfield = ( |
($srchby,$srchtype,$srchterm) = |
uname => 'username', |
map {&unescape($_);} ($arg1,$arg2,$arg3); |
lastname => 'lastname', |
|
); |
|
if ($srchtype eq 'exact') { |
|
$query .= $srchfield{$srchby}.' = '.$dbh->quote($srchterm); |
|
} else { |
|
$query .= $srchfield{$srchby}.' LIKE '.$dbh->quote('%'.$srchterm.'%'); |
|
} |
|
} |
} |
$query .= ") ORDER BY username "; |
$result = &do_user_search($searchdomain,$srchby, |
my $sth = $dbh->prepare($query); |
$srchtype,$srchterm); |
if ($sth->execute()) { |
|
my @results; |
|
while (my @row = $sth->fetchrow_array) { |
|
my @items; |
|
for (my $i=0; $i<@row; $i++) { |
|
push(@items,&escape($fields[$i]).'='.&escape($row[$i])); |
|
} |
|
push(@results,join(":", @items)); |
|
} |
|
$sth->finish; |
|
$result = &escape(join("&",@results)); |
|
} else { |
|
&logthis('<font color="blue">'. |
|
'WARNING: Could not retrieve from database:'. |
|
$sth->errstr().'</font>'); |
|
} |
|
} elsif ($query eq 'instdirsearch') { |
} elsif ($query eq 'instdirsearch') { |
$result = &do_inst_dir_search($searchdomain,$arg1,$arg2,$arg3); |
$result = &do_inst_dir_search($searchdomain,$arg1,$arg2,$arg3); |
|
} elsif ($query eq 'getinstuser') { |
|
$result = &get_inst_user($searchdomain,$arg1,$arg2); |
} elsif ($query eq 'prepare activity log') { |
} elsif ($query eq 'prepare activity log') { |
my ($cid,$domain) = map {&unescape($_);} ($arg1,$arg2); |
my ($cid,$domain) = map {&unescape($_);} ($arg1,$arg2); |
&logthis('preparing activity log tables for '.$cid); |
&logthis('preparing activity log tables for '.$cid); |
Line 547 sub make_new_child {
|
Line 509 sub make_new_child {
|
} |
} |
} |
} |
|
|
|
sub do_user_search { |
|
my ($domain,$srchby,$srchtype,$srchterm) = @_; |
|
my $result; |
|
my $quoted_dom = $dbh->quote( $domain ); |
|
my ($query,$quoted_srchterm,@fields); |
|
my ($table_columns,$table_indices) = |
|
&LONCAPA::lonmetadata::describe_metadata_storage('allusers'); |
|
foreach my $coldata (@{$table_columns}) { |
|
push(@fields,$coldata->{'name'}); |
|
} |
|
my $fieldlist = join(',',@fields); |
|
$query = "SELECT $fieldlist FROM allusers WHERE (domain = $quoted_dom AND "; |
|
if ($srchby eq 'lastfirst') { |
|
my ($fraglast,$fragfirst) = split(/,/,$srchterm); |
|
$fragfirst =~ s/^\s+//; |
|
$fraglast =~ s/\s+$//; |
|
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.'%'); |
|
} |
|
} else { |
|
my %srchfield = ( |
|
uname => 'username', |
|
lastname => 'lastname', |
|
); |
|
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.'%'); |
|
} |
|
} |
|
$query .= ") ORDER BY username "; |
|
my $sth = $dbh->prepare($query); |
|
if ($sth->execute()) { |
|
my @results; |
|
while (my @row = $sth->fetchrow_array) { |
|
my @items; |
|
for (my $i=0; $i<@row; $i++) { |
|
push(@items,&escape($fields[$i]).'='.&escape($row[$i])); |
|
} |
|
my $userstr = join(':', @items); |
|
push(@results,&escape($userstr)); |
|
} |
|
$sth->finish; |
|
$result = join('&',@results); |
|
} else { |
|
&logthis('<font color="blue">'. |
|
'WARNING: Could not retrieve from database:'. |
|
$sth->errstr().'</font>'); |
|
} |
|
return $result; |
|
} |
|
|
sub do_inst_dir_search { |
sub do_inst_dir_search { |
my ($domain,$srchby,$srchterm,$srchtype) = @_; |
my ($domain,$srchby,$srchterm,$srchtype) = @_; |
$srchby = &unescape($srchby); |
$srchby = &unescape($srchby); |
Line 567 sub do_inst_dir_search {
|
Line 590 sub do_inst_dir_search {
|
} |
} |
} |
} |
$response=~s/\&$//; |
$response=~s/\&$//; |
|
} else { |
|
$response = 'unavailable'; |
|
} |
|
return $response; |
|
} |
|
|
|
sub get_inst_user { |
|
my ($domain,$uname,$id) = @_; |
|
$uname = &unescape($uname); |
|
$id = &unescape($id); |
|
my (%instusers,%instids,$result,$response); |
|
eval { |
|
local($SIG{__DIE__})='DEFAULT'; |
|
$result=&localenroll::get_userinfo($domain,$uname,$id,\%instusers, |
|
\%instids); |
|
}; |
|
if ($result eq 'ok') { |
|
if (keys(%instusers) > 0) { |
|
foreach my $key (keys(%instusers)) { |
|
my $usrstr = &Apache::lonnet::freeze_escape($instusers{$key}); |
|
$response .= &escape(&escape($key).'='.$usrstr).'&'; |
|
} |
|
} |
|
$response=~s/\&$//; |
|
} else { |
|
$response = 'unavailable'; |
} |
} |
return $response; |
return $response; |
} |
} |