author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /backend/php/src/objects/class.onetimepassword.php | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'backend/php/src/objects/class.onetimepassword.php') (more/less context) (show whitespace changes)
-rw-r--r-- | backend/php/src/objects/class.onetimepassword.php | 400 |
1 files changed, 400 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.onetimepassword.php b/backend/php/src/objects/class.onetimepassword.php new file mode 100644 index 0000000..90d5f1d --- a/dev/null +++ b/backend/php/src/objects/class.onetimepassword.php | |||
@@ -0,0 +1,400 @@ | |||
1 | <?php | ||
2 | /* | ||
3 | This SQL query will create the table to store your object. | ||
4 | |||
5 | CREATE TABLE `onetimepassword` ( | ||
6 | `onetimepasswordid` int(11) NOT NULL auto_increment, | ||
7 | `userid` int(11) NOT NULL, | ||
8 | `onetimepasswordstatusid` int(11) NOT NULL, | ||
9 | `reference` VARCHAR(255) NOT NULL, | ||
10 | `key` VARCHAR(255) NOT NULL, | ||
11 | `key_checksum` VARCHAR(255) NOT NULL, | ||
12 | `data` TEXT NOT NULL, | ||
13 | `version` VARCHAR(255) NOT NULL, | ||
14 | `creation_date` TIMESTAMP NOT NULL, | ||
15 | `request_date` TIMESTAMP NOT NULL, | ||
16 | `usage_date` TIMESTAMP NOT NULL, INDEX(`userid`,`onetimepasswordstatusid`), PRIMARY KEY (`onetimepasswordid`)) ENGINE=MyISAM; | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * <b>onetimepassword</b> class with integrated CRUD methods. | ||
21 | * @author Php Object Generator | ||
22 | * @version POG 3.0d / PHP5.1 | ||
23 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
24 | * @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pog&objectName=onetimepassword&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27onetimepasswordstatus%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27key%27%2C%0A++4+%3D%3E+%27key_checksum%27%2C%0A++5+%3D%3E+%27data%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27creation_date%27%2C%0A++8+%3D%3E+%27request_date%27%2C%0A++9+%3D%3E+%27usage_date%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27BELONGSTO%27%2C%0A++1+%3D%3E+%27BELONGSTO%27%2C%0A++2+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++3+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++4+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++5+%3D%3E+%27TEXT%27%2C%0A++6+%3D%3E+%27VARCHAR%28255%29%27%2C%0A++7+%3D%3E+%27TIMESTAMP%27%2C%0A++8+%3D%3E+%27TIMESTAMP%27%2C%0A++9+%3D%3E+%27TIMESTAMP%27%2C%0A%29 | ||
25 | */ | ||
26 | include_once('class.pog_base.php'); | ||
27 | class onetimepassword extends POG_Base | ||
28 | { | ||
29 | public $onetimepasswordId = ''; | ||
30 | |||
31 | /** | ||
32 | * @var INT(11) | ||
33 | */ | ||
34 | public $userId; | ||
35 | |||
36 | /** | ||
37 | * @var INT(11) | ||
38 | */ | ||
39 | public $onetimepasswordstatusId; | ||
40 | |||
41 | /** | ||
42 | * @var VARCHAR(255) | ||
43 | */ | ||
44 | public $reference; | ||
45 | |||
46 | /** | ||
47 | * @var VARCHAR(255) | ||
48 | */ | ||
49 | public $key; | ||
50 | |||
51 | /** | ||
52 | * @var VARCHAR(255) | ||
53 | */ | ||
54 | public $key_checksum; | ||
55 | |||
56 | /** | ||
57 | * @var TEXT | ||
58 | */ | ||
59 | public $data; | ||
60 | |||
61 | /** | ||
62 | * @var VARCHAR(255) | ||
63 | */ | ||
64 | public $version; | ||
65 | |||
66 | /** | ||
67 | * @var TIMESTAMP | ||
68 | */ | ||
69 | public $creation_date; | ||
70 | |||
71 | /** | ||
72 | * @var TIMESTAMP | ||
73 | */ | ||
74 | public $request_date; | ||
75 | |||
76 | /** | ||
77 | * @var TIMESTAMP | ||
78 | */ | ||
79 | public $usage_date; | ||
80 | |||
81 | public $pog_attribute_type = array( | ||
82 | "onetimepasswordId" => array('db_attributes' => array("NUMERIC", "INT")), | ||
83 | "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
84 | "onetimepasswordstatus" => array('db_attributes' => array("OBJECT", "BELONGSTO")), | ||
85 | "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
86 | "key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
87 | "key_checksum" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
88 | "data" => array('db_attributes' => array("TEXT", "TEXT")), | ||
89 | "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")), | ||
90 | "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
91 | "request_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
92 | "usage_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")), | ||
93 | ); | ||
94 | public $pog_query; | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Getter for some private attributes | ||
99 | * @return mixed $attribute | ||
100 | */ | ||
101 | public function __get($attribute) | ||
102 | { | ||
103 | if (isset($this->{"_".$attribute})) | ||
104 | { | ||
105 | return $this->{"_".$attribute}; | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | return false; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | function onetimepassword($reference='', $key='', $key_checksum='', $data='', $version='', $creation_date='', $request_date='', $usage_date='') | ||
114 | { | ||
115 | $this->reference = $reference; | ||
116 | $this->key = $key; | ||
117 | $this->key_checksum = $key_checksum; | ||
118 | $this->data = $data; | ||
119 | $this->version = $version; | ||
120 | $this->creation_date = $creation_date; | ||
121 | $this->request_date = $request_date; | ||
122 | $this->usage_date = $usage_date; | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Gets object from database | ||
128 | * @param integer $onetimepasswordId | ||
129 | * @return object $onetimepassword | ||
130 | */ | ||
131 | function Get($onetimepasswordId) | ||
132 | { | ||
133 | $connection = Database::Connect(); | ||
134 | $this->pog_query = "select * from `onetimepassword` where `onetimepasswordid`='".intval($onetimepasswordId)."' LIMIT 1"; | ||
135 | $cursor = Database::Reader($this->pog_query, $connection); | ||
136 | while ($row = Database::Read($cursor)) | ||
137 | { | ||
138 | $this->onetimepasswordId = $row['onetimepasswordid']; | ||
139 | $this->userId = $row['userid']; | ||
140 | $this->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
141 | $this->reference = $this->Unescape($row['reference']); | ||
142 | $this->key = $this->Unescape($row['key']); | ||
143 | $this->key_checksum = $this->Unescape($row['key_checksum']); | ||
144 | $this->data = $this->Unescape($row['data']); | ||
145 | $this->version = $this->Unescape($row['version']); | ||
146 | $this->creation_date = $row['creation_date']; | ||
147 | $this->request_date = $row['request_date']; | ||
148 | $this->usage_date = $row['usage_date']; | ||
149 | } | ||
150 | return $this; | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Returns a sorted array of objects that match given conditions | ||
156 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
157 | * @param string $sortBy | ||
158 | * @param boolean $ascending | ||
159 | * @param int limit | ||
160 | * @return array $onetimepasswordList | ||
161 | */ | ||
162 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | ||
163 | { | ||
164 | $connection = Database::Connect(); | ||
165 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | ||
166 | $this->pog_query = "select * from `onetimepassword` "; | ||
167 | $onetimepasswordList = Array(); | ||
168 | if (sizeof($fcv_array) > 0) | ||
169 | { | ||
170 | $this->pog_query .= " where "; | ||
171 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
172 | { | ||
173 | if (sizeof($fcv_array[$i]) == 1) | ||
174 | { | ||
175 | $this->pog_query .= " ".$fcv_array[$i][0]." "; | ||
176 | continue; | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | if ($i > 0 && sizeof($fcv_array[$i-1]) != 1) | ||
181 | { | ||
182 | $this->pog_query .= " AND "; | ||
183 | } | ||
184 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
185 | { | ||
186 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
187 | { | ||
188 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'"; | ||
189 | $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'"; | ||
194 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'"; | ||
200 | $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | if ($sortBy != '') | ||
206 | { | ||
207 | if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET') | ||
208 | { | ||
209 | if ($GLOBALS['configuration']['db_encoding'] == 1) | ||
210 | { | ||
211 | $sortBy = "BASE64_DECODE($sortBy) "; | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | $sortBy = "$sortBy "; | ||
216 | } | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | $sortBy = "$sortBy "; | ||
221 | } | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | $sortBy = "onetimepasswordid"; | ||
226 | } | ||
227 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | ||
228 | $thisObjectName = get_class($this); | ||
229 | $cursor = Database::Reader($this->pog_query, $connection); | ||
230 | while ($row = Database::Read($cursor)) | ||
231 | { | ||
232 | $onetimepassword = new $thisObjectName(); | ||
233 | $onetimepassword->onetimepasswordId = $row['onetimepasswordid']; | ||
234 | $onetimepassword->userId = $row['userid']; | ||
235 | $onetimepassword->onetimepasswordstatusId = $row['onetimepasswordstatusid']; | ||
236 | $onetimepassword->reference = $this->Unescape($row['reference']); | ||
237 | $onetimepassword->key = $this->Unescape($row['key']); | ||
238 | $onetimepassword->key_checksum = $this->Unescape($row['key_checksum']); | ||
239 | $onetimepassword->data = $this->Unescape($row['data']); | ||
240 | $onetimepassword->version = $this->Unescape($row['version']); | ||
241 | $onetimepassword->creation_date = $row['creation_date']; | ||
242 | $onetimepassword->request_date = $row['request_date']; | ||
243 | $onetimepassword->usage_date = $row['usage_date']; | ||
244 | $onetimepasswordList[] = $onetimepassword; | ||
245 | } | ||
246 | return $onetimepasswordList; | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Saves the object to the database | ||
252 | * @return integer $onetimepasswordId | ||
253 | */ | ||
254 | function Save() | ||
255 | { | ||
256 | $connection = Database::Connect(); | ||
257 | $this->pog_query = "select `onetimepasswordid` from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."' LIMIT 1"; | ||
258 | $rows = Database::Query($this->pog_query, $connection); | ||
259 | if ($rows > 0) | ||
260 | { | ||
261 | $this->pog_query = "update `onetimepassword` set | ||
262 | `userid`='".$this->userId."', | ||
263 | `onetimepasswordstatusid`='".$this->onetimepasswordstatusId."', | ||
264 | `reference`='".$this->Escape($this->reference)."', | ||
265 | `key`='".$this->Escape($this->key)."', | ||
266 | `key_checksum`='".$this->Escape($this->key_checksum)."', | ||
267 | `data`='".$this->Escape($this->data)."', | ||
268 | `version`='".$this->Escape($this->version)."', | ||
269 | `creation_date`='".$this->creation_date."', | ||
270 | `request_date`='".$this->request_date."', | ||
271 | `usage_date`='".$this->usage_date."' where `onetimepasswordid`='".$this->onetimepasswordId."'"; | ||
272 | } | ||
273 | else | ||
274 | { | ||
275 | $this->pog_query = "insert into `onetimepassword` (`userid`, `onetimepasswordstatusid`, `reference`, `key`, `key_checksum`, `data`, `version`, `creation_date`, `request_date`, `usage_date` ) values ( | ||
276 | '".$this->userId."', | ||
277 | '".$this->onetimepasswordstatusId."', | ||
278 | '".$this->Escape($this->reference)."', | ||
279 | '".$this->Escape($this->key)."', | ||
280 | '".$this->Escape($this->key_checksum)."', | ||
281 | '".$this->Escape($this->data)."', | ||
282 | '".$this->Escape($this->version)."', | ||
283 | '".$this->creation_date."', | ||
284 | '".$this->request_date."', | ||
285 | '".$this->usage_date."' )"; | ||
286 | } | ||
287 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | ||
288 | if ($this->onetimepasswordId == "") | ||
289 | { | ||
290 | $this->onetimepasswordId = $insertId; | ||
291 | } | ||
292 | return $this->onetimepasswordId; | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Clones the object and saves it to the database | ||
298 | * @return integer $onetimepasswordId | ||
299 | */ | ||
300 | function SaveNew() | ||
301 | { | ||
302 | $this->onetimepasswordId = ''; | ||
303 | return $this->Save(); | ||
304 | } | ||
305 | |||
306 | |||
307 | /** | ||
308 | * Deletes the object from the database | ||
309 | * @return boolean | ||
310 | */ | ||
311 | function Delete() | ||
312 | { | ||
313 | $connection = Database::Connect(); | ||
314 | $this->pog_query = "delete from `onetimepassword` where `onetimepasswordid`='".$this->onetimepasswordId."'"; | ||
315 | return Database::NonQuery($this->pog_query, $connection); | ||
316 | } | ||
317 | |||
318 | |||
319 | /** | ||
320 | * Deletes a list of objects that match given conditions | ||
321 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | ||
322 | * @param bool $deep | ||
323 | * @return | ||
324 | */ | ||
325 | function DeleteList($fcv_array) | ||
326 | { | ||
327 | if (sizeof($fcv_array) > 0) | ||
328 | { | ||
329 | $connection = Database::Connect(); | ||
330 | $pog_query = "delete from `onetimepassword` where "; | ||
331 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | ||
332 | { | ||
333 | if (sizeof($fcv_array[$i]) == 1) | ||
334 | { | ||
335 | $pog_query .= " ".$fcv_array[$i][0]." "; | ||
336 | continue; | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1) | ||
341 | { | ||
342 | $pog_query .= " AND "; | ||
343 | } | ||
344 | if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET') | ||
345 | { | ||
346 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'"; | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'"; | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | return Database::NonQuery($pog_query, $connection); | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Associates the user object to this one | ||
361 | * @return boolean | ||
362 | */ | ||
363 | function GetUser() | ||
364 | { | ||
365 | $user = new user(); | ||
366 | return $user->Get($this->userId); | ||
367 | } | ||
368 | |||
369 | |||
370 | /** | ||
371 | * Associates the user object to this one | ||
372 | * @return | ||
373 | */ | ||
374 | function SetUser(&$user) | ||
375 | { | ||
376 | $this->userId = $user->userId; | ||
377 | } | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Associates the onetimepasswordstatus object to this one | ||
382 | * @return boolean | ||
383 | */ | ||
384 | function GetOnetimepasswordstatus() | ||
385 | { | ||
386 | $onetimepasswordstatus = new onetimepasswordstatus(); | ||
387 | return $onetimepasswordstatus->Get($this->onetimepasswordstatusId); | ||
388 | } | ||
389 | |||
390 | |||
391 | /** | ||
392 | * Associates the onetimepasswordstatus object to this one | ||
393 | * @return | ||
394 | */ | ||
395 | function SetOnetimepasswordstatus(&$onetimepasswordstatus) | ||
396 | { | ||
397 | $this->onetimepasswordstatusId = $onetimepasswordstatus->onetimepasswordstatusId; | ||
398 | } | ||
399 | } | ||
400 | ?> \ No newline at end of file | ||