--- loncom/lonsql 2011/11/07 18:13:38 1.91 +++ loncom/lonsql 2015/08/05 18:47:12 1.94 @@ -3,7 +3,7 @@ # The LearningOnline Network # lonsql - LON TCP-MySQL-Server Daemon for handling database requests. # -# $Id: lonsql,v 1.91 2011/11/07 18:13:38 raeburn Exp $ +# $Id: lonsql,v 1.94 2015/08/05 18:47:12 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -95,8 +95,6 @@ the database. =head1 Internals -=over 4 - =cut use strict; @@ -121,6 +119,8 @@ use GDBM_File; =pod +=over 4 + =item Global Variables =over 4 @@ -458,6 +458,8 @@ sub make_new_child { $result = &do_inst_dir_search($searchdomain,$arg1,$arg2,$arg3); } elsif ($query eq 'getinstuser') { $result = &get_inst_user($searchdomain,$arg1,$arg2); + } elsif ($query eq 'getmultinstusers') { + $result = &get_multiple_instusers($searchdomain,$arg3); } elsif ($query eq 'prepare activity log') { my ($cid,$domain) = map {&unescape($_);} ($arg1,$arg2); &logthis('preparing activity log tables for '.$cid); @@ -489,7 +491,7 @@ sub make_new_child { $result = &allusers_table_update($query,$uname,$udom,\%userdata); } else { # Do an sql query - $result = &do_sql_query($query,$arg1,$arg2,$searchdomain); + $result = &do_sql_query($query,$arg1,$arg2,$arg3,$searchdomain); } # result does not need to be escaped because it has already been # escaped. @@ -620,6 +622,33 @@ sub get_inst_user { return $response; } +sub get_multiple_instusers { + my ($domain,$data) = @_; + my ($type,$users) = split(/=/,$data,2); + my $requested = &Apache::lonnet::thaw_unescape($users); + my $response; + if (ref($requested) eq 'HASH') { + my (%instusers,%instids,$result); + eval { + local($SIG{__DIE__})='DEFAULT'; + $result=&localenroll::get_multusersinfo($domain,$type,$requested,\%instusers, + \%instids); + }; + if ($@) { + $response = 'error'; + } elsif ($result eq 'ok') { + if (keys(%instusers)) { + $response = $result.':'.&Apache::lonnet::freeze_escape(\%instusers); + } + } else { + $response = 'unavailable'; + } + } else { + $response = 'invalid'; + } + return $response; +} + ######################################################## ######################################################## @@ -651,12 +680,30 @@ sub process_file { } sub do_sql_query { - my ($query,$custom,$customshow,$searchdomain) = @_; + my ($query,$custom,$customshow,$domainstr,$searchdomain) = @_; # # limit to searchdomain if given and table is metadata # - if (($searchdomain) && ($query=~/FROM metadata/)) { + if ($domainstr && ($query=~/FROM metadata/)) { + my $havingstr; + $domainstr = &unescape($domainstr); + if ($domainstr =~ /,/) { + foreach my $dom (split(/,/,$domainstr)) { + if ($dom =~ /^$LONCAPA::domain_re$/) { + $havingstr .= 'domain="'.$dom.'" OR '; + } + } + $havingstr =~ s/ OR $//; + } else { + if ($domainstr =~ /^$LONCAPA::domain_re$/) { + $havingstr = 'domain="'.$domainstr.'"'; + } + } + if ($havingstr) { + $query.=' HAVING ('.$havingstr.')'; + } + } elsif (($searchdomain) && ($query=~/FROM metadata/)) { $query.=' HAVING (domain="'.$searchdomain.'")'; } # &logthis('doing query ('.$searchdomain.')'.$query);