phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/include/tabledefs.php

    r427 r485  
    3939if(class_exists("phpbmsTable")){ 
    4040        class tableDefinitions extends phpbmsTable{ 
    41          
     41 
     42                var $availableRoleIDs = array(); 
     43 
    4244                function getDefaults(){ 
    4345                        $therecord = parent::getDefaults(); 
    44                          
     46 
    4547                        $therecord["moduleid"]=1; 
    4648                        $therecord["deletebutton"]="delete"; 
     
    5052                        $therecord["advsearchroleid"]=-100; 
    5153                        $therecord["viewsqlroleid"]=-100; 
    52                          
     54 
    5355                        return $therecord; 
    5456                } 
    55                  
     57 
     58                //populates $this->availableRoleIDs 
     59                function populateRoleArray(){ 
     60 
     61                        $this->availableRoleIDs = array(); 
     62 
     63                        $querystatement = " 
     64                                SELECT 
     65                                        `id` 
     66                                FROM 
     67                                        `roles`; 
     68                                "; 
     69 
     70                        $queryresult = $this->db->query($querystatement); 
     71 
     72                        $this->availableRoleIDs[] = 0;//for everyone 
     73                        $this->availableRoleIDs[] = -100;//for administrators 
     74 
     75                        while($therecord = $this->db->fetchArray($queryresult)) 
     76                                $this->availableRoleIDs[] = $therecord["id"]; 
     77 
     78                }//end method --populateRoleArray-- 
     79 
     80 
     81                function verifyVariables($variables){ 
     82 
     83 
     84                        //the following ifs are constructed in such a way as to allow 
     85                        //the integer 0 as an acceptable value 
     86 
     87                        if(isset($variables["maintable"])){ 
     88                                if($variables["maintable"] === "" || $variables["maintable"] === NULL) 
     89                                        $this->verifyErrors[] = "The `maintable` field must not be blank."; 
     90                        }else 
     91                                $this->verifyErrors[] = "The `maintable` field must be set."; 
     92 
     93                        if(isset($variables["addfile"])){ 
     94                                if($variables["addfile"] === "" || $variables["addfile"] === NULL) 
     95                                        $this->verifyErrors[] = "The `addfile` field must not be blank."; 
     96                        }else 
     97                                $this->verifyErrors[] = "The `addfile` field must be set."; 
     98 
     99                        if(isset($variables["editfile"])){ 
     100                                if($variables["editfile"] === "" || $variables["editfile"] === NULL) 
     101                                        $this->verifyErrors[] = "The `editfile` field must not be blank."; 
     102                        }else 
     103                                $this->verifyErrors[] = "The `editfile` field must be set."; 
     104 
     105                        if(isset($variables["querytable"])){ 
     106                                if($variables["querytable"] === "" || $variables["querytable"] === NULL) 
     107                                        $this->verifyErrors[] = "The `querytable` field must not be blank."; 
     108                        }else 
     109                                $this->verifyErrors[] = "The `querytable` field must be set."; 
     110 
     111                        if(isset($variables["defaultwhereclause"])){ 
     112                                if($variables["defaultwhereclause"] === "" || $variables["defaultwhereclause"] === NULL) 
     113                                        $this->verifyErrors[] = "The `defaultwhereclause` field must not be blank."; 
     114                        }else 
     115                                $this->verifyErrors[] = "The `defaultwhereclause` field must be set."; 
     116 
     117                        if(isset($variables["defaultsortorder"])){ 
     118                                if($variables["defaultsortorder"] === "" || $variables["defaultsortorder"] === NULL) 
     119                                        $this->verifyErrors[] = "The `defaultsortorder` field must not be blank."; 
     120                        }else 
     121                                $this->verifyErrors[] = "The `defaultsortorder` field must be set."; 
     122 
     123                        if(isset($variables["deletebutton"])){ 
     124                                if($variables["deletebutton"] === "" || $variables["deletebutton"] === NULL) 
     125                                        $this->verifyErrors[] = "The `delete` field must not be blank."; 
     126                        }else 
     127                                $this->verifyErrors[] = "The `delete` field must be set."; 
     128 
     129                        //table default sufficient 
     130                        if(isset($variables["type"])) 
     131                                switch($variables["type"]){ 
     132 
     133                                        case "table": 
     134                                        case "view": 
     135                                        case "system": 
     136                                        break; 
     137 
     138                                        default: 
     139                                                $this->verifyErrors[] = "The value of `type` field is invalid. Its value must be 
     140                                                        'table', 'view', or 'system'."; 
     141                                        break; 
     142 
     143                                }//end switch 
     144 
     145                        if(isset($variables["addroleid"])){ 
     146 
     147                                if(is_numeric($variables["addroleid"]) || !$variables["addroleid"]){ 
     148 
     149                                        if(!count($this->availableRoleIDs)) 
     150                                                $this->populateRoleArray(); 
     151 
     152                                        if(!in_array(((int)$variables["addroleid"]), $this->availableRoleIDs)) 
     153                                                $this->verifyErrors[] = "The `addroleid` field does not give an existing/acceptable role id number."; 
     154 
     155                                }else 
     156                                        $this->verifyErrors[] = "The `addroleid` field must be numeric or equivalent to 0."; 
     157 
     158                        }//end if 
     159 
     160                        if(isset($variables["editroleid"])){ 
     161 
     162                                if(is_numeric($variables["editroleid"]) || !$variables["editroleid"]){ 
     163 
     164                                        if(!count($this->availableRoleIDs)) 
     165                                                $this->populateRoleArray(); 
     166 
     167                                        if(!in_array(((int)$variables["editroleid"]), $this->availableRoleIDs)) 
     168                                                $this->verifyErrors[] = "The `editroleid` field does not give an existing/acceptable role id number."; 
     169 
     170                                }else 
     171                                        $this->verifyErrors[] = "The `editroleid` field must be numeric or equivalent to 0."; 
     172 
     173                        }//end if 
     174 
     175                        if(isset($variables["importroleid"])){ 
     176 
     177                                if(is_numeric($variables["importroleid"]) || !$variables["importroleid"]){ 
     178 
     179                                        if(!count($this->availableRoleIDs)) 
     180                                                $this->populateRoleArray(); 
     181 
     182                                        if(!in_array(((int)$variables["importroleid"]), $this->availableRoleIDs)) 
     183                                                $this->verifyErrors[] = "The `importroleid` field does not give an existing/acceptable role id number."; 
     184 
     185                                }else 
     186                                        $this->verifyErrors[] = "The `importroleid` field must be numeric or equivalent to 0."; 
     187 
     188                        }//end if 
     189 
     190                        if(isset($variables["searchroleid"])){ 
     191 
     192                                if(is_numeric($variables["searchroleid"]) || !$variables["searchroleid"]){ 
     193 
     194                                        if(!count($this->availableRoleIDs)) 
     195                                                $this->populateRoleArray(); 
     196 
     197                                        if(!in_array(((int)$variables["searchroleid"]), $this->availableRoleIDs)) 
     198                                                $this->verifyErrors[] = "The `searchroleid` field does not give an existing/acceptable role id number."; 
     199 
     200                                }else 
     201                                        $this->verifyErrors[] = "The `searchroleid` field must be numeric or equivalent to 0."; 
     202 
     203                        }//end if 
     204 
     205                        if(isset($variables["advsearchroleid"])){ 
     206 
     207                                if(is_numeric($variables["advsearchroleid"]) || !$variables["advsearchroleid"]){ 
     208 
     209                                        if(!count($this->availableRoleIDs)) 
     210                                                $this->populateRoleArray(); 
     211 
     212                                        if(!in_array(((int)$variables["advsearchroleid"]), $this->availableRoleIDs)) 
     213                                                $this->verifyErrors[] = "The `advsearchroleid` field does not give an existing/acceptable role id number."; 
     214 
     215                                }else 
     216                                        $this->verifyErrors[] = "The `advsearchroleid` field must be numeric or equivalent to 0."; 
     217 
     218                        }//end if 
     219 
     220                        if(isset($variables["viewsqlroleid"])){ 
     221 
     222                                if(is_numeric($variables["viewsqlroleid"]) || !$variables["viewsqlroleid"]){ 
     223 
     224                                        if(!count($this->availableRoleIDs)) 
     225                                                $this->populateRoleArray(); 
     226 
     227                                        if(!in_array(((int)$variables["viewsqlroleid"]), $this->availableRoleIDs)) 
     228                                                $this->verifyErrors[] = "The `viewsqlroleid` field does not give an existing/acceptable role id number."; 
     229 
     230                                }else 
     231                                        $this->verifyErrors[] = "The `viewsqlroleid` field must benumeric or quivalent to 0."; 
     232 
     233                        }//end if 
     234 
     235                        return parent::verifyVariables($variables); 
     236 
     237                }//end method --verifyVariables-- 
     238 
    56239                function insertRecord($variables,$createdby = NULL){ 
    57240 
    58241                        if(!isset($variables["newid"])) 
    59242                                $variables["newid"] = ""; 
    60                                  
     243 
    61244                        if($variables["newid"]){ 
    62                                 //this will set a specific ID to be used.                                
     245                                //this will set a specific ID to be used. 
    63246                                $variables["id"] = $variables["newid"]; 
    64247                                parent::insertRecord($variables,$createdby,true); 
    65248                                $newid =  $variables["newid"]; 
    66                          
     249 
    67250                        } else { 
    68                          
     251 
    69252                                $newid = parent::insertRecord($variables,$createdby); 
    70                                  
     253 
    71254                        }//endif - newid 
    72                          
     255 
    73256                        //we need to create the some default supporting records 
    74257                        //first a single column. 
    75                         $querystatement = "INSERT INTO `tablecolumns`  
    76                         (`tabledefid`, `name`, `column`, `align`, `footerquery`, `displayorder`, `sortorder`, `wrap`, `size`, `format`, `roleid`)  
     258                        $querystatement = "INSERT INTO `tablecolumns` 
     259                        (`tabledefid`, `name`, `column`, `align`, `footerquery`, `displayorder`, `sortorder`, `wrap`, `size`, `format`, `roleid`) 
    77260                        VALUES (".$newid.",'id','".$variables["maintable"].".id','left','',0,'',0,'',NULL,0);"; 
    78261                        $this->db->query($querystatement); 
    79                          
     262 
    80263                        //next default button options 
    81                         $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`)  
     264                        $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`) 
    82265                        VALUES (".$newid.",'new','1',0,0,0);"; 
    83266                        $this->db->query($querystatement); 
    84267 
    85                         $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`)  
     268                        $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`) 
    86269                        VALUES (".$newid.",'edit','1','1',0,0);"; 
    87270                        $this->db->query($querystatement); 
    88271 
    89                         $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`)  
     272                        $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`) 
    90273                        VALUES (".$newid.",'printex','1',0,0,0);"; 
    91274                        $this->db->query($querystatement); 
    92275 
    93                         $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`)  
     276                        $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`) 
    94277                        VALUES (".$newid.",'select','1',0,0,0);"; 
    95278                        $this->db->query($querystatement); 
    96                          
    97                         $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`)  
     279 
     280                        $querystatement = "INSERT INTO `tableoptions` (`tabledefid`, `name`, `option`, `needselect`, `othercommand`, `roleid`) 
    98281                        VALUES (".$newid.",'import','1',0,0,'-100');"; 
    99282                        $this->db->query($querystatement); 
    100283 
    101284                        //next quicksearch 
    102                         $querystatement = "INSERT INTO `tablefindoptions` (`tabledefid`, `name`, `search`, `displayorder`, `roleid`)  
     285                        $querystatement = "INSERT INTO `tablefindoptions` (`tabledefid`, `name`, `search`, `displayorder`, `roleid`) 
    103286                        VALUES (".$newid.",'All Records','".$variables["maintable"].".id!=-1',0,0);"; 
    104287                        $this->db->query($querystatement); 
    105288 
    106289                        //and last findfields 
    107                         $querystatement = "INSERT INTO `tablesearchablefields` (`tabledefid`, `field`, `name`, `displayorder`, `type`)  
     290                        $querystatement = "INSERT INTO `tablesearchablefields` (`tabledefid`, `field`, `name`, `displayorder`, `type`) 
    108291                        VALUES (".$newid.",'".$variables["maintable"].".id','id',1,'field');"; 
    109292                        $this->db->query($querystatement); 
    110                          
     293 
    111294                        return $newid; 
    112                          
     295 
    113296                } 
    114297        }//end class 
     
    119302 
    120303                function delete_record(){ 
    121                  
     304 
    122305                        //passed variable is array of user ids to be revoked 
    123306                        $whereclause=""; 
     
    127310                        $linkedwhereclause = $this->buildWhereClause("tabledefid"); 
    128311                        $relationshipswhereclause = $this->buildWhereClause("fromtableid")." or ".$this->buildWhereClause("totableid"); 
    129                          
     312 
    130313                        $querystatement = "DELETE FROM tablecolumns WHERE ".$linkedwhereclause.";"; 
    131314                        $queryresult = $this->db->query($querystatement); 
    132                  
     315 
    133316                        $querystatement = "DELETE FROM tablefindoptions WHERE ".$linkedwhereclause.";"; 
    134317                        $queryresult = $this->db->query($querystatement); 
    135                  
     318 
    136319                        $querystatement = "DELETE FROM tableoptions WHERE ".$linkedwhereclause.";"; 
    137320                        $queryresult = $this->db->query($querystatement); 
    138                  
     321 
    139322                        $querystatement = "DELETE FROM tablesearchablefields WHERE ".$linkedwhereclause.";"; 
    140323                        $queryresult = $this->db->query($querystatement); 
    141                  
     324 
    142325                        $querystatement = "DELETE FROM usersearches WHERE ".$linkedwhereclause.";"; 
    143326                        $queryresult = $this->db->query($querystatement); 
    144                  
     327 
    145328                        $querystatement = "DELETE FROM relationships WHERE ".$relationshipswhereclause.";"; 
    146329                        $queryresult = $this->db->query($querystatement); 
    147                  
     330 
    148331                        $querystatement = "DELETE FROM tabledefs WHERE ".$whereclause.";"; 
    149332                        $queryresult = $this->db->query($querystatement); 
    150                  
     333 
    151334                        $message = $this->buildStatusMessage(); 
    152335                        $message.=" deleted."; 
    153                         return $message;         
     336                        return $message; 
    154337                }//end method 
    155338 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.