phpBMS

Show
Ignore:
Timestamp:
08/27/07 14:05:27 (5 years ago)
Author:
brieb
Message:

Merging object oriented branch back into trunk.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/loadsearch.php

    r205 r285  
    3838*/ 
    3939        require("include/session.php"); 
    40         require("include/common_functions.php"); 
    4140         
    42         function deleteSearch($id){ 
    43                 global $dblink; 
     41        class savedSearch{ 
     42 
     43                var $db; 
     44                 
     45                function savedSearch($db){ 
     46                        $this->db=$db; 
     47                } 
    4448         
    45                 $querystatement="DELETE FROM usersearches  
    46                                                 WHERE id=".$id; 
    47                 $queryresult = mysql_query($querystatement,$dblink); 
    48                 if(!$queryresult) reportError(500,"Cannot delete search"); 
     49                function delete($id){ 
     50                        $querystatement="DELETE FROM usersearches  
     51                                                        WHERE id=".((int) $id); 
     52                        $queryresult = $this->db->query($querystatement); 
     53                         
     54                        echo "success"; 
     55                }  
     56 
     57 
     58                function save($name,$tabledefid,$userid){ 
     59                        $querystatement="INSERT INTO usersearches (userid,tabledefid,name,type,sqlclause) values ("; 
     60                        $querystatement.=((int) $userid).", "; 
     61                        $querystatement.="\"".$tabledefid."\", "; 
     62                        $querystatement.="\"".$name."\", "; 
     63                        $querystatement.="\"SCH\", ";            
     64                        $querystatement.="\"".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."\")"; 
     65 
     66                        $queryresult = $this->db->query($querystatement); 
     67                         
     68                        echo "search saved"; 
     69                } 
    4970                 
    50                 echo "success"; 
    51         }  
     71                function get($id){ 
     72                        $querystatement="SELECT sqlclause FROM usersearches  
     73                                                        WHERE id=".((int) $id); 
     74                        $queryresult = $this->db->query($querystatement); 
     75 
     76                        $therecord=$this->db->fetchArray($queryresult); 
     77                         
     78                        echo $therecord["sqlclause"]; 
     79                 
     80                } 
     81                 
     82                 
     83                function showSavedSearchList($queryresult,$basepath){ 
     84                         
     85                        $numrows=$this->db->numRows($queryresult); 
     86                         
     87                        ?> 
     88                        <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo $basepath ?>')"> 
     89                                <?php if($numrows<1) {?> 
     90                                        <option value="NA">No Saved Searches</option> 
     91                                <?php  
     92                                        } else { 
     93                                                $numglobal=0; 
     94                                                while($therecord=$this->db->fetchArray($queryresult)) 
     95                                                        if($therecord["userid"]<1) $numglobal++; 
     96                                                $this->db->seek($queryresult,0);                                 
     97                                ?>                       
     98                                        <?php if($numglobal>0){ ?> 
     99                                        <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> 
     100                                        <?php 
     101                                                }//end if 
     102                                                $userqueryline=true; 
     103                                                while($therecord=$this->db->fetchArray($queryresult)){ 
     104                                                        if ($therecord["userid"]> 0 and $userqueryline) { 
     105                                                                $userqueryline=false;                                            
     106                                                                ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php  
     107                                                        } 
     108                                                        ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php  
     109                                                }// end while 
     110                                        }//end if 
     111                                ?> 
     112                        </select> 
     113                        <?php 
     114                }//end function 
     115 
     116                 
     117                function showLoad($tabledefid,$basepath,$userid,$securitywhere){ 
    52118         
    53         function saveSearch($name,$tabledefid,$userid){ 
    54                 global $dblink; 
    55                  
    56                 $querystatement="INSERT INTO usersearches (userid,tabledefid,name,type,sqlclause) values ("; 
    57                 $querystatement.=$userid.", "; 
    58                 $querystatement.="\"".$tabledefid."\", "; 
    59                 $querystatement.="\"".$name."\", "; 
    60                 $querystatement.="\"SCH\", ";            
    61                 $querystatement.="\"".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."\")"; 
    62                 $queryresult = mysql_query($querystatement,$dblink); 
    63                 if(!$queryresult) reportError(500,"Cannot save search ".$querystatement); 
    64                 else echo "search saved"; 
    65         } 
     119                        $querystatement="SELECT id,name,userid FROM usersearches  
     120                                                        WHERE tabledefid=".$tabledefid." AND type=\"SCH\" AND ((userid=0 ".$securitywhere.") OR userid=\"".$userid."\") ORDER BY userid, name"; 
     121                        $queryresult = $this->db->query($querystatement); 
     122                        if(!$queryresult) $error = new appError(500,"Cannot retrieve saved search infromation"); 
     123                         
     124         
     125                        $querystatement="SELECT advsearchroleid FROM tabledefs WHERE id=".$tabledefid ; 
     126                        $tabledefresult = $this->db->query($querystatement); 
     127                        if(!$tabledefresult) $error = new appError(500,"Cannot retrieve table definition information."); 
     128                        $tableinfo=$this->db->fetchArray($tabledefresult); 
     129                         
     130                        ?> 
     131                        <table border="0" cellpadding="0" cellspacing="0"> 
     132                                <tr> 
     133                                        <td valign="top"> 
     134                                        <p> 
     135                                        <label for="LSList">saved searches</label><br /> 
     136                                                <?php $this->showSavedSearchList($queryresult,$basepath)?>                               
     137                                        </p> 
     138                                        </td> 
     139                                        <td valign="top" width="100%"> 
     140                                                <p> 
     141                                                <label for="LSSelectedSearch">name</label><br /> 
     142                                                        <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" />                                     
     143                                                </p> 
     144                                                <p> 
     145                                                        <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> 
     146                                                </p> 
     147                                        </td> 
     148                                        <td valign="top"> 
     149                                                <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> 
     150                                                <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo $basepath ?>')" class="Buttons" disabled="disabled" value="delete"/></p> 
     151                                                <div id="LSResults">&nbsp;</div> 
     152                                        </td> 
     153                                </tr> 
     154                        </table> 
     155                        <?php            
     156                } 
     157        }//end class 
     158         
     159         
     160         
    66161 
    67         function getSearch($id){ 
    68                 global $dblink; 
    69                  
    70                 $querystatement="SELECT sqlclause FROM usersearches  
    71                                                 WHERE id=".$id; 
    72                 $queryresult = mysql_query($querystatement,$dblink); 
    73                 if(!$queryresult) reportError(500,"Cannot retrieve saved search infromation"); 
    74                 $therecord=mysql_fetch_array($queryresult); 
    75                  
    76                 echo $therecord["sqlclause"]; 
    77          
    78         } 
    79162 
    80         function displaySavedSearchList($queryresult,$basepath){ 
    81                 $numrows=mysql_num_rows($queryresult); 
    82                 ?> 
    83                 <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo $basepath ?>')"> 
    84                         <?php if($numrows<1) {?> 
    85                                 <option value="NA">No Saved Searches</option> 
    86                         <?php  
    87                                 } else { 
    88                                         $numglobal=0; 
    89                                         while($therecord=mysql_fetch_array($queryresult)) 
    90                                                 if($therecord["userid"]<1) $numglobal++; 
    91                                         mysql_data_seek($queryresult,0);                                 
    92                         ?>                       
    93                                 <?php if($numglobal>0){ ?> 
    94                                 <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> 
    95                                 <?php 
    96                                         }//end if 
    97                                         $userqueryline=true; 
    98                                         while($therecord=mysql_fetch_array($queryresult)){ 
    99                                                 if ($therecord["userid"]> 0 and $userqueryline) { 
    100                                                         $userqueryline=false;                                            
    101                                                         ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php  
    102                                                 } 
    103                                                 ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php  
    104                                         }// end while 
    105                                 }//end if 
    106                         ?> 
    107                 </select> 
    108                 <?php 
    109         }//end function 
    110163 
    111         function showLoad($tabledefid,$basepath,$userid,$securitywhere){ 
    112                 global $dblink; 
    113                  
    114                 $querystatement="SELECT id,name,userid FROM usersearches  
    115                                                 WHERE tabledefid=".$tabledefid." AND type=\"SCH\" AND ((userid=0 ".$securitywhere.") OR userid=\"".$userid."\") ORDER BY userid, name"; 
    116                 $queryresult = mysql_query($querystatement,$dblink); 
    117                 if(!$queryresult) reportError(500,"Cannot retrieve saved search infromation"); 
    118                  
    119164 
    120                 $querystatement="SELECT advsearchroleid FROM tabledefs WHERE id=".$tabledefid ; 
    121                 $tabledefresult = mysql_query($querystatement,$dblink); 
    122                 if(!$tabledefresult) reportError(500,"Cannot retrieve table definition information."); 
    123                 $tableinfo=mysql_fetch_array($tabledefresult); 
    124                  
    125                 ?> 
    126                 <table border="0" cellpadding="0" cellspacing="0"> 
    127                         <tr> 
    128                                 <td valign="top"> 
    129                                 <p> 
    130                                 <label for="LSList">saved searches</label><br /> 
    131                                         <?php displaySavedSearchList($queryresult,$basepath)?>                           
    132                                 </p> 
    133                                 </td> 
    134                                 <td valign="top" width="100%"> 
    135                                         <p> 
    136                                         <label for="LSSelectedSearch">name</label><br /> 
    137                                                 <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" />                                     
    138                                         </p> 
    139                                         <p> 
    140                                                 <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> 
    141                                         </p> 
    142                                 </td> 
    143                                 <td valign="top"> 
    144                                         <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> 
    145                                         <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo $basepath ?>')" class="Buttons" disabled="disabled" value="delete"/></p> 
    146                                         <div id="LSResults">&nbsp;</div> 
    147                                 </td> 
    148                         </tr> 
    149                 </table> 
    150                 <?php            
    151         } 
    152165 
    153166        if(isset($_GET["cmd"])){ 
     167                 
     168                $thesearch = new savedSearch($db); 
     169                 
    154170                switch($_GET["cmd"]){ 
    155171                        case "show": 
     
    157173                                if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0) 
    158174                                        $securitywhere=" AND roleid IN (".implode(",",$_SESSION["userinfo"]["roles"]).",0)";                     
    159                                 showLoad($_GET["tid"],$_GET["base"],$_SESSION["userinfo"]["id"],$securitywhere); 
     175                                $thesearch->showLoad($_GET["tid"],$_GET["base"],$_SESSION["userinfo"]["id"],$securitywhere); 
    160176                        break; 
    161177                        case "getsearch": 
    162                                 getSearch($_GET["id"]); 
     178                                $thesearch->get($_GET["id"]); 
    163179                        break; 
    164180                        case "savesearch": 
    165                                 saveSearch($_GET["name"],$_GET["tid"],$_SESSION["userinfo"]["id"]); 
     181                                $thesearch->save($_GET["name"],$_GET["tid"],$_SESSION["userinfo"]["id"]); 
    166182                        break; 
    167183                        case "deletesearch": 
    168                                 deleteSearch($_GET["id"]); 
     184                                $thesearch->delete($_GET["id"]); 
    169185                        break; 
    170186                }//end switch 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.