25c36d54f470a7bd4ef363928ff1e27267646e10
[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($supp_comp)
120     {
121         $this->supp_comp = $supp_comp;
122     }
123
124     function tos_vers_get()
125     {
126         return $this->tos_vers;
127     }
128     function tos_vers_set($tos_vers)
129     {
130         $this->tos_vers = $tos_vers;
131     }
132
133     function disa_reas_get()
134     {
135         return $this->disa_reas;
136     }
137     function disa_reas_set($disa_reas)
138     {
139         $this->disa_reas = $disa_reas;
140     }
141     function guar_code_get()
142     {
143         return $this->guar_code;
144     }
145
146     function match_cnt_get()
147     {
148         return $this->match_cnt;
149     }
150     function match_cnt_add($v)
151     {
152         return $this->match_cnt += $v;
153     }
154
155     function game_cnt_get()
156     {
157         return $this->game_cnt;
158     }
159     function game_cnt_add($v)
160     {
161         return $this->game_cnt += $v;
162     }
163 }
164
165 define('MAIL_TYP_CHECK', 1);
166
167 class MailDBItem {
168     var $code;
169     var $ucode;
170     var $type;
171     var $tstamp;
172     var $subj;
173     var $body_txt;
174     var $body_htm;
175     var $hash;
176
177     function MailDBItem($code, $ucode, $type, $tstamp, $subj, $body_txt, $body_htm, $hash=NULL)
178     {
179         $this->code = $code;
180         $this->ucode = $ucode;
181         $this->type = $type;
182         $this->tstamp = $tstamp;
183         $this->subj = $subj;
184         $this->body_txt = $body_txt;
185         $this->body_htm = $body_htm;
186         $this->hash = $hash;
187     }
188
189     static function MailDBItemFromRecord($rec)
190     {
191         $ret = new MailDBItem($rec->code, $rec->ucode, $rec->type, $rec->tstamp, $rec->subj,
192                               $rec->body_txt, $rec->body_htm, $rec->hash);
193
194         return ($ret);
195     }
196
197     function store($bdb)
198     {
199         return $bdb->mail_add_fromitem($this);
200     }
201 }
202
203 define('USERSNET_DEF_FRIEND', 2);
204 define('USERSNET_DEF_SKILL', 2);
205 define('USERSNET_DEF_TRUST', 2);
206
207 class UsersNetItem {
208     var $owner;
209     var $target;
210     var $friend;
211     var $skill;
212     var $trust;
213
214     var $from_db;
215
216     function UsersNetItem($owner, $target, $friend, $skill, $trust,
217                           $widefriend, $narrowfriend, $from_db)
218     {
219         $this->owner = $owner;
220         $this->target = $target;
221         $this->friend = $friend;
222         $this->skill = $skill;
223         $this->trust = $trust;
224         $this->widefriend = $widefriend;
225         $this->narrowfriend = $narrowfriend;
226
227         $this->from_db = $from_db;
228     }
229
230     static function UsersNetItemFromRecord($rec, $widefriend, $narrowfriend)
231     {
232         $ret = new UsersNetItem($rec->owner, $rec->target, $rec->friend,
233                                $rec->skill, $rec->trust,
234                                 $widefriend, $narrowfriend, TRUE);
235
236         return ($ret);
237     }
238
239     static function UsersNetItemDefaults($owner, $target, $widefriend, $narrowfriend)
240     {
241         $ret = new UsersNetItem($owner, $target, USERSNET_DEF_FRIEND,
242                                 USERSNET_DEF_SKILL, USERSNET_DEF_TRUST,
243                                 $widefriend, $narrowfriend, FALSE);
244
245         return ($ret);
246     }
247
248
249 }
250
251 ?>