diff options
author | msquare <msquare@notrademark.de> | 2016-11-17 14:35:04 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-11-17 14:35:04 +0100 |
commit | 9c4636f5c4dd5d3b7ff12effb553172f8235cfe6 (patch) | |
tree | aa1ac8dc1fdbe18120ec667610eab7f64cc8ac34 /includes/controller | |
parent | b5784e5961c0121f6c4d9f27f75473c56c727a5a (diff) |
reduce complexity of user driver license
Diffstat (limited to 'includes/controller')
-rw-r--r-- | includes/controller/user_driver_licenses_controller.php | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 595fc3b6..818ff86b 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -33,11 +33,9 @@ function user_driver_licenses_controller() { redirect(page_link_to('')); } - if (! isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'edit'; - } + $action = strip_request_item('action', 'edit'); - switch ($_REQUEST['action']) { + switch ($action) { default: case 'edit': return user_driver_license_edit_controller(); @@ -87,64 +85,48 @@ function user_driver_license_edit_controller() { redirect(user_driver_license_edit_link()); } - $wants_to_drive = false; - $has_car = false; - $has_license_car = false; - $has_license_3_5t_transporter = false; - $has_license_7_5t_truck = false; - $has_license_12_5t_truck = false; - $has_license_forklift = false; - $user_driver_license = UserDriverLicense($user_source['UID']); - if ($user_driver_license != null) { + if ($user_driver_license == null) { + $wants_to_drive = false; + $user_driver_license = UserDriverLicense_new($user_source); + } else { $wants_to_drive = true; - $has_car = $user_driver_license['has_car']; - $has_license_car = $user_driver_license['has_license_car']; - $has_license_3_5t_transporter = $user_driver_license['has_license_3_5t_transporter']; - $has_license_7_5t_truck = $user_driver_license['has_license_7_5t_truck']; - $has_license_12_5t_truck = $user_driver_license['has_license_12_5t_truck']; - $has_license_forklift = $user_driver_license['has_license_forklift']; } if (isset($_REQUEST['submit'])) { $valid = true; $wants_to_drive = isset($_REQUEST['wants_to_drive']); - $has_car = isset($_REQUEST['has_car']); - $has_license_car = isset($_REQUEST['has_license_car']); - $has_license_3_5t_transporter = isset($_REQUEST['has_license_3_5t_transporter']); - $has_license_7_5t_truck = isset($_REQUEST['has_license_7_5t_truck']); - $has_license_12_5t_truck = isset($_REQUEST['has_license_12_5t_truck']); - $has_license_forklift = isset($_REQUEST['has_license_forklift']); - - if ($wants_to_drive && ! $has_license_car && ! $has_license_3_5t_transporter && ! $has_license_7_5t_truck && ! $has_license_12_5t_truck && ! $has_license_forklift) { - $valid = false; - error(_("Please select at least one driving license.")); - } - - if ($valid) { - if (! $wants_to_drive && $user_driver_license != null) { - UserDriverLicenses_delete($user_source['UID']); - engelsystem_log("Driver license information removed."); - success(_("Your driver license information has been removed.")); - } else { - if ($wants_to_drive) { - if ($user_driver_license == null) { - $result = UserDriverLicenses_create($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift); - } else { - $result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift); - } - engelsystem_log("Driver license information updated."); + if ($wants_to_drive) { + $user_driver_license['has_car'] = isset($_REQUEST['has_car']); + $user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']); + $user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']); + $user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']); + $user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']); + $user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']); + + if (UserDriverLicense_valid($user_driver_license)) { + if ($user_driver_license == null) { + UserDriverLicenses_create($user_driver_license); + } else { + UserDriverLicenses_update($user_driver_license); } + engelsystem_log("Driver license information updated."); success(_("Your driver license information has been saved.")); + redirect(user_link($user_source)); + } else { + error(_("Please select at least one driving license.")); } - + } elseif ($user_driver_license['id'] != null) { + UserDriverLicenses_delete($user_source['UID']); + engelsystem_log("Driver license information removed."); + success(_("Your driver license information has been removed.")); redirect(user_link($user_source)); } } return [ sprintf(_("Edit %s driving license information"), $user_source['Nick']), - UserDriverLicense_edit_view($user_source, $wants_to_drive, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) + UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) ]; } |