<?php

$page->title_bar();
$termin = new tb_termin();
if ($termin->load_tb_termin($id)) {
    if ($termin->return_field('flag_kueche')) {
        $temp = 'ja';
    } else {
        $temp = 'nein';
    }
    $message = '
				<table width=100% align=center border=0>
					<tr>
						<td width=30% class=list_table_active>
							Terminart:
						</td>
						<td>
							<b>' . $DATE_TYPES[$termin->return_field('terminart')][name] . '</b>
						</td>
					</tr>
					<tr>
						<td width=30% class=list_table_active>
							Datum:
						</td>
						<td>
							<b>' . $termin->return_field('date_begin_readable') . '</b> - <b>' . $termin->return_field('date_end_readable') . '</b>
						</td>
					</tr>
					<tr>
						<td width=30% class=list_table_active>
							Kommentar:
<?php

require_once 'inc/classes/class_helferliste.inc.php';
$page->title_bar();
$date = new tb_termin();
// Muss überhaupt schon was getan werden??
if ($confirmed) {
    $date->remove_tb_termin($id);
    $message = '
				Der Termin wurde gelöscht...
			';
    $userliste = new tb_helferliste2();
    $message .= $userliste->drop_userlist($id);
    $menu = array();
    $menu[0][link] = $PHP_SELF . '?action=date';
    $menu[0][text] = 'Übersicht';
    echo $page->dialog_box('Termin löschen', $message, 0, $menu, '50%');
} else {
    $message = 'Soll der Termin wirklich gelöscht werden?';
    $menu = array();
    $menu[0][link] = $PHP_SELF . '?action=date_delete&confirmed=1&id=' . $id;
    $menu[0][text] = 'Ja, löschen';
    $menu[1][link] = $PHP_SELF . '?action=date_view&id=' . $id;
    $menu[1][text] = 'Nein, nicht löschen';
    echo $page->dialog_box('Termin löschen', $message, 0, $menu, '50%');
}
?>

{
    // TODO :
    // evtl. plausi-checks einbauen!
    // Zuerst Uhrzeit vom Datum trennen :
    $date_array = explode(" ", $date);
    // Uhrzeit splitten :
    $time = explode(":", $date_array[1]);
    // Datum splitten :
    $date = explode('.', $date_array[0]);
    // Beides zusammensetzen :
    $timestamp = mktime($time[0], $time[1], 0, $date[1], $date[0], $date[2]);
    return $timestamp;
}
$page->title_bar();
// Zuerstmal alles aus der DB holen
$termin = new tb_termin();
$termin->load_tb_termin($id);
// TODO: Presets evtl nur einmal laden!!! (Counter??)
if (!$submit) {
    $presets = array();
    $presets[date_begin] = $termin->return_field('date_begin_readable');
    $presets[date_end] = $termin->return_field('date_end_readable');
    $presets[terminart] = $termin->return_field('terminart');
    $presets[kommentar] = $termin->return_field('kommentar');
    $presets[flag_kueche] = $termin->return_field('flag_kueche');
    $fields = array();
    $fields[0] = array('type' => 'separator', 'value' => '<b>Datum</b>');
    $fields[] = array('name' => 'date_begin', 'type' => 'text', 'title' => 'Anfangsdatum:', 'important' => 1, 'attribs' => array(0 => array('name' => 'title', 'value' => 'Hier das Anfangsdatum eingeben, Format: TT.MM.JJJJ HH:MM'), 1 => array('name' => 'size', 'value' => '15')));
    $fields[] = array('name' => 'date_end', 'type' => 'text', 'title' => 'Enddatum:', 'important' => 1, 'attribs' => array(0 => array('name' => 'title', 'value' => 'Hier das Enddatum eingeben, Format: TT.MM.JJJJ HH:MM'), 1 => array('name' => 'size', 'value' => '15')));
    $fields[] = array('type' => 'separator', 'value' => '<b>Infos zum Termin</b>');
    $fields[] = array('name' => 'terminart', 'type' => 'select', 'title' => 'Termintyp', 'important' => 1, 'selections' => array(), 'attribs' => array(0 => array('name' => 'title', 'value' => 'Bitte den <b>Termintyp</b> auswählen!!'), 1 => array('name' => 'size', 'value' => '1')));
    $fields[$tmp++] = array('name' => 'kommentar', 'type' => 'textarea', 'title' => 'Kommentar:', 'important' => 1, 'attribs' => array(0 => array('name' => 'title', 'value' => 'Kurzer Kommentar worum es in dem Dienst geht!'), 1 => array('name' => 'cols', 'value' => '40'), 2 => array('name' => 'rows', 'value' => '10')));
    $fields[$tmp++] = array('type' => 'hidden', 'important' => 0, 'selections' => array(0 => array('value' => 'date_create', 'name' => 'action')));
    $fields[$tmp++] = array('type' => 'buttons', 'important' => 0, 'selections' => array(0 => array('value' => 'Termin anlegen&gt;&gt;', 'type' => 'submit', 'name' => 'submit'), 1 => array('value' => 'Reset', 'type' => 'reset', 'name' => 'reset')));
    $form->load_form($fields);
    // Formular laden
    $form->precheck_form();
    if (!$GLOBALS[submit]) {
        $form->set_precheck_error();
    }
    if ($form->is_form_error()) {
        $message = $form->build_form();
        $width = '60%';
    } else {
        // Fertig!!! Daten eintragen!!!!!
        $width = '50%';
        $date = new tb_termin();
        if (!$flag_kueche) {
            $flag_kueche = 0;
        }
        $date_data = array('date_begin' => datestring2unix($date_begin), 'date_end' => datestring2unix($date_end), 'flag_public' => $public, 'kommentar' => trim($kommentar), 'flag_edit' => 1, 'terminart' => $terminart, 'flag_kueche' => $flag_kueche);
        $last_id = $date->add_tb_termin($date_data);
        $message = 'Der Termin wurde gespeichert...';
        $message .= '<br>
								Weitere Optionen:
								<ul>
									<li><a href="' . $GLOBALS[PHP_SELF] . '?action=userlist_create&id=' . $last_id . '&type=date">Dem Termin eine Userliste anfügen</a></li>
								</ul>';
        $menu = array();
        $menu[0][link] = $PHP_SELF . '?action=date_create';
        $menu[0][text] = 'Weiteren Termin anlegen';
        $menu[1][link] = $PHP_SELF . '?action=date';