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/files.php

    r285 r485  
    4040if(class_exists("phpbmsTable")){ 
    4141        class files extends phpbmsTable{ 
    42          
     42 
     43                var $availableRoleIDs = array(); 
     44 
    4345                function getPicture($name){ 
    4446                        if (function_exists('file_get_contents')) { 
     
    4850                                $file = addslashes(fread(fopen($_FILES[$name]['tmp_name'], 'r'), filesize($_FILES[$name]['tmp_name']))); 
    4951                        } 
    50                          
     52 
    5153                        return $file; 
    5254                } 
    53                  
    54                 function formatVariables($variables){ 
    55          
    56                         if($_FILES['upload']["name"]){ 
    57                                  
    58                                 $variables["name"] = $_FILES['upload']["name"];                  
    59                                 $variables["type"] = $_FILES['upload']['type'];                  
    60                                 $variables["file"] = $this->getPicture("upload"); 
    61                                  
    62                         } else { 
    63                                 unset($this->fields["type"]); 
    64                                 unset($this->fields["file"]); 
     55 
     56                //populates the list of possible role ids 
     57                //into $this->availableRoleIDs (an array) 
     58                function populateRoleArray(){ 
     59 
     60                        $this->availableRoleIDs = array(); 
     61 
     62                        $querystatement = " 
     63                                SELECT 
     64                                        `id` 
     65                                FROM 
     66                                        `roles`; 
     67                                "; 
     68 
     69                        $queryresult = $this->db->query($querystatement); 
     70 
     71                        //next two should also be allowed, but aren't stored in the database 
     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                        //if it is set, we'll have to check, if not, it defaults to 0 which is an acceptable 
     84                        //value. 
     85                        if(isset($variables["roleid"])){ 
     86 
     87                                //either its numeric or == 0 
     88                                if(is_numeric($variables["roleid"]) || !$variables["roleid"]){ 
     89 
     90                                        //check to see if the RoleIDs are populated 
     91                                        if(!count($this->availableRoleIDs)) 
     92                                                $this->populateRoleArray();//populate if not 
     93 
     94                                        //check to see if the int typecast of the roleid (to allow for values 
     95                                        //equivalent to 0) is an acceptable role id. 
     96                                        if(!in_array(((int)$variables["roleid"]), $this->availableRoleIDs)) 
     97                                                $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable role id number."; 
     98                                }else 
     99                                        $this->verifyErrors[] = "The `roleid` field must be numeric or equivalent to 0."; 
    65100                        }//end if 
    66                          
    67                         return $variables;                       
    68                  
     101 
     102                        return parent::verifyVariables($variables); 
     103 
     104                }//end method 
     105 
     106 
     107                function prepareVariables($variables){ 
     108 
     109                        if(isset($_FILES['upload'])) 
     110                                if($_FILES['upload']["name"]){ 
     111 
     112                                        $variables["name"] = $_FILES['upload']["name"]; 
     113                                        $variables["type"] = $_FILES['upload']['type']; 
     114                                        $variables["file"] = $this->getPicture("upload"); 
     115 
     116                                } else { 
     117                                        unset($this->fields["type"]); 
     118                                        unset($this->fields["file"]); 
     119                                }//end if 
     120 
     121                        return $variables; 
     122 
    69123                }//end function 
    70          
    71          
     124 
     125 
    72126                function updateRecord($variables, $modifiedby = NULL){ 
    73          
    74                         $variables = $this->formatVariables($variables); 
    75          
     127 
    76128                        $thereturn = parent::updateRecord($variables, $modifiedby); 
    77                          
     129 
    78130                        //restore the fields 
    79131                        $this->getTableInfo(); 
    80                          
     132 
    81133                        return $thereturn; 
    82134                }//end method 
    83                  
    84                  
     135 
     136 
    85137                function insertRecord($variables, $createdby = NULL){ 
    86                  
    87                         $variables = $this->formatVariables($variables); 
    88          
     138 
    89139                        $newid = parent::insertRecord($variables, $createdby); 
    90                          
     140 
    91141                        //restore the fields 
    92142                        $this->getTableInfo(); 
    93                          
     143 
    94144                        return $newid; 
    95                          
     145 
    96146                }//end method 
    97                          
     147 
    98148        }//end class 
    99149}//end if 
     
    101151if(class_exists("searchFunctions")){ 
    102152        class filesSearchFunctions extends searchFunctions{ 
    103          
     153 
    104154                function delete_record(){ 
    105                  
     155 
    106156                        $whereclause = $this->buildWhereClause(); 
    107157                        $attachmentwhereclause = $this->buildWhereClause("attachments.fileid"); 
    108                  
     158 
    109159                        $querystatement = "DELETE FROM attachments WHERE ".$attachmentwhereclause." AND attachments.fileid!=1;"; 
    110160                        $queryresult = $this->db->query($querystatement); 
    111                  
     161 
    112162                        $querystatement = "DELETE FROM files WHERE ".$whereclause." AND files.id!=1;"; 
    113163                        $queryresult = $this->db->query($querystatement); 
    114                          
     164 
    115165                        $message = $this->buildStatusMessage(); 
    116166                        $message.=" deleted"; 
    117167                        return $message; 
    118168                } 
    119          
     169 
    120170        }//end class 
    121171}//end if 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.