Permalink
Browse files

Initial commit

  • Loading branch information...
sergejey committed Dec 3, 2018
1 parent 79479ae commit c5e1a8dfaa0d16646ee8816f90c4a8ffce4ba24c
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,50 @@
<?php
/*
* @version 0.1 (wizard)
*/
if ($this->owner->name=='panel') {
$out['CONTROLPANEL']=1;
}
$table_name='wirenboard_devices';
$rec=SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
if ($this->mode=='update') {
$ok=1;
//updating '<%LANG_TITLE%>' (varchar, required)
$rec['TITLE']=gr('title');
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
}
//updating 'MQTT_HOST' (varchar)
$rec['MQTT_HOST']=gr('mqtt_host');
//updating 'MQTT_USERNAME' (varchar)
$rec['MQTT_USERNAME']=gr('mqtt_username');
//updating 'MQTT_PASSWORD' (varchar)
$rec['MQTT_PASSWORD']=gr('mqtt_password');
//updating 'MQTT_PORT' (varchar)
$rec['MQTT_PORT']=gr('mqtt_port');
//updating 'MQTT_QUERY' (varchar)
$rec['MQTT_QUERY']=gr('mqtt_query');
//UPDATING RECORD
if ($ok) {
if ($rec['ID']) {
SQLUpdate($table_name, $rec); // update
} else {
$new_rec=1;
$rec['ID']=SQLInsert($table_name, $rec); // adding new record
}
$out['OK']=1;
$this->restartCycle();
$this->redirect("?data_source=".$this->data_source);
} else {
$out['ERR']=1;
}
}
if (is_array($rec)) {
foreach($rec as $k=>$v) {
if (!is_array($v)) {
$rec[$k]=htmlspecialchars($v);
}
}
}
outHash($rec, $out);
@@ -0,0 +1,30 @@
<?php
/*
* @version 0.1 (wizard)
*/
global $session;
if ($this->owner->name=='panel') {
$out['CONTROLPANEL']=1;
}
$qry="1";
// search filters
// QUERY READY
global $save_qry;
if ($save_qry) {
$qry=$session->data['wirenboard_devices_qry'];
} else {
$session->data['wirenboard_devices_qry']=$qry;
}
if (!$qry) $qry="1";
$sortby_wirenboard_devices="ID DESC";
$out['SORTBY']=$sortby_wirenboard_devices;
// SEARCH RESULTS
$res=SQLSelect("SELECT * FROM wirenboard_devices WHERE $qry ORDER BY ".$sortby_wirenboard_devices);
if ($res[0]['ID']) {
//paging($res, 100, $out); // search result paging
$total=count($res);
for($i=0;$i<$total;$i++) {
// some action for every record if required
}
$out['RESULT']=$res;
}
@@ -0,0 +1,115 @@
<?php
/*
* @version 0.1 (wizard)
*/
if ($this->owner->name == 'panel') {
$out['CONTROLPANEL'] = 1;
}
$table_name = 'wirenboard';
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
if ($this->mode == 'update') {
$ok = 1;
//updating 'TITLE' (varchar, required)
/*
global $title;
$rec['TITLE']=$title;
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
}
*/
//updating 'LOCATION_ID' (select)
if (IsSet($this->location_id)) {
$rec['LOCATION_ID'] = $this->location_id;
} else {
global $location_id;
$rec['LOCATION_ID'] = $location_id;
}
//updating 'PATH' (varchar, required)
global $path;
$rec['PATH'] = $path;
if ($rec['PATH'] == '') {
$out['ERR_PATH'] = 1;
$ok = 0;
}
global $path_write;
$rec['PATH_WRITE'] = trim($path_write);
global $disp_flag;
$rec['DISP_FLAG'] = (int)$disp_flag;
global $qos;
$rec['QOS'] = (int)$qos;
global $retain;
$rec['RETAIN'] = (int)$retain;
$rec['REPLACE_LIST'] = trim(gr('replace_list'));
$old_linked_object = $rec['LINKED_OBJECT'];
$old_linked_property = $rec['LINKED_PROPERTY'];
//updating 'LINKED_OBJECT' (varchar)
global $linked_object;
$rec['LINKED_OBJECT'] = $linked_object;
//updating 'LINKED_PROPERTY' (varchar)
global $linked_property;
$rec['LINKED_PROPERTY'] = $linked_property;
//UPDATING RECORD
if ($ok) {
if ($rec['ID']) {
SQLUpdate($table_name, $rec); // update
} else {
$new_rec = 1;
$rec['ID'] = SQLInsert($table_name, $rec); // adding new record
}
if ($old_linked_object && $old_linked_object != $rec['LINKED_OBJECT'] && $old_linked_property && $old_linked_property != $rec['LINKED_PROPERTY']) {
removeLinkedProperty($old_linked_object, $old_linked_property, $this->name);
}
$out['OK'] = 1;
} else {
$out['ERR'] = 1;
}
global $new_value;
if ($new_value !== '') {
$rec['VALUE'] = $new_value;
SQLUpdate('wirenboard', $rec);
$this->setProperty($rec['ID'], $new_value, 1);
}
}
if ($rec['DATA_TYPE']=='switch') {
$out['SDEVICE_TYPE']='relay';
}
if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) {
addLinkedProperty($rec['LINKED_OBJECT'], $rec['LINKED_PROPERTY'], $this->name);
}
//options for 'LOCATION_ID' (select)
$tmp = SQLSelect("SELECT ID, TITLE FROM locations ORDER BY TITLE");
$locations_total = count($tmp);
for ($locations_i = 0; $locations_i < $locations_total; $locations_i++) {
$location_id_opt[$tmp[$locations_i]['ID']] = $tmp[$locations_i]['TITLE'];
}
for ($i = 0; $i < count($tmp); $i++) {
if ($rec['LOCATION_ID'] == $tmp[$i]['ID']) $tmp[$i]['SELECTED'] = 1;
}
$out['LOCATION_ID_OPTIONS'] = $tmp;
if (is_array($rec)) {
foreach ($rec as $k => $v) {
if (!is_array($v)) {
$rec[$k] = htmlspecialchars($v);
}
}
}
outHash($rec, $out);
?>
@@ -0,0 +1,121 @@
<?php
/*
* @version 0.1 (wizard)
*/
global $session;
if ($this->owner->name == 'panel') {
$out['CONTROLPANEL'] = 1;
}
$qry = "1";
// search filters
//searching 'TITLE' (varchar)
global $title;
if ($title != '') {
$qry .= " AND (wirenboard.TITLE LIKE '%" . DBSafe($title) . "%' OR VALUE LIKE '%" . DBSafe($title) . "%' OR PATH LIKE '%" . DBSafe($title) . "%')";
$out['TITLE'] = $title;
}
global $location_id;
if ($location_id) {
$qry .= " AND wirenboard.LOCATION_ID='" . (int)$location_id . "'";
$out['LOCATION_ID'] = (int)$location_id;
}
$device_id=gr('device_id','int');
if ($device_id) {
$qry.=" AND DEVICE_ID=".$device_id;
$out['DEVICE_ID']=$device_id;
}
if (IsSet($this->location_id)) {
$location_id = $this->location_id;
$qry .= " AND wirenboard.LOCATION_ID='" . $this->location_id . "'";
} else {
global $location_id;
}
// QUERY READY
global $save_qry;
if ($save_qry) {
$qry = $session->data['mqtt_qry'];
} else {
$session->data['mqtt_qry'] = $qry;
}
if (!$qry) $qry = "1";
// FIELDS ORDER
global $sortby_mqtt;
if (!$sortby_mqtt) {
$sortby_mqtt = $session->data['mqtt_sort'];
} else {
if ($session->data['mqtt_sort'] == $sortby_mqtt) {
if (Is_Integer(strpos($sortby_mqtt, ' DESC'))) {
$sortby_mqtt = str_replace(' DESC', '', $sortby_mqtt);
} else {
$sortby_mqtt = $sortby_mqtt . " DESC";
}
}
$session->data['mqtt_sort'] = $sortby_mqtt;
}
//if (!$sortby_mqtt) $sortby_mqtt="ID DESC";
$sortby_mqtt = "UPDATED DESC";
$out['SORTBY'] = $sortby_mqtt;
global $tree;
if (!isset($tree)) {
$tree = (int)$session->data['MQTT_TREE_VIEW'];
} else {
$session->data['MQTT_TREE_VIEW'] = $tree;
}
if (isset($_GET['tree'])) {
$tree = (int)$_GET['tree'];
$this->config['TREE_VIEW'] = $tree;
$this->saveConfig();
} else {
$tree = $this->config['TREE_VIEW'];
}
if ($tree) {
$out['TREE'] = 1;
}
// SEARCH RESULTS
if ($out['TREE']) {
$sortby_mqtt = 'PATH';
}
$res = SQLSelect("SELECT wirenboard.*, wirenboard_devices.TITLE as DEVICE FROM wirenboard LEFT JOIN wirenboard_devices ON wirenboard.DEVICE_ID=wirenboard_devices.ID WHERE $qry ORDER BY " . $sortby_mqtt);
if ($res[0]['ID']) {
if (!$out['TREE']) {
paging($res, 50, $out); // search result paging
}
$total = count($res);
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];
$res[$i]['VALUE'] = str_replace('":', '": ', $res[$i]['VALUE']);
if ($res[$i]['LINKED_OBJECT'] != '') {
$object = SQLSelectOne("SELECT ID,DESCRIPTION FROM objects WHERE TITLE LIKE '" . DBSafe($res[$i]['LINKED_OBJECT']) . "'");
if ($object['DESCRIPTION'] != '') {
$res[$i]['DESCRIPTION'] = $object['DESCRIPTION'];
}
}
$res[$i]['PATH']=$res[$i]['DEVICE'].'/'.$res[$i]['PATH'];
$res[$i]['PATH']=str_replace('//','/',$res[$i]['PATH']);
if ($res[$i]['TITLE'] == $res[$i]['PATH'] && !$out['TREE']) $res[$i]['PATH'] = '';
}
$out['RESULT'] = $res;
if ($out['TREE']) {
$out['RESULT'] = $this->pathToTree($res);
}
}
$out['LOCATIONS'] = SQLSelect("SELECT * FROM locations ORDER BY TITLE");
$devices = SQLSelect("SELECT * FROM wirenboard_devices ORDER BY TITLE");
if (!count($devices)) {
$this->redirect("?data_source=wirenboard_devices&view_mode=edit_wirenboard_devices");
}
$out['DEVICES'] = $devices;
Oops, something went wrong.

0 comments on commit c5e1a8d

Please sign in to comment.