4 * welcome.TU.code Anmeldesystem.
5 * by Jan Vales <jan@jvales.net> (aka. Someone <someone@somenet.org>)
8 require_once(FUNCS_PATH.'/settings.php');
10 function db_get_uinfo($user, $pass){
12 $prep = $GLOBALS['dbc']->prepare('SELECT uname,lvl FROM users WHERE lower(uname)=lower(?) and pwd=encode(digest(?, \'sha512\'),\'hex\')');
13 $prep->execute(array($user, $pass));
14 $row = $prep->fetch();
15 if(isset($row['uname'])){
22 function db_list_anmeldungen(){
23 if($GLOBALS['lvl'] >= 2){
24 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen');
27 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen WHERE lower(uname)=lower(?)');
28 $prep->execute(array($GLOBALS['uname'],));
30 return $prep->fetchAll();
33 function db_get_person($id){
34 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen WHERE id = ?');
35 $prep->execute(array($id,));
36 $ret = $prep->fetch();
37 if($ret !== FALSE && $ret['uname'] != $GLOBALS['uname'] && $GLOBALS['lvl'] < 2) throw new Exception('PERMISSION_ERROR');
41 function db_delete_person($id){
42 if($GLOBALS['lvl'] >= 2){
43 $prep = $GLOBALS['dbc']->prepare('DELETE FROM anmeldungen WHERE id = ?');
44 $prep->execute(array($id,));
46 $prep = $GLOBALS['dbc']->prepare('DELETE FROM anmeldungen WHERE id = ? and lower(uname) = ?');
47 $prep->execute(array($id,$GLOBALS['uname']));
49 if($prep->rowCount() != 1)throw new Exception('NOTHING_DELETED');
52 function db_store_person($id, $pdata){
53 $p = db_get_person($id);
55 if($p !== FALSE && $p['id'] == $id){
56 // found, we do updating. We are permitted, as there was no exception rtrieving the personinfo.
57 if($pdata['analphabet'] == '')$pdata['analphabet'] = 0;
58 if($pdata['fotoerlaubnis'] == '')$pdata['fotoerlaubnis'] = 0;
59 if($pdata['videoerlaubnis'] == '')$pdata['videoerlaubnis'] = 0;
60 if($pdata['vorwissen'] == '')$pdata['vorwissen'] = 0;
61 if($pdata['gebdatum'] == '')$pdata['gebdatum'] = '1900-01-01';
62 $prep = $GLOBALS['dbc']->prepare('UPDATE anmeldungen SET nname=?, vname=?, gebdatum=?, nationaliaet=?, sprachen=?, analphabet=?, '.
63 'bemerkungen=?, vorwissen=?, fotoerlaubnis=?, videoerlaubnis=?, status=?,termin=? WHERE id=?');
64 $prep->execute(array($pdata['nname'], $pdata['vname'], $pdata['gebdatum'], $pdata['nationaliaet'], $pdata['sprachen'], $pdata['analphabet'],
65 $pdata['bemerkungen'], $pdata['vorwissen'], $pdata['fotoerlaubnis'], $pdata['videoerlaubnis'], $pdata['status'], $pdata['termin'], $p['id']));
66 if($prep->rowCount() != 1)throw new Exception('UPDATE_FAILED');
69 // inserting a new person.
70 if($pdata['analphabet'] == '')$pdata['analphabet'] = 0;
71 if($pdata['fotoerlaubnis'] == '')$pdata['fotoerlaubnis'] = 0;
72 if($pdata['videoerlaubnis'] == '')$pdata['videoerlaubnis'] = 0;
73 if($pdata['vorwissen'] == '')$pdata['vorwissen'] = 0;
74 if($pdata['gebdatum'] == '')$pdata['gebdatum'] = '1900-01-01';
75 $prep = $GLOBALS['dbc']->prepare('INSERT INTO anmeldungen(uname, nname, vname, gebdatum, nationaliaet, sprachen, analphabet, bemerkungen,
76 vorwissen, fotoerlaubnis, videoerlaubnis, status, termin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) returning id;');
77 $prep->execute(array($GLOBALS['uname'], $pdata['nname'], $pdata['vname'], $pdata['gebdatum'], $pdata['nationaliaet'], $pdata['sprachen'],
78 $pdata['analphabet'], $pdata['bemerkungen'], $pdata['vorwissen'], $pdata['fotoerlaubnis'], $pdata['videoerlaubnis'], $pdata['status'], $pdata['termin']));
79 return $prep->fetchColumn();