From 8c518d4c3496ce9c72e4eed400923bd978b4e6a5 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Sun, 12 Jul 2015 14:45:58 +0200 Subject: add arrival date feature --- db/install.sql | 11 +++++++---- db/update.sql | 6 ++++++ includes/model/User_model.php | 6 ++++-- includes/pages/admin_arrive.php | 9 +++++++-- includes/pages/guest_login.php | 21 +++++++++++++++++++-- includes/sys_template.php | 11 ++++++++--- includes/view/User_view.php | 4 +++- 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/db/install.sql b/db/install.sql index d64c0263..1fbd807b 100644 --- a/db/install.sql +++ b/db/install.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Erstellungszeit: 14. Mai 2015 um 16:36 +-- Erstellungszeit: 12. Jul 2015 um 14:45 -- Server Version: 5.6.12 -- PHP-Version: 5.5.3 @@ -418,19 +418,22 @@ CREATE TABLE IF NOT EXISTS `User` ( `Hometown` varchar(255) NOT NULL DEFAULT '', `api_key` varchar(32) NOT NULL, `got_voucher` tinyint(1) NOT NULL, + `arrival_date` int(11) DEFAULT NULL, + `planned_arrival_date` int(11) NOT NULL, PRIMARY KEY (`UID`), UNIQUE KEY `Nick` (`Nick`), KEY `api_key` (`api_key`), KEY `password_recovery_token` (`password_recovery_token`), - KEY `force_active` (`force_active`) + KEY `force_active` (`force_active`), + KEY `arrival_date` (`arrival_date`,`planned_arrival_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; -- -- Daten für Tabelle `User` -- -INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT`, `Handy`, `email`, `email_shiftinfo`, `jabber`, `Size`, `Passwort`, `password_recovery_token`, `Gekommen`, `Aktiv`, `force_active`, `Tshirt`, `color`, `Sprache`, `Menu`, `lastLogIn`, `CreateDate`, `Art`, `kommentar`, `Hometown`, `api_key`, `got_voucher`) VALUES -(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', 0, '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 0, 0, 0, 2, 'de_DE.UTF-8', 'L', 1431613486, '0000-00-00 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235', 0); +INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT`, `Handy`, `email`, `email_shiftinfo`, `jabber`, `Size`, `Passwort`, `password_recovery_token`, `Gekommen`, `Aktiv`, `force_active`, `Tshirt`, `color`, `Sprache`, `Menu`, `lastLogIn`, `CreateDate`, `Art`, `kommentar`, `Hometown`, `api_key`, `got_voucher`, `arrival_date`, `planned_arrival_date`) VALUES +(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', 0, '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 0, 0, 0, 2, 'de_DE.UTF-8', 'L', 1436705059, '0000-00-00 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235', 0, NULL, 0); -- -------------------------------------------------------- diff --git a/db/update.sql b/db/update.sql index 8364e2e5..2e03c3d9 100644 --- a/db/update.sql +++ b/db/update.sql @@ -1,3 +1,9 @@ + +/* introduce user arrival date */ +ALTER TABLE `User` ADD `arrival_date` INT NULL , +ADD `planned_arrival_date` INT NOT NULL , +ADD INDEX ( `arrival_date` , `planned_arrival_date` ) ; + /* fix log */ ALTER TABLE `LogEntries` CHANGE `nick` `nick` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ; diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 9df72748..ce760552 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -29,8 +29,10 @@ function User_update($user) { `color`='" . sql_escape($user['color']) . "', `Sprache`='" . sql_escape($user['Sprache']) . "', `Hometown`='" . sql_escape($user['Hometown']) . "', - `got_voucher`=" . sql_bool($user['got_voucher']) . " - WHERE `UID`='" . sql_escape($user['UID']). "'"); + `got_voucher`=" . sql_bool($user['got_voucher']) . ", + `arrival_date`='" . sql_escape($user['arrival_date']) . "' + `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "' + WHERE `UID`='" . sql_escape($user['UID']) . "'"); } /** diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index f51ef7ac..399cb335 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -1,4 +1,5 @@ '; $table .= '' . User_Nick_render($usr) . ''; $usr['nick'] = User_Nick_render($usr); + $usr['planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']); + $usr['arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-"; $usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : ""; $usr['actions'] = $usr['Gekommen'] == 1 ? '' . _("reset") . '' : '' . _("arrived") . ''; if ($usr['Gekommen'] == 1) @@ -68,7 +71,9 @@ function admin_arrive() { )), table(array( 'nick' => _("Nickname"), + 'planned_arrival_date' => _("Planned date"), 'arrived' => _("Arrived?"), + 'arrival_date' => _("Arrival date"), 'actions' => "" ), $users_matched) )); diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 741fd826..64a97d70 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -32,6 +32,7 @@ function guest_register() { $tshirt_size = ''; $password_hash = ""; $selected_angel_types = array(); + $planned_arrival_date = null; $angel_types_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angel_types = array(); @@ -96,6 +97,13 @@ function guest_register() { $msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), MIN_PASSWORD_LENGTH), true); } + if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) { + $planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp(); + } else { + $ok = false; + $msg .= error(_("Please enter your planned date of arrival."), true); + } + $selected_angel_types = array(); foreach ($angel_types as $angel_type_id => $angel_type_name) if (isset($_REQUEST['angel_types_' . $angel_type_id])) @@ -138,7 +146,9 @@ function guest_register() { `kommentar`='" . sql_escape($comment) . "', `Hometown`='" . sql_escape($hometown) . "', `CreateDate`=NOW(), - `Sprache`='" . sql_escape($_SESSION["locale"]) . "'"); + `Sprache`='" . sql_escape($_SESSION["locale"]) . "', + `arrival_date`=NULL, + `planned_arrival_date`='" . sql_escape($planned_arrival_date) . "'"); // Assign user-group and set password $user_id = sql_id(); @@ -174,7 +184,14 @@ function guest_register() { form_checkbox('email_shiftinfo', _("Please send me an email if my shifts change"), $email_shiftinfo) )) )), - $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : '', + div('row', array( + div('col-sm-6', array( + form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, time()) + )), + div('col-sm-6', array( + $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : '' + )) + )), div('row', array( div('col-sm-6', array( form_password('password', _("Password") . ' ' . entry_required()) diff --git a/includes/sys_template.php b/includes/sys_template.php index 452e3a82..1c631dbe 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -131,20 +131,25 @@ function form_spinner($name, $label, $value) { * Label * @param int $value * Unix Timestamp + * @param int $min_date + * Earliest possible date * @return HTML */ -function form_date($name, $label, $value) { +function form_date($name, $label, $value, $start_date = '') { $id = $name . '-date'; $value = is_numeric($value) ? date('Y-m-d', $value) : ''; + $start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : ''; return form_element($label, '
- ' . glyph('th') . ' + ' . glyph('th') . '
diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 0add8e82..da52a913 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -171,7 +171,9 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel '

' . _("User state") . '

', ($admin_user_privilege && $freeloader) ? ' ' . _("Freeloader") . '
' : '', $user_source['Gekommen'] ? User_shift_state_render($user_source) . '
' : '', - ($user_source['Gekommen'] ? ' ' . _("Arrived") . '' : '' . _("Not arrived") . ''), + $admin_user_privilege + ? ($user_source['Gekommen'] ? ' ' . sprintf(_("Arrived at %s"), date('Y-m-d', $user_source['arrival_date'])) . '' : '' . sprintf(_("Not arrived (Planned: %s)"), date('Y-m-d', $user_source['planned_arrival_date'])) . '') + : ($user_source['Gekommen'] ? ' ' . _("Arrived") . '' : '' . _("Not arrived") . ''), $admin_user_privilege ? ($user_source['got_voucher'] ? '
' . glyph('cutlery') . _("Got vouchers") . '' : '
' . _("Got no vouchers") . '') : '', ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Aktiv']) ? ' ' . _("Active") . '' : '', ($user_source['Gekommen'] && $admin_user_privilege && $user_source['Tshirt']) ? ' ' . _("T-Shirt") . '' : '' -- cgit v1.2.3-70-g09d2