| 55 | | |
| 56 | | |
| | 55 | |
| | 56 | |
| | 57 | /** |
| | 58 | * function getDefaults |
| | 59 | * |
| | 60 | * Retrieves default values for a single record |
| | 61 | * |
| | 62 | * Uses the field names to guess a default value. If it cannot find |
| | 63 | * one of the standard names it sets the default value based on the type |
| | 64 | * |
| | 65 | * @retrun array associative array with record defaults |
| | 66 | */ |
| | 67 | function getDefaults(){ |
| | 68 | |
| | 69 | $therecord = parent::getDefaults(); |
| | 70 | |
| | 71 | $therecord["apifileurl"] = ""; |
| | 72 | |
| | 73 | return $therecord; |
| | 74 | |
| | 75 | }//end function --getDefaults |
| | 76 | |
| | 77 | |
| | 78 | /** |
| | 79 | * function getRecord |
| | 80 | * |
| | 81 | * Retrieves a single record from the database |
| | 82 | * |
| | 83 | * @param integer|string $id the record id or uuid |
| | 84 | * @param bool $useUuid specifies whther the $id is a uuid (true) or not. Default is false |
| | 85 | * |
| | 86 | * @return array the record as an associative array |
| | 87 | */ |
| | 88 | function getRecord($id, $useUuid = false){ |
| | 89 | |
| | 90 | if($useUuid){ |
| | 91 | |
| | 92 | $id = mysql_real_escape_string($id); |
| | 93 | $whereclause = "`uuid` = '".$id."'"; |
| | 94 | |
| | 95 | } else { |
| | 96 | |
| | 97 | $id = (int) $id; |
| | 98 | $whereclause = "`id` = ".$id; |
| | 99 | |
| | 100 | }//endif |
| | 101 | |
| | 102 | $querystatement = " |
| | 103 | SELECT |
| | 104 | `id`, |
| | 105 | `uuid`, |
| | 106 | `name`, |
| | 107 | `description`, |
| | 108 | `type`, |
| | 109 | `createdby`, |
| | 110 | `creationdate`, |
| | 111 | `modifiedby`, |
| | 112 | `modifieddate`, |
| | 113 | `roleid`, |
| | 114 | '' AS `file`, |
| | 115 | `custom1`, |
| | 116 | `custom2`, |
| | 117 | `custom3`, |
| | 118 | `custom4`, |
| | 119 | `custom5`, |
| | 120 | `custom6`, |
| | 121 | `custom7`, |
| | 122 | `custom8` |
| | 123 | FROM |
| | 124 | `files` |
| | 125 | WHERE |
| | 126 | ".$whereclause; |
| | 127 | |
| | 128 | $queryresult = $this->db->query($querystatement); |
| | 129 | |
| | 130 | if($this->db->numRows($queryresult)){ |
| | 131 | $therecord = $this->db->fetchArray($queryresult); |
| | 132 | |
| | 133 | if(!empty($_SERVER["HTTPS"])) |
| | 134 | $protocol = "https://"; |
| | 135 | else |
| | 136 | $protocol = "http://"; |
| | 137 | |
| | 138 | |
| | 139 | if( ($_SERVER["SERVER_PORT"] == "443" && !empty($_SERVER["HTTPS"])) || ($_SERVER["SERVER_PORT"] == "80" && empty($_SERVER["HTTPS"])) ) |
| | 140 | $port = ""; |
| | 141 | else |
| | 142 | $port = ":".$_SERVER["SEVER_PORT"]; |
| | 143 | |
| | 144 | $therecord["apifileurl"] = $protocol.$_SERVER["SERVER_NAME"].$port.APP_PATH."modules/api/api_servefile.php?i=".(int)$therecord["id"]; |
| | 145 | }else |
| | 146 | $therecord = $this-> getDefaults(); |
| | 147 | |
| | 148 | return $therecord; |
| | 149 | |
| | 150 | }//end function --getRecord-- |
| | 151 | |
| | 152 | |