phpBMS

Show
Ignore:
Timestamp:
06/25/09 17:55:57 (3 years ago)
Author:
nate
Message:
  • Initial changes to make the api use both uuids and ids, if possible.
  • An "options" object was added to the api's request array of objects. It currently has one option: useUuids. This toggles whether to use the id or the uuid in the update/get/delete commands.
  • Changes to delete, insertRecord, updateRecord commands in the main phpbms table / searchfunction classes and also the class extensions.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/loadsearch.php

    r559 r621  
    5656 
    5757 
    58                 /** 
    59                 * saves current search 
    60                 * 
    61                 * @param string $name name to save search as 
    62                 * @param integer $tabledefid table definition's id 
    63                 * @param string $userid uuid of user 
    64                 */ 
     58                /** 
     59                * saves current search 
     60                * 
     61                * @param string $name name to save search as 
     62                * @param integer $tabledefid table definition's id 
     63                * @param string $userid uuid of user 
     64                */ 
    6565                function save($name,$tabledefid,$userid){ 
    6666 
    67                     $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); 
    68  
    69                     $insertstatement = " 
    70                         INSERT INTO 
    71                             usersearches 
    72                         ( 
    73                             userid, 
    74                             tabledefid, 
    75                             name, 
    76                             `type`, 
    77                             sqlclause 
    78                         ) VALUES ( 
    79                             '".mysql_real_escape_string($userid)."', 
    80                             '".mysql_real_escape_string($uuid)."', 
    81                             '".mysql_real_escape_string($name)."', 
    82                             'SCH', 
    83                             '".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."' 
    84                         )"; 
    85  
    86                     $this->db->query($insertstatement); 
    87  
    88                     echo "search saved"; 
     67                        $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); 
     68 
     69                        $insertstatement = " 
     70                                INSERT INTO 
     71                                        usersearches 
     72                                ( 
     73                                        userid, 
     74                                        tabledefid, 
     75                                        name, 
     76                                        `type`, 
     77                                        sqlclause 
     78                                ) VALUES ( 
     79                                        '".mysql_real_escape_string($userid)."', 
     80                                        '".mysql_real_escape_string($uuid)."', 
     81                                        '".mysql_real_escape_string($name)."', 
     82                                        'SCH', 
     83                                        '".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."' 
     84                                )"; 
     85 
     86                        $this->db->query($insertstatement); 
     87 
     88                        echo "search saved"; 
    8989 
    9090                }//endfunction save 
    9191 
    9292 
    93                 /** 
    94                 * displays sql clause for saved search 
    95                 * 
    96                 * @param integer $id savedsearch id 
    97                 */ 
     93                /** 
     94                * displays sql clause for saved search 
     95                * 
     96                * @param integer $id savedsearch id 
     97                */ 
    9898                function get($id){ 
    9999 
    100100                    $querystatement=" 
    101                         SELECT 
    102                             sqlclause 
    103                         FROM 
    104                             usersearches 
    105                         WHERE id=".((int) $id); 
     101                                SELECT 
     102                                        sqlclause 
     103                                FROM 
     104                                        usersearches 
     105                                WHERE id=".((int) $id); 
    106106 
    107107                    $queryresult = $this->db->query($querystatement); 
     
    114114 
    115115 
    116                 /** 
    117                 * generates the select input of saved searches 
    118                 * 
    119                 * @param mysql query result $queryresult 
    120                 */ 
     116                /** 
     117                * generates the select input of saved searches 
     118                * 
     119                * @param mysql query result $queryresult 
     120                */ 
    121121                function showSavedSearchList($queryresult){ 
    122122 
    123                     $numrows = $this->db->numRows($queryresult); 
    124  
    125                     ?> 
    126                     <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo APP_PATH ?>')"> 
    127                         <?php if($numrows<1) {?> 
    128  
    129                             <option value="NA">No Saved Searches</option> 
    130  
    131                         <?php 
    132                             } else { 
    133  
    134                                 $numglobal=0; 
    135  
    136                                 while($therecord=$this->db->fetchArray($queryresult)) 
    137                                     if($therecord["userid"]<1) $numglobal++; 
    138  
    139                                 $this->db->seek($queryresult,0); 
    140  
    141                                 if($numglobal>0){ ?> 
    142                                     <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> 
    143                                 <?php 
    144                                 }//end if 
    145  
    146                                 $userqueryline = true; 
    147  
    148                                 while($therecord=$this->db->fetchArray($queryresult)){ 
    149  
    150                                     if ($therecord["userid"] != '' and $userqueryline) { 
    151  
    152                                         $userqueryline = false; 
    153  
    154                                         ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php 
    155  
    156                                     }//endif 
    157  
    158                                     ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php 
    159  
    160                                 }// end while 
    161  
    162                             }//end if 
    163                         ?> 
    164                     </select> 
    165                     <?php 
     123                        $numrows = $this->db->numRows($queryresult); 
     124 
     125                        ?> 
     126                        <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo APP_PATH ?>')"> 
     127                                <?php if($numrows<1) {?> 
     128 
     129                                        <option value="NA">No Saved Searches</option> 
     130 
     131                                <?php 
     132                                        } else { 
     133 
     134                                                $numglobal=0; 
     135 
     136                                                while($therecord=$this->db->fetchArray($queryresult)) 
     137                                                        if($therecord["userid"]<1) $numglobal++; 
     138 
     139                                                $this->db->seek($queryresult,0); 
     140 
     141                                                if($numglobal>0){ ?> 
     142                                                        <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> 
     143                                                <?php 
     144                                                }//end if 
     145 
     146                                                $userqueryline = true; 
     147 
     148                                                while($therecord=$this->db->fetchArray($queryresult)){ 
     149 
     150                                                        if ($therecord["userid"] != '' and $userqueryline) { 
     151 
     152                                                                $userqueryline = false; 
     153 
     154                                                                ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php 
     155 
     156                                                        }//endif 
     157 
     158                                                        ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php 
     159 
     160                                                }// end while 
     161 
     162                                        }//end if 
     163                                ?> 
     164                        </select> 
     165                        <?php 
    166166 
    167167                }//end function showSavedSearchList 
    168168 
    169169 
    170                 /** 
    171                 * displays the load box for saved searches 
    172                 * 
    173                 * @param integer $tabledefid id of tabledef 
    174                 * @param string $userid uuid of user 
    175                 * @param string $securitywhere additional security based where clause to pass 
    176                 */ 
     170                /** 
     171                * displays the load box for saved searches 
     172                * 
     173                * @param integer $tabledefid id of tabledef 
     174                * @param string $userid uuid of user 
     175                * @param string $securitywhere additional security based where clause to pass 
     176                */ 
    177177                function showLoad($tabledefid,$userid,$securitywhere){ 
    178178 
    179                     $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); 
    180  
    181                     $querystatement = " 
    182                         SELECT 
    183                             id, 
    184                             name, 
    185                             userid 
    186                         FROM 
    187                             usersearches 
    188                         WHERE 
    189                             tabledefid = '".$uuid."' 
    190                             AND type='SCH' 
    191                             AND ( 
    192                                 (userid = '' ".$securitywhere.") 
    193                                 OR userid = '".$userid."') 
    194                         ORDER BY 
    195                             userid, 
    196                             name"; 
    197  
    198                     $queryresult = $this->db->query($querystatement); 
    199  
    200                     if(!$queryresult) 
    201                         $error = new appError(500,"Cannot retrieve saved search infromation"); 
    202  
    203                     $querystatement=" 
    204                         SELECT 
    205                             advsearchroleid 
    206                         FROM 
    207                             tabledefs 
    208                         WHERE id= '".$tabledefid."'"; 
    209  
    210                     $tabledefresult = $this->db->query($querystatement); 
    211  
    212                     if(!$tabledefresult) 
    213                         $error = new appError(500,"Cannot retrieve table definition information."); 
    214  
    215                     $tableinfo=$this->db->fetchArray($tabledefresult); 
    216  
    217                     ?> 
    218                     <table border="0" cellpadding="0" cellspacing="0"> 
    219                         <tr> 
    220                             <td valign="top"> 
    221                                 <p> 
    222                                     <label for="LSList">saved searches</label><br /> 
    223                                     <?php $this->showSavedSearchList($queryresult)?> 
    224                                 </p> 
    225                             </td> 
    226                             <td valign="top" width="100%"> 
    227                                 <p> 
    228                                     <label for="LSSelectedSearch">name</label><br /> 
    229                                     <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" /> 
    230                                 </p> 
    231                                 <p> 
    232                                     <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> 
    233                                 </p> 
    234                             </td> 
    235                             <td valign="top"> 
    236                                 <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> 
    237                                 <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo APP_PATH ?>')" class="Buttons" disabled="disabled" value="delete"/></p> 
    238                                 <div id="LSResults">&nbsp;</div> 
    239                             </td> 
    240                         </tr> 
    241                     </table> 
    242                     <?php 
     179                        $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); 
     180 
     181                        $querystatement = " 
     182                                SELECT 
     183                                        id, 
     184                                        name, 
     185                                        userid 
     186                                FROM 
     187                                        usersearches 
     188                                WHERE 
     189                                        tabledefid = '".$uuid."' 
     190                                        AND type='SCH' 
     191                                        AND ( 
     192                                                (userid = '' ".$securitywhere.") 
     193                                                OR userid = '".$userid."') 
     194                                ORDER BY 
     195                                        userid, 
     196                                        name"; 
     197 
     198                        $queryresult = $this->db->query($querystatement); 
     199 
     200                        if(!$queryresult) 
     201                                $error = new appError(500,"Cannot retrieve saved search infromation"); 
     202 
     203                        $querystatement=" 
     204                                SELECT 
     205                                        advsearchroleid 
     206                                FROM 
     207                                        tabledefs 
     208                                WHERE id= '".$tabledefid."'"; 
     209 
     210                        $tabledefresult = $this->db->query($querystatement); 
     211 
     212                        if(!$tabledefresult) 
     213                                $error = new appError(500,"Cannot retrieve table definition information."); 
     214 
     215                        $tableinfo=$this->db->fetchArray($tabledefresult); 
     216 
     217                        ?> 
     218                        <table border="0" cellpadding="0" cellspacing="0"> 
     219                                <tr> 
     220                                        <td valign="top"> 
     221                                                <p> 
     222                                                        <label for="LSList">saved searches</label><br /> 
     223                                                        <?php $this->showSavedSearchList($queryresult)?> 
     224                                                </p> 
     225                                        </td> 
     226                                        <td valign="top" width="100%"> 
     227                                                <p> 
     228                                                        <label for="LSSelectedSearch">name</label><br /> 
     229                                                        <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" /> 
     230                                                </p> 
     231                                                <p> 
     232                                                        <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> 
     233                                                </p> 
     234                                        </td> 
     235                                        <td valign="top"> 
     236                                                <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> 
     237                                                <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo APP_PATH ?>')" class="Buttons" disabled="disabled" value="delete"/></p> 
     238                                                <div id="LSResults">&nbsp;</div> 
     239                                        </td> 
     240                                </tr> 
     241                        </table> 
     242                        <?php 
    243243 
    244244                }//end function showLoad 
    245245 
    246246        }//end class 
    247  
    248  
    249  
    250  
    251247 
    252248 
     
    259255                switch($_GET["cmd"]){ 
    260256                        case "show": 
    261                             $securitywhere = ""; 
    262  
    263                             if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){ 
    264  
    265                                 $securitywhere = ""; 
    266  
    267                                 foreach($_SESSION["userinfo"]["roles"] as $role) 
    268                                     $securitywhere .= ", '".$role."'"; 
    269  
    270                                 $securitywhere = " AND (`roleid` IN (''".$securitywhere.") OR `roleid` IS NULL)"; 
    271  
    272                             }//endif 
    273  
    274                             $thesearch->showLoad($_GET["tid"], $_SESSION["userinfo"]["uuid"], $securitywhere); 
    275                             break; 
     257                                $securitywhere = ""; 
     258 
     259                                if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){ 
     260 
     261                                        $securitywhere = ""; 
     262 
     263                                        foreach($_SESSION["userinfo"]["roles"] as $role) 
     264                                                $securitywhere .= ", '".$role."'"; 
     265 
     266                                        $securitywhere = " AND (`roleid` IN (''".$securitywhere.") OR `roleid` IS NULL)"; 
     267 
     268                                }//endif 
     269 
     270                                $thesearch->showLoad($_GET["tid"], $_SESSION["userinfo"]["uuid"], $securitywhere); 
     271                                break; 
    276272 
    277273                        case "getsearch": 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.