function dirtydates($userid, $options)
 {
     $formcallback = $_SERVER['REQUEST_URI'];
     global $gCurrentUser;
     $dd = new class_admidio_db_dates($options);
     //--------------------------------
     //Ansichts-Menü darstellen
     $form = "<form action=" . $formcallback . " method=post\n>";
     $form .= "<select size=\"1\" name=\"dd_userid\" class=\"eingabetext\">";
     $form .= "<option value=\"" . "overview" . "\">";
     $form .= "User auswählen";
     $form .= "</option>\n";
     foreach ($dd->users as $datensatz) {
         $form .= "<option value=\"" . $datensatz['usr_id'] . "\">";
         $form .= $datensatz['first_name'] . " " . $datensatz['last_name'] . " (" . $datensatz['birthday'] . ")";
         $form .= "</option>\n";
     }
     $form .= "</select>\n";
     $form .= "<input type=\"submit\" value=\"Los gehts !\">\n";
     $form .= "<input type=\"submit\" name=\"overview\" value=\"Zurück zur Übersicht\">\n";
     $form .= "</form>\n";
     //-----------------------------------
     //Status eines Users ändern
     //-----------------------------------
     if (isset($_REQUEST['status_changed'])) {
         if (!($gCurrentUser->getValue('usr_id') === $userid || $gCurrentUser->editUsers() === true)) {
             return 'Not allowed!';
         }
         $changes = array();
         foreach ($_REQUEST as $key => $value) {
             preg_match('/^status_new_([0-9]+)/', $key, $match);
             if (!isset($match[1])) {
                 continue;
             }
             $dateid = $match[1];
             /*print_r($match);
             		echo $dateid." changed to ".$value."<br>";
             		*/
             $changes[$dateid]['status'] = intval($value);
             $changes[$dateid]['comment'] = htmlspecialchars($_REQUEST['status_new_comment_' . $dateid]);
         }
         $dd->save_status($userid, $changes);
         //reload status
         $dd->load_status();
         //load overview
         $userid = 'overview';
     }
     //------------------------------------
     //Übersichtsmenü darstellen mit allen Usern und Daten
     //------------------------------------
     if ($userid == 'overview' or !isset($userid)) {
         //tabelle erzeugen
         $out = "<table width=200 border=1>\n<tr>";
         if (isset($options->group_field)) {
             $out .= "<th>Gruppe</th>";
         }
         $out .= "<th>Name</th>";
         foreach ($dd->dates as $date) {
             $out .= "<th class=\"admidio_dirtydates_headline\" id=\"" . $date['dat_id'] . "\">";
             $out .= $date['dat_headline'];
             $out .= "</th>";
             $dataID[] = $date['dat_id'];
         }
         $out .= "</tr>\n<tr>";
         if (isset($options->group_field)) {
             $out .= "<td></td>";
         }
         $out .= "<td>Termin</td>";
         foreach ($dd->dates as $date) {
             $time = strtotime($date['dat_begin']);
             $out .= "<td class=\"admidio_dirtydates_time\" id=\"" . $date['dat_id'] . "\">";
             if (date('H:i', $time) == "00:00") {
                 $out .= date('D, d.m.y', $time) . "<br>??&nbsp;Uhr";
             } else {
                 $out .= date('D, d.m.y', $time) . "<br>" . date('H:i', $time) . '&nbsp;Uhr';
             }
             $out .= "</td>";
         }
         $out .= "</tr>\n";
         foreach ($dd->users as $user) {
             $out .= "<tr>";
             if (isset($options->group_field)) {
                 $out .= "<td>" . $user['group_name'] . "</td>";
             }
             if (!($gCurrentUser->getValue('usr_id') === $user['usr_id'] || $gCurrentUser->editUsers() === true)) {
                 //only show name for others
                 $out .= "<td>" . $user['first_name'] . '&nbsp;' . $user['last_name'] . "</td>";
             } else {
                 // for myself and admins show link
                 $out .= "<td><a href=" . $_SELF . "?dd_userid=" . $user['usr_id'] . ">" . $user['first_name'] . '&nbsp;' . $user['last_name'] . "</a></td>";
             }
             for ($i = 0; $i < count($dataID); $i++) {
                 if (isset($dd->status[$user['usr_id']][$dataID[$i]]['dd_status'])) {
                     $status = $dd->status[$user['usr_id']][$dataID[$i]]['dd_status'];
                 } else {
                     $status = false;
                 }
                 if ($status == 2) {
                     $out .= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=red id=\"" . $dataID[$i] . "\">";
                 } else {
                     if ($status == 1) {
                         $out .= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=green id=\"" . $dataID[$i] . "\">";
                     } else {
                         if ($status == 3 && $options['allow_maybe']) {
                             $out .= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=yellow id=\"" . $dataID[$i] . "\">";
                         } else {
                             $out .= "<TD id=\"" . $dataID[$i] . "\">";
                         }
                     }
                 }
                 if (!empty($dd->status[$user['usr_id']][$dataID[$i]]['dd_comment'])) {
                     $comment = $dd->status[$user['usr_id']][$dataID[$i]]['dd_comment'];
                     $out .= '<abbr title="' . $comment . '">Info</abbr></td>';
                 } else {
                     $out .= "</TD>";
                 }
             }
             $out .= "</tr>\n";
         }
         $out .= "</table>";
     } else {
         if (!($gCurrentUser->getValue('usr_id') === $userid || $gCurrentUser->editUsers() === true)) {
             return 'Not allowed!';
         }
         $user = $dd->get_user_by_id($userid);
         if ($user === false) {
             $out .= '<p>Fehler, User mit id "' . $userid . '" nicht gefunden!</p>';
             return $out;
         }
         $out .= "<p><font size=+4 color=red>" . $user['first_name'] . " " . $user['last_name'] . "</font></p>\n";
         $out .= "<form action=" . $formcallback . " method=post>";
         $out .= "<table border=1>\n";
         $out .= "<tr><th>Termin</th><th>Datum</th><th>weitere Infos</th>";
         if ($options['allow_maybe']) {
             $out .= '<th>JA&nbsp;-&nbsp;?&nbsp;-&nbsp;Nein&nbsp;-&nbsp;Reset</th>';
         } else {
             $out .= '<th>JA&nbsp;-&nbsp;Nein&nbsp;-&nbsp;Reset</th>';
         }
         $out .= "<th>Kommentar</th></tr>";
         foreach ($dd->dates as $date) {
             //pro termin eine reihe!
             $time = strtotime($date['dat_begin']);
             if (isset($dd->status[$userid][$date['dat_id']])) {
                 $oldstatus = $dd->status[$userid][$date['dat_id']]['dd_status'];
             } else {
                 $oldstatus = 0;
             }
             $oldcomment = $dd->status[$userid][$date['dat_id']]['dd_comment'];
             $checked_no = '';
             $checked_yes = '';
             $checked_perhaps = '';
             if ($oldstatus[0] == 2) {
                 $checked_no = 'checked';
             } else {
                 if ($oldstatus[0] == 1) {
                     $checked_yes = 'checked';
                 } else {
                     if ($oldstatus[0] == 3) {
                         $checked_perhaps = 'checked';
                     }
                 }
             }
             $out .= "\n<tr>";
             $out .= "<td>" . $date['dat_headline'] . "</td>";
             $out .= "<td>" . date('D, d.m.y </br> \\u\\m G:i', $time) . "</td>";
             $out .= "<td>" . $date['dat_description'] . "</td>";
             $out .= "<td><input type=radio name=status_new_" . $date['dat_id'] . " value=1 " . $checked_yes . ">";
             if ($options['allow_maybe']) {
                 $out .= "\t<input type=radio name=status_new_" . $date['dat_id'] . " value=3 " . $checked_perhaps . ">";
             }
             $out .= "\t<input type=radio name=status_new_" . $date['dat_id'] . " value=2 " . $checked_no . ">";
             $out .= "\t<input type=radio name=status_new_" . $date['dat_id'] . " value=0 ></td>";
             $out .= "<td><input type=text name=status_new_comment_" . $date['dat_id'] . " value=\"" . $oldcomment . "\">";
             $out .= "</tr>\n";
         }
         $out .= "</table>\n";
         $out .= "<input type=hidden name=status_changed value=1>\n";
         $out .= "<input type=hidden name=dd_userid value=" . $userid . ">\n";
         $out .= "<input type=\"submit\" value=\"Änderungen speichern\">\n";
         $out .= "</form>\n";
     }
     if ($gCurrentUser->editUsers() === true) {
         //only show form for admins
         return $form . $out;
     } else {
         return $out;
     }
 }
 function dirtydates($atts)
 {
     if (isset($_REQUEST['dd_userid']) && !isset($_REQUEST['overview'])) {
         $userid = $_REQUEST['dd_userid'];
     }
     $dd = new class_admidio_db_dates(self::$options);
     //--------------------------------
     //Ansichts-Menü darstellen
     $form = "<form action=" . get_permalink() . " method=post\n>";
     $form .= "<select size=\"1\" name=\"dd_userid\" class=\"eingabetext\">";
     $form .= "<option value=\"" . "--" . "\">";
     $form .= "User auswählen";
     $form .= "</option>\n";
     foreach ($dd->users as $datensatz) {
         $form .= "<option value=\"" . $datensatz['usr_id'] . "\">";
         $form .= $datensatz['first_name'] . " " . $datensatz['last_name'] . " (" . $datensatz['birthday'] . ")";
         $form .= "</option>\n";
     }
     $form .= "</select>\n";
     $form .= "<input type=\"submit\" value=\"Los gehts !\">\n";
     $form .= "<input type=\"submit\" name=\"overview\" value=\"Zurück zur Übersicht\">\n";
     $form .= "</form>\n";
     //-----------------------------------
     //Status eines Users ändern
     //-----------------------------------
     if (isset($_REQUEST['status_changed'])) {
         /*
         echo "<pre>";
         print_r($_REQUEST);
         echo "-------------Parse Request------------<br>";
         */
         $changes = array();
         foreach ($_REQUEST as $key => $value) {
             preg_match('/^status_new[_a-z]*_([0-9]+)/', $key, $match);
             if (!isset($match[1])) {
                 continue;
             }
             $dateid = $match[1];
             $changes[$dateid]['status'] = intval($_REQUEST['status_new_' . $dateid]);
             $changes[$dateid]['comment'] = htmlspecialchars($_REQUEST['status_new_comment_' . $dateid]);
             /*print_r($match);
             		echo $dateid." changed to ".$changes[$dateid]['status']."(".$changes[$dateid]['comment'].")"."<br>";
             		*/
         }
         $dd->save_status($userid, $changes);
         //reload status
         $dd->load_status();
         //load overview
         $userid = '--';
     }
     //------------------------------------
     //Übersichtsmenü darstellen mit allen Usern und Daten
     //------------------------------------
     if ($userid == '--' or !isset($userid)) {
         //tabelle erzeugen
         $out = "<div class=admidio_dirtydates_overview_table>";
         $out .= "<table>\n<tr>";
         $out .= "<th>Gruppe</th>";
         $out .= "<th>Name</th>";
         foreach ($dd->dates as $date) {
             $out .= "<th class=\"admidio_dirtydates_headline\" id=\"" . $date['dat_id'] . "\">";
             $out .= $date['dat_headline'];
             $out .= "</th>";
             $dataID[] = $date['dat_id'];
         }
         $out .= "</tr>\n<tr>";
         $out .= "<td></td>";
         $out .= "<td>Termin</td>";
         foreach ($dd->dates as $date) {
             $time = strtotime($date['dat_begin']);
             $out .= "<td class=\"admidio_dirtydates_time\" id=\"" . $date['dat_id'] . "\">";
             if (date('H:i', $time) == "00:00") {
                 $out .= date_i18n('D, d.m.y', $time) . "<br>??&nbsp;Uhr";
             } else {
                 $out .= date_i18n('D, d.m.y', $time) . "<br>" . date('H:i', $time) . '&nbsp;Uhr';
             }
             $out .= "</td>";
         }
         $out .= "</tr>\n";
         foreach ($dd->users as $i => $user) {
             $out .= '<tr class="groups group_' . $user['grouping'] . '">';
             $out .= "<td>" . $user['group_name'] . "</td>";
             $out .= "<td><a href=" . get_permalink() . "?dd_userid=" . $user['usr_id'] . ">" . $user['first_name'] . '&nbsp;' . $user['last_name'] . "</a></td>";
             for ($i = 0; $i < count($dataID); $i++) {
                 if (isset($dd->status[$user['usr_id']][$dataID[$i]]['dd_status'])) {
                     $status = $dd->status[$user['usr_id']][$dataID[$i]]['dd_status'];
                 } else {
                     $status = false;
                 }
                 if ($status == 2) {
                     $out .= "<TD class=\"admidio_dirtydates_status\" style=\"background-color:red!important;\" id=\"" . $dataID[$i] . "\">";
                 } else {
                     if ($status == 1) {
                         $out .= "<TD class=\"admidio_dirtydates_status\" style=\"background-color:green!important;\" id=\"" . $dataID[$i] . "\">";
                     } else {
                         if ($status == 3 && self::$options['allow_maybe']) {
                             $out .= "<TD class=\"admidio_dirtydates_status\" style=\"background-color:yellow!important;\" id=\"" . $dataID[$i] . "\">";
                         } else {
                             $out .= "<TD id=\"" . $dataID[$i] . "\">";
                         }
                     }
                 }
                 if (!empty($dd->status[$user['usr_id']][$dataID[$i]]['dd_comment'])) {
                     $comment = $dd->status[$user['usr_id']][$dataID[$i]]['dd_comment'];
                     $out .= '<abbr title="' . $comment . '">Info</abbr></td>';
                 } else {
                     $out .= "</TD>";
                 }
             }
             $out .= "</tr>\n";
         }
         $out .= "</table></div>";
     } else {
         $user = $dd->get_user_by_id($userid);
         if ($user === false) {
             $out .= '<p>Fehler, User mit id "' . $userid . '" nicht gefunden!</p>';
             return $out;
         }
         $out .= "<div class=admidio_dirtydates_change_table>";
         $out .= "<p id=dirtydates_user>" . $user['first_name'] . " " . $user['last_name'] . "</p>\n";
         $out .= "<form action=" . get_permalink() . " method=post>";
         $out .= "<table>\n";
         if (self::$options['allow_maybe']) {
             $out .= '<tr><th>Termin</th><th>Datum</th><th>weitere Infos</th><th>JA&nbsp;-&nbsp;?&nbsp;-&nbsp;Nein&nbsp;-&nbsp;Reset</th><th>Kommentar</th></tr>';
         } else {
             $out .= '<tr><th>Termin</th><th>Datum</th><th>weitere Infos</th><th>JA&nbsp;-&nbsp;Nein&nbsp;-&nbsp;Reset</th><th>Kommentar</th></tr>';
         }
         foreach ($dd->dates as $date) {
             //pro termin eine reihe!
             $time = strtotime($date['dat_begin']);
             if (isset($dd->status[$userid][$date['dat_id']])) {
                 $oldstatus = $dd->status[$userid][$date['dat_id']]['dd_status'];
             } else {
                 $oldstatus = 0;
             }
             $oldcomment = $dd->status[$userid][$date['dat_id']]['dd_comment'];
             $checked_no = '';
             $checked_yes = '';
             $checked_perhaps = '';
             if ($oldstatus[0] == 2) {
                 $checked_no = 'checked';
             } else {
                 if ($oldstatus[0] == 1) {
                     $checked_yes = 'checked';
                 } else {
                     if ($oldstatus[0] == 3 && self::$options['allow_maybe']) {
                         $checked_perhaps = 'checked';
                     }
                 }
             }
             $out .= "\n<tr>";
             $out .= "<td>" . $date['dat_headline'] . "</td>";
             $out .= "<td>" . date_i18n('D, d.m.y </br> \\u\\m G:i', $time) . "</td>";
             $out .= "<td>" . $date['dat_description'] . "</td>";
             $out .= "<td><input type=radio name=status_new_" . $date['dat_id'] . " value=1 " . $checked_yes . ">";
             if (self::$options['allow_maybe']) {
                 $out .= "<input type=radio name=status_new_" . $date['dat_id'] . " value=3 " . $checked_perhaps . ">";
             }
             $out .= "<input type=radio name=status_new_" . $date['dat_id'] . " value=2 " . $checked_no . ">";
             $out .= "<input type=radio name=status_new_" . $date['dat_id'] . " value=0 ></td>";
             $out .= "<td><input type=text name=status_new_comment_" . $date['dat_id'] . " value=\"" . $oldcomment . "\">";
             $out .= "</tr>\n";
         }
         $out .= "</table>\n";
         $out .= "<input type=hidden name=status_changed value=1>\n";
         $out .= "<input type=hidden name=dd_userid value=" . $userid . ">\n";
         $out .= "<input type=\"submit\" value=\"Änderungen speichern\">\n";
         $out .= "</form></div>\n";
     }
     return $form . $out;
 }
    echo "-------------Parse Request------------<br>";
    */
    $changes = array();
    foreach ($_REQUEST as $key => $value) {
        preg_match('/^status_new_([0-9]+)/', $key, $match);
        if (!isset($match[1])) {
            continue;
        }
        $dateid = $match[1];
        /*print_r($match);
        		echo $dateid." changed to ".$value."<br>";
        		*/
        $changes[$dateid]['status'] = intval($value);
        $changes[$dateid]['comment'] = htmlspecialchars($_REQUEST['status_new_comment_' . $dateid]);
    }
    $dd->save_status($userid, $changes);
    //reload status
    $dd->load_status();
    //load overview
    $userid = '--';
}
//------------------------------------
//Übersichtsmenü darstellen mit allen Usern und Daten
//------------------------------------
if ($userid == '--' or !isset($userid)) {
    //tabelle erzeugen
    echo "<table width=200 border=1>\n<tr>";
    echo "<th>Name</th>";
    foreach ($dd->dates as $date) {
        echo "<th style=\"width:400\">";
        echo $date['dat_headline'];