phpBMS

Changeset 570

Show
Ignore:
Timestamp:
06/03/09 19:08:38 (3 years ago)
Author:
nate
Message:
  • Files now uses uuid files correctly.
  • Initial implementation of uuids for attachments.
Location:
trunk/phpbms
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/include/search_class.php

    r563 r570  
    291291                        //Add limit (settings) 
    292292                        $_SESSION["thequerystatement"].=" limit ".$this->recordoffset.", ".RECORD_LIMIT.";"; 
    293  
    294293 
    295294                        $this->db->logError=false; 
  • trunk/phpbms/include/tables.php

    r565 r570  
    394394         * @return array A list of uuids used in the table. 
    395395         */ 
    396   
     396 
    397397        function _loadUUIDList($tableName) { 
    398398 
     
    462462            if(isset($variables["uuid"])) 
    463463                if(!$variables["uuid"]) 
    464                     $this->verifyErrors[] = "The `uuid` field annot be blank"; 
     464                    $this->verifyErrors[] = "The `uuid` field cannot be blank"; 
    465465 
    466466            if(isset($variables["inactive"])) 
     
    705705 
    706706                                $this->updateRecord($variables); 
     707                                if(isset($variables["getid"])) 
     708                                    if(is_numeric($variables["getid"])) 
     709                                        $theid = (int) $variables["getid"];// special variable to override the 
     710                                        //id for get record 
    707711 
    708712                                //get record 
  • trunk/phpbms/install/files.sql

    r542 r570  
    1 INSERT INTO `files` (`id`, `uuid`, `name`, `description`, `file`, `type`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`, `roleid`, `custom1`, `custom2`, `custom3`, `custom4`, `custom5`, `custom6`, `custom7`, `custom8`) VALUES ('1', '', 'logo.png', 'Company Logo Used in PDF reports', '‰PNG\r\n\Z\n\0\0\0\rIHDR\0\0\0\0\0]\0\0\0ŸS°\0\0\0gAMA\0\0¯È7Šé\0\0\0tEXtSoftware\0Adobe ImageReadyqÉe<\0\0\0`PLTE666ÑÑѶ¶¶óó󪪪kkk   rrrœœœÅÅŎŽŽèèèÛÛۄ„„¿¿¿|||XXXÞÞÞðððˆˆˆÉÉÉââ╕•€€€KKK&&&QQQPPP%%%bbbcccÿÿÿV\"l\0\0\0ØIDATxÚb \0@£A\0\0D£påΡ\0D£pà”®¡\04ˆÃA‘‘‘‰˜±I#€<^inT)&1^v99YYv^.f°@\0a†ƒ /¿¬ 
     1INSERT INTO `files` (`id`, `uuid`, `name`, `description`, `file`, `type`, `createdby`, `creationdate`, `modifiedby`, `modifieddate`, `roleid`, `custom1`, `custom2`, `custom3`, `custom4`, `custom5`, `custom6`, `custom7`, `custom8`) VALUES ('1', 'file:ad761197-e5a2-3fdf-f330-d1508f10813e', 'logo.png', 'Company Logo Used in PDF reports', '‰PNG\r\n\Z\n\0\0\0\rIHDR\0\0\0\0\0]\0\0\0ŸS°\0\0\0gAMA\0\0¯È7Šé\0\0\0tEXtSoftware\0Adobe ImageReadyqÉe<\0\0\0`PLTE666ÑÑѶ¶¶óó󪪪kkk   rrrœœœÅÅŎŽŽèèèÛÛۄ„„¿¿¿|||XXXÞÞÞðððˆˆˆÉÉÉââ╕•€€€KKK&&&QQQPPP%%%bbbcccÿÿÿV\"l\0\0\0ØIDATxÚb \0@£A\0\0D£påΡ\0D£pà”®¡\04ˆÃA‘‘‘‰˜±I#€<^inT)&1^v99YYv^.f°@\0a†ƒ /¿¬ 
    22X#%á I~8°\0] +t*‚#ËÏ&‚¬†WVVN®‚ÝV~šŽ¬Bœ› 
    33\"\n0àgj Žp\0«’“ 
     
    122122܀€\0Â(­Uº 
    123123H•B=óÄ u¶±*€\0\ZYóÜšå0\0 Ñy 
    124 \0 Ñp€\0€\0\Z\r\00\0tP|O;ë\0\0\0\0IEND®B`‚', 'image/png', 1, NOW(), 1, NOW(), '90', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 
     124\0 Ñp€\0€\0\Z\r\00\0tP|O;ë\0\0\0\0IEND®B`‚', 'image/png', 1, NOW(), 1, NOW(), 'Admin', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 
  • trunk/phpbms/install/generateuuids.php

    r569 r570  
    110110        $this->roleList[0] = ""; 
    111111 
     112        $this->tabledefList = $this->generateUUIDList("tabledefs"); 
     113        // 
     114        //$this->moduleList= $this->generateUUIDList("modules"); 
     115 
    112116        $menuList = $this->generateUUIDList("menu"); 
    113117        $menuList[0] = ""; 
     
    128132        //$this->updateFields("usersearches", array("tabledefid"=>$this->tabledefList, "userid"=>$this->userList, "roleid"=>$this->roleList)); 
    129133        //$this->updateFields("relationships", array("fromtableid"=>$this->tabledefList, "totableid"=>$this->tabledefList)); 
     134 
     135        //$this->updateFields("files", array("roleid"=>$this->roleList)); 
    130136        //$this->updateFields("menu", array("parentid"=>$menuList, "roleid"=>$this->roleList)); 
    131137        //$this->updateFields("smartsearches", array("tabledefid"=>$this->tabledefList, "moduleid"=>$this->moduleList)); 
  • trunk/phpbms/install/updatev0.98.sql

    r569 r570  
    232232--end usersearches ALTER-- 
    233233 
     234--files UPDATE-- 
     235UPDATE `files` SET 
     236    `uuid`='file:ad761197-e5a2-3fdf-f330-d1508f10813e', 
     237    `roleid` = 'Admin' 
     238WHERE 
     239    `id`='1'; 
     240--end files UPDATE-- 
    234241--menu INSERT-- 
    235242DELETE FROM `menu`; 
  • trunk/phpbms/modules/base/files_addedit.php

    r543 r570  
    6767        function getAttachments($db,$id){ 
    6868                $querystatement="SELECT tabledefs.displayname, attachments.recordid, attachments.creationdate, tabledefs.editfile 
    69                                                 FROM attachments INNER JOIN tabledefs ON attachments.tabledefid=tabledefs.id 
     69                                                FROM attachments INNER JOIN tabledefs ON attachments.tabledefid=tabledefs.uuid 
    7070                                                WHERE fileid=".$id; 
    7171                $queryresult=$db->query($querystatement); 
  • trunk/phpbms/modules/base/include/attachments.php

    r427 r570  
    3939if(class_exists("files")){ 
    4040        class attachments extends files{ 
    41          
    42          
     41 
     42 
    4343                function getRecord($id){ 
    4444                        $id = (int) $id; 
    45                          
    46                         $querystatement = "SELECT 
    47                                         files.id,attachments.id as attachmentid,name,description,type,roleid,ISNULL(file) as nofile, 
    48                                          
    49                                         attachments.createdby, attachments.creationdate,  
    50                                         attachments.modifiedby, attachments.modifieddate 
    51          
    52                                         FROM attachments INNER JOIN files on attachments.fileid=files.id 
    53                                         WHERE attachments.id=".$id; 
    54                                          
    55                         $queryresult = $this->db->query($querystatement); 
    56                          
     45 
     46                        $querystatement = " 
     47                                SELECT 
     48                                        `files`.`id`, 
     49                                        `files`.`uuid`, 
     50                                        `attachments`.`id` AS `attachmentid`, 
     51                                        `name`, 
     52                                        `description`, 
     53                                        `type`, 
     54                                        `roleid`, 
     55                                        ISNULL(`file`) AS `nofile`, 
     56                                        `attachments`.`createdby`, 
     57                                        `attachments`.`creationdate`, 
     58                                        `attachments`.`modifiedby`, 
     59                                        `attachments`.`modifieddate` 
     60                                FROM 
     61                                        `attachments`INNER JOIN `files` ON `attachments`.`fileid`=`files`.`uuid` 
     62                                WHERE 
     63                                        `attachments`.`id`='".$id."' 
     64                                "; 
     65 
     66                        $queryresult = $this->db->query($querystatement); 
     67 
    5768                        if($this->db->numRows($queryresult)) 
    5869                                $therecord = $this->db->fetchArray($queryresult); 
    59                         else  
     70                        else 
    6071                                $therecord = $this-> getDefaults(); 
    61                  
    62                          
     72 
     73 
    6374                        return $therecord; 
    64          
    65                 } 
    66                  
     75 
     76                } 
     77 
    6778                function getDefaults(){ 
    6879                        $therecord = parent::getDefaults(); 
    69                          
     80 
    7081                        $therecord["attachmentid"] = NULL; 
    7182                        $therecord["nofile"] = 1; 
    72                          
    73                         return $therecord;       
    74          
    75                 } 
    76                  
    77                  
     83 
     84                        return $therecord; 
     85 
     86                } 
     87 
     88 
     89                function prepareVariables($variables){ 
     90 
     91                        $variables["getid"] = $variables["attachmentid"]; //to fix the get record problem 
     92 
     93                        return parent::prepareVariables($variables); 
     94 
     95                }//end method 
     96 
     97 
    7898                function updateRecord($variables, $modifiedby = NULL){ 
    7999                        parent::updateRecord($variables, $modifiedby); 
    80                          
     100 
    81101                        $_POST["id"] = $variables["attachmentid"]; 
    82                 } 
    83                  
    84          
     102 
     103                } 
     104 
     105 
    85106                function insertRecord($variables, $createdby = NULL){ 
    86                          
     107 
    87108                        if($createdby == NULL) 
    88109                                $createdby = $_SESSION["userinfo"]["id"]; 
    89                          
     110 
    90111                        if($variables["newexisting"]=="new"){ 
    91112                                //we need to add a new file record before adding a new 
    92113                                //attachment record 
    93                                  
    94                                 $variables["fileid"] = parent::insertRecord($variables, $createdby);                     
     114 
     115                                $variables["fileid"] = parent::insertRecord($variables, $createdby); 
    95116                        } 
    96                          
     117 
    97118                        //next we create the attachment record 
    98                         $querystatement="INSERT INTO attachments ";      
     119 
     120                        $querystatement = " 
     121                                SELECT 
     122                                        `uuid`, 
     123                                        `maintable` 
     124                                FROM 
     125                                        `tabledefs` 
     126                                WHERE 
     127                                        `id` = '".(int)$variables["tabledefid"]."' 
     128                                "; 
     129 
     130                        $queryresult = $this->db->query($querystatement); 
     131                        $therecord = $this->db->fetchArray($queryresult); 
     132                        $tabldefid = $therecord["uuid"]; 
     133                        $maintable = $therecord["maintable"]; 
     134 
     135                        $querystatement = " 
     136                                SELECT 
     137                                        `uuid` 
     138                                FROM 
     139                                        `".$maintable."` 
     140                                WHERE 
     141                                        `id` = '".$variables["recordid"]."' 
     142                                "; 
     143 
     144                        $queryresult = $this->db->query($querystatement); 
     145                        $therecord = $this->db->fetchArray($queryresult); 
     146                        $recordid = $therecord["uuid"]; 
     147 
     148                        $querystatement = " 
     149                                SELECT 
     150                                        `uuid` 
     151                                FROM 
     152                                        `files` 
     153                                WHERE 
     154                                        `id` = '".$variables["fileid"]."' 
     155                                "; 
     156 
     157                        $queryresult = $this->db->query($querystatement); 
     158                        $therecord = $this->db->fetchArray($queryresult); 
     159                        $fileid = $therecord["uuid"]; 
     160 
     161                        $querystatement="INSERT INTO attachments "; 
    99162                        $querystatement.="(fileid,tabledefid,recordid, 
    100163                                                                createdby,creationdate,modifiedby) VALUES ("; 
    101                          
    102                         $querystatement.=$variables["fileid"].", ";  
    103                         $querystatement.=$variables["tabledefid"].", ";  
    104                         $querystatement.=$variables["recordid"].", ";  
    105                                                  
    106                         $querystatement.=$createdby.", ";  
     164 
     165                        $querystatement.="'".$fileid."', "; 
     166                        $querystatement.="'".$tabldefid."', "; 
     167                        $querystatement.="'".$recordid."', "; 
     168 
     169                        $querystatement.=$createdby.", "; 
    107170                        $querystatement.="Now(), "; 
    108                         $querystatement.=$createdby.")";  
    109                  
    110                         $queryresult = $this->db->query($querystatement); 
    111                          
     171                        $querystatement.=$createdby.")"; 
     172 
     173                        $queryresult = $this->db->query($querystatement); 
     174 
    112175                        if($queryresult) 
    113176                                return $this->db->insertId(); 
    114177                        else 
    115178                                return false; 
    116                                          
     179 
    117180                }//end method 
    118                  
     181 
    119182        }//end class 
    120183}//end if 
     
    124187 
    125188                function delete_record(){ 
    126                          
     189 
    127190                        $whereclause = $this->buildWhereClause(); 
    128                          
     191 
    129192                        $rowsdeleted=0; 
    130193                        foreach($this->idsArray as $id){ 
     
    132195                                $queryresult = $this->db->query($querystatement); 
    133196                                $therecord=$this->db->fetchArray($queryresult); 
    134                                  
     197 
    135198                                $querystatement = "DELETE FROM attachments WHERE id=".$id.";"; 
    136199                                $queryresult = $this->db->query($querystatement); 
    137200                                $rowsdeleted++; 
    138                                  
     201 
    139202                                $querystatement = "SELECT id FROM attachments WHERE fileid=".$therecord["fileid"].";"; 
    140203                                $queryresult = $this->db->query($querystatement); 
     
    144207                                        $queryresult = $this->db->query($querystatement); 
    145208                                } 
    146                                  
     209 
    147210                        } 
    148                  
     211 
    149212                        $querystatement = "DELETE FROM attachments WHERE ".$whereclause.";"; 
    150213                        $queryresult = $this->db->query($querystatement); 
    151                          
     214 
    152215                        $message = $this->buildStatusMessage($rowsdeleted); 
    153216                        $message.=" deleted."; 
  • trunk/phpbms/modules/base/include/files.php

    r515 r570  
    4141        class files extends phpbmsTable{ 
    4242 
    43                 var $availableRoleIDs = array(); 
     43                var $_availableRoleUUIDs = NULL; 
    4444 
    4545                function getPicture($name){ 
     
    5454                } 
    5555 
    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  
    8056 
    8157                function verifyVariables($variables){ 
    8258 
    83                         //if it is set, we'll have to check, if not, it defaults to 0 which is an acceptable 
     59                        //if it is set, we'll have to check, if not, it defaults to '' which is an acceptable 
    8460                        //value. 
    8561                        if(isset($variables["roleid"])){ 
    8662 
    87                                 //either its numeric or == 0 
    88                                 if(is_numeric($variables["roleid"]) || !$variables["roleid"]){ 
     63                                //check to see if the RoleIDs are populated 
     64                                if($this->_availableRoleUUIDs === NULL){ 
     65                                        $this->_availableRoleUUIDs = $this->_loadUUIDList("roles"); 
     66                                        $this->_availableRoleUUIDs[] = ""; 
     67                                        $this->_availableRoleUUIDs[] = "Admin"; 
     68                                }//end if 
    8969 
    90                                         //check to see if the RoleIDs are populated 
    91                                         if(!count($this->availableRoleIDs)) 
    92                                                 $this->populateRoleArray();//populate if not 
     70                                if(!in_array(((string)$variables["roleid"]), $this->_availableRoleUUIDs)) 
     71                                        $this->verifyErrors[] = "The `roleid` field does not give an existing/acceptable role id number."; 
    9372 
    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."; 
    10073                        }//end if 
    10174 
     
    11992                                }//end if 
    12093 
    121                         return $variables; 
     94                        return parent::prepareVariables($variables); 
    12295 
    12396                }//end function 
  • trunk/phpbms/modules/bms/clients_attachments.php

    r545 r570  
    5050    $refid = (integer) $_GET["id"]; 
    5151 
     52    $querystatement = " 
     53        SELECT 
     54            `uuid`, 
     55            `maintable` 
     56        FROM 
     57            `tabledefs` 
     58        WHERE 
     59            `id` = '".(int)$tabledefid."' 
     60        "; 
     61 
     62    $queryresult = $db->query($querystatement); 
     63    $therecord = $db->fetchArray($queryresult); 
     64    $tabledefuuid = $therecord["uuid"]; 
     65    $maintable = $therecord["maintable"]; 
     66 
     67    $querystatement = " 
     68        SELECT 
     69            `uuid` 
     70        FROM 
     71            `".$maintable."` 
     72        WHERE 
     73            `id` = '".$refid."' 
     74        "; 
     75 
     76    $queryresult = $db->query($querystatement); 
     77    $therecord = $db->fetchArray($queryresult); 
     78    $refuuid = $therecord["uuid"]; 
     79 
    5280    $securitywhere=""; 
    53     if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0) 
    54         $securitywhere=" AND files.roleid IN (".implode(",",$_SESSION["userinfo"]["roles"]).",0)"; 
     81    if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){ 
     82        $securitywhere = "''"; 
     83        foreach($_SESSION["userinfo"]["roles"] as $roleuuid) 
     84            $securitywhere .= ",'".$roleuuid."'"; 
     85    }//end if 
    5586 
    56     $whereclause="attachments.tabledefid=".$tabledefid." AND attachments.recordid=".$refid.$securitywhere; 
     87    $whereclause="attachments.tabledefid='".$tabledefuuid."' AND attachments.recordid='".$refuuid."'".$securitywhere; 
    5788    $backurl="../bms/clients_attachments.php"; 
    5889    $base="../../"; 
  • trunk/phpbms/modules/bms/invoices_attachments.php

    r546 r570  
    4848        if(isset($_GET["refid"])) $_GET["id"]=$_GET["refid"]; 
    4949        $refid=(integer) $_GET["id"]; 
    50         $securitywhere=""; 
    51         if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0) 
    52                 $securitywhere=" AND files.roleid IN (".implode(",",$_SESSION["userinfo"]["roles"]).",0)"; 
    53         $whereclause="attachments.tabledefid=".$tabledefid." AND attachments.recordid=".$refid.$securitywhere; 
     50 
     51    $querystatement = " 
     52        SELECT 
     53            `uuid`, 
     54            `maintable` 
     55        FROM 
     56            `tabledefs` 
     57        WHERE 
     58            `id` = '".(int)$tabledefid."' 
     59        "; 
     60 
     61    $queryresult = $db->query($querystatement); 
     62    $therecord = $db->fetchArray($queryresult); 
     63    $tabledefuuid = $therecord["uuid"]; 
     64    $maintable = $therecord["maintable"]; 
     65 
     66    $querystatement = " 
     67        SELECT 
     68            `uuid` 
     69        FROM 
     70            `".$maintable."` 
     71        WHERE 
     72            `id` = '".$refid."' 
     73        "; 
     74 
     75    $queryresult = $db->query($querystatement); 
     76    $therecord = $db->fetchArray($queryresult); 
     77    $refuuid = $therecord["uuid"]; 
     78 
     79    $securitywhere=""; 
     80    if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){ 
     81        $securitywhere = "''"; 
     82        foreach($_SESSION["userinfo"]["roles"] as $roleuuid) 
     83            $securitywhere .= ",'".$roleuuid."'"; 
     84    }//end if 
     85 
     86    $whereclause="attachments.tabledefid='".$tabledefuuid."' AND attachments.recordid='".$refuuid."'".$securitywhere; 
    5487        $backurl="../bms/invoices_attachments.php"; 
    5588        $base="../../"; 
  • trunk/phpbms/modules/bms/products_attachments.php

    r546 r570  
    4848        if(isset($_GET["refid"])) $_GET["id"]=$_GET["refid"]; 
    4949        $refid=(integer) $_GET["id"]; 
    50         $securitywhere=""; 
    51         if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0) 
    52                 $securitywhere=" AND files.roleid IN (".implode(",",$_SESSION["userinfo"]["roles"]).",0)"; 
    53         $whereclause="attachments.tabledefid=".$tabledefid." AND attachments.recordid=".$refid.$securitywhere; 
     50    $querystatement = " 
     51        SELECT 
     52            `uuid`, 
     53            `maintable` 
     54        FROM 
     55            `tabledefs` 
     56        WHERE 
     57            `id` = '".(int)$tabledefid."' 
     58        "; 
     59 
     60    $queryresult = $db->query($querystatement); 
     61    $therecord = $db->fetchArray($queryresult); 
     62    $tabledefuuid = $therecord["uuid"]; 
     63    $maintable = $therecord["maintable"]; 
     64 
     65    $querystatement = " 
     66        SELECT 
     67            `uuid` 
     68        FROM 
     69            `".$maintable."` 
     70        WHERE 
     71            `id` = '".$refid."' 
     72        "; 
     73 
     74    $queryresult = $db->query($querystatement); 
     75    $therecord = $db->fetchArray($queryresult); 
     76    $refuuid = $therecord["uuid"]; 
     77 
     78    $securitywhere=""; 
     79    if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0){ 
     80        $securitywhere = "''"; 
     81        foreach($_SESSION["userinfo"]["roles"] as $roleuuid) 
     82            $securitywhere .= ",'".$roleuuid."'"; 
     83    }//end if 
     84 
     85    $whereclause="attachments.tabledefid='".$tabledefuuid."' AND attachments.recordid='".$refuuid."'".$securitywhere; 
    5486        $backurl="../bms/products_attachments.php"; 
    5587        $base="../../"; 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.