d2cebbc49d80d784fc70b88208c0fdd6045abdce
[brisk.git] / web / Obj / dbase_base.phh
1 <?php
2   /*
3    *  brisk - dbase_base.phh
4    *
5    *  Copyright (C) 2011-2012 Matteo Nastasi
6    *                          mailto: nastasi@alternativeoutput.it
7    *                                  matteo.nastasi@milug.org
8    *                          web: http://www.alternativeoutput.it
9    *
10    * This program is free software; you can redistribute it and/or modify
11    * it under the terms of the GNU General Public License as published by
12    * the Free Software Foundation; either version 2 of the License, or
13    * (at your option) any later version.
14    *
15    * This program is distributed in the hope that it will be useful, but
16    * WITHOUT ANY WARRANTY; without even the implied warranty of
17    * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18    * General Public License for more details. You should have received a
19    * copy of the GNU General Public License along with this program; if
20    * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21    * Suite 330, Boston, MA 02111-1307, USA.
22    *
23    */
24
25
26 class LoginDBItem {
27     var $code;
28     var $login;
29     var $pass;
30     var $email;
31     var $type;
32     var $last_dona;
33     var $supp_comp;
34     var $tos_vers;
35     var $disa_reas;
36     var $guar_code;
37     var $match_cnt;
38     var $game_cnt;
39
40     function LoginDBItem($code, $login, $pass, $email, $type, $last_dona, $supp_comp, $tos_vers,
41                          $disa_reas, $guar_code, $match_cnt, $game_cnt)
42     {
43         $this->code      = $code;
44         $this->login     = $login;
45         $this->pass      = $pass;
46         $this->email     = $email;
47         $this->type      = $type;
48         $this->last_dona = $last_dona;
49         $this->supp_comp = $supp_comp;
50         $this->tos_vers  = $tos_vers;
51         $this->disa_reas = $disa_reas;
52         $this->guar_code = $guar_code;
53         $this->match_cnt = $match_cnt;
54         $this->game_cnt  = $game_cnt;
55     }
56
57     static function LoginDBItemFromRecord($rec)
58     {
59         $ret = new LoginDBItem($rec->code, $rec->login, $rec->pass,
60                                $rec->email, $rec->type, $rec->last_dona,
61                                $rec->supp_comp, $rec->tos_vers, $rec->disa_reas, $rec->guar_code,
62                                $rec->match_cnt, $rec->game_cnt);
63
64         return ($ret);
65     }
66
67     function code_get()
68     {
69         return $this->code;
70     }
71
72     function login_get()
73     {
74         return $this->login;
75     }
76
77     function pass_get()
78     {
79         return $this->pass;
80     }
81
82     function email_get()
83     {
84         return $this->email;
85     }
86
87     function type_get()
88     {
89         return $this->type;
90     }
91
92     function last_dona_get()
93     {
94         return $this->last_dona;
95     }
96
97     function supp_comp_get()
98     {
99         return $this->supp_comp;
100     }
101     function supp_comp_get_array()
102     {
103         $ret = array();
104         $group_id = array("fg", "bg");
105         $comp_id = array("r", "g", "b");
106         $ret_arr = array();
107         $supp_comp = $this->supp_comp;
108
109         for ($i = 0 ; $i < 2 ; $i++) {
110             $group_cur = $group_id[$i];
111             $ret_arr[$group_cur] = array();
112             for ($e = 0 ; $e < 3 ; $e++) {
113                 $ret_arr[$group_cur][$comp_id[$e]] = base_convert(substr($supp_comp, $i*3 + $e, 2), 16, 10);
114             }
115         }
116
117         return ($ret_arr);
118     }
119
120     function supp_comp_set($supp_comp)
121     {
122         $this->supp_comp = $supp_comp;
123     }
124
125     function tos_vers_get()
126     {
127         return $this->tos_vers;
128     }
129     function tos_vers_set($tos_vers)
130     {
131         $this->tos_vers = $tos_vers;
132     }
133
134     function disa_reas_get()
135     {
136         return $this->disa_reas;
137     }
138     function disa_reas_set($disa_reas)
139     {
140         $this->disa_reas = $disa_reas;
141     }
142     function guar_code_get()
143     {
144         return $this->guar_code;
145     }
146
147     function match_cnt_get()
148     {
149         return $this->match_cnt;
150     }
151     function match_cnt_add($v)
152     {
153         return $this->match_cnt += $v;
154     }
155
156     function game_cnt_get()
157     {
158         return $this->game_cnt;
159     }
160     function game_cnt_add($v)
161     {
162         return $this->game_cnt += $v;
163     }
164 }
165
166 define('MAIL_TYP_CHECK', 1);
167
168 class MailDBItem {
169     var $code;
170     var $ucode;
171     var $type;
172     var $tstamp;
173     var $subj;
174     var $body_txt;
175     var $body_htm;
176     var $hash;
177
178     function MailDBItem($code, $ucode, $type, $tstamp, $subj, $body_txt, $body_htm, $hash=NULL)
179     {
180         $this->code = $code;
181         $this->ucode = $ucode;
182         $this->type = $type;
183         $this->tstamp = $tstamp;
184         $this->subj = $subj;
185         $this->body_txt = $body_txt;
186         $this->body_htm = $body_htm;
187         $this->hash = $hash;
188     }
189
190     static function MailDBItemFromRecord($rec)
191     {
192         $ret = new MailDBItem($rec->code, $rec->ucode, $rec->type, $rec->tstamp, $rec->subj,
193                               $rec->body_txt, $rec->body_htm, $rec->hash);
194
195         return ($ret);
196     }
197
198     function store($bdb)
199     {
200         return $bdb->mail_add_fromitem($this);
201     }
202 }
203
204 define('USERSNET_DEF_FRIEND', 2);
205 define('USERSNET_DEF_SKILL', 2);
206 define('USERSNET_DEF_TRUST', 2);
207
208 class UsersNetItem {
209     var $owner;
210     var $target;
211     var $friend;
212     var $skill;
213     var $trust;
214
215     var $from_db;
216
217     function UsersNetItem($owner, $target, $friend, $skill, $trust,
218                           $widefriend, $narrowfriend, $from_db)
219     {
220         $this->owner = $owner;
221         $this->target = $target;
222         $this->friend = $friend;
223         $this->skill = $skill;
224         $this->trust = $trust;
225         $this->widefriend = $widefriend;
226         $this->narrowfriend = $narrowfriend;
227
228         $this->from_db = $from_db;
229     }
230
231     static function UsersNetItemFromRecord($rec, $widefriend, $narrowfriend)
232     {
233         $ret = new UsersNetItem($rec->owner, $rec->target, $rec->friend,
234                                $rec->skill, $rec->trust,
235                                 $widefriend, $narrowfriend, TRUE);
236
237         return ($ret);
238     }
239
240     static function UsersNetItemDefaults($owner, $target, $widefriend, $narrowfriend)
241     {
242         $ret = new UsersNetItem($owner, $target, USERSNET_DEF_FRIEND,
243                                 USERSNET_DEF_SKILL, USERSNET_DEF_TRUST,
244                                 $widefriend, $narrowfriend, FALSE);
245
246         return ($ret);
247     }
248
249
250 }
251
252 ?>