2011-07-19 19:31:07 +02:00
|
|
|
<?php
|
2015-07-12 14:45:58 +02:00
|
|
|
|
2013-11-25 21:04:58 +01:00
|
|
|
function admin_arrive_title() {
|
|
|
|
return _("Arrived angels");
|
|
|
|
}
|
|
|
|
|
2011-07-19 19:31:07 +02:00
|
|
|
function admin_arrive() {
|
2012-12-26 14:02:27 +01:00
|
|
|
$msg = "";
|
|
|
|
$search = "";
|
2013-11-28 22:49:15 +01:00
|
|
|
if (isset($_REQUEST['search']))
|
2012-12-26 14:02:27 +01:00
|
|
|
$search = strip_request_item('search');
|
2013-11-28 22:49:15 +01:00
|
|
|
|
|
|
|
if (isset($_REQUEST['reset']) && preg_match("/^[0-9]*$/", $_REQUEST['reset'])) {
|
2012-12-26 14:02:27 +01:00
|
|
|
$id = $_REQUEST['reset'];
|
|
|
|
$user_source = User($id);
|
2013-11-28 22:49:15 +01:00
|
|
|
if ($user_source != null) {
|
2015-07-12 14:45:58 +02:00
|
|
|
sql_query("UPDATE `User` SET `Gekommen`=0, `arrival_date` = NULL WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
|
2012-12-30 17:58:23 +01:00
|
|
|
engelsystem_log("User set to not arrived: " . User_Nick_render($user_source));
|
2014-08-22 22:34:13 +02:00
|
|
|
$msg = success(_("Reset done. Angel has not arrived."), true);
|
2013-11-28 22:49:15 +01:00
|
|
|
} else
|
2014-08-22 22:34:13 +02:00
|
|
|
$msg = error(_("Angel not found."), true);
|
2013-11-28 22:49:15 +01:00
|
|
|
} elseif (isset($_REQUEST['arrived']) && preg_match("/^[0-9]*$/", $_REQUEST['arrived'])) {
|
2012-12-26 14:02:27 +01:00
|
|
|
$id = $_REQUEST['arrived'];
|
|
|
|
$user_source = User($id);
|
2013-11-28 22:49:15 +01:00
|
|
|
if ($user_source != null) {
|
2015-07-12 14:45:58 +02:00
|
|
|
sql_query("UPDATE `User` SET `Gekommen`=1, `arrival_date`='" . time() . "' WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
|
2012-12-30 17:58:23 +01:00
|
|
|
engelsystem_log("User set has arrived: " . User_Nick_render($user_source));
|
2014-08-22 22:34:13 +02:00
|
|
|
$msg = success(_("Angel has been marked as arrived."), true);
|
2013-11-28 22:49:15 +01:00
|
|
|
} else
|
2014-08-22 22:34:13 +02:00
|
|
|
$msg = error(_("Angel not found."), true);
|
2012-12-26 14:02:27 +01:00
|
|
|
}
|
2013-11-28 22:49:15 +01:00
|
|
|
|
2012-12-26 14:02:27 +01:00
|
|
|
$users = sql_select("SELECT * FROM `User` ORDER BY `Nick`");
|
2015-07-18 21:27:30 +02:00
|
|
|
$arrival_count_at_day = array();
|
2012-12-26 14:02:27 +01:00
|
|
|
$table = "";
|
2013-11-28 22:49:15 +01:00
|
|
|
$users_matched = array();
|
2012-12-26 14:02:27 +01:00
|
|
|
if ($search == "")
|
2013-11-28 22:49:15 +01:00
|
|
|
$tokens = array();
|
2012-12-26 14:02:27 +01:00
|
|
|
else
|
|
|
|
$tokens = explode(" ", $search);
|
|
|
|
foreach ($users as $usr) {
|
|
|
|
if (count($tokens) > 0) {
|
|
|
|
$match = false;
|
2013-12-27 18:45:27 +01:00
|
|
|
$index = join(" ", $usr);
|
2012-12-26 14:02:27 +01:00
|
|
|
foreach ($tokens as $t)
|
2012-12-27 14:24:05 +01:00
|
|
|
if (stristr($index, trim($t))) {
|
2013-11-28 22:49:15 +01:00
|
|
|
$match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (! $match)
|
2012-12-26 14:02:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-18 21:27:30 +02:00
|
|
|
|
2013-11-28 22:49:15 +01:00
|
|
|
$usr['nick'] = User_Nick_render($usr);
|
2015-07-18 21:27:30 +02:00
|
|
|
$usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
|
|
|
|
$usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-";
|
2013-11-28 22:49:15 +01:00
|
|
|
$usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : "";
|
|
|
|
$usr['actions'] = $usr['Gekommen'] == 1 ? '<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>';
|
2015-07-18 21:27:30 +02:00
|
|
|
|
|
|
|
$day = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : date('Y-m-d', $usr['planned_arrival_date']);
|
|
|
|
if (! isset($arrival_count_at_day[$day]))
|
|
|
|
$arrival_count_at_day[$day] = 0;
|
|
|
|
$arrival_count_at_day[$day] ++;
|
|
|
|
|
2013-11-28 22:49:15 +01:00
|
|
|
$users_matched[] = $usr;
|
2012-12-26 14:02:27 +01:00
|
|
|
}
|
2015-07-18 21:27:30 +02:00
|
|
|
|
|
|
|
ksort($arrival_count_at_day);
|
|
|
|
|
|
|
|
$arrival_count = array();
|
|
|
|
$arrival_sums = array();
|
|
|
|
$arrival_sum = 0;
|
|
|
|
foreach ($arrival_count_at_day as $day => $count) {
|
|
|
|
$arrival_sum += $count;
|
|
|
|
$arrival_sums[$day] = $arrival_sum;
|
|
|
|
$arrival_count[] = array(
|
|
|
|
'day' => $day,
|
|
|
|
'count' => $count,
|
|
|
|
'sum' => $arrival_sum
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-22 22:34:13 +02:00
|
|
|
return page_with_title(admin_arrive_title(), array(
|
2013-11-28 22:49:15 +01:00
|
|
|
msg(),
|
|
|
|
form(array(
|
|
|
|
form_text('search', _("Search"), $search),
|
|
|
|
form_submit('submit', _("Search"))
|
|
|
|
)),
|
|
|
|
table(array(
|
|
|
|
'nick' => _("Nickname"),
|
2015-07-18 21:27:30 +02:00
|
|
|
'rendered_planned_arrival_date' => _("Planned date"),
|
2013-11-28 22:49:15 +01:00
|
|
|
'arrived' => _("Arrived?"),
|
2015-07-18 21:27:30 +02:00
|
|
|
'rendered_arrival_date' => _("Arrival date"),
|
2013-11-28 22:49:15 +01:00
|
|
|
'actions' => ""
|
2015-07-18 21:27:30 +02:00
|
|
|
), $users_matched),
|
|
|
|
heading(_("Arrival statistics"), 2),
|
|
|
|
'<canvas id="daily_arrives" style="width: 100%; height: 300px;"></canvas>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function(){
|
|
|
|
var ctx = $("#daily_arrives").get(0).getContext("2d");
|
2015-07-18 21:32:50 +02:00
|
|
|
var chart = new Chart(ctx).Bar(' . json_encode(array(
|
2015-07-18 21:27:30 +02:00
|
|
|
'labels' => array_keys($arrival_count_at_day),
|
|
|
|
'datasets' => array(
|
|
|
|
array(
|
|
|
|
'label' => _("arrived"),
|
|
|
|
'fillColor' => "#444",
|
|
|
|
'data' => array_values($arrival_count_at_day)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'label' => _("arrived sum"),
|
|
|
|
'fillColor' => "#888",
|
|
|
|
'data' => array_values($arrival_sums)
|
|
|
|
)
|
|
|
|
)
|
2015-07-27 17:36:42 +02:00
|
|
|
)) . ');
|
2015-07-18 21:27:30 +02:00
|
|
|
});
|
2015-07-18 21:34:14 +02:00
|
|
|
</script>',
|
|
|
|
table(array(
|
|
|
|
'day' => _("Date"),
|
|
|
|
'count' => _("arrived"),
|
|
|
|
'sum' => _("arrived sum")
|
|
|
|
), $arrival_count)
|
2012-12-26 14:02:27 +01:00
|
|
|
));
|
2011-07-19 19:31:07 +02:00
|
|
|
}
|
2012-12-27 14:24:05 +01:00
|
|
|
?>
|