full 'listen' prefs management completed and partial 'comps' prefs implemented
[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*6 + $e*2, 2), 16, 10);
114             }
115         }
116         return ($ret_arr);
117     }
118
119     function supp_comp_set_array($supp_comp_in)
120     {
121         $group_id = array("fg", "bg");
122         $comp_id = array("r", "g", "b");
123         $supp_comp = "";
124
125         for ($i = 0 ; $i < 2 ; $i++) {
126             for ($e = 0 ; $e < 3 ; $e++) {
127                 $supp_comp += sprintf("%02x", $supp_comp_in[$group_id[$i]][$comp_id[$e]]);
128             }
129         }
130         $this->supp_comp = $supp_comp;
131     }
132
133     function supp_comp_set($supp_comp)
134     {
135         $this->supp_comp = $supp_comp;
136     }
137
138     function tos_vers_get()
139     {
140         return $this->tos_vers;
141     }
142     function tos_vers_set($tos_vers)
143     {
144         $this->tos_vers = $tos_vers;
145     }
146
147     function disa_reas_get()
148     {
149         return $this->disa_reas;
150     }
151     function disa_reas_set($disa_reas)
152     {
153         $this->disa_reas = $disa_reas;
154     }
155     function guar_code_get()
156     {
157         return $this->guar_code;
158     }
159
160     function match_cnt_get()
161     {
162         return $this->match_cnt;
163     }
164     function match_cnt_add($v)
165     {
166         return $this->match_cnt += $v;
167     }
168
169     function game_cnt_get()
170     {
171         return $this->game_cnt;
172     }
173     function game_cnt_add($v)
174     {
175         return $this->game_cnt += $v;
176     }
177 }
178
179 define('MAIL_TYP_CHECK', 1);
180
181 class MailDBItem {
182     var $code;
183     var $ucode;
184     var $type;
185     var $tstamp;
186     var $subj;
187     var $body_txt;
188     var $body_htm;
189     var $hash;
190
191     function MailDBItem($code, $ucode, $type, $tstamp, $subj, $body_txt, $body_htm, $hash=NULL)
192     {
193         $this->code = $code;
194         $this->ucode = $ucode;
195         $this->type = $type;
196         $this->tstamp = $tstamp;
197         $this->subj = $subj;
198         $this->body_txt = $body_txt;
199         $this->body_htm = $body_htm;
200         $this->hash = $hash;
201     }
202
203     static function MailDBItemFromRecord($rec)
204     {
205         $ret = new MailDBItem($rec->code, $rec->ucode, $rec->type, $rec->tstamp, $rec->subj,
206                               $rec->body_txt, $rec->body_htm, $rec->hash);
207
208         return ($ret);
209     }
210
211     function store($bdb)
212     {
213         return $bdb->mail_add_fromitem($this);
214     }
215 }
216
217 define('USERSNET_DEF_FRIEND', 2);
218 define('USERSNET_DEF_SKILL', 2);
219 define('USERSNET_DEF_TRUST', 2);
220
221 class UsersNetItem {
222     var $owner;
223     var $target;
224     var $friend;
225     var $skill;
226     var $trust;
227
228     var $from_db;
229
230     function UsersNetItem($owner, $target, $friend, $skill, $trust,
231                           $widefriend, $narrowfriend, $from_db)
232     {
233         $this->owner = $owner;
234         $this->target = $target;
235         $this->friend = $friend;
236         $this->skill = $skill;
237         $this->trust = $trust;
238         $this->widefriend = $widefriend;
239         $this->narrowfriend = $narrowfriend;
240
241         $this->from_db = $from_db;
242     }
243
244     static function UsersNetItemFromRecord($rec, $widefriend, $narrowfriend)
245     {
246         $ret = new UsersNetItem($rec->owner, $rec->target, $rec->friend,
247                                $rec->skill, $rec->trust,
248                                 $widefriend, $narrowfriend, TRUE);
249
250         return ($ret);
251     }
252
253     static function UsersNetItemDefaults($owner, $target, $widefriend, $narrowfriend)
254     {
255         $ret = new UsersNetItem($owner, $target, USERSNET_DEF_FRIEND,
256                                 USERSNET_DEF_SKILL, USERSNET_DEF_TRUST,
257                                 $widefriend, $narrowfriend, FALSE);
258
259         return ($ret);
260     }
261
262
263 }
264
265 ?>