You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.6 KiB
PHTML

<?php
use Engelsystem\Database\DB;
/**
* @return string
*/
8 years ago
function admin_free_title()
{
return _('Free angels');
}
/**
* @return string
*/
8 years ago
function admin_free()
{
global $privileges;
8 years ago
$search = '';
8 years ago
if (isset($_REQUEST['search'])) {
$search = strip_request_item('search');
}
8 years ago
$angelTypeSearch = '';
8 years ago
if (empty($_REQUEST['angeltype'])) {
$_REQUEST['angeltype'] = '';
} else {
$angelTypeSearch = ' INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '
. DB::getPdo()->quote($_REQUEST['angeltype'])
. ' AND `UserAngelTypes`.`user_id` = `User`.`UID`';
8 years ago
if (isset($_REQUEST['confirmed_only'])) {
$angelTypeSearch .= ' AND `UserAngelTypes`.`confirm_user_id`';
8 years ago
}
$angelTypeSearch .= ') ';
}
8 years ago
$angel_types_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
8 years ago
$angel_types = [
8 years ago
'' => 'alle Typen'
];
8 years ago
foreach ($angel_types_source as $angel_type) {
$angel_types[$angel_type['id']] = $angel_type['name'];
}
8 years ago
$users = DB::select('
SELECT `User`.*
FROM `User`
' . $angelTypeSearch . '
LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts`
ON (
`ShiftEntry`.`SID` = `Shifts`.`SID`
AND `Shifts`.`start` < ?
AND `Shifts`.`end` > ?
)
WHERE `User`.`Gekommen` = 1
AND `Shifts`.`SID` IS NULL
GROUP BY `User`.`UID`
ORDER BY `Nick`
',
[
time(),
time(),
]
);
8 years ago
8 years ago
$free_users_table = [];
if ($search == '') {
8 years ago
$tokens = [];
} else {
$tokens = explode(' ', $search);
}
8 years ago
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
$index = join('', $usr);
8 years ago
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
break;
}
}
8 years ago
if (!$match) {
8 years ago
continue;
}
}
8 years ago
8 years ago
$free_users_table[] = [
8 years ago
'name' => User_Nick_render($usr),
'shift_state' => User_shift_state_render($usr),
'dect' => $usr['DECT'],
'jabber' => $usr['jabber'],
'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'),
'actions' =>
in_array('admin_user', $privileges)
? button(page_link_to('admin_user') . '&amp;id=' . $usr['UID'], _('edit'), 'btn-xs')
8 years ago
: ''
];
8 years ago
}
return page_with_title(admin_free_title(), [
8 years ago
form([
div('row', [
div('col-md-4', [
form_text('search', _('Search'), $search)
8 years ago
]),
div('col-md-4', [
form_select('angeltype', _('Angeltype'), $angel_types, $_REQUEST['angeltype'])
8 years ago
]),
div('col-md-2', [
form_checkbox('confirmed_only', _('Only confirmed'), isset($_REQUEST['confirmed_only']))
8 years ago
]),
div('col-md-2', [
form_submit('submit', _('Search'))
8 years ago
])
])
]),
table([
'name' => _('Nick'),
8 years ago
'shift_state' => '',
'dect' => _('DECT'),
'jabber' => _('Jabber'),
'email' => _('E-Mail'),
8 years ago
'actions' => ''
], $free_users_table)
]);
}