Newer
Older
<?php
error_reporting(E_ALL || E_STRICT);
require 'config.inc.php';
require 'frameworks/medoo.php';
require 'frameworks/commons.php';

Tim Repke
committed
require 'lang.php';
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$index_db = new medoo(array(
'database_type' => $config_db["type"],
'database_name' => $config_db["name"],
'server' => $config_db["host"],
'username' => $config_db["user"],
'password' => $config_db["pass"]
));
require 'view/default_index.php';
// ================================================================
// functions
/**
* main function
* gets called within the template
*/
function index_show_content(){
global $index_db;
// Zeige Details einer FS Fahrt
if(isset($_REQUEST['fid'])){
$fid = $_REQUEST['fid'];
// wenn die fahrt-id falsch, liste alle fahrten
if(!$index_db->has('fahrten',array('fahrt_id'=>$fid))){
comm_verbose(1,"FID nicht vorhanden!");
goto allefahrten;
}
// --- Fahrtinfos
index_show_fahrtHeader($fid);
// --- Formular
if(isset($_REQUEST['submit'])){ // Formular auswerten
comm_verbose(1,"Formular bekommen");

Tim Repke
committed
$data = index_check_form();
if(!is_null($data))
index_form_to_db($data);
} /*elseif(isset($_REQUEST['bid'])){ // Änderungsformular anzeigen, Anmeldung noch offen?

Tim Repke
committed
} */ else { // leeres Formular anzeigen
index_show_formular($fid);
}
// --- Liste der Anmeldungen
index_show_signupTable($fid);
}
// Zeige Übersicht aller Fahrten
else {
allefahrten:
index_show_alleFahrten();
}
}
function show_content(){
index_show_content();
}
/**
* puts the dataarray into DB
* adds version = 1 and generates a unique hash for entry
* @param $data
*/

Tim Repke
committed
function index_form_to_db($data){

Tim Repke
committed
global $index_db, $config_baseurl, $lang_regmail, $config_current_fahrt_id;

Tim Repke
committed
$data['version'] = 1;
$data['bachelor_id'] = comm_generate_key($index_db, "bachelor", "bachelor_id", array('fahrt_id'=>$data['fahrt_id']));
$data['anm_time'] = time();
$data['anday'] = DateTime::createFromFormat('d.m.Y',$data['anday'])->getTimestamp();
$data['abday'] = DateTime::createFromFormat('d.m.Y',$data['abday'])->getTimestamp();

Tim Repke
committed
$index_db->insert("bachelor", $data);

Tim Repke
committed
$from = $index_db->get("fahrten", array("kontakt","leiter"), array("fahrt_id"=>$config_current_fahrt_id));
$mail = comm_get_lang("lang_regmail", array( "{{url}}" => $config_baseurl."status.php?hash=".$data['bachelor_id'],
"{{organisator}}" => $from['leiter']));
comm_send_mail($index_db, $data['mehl'], $mail, $from['kontakt']);

Tim Repke
committed
}
/**
* validates the sent form
* on failure: repost form with prefilled data and errors
* on success: put data into DB and post success messagage
*
*/
function index_check_form(){
global $config_studitypen, $config_essen, $config_reisearten, $index_db, $invalidCharsRegEx;

Tim Repke
committed
$data = array();

Tim Repke
committed
$data['fahrt_id'] = $fid;
if(!comm_isopen_fid($index_db, $fid)){
$errors = array("Ungültige Fahrt!");
goto index_check_form_skip;
}
index_check_field('forname', $invalidCharsRegEx, $data, $errors, "Fehlerhafter oder fehlender Vorname!");
index_check_field('sirname', $invalidCharsRegEx, $data, $errors, "Fehlerhafter oder fehlender Nachname!");
index_check_field('pseudo', $invalidCharsRegEx, $data, $errors, "Fehlerhafter oder fehlender Anzeigename!");
index_check_field('mehl', 'mail', $data, $errors, "Fehlerhafte oder fehlende E-Mail-Adresse!");
index_check_field('anday', array_slice($possible_dates,0, -1), $data, $errors, 'Hilfe beim Ausfüllen: <a href="https://www.hu-berlin.de/studium/bewerbung/imma/exma">hier klicken!</a>');
index_check_field('antyp', $config_reisearten, $data, $errors, 'Trolle hier lang: <a href="https://www.hu-berlin.de/studium/bewerbung/imma/exma">hier klicken!</a>');
index_check_field('abday', array_slice($possible_dates,1), $data, $errors, 'Ruth hat mitgedacht: <a href="https://www.hu-berlin.de/studium/bewerbung/imma/exma">hier klicken!</a>');
index_check_field('abtyp', $config_reisearten, $data, $errors, 'Entwickler Bier geben und: <a href="https://www.hu-berlin.de/studium/bewerbung/imma/exma">hier klicken!</a>');
index_check_field('essen', $config_essen, $data, $errors, 'Hat das wirklich nicht gereicht??'); // ggf trollable machen mit /^[a-zA-Z]{2,50}$/
index_check_field('studityp', $config_studitypen, $data, $errors, 'Neue Chance, diesmal FS-Ini wählen!');
index_check_field('public', "public", $data, $errors, 'Trollololol');
index_check_field('virgin', array("Ja","Nein"), $data, $errors, 'Bitte Altersbereich wählen!');
index_check_field('comment', "comment", $data, $errors, 'Trollololol');

Tim Repke
committed
index_check_form_skip:
if(count($errors)>0){
index_show_errors($errors);
index_show_formular($fid, NULL, $data);

Tim Repke
committed
return NULL;

Tim Repke
committed
return $data;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
}
}
/**
* puts out a list of all errors
* @param $errors
*/
function index_show_errors($errors){
echo '<div class="message error"><ul>';
foreach($errors as $e){
echo '<li>'.$e.'</li>';
}
echo'</ul></div>';
}
/**
* checks for correctness of a given field ($index) by trying $check.
* pushes $errmess into $errarr, if $check fails
* pushes empty data on fail or correct data on success into $data
*
* check can be regex or array or special (public, mail, comment).
* if array, than check only succeeds if sent data is inside that array
*
* @param $index
* @param $check
* @param $datarr
* @param $errarr
* @param $errmess
*/
function index_check_field($index, $check, &$datarr, &$errarr, $errmess){
$pushdat = "";
comm_verbose(3,"checking ".$index);
if($check == "public"){
if(isset($_REQUEST[$index])) $datarr[$index] = 0;
else $datarr[$index] = 1;
} elseif(!isset($_REQUEST[$index])){
array_push($errarr, $errmess);
$datarr[$index] = "";
} else {
$tmp = trim($_REQUEST[$index]);
if(is_array($check)){
if(!in_array($tmp,$check)){
array_push($errarr, $errmess);
}
} else {
if($check == "mail"){
if (!filter_var($tmp, FILTER_VALIDATE_EMAIL)) {
array_push($errarr, $errmess);
}
} elseif($check == "comment"){
// do nothing? maybe some graphical joke, is somebody tries to drop DB
} elseif(!(preg_match($check, $tmp)==1)){
array_push($errarr, $errmess);
}
}
$datarr[$index] = $tmp;
}
}
/**
* Generates a registration form for a given event ($fid)
*
* @param $fid
* @param null $bid - if not null: prefill form with data from DB
* @param null $bachelor - if not null: prefill form with these data (take care, keys have to exist!)
*/
function index_show_formular($fid, $bid = NULL, $bachelor = NULL){
global $index_db, $config_studitypen, $config_essen, $config_reisearten, $invalidCharsRegEx;
if (!isset($_GET['noscript']))
echo '<noscript>';
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
$possible_dates = comm_get_possible_dates($fid);
if(is_null($bachelor))
$bachelor = array('forname' => "", 'sirname' => "", 'anday' => $possible_dates[0], 'abday' => $possible_dates[count($possible_dates)-1], 'antyp' => "", 'abtyp' => "", 'pseudo' => "", 'mehl' => "", 'essen' => "", 'public' => "", 'virgin' => "", 'studityp' => "", 'comment'=>"");
if(!is_null($bid)){
if($index_db->has('bachelor',array('bachelor_id' => $bid))){
$bachelor = $index_db->select('bachelor', array('forname','sirname','anday','abday','antyp','abtyp','pseudo','mehl','essen','public','virgin','studityp','comment'), array('bachelor_id'=>$bid));
$bachelor = $bachelor[0];
}
}
$fidd = is_null($bid) ? $fid : $fid."&bid=".$bid;
echo '<div id="stylized" class="myform">
<form id="form" name="form" method="post" action="index.php?fid='.$fidd.'">
<h1>Anmeldeformular</h1>
<p>Bitte hier verbindlich anmelden.</p>';
index_show_formular_helper_input("Vorname", "forname", $bachelor["forname"], "");
index_show_formular_helper_input("Nachname","sirname",$bachelor["sirname"],"");
index_show_formular_helper_input("Anzeigename","pseudo",$bachelor["pseudo"],"");
index_show_formular_helper_input("E-Mail-Adresse","mehl",$bachelor["mehl"],"regelmäßig lesen!");
index_show_formular_helper_sel("Du bist","studityp",$config_studitypen, $bachelor["studityp"],"");
index_show_formular_helper_sel("Alter 18+?","virgin",array("", "Nein", "Ja"), $bachelor["virgin"], "Bist du älter als 18 Jahre?");
index_show_formular_helper_sel("Essenswunsch","essen",$config_essen, $bachelor["essen"],"Info für den Koch.");
index_show_formular_helper_sel2("Anreise","anday", array_slice($possible_dates,0, -1), $bachelor["anday"]
,"antyp",$config_reisearten, $bachelor["antyp"],"");
index_show_formular_helper_sel2("Abreise","abday", array_slice($possible_dates,1), $bachelor["abday"]
,"abtyp",$config_reisearten,$bachelor["abtyp"],"");
$soft_prot = new soft_protect();
echo $soft_prot->add(array('forname', 'sirname', 'pseudo'), $invalidCharsRegEx)->write();
echo'
<label>Anmerkung</label>
<textarea id="comment" name ="comment" rows="3" cols="50">'.$bachelor["comment"].'</textarea>
<input type="checkbox" name="public" value="public" style="width:40px"><span style="float:left">Anmeldung verstecken</span>
<button type="submit" name="submit" id="submit" value="submit">Anmelden!</button>
<div class="spacer"></div>
</form>
</div>';
if (!isset($_GET['noscript']))
{
echo '</noscript>';
echo '<div style="margin:0 auto; position:relative; width:900px; height:500px; overflow:hidden"><div id="storybox"></div>';
echo '<div id="story_umleitung" style="position:absolute; left:0px; bottom:-70px; background:#f0f; cursor:pointer; background:url(view/graphics/story/umleitung.png); width:120px; height: 70px" onclick="story.next(true)"> </div></div>';
echo '<div style="text-align:center;font-weight:bold"><a style="float:none;margin:0 auto;" href="'.$_SERVER['REQUEST_URI'].'&noscript">Seite funktioniert nicht / zu bunt?</a></div>';
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
}
/**
* Puts out Label and Selection box
*
* @param $name
* @param $id
* @param $values
* @param $selected
* @param $subtext
*/
function index_show_formular_helper_sel($name, $id, $values, $selected, $subtext){
echo '<label>'.$name.'
<span class="small">'.$subtext.'</span>
</label>
<select name="'.$id.'" id="'.$id.'">';
foreach($values as $val){
echo '<option value="'.$val.'"';
if($val == $selected) echo ' selected';
echo'>'.$val.'</option>';
}
echo '</select>';
}
/**
* Puts out Label and two selection boxes side by side right below
*
* @param $name
* @param $id
* @param $values
* @param $selected
* @param $id2
* @param $values2
* @param $selected2
* @param $subtext
*/
function index_show_formular_helper_sel2($name, $id, $values, $selected, $id2, $values2, $selected2, $subtext){
echo '<label style="text-align:left">'.$name.'
<span class="small">'.$subtext.'</span>
</label><table><tr><td>
<select name="'.$id.'" id="'.$id.'" style="width:110px; text-align: center">';
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
foreach($values as $val){
echo '<option value="'.$val.'"';
if($val == $selected) echo ' selected';
echo'>'.$val.'</option>';
}
echo '</select></td><td><select name="'.$id2.'" id="'.$id2.'">';
foreach($values2 as $val){
echo '<option value="'.$val.'"';
if($val == $selected2) echo ' selected';
echo'>'.$val.'</option>';
}
echo '</select></td></tr></table>';
}
function index_show_formular_helper_input($name, $id, $value, $subtext){
echo '<label>'.$name.'
<span class="small">'.$subtext.'</span>
</label>
<input type="text" name="'.$id.'" id="'.$id.'" value="'.$value.'" />';
}
/**
* show list of all fahrten
*/
function index_show_alleFahrten(){
global $index_db;
comm_verbose(2,"Liste aller Fahrten (Jahr, Ziel, Zeitraum, Anz. Mitfahrer)");
$foos = $index_db->select("fahrten",array('fahrt_id','titel','ziel','von','bis','beschreibung','leiter','kontakt'));
foreach($foos as $foo){
index_show_fahrtHeader($foo);
}
}
/**
* @param $fahrt wenn array, dann Datenbankrow; wenn zahl, dann wird das selektiert
*/
function index_show_fahrtHeader($fahrt){
global $index_db;
if(!is_array($fahrt)){
// select fahrt by ID
$fahrt = $index_db->select('fahrten', array('fahrt_id','titel','ziel', 'von', 'bis', 'leiter', 'kontakt', 'beschreibung'), array('fahrt_id'=> $fahrt));
if(!$fahrt){ index_show_alleFahrten(); return;}
else $fahrt = $fahrt[0];
}
echo '<div class="fahrt"><a href="index.php?fid='.$fahrt['fahrt_id'].'">'.$fahrt['titel'].'</a>';
echo 'Ziel: <i>'.$fahrt['ziel'].'</i><br />';
echo 'Datum: <i>'.comm_format_date($fahrt['von'])." - ".comm_format_date($fahrt['bis']).'</i><br />';
echo "Ansprechpartner: <i>".$fahrt['leiter']." (".comm_convert_mail($fahrt['kontakt']).")</i>";
echo '<p>'.$fahrt['beschreibung'].'</p>
</div>';
}
/**
* show table of public registrations
*/
function index_show_signupTable($fid){
global $index_db, $config_studitypen;
$data = $index_db->select('bachelor',array("pseudo","antyp","abtyp","anday","abday","comment","studityp"),
'fahrt_id' => (int) $fid,
'public' => 1
)));
if(!$data) echo'<div class="signups">Noch keine (sichtbaren) Anmeldungen!</div>';
else {
echo '
<table class="signups">
<thead>
<tr>
<th>Kommentar</th>
</tr>
</thead>';
foreach($data as $d){
echo '<tr>
<!--td>'.$d["studityp"].'</td-->
<td>'.date('d.m.Y', $d["anday"]).'</td>
<td>'.date('d.m.Y', $d["abday"]).'</td>