2011-12-17 16:25:54 +01:00
|
|
|
<?php
|
2016-09-29 10:53:17 +02:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
2018-10-11 01:26:34 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_free_title()
|
|
|
|
{
|
2018-08-29 21:55:32 +02:00
|
|
|
return __('Free angels');
|
2013-11-25 21:04:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_free()
|
|
|
|
{
|
|
|
|
global $privileges;
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-03 14:12:17 +01:00
|
|
|
$search = '';
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('search')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$search = strip_request_item('search');
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$angelTypeSearch = '';
|
2017-07-18 21:38:53 +02:00
|
|
|
$angelType = $request->input('angeltype', '');
|
|
|
|
if (!empty($angelType)) {
|
2017-01-21 13:58:53 +01:00
|
|
|
$angelTypeSearch = ' INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '
|
2017-07-18 21:38:53 +02:00
|
|
|
. DB::getPdo()->quote($angelType)
|
2018-10-11 01:26:34 +02:00
|
|
|
. ' AND `UserAngelTypes`.`user_id` = `users`.`id`';
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('confirmed_only')) {
|
2017-01-21 13:58:53 +01:00
|
|
|
$angelTypeSearch .= ' AND `UserAngelTypes`.`confirm_user_id`';
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
$angelTypeSearch .= ') ';
|
2016-09-29 10:53:17 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
|
2017-01-02 03:57:23 +01:00
|
|
|
$angel_types = [
|
2017-01-02 15:43:36 +01:00
|
|
|
'' => 'alle Typen'
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($angel_types_source as $angel_type) {
|
|
|
|
$angel_types[$angel_type['id']] = $angel_type['name'];
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-10-11 01:26:34 +02:00
|
|
|
/** @var User[] $users */
|
|
|
|
$users = User::query()->raw(sprintf('
|
|
|
|
SELECT `users`.*
|
|
|
|
FROM `users`
|
|
|
|
%s
|
|
|
|
LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
|
|
|
|
LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
|
2017-01-21 13:58:53 +01:00
|
|
|
LEFT JOIN `Shifts`
|
|
|
|
ON (
|
|
|
|
`ShiftEntry`.`SID` = `Shifts`.`SID`
|
2018-10-11 01:26:34 +02:00
|
|
|
AND `Shifts`.`start` < %u
|
|
|
|
AND `Shifts`.`end` > %u
|
2017-01-21 13:58:53 +01:00
|
|
|
)
|
2018-10-11 01:26:34 +02:00
|
|
|
WHERE `users_state`.`arrived` = 1
|
2017-01-22 01:02:52 +01:00
|
|
|
AND `Shifts`.`SID` IS NULL
|
2018-10-11 01:26:34 +02:00
|
|
|
GROUP BY `users`.`id`
|
|
|
|
ORDER BY `users`
|
|
|
|
', $angelTypeSearch, time(), time()
|
|
|
|
)
|
2017-01-21 13:58:53 +01:00
|
|
|
);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$free_users_table = [];
|
2017-01-03 14:12:17 +01:00
|
|
|
if ($search == '') {
|
2017-01-02 03:57:23 +01:00
|
|
|
$tokens = [];
|
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$tokens = explode(' ', $search);
|
2012-12-30 17:58:23 +01:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($users as $usr) {
|
|
|
|
if (count($tokens) > 0) {
|
|
|
|
$match = false;
|
2018-10-11 01:26:34 +02:00
|
|
|
$index = join('', $usr->toArray());
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($tokens as $t) {
|
|
|
|
if (stristr($index, trim($t))) {
|
|
|
|
$match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!$match) {
|
2017-01-02 03:57:23 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$free_users_table[] = [
|
2017-01-02 15:43:36 +01:00
|
|
|
'name' => User_Nick_render($usr),
|
|
|
|
'shift_state' => User_shift_state_render($usr),
|
2018-10-11 01:26:34 +02:00
|
|
|
'dect' => $usr->contact->dect,
|
|
|
|
'email' => $usr->settings->email_human ? ($usr->contact->email ? $usr->contact->email : $usr->email) : glyph('eye-close'),
|
2017-01-02 15:43:36 +01:00
|
|
|
'actions' =>
|
|
|
|
in_array('admin_user', $privileges)
|
2018-10-11 01:26:34 +02:00
|
|
|
? button(page_link_to('admin_user', ['id' => $usr->id]), __('edit'), 'btn-xs')
|
2017-01-02 15:43:36 +01:00
|
|
|
: ''
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
|
|
|
return page_with_title(admin_free_title(), [
|
2017-01-02 15:43:36 +01:00
|
|
|
form([
|
|
|
|
div('row', [
|
|
|
|
div('col-md-4', [
|
2018-08-29 21:55:32 +02:00
|
|
|
form_text('search', __('Search'), $search)
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
div('col-md-4', [
|
2018-08-29 21:55:32 +02:00
|
|
|
form_select('angeltype', __('Angeltype'), $angel_types, $angelType)
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
div('col-md-2', [
|
2018-08-29 21:55:32 +02:00
|
|
|
form_checkbox('confirmed_only', __('Only confirmed'), $request->has('confirmed_only'))
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
div('col-md-2', [
|
2018-08-29 21:55:32 +02:00
|
|
|
form_submit('submit', __('Search'))
|
2017-01-02 15:43:36 +01:00
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
table([
|
2018-08-29 21:55:32 +02:00
|
|
|
'name' => __('Nick'),
|
2017-01-02 15:43:36 +01:00
|
|
|
'shift_state' => '',
|
2018-08-29 21:55:32 +02:00
|
|
|
'dect' => __('DECT'),
|
|
|
|
'email' => __('E-Mail'),
|
2017-01-02 15:43:36 +01:00
|
|
|
'actions' => ''
|
|
|
|
], $free_users_table)
|
|
|
|
]);
|
2011-12-17 16:25:54 +01:00
|
|
|
}
|