From facc32f13331498999ee07d467ea4ef420ebf190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Sat, 19 Dec 2015 23:31:08 +0100 Subject: [PATCH] #198 add basic driver license information --- db/update.sql | 13 ++ includes/controller/angeltypes_controller.php | 6 - .../user_driver_licenses_controller.php | 118 ++++++++++++++++++ includes/engelsystem_provider.php | 3 + includes/model/UserDriverLicenses_model.php | 69 ++++++++++ includes/view/UserDriverLicenses_view.php | 56 +++++++++ includes/view/User_view.php | 1 + public/index.php | 3 + 8 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 includes/controller/user_driver_licenses_controller.php create mode 100644 includes/model/UserDriverLicenses_model.php create mode 100644 includes/view/UserDriverLicenses_view.php diff --git a/db/update.sql b/db/update.sql index e69de29b..402812c4 100644 --- a/db/update.sql +++ b/db/update.sql @@ -0,0 +1,13 @@ +-- drivers license information +CREATE TABLE IF NOT EXISTS `UserDriverLicenses` ( + `user_id` int(11) NOT NULL, + `has_car` tinyint(1) NOT NULL, + `has_license_car` tinyint(1) NOT NULL, + `has_license_3_5t_transporter` tinyint(1) NOT NULL, + `has_license_7_5t_truck` tinyint(1) NOT NULL, + `has_license_12_5t_truck` tinyint(1) NOT NULL, + `has_license_forklift` tinyint(1) NOT NULL, + PRIMARY KEY (`user_id`) +) 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; diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 44427f5b..d174b890 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -202,24 +202,18 @@ function angeltypes_list_controller() { foreach ($angeltypes as &$angeltype) { $actions = array( button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'],_("view"),"btn-xs") - //'' . _("view") . '' ); if (in_array('admin_angel_types', $privileges)) { $actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs"); $actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs"); - - //$actions[] = '' . _("edit") . ''; - //$actions[] = '' . _("delete") . ''; } $angeltype['membership'] = AngelType_render_membership($angeltype); if ($angeltype['user_angeltype_id'] != null) { - //$actions[] = '' . _("leave") . ''; $actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs"); } else { $actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs"); - //$actions[] = '' . _("join") . ''; } $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : ''; diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php new file mode 100644 index 00000000..b18a78b6 --- /dev/null +++ b/includes/controller/user_driver_licenses_controller.php @@ -0,0 +1,118 @@ + \ No newline at end of file diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 9ad3970a..30bfae7d 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -19,6 +19,7 @@ require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php'); require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php'); require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php'); +require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserGroups_model.php'); require_once realpath(__DIR__ . '/../includes/model/User_model.php'); @@ -29,6 +30,7 @@ require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php'); require_once realpath(__DIR__ . '/../includes/view/UserAngelTypes_view.php'); +require_once realpath(__DIR__ . '/../includes/view/UserDriverLicenses_view.php'); require_once realpath(__DIR__ . '/../includes/view/User_view.php'); require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php'); @@ -37,6 +39,7 @@ require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php') require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/users_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/user_angeltypes_controller.php'); +require_once realpath(__DIR__ . '/../includes/controller/user_driver_licenses_controller.php'); require_once realpath(__DIR__ . '/../includes/helper/graph_helper.php'); require_once realpath(__DIR__ . '/../includes/helper/internationalization_helper.php'); diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php new file mode 100644 index 00000000..b99c8b1b --- /dev/null +++ b/includes/model/UserDriverLicenses_model.php @@ -0,0 +1,69 @@ + 0) + return $user_driver_license[0]; + return null; +} + +/** + * Create a user's driver license entry + * + * @param bool $user_id + * @param bool $has_car + * @param bool $has_license_car + * @param bool $has_license_3_5t_transporter + * @param bool $has_license_7_5t_truck + * @param bool $has_license_12_5t_truck + * @param bool $has_license_forklift + */ +function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) { + return sql_query(" + INSERT INTO `UserDriverLicenses` SET + `user_id`=" . sql_escape($user_id) . ", + `has_car`=" . sql_bool($has_car) . ", + `has_license_car`=" . sql_bool($has_license_car) . ", + `has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ", + `has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ", + `has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ", + `has_license_forklift`=" . sql_bool($has_license_forklift)); +} + +/** + * Update a user's driver license entry + * + * @param bool $user_id + * @param bool $has_car + * @param bool $has_license_car + * @param bool $has_license_3_5t_transporter + * @param bool $has_license_7_5t_truck + * @param bool $has_license_12_5t_truck + * @param bool $has_license_forklift + */ +function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) { + return sql_query("UPDATE `UserDriverLicenses` SET + `has_car`=" . sql_bool($has_car) . ", + `has_license_car`=" . sql_bool($has_license_car) . ", + `has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ", + `has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ", + `has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ", + `has_license_forklift`=" . sql_bool($has_license_forklift) . " + WHERE `user_id`='" . sql_escape($user_id) . "'"); +} + +/** + * Delete a user's driver license entry + * + * @param int $user_id + */ +function UserDriverLicenses_delete($user_id) { + return sql_query("DELETE FROM `UserDriverLicenses` WHERE `user_id`=" . sql_escape($user_id)); +} +?> \ No newline at end of file diff --git a/includes/view/UserDriverLicenses_view.php b/includes/view/UserDriverLicenses_view.php new file mode 100644 index 00000000..041c8734 --- /dev/null +++ b/includes/view/UserDriverLicenses_view.php @@ -0,0 +1,56 @@ + + $(function() { + if($("#wants_to_drive").is(":checked")) + $("#driving_license").show(); + else + $("#driving_license").hide(); + + $("#wants_to_drive").click( + function(e) { + if($("#wants_to_drive").is(":checked")) + $("#driving_license").show(); + else + $("#driving_license").hide(); + } + ); + }); + ' + ]); +} + +?> \ No newline at end of file diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 3ab5f816..90e849a6 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -205,6 +205,7 @@ function User_view($user_source, $admin_user_privilege, $freeloader, $user_angel div('col-md-12', array( buttons(array( $admin_user_privilege ? button(page_link_to('admin_user') . '&id=' . $user_source['UID'], glyph("edit") . _("edit")) : '', + $admin_user_privilege ? button(user_driver_license_edit_link($user_source), glyph("road") . _("driving license")) : '', ($admin_user_privilege && ! $user_source['Gekommen']) ? button(page_link_to('admin_arrive') . '&arrived=' . $user_source['UID'], _("arrived")) : '', $admin_user_privilege ? button(page_link_to('users') . '&action=edit_vouchers&user_id=' . $user_source['UID'], glyph('cutlery') . _('Edit vouchers')) : '', $its_me ? button(page_link_to('user_settings'), glyph('list-alt') . _("Settings")) : '', diff --git a/public/index.php b/public/index.php index 520649ed..08bbaead 100644 --- a/public/index.php +++ b/public/index.php @@ -9,6 +9,7 @@ $free_pages = array( 'credits', 'angeltypes', 'users', + 'user_driver_licenses', 'ical', 'shifts_json_export', 'shifts', @@ -58,6 +59,8 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i list($title, $content) = users_controller(); } elseif ($p == "user_angeltypes") { list($title, $content) = user_angeltypes_controller(); + } elseif ($p == "user_driver_licenses") { + list($title, $content) = user_driver_licenses_controller(); } elseif ($p == "shifttypes") { list($title, $content) = shifttypes_controller(); } elseif ($p == "news") {