<?php
### Copyright by [BU*M]BöhserOnkel
### Support www.baduncles.de
defined ('main') or die ( 'no direct access' );
require_once ('include/includes/func/trains.php');
del_train_user();
switch($menu->get(1)) {
case 'anmelden' :
$aktime = '';
$deluser = '';
$maske = '';
$deltime = '';
if(isset($_POST['type']) AND escape($_POST['type'], 'string') != ''){
$_SESSION['trainan_type'] = escape($_POST['type'], 'string');
}elseif( ( !is_numeric($menu->get(3)) OR $menu->get(2) != 'delet') AND $menu->get(3) != ''){
$_SESSION['trainan_type'] = $menu->get(3);
}
if(escape($menu->get(2), 'string') != 'delet' AND escape($menu->get(2), 'string') != ''){
$aktime = escape($menu->get(2), 'string');
}else{
$aktime = @db_result(db_query('SELECT date FROM prefix_traindates WHERE date > "'.time().'" AND type = "'.$_SESSION['trainan_type'].'" ORDER by date'),0);
}
if(escape($menu->get(2), 'string') == 'delet'){
$maske = escape($menu->get(2), 'string');
if(escape($menu->get(3), 'string') > '0'){
$deluser = escape($menu->get(3), 'string');
}
if(escape($menu->get(4), 'string') > '0'){
$deltime = escape($menu->get(4), 'string');
}
}
$anzeigen = db_fetch_assoc(db_query("SELECT date,prefix_groups.name as squad_name,squad,txt,type FROM `prefix_traindates` LEFT JOIN prefix_groups on prefix_traindates.squad = prefix_groups.id WHERE date >= '".$aktime."' AND type = '".$_SESSION['trainan_type']."' ORDER by date LIMIT 1"));
if(strlen($anzeigen['type']) < 2){
$anzeigen['type'] = @db_result(db_query("SElECT name FROM prefix_groups WHERE id = '".$anzeigen['type']."'"));
}
if($anzeigen['date'] != ''){$anztime = $anzeigen['date'];
$anzeigen['date'] = date("d.m.Y - H:i",$anzeigen['date']).' Uhr';
}
if($anzeigen['squad'] == 'alle'){
$anzeigen['squad_name'] = 'Alle';
}
if($anzeigen['squad'] == 'alle'){
$xsquad = 'alle';
}else{
$xsquad = $anzeigen['squad'];
}
if($_SESSION['authright'] == '-9'){
if($maske != ''){$row['ansicht1'] = $maske;}else{$row['ansicht1'] = 'normal';}
$ansichtsoption = 'Ansichtsoption <select id="ansicht" name="ansicht" onChange=ansicht();if(this.value=="delet"){location.href="index.php?trains-anmelden-delet-1";}else{location.href="index.php?trains-anmelden";}>'.arlistee($row['ansicht1'],array('normal'=>'AnmeldeMaske','delet'=>'LöschMaske',)).'</select><br><br>';
$usere = '<select name="user">'.dblistee($row['user'], "SELECT id,name FROM `prefix_user` WHERE recht <= '-3'").'</select>';
$squadc = "SELECT id,name FROM `prefix_groups` ORDER by id";
$alttrain = @db_result(db_query('SELECT COUNT(id) FROM prefix_traindates WHERE date < "'.time().'" AND type = "'.$_SESSION['trainan_type'].'"'),0);
$limit = $alttrain+5;
$time = "SELECT DISTINCT date,date FROM `prefix_traindates` WHERE type = '".$_SESSION['trainan_type']."' ORDER by date ASC LIMIT $limit";
}else{
$ansichtsoption = '<input type="hidden" onChange="sichtbar()" id="ansicht" name="ansicht" value="normal">';
$usere = '<input type="hidden" value="'.$_SESSION['authid'].'" name="user">'.$_SESSION['authname'];
$squadc = "SELECT gid,prefix_groups.name FROM `prefix_groupusers` LEFT JOIN `prefix_groups` on prefix_groupusers.gid = prefix_groups.id WHERE uid = '".$_SESSION['authid']."'";
$time = 'SELECT DISTINCT date,date FROM `prefix_traindates` WHERE date > "'.time().'" AND type = "'.$_SESSION['trainan_type'].'" ORDER by date ASC LIMIT 5';
}
$row = array();
if($aktime != ''){$row['aktime'] = $aktime;}
$row['ansichtsoption'] = $ansichtsoption;
$row['sub3'] = '<button value="Eintragen" type="submit" name="sub3">Eintragen/Ändern</button>';
$row['user'] = $usere;
$row['squad'] = dblistee($row['squad'], $squadc);
$row['date'] = datelistee($row['aktime'],$time);
$row['teilnahme'] = teilnahmear ();
$row['xsquad'] = $xsquad;
$row['txtanz'] = ($anzeigen['txt'] == '' ? 'Keine Informationen vorhanden' : $anzeigen['txt'] );
$row['squadanz'] = $anzeigen['squad_name'];
$row['dateanz'] = $anzeigen['date'];
$row['gegneranz'] = $anzeigen['type'];
$datedel1 = db_fetch_assoc(db_query('SELECT DISTINCT date FROM `prefix_trainuser` WHERE user = "'.$deluser.'" AND type = "'.$_SESSION['trainan_type'].'" ORDER by date ASC LIMIT 1'));
if($deltime == ''){$deltime = $datedel1['date'];}
$teildel = db_fetch_assoc(db_query('SELECT prefix_groups.name as squadname,teilnahme FROM `prefix_trainuser` LEFT JOIN `prefix_groups` on prefix_trainuser.squad = prefix_groups.id WHERE user = "'.$deluser.'" AND type = "'.$_SESSION['trainan_type'].'" AND date = "'.$deltime.'"'));
if($_SESSION['authright'] == '-9'){
$row['datedel'] = datelistee($deltime, "SELECT DISTINCT date,date FROM `prefix_trainuser` WHERE user = '".$deluser."' AND type = '".$_SESSION['trainan_type']."' ORDER by date ASC");
$row['delsquad'] = $teildel['squadname'];
$row['delteil'] = get_trstatus ($teildel['teilnahme']);
$row['subdel'] = '<button value="Löschen" type="submit" name="subdel">Löschen</button>';
$row['userdel'] = dblistee($deluser, "SELECT DISTINCT user,prefix_user.name FROM `prefix_trainuser` LEFT JOIN prefix_user on prefix_trainuser.user = prefix_user.id ORDER by name");}
else{
$row['datedel'] = '';
$row['delsquad'] = '';
$row['delteil'] = '';
$row['subdel'] = '';
$row['userdel'] = '';}
$title = $allgAr['title'].' :: Trainingszeiten :: Anmelden';
$hmenu = '<a class="smalfont" href="?trains" target="_self">Trainingszeiten</a><b> » </b>Anmelden';
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ('training/anmelden.htm');
$row['txtanz'] = bbcode($row['txtanz']);
$tpl->set_ar_out($row,0);
$erg1 = db_query("SELECT prefix_trainuser.id,prefix_user.name as user,prefix_groups.name as squad_name,squad,teilnahme,date,comment FROM `prefix_trainuser` LEFT JOIN prefix_groups ON prefix_trainuser.squad = prefix_groups.id LEFT JOIN `prefix_user` on prefix_trainuser.user = prefix_user.id WHERE date = '".$anztime."' AND type = '".$_SESSION['trainan_type']."' ORDER by prefix_trainuser.teilnahme DESC,prefix_user.name ASC");
while($row = db_fetch_assoc($erg1)){
$clas = ($clas == 'Cmite' ? 'Cnorm' : 'Cmite');
$row['class'] = $clas;
$row['teilnahme'] = get_trstatus ($row['teilnahme']);
$tpl->set_ar_out($row,1);
}
$tpl->out(2);
$design->footer();
break;
case 'save' :
$title = $allgAr['title'].' :: Trainingszeiten :: Anmelden :: Speichern';
$hmenu = '<a class="smalfont" href="?trains" target="_self">Trainingszeiten</a><b> » </b><a class="smalfont" href="?trains-anmelden" target="_self">Anmelden</a><b> » </b>Speichern';
$design = new design ( $title , $hmenu );
$design->header();
if(isset($_POST['user']) AND isset($_POST['date']) AND isset($_POST['squad']) AND isset($_POST['teilnahme']) AND isset($_POST['xsquad'])){
$user = escape($_POST['user'], 'string');
$date = escape($_POST['date'], 'string');
$squad = escape($_POST['squad'], 'string'); // gewählt
$teilnahme = escape($_POST['teilnahme'], 'string');
$xsquad = escape($_POST['xsquad'], 'string'); // Vorgabe
$comm = escape($_POST['com'], 'string');
$commch = escape($_POST['comch'], 'string');
$spc = @db_result(db_query("SELECT gid FROM prefix_groupusers WHERE uid = $user AND gid = $squad"),0);
}elseif(isset($_POST['userdel']) AND isset($_POST['datedel'])){
$userdel = escape($_POST['userdel'], 'string');
$datedel = escape($_POST['datedel'], 'string');
}
$type = $_SESSION['trainan_type'];
$inputcheck = db_fetch_assoc(db_query("SELECT * FROM `prefix_trainuser` WHERE date = '".$date."' AND user = '".$user."' AND type = '".$type."'")); // Eingetragen > 0
if($commch == '1' AND $inputcheck['id'] >= '1'){
db_query('UPDATE `prefix_trainuser` SET comment = "'.$comm.'" WHERE date = "'.$date.'" AND type = "'.$type.'" AND user = "'.$user.'"' );
}
if($squad != ''){
if($xsquad == 'alle'){
$squadid = '1';
$squadgid = $squad;
}elseif($xsquad == $squad){
$squadgid = $squad;
$squadid = $squad;
}else{
$squadid = '';
}
}
if($_SESSION['authid'] == $user){
$ausg = 'Deine ';
}else{
$username = db_fetch_assoc(db_query("SELECT name FROM `prefix_user` WHERE id = '".$user."'"));
$ausg = $username['name']."'s ";
}
if(isset($_POST['sub3']) AND !empty($_POST['sub3'])){
if($_SESSION['authright'] >= '-2'){ ### Wenn Trial oder mehr
wd('index.php?trains-anmelden',"Du hast leider nicht die nötigen Rechte dafür!<br>Entwerder bist du kein <b>Trial/Member</b> oder <b>nicht eingeloggt</b>",7);
}elseif($date == ''){ ### Wenn kein Datum
wd('index.php?trains-anmelden',"Kein Termin für das Training gegen ".$type." vorhanden!<br><b>Informiere bitte den Admin über diesen Vorfall!</b>",10);
}elseif($squadid == '' OR $spc == ''){ ### Wenn User nicht im Squad
wd('index.php?trains-anmelden',"Du bist nicht in dem Squad für dieses Training!<br>Oder hast den falschen Squad gewählt!",5);
}elseif($inputcheck['id'] >= '1'){ ### Wenn User schon eingetragen
db_query('UPDATE `prefix_trainuser` SET teilnahme = "'.$teilnahme.'" WHERE date = "'.$date.'" AND type = "'.$type.'" AND user = "'.$user.'"' );
wd('index.php?trains-anmelden',$ausg."Anmeldung wurde erfolgreich geändert!",5);
}else{ ### Neue Anmeldung
db_query('INSERT INTO `prefix_trainuser` (date,user,teilnahme,type,squad,comment) VALUES ("'.$date.'","'.$user.'","'.$teilnahme.'","'.$type.'","'.$squadgid.'","'.$comm.'" ) ' );
wd('index.php?trains-anmelden',$ausg."Anmeldung wurde erfolgreich eingetragen!",5);
}
}elseif(isset($_POST['subdel']) AND !empty($_POST['subdel']) AND $_SESSION['authright'] == '-9'){ ### Anmeldung löschen
db_query('DELETE FROM `prefix_trainuser` WHERE date = "'.$datedel.'" AND type = "'.$type.'" AND user = "'.$userdel.'" LIMIT 1' );
wd('index.php?trains-anmelden',"Anmeldung wurde erfolgreich gelöscht!",5);
}elseif(empty($_POST['sub3']) OR empty($_POST['subdel'])){ ### Wenn ?trains-save direkt aufgerufen wurde oder das Formular fehler hat
wd('index.php?trains',"Du hast diese Seite direkt aufgerufen ohne das Formular auszufüllen oder es ist ein Fehler beim Absenden des Formulars aufgetreten.!",10);
}else{ ### Automatischer Fehler, wenn zu wenig Rechte -> Login wird aufgerufen
wd('index.php?user-login',"Du hast nicht die nötigen Rechte dafür!",5);
}
$design->footer();
break;
case 'alte' :
$title = $allgAr['title'].' :: Trainingszeiten :: Anmeldungen';
$hmenu = '<a class="smalfont" href="?trains" target="_self">Trainingszeiten</a><b> » </b>Anmeldungen';
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ('training/anmeldungen.htm');
$anmeldung = '';
$datum = '';
if(isset($_POST['type2'])){$type = escape($_POST['type2'], 'string');}
$zeitan = time();
if($type == 'alt'){$type1 = '< '.$zeitan;
$anmel = 'Alle alten Trainingsanmeldungen';}
elseif($type == 'neu'){$type1 = '> '.$zeitan;
$lim = ' LIMIT 5';
$anmel = 'Trainingsanmeldungen der nächsten 5 Termine';}
else{$type1 = '= '.$type;
$anmel = 'Trainingsanmeldungen vom '.date("d.m.Y \u\m H:i",$type).' Uhr';}
$anmeldung = '<div align="left"><b>'.$anmel.':</b></div><br><br>';
if($type == 'alt' OR $type == 'neu'){$datum = '<th align="center">Datum</th>';}
$tpl->set('ANMELDUNG',$anmeldung);
$tpl->set('DATUM',$datum);
$tpl->out(0);
$erg2 = db_query("SELECT prefix_trainuser.id,prefix_user.name as user,prefix_groups.name as squad_name,squad,teilnahme,date,comment FROM `prefix_trainuser` LEFT JOIN prefix_groups ON prefix_trainuser.squad = prefix_groups.id LEFT JOIN `prefix_user` on prefix_trainuser.user = prefix_user.id WHERE date $type1 ORDER by date,prefix_trainuser.teilnahme DESC$lim");
while ($row = db_fetch_assoc($erg2)){
$clas = ($clas == 'Cmite' ? 'Cnorm' : 'Cmite' );
$row['class'] = $clas;
$row['teilnahme'] = get_trstatus ($row['teilnahme']);
$row['date1'] = date("d.m.Y \u\m H:i",$row['date']);
if($type == 'alt' OR $type == 'neu'){$row['date'] = '<td align="center" nowrap>'.$row['date1'].' Uhr</td>';}
else{$row['date'] = '';}
$tpl->set_ar_out($row,1);}
$tpl->out(2);
$design->footer();
break;
case 'eigene' :
$title = $allgAr['title'].' :: Trainingszeiten :: Eigene Anmeldungen';
$hmenu = '<a class="smalfont" href="?trains" target="_self">Trainingszeiten</a><b> » </b>Eigene Anmeldungen';
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ('training/meine.htm');
$datum = '';
$username = '';
if(isset($_POST['type3'])){$type = escape($_POST['type3'], 'string');}
$zeitan = time();
if($type == 'alle'){$type1 = '> 0';
$anmel = 'Deine gesamten Trainingsanmeldungen';
$sort = 'DESC';}
elseif($type == 'neu'){$type1 = '> '.$zeitan;
$lim = ' LIMIT 5';
$anmel = 'Deine Trainingsanmeldungen der nächsten 5 Termine';
$sort = 'ASC';}
else{$type1 = '= '.$type;
$anmel = 'Deine Trainingsanmeldungen vom '.date("d.m.Y \u\m H:i",$type).' Uhr';
$sort = 'DESC';}
$username = '<div align="left">'.$_SESSION['authname'].'</div><br><br><b>'.$anmel.':</b><br><br>';
if($type == 'alle' OR $type == 'neu'){$datum = '<th width="35%" align="center">Datum</th>'; }
$tpl->set('DATUM',$datum);
$tpl->set('USER',$username);
$tpl->out(0);
$erg2 = db_query("SELECT prefix_trainuser.id,user,prefix_groups.name as squad_name,squad,teilnahme,date FROM `prefix_trainuser` LEFT JOIN prefix_groups ON prefix_trainuser.squad = prefix_groups.id WHERE date $type1 AND user = '".$_SESSION['authid']."' ORDER by date $sort");
while ($row = db_fetch_assoc($erg2)){
$clas = ($clas == 'Cmite' ? 'Cnorm' : 'Cmite' );
$row['class'] = $clas;
$row['teilnahme'] = get_trstatus ($row['teilnahme']);
$row['date1'] = date("d.m.Y \u\m H:i",$row['date']);
if($type == 'alle' OR $type == 'neu'){$row['date'] = '<td align="center">'.$row['date1'].' Uhr</td>';}
else{$row['date'] = '';}
$tpl->set_ar_out($row,1);}
$tpl->out(2);
$design->footer();
break;
default :
$title = $allgAr['title'].' :: Trainingszeiten';
$hmenu = 'Trainingszeiten';
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ('trains.htm');
$row5 = db_fetch_object(db_query("SELECT t1 FROM `prefix_allg` WHERE k = 'trainzeiten'"));
$dbe=explode('#',$row5->t1);
$ar = array ('MON' => bbcode($dbe[0]), 'DIE' => bbcode($dbe[1]), 'MIT' => bbcode($dbe[2]), 'DON' => bbcode($dbe[3]),
'FRE' => bbcode($dbe[4]), 'SAM' => bbcode($dbe[5]), 'SON' => bbcode($dbe[6]));
$ar['type'] .= dblistee($ar['type'], "SELECT DISTINCT type,prefix_groups.name FROM `prefix_traindates` LEFT JOIN prefix_groups on prefix_traindates.type = prefix_groups.id WHERE LENGTH(type) < 3 AND date > '".time()."' ORDER by prefix_traindates.id");
$ar['type'] .= dblistee($ar['type'], "SELECT DISTINCT type,type FROM `prefix_traindates` WHERE LENGTH(type) > 2 AND date > '".time()."' ORDER by type ASC");
$ar['type2'] = datelistee($ar['type2'], "SELECT DISTINCT date,date FROM `prefix_trainuser` WHERE date < '".time()."' ORDER by date");
$ar['type3'] = datelistee('', "SELECT DISTINCT date,date FROM `prefix_trainuser` WHERE date < '".time()."' AND user = '".$_SESSION['authid']."' ORDER by date");
$tpl->set_ar_out($ar,0);
$design->footer();
break;
}
?>