Skip to content

Commit a68f8f9

Browse files
committed
end date for charts
Ability to select "end" date for charts.
1 parent f229faa commit a68f8f9

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

pChart/index.php

+56-37
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
&gtype=curve - тип графика (может быть: curve, bar, line -- плавная линия, столбцы, ступенчатый)
2222
&type=8h - Период (8h = 8 часов, 8d = 8 дней, 8m = 8 месяцев)
2323
&start=2014/09/25 - дата с которой берется начало графика в формате (гггг/мм/дд)
24+
&end=2014/09/25 - дата с которой берется конец графика в формате (гггг/мм/дд)
2425
&interval= секунд в интервале
2526
&width=610 - ширина графика в пикселях
2627
&height=210 - высота графика в пикселях
@@ -41,7 +42,14 @@
4142
$w_delta = 80;
4243
$px_per_point = 6;
4344
$unit = "°C";
44-
$end_time = time();
45+
46+
if (preg_match('/(\d+)\/(\d+)\/(\d+)/', $_GET['end'], $m)) {
47+
$end_time = mktime(23, 59, 59, $m[2], $m[3], $m[1]);
48+
} else {
49+
$end_time = time();
50+
}
51+
52+
4553
$approx = 'avg';
4654
$fil01 = 0;
4755

@@ -208,13 +216,13 @@
208216
$data = SQLSelect("SELECT * FROM $history_table WHERE VALUE_ID='" . $pvalue['ID'] . "' ORDER BY ADDED");
209217
//dprint($data);
210218

211-
$csv = implode("\t", array('ADDED','VALUE')) . PHP_EOL;
219+
$csv = implode("\t", array('ADDED', 'VALUE')) . PHP_EOL;
212220
foreach ($data as $row) {
213-
$csv .= $row['ADDED']."\t".$row['VALUE'];
221+
$csv .= $row['ADDED'] . "\t" . $row['VALUE'];
214222
$csv .= PHP_EOL;
215223
}
216224

217-
$filename = 'data_'.date('Y-m-d-H_i_s').'.txt';
225+
$filename = 'data_' . date('Y-m-d-H_i_s') . '.txt';
218226
$now = gmdate("D, d M Y H:i:s");
219227
//header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
220228
//header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
@@ -239,6 +247,7 @@
239247

240248
echo "<html><head>";
241249
$roothtml = ROOTHTML;
250+
$url = str_replace('&end=', '&', $_SERVER['REQUEST_URI']);
242251
echo <<<FF
243252
<meta name="apple-mobile-web-app-capable" content="yes">
244253
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
@@ -248,32 +257,42 @@
248257
<script type="text/javascript" src="{$roothtml}3rdparty/jquery/jquery-migrate-3.0.0.min.js"></script>
249258
<link rel="stylesheet" href="{$roothtml}3rdparty/bootstrap/css/bootstrap.min.css" type="text/css">
250259
<script type="text/javascript" src="{$roothtml}3rdparty/bootstrap/js/bootstrap.min.js"></script>
260+
<link rel="stylesheet" type="text/css" href="{$roothtml}3rdparty/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"/>
261+
<script type="text/javascript" src="{$roothtml}3rdparty/moment/moment.min.js"></script>
262+
<script type="text/javascript" src="{$roothtml}3rdparty/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
263+
<script type="text/javascript">
264+
$(document).ready(function() {
265+
$('.datepicker').datetimepicker({
266+
format:'YYYY/MM/DD',
267+
}).on('dp.change',function(e) {
268+
var formatedValue = e.date.format(e.date._f);
269+
dateChanged(formatedValue);
270+
});
271+
});
272+
function dateChanged(dt) {
273+
let url = "{$url}";
274+
window.location.href = url + '&end='+encodeURI(dt);
275+
}
276+
</script>
251277
FF;
252278
echo "</head><body><div>";
253279
//echo "<table width=100%><tr><td width='99%'>";
254280

255281
$_SERVER['REQUEST_URI'] = preg_replace('/&subop=(\w+)/', '', $_SERVER['REQUEST_URI']);
256-
echo "<ul class='nav nav-tabs'>";
257-
echo '<li'.($_GET['subop']==''?' class="active"':'').'><a href="' . $_SERVER['REQUEST_URI'] . '&subop=">H</a></li>';
258-
echo '<li'.($_GET['subop']=='1h'?' class="active"':'').'><a href="' . $_SERVER['REQUEST_URI'] . '&subop=1h">1h</a></li>';
259-
echo '<li'.($_GET['subop']=='24h'?' class="active"':'').'><a href="' . $_SERVER['REQUEST_URI'] . '&subop=24h">24h</a></li>';
260-
echo '<li'.($_GET['subop']=='7d'?' class="active"':'').'><a href="' . $_SERVER['REQUEST_URI'] . '&subop=7d">7d</a></li>';
261-
echo '<li'.($_GET['subop']=='31d'?' class="active"':'').'><a href="' . $_SERVER['REQUEST_URI'] . '&subop=31d">31d</a></li>';
282+
echo "<div class='row'><div class='col-md-10'><ul class='nav nav-tabs'>";
283+
echo '<li' . ($_GET['subop'] == '' ? ' class="active"' : '') . '><a href="' . $_SERVER['REQUEST_URI'] . '&subop=">H</a></li>';
284+
echo '<li' . ($_GET['subop'] == '1h' ? ' class="active"' : '') . '><a href="' . $_SERVER['REQUEST_URI'] . '&subop=1h">1h</a></li>';
285+
echo '<li' . ($_GET['subop'] == '24h' ? ' class="active"' : '') . '><a href="' . $_SERVER['REQUEST_URI'] . '&subop=24h">24h</a></li>';
286+
echo '<li' . ($_GET['subop'] == '7d' ? ' class="active"' : '') . '><a href="' . $_SERVER['REQUEST_URI'] . '&subop=7d">7d</a></li>';
287+
echo '<li' . ($_GET['subop'] == '31d' ? ' class="active"' : '') . '><a href="' . $_SERVER['REQUEST_URI'] . '&subop=31d">31d</a></li>';
262288
if (!$_GET['minimal']) {
263289
echo '<li><a href="' . $_SERVER['REQUEST_URI'] . '&subop=clear" onClick="return confirm(\'' . LANG_ARE_YOU_SURE . '\')">' . LANG_CLEAR_ALL . '</a></li>';
264290
echo '<li><a href="' . $_SERVER['REQUEST_URI'] . '&subop=optimize" onClick="return confirm(\'' . LANG_ARE_YOU_SURE . '\')">' . LANG_OPTIMIZE_LOG . '</a></li>';
265291
}
266292
echo "</ul>";
267-
//echo "</td>";
268-
/*
269-
if (!$_GET['minimal']) {
270-
echo "<td>";
271-
echo '<a href="javascript:window.close();">X</a>';
272-
echo "</td>";
273-
}
274-
*/
275-
//echo "</tr></table>";
276-
//echo '<br/>';
293+
echo "</div><div class='col-md-2'><form class='form' method='get'>";
294+
echo '<input type="text" id="end" name="end" value="' . date('Y-m-d', $end_time) . '" class="form-control datepicker">';
295+
echo "</form></div></div>";
277296

278297
if (preg_match('/^\d+\w$/', $_GET['subop'])) {
279298

@@ -285,26 +304,26 @@
285304
}
286305

287306
if (!is_array($_GET['p'])) {
288-
$properties=array($_GET['p']);
307+
$properties = array($_GET['p']);
289308
} else {
290309
$properties = $_GET['p'];
291310
$p_url .= '&height=' . $height;
292311
}
293312
$p_url = '';
294313
foreach ($properties as $p) {
295314
$p_url .= '&properties[]=' . urlencode($p);
296-
if (preg_match('/^(\w+)\.(\w+)$/',$p,$m)) {
315+
if (preg_match('/^(\w+)\.(\w+)$/', $p, $m)) {
297316
$object = getObject($m[1]);
298317
if ($object->description) {
299-
$p_url .= '&legend[]=' . urlencode($object->description.' ('.$m[2].')');
318+
$p_url .= '&legend[]=' . urlencode($object->description . ' (' . $m[2] . ')');
300319
} else {
301320
$p_url .= '&legend[]=' . urlencode($p);
302321
}
303322
}
304323
}
305-
$code = '&nbsp;<iframe allowfullscreen="true" border="0" frameborder="0" src="' . ROOTHTML . 'module/charts.html?id=config&enable_fullscreen=1&period=' . $_GET['subop'] . '&chart_type=' . urlencode($_GET['chart_type']) . '&group=' . $group . $p_url . '&theme=grid-light&frameBorder=0" style="height:80% !important" width=100% ></iframe>';//height=' . $height . '
324+
$code = '&nbsp;<iframe allowfullscreen="true" border="0" frameborder="0" src="' . ROOTHTML . 'module/charts.html?id=config&enable_fullscreen=1&period=' . $_GET['subop'] . '&end=' . urlencode($_GET['end']) . '&chart_type=' . urlencode($_GET['chart_type']) . '&group=' . $group . $p_url . '&theme=grid-light&frameBorder=0" style="height:80% !important" width=100% ></iframe>';//height=' . $height . '
306325
} else {
307-
$code = '&nbsp;<img src="' . ROOTHTML . '3rdparty/jpgraph/?p=' . $p . '&type=' . $_GET['subop'] . '&width=500&"/>';
326+
$code = '&nbsp;<img src="' . ROOTHTML . '3rdparty/jpgraph/?p=' . $p . '&type=' . $_GET['subop'] . '&end=' . urlencode($_GET['end']) . '&width=500&"/>';
308327
}
309328
echo $code;
310329
/*
@@ -325,33 +344,33 @@
325344
$total_values = count($history);
326345
}
327346
*/
328-
require(ROOT.'3rdparty/Paginator/Paginator.php');
329-
$page=(int)$_GET['page'];
330-
if (!$page) $page=1;
347+
require(ROOT . '3rdparty/Paginator/Paginator.php');
348+
$page = (int)$_GET['page'];
349+
if (!$page) $page = 1;
331350

332-
$on_page=20;
351+
$on_page = 20;
333352
//$limit=(($page-1)*$on_page).','.$on_page;
334-
$start_offset = (($page-1)*$on_page);
353+
$start_offset = (($page - 1) * $on_page);
335354
//$urlPattern='?page=(:num)';
336355
$url = $_SERVER['REQUEST_URI'];
337-
$url = preg_replace('/&page=\d+/','',$url);
338-
$urlPattern=$url.'&page=(:num)';
356+
$url = preg_replace('/&page=\d+/', '', $url);
357+
$urlPattern = $url . '&page=(:num)';
339358
$paginator = new JasonGrimes\Paginator($total_values, $on_page, $page, $urlPattern);
340359

341-
$history = array_slice($history,$start_offset,$on_page);
360+
$history = array_slice($history, $start_offset, $on_page);
342361
$total_values = count($history);
343362

344363
echo "<div class='row'><div class='col-md-1'>&nbsp;</div>";
345364
echo "<div class='col-md-5'>";
346365
echo $paginator;
347366
echo "</div>";
348367
echo "<div class='col-md-5 text-right pagination'>";
349-
echo "<a href=\"".$_SERVER['REQUEST_URI'] . "&type=1&export=1\" class='btn btn-default'><i class='glyphicon glyphicon-export'></i> ".LANG_EXPORT."</a>";
368+
echo "<a href=\"" . $_SERVER['REQUEST_URI'] . "&type=1&export=1\" class='btn btn-default'><i class='glyphicon glyphicon-export'></i> " . LANG_EXPORT . "</a>";
350369
echo "</div>";
351370
echo "<div class='col-md-1'>&nbsp;</div></div>";
352371

353372
echo "<table class='table table-striped'>";
354-
echo "<thead><tr><th>".LANG_ADDED."</th><th>".LANG_VALUE."</th><th>Src</th><th>&nbsp;</th></tr></thead>";
373+
echo "<thead><tr><th>" . LANG_ADDED . "</th><th>" . LANG_VALUE . "</th><th>Src</th><th>&nbsp;</th></tr></thead>";
355374
for ($i = 0; $i < $total_values; $i++) {
356375
//echo date('Y-m-d H:i:s', $history[$i]['UNX']);
357376
echo "<tr><td>";
@@ -361,7 +380,7 @@
361380
if ($property['DATA_TYPE'] == 5) {
362381
echo "<a href='" . ROOTHTML . "cms/images/" . $history[$i]['VALUE'] . "' target='_blank'><img src='" . ROOTHTML . "cms/images/" . $history[$i]['VALUE'] . "' height=100></a>";
363382
} else {
364-
echo "<b>".htmlspecialchars($history[$i]['VALUE']) . "</b>";
383+
echo "<b>" . htmlspecialchars($history[$i]['VALUE']) . "</b>";
365384
}
366385
echo "</td>";
367386
echo "<td>";
@@ -733,7 +752,7 @@
733752

734753
//������� ��������� �������
735754

736-
if (IsSet($_GET['title'])) {
755+
if (isset($_GET['title'])) {
737756
$_GET['title'] = strip_tags($_GET['title']);
738757
}
739758

templates/panel.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,14 @@ <h4 style="font-weight: bold;"><#LANG_NEWDASH_PRELOAD_HEADER#></h4>
392392

393393
if ($(window).scrollTop() > 200 && (document.documentElement.scrollHeight - window.innerHeight) >= 200) {
394394
$("nav").addClass("navbar-fixed-top");
395-
$("nav").attr('style', 'box-shadow: 0px 1px 10px rgb(0 0 0 / 25%);z-index: 99999;border-radius: 4px;border-bottom: 2px solid #4792d1;');
395+
$("nav").attr('style', 'box-shadow: 0px 1px 10px rgb(0 0 0 / 25%);z-index: 999;border-radius: 4px;border-bottom: 2px solid #4792d1;');
396396
}
397397

398398
$(window).on("scroll", function(e) {
399399
if ($(window).scrollTop() > 200 && (document.documentElement.scrollHeight - window.innerHeight) >= 200) {
400400
$("nav").addClass("navbar-fixed-top");
401401
$("body").css('padding-top', '54px');
402-
$("nav").attr('style', 'box-shadow: 0px 1px 10px rgb(0 0 0 / 25%);z-index: 99999;border-radius: 4px;border-bottom: 2px solid #4792d1;');
402+
$("nav").attr('style', 'box-shadow: 0px 1px 10px rgb(0 0 0 / 25%);z-index: 999;border-radius: 4px;border-bottom: 2px solid #4792d1;');
403403
} else {
404404
$("nav").removeClass("navbar-fixed-top");
405405
$("nav").removeAttr('style');

0 commit comments

Comments
 (0)