4 * welcome.TU.code Anmeldesystem.
5 * by Jan Vales <jan@jvales.net> (aka. Someone <someone@somenet.org>)
8 require_once('./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 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen WHERE lower(uname)=lower(?)');
24 $prep->execute(array($GLOBALS['uname'],));
25 if($GLOBALS['lvl'] >= 2){
26 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen');
29 return $prep->fetchAll();
32 function db_get_person($id){
33 $prep = $GLOBALS['dbc']->prepare('SELECT * FROM anmeldungen WHERE id = ?');
34 $prep->execute(array($id,));
35 return $prep->fetch();
38 function db_delete_person($id){
39 if($GLOBALS['lvl'] >= 2){
40 $prep = $GLOBALS['dbc']->prepare('DELETE FROM anmeldungen WHERE id = ?');
41 $prep->execute(array($id,));
43 $prep = $GLOBALS['dbc']->prepare('DELETE FROM anmeldungen WHERE id = ? and lower(uname) = ?');
44 $prep->execute(array($id,$GLOBALS['uname']));
46 return $prep->rowCount();
49 function db_store_person($id, $pdata){
50 $p = db_get_person($id);
52 if($p !== FALSE && $p['id'] == $id){
53 // found, we do updating, if uname == uname.
54 if($p['uname'] == $GLOBALS['uname'] || $GLOBALS['lvl'] >= 2){
55 if($pdata['analphabet'] == '')$pdata['analphabet'] = 0;
56 if($pdata['fotoerlaubnis'] == '')$pdata['fotoerlaubnis'] = 0;
57 if($pdata['videoerlaubnis'] == '')$pdata['videoerlaubnis'] = 0;
58 if($pdata['vorwissen'] == '')$pdata['vorwissen'] = 0;
59 if($pdata['gebdatum'] == '')$pdata['gebdatum'] = '1900-01-01';
60 $prep = $GLOBALS['dbc']->prepare('UPDATE anmeldungen SET nname=?, vname=?, gebdatum=?, nationaliaet=?, sprachen=?, analphabet=?, bemerkungen=?, vorwissen=?, fotoerlaubnis=?, videoerlaubnis=? WHERE id=?');
61 $prep->execute(array($pdata['nname'], $pdata['vname'], $pdata['gebdatum'], $pdata['nationaliaet'], $pdata['sprachen'], $pdata['analphabet'], $pdata['bemerkungen'], $pdata['vorwissen'], $pdata['fotoerlaubnis'], $pdata['videoerlaubnis'], $p['id']));
62 return $prep->rowCount();
65 // inserting a new person.
66 if($pdata['analphabet'] == '')$pdata['analphabet'] = 0;
67 if($pdata['fotoerlaubnis'] == '')$pdata['fotoerlaubnis'] = 0;
68 if($pdata['videoerlaubnis'] == '')$pdata['videoerlaubnis'] = 0;
69 if($pdata['vorwissen'] == '')$pdata['vorwissen'] = 0;
70 if($pdata['gebdatum'] == '')$pdata['gebdatum'] = '1900-01-01';
71 $prep = $GLOBALS['dbc']->prepare('INSERT INTO anmeldungen(uname, nname, vname, gebdatum, nationaliaet, sprachen, analphabet, bemerkungen, vorwissen, fotoerlaubnis, videoerlaubnis) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) returning id;');
72 $prep->execute(array($GLOBALS['uname'], $pdata['nname'], $pdata['vname'], $pdata['gebdatum'], $pdata['nationaliaet'], $pdata['sprachen'], $pdata['analphabet'], $pdata['bemerkungen'], $pdata['vorwissen'], $pdata['fotoerlaubnis'], $pdata['videoerlaubnis']));
73 $r = $prep->fetchColumn();