]> git.somenet.org - fsinf/pub/w2c.git/blob - funcs.php
changed table to be sortable AND searchable.
[fsinf/pub/w2c.git] / funcs.php
1 <?php
2
3 /**
4 * welcome.TU.code Anmeldesystem.
5 * by Jan Vales <jan@jvales.net> (aka. Someone <someone@somenet.org>)
6 */
7
8 require_once('./settings.php');
9 require_once('./db_funcs.php');
10 require_once('./html_funcs.php');
11
12 function login(){
13   if(!isset($_SERVER['HTTPS'])){
14     $url = 'https://'.$_SERVER["HTTP_HOST"].$_SERVER['REQUEST_URI'];
15     header('Location: '.$url, true, 301);
16     exit('<h1>Redirecting to: <a href="'.$url.'">'.$url.'</a></h1>');
17   }
18   $uinfo = db_get_uinfo($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
19   if($uinfo['lvl'] >= 1){
20     $GLOBALS['uname'] = $uinfo['uname'];
21     $GLOBALS['lvl'] = $uinfo['lvl'];
22   }else{
23     header('WWW-Authenticate: Basic realm="WelcomeTUcode login"');
24     header('HTTP/1.0 401 Unauthorized');
25     exit('Nicht eingeloggt. Falsche Anmeldedaten?');
26   }
27 }
28
29 function list_anmeldungen(){
30   $liste = db_list_anmeldungen();
31   $ret = '<table id="sortable"><thead><tr><th>Aktion</th><th>id</th><th>Anmeldung bei</th><th>Nachname(n)</th><th>Vorname(n)</th><th>Geboren</th>'.
32     '<th>Nationalität</th><th>Sprachkenntnis</th><th>Vorwissen</th><th>Analphabet</th><th>Foto-</th><th>Videoerlaubnis</th>'.
33         '<th>Status</th><th>Bemerkung</th><th>Termin</th></tr></thead><tbody>'."\n";
34   foreach ($liste as &$person) {
35     $ret .='<tr id="pers_'.$person['id'].'"><td><a href="./person.php?id='.$person['id'].'">Bearbeiten</a></td><td>'.$person['id'].'</td>';
36         $ret .='<td>'.$person['uname'].'</td><td>'.$person['nname'].'</td><td>'.$person['vname'].'</td><td><nobr>'.$person['gebdatum'].'</nobr></td>';
37         $ret .='<td>'.$person['nationaliaet'].'</td><td>'.$person['sprachen'].'</td><td>'.$person['vorwissen'].'</td><td>'.$person['analphabet'].'</td>';
38         $ret .='<td>'.$person['fotoerlaubnis'].'</td><td>'.$person['videoerlaubnis'].'</td><td>'.$person['status'].'</td><td>'.$person['bemerkungen'].'</td>';
39         $ret .='<td>'.$person['termin'].'</td></tr>'."\n";
40   }
41   return $ret.'</tbody></table>'."\n";
42 }
43
44 function store_person(){
45   if(!isset($_REQUEST['delete']) && !isset($_REQUEST['save']))return;
46
47 //var_export($_REQUEST);
48
49   if(isset($_REQUEST['delete']))return db_delete_person($_REQUEST['id']);
50   if(isset($_REQUEST['save'])){
51
52     if(!isset($_REQUEST['vname']))throw new Exception('NOT_SET vname');
53     $pdata['vname']=$_REQUEST['vname'];
54
55     if(!isset($_REQUEST['nname']))throw new Exception('NOT_SET nname');
56     $pdata['nname']=$_REQUEST['nname'];
57
58     if($pdata['vname'] == '' && $pdata['nname'] == '')throw new Exception('NO_NAME');
59
60     if(!isset($_REQUEST['gebdatum']))throw new Exception('NOT_SET gebdatum');
61     $pdata['gebdatum']=$_REQUEST['gebdatum'];
62         
63     if(!isset($_REQUEST['nationaliaet']))throw new Exception('NOT_SET nationalitaet');
64     $pdata['nationaliaet']=$_REQUEST['nationaliaet'];
65
66     if(!isset($_REQUEST['sprachen']))throw new Exception('NOT_SET sprachen');
67     $pdata['sprachen']=$_REQUEST['sprachen'];
68
69     if(!isset($_REQUEST['vorwissen']))throw new Exception('NOT_SET vorwissen');
70     $pdata['vorwissen']=$_REQUEST['vorwissen'];
71         
72     if(!isset($_REQUEST['analphabet']))$_REQUEST['analphabet'] = '0';
73     $pdata['analphabet']=$_REQUEST['analphabet'];
74
75     if(!isset($_REQUEST['fotoerlaubnis']))$_REQUEST['fotoerlaubnis'] = '0';
76     $pdata['fotoerlaubnis']=$_REQUEST['fotoerlaubnis'];
77
78     if(!isset($_REQUEST['videoerlaubnis']))$_REQUEST['videoerlaubnis'] = '0';
79     $pdata['videoerlaubnis']=$_REQUEST['videoerlaubnis'];
80
81     if(!isset($_REQUEST['bemerkungen']))throw new Exception('NOT_SET bemerkungen');
82     $pdata['bemerkungen']=$_REQUEST['bemerkungen'];
83
84     if(!isset($_REQUEST['termin']))throw new Exception('NOT_SET termin');
85     $pdata['termin']=$_REQUEST['termin'];
86
87     if(!isset($_REQUEST['status']))throw new Exception('NOT_SET status');
88     $pdata['status']=$_REQUEST['status'];
89
90     return db_store_person($_REQUEST['id'], $pdata);
91   }
92 }
93
94 function get_person($id){
95   if(!is_numeric($id)) return NULL;
96   return db_get_person($id);
97 }
98