2015-12-19 23:31:08 +01:00
|
|
|
<?php
|
|
|
|
|
2015-12-20 11:36:12 +01:00
|
|
|
/**
|
2017-01-02 15:43:36 +01:00
|
|
|
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
|
|
|
|
* information provided.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return string|null
|
2015-12-20 11:36:12 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_driver_license_required_hint()
|
|
|
|
{
|
|
|
|
global $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$angeltypes = User_angeltypes($user);
|
|
|
|
$user_driver_license = UserDriverLicense($user['UID']);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
|
|
|
// User has already entered data, no hint needed.
|
|
|
|
if ($user_driver_license != null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($angeltypes as $angeltype) {
|
|
|
|
if ($angeltype['requires_driver_license']) {
|
2017-01-02 15:43:36 +01:00
|
|
|
return sprintf(
|
2017-01-03 14:12:17 +01:00
|
|
|
_('You joined an angeltype which requires a driving license. Please edit your driving license information here: %s.'),
|
|
|
|
'<a href="' . user_driver_license_edit_link() . '">' . _('driving license information') . '</a>'
|
2017-01-02 15:43:36 +01:00
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2015-12-20 11:36:12 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return null;
|
2015-12-20 11:36:12 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 23:31:08 +01:00
|
|
|
/**
|
|
|
|
* Route user driver licenses actions.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_driver_licenses_controller()
|
|
|
|
{
|
|
|
|
global $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
|
|
|
if (!isset($user)) {
|
2017-01-02 03:57:23 +01:00
|
|
|
redirect(page_link_to(''));
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$action = strip_request_item('action', 'edit');
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
switch ($action) {
|
2017-01-02 15:43:36 +01:00
|
|
|
default:
|
|
|
|
case 'edit':
|
|
|
|
return user_driver_license_edit_controller();
|
|
|
|
}
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link to user driver license edit page for given user.
|
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param array $user
|
|
|
|
* @return string
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_driver_license_edit_link($user = null)
|
|
|
|
{
|
|
|
|
if ($user == null) {
|
|
|
|
return page_link_to('user_driver_licenses');
|
|
|
|
}
|
|
|
|
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-10 13:55:16 +01:00
|
|
|
* Loads the user for the driver license.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_driver_license_load_user()
|
|
|
|
{
|
|
|
|
global $user;
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 03:57:23 +01:00
|
|
|
$user_source = $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('user_id')) {
|
|
|
|
$user_source = User($request->input('user_id'));
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($user_source == null) {
|
|
|
|
redirect(user_driver_license_edit_link());
|
|
|
|
}
|
2016-09-29 09:43:08 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return $user_source;
|
2016-11-10 13:55:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a users driver license information.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2016-11-10 13:55:16 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function user_driver_license_edit_controller()
|
|
|
|
{
|
|
|
|
global $privileges, $user;
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 03:57:23 +01:00
|
|
|
$user_source = user_driver_license_load_user();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
|
|
|
// only privilege admin_user can edit other users driver license information
|
|
|
|
if ($user['UID'] != $user_source['UID'] && !in_array('admin_user', $privileges)) {
|
|
|
|
redirect(user_driver_license_edit_link());
|
|
|
|
}
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$user_driver_license = UserDriverLicense($user_source['UID']);
|
|
|
|
if ($user_driver_license == null) {
|
|
|
|
$wants_to_drive = false;
|
|
|
|
$user_driver_license = UserDriverLicense_new();
|
|
|
|
} else {
|
|
|
|
$wants_to_drive = true;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('submit')) {
|
|
|
|
$wants_to_drive = $request->has('wants_to_drive');
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($wants_to_drive) {
|
2017-07-18 21:38:53 +02:00
|
|
|
$user_driver_license['has_car'] = $request->has('has_car');
|
|
|
|
$user_driver_license['has_license_car'] = $request->has('has_license_car');
|
|
|
|
$user_driver_license['has_license_3_5t_transporter'] = $request->has('has_license_3_5t_transporter');
|
|
|
|
$user_driver_license['has_license_7_5t_truck'] = $request->has('has_license_7_5t_truck');
|
|
|
|
$user_driver_license['has_license_12_5t_truck'] = $request->has('has_license_12_5t_truck');
|
|
|
|
$user_driver_license['has_license_forklift'] = $request->has('has_license_forklift');
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if (UserDriverLicense_valid($user_driver_license)) {
|
|
|
|
if ($user_driver_license['user_id'] == null) {
|
2017-01-22 01:16:00 +01:00
|
|
|
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source);
|
2017-01-02 03:57:23 +01:00
|
|
|
} else {
|
|
|
|
UserDriverLicenses_update($user_driver_license);
|
|
|
|
}
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_log('Driver license information updated.');
|
|
|
|
success(_('Your driver license information has been saved.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
redirect(user_link($user_source));
|
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
error(_('Please select at least one driving license.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-22 01:16:00 +01:00
|
|
|
} elseif ($user_driver_license['user_id'] != null) {
|
2017-01-02 03:57:23 +01:00
|
|
|
UserDriverLicenses_delete($user_source['UID']);
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_log('Driver license information removed.');
|
|
|
|
success(_('Your driver license information has been removed.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
redirect(user_link($user_source));
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return [
|
2017-01-03 14:12:17 +01:00
|
|
|
sprintf(_('Edit %s driving license information'), $user_source['Nick']),
|
2017-01-02 15:43:36 +01:00
|
|
|
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
|
|
|
];
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|