Skip to content
Permalink
Browse files

Добавлено поле status_updated, исправлены ошибки

  • Loading branch information...
Krinopotam committed Sep 30, 2019
1 parent 66b8ad4 commit 030bd852829879b8b7a577d4f3c848c32a39bf38
@@ -171,7 +171,7 @@ function admin(&$out)
$out['ADMIN_PASSWORD'] = $this->config['ADMIN_PASSWORD'];
$out['UPDATE_PERIOD'] = $this->config['UPDATE_PERIOD'];
if (!$out['UPDATE_PERIOD']) { $out['UPDATE_PERIOD'] = '10'; }
//if (!$out['UPDATE_PERIOD']) { $out['UPDATE_PERIOD'] = '10'; }
if ($this->view_mode == 'update_settings')
{
@@ -185,6 +185,7 @@ function admin(&$out)
$this->config['UPDATE_PERIOD'] = $update_period;
$this->saveConfig();
setGlobal('cycle_keenetic_lan_devices', 'restart');
$this->redirect("?");
}
if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source'])
@@ -285,10 +286,9 @@ function edit_keenetic_lan_devices(&$out, $id)
*/
function delete_keenetic_lan_devices($id)
{
$rec = SQLSelectOne("SELECT * FROM keenetic_lan_devices WHERE ID='" . DBSafe($id) . "'");
// some action for related tables
SQLExec("DELETE FROM keenetic_lan_devices WHERE ID='" . DBSafe($rec['ID']) . "'");
SQLExec("DELETE FROM keenetic_lan_devices_values WHERE DEVICE_ID='" . DBSafe($rec['ID']) . "'");
SQLExec("DELETE FROM keenetic_lan_devices WHERE ID='" . DBSafe($id) . "'");
SQLExec("DELETE FROM keenetic_lan_devices_values WHERE DEVICE_ID='" . DBSafe($id) . "'");
}
/**
@@ -361,11 +361,15 @@ function updateDevices()
$equipmentsInDb = SQLSelect("SELECT * FROM keenetic_lan_devices ");
$previousStatus=0;
//проходим по устройствам, которые есть в БД
foreach ($equipmentsInDb as $key => $value)
{
if (!isset($equipments[$value["MAC"]])) {continue;}
$previousStatus=(int)$value["ONLINE"];
$value["HOST_NAME"] = $equipments[$value["MAC"]]["HOST_NAME"];
$value["DEVICE_NAME"] = $equipments[$value["MAC"]]["DEVICE_NAME"];
$value["IP"] = $equipments[$value["MAC"]]["IP"];
@@ -374,7 +378,7 @@ function updateDevices()
$value['UPDATED'] = date('Y-m-d H:i:s');
SQLUpdate('keenetic_lan_devices', $value);
$this->updateValues($value['ID'], $equipments[$value["MAC"]]);
$this->updateValues($value['ID'], $equipments[$value["MAC"]], $previousStatus);
unset($equipments[$value["MAC"]]);
}
@@ -394,11 +398,13 @@ function updateDevices()
$newEquipment["REGISTERED"] = $value["REGISTERED"];
$newEquipment["ONLINE"] = $value["STATUS"];
$previousStatus = $value["STATUS"]==0 ? 1 : 0;
$newEquipment['ID'] = SQLInsert('keenetic_lan_devices', $newEquipment);
if (!$newEquipment['ID']) {return;}
$this->updateValues($newEquipment['ID'], $value);
$this->updateValues($newEquipment['ID'], $value, $previousStatus);
}
}
@@ -455,8 +461,9 @@ private function getAllDevicesInfo()
* Обновление значений устройства
* @param int $deviceId устройства в БД
* @param array $values значения устройства
* @param $previousStatus - значения предыдущего статуса в БД
*/
function updateValues($deviceId, $values)
function updateValues($deviceId, $values, $previousStatus)
{
if (!is_array($values)) {return;}
@@ -470,6 +477,15 @@ function updateValues($deviceId, $values)
$rec_val['DESCRIPTION'] = " (R/O) Статус";
$rec_val['VALUE'] = $values['STATUS'];
$rec_vals[] = $rec_val;
if ($previousStatus != $values['STATUS'])
{
$rec_val['DEVICE_ID'] = $deviceId;
$rec_val['TITLE'] = "status_updated";
$rec_val['DESCRIPTION'] = " (R/O) Последнее изменение статуса";
$rec_val['VALUE'] = date("Y-m-d H:i:s");
$rec_vals[] = $rec_val;
}
}
if (isset($values['MAC']))
@@ -595,7 +611,7 @@ function log($message)
mkdir(ROOT . 'cms/debmes', 0777);
}
$today_file = ROOT . 'cms/debmes/log_' . date('Y-m-d') . '-keenetic_lan_devices.php.txt';
$today_file = ROOT . 'cms/debmes/' . date('Y-m-d') . '-keenetic_lan_devices.txt';
$data = date("H:i:s") . " " . $message . "\n";
file_put_contents($today_file, $data, FILE_APPEND | LOCK_EX);
}
@@ -52,56 +52,10 @@
// step: default
if ($this->tab == '')
{
$updated_minutes="";
$updated_hours="";
if ($rec['UPDATED'] != '')
{
$tmp = explode(' ', $rec['UPDATED']);
$out['UPDATED_DATE'] = fromDBDate($tmp[0]);
$tmp2 = explode(':', $tmp[1]);
$updated_hours = $tmp2[0];
$updated_minutes = $tmp2[1];
}
for ($i = 0; $i < 60; $i++)
{
$title = $i;
if ($i < 10)
{
$title = "0$i";
}
if ($title == $updated_minutes)
{
$out['UPDATED_MINUTES'][] = array('TITLE' => $title, 'SELECTED' => 1);
}
else
{
$out['UPDATED_MINUTES'][] = array('TITLE' => $title);
}
}
for ($i = 0; $i < 24; $i++)
{
$title = $i;
if ($i < 10)
{
$title = "0$i";
}
if ($title == $updated_hours)
{
$out['UPDATED_HOURS'][] = array('TITLE' => $title, 'SELECTED' => 1);
}
else
{
$out['UPDATED_HOURS'][] = array('TITLE' => $title);
}
}
}
// step: data
if ($this->tab == 'data')
{
}
// step: data
if ($this->tab == 'data')
{
//dataset2
@@ -56,8 +56,8 @@
for ($i = 0; $i < $total; $i++)
{
// some action for every record if required
$tmp = explode(' ', $res[$i]['UPDATED']);
$res[$i]['UPDATED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
//$tmp = explode(' ', $res[$i]['UPDATED']);
//$res[$i]['UPDATED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
}
$out['RESULT'] = $res;
}
@@ -12,20 +12,20 @@
//$ctl = new control_modules();
include_once(DIR_MODULES . 'keenetic_lan_devices/keenetic_lan_devices.class.php');
$keenetic_lan_devices_module = new keenetic_lan_devices();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
$keenetic_lan_devices_module->getConfig();
$sleepTime = (int)$keenetic_lan_devices_module->config['UPDATE_PERIOD'];
while (TRUE)
if ($sleepTime == 0)
{
$keenetic_lan_devices_module->getConfig();
$sleepTime = (int)$keenetic_lan_devices_module->config['UPDATE_PERIOD'];
setGlobal('cycle_keenetic_lan_devices', 'stop');
setGlobal('cycle_keenetic_lan_devices', '0');
exit;
}
if ($sleepTime == 0) //'период обновления не указан, значит не обновляем, пока не будет указан
{
sleep(30);
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
continue;
}
setGlobal('cycle_keenetic_lan_devices', '1');
while (TRUE)
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
$keenetic_lan_devices_module->processCycle();
@@ -1,8 +1,11 @@
<!-- table zwave_devices search -->
<div>
[ <a href="#" onClick="$('#api_settings').toggle();return false;"><#LANG_SETUP#></a> ]
<!-- table keenetic_lan_devices search -->
<div class="row">
<div class="col-md-6">
<a class="btn btn-default" href="#api_settings" data-toggle="collapse"><i class="glyphicon glyphicon-cog"></i> <#LANG_SETUP#></a>
</div>
</div>
<div style="display:none" id='api_settings'>

<div class="collapse" id='api_settings'>
&nbsp;
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
<fieldset>
@@ -24,7 +27,7 @@
<div class="controls"><input type="text" name="update_period" value="[#UPDATE_PERIOD#]" class="input"></div>
</div>
<div class="form-actions">
<button type="submit" name="subm" value="Submit" class="btn btn-primary"><#LANG_UPDATE#></button>
<button type="submit" name="subm" value="Submit" class="btn btn-primary">Сохранить</button>
<input type="hidden" name="view_mode" value="update_settings">
<input type="hidden" name="mode" value="update">
</div>
@@ -1,10 +1,15 @@
<!-- table keenetic_lan_devices search -->
<p></p>
<p>
<a href="?view_mode=update_keenetic_lan_devices" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i>
<#LANG_UPDATE#>
</a>
</p>

<div class="row">
<div class="col-md-6">
<a href="?view_mode=update_keenetic_lan_devices" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i> <#LANG_UPDATE#></a>
</div>
<div class="col-md-6">
[#module name="xray" action="service" cycle="keenetic_lan_devices"#]
</div>
</div>
<p></p>
<table width=100% border=0>
<tr>
<td valign=top>

0 comments on commit 030bd85

Please sign in to comment.
You can’t perform that action at this time.