From 0ac05d251c0df5fa09a27b7686acc5690b436f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Sun, 20 Dec 2015 11:36:12 +0100 Subject: [PATCH] #198 fixed: driving license feature completed - integrated into angeltypes --- db/update.sql | 2 + includes/controller/angeltypes_controller.php | 21 ++++-- .../user_driver_licenses_controller.php | 26 +++++++ includes/model/AngelType_model.php | 17 +++-- includes/model/UserAngelTypes_model.php | 6 ++ includes/model/User_model.php | 4 +- includes/sys_menu.php | 4 + includes/view/AngelTypes_view.php | 75 ++++++++++++------- 8 files changed, 115 insertions(+), 40 deletions(-) diff --git a/db/update.sql b/db/update.sql index 402812c4..ae9c68d7 100644 --- a/db/update.sql +++ b/db/update.sql @@ -11,3 +11,5 @@ CREATE TABLE IF NOT EXISTS `UserDriverLicenses` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `UserDriverLicenses` ADD CONSTRAINT `userdriverlicenses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE `AngelTypes` ADD `requires_driver_license` BOOLEAN NOT NULL; diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 16f0a4f2..0fdbaa28 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -97,6 +97,7 @@ function angeltype_edit_controller() { $name = ""; $restricted = false; $description = ""; + $requires_driver_license = false; if (isset($_REQUEST['angeltype_id'])) { $angeltype = AngelType($_REQUEST['angeltype_id']); @@ -108,6 +109,7 @@ function angeltype_edit_controller() { $name = $angeltype['name']; $restricted = $angeltype['restricted']; $description = $angeltype['description']; + $requires_driver_license = $angeltype['requires_driver_license']; if (! User_is_AngelType_coordinator($user, $angeltype)) redirect(page_link_to('angeltypes')); @@ -132,6 +134,7 @@ function angeltype_edit_controller() { } $restricted = isset($_REQUEST['restricted']); + $requires_driver_license = isset($_REQUEST['requires_driver_license']); } if (isset($_REQUEST['description'])) @@ -140,26 +143,26 @@ function angeltype_edit_controller() { if ($ok) { $restricted = $restricted ? 1 : 0; if (isset($angeltype)) { - $result = AngelType_update($angeltype['id'], $name, $restricted, $description); + $result = AngelType_update($angeltype['id'], $name, $restricted, $description, $requires_driver_license); if ($result === false) engelsystem_error("Unable to update angeltype."); - engelsystem_log("Updated angeltype: " . $name . ", restricted: " . $restricted); + engelsystem_log("Updated angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : "")); $angeltype_id = $angeltype['id']; } else { - $angeltype_id = AngelType_create($name, $restricted, $description); + $angeltype_id = AngelType_create($name, $restricted, $description, $requires_driver_license); if ($angeltype_id === false) engelsystem_error("Unable to create angeltype."); - engelsystem_log("Created angeltype: " . $name . ", restricted: " . $restricted); + engelsystem_log("Created angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : "")); } success("Angel type saved."); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id); + redirect(angeltype_link($angeltype_id)); } } return array( sprintf(_("Edit %s"), $name), - AngelType_edit_view($name, $restricted, $description, $coordinator_mode) + AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) ); } @@ -185,13 +188,17 @@ function angeltype_controller() { if ($user_angeltype === false) engelsystem_error("Unable to load user angeltype."); + $user_driver_license = UserDriverLicense($user['UID']); + if ($user_driver_license === false) + engelsystem_error("Unable to load user driver license."); + $members = Users_by_angeltype($angeltype); if ($members === false) engelsystem_error("Unable to load members."); return array( sprintf(_("Team %s"), $angeltype['name']), - AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator']) + AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'], $user_driver_license, $user) ); } diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index b18a78b6..ec094220 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -1,5 +1,31 @@ ' . _("driving license information") . ''), true); + + return ''; +} + /** * Route user driver licenses actions. */ diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 5e7f4fb6..e4aef450 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -17,15 +17,17 @@ function AngelType_delete($angeltype) { * * @param int $angeltype_id * @param string $name - * @param boolean $restricted + * @param bool $restricted * @param string $description + * @param bool $requires_driver_license */ -function AngelType_update($angeltype_id, $name, $restricted, $description) { +function AngelType_update($angeltype_id, $name, $restricted, $description, $requires_driver_license) { return sql_query(" UPDATE `AngelTypes` SET `name`='" . sql_escape($name) . "', - `restricted`='" . sql_escape($restricted ? 1 : 0) . "', - `description`='" . sql_escape($description) . "' + `restricted`=" . sql_bool($restricted) . ", + `description`='" . sql_escape($description) . "', + `requires_driver_license`=" . sql_bool($requires_driver_license) . " WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1"); } @@ -38,12 +40,13 @@ function AngelType_update($angeltype_id, $name, $restricted, $description) { * @param string $description * @return New Angeltype id */ -function AngelType_create($name, $restricted, $description) { +function AngelType_create($name, $restricted, $description, $requires_driver_license) { $result = sql_query(" INSERT INTO `AngelTypes` SET `name`='" . sql_escape($name) . "', - `restricted`='" . sql_escape($restricted ? 1 : 0) . "', - `description`='" . sql_escape($description) . "'"); + `restricted`=" . sql_bool($restricted) . ", + `description`='" . sql_escape($description) . "', + `requires_driver_license`=" . sql_bool($requires_driver_license)); if ($result === false) return false; return sql_id(); diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index b2ebd9fe..f942483e 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -1,8 +1,14 @@ ' . $parsedown->parse($angeltype['description']) . ''; - - // Team-Coordinators list missing $coordinators = array(); $members_confirmed = array(); $members_unconfirmed = array(); foreach ($members as $member) { $member['Nick'] = User_Nick_render($member); + + if ($angeltype['requires_driver_license']) { + $member['wants_to_drive'] = glyph_bool($member['user_id']); + $member['has_car'] = glyph_bool($member['has_car']); + $member['has_license_car'] = glyph_bool($member['has_license_car']); + $member['has_license_3_5t_transporter'] = glyph_bool($member['has_license_3_5t_transporter']); + $member['has_license_7_5t_truck'] = glyph_bool($member['has_license_7_5t_truck']); + $member['has_license_12_5t_truck'] = glyph_bool($member['has_license_12_5t_truck']); + $member['has_license_forklift'] = glyph_bool($member['has_license_forklift']); + } + if ($angeltype['restricted'] && $member['confirm_user_id'] == null) { $member['actions'] = table_buttons([ button(page_link_to('user_angeltypes') . '&action=confirm&user_angeltype_id=' . $member['user_angeltype_id'], _("confirm"), 'btn-xs'), @@ -125,13 +141,30 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel $members_confirmed[] = $member; } } - if (count($coordinators) > 0) { - $page[] = '

' . _("Coordinators") . '

'; - $page[] = table(array( + + $table_headers = [ + 'Nick' => _("Nick"), + 'DECT' => _("DECT"), + 'actions' => '' + ]; + + if ($angeltype['requires_driver_license'] && ($coordinator || $admin_angeltypes)) + $table_headers = [ 'Nick' => _("Nick"), 'DECT' => _("DECT"), - 'actions' => "" - ), $coordinators); + 'wants_to_drive' => _("Driver"), + 'has_car' => _("Has car"), + 'has_license_car' => _("Car"), + 'has_license_3_5t_transporter' => _("3,5t Transporter"), + 'has_license_7_5t_truck' => _("7,5t Truck"), + 'has_license_12_5t_truck' => _("12,5t Truck"), + 'has_license_forklift' => _("Forklift"), + 'actions' => '' + ]; + + if (count($coordinators) > 0) { + $page[] = '

' . _("Coordinators") . '

'; + $page[] = table($table_headers, $coordinators); } if (count($members_confirmed) > 0) @@ -150,26 +183,18 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel $page[] = '

' . _("Members") . '

'; if ($admin_user_angeltypes) - $page[] = buttons(array( + $page[] = buttons([ button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') - )); - $page[] = table(array( - 'Nick' => _("Nick"), - 'DECT' => _("DECT"), - 'actions' => "" - ), $members_confirmed); + ]); + $page[] = table($table_headers, $members_confirmed); if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) { $page[] = '

' . _("Unconfirmed") . '

'; - $page[] = buttons(array( + $page[] = buttons([ button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'], _("confirm all"), 'ok'), button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel') - )); - $page[] = table(array( - 'Nick' => _("Nick"), - 'DECT' => _("DECT"), - 'actions' => "" - ), $members_unconfirmed); + ]); + $page[] = table($table_headers, $members_unconfirmed); } return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page);