removed '&' symbol behind passed variables as arguments
[brisk.git] / web / Obj / dbase_file.phh
1 <?php
2   /*
3    *  brisk - dbase_file.phh
4    *
5    *  Copyright (C) 2006-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 require_once("${G_base}Obj/dbase_base.phh");
26
27 define(BRISK_AUTH_CONF,   "brisk_auth.conf.pho");
28
29 class BriskDB {
30     var $item;
31     var $item_n;
32
33   
34     function BriskDB()
35     {
36         log_main("BriskDB create:start");
37
38         log_main("BriskDB create:end");
39     }
40
41     static function create()
42     {
43         $ret = new BriskDB();
44         
45         return ($ret);
46     }
47
48     function users_load() 
49     {
50         GLOBAL $DOCUMENT_ROOT;
51
52         if (file_exists("$DOCUMENT_ROOT/Etc/".BRISK_AUTH_CONF)) {
53             require("$DOCUMENT_ROOT/Etc/".BRISK_AUTH_CONF);
54         }
55         else {
56             $this->item = array( new LoginDBItem(1, "uno", md5("one"),   "pippo@pluto.com", USER_FLAG_TY_SUPER),
57                                  new LoginDBItem(2, "due", md5("two"),   "pippo@pluto.com", USER_FLAG_TY_NORM),
58                                  new LoginDBItem(3, "a_b", md5("abb"),   "pippo@pluto.com", USER_FLAG_TY_NORM),
59                                  new LoginDBItem(4, "tre", md5("three"), "pippo@pluto.com", USER_FLAG_TY_NORM) );
60         }
61         $this->item_n = count($this->item);
62     }
63
64     function count()
65     {
66         return ($this->item_n);
67     }
68
69     function login_exists($login)
70     {
71         log_main("login_exists: ".$login);
72     
73         /* check the existence of the nick in the BriskDB */
74         for ($i = 0 ; $i < $this->item_n ; $i++) {
75             if (strcasecmp($this->item[$i]->login, $login) == 0) {
76                 log_main("login[".$i."]: ".$this->item[$i]->login);
77                 return (TRUE);
78             }
79         }
80         return (FALSE);
81     }
82
83     function getlogin_byidx($idx)
84     {
85         if ($idx >= $this->item_n)
86             return FALSE;
87         return ($this->item[$idx]->login);
88     }
89
90     function getitem_bylogin($login, &$id)
91         {
92             log_main("login_exists: ".$login);
93     
94             /* check the existence of the nick in the BriskDB */
95             for ($i = 0 ; $i < $this->item_n ; $i++) {
96                 if (strcasecmp($this->item[$i]->login, $login) == 0) {
97                     log_main("login[".$i."]: ".$this->item[$i]->login);
98                     $ret = &$this->item[$i];
99                     $id = $i;
100                     return ($ret);
101                 }
102             }
103             $id = -1;
104             return (FALSE);
105         }
106
107     function getmail($login)
108     {
109         log_main("getmail");
110     
111         /* check the existence of the nick in the BriskDB */
112         for ($i = 0 ; $i < $this->item_n ; $i++) {
113             if (strcasecmp($this->item[$i]->login, $login) == 0) {
114                 log_main("login[".$i."]: ".$this->item[$i]->login);
115                 return ($this->item[$i]->email);
116             }
117         }
118         return (FALSE);
119     }
120
121     function gettype($login)
122     {
123         log_main("getmail");
124     
125         /* check the existence of the nick in the BriskDB */
126         for ($i = 0 ; $i < $this->item_n ; $i++) {
127             if (strcasecmp($this->item[$i]->login, $login) == 0) {
128                 log_main("login[".$i."]: ".$this->item[$i]->login);
129                 return ($this->item[$i]->type);
130             }
131         }
132         return (FALSE);
133     }
134
135     function login_verify($login, $pass)
136     {
137         $ret = FALSE;
138         
139         log_main("login_verify: ".$login);
140         
141         /* check the existence of the nick in the BriskDB */
142         for ($i = 0 ; $i < $this->item_n ; $i++) {
143             log_main("login_verify: LOOP");
144             if (strcasecmp($this->item[$i]->login, $login) == 0) {
145                 log_main("login[".$i."]: ".$this->item[$i]->login);
146                 
147                 /* if it exists check for a valid challenge */
148                 if (($a_sem = Challenges::lock_data(TRUE)) != FALSE) { 
149                     
150                     if (($chals = &Challenges::load_data()) != FALSE) {
151                         for ($e = 0 ; $e < $chals->item_n ; $e++) {
152                             
153                             log_main("challenge[".$i."]: ".$chals->item[$e]->login);
154                             if (strcmp($login, $chals->item[$e]->login) == 0) {
155                                 log_main("login_verify [".$pass."] with [".md5($chals->item[$e]->token.$this->item[$i]->pass)."]");
156                                 
157                                 if (strcmp($pass , md5($chals->item[$e]->token.$this->item[$i]->pass)) == 0) {
158                                     log_main("login_verify SUCCESS for ".$login);
159                                     
160                                     $chals->rem($login);
161                                     $ret = &$this->item[$i];
162                                     break;
163                                 }
164                             }
165                         } // end for ($e = 0 ...
166                     }
167                     
168                     if ($chals->ismod()) {
169                         Challenges::save_data($chals);
170                     }
171                     
172                     Challenges::unlock_data($a_sem);
173                 }
174                 break;
175             } //  if (strcasecmp($this->item[$i]->login, ...
176         }
177         
178         return ($ret);
179     }
180
181     function bin5_points_save($date, $table, $tidx, $action, $ucodes, $pts)
182     {
183         return TRUE;
184     }
185 } // End class BriskDB
186
187 ?>