/** * Title * * Description * * @access public */ function getObject($name) { $rec=SQLSelectOne("SELECT * FROM objects WHERE TITLE LIKE '".DBSafe($name)."'"); if ($rec['ID']) { include_once(DIR_MODULES.'objects/objects.class.php'); $obj=new objects(); $obj->id=$rec['ID']; $obj->loadObject($rec['ID']); return $obj; } return 0; }
function subscribeToEvent($module_name, $event_name, $filter_details = '') { $rec = SQLSelectOne("SELECT * FROM settings WHERE NAME='HOOK_EVENT_" . DBSafe(strtoupper($event_name)) . "'"); if (!$rec['ID']) { $rec = array(); $rec['NAME'] = 'HOOK_EVENT_' . strtoupper($event_name); $rec['TITLE'] = $rec['NAME']; $rec['TYPE'] = 'json'; $rec['PRIORITY'] = 0; $rec['ID'] = SQLInsert('settings', $rec); } $data = json_decode($rec['VALUE'], true); if (!isset($data[$module_name])) { $data[$module_name] = 1; $rec['VALUE'] = json_encode($data); SQLUpdate('settings', $rec); } }
/** * Summary of checkFromCache * @param mixed $key Key * @return mixed */ function checkFromCache($key) { global $memory_cache; if (isset($_SERVER['REQUEST_METHOD']) && !is_array($memory_cache)) { $tmp = SQLSelect("SELECT KEYWORD, DATAVALUE FROM cached_values"); $total = count($tmp); for ($i = 0; $i < $total; $i++) { if ($tmp[$i]['DATAVALUE'] != '(too big)') { $memory_cache[$tmp[$i]['KEYWORD']] = $tmp[$i]['DATAVALUE']; } } } if (isset($memory_cache[$key])) { return $memory_cache[$key]; } $rec = SQLSelectOne("SELECT * FROM cached_values WHERE KEYWORD = '" . DBSafe($key) . "'"); if ($rec['KEYWORD'] && $rec['DATAVALUE'] != '(too big)') { return $rec['DATAVALUE']; } else { return false; } }
/** * Title * * Description * * @access public */ function getGlobal($varname) { $value = SQLSelectOne("SELECT VALUE FROM pvalues WHERE PROPERTY_NAME = '" . DBSafe($varname) . "'"); if (isset($value['VALUE'])) { return $value['VALUE']; } $tmp = explode('.', $varname); if ($tmp[2]) { $object_name = $tmp[0] . '.' . $tmp[1]; $varname = $tmp[2]; } elseif ($tmp[1]) { $object_name = $tmp[0]; $varname = $tmp[1]; } else { $object_name = 'ThisComputer'; } $obj = getObject($object_name); if ($obj) { return $obj->getProperty($varname); } else { return 0; } }
} $table_name = 'app_quotes'; if ($this->mode == 'update') { global $file; if (file_exists($file)) { $tmp = LoadFile($file); $ok = 1; //$tmp=str_replace("\r", '', $tmp); $lines = mb_split("\n", $tmp); $total_lines = count($lines); for ($i = 0; $i < $total_lines; $i++) { //$values=explode("\t", $lines[$i]); $rec = array(); $rec_ok = 1; $rec['BODY'] = $lines[$i]; if ($rec['BODY'] == '') { $rec_ok = 0; } if ($rec_ok) { $old = SQLSelectOne("SELECT ID FROM " . $table_name . " WHERE BODY LIKE '" . DBSafe($rec['BODY']) . "'"); if ($old['ID']) { $rec['ID'] = $old['ID']; SQLUpdate($table_name, $rec); } else { SQLInsert($table_name, $rec); } $out["TOTAL"]++; } } } }
// connecting to database $db = new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME); include_once "./load_settings.php"; include_once DIR_MODULES . "control_modules/control_modules.class.php"; // ... set_time_limit(0); include_once DIR_MODULES . 'snmpdevices/snmpdevices.class.php'; $snmpdevices = new snmpdevices(); $socket = stream_socket_server("udp://0.0.0.0:162", $errno, $errstr, STREAM_SERVER_BIND); // If we could not bind successfully, let's throw an error if (!$socket) { die($errstr); } else { do { $pkt = stream_socket_recvfrom($socket, 512, 0, $peer); if (preg_match('/:\\d+$/', $peer, $m)) { $peer = str_replace($m[0], '', $peer); } echo date('Y-m-d H:i:s') . ' new snmp trap from ' . $peer . "\n"; $device = SQLSelectOne("SELECT ID FROM snmpdevices WHERE HOST LIKE '" . DBSafe($peer) . "'"); if ($device['ID']) { $snmpdevices->readDevice($device['ID']); } else { $device['TITLE'] = $peer; $device['HOST'] = $peer; $device['ID'] = SQLInsert('snmpdevices', $device); } } while ($pkt !== false); } $db->Disconnect(); // closing database connection
exit; } if (isset($_REQUEST['latitude'])) { //DebMes("GPS DATA RECEIVED: \n".serialize($_REQUEST)); if ($_REQUEST['deviceid']) { $sqlQuery = "SELECT *\n FROM gpsdevices\n WHERE DEVICEID = '" . DBSafe($_REQUEST['deviceid']) . "'"; $device = SQLSelectOne($sqlQuery); if (!$device['ID']) { $device = array(); $device['DEVICEID'] = $_REQUEST['deviceid']; $device['TITLE'] = 'New GPS Device'; if ($_REQUEST['token']) { $device['TOKEN'] = $_REQUEST['token']; } $device['ID'] = SQLInsert('gpsdevices', $device); $sqlQuery = "UPDATE gpslog\n SET DEVICE_ID = '" . $device['ID'] . "'\n WHERE DEVICEID = '" . DBSafe($_REQUEST['deviceid']) . "'"; SQLExec($sqlQuery); } $device['LAT'] = $_REQUEST['latitude']; $device['LON'] = $_REQUEST['longitude']; $device['UPDATED'] = date('Y-m-d H:i:s'); SQLUpdate('gpsdevices', $device); } $rec = array(); //$rec['ADDED'] = ($time) ? $time : date('Y-m-d H:i:s'); $rec['ADDED'] = date('Y-m-d H:i:s'); $rec['LAT'] = $_REQUEST['latitude']; $rec['LON'] = $_REQUEST['longitude']; $rec['ALT'] = round($_REQUEST['altitude'], 2); $rec['PROVIDER'] = $_REQUEST['provider']; $rec['SPEED'] = round($_REQUEST['speed'], 2);
function run() { // running current module global $mode; global $name; $rep_ext = ""; if (preg_match('/\\.dev/is', $_SERVER['HTTP_HOST'])) { $rep_ext = '.dev'; } if (preg_match('/\\.jbk/is', $_SERVER['HTTP_HOST'])) { $rep_ext = '.jbk'; } if (preg_match('/\\.bk/is', $_SERVER['HTTP_HOST'])) { $rep_ext = '.bk'; } if ($rep_ext) { $out['LOCAL_PROJECT'] = 1; $out['REP_EXT'] = $rep_ext; $out['HOST'] = $_SERVER['HTTP_HOST']; $out['DOCUMENT_ROOT'] = dirname($_SERVER['SCRIPT_FILENAME']); } if ($mode == "edit") { global $mode2; $rec = SQLSelectOne("SELECT * FROM project_modules WHERE NAME='" . $name . "'"); $rec['NAME'] = $name; if ($mode2 == "update") { global $title; global $category; $rec['TITLE'] = $title; $rec['CATEGORY'] = $category; SQLUpdate("project_modules", $rec); $this->redirect("?name={$name}&mode=edit"); } elseif ($mode2 == "show") { if ($rec['HIDDEN']) { $rec['HIDDEN'] = 0; } else { $rec['HIDDEN'] = 1; } SQLUpdate('project_modules', $rec); $this->redirect("?"); } elseif ($mode2 == "install") { $rec = SQLSelectOne("SELECT * FROM project_modules WHERE NAME='" . $name . "'"); SQLExec("DELETE FROM project_modules WHERE NAME='" . $name . "'"); @unlink(DIR_MODULES . $name . "/installed"); include_once DIR_MODULES . $name . "/" . $name . ".class.php"; $obj = "\$object{$i}"; $code .= "{$obj}=new " . $name . ";\n"; @eval($code); // add module to control access global $session; $user = SQLSelectOne("SELECT * FROM admin_users WHERE LOGIN='******'"); if ($user['ID'] && !Is_Integer(strpos($user["ACCESS"], $name))) { if ($user["ACCESS"] != '') { $user["ACCESS"] .= ",{$name}"; } else { $user["ACCESS"] = $name; } SQLUpdate('admin_users', $user); } SQLExec("UPDATE project_modules SET HIDDEN='" . (int) $rec['HIDDEN'] . "' WHERE NAME='" . $name . "'"); // redirect to edit $this->redirect("?name={$name}&mode=edit"); } elseif ($mode2 == 'uninstall') { SQLExec("DELETE FROM project_modules WHERE NAME='" . $name . "'"); @unlink(DIR_MODULES . $name . "/installed"); if (file_exists(DIR_MODULES . $name . "/" . $name . ".class.php")) { include_once DIR_MODULES . $name . "/" . $name . ".class.php"; $obj = "\$object{$i}"; $code .= "{$obj}=new " . $name . ";\n"; $code .= "{$obj}" . "->uninstall();"; eval($code); } if ($out['LOCAL_PROJECT']) { $this->redirect("?mode=repository_uninstall&module={$name}"); } else { $this->redirect("?"); } } outHash($rec, $out); } if ($mode == 'repository_uninstall') { global $module; $out['MODULE'] = $module; } $out["MODE"] = $mode; $this->getModulesList(); $lst = $this->modules; for ($i = 0; $i < count($lst); $i++) { $rec = SQLSelectOne("SELECT *, DATE_FORMAT(ADDED, '%M %d, %Y (%H:%i)') as DAT FROM project_modules WHERE NAME='" . $lst[$i]['FILENAME'] . "'"); if (isset($rec['ID'])) { outHash($rec, $lst[$i]); } } $out["MODULES"] = $lst; $this->data = $out; $p = new parser(DIR_TEMPLATES . $this->name . "/" . $this->name . ".html", $this->data, $this); $this->result = $p->result; }
for ($i = 0; $i < $total; $i++) { SQLExec("DELETE FROM phistory WHERE VALUE_ID='" . $pvalues[$i]['ID'] . "'"); } } } else { $new_rec = 1; $rec['ID'] = SQLInsert($table_name, $rec); // adding new record } $out['OK'] = 1; if ($rec['CLASS_ID']) { $objects = getObjectsByClass($rec['CLASS_ID']); $total = count($objects); $replaces = array(); for ($i = 0; $i < $total; $i++) { $property = SQLSelectOne("SELECT ID FROM properties WHERE TITLE LIKE '" . DBSafe($rec['TITLE']) . "' AND OBJECT_ID=" . (int) $objects[$i]['ID'] . " AND CLASS_ID!=" . (int) $rec['CLASS_ID']); if ($property['ID']) { $replaces[] = $property['ID']; } } $total = count($replaces); for ($i = 0; $i < $total; $i++) { SQLExec("UPDATE pvalues SET PROPERTY_ID=" . (int) $rec['ID'] . " WHERE PROPERTY_ID=" . (int) $replaces[$i]); SQLExec("DELETE FROM properties WHERE ID=" . (int) $replaces[$i]); } } } else { $out['ERR'] = 1; } } if (is_array($rec)) {
function updateDevice($id) { if (!defined('ONEWIRE_SERVER')) { return 0; } $rec = SQLSelectOne("SELECT * FROM owdevices WHERE ID='" . $id . "'"); if (!$rec['ID']) { return 0; } $ow = new OWNet(ONEWIRE_SERVER); $device = '/' . $rec['UDID']; $rec['CHECK_LATEST'] = date('Y-m-d H:i:s'); $rec['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + (int) $rec['ONLINE_INTERVAL']); $old_status = $rec['STATUS']; $tmp = $ow->get($device, OWNET_MSG_DIR, false); if (!$tmp) { $rec['STATUS'] = 0; } else { $rec['STATUS'] = 1; } SQLUpdate('owdevices', $rec); if ($rec['STATUS'] != $old_status && ($rec['SCRIPT_ID'] || $rec['CODE'])) { $params = array(); $params['DEVICE'] = $device; $params['STATUS'] = $rec['STATUS']; $params['STATUS_CHANGED'] = 1; if ($rec['SCRIPT_ID']) { runScript($rec['SCRIPT_ID'], $params); } elseif ($rec['CODE']) { try { $code = $rec['CODE']; $success = eval($code); if ($success === false) { DebMes("Error in 1-wire action code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); } } } if (!$rec['STATUS']) { return 0; } $changed_values = array(); $changed = 0; $properties = explode(',', $tmp); $totalp = count($properties); for ($ip = 0; $ip < $totalp; $ip++) { $sysname = str_replace($device . '/', '', $properties[$ip]); //echo $properties[$ip]." (".$sysname."): "; $prec = SQLSelectOne("SELECT * FROM owproperties WHERE DEVICE_ID='" . $rec['ID'] . "' AND SYSNAME='" . DBSafe($sysname) . "'"); if (!$prec['ID']) { $prec['DEVICE_ID'] = $rec['ID']; $prec['SYSNAME'] = $sysname; $prec['PATH'] = $properties[$ip]; $prec['ID'] = SQLInsert('owproperties', $prec); } $old_value = $prec['VALUE']; $value = $ow->get($properties[$ip], OWNET_MSG_READ, false); if (is_null($value)) { $ow->get("/", OWNET_MSG_DIR, false); // hack. for some reason it didn't work correct without it on some devices $value = $ow->get($properties[$ip], OWNET_MSG_READ, false); } if (!is_null($value)) { $value = iconv("CP1251", "UTF-8", $value); // value updated $prec['VALUE'] = $value; $prec['UPDATED'] = date('Y-m-d H:i:s'); $prec['CHECK_LATEST'] = $prec['UPDATED']; SQLUpdate('owproperties', $prec); //$rec['LOG']=date('Y-m-d H:i:s')." ".$prec['SYSNAME'].": ".$prec['VALUE']."\n".$rec['LOG']; //SQLUpdate('owdevices', $rec); if ($prec['LINKED_OBJECT'] && $prec['LINKED_PROPERTY']) { setGlobal($prec['LINKED_OBJECT'] . '.' . $prec['LINKED_PROPERTY'], $prec['VALUE'], array($this->name => '0')); } if ($old_value != $value) { $changed = 1; $changed_values[$prec['SYSNAME']] = array('OLD_VALUE' => $old_value, 'VALUE' => $prec['VALUE']); } } } if ($changed) { $params = $changed_values; $params['DEVICE'] = $device; if ($rec['SCRIPT_ID']) { runScript($rec['SCRIPT_ID'], $params); } elseif ($rec['CODE']) { try { $code = $rec['CODE']; $success = eval($code); if ($success === false) { DebMes("Error in code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); } } } }
<?php global $session; global $uid; if ($nid != '') { $qry .= " AND USER_ID LIKE '%" . DBSafe($nid) . "%'"; $out['USER_ID'] = $nid; } global $name; if ($name != '') { $qry .= " AND NAME LIKE '%" . DBSafe($name) . "%'"; $out['NAME'] = $name; } // FIELDS ORDER global $sortby_user; if (!$sortby_user) { $sortby_user = $session->data['tlg_user_sort']; } else { if ($session->data['tlg_user_sort'] == $sortby_user) { if (Is_Integer(strpos($sortby_user, ' DESC'))) { $sortby_user = str_replace(' DESC', '', $sortby_user); } else { $sortby_user = $sortby_user . " DESC"; } } $session->data['tlg_user_sort'] = $sortby_user; } if (!$sortby_user) { $sortby_user = "******"; } $out['SORTBY'] = $sortby_user;
$rec['TITLE'] = 'ws'; $rec['ID'] = SQLInsert('objects', $rec); $obj = getObject('ws'); } $object_rec = SQLSelectOne("SELECT * FROM objects WHERE ID = '" . $obj->id . "'"); if (!$object_rec['CLASS_ID']) { $class_rec = array(); $class_rec['TITLE'] = 'WeatherStations'; $class_rec['SUB_LIST'] = 0; $class_rec['PARENT_LIST'] = 0; $class_rec['ID'] = SQLInsert('classes', $class_rec); $object_rec['CLASS_ID'] = $class_rec['ID']; SQLUpdate('objects', $object_rec); } foreach ($known_fields as $k => $v) { $prop_rec = SQLSelectOne("SELECT * FROM properties WHERE TITLE LIKE '" . DBSafe($k) . "' AND CLASS_ID = '" . $object_rec['CLASS_ID'] . "'"); if (!$prop_rec['ID']) { $prop_rec['CLASS_ID'] = $object_rec['CLASS_ID']; $prop_rec['TITLE'] = $k; $prop_rec['KEEP_HISTORY'] = 7; $prop_rec['ID'] = SQLInsert('properties', $prop_rec); } } $res = ''; $updated = array(); foreach ($known_fields as $k => $v) { if ($v < 0) { continue; } $res .= $k . ' = ' . $data[(int) $v] . "\n"; $old_value = getGlobal('ws.' . $k);
} if (!$my_meth['ID']) { $out['CALL_PARENT'] = 1; } else { $out['CODE'] = htmlspecialchars($my_meth['CODE']); $out['SCRIPT_ID'] = $my_meth['SCRIPT_ID']; $out['CALL_PARENT'] = (int) $my_meth['CALL_PARENT']; } $out['OVERWRITE'] = 1; } include_once DIR_MODULES . 'classes/classes.class.php'; $cl = new classes(); $methods = $cl->getParentMethods($rec['CLASS_ID'], '', 1); $total = count($methods); for ($i = 0; $i < $total; $i++) { $my_meth = SQLSelectOne("SELECT ID FROM methods WHERE OBJECT_ID='" . $rec['ID'] . "' AND TITLE LIKE '" . DBSafe($methods[$i]['TITLE']) . "'"); if ($my_meth['ID']) { $methods[$i]['CUSTOMIZED'] = 1; } } $out['METHODS'] = $methods; } // step: history if ($this->tab == 'history') { } if (is_array($rec)) { foreach ($rec as $k => $v) { if (!is_array($v)) { $rec[$k] = htmlspecialchars($v); } }
/** * Title * * Description * * @access public */ function registerError($code = 'custom', $details = '') { $code = trim($code); if (!$code) { $code = 'custom'; } $error_rec = SQLSelectOne("SELECT * FROM system_errors WHERE CODE LIKE '" . DBSafe($code) . "'"); if (!$error_rec['ID']) { $error_rec['CODE'] = $code; $error_rec['KEEP_HISTORY'] = 1; $error_rec['ID'] = SQLInsert('system_errors', $error_rec); } $error_rec['LATEST_UPDATE'] = date('Y-m-d H:i:s'); $error_rec['ACTIVE'] = (int) $error_rec['ACTIVE'] + 1; SQLUpdate('system_errors', $error_rec); $history_rec = array(); $history_rec['ERROR_ID'] = $error_rec['ID']; $history_rec['COMMENTS'] = $details; $history_rec['ADDED'] = $error_rec['LATEST_UPDATE']; //Temporary disabled /* $history_rec['PROPERTIES_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=', 0); $history_rec['METHODS_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=methods', 0); $history_rec['SCRIPTS_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=scripts', 0); $history_rec['TIMERS_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=timers', 0); $history_rec['EVENTS_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=events', 0); $history_rec['DEBUG_DATA']=getURL(BASE_URL.ROOTHTML.'popup/xray.html?ajax=1&md=xray&op=getcontent&view_mode=debmes', 0); */ $history_rec['ID'] = SQLInsert('system_errors_data', $history_rec); if (!$error_rec['KEEP_HISTORY']) { SQLExec("DELETE FROM system_errors_data WHERE ID!='" . $history_rec['ID'] . "'"); } }
function install() { //$className = 'Push'; //$objectName = 'PushBullet'; //$propertis = array('API_KEY1', 'Device1'); $rec = SQLSelectOne("SELECT ID FROM classes WHERE TITLE LIKE '" . DBSafe($className) . "'"); if (!$rec['ID']) { $rec = array(); $rec['TITLE'] = $className; //$rec['PARENT_LIST']='0'; $rec['DESCRIPTION'] = 'Push-notes'; $rec['ID'] = SQLInsert('classes', $rec); } $obj_rec = SQLSelectOne("SELECT ID FROM objects WHERE CLASS_ID='" . $rec['ID'] . "' AND TITLE LIKE '" . DBSafe($objectName) . "'"); if (!$obj_rec['ID']) { $obj_rec = array(); $obj_rec['CLASS_ID'] = $rec['ID']; $obj_rec['TITLE'] = $objectName; $obj_rec['DESCRIPTION'] = 'Настройки'; $obj_rec['ID'] = SQLInsert('objects', $obj_rec); } for ($i = 0; $i < count($propertis); $i++) { $prop_rec = SQLSelectOne("SELECT ID FROM properties WHERE OBJECT_ID='" . $obj_rec['ID'] . "' AND TITLE LIKE '" . DBSafe($propertis[$i]) . "'"); if (!$prop_rec['ID']) { $prop_rec = array(); $prop_rec['TITLE'] = $propertis[$i]; $prop_rec['OBJECT_ID'] = $obj_rec['ID']; $prop_rec['ID'] = SQLInsert('properties', $prop_rec); } } parent::install(); }
/** * Title * * Description * * @access public */ function setProperty($property, $value, $no_linked = 0) { startMeasure('setProperty'); startMeasure('setProperty (' . $property . ')'); $id = $this->getPropertyByName($property, $this->class_id, $this->id); $old_value = ''; if ($id) { $prop = SQLSelectOne("SELECT * FROM properties WHERE ID='" . $id . "'"); $v = SQLSelectOne("SELECT * FROM pvalues WHERE PROPERTY_ID='" . (int) $id . "' AND OBJECT_ID='" . (int) $this->id . "'"); $old_value = $v['VALUE']; $v['VALUE'] = $value; if ($v['ID']) { $v['UPDATED'] = date('Y-m-d H:i:s'); if ($old_value != $value) { SQLUpdate('pvalues', $v); //DebMes("Setting [".$this->object_title.".".$property."] to new value [".$value."]"); } else { SQLExec("UPDATE pvalues SET UPDATED='" . $v['UPDATED'] . "' WHERE ID='" . $v['ID'] . "'"); //DebMes("Setting [".$this->object_title.".".$property."] to the same value [".$value."]"); } } else { $v['PROPERTY_ID'] = $id; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } //DebMes(" $id to $value "); } else { $prop = array(); $prop['OBJECT_ID'] = $this->id; $prop['TITLE'] = $property; $prop['ID'] = SQLInsert('properties', $prop); $v['PROPERTY_ID'] = $prop['ID']; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } if ($prop['KEEP_HISTORY'] > 0) { startMeasure('DeleteOldHistory'); SQLExec("DELETE FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' AND TO_DAYS(NOW())-TO_DAYS(ADDED)>" . (int) $prop['KEEP_HISTORY']); endMeasure('DeleteOldHistory', 1); $h = array(); $h['VALUE_ID'] = $v['ID']; $h['ADDED'] = date('Y-m-d H:i:s'); $h['VALUE'] = $value; $h['ID'] = SQLInsert('phistory', $h); } /* $h=array(); $h['ADDED']=date('Y-m-d H:i:s'); $h['OBJECT_ID']=$this->id; $h['VALUE_ID']=$v['ID']; $h['OLD_VALUE']=$old_value; $h['NEW_VALUE']=$value; SQLInsert('history', $h); */ //commands, owproperties, snmpproperties, zwave_properties, mqtt $tables = array('commands', 'owproperties', 'snmpproperties', 'zwave_properties', 'mqtt', 'modbusdevices'); if (!is_array($no_linked) && $no_linked) { $no_linked = array(); foreach ($tables as $t) { $no_linked[$k] = '0'; } } elseif (is_array($no_linked)) { foreach ($tables as $t) { if (!isset($no_linked[$k])) { $no_linked[$k] = '1'; } } } else { $no_linked = array(); foreach ($tables as $t) { $no_linked[$k] = '1'; } } foreach ($tables as $t) { if ($no_linked[$t] == '') { $no_linked[$t] = '1'; } } if ($no_linked['commands'] != '') { $commands = SQLSelect("SELECT * FROM commands WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['commands']); $total = count($commands); for ($i = 0; $i < $total; $i++) { $commands[$i]['CUR_VALUE'] = $value; SQLUpdate('commands', $commands[$i]); } } if ($no_linked['owproperties'] != '' && file_exists(DIR_MODULES . '/onewire/onewire.class.php')) { $owp = SQLSelect("SELECT ID FROM owproperties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['owproperties']); $total = count($owp); if ($total) { include_once DIR_MODULES . '/onewire/onewire.class.php'; $on_wire = new onewire(); for ($i = 0; $i < $total; $i++) { $on_wire->setProperty($owp[$i]['ID'], $value); } } } if ($no_linked['snmpproperties'] != '' && file_exists(DIR_MODULES . '/snmpdevices/snmpdevices.class.php')) { $snmpdevices = SQLSelect("SELECT ID FROM snmpproperties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['snmpproperties']); $total = count($snmpdevices); if ($total) { include_once DIR_MODULES . '/snmpdevices/snmpdevices.class.php'; $snmp = new snmpdevices(); for ($i = 0; $i < $total; $i++) { $snmp->setProperty($snmpdevices[$i]['ID'], $value); } } } if ($no_linked['zwave_properties'] != '' && file_exists(DIR_MODULES . '/zwave/zwave.class.php')) { $zwave_properties = SQLSelect("SELECT ID FROM zwave_properties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['zwave_properties']); $total = count($zwave_properties); if ($total) { include_once DIR_MODULES . '/zwave/zwave.class.php'; $zwave = new zwave(); for ($i = 0; $i < $total; $i++) { $zwave->setProperty($zwave_properties[$i]['ID'], $value); } } } if ($no_linked['mqtt'] != '' && file_exists(DIR_MODULES . '/mqtt/mqtt.class.php')) { $mqtt_properties = SQLSelect("SELECT ID FROM mqtt WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['mqtt']); $total = count($mqtt_properties); if ($total) { include_once DIR_MODULES . '/mqtt/mqtt.class.php'; $mqtt = new mqtt(); for ($i = 0; $i < $total; $i++) { $mqtt->setProperty($mqtt_properties[$i]['ID'], $value); } } } if ($no_linked['modbusdevices'] != '' && file_exists(DIR_MODULES . '/modbus/modbus.class.php')) { $modbusdevices = SQLSelect("SELECT ID FROM modbusdevices WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['modbusdevices']); $total = count($modbusdevices); if ($total) { include_once DIR_MODULES . '/modbus/modbus.class.php'; $modbus = new modbus(); for ($i = 0; $i < $total; $i++) { $modbus->poll_device($modbusdevices[$i]['ID']); } } } if ($prop['ONCHANGE']) { global $property_linked_history; if (!$property_linked_history[$property][$prop['ONCHANGE']]) { $property_linked_history[$property][$prop['ONCHANGE']] = 1; global $on_change_called; $params = array(); $params['PROPERTY'] = $property; $params['NEW_VALUE'] = (string) $value; $params['OLD_VALUE'] = (string) $old_value; $this->callMethod($prop['ONCHANGE'], $params); unset($property_linked_history[$property][$prop['ONCHANGE']]); } } endMeasure('setProperty (' . $property . ')', 1); endMeasure('setProperty', 1); }
} $qry = "1"; // search filters // search filters if ($this->filter_name != '') { $qry .= " AND NAME LIKE '%" . DBSafe($this->filter_name) . "%'"; $out['FILTER_NAME'] = $this->filter_name; } if ($this->filter_exname != '') { $qry .= " AND NAME NOT LIKE '%" . DBSafe($this->filter_exname) . "%'"; $out['FILTER_EXNAME'] = $this->filter_exname; } if (!$this->filter_name) { //$words=array('HP', 'PROFILE'); foreach ($words as $wrd) { $qry .= " AND NAME NOT LIKE '%" . DBSafe($wrd) . "%'"; } } if ($this->section_title != '') { $out['SECTION_TITLE'] = $this->section_title; } // QUERY READY // QUERY READY global $save_qry; if ($save_qry) { $qry = $session->data['settings_qry']; } else { $session->data['settings_qry'] = $qry; } if (!$qry) { $qry = "1";
//updating 'DEVICEID' (varchar) global $deviceid; $rec['DEVICEID'] = $deviceid; //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; if ($rec['DEVICEID']) { SQLExec("UPDATE gpslog SET DEVICE_ID='" . $rec['ID'] . "' WHERE DEVICE_ID=0 AND DEVICEID='" . DBSafe($rec['DEVICEID']) . "'"); } } else { $out['ERR'] = 1; } } //options for 'USER_ID' (select) $tmp = SQLSelect("SELECT ID, NAME FROM users ORDER BY NAME"); $users_total = count($tmp); for ($users_i = 0; $users_i < $users_total; $users_i++) { $user_id_opt[$tmp[$users_i]['ID']] = $tmp[$users_i]['NAME']; } for ($i = 0; $i < $users_total; $i++) { if ($rec['USER_ID'] == $tmp[$i]['ID']) { $tmp[$i]['SELECTED'] = 1; }
function run() { // running current module global $session; if ($this->owner->name != 'panel' && $this->owner->name != 'master') { echo "Unauthorized Access"; exit; } if ($this->id == '1') { $this->mode = 'edit'; global $id; global $mode; $id = $this->id; $mode = 'edit'; $out['MASTER'] = 1; } // LDAP inicial if (function_exists('ldap_connect') && is_file(ROOT . 'modules/ldap_users/installed')) { $out['LDAP_ON'] = 1; } if ($this->mode == 'logoff') { unset($session->data['AUTHORIZED']); unset($session->data['USER_NAME']); unset($session->data['USERNAME']); unset($session->data['SITE_USERNAME']); unset($session->data['SITE_USER_ID']); unset($session->data["cp_requested_url"]); $this->owner->redirect("/"); } if ($this->action == "enter") { global $md; global $login; if (!$session->data["cp_requested_url"] && ($md != 'panel' || $action != '') && !$login) { $session->data["cp_requested_url"] = $_SERVER['REQUEST_URI']; } if ($this->mode == "check") { global $login; global $psw; // $user=SQLSelectOne("SELECT * FROM admin_users WHERE LOGIN='******' AND PASSWORD='******'"); $user = SQLSelectOne("SELECT * FROM admin_users WHERE LOGIN='******' AND PASSWORD='******'"); // $user=SQLSelectOne("SELECT * FROM admin_users WHERE 1"); // LDAP logining if ($out['LDAP_ON'] != false && ($user == false || $psw == 'this_ldap_admin')) { include_once ROOT . 'modules/ldap_users/ldap_users.class.php'; $ldap = new ldap_users(); $user = $ldap->ctrl_access(); } // LDAP loginig if (!isset($user['ID'])) { $out["ERRMESS"] = "Wrong username and/or password"; } else { $session->data['AUTHORIZED'] = 1; $session->data['USER_NAME'] = $user['LOGIN']; $session->data['USER_LEVEL'] = $user['PRIVATE']; $session->data['USER_ID'] = $user['ID']; if (!$session->data["cp_requested_url"]) { if (file_exists(DIR_MODULES . 'dashboard/dashboard.class.php')) { $this->owner->redirect("?action=dashboard"); } $this->owner->redirect("?"); } else { $this->owner->redirect($session->data["cp_requested_url"]); } } } } elseif ($this->action == "logged") { $out["USER_NAME"] = $session->data["USER_NAME"]; $tmp = SQLSelectOne("SELECT ID FROM admin_users WHERE LOGIN='******' AND PASSWORD='******'admin') . "'"); if ($tmp['ID']) { $out['WARNING'] = 1; } $user = SQLSelectOne("SELECT * FROM admin_users WHERE LOGIN='******'"); if (!$user['ID']) { unset($session->data['AUTHORIZED']); unset($session->data['USER_NAME']); $session->save(); $this->owner->redirect("?"); } $modules = SQLSelect("SELECT * FROM project_modules WHERE HIDDEN='0' ORDER BY CATEGORY, NAME"); $modulesCnt = count($modules); for ($i = 0; $i < $modulesCnt; $i++) { if (preg_match("/," . $modules[$i]['NAME'] . ",/i", @$user["ACCESS"]) || preg_match("/," . $modules[$i]['NAME'] . "\$/i", @$user["ACCESS"]) || preg_match("/^" . $modules[$i]['NAME'] . ",/i", @$user["ACCESS"]) || preg_match("/^" . $modules[$i]['NAME'] . "\$/i", @$user["ACCESS"]) || 0) { $new[] = $modules[$i]; } } $on_row = 0; $newCnt = count($new); for ($i = 0; $i < $newCnt; $i++) { if ($new[$i]['CATEGORY'] != $new_category) { $new[$i]['NEWCATEGORY'] = 1; $new_category = $new[$i]['CATEGORY']; $on_row = 0; } $on_row++; if ($on_row % 6 == 0 && $on_row >= 6) { $new[$i]['NEWROW'] = 1; } if (file_exists(ROOT . 'img/admin/icons/ico_' . $new[$i]['NAME'] . '.gif')) { $new[$i]['ICON'] = ROOTHTML . 'img/admin/icons/ico_' . $new[$i]['NAME'] . '.gif'; } else { $new[$i]['ICON'] = ROOTHTML . 'img/admin/icons/ico_default.gif'; } } $out["MODULES"] = $new; if (file_exists(DIR_MODULES . 'saverestore/saverestore.class.php')) { $out['CHECK_UPDATES'] = 1; global $check; if ($check) { include_once DIR_MODULES . 'saverestore/saverestore.class.php'; $sv = new saverestore(); $sv->checkUpdates($o); if ($o['NO_UPDATES'] || $o['ERROR_CHECK']) { echo "no"; } else { echo "yes"; } exit; } } } elseif ($this->action == "logoff") { unset($session->data['AUTHORIZED']); unset($session->data['USER_NAME']); unset($session->data['USERNAME']); $this->owner->redirect("?"); } elseif ($this->action == "admin") { global $mode; global $mode2; global $id; if (!$session->data['AUTHORIZED']) { exit; } if ($mode == "delete") { SQLExec("DELETE FROM admin_users WHERE ID='" . $id . "'"); $this->redirect("?"); } if ($mode == "edit") { $user = SQLSelectOne("SELECT * FROM admin_users WHERE ID='" . $id . "'"); if ($mode2 == "update") { $ok = 1; global $name; global $login; global $password; global $email; global $comments; global $sel; global $private; global $EMAIL_ORDERS; global $EMAIL_INVENTORY; $user['NAME'] = $name; if (!checkGeneral($user['NAME'])) { $out["ERR_NAME"] = 1; $ok = 0; } $user['LOGIN'] = $login; if (!checkGeneral($user['LOGIN'])) { $out["ERR_LOGIN"] = 1; $ok = 0; } if ($password != '' || !$user['ID']) { $user['PASSWORD'] = $password; if (!checkGeneral($user['PASSWORD'])) { $out["ERR_PASSWORD"] = 1; $ok = 0; } else { $user['PASSWORD'] = md5($user['PASSWORD']); } } $user['EMAIL'] = $email; $user['COMMENTS'] = $comments; $user['PRIVATE'] = (int) $private; $user['EMAIL_ORDERS'] = $EMAIL_ORDERS; $user['EMAIL_INVENTORY'] = $EMAIL_INVENTORY; if (count($sel) > 0) { $user['ACCESS'] = join(",", $sel); } else { $user['ACCESS'] = ""; } if ($ok) { SQLUpdateInsert("admin_users", $user); $out["OK"] = 1; } } $modules = SQLSelect("SELECT * FROM project_modules"); $modulesCnt = count($modules); for ($i = 0; $i < $modulesCnt; $i++) { if (preg_match("/," . $modules[$i]['NAME'] . ",/i", @$user["ACCESS"]) || preg_match("/," . $modules[$i]['NAME'] . "\$/i", @$user["ACCESS"]) || preg_match("/^" . $modules[$i]['NAME'] . ",/i", @$user["ACCESS"]) || preg_match("/^" . $modules[$i]['NAME'] . "\$/i", @$user["ACCESS"]) || 0) { $modules[$i]["SELECTED"] = 1; } if (($i + 1) % 3 == 0) { $modules[$i]['NEWR'] = 1; } } $user["MODULES"] = $modules; outHash($user, $out); } $users = SQlSelect("SELECT * FROM admin_users ORDER BY ID DESC"); $out["USERS"] = $users; } $out["MODE"] = $mode; $out["ACTION"] = $this->action; $this->data = $out; $p = new parser(DIR_TEMPLATES . $this->name . "/" . $this->name . ".html", $this->data, $this); $this->result = $p->result; }
/** * Title * * Description * * @access public */ function getObjectsByClass($class_name) { $class_record = SQLSelectOne("SELECT ID FROM classes WHERE (TITLE LIKE '" . DBSafe(trim($class_name)) . "' OR ID=" . (int) $class_name . ")"); if (!$class_record['ID']) { return 0; } $objects = SQLSelect("SELECT ID, TITLE FROM objects WHERE CLASS_ID='" . $class_record['ID'] . "'"); $sub_classes = SQLSelect("SELECT ID, TITLE FROM classes WHERE PARENT_ID='" . $class_record['ID'] . "'"); if ($sub_classes[0]['ID']) { $total = count($sub_classes); for ($i = 0; $i < $total; $i++) { $sub_objects = getObjectsByClass($sub_classes[$i]['TITLE']); if ($sub_objects[0]['ID']) { foreach ($sub_objects as $obj) { $objects[] = $obj; } } } } /* $total=count($objects); for($i=0;$i<$total;$i++) { $objects[$i]=getObject($objects[$i]['TITLE']) } */ return $objects; }
// SEARCH RESULTS $res = SQLSelect("SELECT * FROM classes WHERE {$qry} ORDER BY {$sortby}"); if ($res[0]['ID']) { colorizeArray($res); $total = count($res); for ($i = 0; $i < $total; $i++) { // some action for every record if required $objects = SQLSelect("SELECT ID, TITLE, CLASS_ID, DESCRIPTION FROM objects WHERE CLASS_ID='" . $res[$i]['ID'] . "'"); if ($objects[0]['ID']) { $total_o = count($objects); for ($o = 0; $o < $total_o; $o++) { $methods = SQLSelect("SELECT ID, TITLE FROM methods WHERE OBJECT_ID='" . $objects[$o]['ID'] . "'"); if ($methods[0]['ID']) { $total_m = count($methods); for ($im = 0; $im < $total_m; $im++) { $parent_method = SQLSelectOne("SELECT ID FROM methods WHERE OBJECT_ID=0 AND CLASS_ID='" . $objects[$o]['CLASS_ID'] . "' AND TITLE='" . DBSafe($methods[$im]['TITLE']) . "'"); if ($methods[$im]['ID'] == 82) { //echo $objects[$];exit; } if ($parent_method['ID']) { $methods[$im]['ID'] = $parent_method['ID']; } } $objects[$o]['METHODS'] = $methods; } } $res[$i]['OBJECTS'] = $objects; if (!is_array($res[$i]['OBJECTS'])) { unset($res[$i]['OBJECTS']); } }
/** * Title * * Description * * @access public */ function updateChannel($id) { $ch = SQLSelectOne("SELECT * FROM rss_channels WHERE ID='" . (int) $id . "'"); $ch['LAST_UPDATE'] = date('Y-m-d H:i:s'); $ch['NEXT_UPDATE'] = date('Y-m-d H:i:s', time() + $ch['UPDATE_EVERY'] * 60); SQLUpdate('rss_channels', $ch); /* $cch =curl_init(); curl_setopt($cch, CURLOPT_URL, $ch['URL']); curl_setopt($cch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3")); curl_setopt($cch, CURLOPT_RETURNTRANSFER, true); $rssdata = curl_exec($cch); curl_close($cch); */ $rssdata = getURL($ch['URL'], 0); $data = simplexml_load_string($rssdata); if ($data) { if (is_object($data->channel) && !empty($data->channel)) { foreach ($data->channel->item as $item) { $rec = array(); $rec['CHANNEL_ID'] = $ch['ID']; $parsedFull = 0; if ($item->pubDate) { $rec['ADDED'] = date('Y-m-d H:i:s', strtotime((string) $item->pubDate)); } else { $rec['ADDED'] = date('Y-m-d H:i:s'); } $rec['TITLE'] = $this->convertObjDataToStr($item->title); $rec['BODY'] = $this->convertObjDataToStr($item->description); $rec['URL'] = $this->convertObjDataToStr($item->link); $rec['GUID'] = $rec['URL']; $timestamp = strtotime($rec['ADDED']); //print_r($rec); //exit; $tmp = SQLSelectOne("SELECT ID FROM rss_items WHERE GUID='" . DBSafe($rec['GUID']) . "'"); if (!$tmp['ID']) { $rec['ID'] = SQLInsert('rss_items', $rec); if ($ch['SCRIPT_ID']) { $params = $rec; $params['CHANNEL_TITLE'] = $ch['TITLE']; $params['TM'] = $timestamp; $params['PASSED'] = time() - $timestamp; runScript($ch['SCRIPT_ID'], $params); } } } } } }
if ($cached_result == '') { if (!file_exists(DIR_MODULES . 'control_modules/installed')) { include_once DIR_MODULES . "control_modules/control_modules.class.php"; $ctl = new control_modules(); } $app = new application(); if ($md != $app->name) { $app->restoreParams(); } else { $app->getParams(); } if ($app->action != '' && $app->action != 'docs') { $fake_doc = ''; } if ($app->action == '' && $fake_doc != "" && file_exists(DIR_MODULES . 'cms_docs/cms_docs.class.php')) { $tmp = SQLSelectOne("SELECT ID FROM cms_docs WHERE NAME='" . DBSafe($fake_doc) . "'"); if (isset($tmp['ID'])) { $app->action = "docs"; $app->doc = $tmp['ID']; } elseif (file_exists(DIR_TEMPLATES . $fake_doc . ".html")) { $app->action = $fake_doc; } else { //$tmp1=SQLSelectOne("SELECT ID FROM cms_docs WHERE NAME='404'"); $tmp1 = array(); if ($tmp1['ID']) { $app->action = "docs"; $app->doc = $tmp1['ID']; } else { header("HTTP/1.0 404 Not Found"); echo "The page cannot be found. Please use <a href='/'>this link</a> to continue browsing."; exit;
/** * Title * * Description * * @access public */ function import_classes(&$out) { global $file; global $overwrite; global $only_classes; $data = LoadFile($file); $records = unserialize($data); if (is_array($records)) { $total = count($records); for ($i = 0; $i < $total; $i++) { $old_class = SQLSelectOne("SELECT ID FROM classes WHERE TITLE LIKE '" . DBSafe($records[$i]['TITLE']) . "'"); $total_o = 0; if ($old_class['ID']) { $old_objects = SQLSelect("SELECT * FROM objects WHERE CLASS_ID='" . $old_class['ID'] . "'"); $total_o = count($old_objects); for ($io = 0; $io < $total_o; $io++) { $old_objects[$io]['CLASS_ID'] = 0; SQLUpdate('objects', $old_objects[$io]); } if ($overwrite) { $this->delete_classes($old_class['ID']); $records[$i]['ID'] = $old_class['ID']; } else { $records[$i]['TITLE'] = $records[$i]['TITLE'] . rand(0, 500); } } $objects = $records[$i]['OBJECTS']; unset($records[$i]['OBJECTS']); $methods = $records[$i]['METHODS']; unset($records[$i]['METHODS']); $properties = $records[$i]['PROPERTIES']; unset($records[$i]['PROPERTIES']); $records[$i]['ID'] = SQLInsert('classes', $records[$i]); if ($total_o) { for ($io = 0; $io < $total_o; $io++) { $old_objects[$io]['CLASS_ID'] = $records[$i]['ID']; SQLUpdate('objects', $old_objects[$io]); } } if (is_array($properties)) { $total_p = count($properties); for ($p = 0; $p < $total_p; $p++) { $properties[$p]['CLASS_ID'] = $records[$i]['ID']; $properties[$p]['ID'] = SQLInsert('properties', $properties[$p]); } } if (is_array($methods)) { $total_m = count($methods); for ($m = 0; $m < $total_m; $m++) { $methods[$m]['CLASS_ID'] = $records[$i]['ID']; $methods[$m]['ID'] = SQLInsert('methods', $methods[$m]); } } if (is_array($objects) && !$only_classes) { $total_o = count($objects); for ($o = 0; $o < $total_o; $o++) { $objects[$o]['CLASS_ID'] = $records[$i]['ID']; $methods = $objects[$o]['METHODS']; unset($objects[$o]['METHODS']); $properties = $objects[$o]['PROPERTIES']; unset($objects[$o]['PROPERTIES']); $objects[$o]['ID'] = SQLInsert('objects', $objects[$o]); if (is_array($properties)) { $total_p = count($properties); for ($p = 0; $p < $total_p; $p++) { $properties[$p]['OBJECT_ID'] = $objects[$o]['ID']; $properties[$p]['ID'] = SQLInsert('properties', $properties[$p]); } } if (is_array($methods)) { $total_m = count($methods); for ($m = 0; $m < $total_m; $m++) { $methods[$m]['OBJECT_ID'] = $objects[$o]['ID']; $methods[$m]['ID'] = SQLInsert('methods', $methods[$m]); } } } } } //print_r($records); } $this->updateTree_classes(); $this->redirect("?"); }
/** * FrontEnd * * Module frontend * * @access public */ function usual(&$out) { global $session; if ($this->action == 'addevent') { global $mode; $this->mode = $mode; if ($this->mode == 'update') { global $type; global $window; global $details; global $terminal_to; global $user_to; $event = array(); $event['EVENT_TYPE'] = $type; $event['WINDOW'] = $window; $event['DETAILS'] = $details; $event['TERMINAL_TO'] = $terminal_to; $event['TERMINAL_FROM'] = $session->data['TERMINAL']; $event['USER_TO'] = $user_to; $event['USER_FROM'] = $session->data['USERNAME']; $event['ADDED'] = date('Y-m-d H:i:s'); $event['EXPIRE'] = date('Y-m-d H:i:s', time() + 5 * 60); //5 minutes expire SQLInsert('events', $event); } $terminals = SQLSelect("SELECT * FROM terminals ORDER BY TITLE"); $total = count($terminals); for ($i = 0; $i < $total; $i++) { if ($terminals[$i]['NAME'] == $session->data['TERMINAL']) { $terminals[$i]['SELECTED'] = 1; $out['TERMINAL_TITLE'] = $terminals[$i]['TITLE']; } } $out['TERMINALS'] = $terminals; $users = SQLSelect("SELECT * FROM users ORDER BY NAME"); $total = count($users); for ($i = 0; $i < $total; $i++) { if ($users[$i]['USERNAME'] == $session->data['USERNAME']) { $users[$i]['SELECTED'] = 1; $out['USER_TITLE'] = $users[$i]['NAME']; } } $out['USERS'] = $users; } if ($this->action == 'getnextevent') { if (!$session->data['TERMINAL']) { $session->data['TERMINAL'] = 'temp' . date('YmdHis'); } //echo "next event for ".$session->data['USERNAME']." on ".$session->data['TERMINAL'];//.date('H:i:s') SQLExec("DELETE FROM events WHERE EXPIRE<NOW() AND EVENT_TYPE!='system'"); $qry = "1"; //$qry.=" AND TERMINAL_FROM!='".DBSafe($session->data['TERMINAL'])."'"; $qry .= " AND EVENT_TYPE!='system'"; $qry .= " AND PROCESSED=0"; $qry .= " AND (TERMINAL_TO='*' OR TERMINAL_TO='" . DBSafe($session->data['TERMINAL']) . "')"; $qry .= " AND (USER_TO='*' OR USER_TO='" . DBSafe($session->data['USERNAME']) . "')"; $event = SQLSelectOne("SELECT * FROM events WHERE {$qry} ORDER BY ADDED"); if ($event['ID']) { $res = $event['ID'] . '|' . $event['EVENT_TYPE'] . '|' . $event['WINDOW'] . '|' . str_replace("\n", '\\n', $event['DETAILS']); echo $res; $event['PROCESSED'] = 1; SQLUpdate('events', $event); } exit; } }
function upload(&$out) { set_time_limit(0); global $restore; global $file; global $file_name; global $folder; if (!$folder) { if (substr(php_uname(), 0, 7) == "Windows") { $folder = '/.'; } else { $folder = '/'; } } else { $folder = '/' . $folder; } if ($restore != '') { $file = $restore; } elseif ($file != '') { copy($file, ROOT . 'saverestore/' . $file_name); $file = $file_name; } umask(0); @mkdir(ROOT . 'saverestore/temp', 0777); if ($file != '') { // && mkdir(ROOT.'saverestore/temp', 0777) chdir(ROOT . 'saverestore/temp'); if (substr(php_uname(), 0, 7) == "Windows") { // for windows only exec(DOC_ROOT . '/gunzip ../' . $file, $output, $res); //echo DOC_ROOT.'/tar xvf ../'.str_replace('.tgz', '.tar', $file);exit; exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res); } else { exec('tar xzvf ../' . $file, $output, $res); } $x = 0; $dir = opendir('./'); while (($filec = readdir($dir)) !== false) { if ($filec == '.' || $filec == '..') { continue; } if (is_Dir($filec)) { $latest_dir = $filec; } elseif (is_File($filec)) { $latest_file = $filec; } $x++; } if ($x == 1 && $latest_dir) { $folder = '/' . $latest_dir; } @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php'); @unlink(ROOT . 'saverestore/temp' . $folder . '/README.md'); chdir('../../'); // UPDATING FILES DIRECTLY $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1); // restore all files $source = ROOT . 'modules'; if ($dir = @opendir($source)) { while (($file = readdir($dir)) !== false) { if (Is_Dir($source . "/" . $file) && $file != '.' && $file != '..') { // && !file_exists($source."/".$file."/installed") @unlink(ROOT . "modules/" . $file . "/installed"); } } } @unlink(ROOT . "modules/control_modules/installed"); @SaveFile(ROOT . 'reboot', 'updated'); global $name; global $version; $rec = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . DBSafe($name) . "'"); $rec['MODULE_NAME'] = $name; $rec['CURRENT_VERSION'] = $version; $rec['IS_INSTALLED'] = 1; $rec['LATEST_UPDATE'] = date('Y-m-d H:i:s'); if ($rec['ID']) { SQLUpdate('plugins', $rec); } else { SQLInsert('plugins', $rec); } $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!")); } }
/** * Title * * Description * * @access public */ function propertySetHandle($object, $property, $value) { $commands = SQLSelect("SELECT * FROM commands WHERE LINKED_OBJECT LIKE '" . DBSafe($object) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "'"); $total = count($commands); for ($i = 0; $i < $total; $i++) { $commands[$i]['CUR_VALUE'] = $value; SQLUpdate('commands', $commands[$i]); } }
/** * FrontEnd * * Module frontend * * @access public */ function usual(&$out) { $terminals=SQLSelect("SELECT * FROM terminals WHERE CANPLAY=1 ORDER BY TITLE"); $total=count($terminals); for($i=0;$i<$total;$i++) { //if ($terminals[$i]['NAME']==$session->data['PLAY_TERMINAL']) { // $terminals[$i]['SELECTED']=1; // $out['TERMINAL_TITLE']=$terminals[$i]['TITLE']; //} } $out['TERMINALS']=$terminals; $out['TERMINALS_TOTAL']=count($terminals); if ($this->mode=='play') { //echo $this->owner->popup; global $showplayer; $this->showplayer=1; if ($this->showplayer) { $showplayer=1; } if ($showplayer) { $this->showplayer=1; $out['SHOWPLAYER']=1; } global $terminal_id; $out['TERMINAL_ID']=$terminal_id; } global $collection_id; if ($this->collection_id) { $collection_id=$this->collection_id; } $this->collection_id=$collection_id; $out['COLLECTIONS']=SQLSelect("SELECT * FROM collections ORDER BY TITLE"); if (count($out['COLLECTIONS'])==1) { $collection_id=$out['COLLECTIONS'][0]['ID']; $this->collection_id=$collection_id; $out['COLLECTIONS_TOTAL']=1; } if ($collection_id) { $collection=SQLSelectOne("SELECT * FROM collections WHERE ID='".(int)$collection_id."'"); $path=($collection['PATH']);//addslashes $out['COLLECTION_ID']=$collection['ID']; } else { return; } //$this->getConfig(); //$path=$this->config['PATH']; // echo $path; // global $folder; if ($this->folder) { $folder=base64_decode($this->folder); } else { $this->folder=base64_encode($folder); } $favorites=SQLSelect("SELECT * FROM media_favorites WHERE 1 ORDER BY ID DESC"); if ($favorites) { $total=count($favorites); for($i=0;$i<$total;$i++) { $favorites[$i]['PATH']=urlencode(utf2win($favorites[$i]['PATH'])); } $out['FAVORITES']=$favorites; } $folder=str_replace('././', './', $folder); $path=str_replace('././', './', $path); $act_dir=$path.$folder; $out['MEDIA_PATH']=win2utf($path); $out['CURRENT_DIR']=win2utf('./'.$folder); $out['CURRENT_DIR']=str_replace('././', './', $out['CURRENT_DIR']); $out['CURRENT_DIR_TITLE']=$folder; $tmp=explode('/', $out['CURRENT_DIR']); $total=count($tmp); if ($total>0) { $spath='.'; for($i=0;$i<$total;$i++) { $tmp_rec=array(); $tmp_rec['TITLE']=$tmp[$i]; $spath.='/'.$tmp_rec['TITLE']; $spath=str_replace('././', './', $spath); $tmp_rec['PATH']=urlencode(utf2win($spath).'/'); if ($tmp_rec['TITLE']=='.') { $tmp_rec['TITLE']='Home'; } $out['HISTORY'][]=$tmp_rec; //echo $tmp_rec['PATH']."<br>"; } $out['CURRENT_DIR_TITLE']=($out['HISTORY'][$total-3]['TITLE'].'/'.$out['HISTORY'][$total-2]['TITLE']); } $out['CURRENT_DIR_TITLE_HTML']=urlencode($out['CURRENT_DIR_TITLE']); $out['CURRENT_DIR_HTML']=urlencode('./'.($folder)); $tmp=SQLSelectOne("SELECT ID FROM media_favorites WHERE LIST_ID='".(int)$list_id."' AND COLLECTION_ID='".$collection['ID']."' AND PATH LIKE '".DBSafe($out['CURRENT_DIR'])."'"); if ($tmp['ID']) { $out['FAVORITE']=1; } global $file; if ($file) { $out['FILE']=win2utf($file); $out['BASEFILE']=win2utf(basename($file)); $file=str_replace('/', '\\\\', $file); $out['FULLFILE']=win2utf(addslashes($path).$file); $out['FULLFILE_S']=str_replace('\\\\', '\\', $out['FULLFILE']); } if (preg_match('/foto/is', $act_dir) || preg_match('/photo/is', $act_dir)) { $out['LIST_MODE']='foto'; } $descriptions=$this->getDescriptions($act_dir); global $media_ajax; if ($media_ajax) { global $op; global $list_id; global $title; global $dir; header ("HTTP/1.0: 200 OK\n"); header ('Content-Type: text/html; charset=utf-8'); $tmp_path=$dir; if ($op=='favorite_add') { $rec=array(); $rec['TITLE']=$title; $rec['PATH']=$tmp_path; $rec['LIST_ID']=(int)$list_id; $rec['COLLECTION_ID']=$collection_id; SQLInsert('media_favorites', $rec); echo "OK"; } if ($op=='favorite_remove') { SQLExec("DELETE FROM media_favorites WHERE LIST_ID='".(int)$list_id."' AND COLLECTION_ID='".$collection['ID']."' AND PATH LIKE '".DBSafe($tmp_path)."'"); echo "OK"; } exit; } function sort_files($a, $b) { return strcmp(strtoupper($a["TITLE"]), strtoupper($b["TITLE"])); } $dirs=array(); //$act_dir='\\\\home\\media\\'; //echo $act_dir; $d=openDir($act_dir); //exit; if ($d) { while ($file=readDir($d)) { if (($file==".") || ($file=="..")) { continue; } if (Is_Dir($act_dir.$file)) { $rec=array(); $rec['TITLE']=$file; $rec['TITLE_SHORT']=$rec['TITLE']; if (strlen($rec['TITLE_SHORT'])>50) { $rec['TITLE_SHORT']=substr($rec['TITLE_SHORT'], 0, 50).'...'; } $rec['TITLE']=win2utf($rec['TITLE']); $rec['TITLE_SHORT']=win2utf($rec['TITLE_SHORT']); if (IsSet($descriptions[$file])) { $rec['DESCR']=$descriptions[$file]; } $rec['PATH']=urlencode(($folder.$file)).'/'; $rec['REAL_PATH']=$dir.$file; $rec['ID']=md5($rec['REAL_PATH']); $dirs[]=$rec; } } closeDir($d); } //$dirs=mysort_array($dirs, "TITLE"); usort($dirs, 'sort_files'); //print_r($dirs); if (count($dirs)>0) $out['DIRS']=$dirs; @$d=openDir($act_dir); if ($d) { $cover=$this->getCover($act_dir); if ($cover) { $out['COVER']=$cover; $out['COVER_PATH']=urlencode(str_replace('\\\\', '\\', $act_dir).$cover); } $files=array(); while ($file=readDir($d)) { if (($file==".") || ($file=="..") || ($file=="Descript.ion")) { continue; } if (Is_File($act_dir.$file)) { $rec=array(); $rec['TITLE']=$file; if (IsSet($descriptions[$file])) { $rec['DESCR']=$descriptions[$file]; } if (strlen($rec['TITLE'])>50) { $rec['TITLE_SHORT']=substr($rec['TITLE'], 0, 50)."..."; } else { $rec['TITLE_SHORT']=$rec['TITLE']; } $rec['TITLE']=win2utf($rec['TITLE']); $rec['TITLE_SHORT']=win2utf($rec['TITLE_SHORT']); $rec['REAL_PATH']=($folder.$file); $rec['PATH']=urlencode($folder.$file); $rec['FULL_PATH']=urlencode(str_replace('\\\\', '\\', $act_dir).$file); $size=filesize($act_dir.$file); $total_size+=$size; if ($size>1024) { if ($size>1024*1024) { $size=(((int)(($size/1024/1024)*10))/10)." Mb"; } else { $size=(int)($size/1024)." Kb"; } } else { $size.=" b"; } $rec['SIZE']=$size; $rec['ID']=md5($rec['PATH']); $files[]=$rec; } } closeDir($d); } //$files=mysort_array($files, "TITLE"); usort($files, 'sort_files'); if (count($files)>0) { $total=count($files); $out['TOTAL_FILES']=$total; for($i=0;$i<$total;$i++) { if (preg_match('/\.jpg$/is', $files[$i]['PATH'])) { $files[$i]['IS_FOTO']=1; } if (($i+1)%4==0) { $files[$i]['NEWROW']=1; } } $out['FILES']=$files; } $out['TOTAL_DIRS']=count($dirs); if ($total_size>1024) { if ($total_size>1024*1024) { $total_size=(((int)(($total_size/1024/1024)*10))/10)." Mb"; } else { $total_size=(int)($total_size/1024)." Kb"; } } else { $total_size.=" b"; } $out['TOTAL_SIZE']=$total_size; }
<?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 TITLE LIKE '%" . DBSafe($title) . "%'"; $out['TITLE'] = $title; } // QUERY READY global $save_qry; if ($save_qry) { $qry = $session->data['veradevices_qry']; } else { $session->data['veradevices_qry'] = $qry; } if (!$qry) { $qry = "1"; } // FIELDS ORDER global $sortby_veradevices; if (!$sortby_veradevices) { $sortby_veradevices = $session->data['veradevices_sort'];
/** * Title * * Description * * @access public */ function pollDevice($device_id, $data = 0) { $rec = SQLSelectOne("SELECT * FROM zwave_devices WHERE ID='" . $device_id . "'"); $rec_updated = 0; $comments = array(); $updatedList = array(); $properties = array(); $command_classes = array(); if (!$data) { $data = $this->apiCall('/ZWaveAPI/Run/devices[' . $rec['NODE_ID'] . '].instances[' . $rec['INSTANCE_ID'] . ']'); } if (!$data) { return 0; } if ($_GET['debug']) { //echo $data->updateTime;exit; var_dump($data); } $updateTime = 0; if (!$rec['RAW_DATA']) { $rec_updated = 1; } $rec['RAW_DATA'] = json_encode($data); $rec['SENSOR_VALUE'] = ''; if ($data->data->updateTime) { $updateTime = $data->data->updateTime; } if ($rec['CLASS_BASIC']) { $value = $data->commandClasses->{"32"}->data->value; if ($value !== $rec['BASIC']) { $rec['BASIC'] = $value; $rec_updated = 1; } $command_classes['Basic'] = 32; $properties['Basic'] = $rec['BASIC']; $updatedList['Basic'] = $data->commandClasses->{"32"}->data->{"updateTime"}; if ($data->commandClasses->{"32"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"32"}->data->{"updateTime"}; } } if ($rec['CLASS_SENSOR_BINARY']) { $sensor_data = $data->commandClasses->{"48"}->data; if (isset($data->commandClasses->{"48"}->data->{"1"})) { $sensor_data = $data->commandClasses->{"48"}->data->{"1"}; } $value = (int) $sensor_data->level->value; if ($value !== $rec['LEVEL']) { $rec['LEVEL'] = $value; $rec_updated = 1; } $properties['Level'] = $rec['LEVEL']; $command_classes['Level'] = 48; $updatedList['Level'] = $sensor_data->{"updateTime"}; if ($sensor_data->{"updateTime"} > $updateTime) { $updateTime = $sensor_data->{"updateTime"}; } } if ($rec['CLASS_SENSOR_MULTILEVEL']) { // multiple sensor support required! //SENSOR_VALUE $values = array(); for ($i = 0; $i < 255; $i++) { if (isset($data->commandClasses->{"49"}->data->{"{$i}"})) { $sensor = $data->commandClasses->{"49"}->data->{"{$i}"}; $values[] = trim($sensor->sensorTypeString->value) . ': ' . $sensor->val->value . $sensor->scaleString->value; if (trim($sensor->sensorTypeString->value)) { $prop_name = trim($sensor->sensorTypeString->value) . ', ' . $sensor->scaleString->value; } else { $prop_name = "Sensor {$i}"; } if ($properties[$prop_name]) { $prop_name .= ' (1)'; } $properties[$prop_name] = $sensor->val->value; $command_classes[$prop_name] = 49; $updatedList[$prop_name] = $data->commandClasses->{"49"}->data->{"{$i}"}->{"updateTime"}; if ($data->commandClasses->{"49"}->data->{"{$i}"}->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"49"}->data->{"{$i}"}->{"updateTime"}; } } } $value = implode('; ', $values); if ($value != $rec['SENSOR_VALUE']) { $rec['SENSOR_VALUE'] .= $value . ';'; $rec_updated = 1; } } if ($rec['CLASS_SWITCH_BINARY']) { $value = (int) $data->commandClasses->{"37"}->data->level->value; if ($value !== $rec['LEVEL']) { $rec['LEVEL'] = $value; $rec_updated = 1; } $properties['Level'] = $rec['LEVEL']; $command_classes['Level'] = 37; $updatedList['Level'] = $data->commandClasses->{"37"}->data->{"updateTime"}; if ($data->commandClasses->{"37"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"37"}->data->{"updateTime"}; } } if ($rec['CLASS_SWITCH_MULTILEVEL']) { $value = (int) $data->commandClasses->{"38"}->data->level->value; if ($value !== $rec['LEVEL']) { $rec['LEVEL'] = $value; $rec_updated = 1; } $properties['Level'] = $rec['LEVEL']; $command_classes['Level'] = 38; $updatedList['Level'] = $data->commandClasses->{"38"}->data->{"updateTime"}; if ($data->commandClasses->{"38"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"38"}->data->{"updateTime"}; } $properties['LevelDuration command (level, duration)'] = ''; } if ($rec['CLASS_BATTERY']) { $value = (int) $data->commandClasses->{"128"}->data->last->value; if ($value != $rec['BATTERY_LEVEL']) { $rec['BATTERY_LEVEL'] = $value; $rec_updated = 1; } $command_classes['Battery'] = 128; $properties['Battery'] = $rec['BATTERY_LEVEL']; $updatedList['Battery'] = $data->commandClasses->{"128"}->data->{"updateTime"}; if ($data->commandClasses->{"128"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"128"}->data->{"updateTime"}; } } if ($rec['CLASS_METER']) { // ... 50 $values = array(); for ($i = 0; $i < 255; $i++) { if (isset($data->commandClasses->{"50"}->data->{"{$i}"})) { $sensor = $data->commandClasses->{"50"}->data->{"{$i}"}; $values[] = trim($sensor->sensorTypeString->value) . ': ' . $sensor->val->value . ' ' . $sensor->scaleString->value; if (trim($sensor->sensorTypeString->value)) { $prop_name = trim($sensor->sensorTypeString->value) . ', ' . $sensor->scaleString->value; } else { $prop_name = "Meter {$i}"; } if ($properties[$prop_name]) { $prop_name .= ' (1)'; } $command_classes[$prop_name] = 50; $properties[$prop_name] = $sensor->val->value; $updatedList[$prop_name] = $data->commandClasses->{"50"}->data->{"{$i}"}->{"updateTime"}; if ($data->commandClasses->{"50"}->data->{"{$i}"}->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"50"}->data->{"{$i}"}->{"updateTime"}; } } } $value = implode('; ', $values); if ($value != '') { $rec['SENSOR_VALUE'] .= $value . '; '; $rec_updated = 1; } } if ($rec['CLASS_SENSOR_ALARM']) { // ... $data->commandClasses->{"156"}->data if (is_object($data->commandClasses->{"156"}->data->{"0"}->sensorState)) { $command_classes['AlarmGeneral'] = 156; $properties['AlarmGeneral'] = $data->commandClasses->{"156"}->data->{"0"}->sensorState->value; $updatedList['AlarmGeneral'] = $data->commandClasses->{"156"}->data->{"0"}->sensorState->updateTime; $value = $properties['AlarmGeneral']; if ($value != $rec['LEVEL']) { $rec['LEVEL'] = $value; $rec_updated = 1; } } if (is_object($data->commandClasses->{"156"}->data->{"1"}->sensorState)) { $command_classes['AlarmSmoke'] = 156; $properties['AlarmSmoke'] = $data->commandClasses->{"156"}->data->{"1"}->sensorState->value; $updatedList['AlarmSmoke'] = $data->commandClasses->{"156"}->data->{"1"}->sensorState->updateTime; } if (is_object($data->commandClasses->{"156"}->data->{"2"}->sensorState)) { $command_classes['AlarmCarbonMonoxide'] = 156; $properties['AlarmCarbonMonoxide'] = $data->commandClasses->{"156"}->data->{"2"}->sensorState->value; $updatedList['AlarmCarbonMonoxide'] = $data->commandClasses->{"156"}->data->{"2"}->sensorState->updateTime; } if (is_object($data->commandClasses->{"156"}->data->{"3"}->sensorState)) { $command_classes['AlarmCarbonDioxide'] = 156; $properties['AlarmCarbonDioxide'] = $data->commandClasses->{"156"}->data->{"3"}->sensorState->value; $updatedList['AlarmCarbonDioxide'] = $data->commandClasses->{"156"}->data->{"3"}->sensorState->updateTime; } if (is_object($data->commandClasses->{"156"}->data->{"4"}->sensorState)) { $command_classes['AlarmHeat'] = 156; $properties['AlarmHeat'] = $data->commandClasses->{"156"}->data->{"4"}->sensorState->value; $updatedList['AlarmHeat'] = $data->commandClasses->{"156"}->data->{"4"}->sensorState->updateTime; } if (is_object($data->commandClasses->{"156"}->data->{"5"}->sensorState)) { $command_classes['AlarmFlood'] = 156; $properties['AlarmFlood'] = $data->commandClasses->{"156"}->data->{"5"}->sensorState->value; $updatedList['AlarmFlood'] = $data->commandClasses->{"156"}->data->{"5"}->sensorState->updateTime; } if ($data->commandClasses->{"156"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"156"}->data->{"updateTime"}; } } if ($rec['CLASS_SCENE_CONTROLLER'] && is_object($data->commandClasses->{"43"}->data->{"currentScene"})) { // ... 43 $properties['CurrentScene'] = $data->commandClasses->{"43"}->data->{"currentScene"}->value; if ($data->commandClasses->{"43"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"43"}->data->{"updateTime"}; } } elseif ($rec['CLASS_SCENE_CONTROLLER'] && is_object($data->commandClasses->{"45"}->data->{"currentScene"})) { // ... 45 $properties['CurrentScene'] = $data->commandClasses->{"45"}->data->{"currentScene"}->value; if ($data->commandClasses->{"45"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"43"}->data->{"updateTime"}; } } if ($rec['CLASS_THERMOSTAT'] && isset($data->commandClasses->{"64"}->data->mode->value)) { //$value=$data->commandClasses->{"64"}->data->{$data->commandClasses->{"64"}->data->mode->value}->modeName->value; $rec['SENSOR_VALUE'] .= " Mode: " . $data->commandClasses->{"64"}->data->{$data->commandClasses->{"64"}->data->mode->value}->modeName->value . ';'; $value = $data->commandClasses->{"64"}->data->mode->value; if ($value != $rec['MODE_VALUE']) { $rec['MODE_VALUE'] = $value; $rec_updated = 1; } $command_classes['Thermostat mode'] = 64; $properties['Thermostat mode'] = $rec['MODE_VALUE']; $updatedList['Thermostat mode'] = $data->commandClasses->{"64"}->data->{"updateTime"}; if ($data->commandClasses->{"64"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"64"}->data->{"updateTime"}; } $comments_str = ''; for ($i = 0; $i < 255; $i++) { if ($data->commandClasses->{"64"}->data->{$i}) { $comments_str .= "{$i} = " . $data->commandClasses->{"64"}->data->{$i}->modeName->value . "; "; } } $comments['Thermostat mode'] = $comments_str; if (isset($data->commandClasses->{"67"}->data)) { //ThermostatSetPoint for ($i = 0; $i < 255; $i++) { if ($data->commandClasses->{"67"}->data->{$i}->val) { $key = 'ThermostatSetPoint ' . $data->commandClasses->{"67"}->data->{$i}->modeName->value; $properties[$key] = $data->commandClasses->{"67"}->data->{$i}->val->value; $command_classes[$key] = 67; if ($data->commandClasses->{"67"}->data->{$i}->scaleString->value) { $comments[$key] = $data->commandClasses->{"67"}->data->{$i}->scaleString->value; } } } } if (isset($data->commandClasses->{"68"}->data->mode->value)) { //ThermostatFanMode $properties['ThermostatFanOn'] = (int) $data->commandClasses->{"68"}->data->on->value; $command_classes['ThermostatFanMode'] = 68; $properties['ThermostatFanMode'] = $data->commandClasses->{"68"}->data->mode->value; if ($data->commandClasses->{"68"}->data->{"updateTime"} > $updateTime) { $updateTime = $data->commandClasses->{"68"}->data->{"updateTime"}; } $rec['SENSOR_VALUE'] .= " Fan Mode: " . $data->commandClasses->{"68"}->data->{$data->commandClasses->{"68"}->data->mode->value}->modeName->value . ';'; $comments_str = ''; for ($i = 0; $i < 255; $i++) { if ($data->commandClasses->{"68"}->data->{$i}) { $comments_str .= "{$i} = " . $data->commandClasses->{"68"}->data->{$i}->modeName->value . "; "; } } $comments['ThermostatFanMode'] = $comments_str; } } if ($updateTime) { $properties['updateTime'] = $updateTime; $rec['LATEST_UPDATE'] = date('Y-m-d H:i:s', $properties['updateTime']); $rec_updated = 1; } if ($rec_updated) { SQLUpdate('zwave_devices', $rec); } foreach ($properties as $k => $v) { $prop = SQLSelectOne("SELECT * FROM zwave_properties WHERE DEVICE_ID='" . $rec['ID'] . "' AND UNIQ_ID LIKE '" . DBSafe($k) . "'"); $prop['DEVICE_ID'] = $rec['ID']; $prop['UNIQ_ID'] = $k; $prop['TITLE'] = $k; $prop['COMMAND_CLASS'] = $command_classes[$k]; if ($prop['VALUE'] != $v) { $prop['UPDATED'] = date('Y-m-d H:i:s'); } if ($updatedList[$k]) { $prop['UPDATED'] = date('Y-m-d H:i:s', $updatedList[$k]); } $prop['VALUE'] = $v; if ($comments[$k]) { $prop['COMMENTS'] = $comments[$k]; } if (is_numeric($prop['VALUE']) && $prop['VALUE'] !== '') { $prop['VALUE'] = round($prop['VALUE'], 3); } if ($prop['ID']) { SQLUpdate('zwave_properties', $prop); if ($prop['VALUE'] !== '') { $validated = 1; } else { $validated = 0; continue; } if ($prop['LINKED_OBJECT']) { if ($prop['CORRECT_VALUE']) { $prop['VALUE'] += (double) $prop['CORRECT_VALUE']; } } if ($prop['VALIDATE']) { if ((double) $prop['VALUE'] < (double) $prop['VALID_FROM'] || (double) $prop['VALUE'] > (double) $prop['VALID_TO']) { $validated = 0; } } if ($prop['LINKED_OBJECT'] && $prop['LINKED_PROPERTY'] && $validated) { $old_value = getGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY']); if ($prop['VALUE'] != $old_value) { setGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'], $prop['VALUE'], array($this->name => '0')); } } if ($prop['LINKED_OBJECT'] && $prop['LINKED_METHOD'] && $validated && ($prop['VALUE'] != $old_value || !$prop['LINKED_PROPERTY'])) { $params = array(); $params['VALUE'] = $prop['VALUE']; callMethod($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_METHOD'], $params); } } else { $prop['ID'] = SQLInsert('zwave_properties', $prop); } } //print_r($data);exit; }