Diff for /loncom/lonsql between versions 1.88 and 1.94

version 1.88, 2007/09/12 03:40:29 version 1.94, 2015/08/05 18:47:12
Line 95  the database. Line 95  the database.
   
 =head1 Internals  =head1 Internals
   
 =over 4  
   
 =cut  =cut
   
 use strict;  use strict;
Line 121  use GDBM_File; Line 119  use GDBM_File;
   
 =pod  =pod
   
   =over 4
   
 =item Global Variables  =item Global Variables
   
 =over 4  =over 4
Line 233  unless ($dbh = DBI->connect("DBI:mysql:l Line 233  unless ($dbh = DBI->connect("DBI:mysql:l
     system("echo 'Cannot connect to MySQL database!' |".      system("echo 'Cannot connect to MySQL database!' |".
            " mailto $emailto -s '$subj' > /dev/null");             " mailto $emailto -s '$subj' > /dev/null");
   
     open(SMP,'>/home/httpd/html/lon-status/mysql.txt');      open(SMP,">$perlvar{'lonDocRoot'}/lon-status/mysql.txt");
     print SMP 'time='.time.'&mysql=defunct'."\n";      print SMP 'time='.time.'&mysql=defunct'."\n";
     close(SMP);      close(SMP);
   
     exit 1;      exit 1;
 } else {  } else {
     unlink('/home/httpd/html/lon-status/mysql.txt');      unlink("$perlvar{'lonDocRoot'}/lon-status/mysql.txt");
     $dbh->disconnect;      $dbh->disconnect;
 }  }
   
Line 447  sub make_new_child { Line 447  sub make_new_child {
                     ($arg2 =~ /\%\%/)) {                      ($arg2 =~ /\%\%/)) {
                     ($srchby,$srchtype) =                      ($srchby,$srchtype) =
                         map {&unescape($_);} (split(/\%\%/,$arg2));                          map {&unescape($_);} (split(/\%\%/,$arg2));
                     my $srchterm = &unescape($arg3);                      $srchterm = &unescape($arg3);
                 } else {                  } else {
                     ($srchby,$srchtype,$srchterm) =                      ($srchby,$srchtype,$srchterm) =
                         map {&unescape($_);} ($arg1,$arg2,$arg3);                          map {&unescape($_);} ($arg1,$arg2,$arg3);
Line 456  sub make_new_child { Line 456  sub make_new_child {
                                           $srchtype,$srchterm);                                            $srchtype,$srchterm);
     } 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 'getmultinstusers') {
                   $result = &get_multiple_instusers($searchdomain,$arg3);
             } 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 487  sub make_new_child { Line 491  sub make_new_child {
                 $result = &allusers_table_update($query,$uname,$udom,\%userdata);                  $result = &allusers_table_update($query,$uname,$udom,\%userdata);
             } else {              } else {
                 # Do an sql query                  # 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              # result does not need to be escaped because it has already been
             # escaped.              # escaped.
Line 594  sub do_inst_dir_search { Line 598  sub do_inst_dir_search {
     return $response;      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;
   }
   
   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;
   }
   
 ########################################################  ########################################################
 ########################################################  ########################################################
   
Line 625  sub process_file { Line 680  sub process_file {
 }  }
   
 sub do_sql_query {  sub do_sql_query {
     my ($query,$custom,$customshow,$searchdomain) = @_;      my ($query,$custom,$customshow,$domainstr,$searchdomain) = @_;
   
 #  #
 # limit to searchdomain if given and table is metadata  # 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.'")';   $query.=' HAVING (domain="'.$searchdomain.'")';
     }      }
 #    &logthis('doing query ('.$searchdomain.')'.$query);  #    &logthis('doing query ('.$searchdomain.')'.$query);

Removed from v.1.88  
changed lines
  Added in v.1.94


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>