Umfragen
user.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * user.class.php
4  *
5  * Copyright 2013 Johannes ter Haak <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
33 interface iUser{
39  public function set_config($name,$value);
40 
46  public function check_config($name,$value);
47 
53  public function get_config($name);
54 
60  public function save_config($db);
61 
67  public function load_config($db,$user);
68 
69 
75  public function load_info($au,$user);
76 
82  public function load_info_ID($au,$user);
83 
84 }
85 
89 class user implements iUser{
90  private $config = array();
91 
92  private $ID;
93  private $fullName;
94  private $givenName;
95  private $surName;
96  private $name;
97  private $group;
98  private $groupName;
99  private $is_auth = false;
100 
101  public function set_config($name,$value){
102  if( ($name == "email") ){
103  $this->config["email"] = $value;
104  }
105  }
106 
107  public function check_config($name,$value){
108  if( ($name == "email") ){
109  if(filter_var($value, FILTER_VALIDATE_EMAIL)) {
110  return true;
111  }else{
112  return false;
113  }
114  }
115  }
116 
117  public function get_config($name){
118  if( $name == "email" ){
119  if( isset($this->config[$name]) ){
120  return $this->config[$name];
121  }else{
122  return "";
123  }
124  }
125  }
126 
130  public function __set($name,$value){
131  if( $name == "ID" ){
132  $this->ID = $value;
133  }else if($name == "fullName"){
134  $this->fullName = $value;
135  }else if($name == "givenName"){
136  $this->givenName = $value;
137  }else if($name == "surName"){
138  $this->surName = $value;
139  }else if($name == "name"){
140  $this->name = $value;
141  }else if($name == "group"){
142  $this->group = $value;
143  }else if($name == "groupName"){
144  $this->groupName = $value;
145  }else if($name == "is_auth"){
146  if( $value === true ){
147  $this->is_auth = $value;
148  }else{
149  $this->is_auth = false;
150  }
151  }
152  }
153 
157  public function __get($name){
158  if( $name == "ID" ){
159  return $this->ID;
160  }else if($name == "fullName"){
161  return $this->fullName;
162  }else if($name == "givenName"){
163  return $this->givenName;
164  }else if($name == "surName"){
165  return $this->surName;
166  }else if($name == "name"){
167  return $this->name;
168  }else if($name == "group"){
169  return $this->group;
170  }else if($name == "groupName"){
171  return $this->groupName;
172  }else if($name == "is_auth"){
173  return $this->is_auth;
174  }
175  }
176 
177  public function __isset($name){
178  if( $name == "ID" ){
179  return isset($this->ID) AND ($this->ID != "");
180  }else if( $name == "fullName" ){
181  return isset($this->fullName) AND ($this->fullName != "");
182  }else if( $name == "givenName" ){
183  return isset($this->givenName) AND ($this->givenName != "");
184  }else if( $name == "surName" ){
185  return isset($this->surName) AND ($this->surName != "");
186  }else if( $name == "name" ){
187  return isset($this->name) AND ($this->name != "");
188  }else if( $name == "group" ){
189  return isset($this->group) AND ($this->group != "");
190  }else if( $name == "groupName" ){
191  return isset($this->groupName) AND ($this->groupName != "");
192  }else if( $name == "is_auth" ){
193  return isset($this->is_auth);
194  }
195  }
196 
197  public function save_config($db){
198  $data = array();
199  foreach( array_keys($this->config) as $key ){
200  if($key !== "email" ){
201  $data[$key] = $this->config[$key];
202  }
203  }
204  $r = $db->update_user_config_field($this->name,"config",serialize($data) );
205  $r2 = $db->update_user_config_field($this->name,"email",$this->config["email"] );
206  return ($r AND $r2);
207  }
208 
209  public function load_config($db,$user){
210  $data = $db->load_user_config_field($user,"*");
211  $config = unserialize($data["config"]);
212  if( is_array($config) ){
213  foreach( array_keys($config) as $key ){
214  $this->config[$key] = $config[$key];
215  }
216  }
217  $this->config["email"] = $data["email"];
218  $this->name = $user;
219  }
220 
221  public function load_info($au,$user){
222  $data = $au->info($user);
223  $this->ID = $data["userID"];
224  $this->group = $data["groupID"];
225  $this->fullName = $data["fullName"];
226  $this->name = $data["userName"];
227  }
228 
229  public function load_info_ID($au,$user){
230  $data = $au->info_ID($user);
231  $this->ID = $data["userID"];
232  $this->group = $data["groupID"];
233  $this->fullName = $data["fullName"];
234  $this->name = $data["userName"];
235  }
236 
237 }
238 
239 class LDAPuser extends user{
240  private $projects;
241 }
242 
243 class MYSQLuser extends user{
244 
245 }
246 
247 // ! no ending newLine
248 ?>