| | 1155 | |
|---|
| | 1156 | class User { |
|---|
| | 1157 | var $usr_id = 0; |
|---|
| | 1158 | var $organisation_id = 0; |
|---|
| | 1159 | var $role_id = 0; |
|---|
| | 1160 | var $username = ''; |
|---|
| | 1161 | var $passwd = ''; |
|---|
| | 1162 | var $first_name = ''; |
|---|
| | 1163 | var $last_name = ''; |
|---|
| | 1164 | var $teleph = ''; |
|---|
| | 1165 | var $mobile = ''; |
|---|
| | 1166 | var $email = ''; |
|---|
| | 1167 | var $addr_1 = ''; |
|---|
| | 1168 | var $addr_2 = ''; |
|---|
| | 1169 | var $addr_3 = ''; |
|---|
| | 1170 | var $city = ''; |
|---|
| | 1171 | var $region = ''; |
|---|
| | 1172 | var $country = ''; |
|---|
| | 1173 | var $post_code = ''; |
|---|
| | 1174 | var $is_email_public = 0; |
|---|
| | 1175 | var $is_acct_active = 0; |
|---|
| | 1176 | var $security_questio = ''; |
|---|
| | 1177 | var $security_answer = ''; |
|---|
| | 1178 | var $date_created = '0000-00-00'; |
|---|
| | 1179 | var $created_by = 0; |
|---|
| | 1180 | var $last_updated = '0000-00-00'; |
|---|
| | 1181 | var $updated_by = ''; |
|---|
| | 1182 | |
|---|
| | 1183 | function User($id = false) { |
|---|
| | 1184 | $this->dbh = & SGL_DB::singleton(); |
|---|
| | 1185 | $c = &SGL_Config::singleton(); |
|---|
| | 1186 | $this->conf = $c->getAll(); |
|---|
| | 1187 | |
|---|
| | 1188 | if($id) { |
|---|
| | 1189 | $aDbobject = $this->dbh->getAssoc("SELECT * FROM {$this->conf['table']['user']} WHERE usr_id = $id"); |
|---|
| | 1190 | foreach (get_object_vars($aDbobject[$id]) as $prop => $val) { |
|---|
| | 1191 | $this->$prop = $val; |
|---|
| | 1192 | } |
|---|
| | 1193 | unset($dbobject); |
|---|
| | 1194 | } |
|---|
| | 1195 | } |
|---|
| | 1196 | |
|---|
| | 1197 | function setFrom($obj) { |
|---|
| | 1198 | foreach (get_object_vars($obj) as $prop => $val) { |
|---|
| | 1199 | $this->$prop = $val; |
|---|
| | 1200 | } |
|---|
| | 1201 | } |
|---|
| | 1202 | |
|---|
| | 1203 | function update() { |
|---|
| | 1204 | $ok = $this->dbh->query(" |
|---|
| | 1205 | UPDATE {$this->conf['table']['user']} |
|---|
| | 1206 | SET |
|---|
| | 1207 | organisation_id = $this->organisation_id, |
|---|
| | 1208 | role_id = $this->role_id, |
|---|
| | 1209 | username = '$this->username', |
|---|
| | 1210 | passwd = '$this->passwd', |
|---|
| | 1211 | first_name = '$this->first_name', |
|---|
| | 1212 | last_name = '$this->last_name', |
|---|
| | 1213 | telephone = '$this->teleph', |
|---|
| | 1214 | mobile = '$this->mobile', |
|---|
| | 1215 | email = '$this->email', |
|---|
| | 1216 | addr_1 = '$this->addr_1', |
|---|
| | 1217 | addr_2 = '$this->addr_2', |
|---|
| | 1218 | addr_3 = '$this->addr_3', |
|---|
| | 1219 | city = '$this->city', |
|---|
| | 1220 | region = '$this->region', |
|---|
| | 1221 | country = '$this->country', |
|---|
| | 1222 | post_code = '$this->post_code', |
|---|
| | 1223 | is_email_public = '$this->is_email_public', |
|---|
| | 1224 | is_acct_active = '$this->is_acct_active', |
|---|
| | 1225 | security_question= '$this->security_question', |
|---|
| | 1226 | security_answer = '$this->security_answer', |
|---|
| | 1227 | date_created = '$this->date_created', |
|---|
| | 1228 | created_by = '$this->created_by', |
|---|
| | 1229 | last_updated = '$this->last_updated', |
|---|
| | 1230 | updated_by = '$this->updated_by' |
|---|
| | 1231 | WHERE |
|---|
| | 1232 | usr_id = $this->usr_id |
|---|
| | 1233 | |
|---|
| | 1234 | "); |
|---|
| | 1235 | } |
|---|
| | 1236 | function insert() { |
|---|
| | 1237 | $ok = $this->dbh->query(" |
|---|
| | 1238 | INSERT INTO {$this->conf['table']['user']} |
|---|
| | 1239 | VALUES ( |
|---|
| | 1240 | $this->usr_id , |
|---|
| | 1241 | $this->organisation_id , |
|---|
| | 1242 | $this->role_id , |
|---|
| | 1243 | '$this->username , |
|---|
| | 1244 | '$this->passwd', |
|---|
| | 1245 | '$this->first_name', |
|---|
| | 1246 | '$this->last_name', |
|---|
| | 1247 | '$this->telephone', |
|---|
| | 1248 | '$this->mobile', |
|---|
| | 1249 | '$this->email', |
|---|
| | 1250 | '$this->addr_1', |
|---|
| | 1251 | '$this->addr_2', |
|---|
| | 1252 | '$this->addr_3', |
|---|
| | 1253 | '$this->city', |
|---|
| | 1254 | '$this->region', |
|---|
| | 1255 | '$this->country', |
|---|
| | 1256 | '$this->post_code', |
|---|
| | 1257 | '$this->is_email_public', |
|---|
| | 1258 | '$this->is_acct_active', |
|---|
| | 1259 | '$this->security_question', |
|---|
| | 1260 | '$this->security_answer', |
|---|
| | 1261 | '$this->date_created', |
|---|
| | 1262 | '$this->created_by', |
|---|
| | 1263 | '$this->last_updated', |
|---|
| | 1264 | '$this->updated_by' |
|---|
| | 1265 | |
|---|
| | 1266 | ); |
|---|
| | 1267 | "); |
|---|
| | 1268 | if(PEAR::isError($ok)) { |
|---|
| | 1269 | return false; |
|---|
| | 1270 | } else { |
|---|
| | 1271 | return true; |
|---|
| | 1272 | } |
|---|
| | 1273 | } |
|---|
| | 1274 | } |
|---|