2011-07-19 19:31:07 +02:00
|
|
|
<?php
|
2015-07-12 14:45:58 +02:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_arrive_title()
|
|
|
|
{
|
2017-01-03 14:12:17 +01:00
|
|
|
return _('Arrived 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_arrive()
|
|
|
|
{
|
2017-01-03 14:12:17 +01:00
|
|
|
$msg = '';
|
|
|
|
$search = '';
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
|
|
|
|
|
|
|
if ($request->has('search')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$search = strip_request_item('search');
|
2016-09-29 10:53:17 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-08-30 14:59:27 +02:00
|
|
|
if ($request->has('reset') && preg_match('/^\d+$/', $request->input('reset'))) {
|
2017-07-18 21:38:53 +02:00
|
|
|
$user_id = $request->input('reset');
|
2017-01-02 03:57:23 +01:00
|
|
|
$user_source = User($user_id);
|
|
|
|
if ($user_source != null) {
|
2017-01-21 13:58:53 +01:00
|
|
|
DB::update('
|
2017-01-03 14:12:17 +01:00
|
|
|
UPDATE `User`
|
|
|
|
SET `Gekommen`=0, `arrival_date` = NULL
|
2017-01-21 13:58:53 +01:00
|
|
|
WHERE `UID`=?
|
2017-01-03 14:12:17 +01:00
|
|
|
LIMIT 1
|
2017-01-21 13:58:53 +01:00
|
|
|
', [$user_id]);
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source));
|
|
|
|
success(_('Reset done. Angel has not arrived.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
redirect(user_link($user_source));
|
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$msg = error(_('Angel not found.'), true);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-08-30 14:59:27 +02:00
|
|
|
} elseif ($request->has('arrived') && preg_match('/^\d+$/', $request->input('arrived'))) {
|
2017-07-18 21:38:53 +02:00
|
|
|
$user_id = $request->input('arrived');
|
2017-01-02 03:57:23 +01:00
|
|
|
$user_source = User($user_id);
|
|
|
|
if ($user_source != null) {
|
2017-01-21 13:58:53 +01:00
|
|
|
DB::update('
|
2017-01-03 14:12:17 +01:00
|
|
|
UPDATE `User`
|
2017-01-21 13:58:53 +01:00
|
|
|
SET `Gekommen`=1, `arrival_date`=?
|
|
|
|
WHERE `UID`=?
|
2017-01-03 14:12:17 +01:00
|
|
|
LIMIT 1
|
2017-01-21 13:58:53 +01:00
|
|
|
', [time(), $user_id]);
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source));
|
|
|
|
success(_('Angel has been marked as arrived.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
redirect(user_link($user_source));
|
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$msg = error(_('Angel not found.'), true);
|
2013-11-28 22:49:15 +01:00
|
|
|
}
|
2012-12-26 14:02:27 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$users = DB::select('SELECT * FROM `User` ORDER BY `Nick`');
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_count_at_day = [];
|
|
|
|
$planned_arrival_count_at_day = [];
|
|
|
|
$planned_departure_count_at_day = [];
|
|
|
|
$users_matched = [];
|
2017-01-03 14:12:17 +01:00
|
|
|
if ($search == '') {
|
2017-01-02 03:57:23 +01:00
|
|
|
$tokens = [];
|
2016-09-29 10:53:17 +02:00
|
|
|
} else {
|
2017-01-03 14:12:17 +01:00
|
|
|
$tokens = explode(' ', $search);
|
2016-09-29 10:53:17 +02:00
|
|
|
}
|
2017-01-02 03:57:23 +01:00
|
|
|
foreach ($users as $usr) {
|
|
|
|
if (count($tokens) > 0) {
|
|
|
|
$match = false;
|
2017-01-03 14:12:17 +01:00
|
|
|
$index = join(' ', $usr);
|
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
|
|
|
$usr['nick'] = User_Nick_render($usr);
|
|
|
|
if ($usr['planned_departure_date'] != null) {
|
|
|
|
$usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']);
|
|
|
|
} else {
|
|
|
|
$usr['rendered_planned_departure_date'] = '-';
|
|
|
|
}
|
|
|
|
$usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
|
2017-01-03 14:12:17 +01:00
|
|
|
$usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : '-';
|
|
|
|
$usr['arrived'] = $usr['Gekommen'] == 1 ? _('yes') : '';
|
|
|
|
$usr['actions'] = $usr['Gekommen'] == 1
|
2017-08-28 16:21:10 +02:00
|
|
|
? '<a href="' . page_link_to(
|
|
|
|
'admin_arrive',
|
|
|
|
['reset' => $usr['UID'], 'search' => $search]
|
|
|
|
) . '">' . _('reset') . '</a>'
|
|
|
|
: '<a href="' . page_link_to(
|
|
|
|
'admin_arrive',
|
|
|
|
['arrived' => $usr['UID'], 'search' => $search]
|
|
|
|
) . '">' . _('arrived') . '</a>';
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($usr['arrival_date'] > 0) {
|
|
|
|
$day = date('Y-m-d', $usr['arrival_date']);
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($arrival_count_at_day[$day])) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_count_at_day[$day] = 0;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
$arrival_count_at_day[$day]++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($usr['planned_arrival_date'] != null) {
|
|
|
|
$day = date('Y-m-d', $usr['planned_arrival_date']);
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($planned_arrival_count_at_day[$day])) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_arrival_count_at_day[$day] = 0;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
$planned_arrival_count_at_day[$day]++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) {
|
|
|
|
$day = date('Y-m-d', $usr['planned_departure_date']);
|
2017-01-02 15:43:36 +01:00
|
|
|
if (!isset($planned_departure_count_at_day[$day])) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_departure_count_at_day[$day] = 0;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
$planned_departure_count_at_day[$day]++;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$users_matched[] = $usr;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
ksort($arrival_count_at_day);
|
|
|
|
ksort($planned_arrival_count_at_day);
|
|
|
|
ksort($planned_departure_count_at_day);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$arrival_at_day = [];
|
|
|
|
$arrival_sum = 0;
|
|
|
|
foreach ($arrival_count_at_day as $day => $count) {
|
|
|
|
$arrival_sum += $count;
|
|
|
|
$arrival_at_day[$day] = [
|
2017-01-02 15:43:36 +01:00
|
|
|
'day' => $day,
|
|
|
|
'count' => $count,
|
|
|
|
'sum' => $arrival_sum
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_arrival_at_day = [];
|
|
|
|
$planned_arrival_sum = 0;
|
|
|
|
foreach ($planned_arrival_count_at_day as $day => $count) {
|
|
|
|
$planned_arrival_sum += $count;
|
|
|
|
$planned_arrival_at_day[$day] = [
|
2017-01-02 15:43:36 +01:00
|
|
|
'day' => $day,
|
|
|
|
'count' => $count,
|
|
|
|
'sum' => $planned_arrival_sum
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
$planned_departure_at_day = [];
|
|
|
|
$planned_departure_sum = 0;
|
|
|
|
foreach ($planned_departure_count_at_day as $day => $count) {
|
|
|
|
$planned_departure_sum += $count;
|
|
|
|
$planned_departure_at_day[$day] = [
|
2017-01-02 15:43:36 +01:00
|
|
|
'day' => $day,
|
|
|
|
'count' => $count,
|
|
|
|
'sum' => $planned_departure_sum
|
|
|
|
];
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return page_with_title(admin_arrive_title(), [
|
2017-01-03 03:22:48 +01:00
|
|
|
$msg . msg(),
|
2017-01-02 15:43:36 +01:00
|
|
|
form([
|
2017-01-03 14:12:17 +01:00
|
|
|
form_text('search', _('Search'), $search),
|
|
|
|
form_submit('submit', _('Search'))
|
2017-01-02 15:43:36 +01:00
|
|
|
]),
|
|
|
|
table([
|
2017-01-03 14:12:17 +01:00
|
|
|
'nick' => _('Nickname'),
|
|
|
|
'rendered_planned_arrival_date' => _('Planned arrival'),
|
|
|
|
'arrived' => _('Arrived?'),
|
|
|
|
'rendered_arrival_date' => _('Arrival date'),
|
|
|
|
'rendered_planned_departure_date' => _('Planned departure'),
|
|
|
|
'actions' => ''
|
2017-01-02 15:43:36 +01:00
|
|
|
], $users_matched),
|
|
|
|
div('row', [
|
|
|
|
div('col-md-4', [
|
2017-01-03 14:12:17 +01:00
|
|
|
heading(_('Planned arrival statistics'), 2),
|
2017-01-02 15:43:36 +01:00
|
|
|
bargraph('planned_arrives', 'day', [
|
2017-01-03 14:12:17 +01:00
|
|
|
'count' => _('arrived'),
|
|
|
|
'sum' => _('arrived sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
|
|
|
'sum' => '#888'
|
|
|
|
], $planned_arrival_at_day),
|
|
|
|
table([
|
2017-01-03 14:12:17 +01:00
|
|
|
'day' => _('Date'),
|
|
|
|
'count' => _('Count'),
|
|
|
|
'sum' => _('Sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], $planned_arrival_at_day)
|
|
|
|
]),
|
|
|
|
div('col-md-4', [
|
2017-01-03 14:12:17 +01:00
|
|
|
heading(_('Arrival statistics'), 2),
|
2017-01-02 15:43:36 +01:00
|
|
|
bargraph('arrives', 'day', [
|
2017-01-03 14:12:17 +01:00
|
|
|
'count' => _('arrived'),
|
|
|
|
'sum' => _('arrived sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
|
|
|
'sum' => '#888'
|
|
|
|
], $arrival_at_day),
|
|
|
|
table([
|
2017-01-03 14:12:17 +01:00
|
|
|
'day' => _('Date'),
|
|
|
|
'count' => _('Count'),
|
|
|
|
'sum' => _('Sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], $arrival_at_day)
|
|
|
|
]),
|
|
|
|
div('col-md-4', [
|
2017-01-03 14:12:17 +01:00
|
|
|
heading(_('Planned departure statistics'), 2),
|
2017-01-02 15:43:36 +01:00
|
|
|
bargraph('planned_departures', 'day', [
|
2017-01-03 14:12:17 +01:00
|
|
|
'count' => _('arrived'),
|
|
|
|
'sum' => _('arrived sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], [
|
|
|
|
'count' => '#090',
|
|
|
|
'sum' => '#888'
|
|
|
|
], $planned_departure_at_day),
|
|
|
|
table([
|
2017-01-03 14:12:17 +01:00
|
|
|
'day' => _('Date'),
|
|
|
|
'count' => _('Count'),
|
|
|
|
'sum' => _('Sum')
|
2017-01-02 15:43:36 +01:00
|
|
|
], $planned_departure_at_day)
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]);
|
2011-07-19 19:31:07 +02:00
|
|
|
}
|