function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_context_id = 0) { $user_id = context_getuser(); $user = SQLSelectOne("SELECT * FROM users WHERE ID='" . (int) $user_id . "'"); $user['ACTIVE_CONTEXT_ID'] = $id; if ($id) { $user['ACTIVE_CONTEXT_EXTERNAL'] = 1; } else { $user['ACTIVE_CONTEXT_EXTERNAL'] = 0; } $user['ACTIVE_CONTEXT_UPDATED'] = date('Y-m-d H:i:s'); DebMes("setting external context: " . $id); SQLUpdate('users', $user); if ($id) { //execute pattern if (!$timeout) { $timeout = 60; } $ev = ''; if ($timeout_code) { $ev .= $timeout_code; } if ($timeout_context_id) { $ev .= "context_activate_ext(" . (int) $timeout_context_id . ");"; } else { $ev .= "context_clear();"; } setTimeOut('user_' . $user_id . '_contexttimeout', $ev, $timeout); } else { context_clear(); clearTimeOut('user_' . $user_id . '_contexttimeout'); } }
function removeMissingSubscribers() { $settings = SQLSelect("SELECT * FROM settings WHERE NAME LIKE 'HOOK_EVENT_%' AND TYPE='json'"); $total = count($settings); for ($i = 0; $i < $total; $i++) { $data = json_decode($settings[$i]['VALUE'], true); $changed = 0; if (is_array($data)) { foreach ($data as $k => $v) { $module_name = $k; if (!file_exists(DIR_MODULES . 'modules/' . $module_name . '/' . $module_name . '.class.php')) { unset($data[$module_name]); $changed = 1; } } if ($changed) { $settings[$i]['VALUE'] = json_encode($data); SQLUpdate('settings', $settings[$i]); } } } }
/** * product_categories update tree * * @access private */ function updateTree_product_categories($parent_id = 0, $parent_list = '') { $table = 'product_categories'; if (!is_array($parent_list)) { $parent_list = array(); } $sub_list = array(); $res = SQLSelect("SELECT * FROM {$table} WHERE PARENT_ID='{$parent_id}'"); $total = count($res); for ($i = 0; $i < $total; $i++) { if ($parent_list[0]) { $res[$i]['PARENT_LIST'] = implode(',', $parent_list); } else { $res[$i]['PARENT_LIST'] = '0'; } $sub_list[] = $res[$i]['ID']; $tmp_parent = $parent_list; $tmp_parent[] = $res[$i]['ID']; $sub_this = $this->updateTree_product_categories($res[$i]['ID'], $tmp_parent); if ($sub_this[0]) { $res[$i]['SUB_LIST'] = implode(',', $sub_this); } else { $res[$i]['SUB_LIST'] = $res[$i]['ID']; } SQLUpdate($table, $res[$i]); $sub_list = array_merge($sub_list, $sub_this); } return $sub_list; }
/** * 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) { 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; } }
$state_rec['CONDITION_ADVANCED'] = ''; } } $state_rec['SWITCH_SCENE'] = (int) $switch_scene_new; if ($state_rec['ID']) { SQLUpdate('elm_states', $state_rec); } else { $state_rec['ID'] = SQLInsert('elm_states', $state_rec); $state_id = $state_rec['ID']; } } elseif ($element['TYPE'] == 'container') { $state_rec['TITLE'] = 'default'; $state_rec['ELEMENT_ID'] = $element['ID']; $state_rec['TITLE'] = $state_title_new; if ($state_rec['ID']) { SQLUpdate('elm_states', $state_rec); } else { $state_rec['ID'] = SQLInsert('elm_states', $state_rec); $state_id = $state_rec['ID']; } } elseif (($element['TYPE'] == 'nav' || $element['TYPE'] == 'navgo') && !$state_rec['ID']) { $state_rec = array(); $state_rec['TITLE'] = 'default'; $state_rec['ELEMENT_ID'] = $element['ID']; $state_rec['HTML'] = $element['TITLE']; $state_rec['ID'] = SQLInsert('elm_states', $state_rec); $state_id = $state_rec['ID']; } elseif ($element['TYPE'] == 'button' && !$state_rec['ID']) { global $linked_object; global $linked_method; $state_rec = array();
/** * btdevices edit/add * * @access public */ function edit_btdevices(&$out, $id) { $rec = SQLSelectOne("SELECT * FROM btdevices WHERE ID='" . (int) $id . "'"); if ($this->mode == 'update') { global $title; global $user_id; $rec['TITLE'] = $title; $rec['USER_ID'] = $user_id; SQLUpdate('btdevices', $rec); $this->redirect("?"); } $rec['LOG'] = nl2br($rec['LOG']); outHash($rec, $out); $out['USERS'] = SQLSelect("SELECT * FROM users ORDER BY NAME"); }
/** * Saving module configuration * * Used for saving $this->config variable in project module repository database for future * * @access public */ function saveConfig() { $rec=SQLSelectOne("SELECT * FROM project_modules WHERE NAME='".$this->name."'"); $rec["DATA"]=serialize($this->config); SQLUpdate("project_modules", $rec); }
function removeLinkedProperty($object, $property, $module) { $value = SQLSelectOne("SELECT * FROM pvalues WHERE ID='" . getValueIdByName($object, $property) . "'"); if ($value['ID']) { if (!$value['LINKED_MODULES']) { $tmp = array(); } else { $tmp = explode(',', $value['LINKED_MODULES']); } if (in_array($module, $tmp)) { $total = count($tmp); $res = array(); for ($i = 0; $i < $total; $i++) { if ($tmp[$i] != $module) { $res[] = $tmp[$i]; } } $tmp = $res; $value['LINKED_MODULES'] = implode(',', $tmp); SQLUpdate('pvalues', $value); } } else { return 0; } }
*/ if ($action == 'testdata') { if ($step < 2) { $content = str_replace(array("\r", "\n\n", ";\n"), array('', "\n", ";<wind>\n"), trim(readover(R_P . 'lang/example.sql'), " \n")); //$content = preg_replace("/{#(.+?)}/eis",'$lang[\\1]',$content).'<wind>'; $content = explode("\n", $content); $writearray = SQLCreate($content); } @set_time_limit(200); if (!file_exists(D_P . 'data/sql_config.php')) { Promptmsg('config_noexists', 'database'); } else { $db = pwNewDBForInstall(); } $sqlcache = readover(D_P . 'data/install_sys.sql'); $update = SQLUpdate($sqlcache, 500); if ($update) { $step = $step ? $step + 1 : 2; $stepstring = str_pad('..', $step); $input = "<input type=\"hidden\" name=\"step\" value=\"{$step}\">"; Promptmsg('install_initdata', $action, true); } else { require_once R_P . 'admin/cache.php'; $pwChannel = L::loadClass('channelservice', 'area'); $pwChannel->updateAreaChannels(); require R_P . 'lang/step/nav_tiyan.php'; //设置门户首页为默认首页 $update = array('area_default_alias', 'string', 'finance', ''); $db->update("REPLACE INTO pw_hack VALUES (" . pwImplode($update) . ')'); //更新关联版块信息 updatecache_cnc();
/** * Title * * Description * * @access public */ function checkAllVars($force = 0) { // ping hosts if ($force) { $pings = SQLSelect("SELECT * FROM webvars WHERE 1"); } else { $pings = SQLSelect("SELECT * FROM webvars WHERE CHECK_NEXT<=NOW()"); } $total = count($pings); for ($i = 0; $i < $total; $i++) { $host = $pings[$i]; if (!$force) { echo date('H:i:s') . " Checking webvar: " . processTitle($host['HOSTNAME']) . "\n"; } if (!$host['HOSTNAME']) { continue; } $online_interval = $host['ONLINE_INTERVAL']; if (!$online_interval) { $online_interval = 60; } $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval); SQLUpdate('webvars', $host); // checking //web host $old_status = $host['LATEST_VALUE']; if ($host['AUTH'] && $host['USERNAME']) { $content = getURL(processTitle($host['HOSTNAME']), $host['ONLINE_INTERVAL'], $host['USERNAME'], $host['PASSWORD']); } else { $content = getURL(processTitle($host['HOSTNAME']), $host['ONLINE_INTERVAL']); } if ($host['ENCODING'] != '') { $content = iconv($host['ENCODING'], "UTF-8", $content); } $ok = 1; $new_status = ''; if ($host['SEARCH_PATTERN']) { if (preg_match('/' . $host['SEARCH_PATTERN'] . '/is', $content, $m)) { //$new_status=$m[1]; $total1 = count($m); for ($i1 = 1; $i1 < $total1; $i1++) { $new_status .= $m[$i1]; } } else { $ok = 0; // result did not matched } } else { $new_status = $content; } if ($host['CHECK_PATTERN'] && !preg_match('/' . $host['CHECK_PATTERN'] . '/is', $new_status)) { $ok = 0; // result did not pass the check } if (strlen($new_status) > 50 * 1024) { $new_status = substr($new_status, 0, 50 * 1024); } if (!$ok) { $host['LOG'] = date('Y-m-d H:i:s') . ' incorrect value:' . $new_status . "\n" . $host['LOG']; $tmp = explode("\n", $host['LOG']); $total = count($tmp); if ($total > 50) { $tmp = array_slice($tmp, 0, 50); $host['LOG'] = implode("\n", $tmp); } SQLUpdate('webvars', $host); continue; } $host['CHECK_LATEST'] = date('Y-m-d H:i:s'); $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval); if ($old_status != $new_status) { $host['LOG'] = date('Y-m-d H:i:s') . ' new value:' . $new_status . "\n" . $host['LOG']; $tmp = explode("\n", $host['LOG']); $total = count($tmp); if ($total > 50) { $tmp = array_slice($tmp, 0, 50); $host['LOG'] = implode("\n", $tmp); } } $host['LATEST_VALUE'] = $new_status; SQLUpdate('webvars', $host); if ($host['LINKED_OBJECT'] != '' && $host['LINKED_PROPERTY'] != '') { getObject($host['LINKED_OBJECT'])->setProperty($host['LINKED_PROPERTY'], $new_status); } if ($old_status != $new_status && $old_status != '') { $params = array('VALUE' => $new_status); // do some status change actions $run_script_id = 0; $run_code = ''; // got online if ($host['SCRIPT_ID']) { $run_script_id = $host['SCRIPT_ID']; } elseif ($host['CODE']) { $run_code = $host['CODE']; } if ($run_script_id) { //run script runScript($run_script_id, $params); } elseif ($run_code) { //run code try { $code = $run_code; $success = eval($code); if ($success === false) { DebMes("Error in webvar code: " . $code); registerError('webvars', "Error in webvar code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); registerError('webvars', get_class($e) . ', ' . $e->getMessage()); } } } } }
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() . '.'); } } } }
// adding new record } if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) { addLinkedProperty($rec['LINKED_OBJECT'], $rec['LINKED_PROPERTY'], $this->name); } 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('mqtt', $rec); $this->setProperty($rec['ID'], $new_value, 1); } } //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;
/** * Title * * Description * * @access public */ function checkAllHosts($limit = 1000) { // ping hosts $pings = SQLSelect("SELECT * FROM pinghosts WHERE CHECK_NEXT<=NOW() ORDER BY CHECK_NEXT LIMIT " . $limit); $total = count($pings); for ($i = 0; $i < $total; $i++) { $host = $pings[$i]; echo "Checking " . $host['HOSTNAME'] . "\n"; $online_interval = $host['ONLINE_INTERVAL']; if (!$online_interval) { $online_interval = 60; } $offline_interval = $host['OFFLINE_INTERVAL']; if (!$offline_interval) { $offline_interval = $online_interval; } if ($host['STATUS'] == '1') { $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval); } else { $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $offline_interval); } SQLUpdate('pinghosts', $host); $online = 0; // checking if (!$host['TYPE']) { //ping host $online = ping(processTitle($host['HOSTNAME'])); } else { //web host $online = getURL(processTitle($host['HOSTNAME']), 0); SaveFile("./cached/host_" . $host['ID'] . '.html', $online); if ($host['SEARCH_WORD'] != '' && !is_integer(strpos($online, $host['SEARCH_WORD']))) { $online = 0; } if ($online) { $online = 1; } } if ($online) { $new_status = 1; } else { $new_status = 2; } $old_status = $host['STATUS']; if ($host['COUNTER_REQUIRED']) { $old_status_expected = $host['STATUS_EXPECTED']; $host['STATUS_EXPECTED'] = $new_status; if ($old_status_expected != $host['STATUS_EXPECTED']) { $host['COUNTER_CURRENT'] = 0; $host['LOG'] = date('Y-m-d H:i:s') . ' tries counter reset (status: ' . $host['STATUS_EXPECTED'] . ')' . "\n" . $host['LOG']; } elseif ($host['STATUS'] != $host['STATUS_EXPECTED']) { $host['COUNTER_CURRENT']++; $host['LOG'] = date('Y-m-d H:i:s') . ' tries counter increased to ' . $host['COUNTER_CURRENT'] . ' (status: ' . $host['STATUS_EXPECTED'] . ')' . "\n" . $host['LOG']; } if ($host['COUNTER_CURRENT'] >= $host['COUNTER_REQUIRED']) { $host['STATUS'] = $host['STATUS_EXPECTED']; $host['COUNTER_CURRENT'] = 0; } else { $interval = min($online_interval, $offline_interval, 20); $online_interval = $interval; $offline_interval = $interval; } } else { $host['STATUS'] = $new_status; $host['STATUS_EXPECTED'] = $host['STATUS']; $host['COUNTER_CURRENT'] = 0; } $host['CHECK_LATEST'] = date('Y-m-d H:i:s'); if ($host['LINKED_OBJECT'] != '' && $host['LINKED_PROPERTY'] != '') { setGlobal($host['LINKED_OBJECT'] . '.' . $host['LINKED_PROPERTY'], $host['STATUS']); } if ($host['STATUS'] == '1') { $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval); } else { $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $offline_interval); } if ($old_status != $host['STATUS']) { if ($host['STATUS'] == 2) { $host['LOG'] .= date('Y-m-d H:i:s') . ' Host is offline' . "\n"; } elseif ($host['STATUS'] == 1) { $host['LOG'] .= date('Y-m-d H:i:s') . ' Host is online' . "\n"; } $tmp = explode("\n", $host['LOG']); $total = count($tmp); if ($total > 50) { $tmp = array_slice($tmp, 0, 50); $host['LOG'] = implode("\n", $tmp); } } SQLUpdate('pinghosts', $host); if ($old_status != $host['STATUS'] && $old_status != 0) { // do some status change actions $run_script_id = 0; $run_code = ''; if ($old_status == 2 && $host['STATUS'] == 1) { // got online if ($host['SCRIPT_ID_ONLINE']) { $run_script_id = $host['SCRIPT_ID_ONLINE']; } elseif ($host['CODE_ONLINE']) { $run_code = $host['CODE_ONLINE']; } } elseif ($old_status == 1 && $host['STATUS'] == 2) { // got offline if ($host['SCRIPT_ID_OFFLINE']) { $run_script_id = $host['SCRIPT_ID_OFFLINE']; } elseif ($host['CODE_OFFLINE']) { $run_code = $host['CODE_OFFLINE']; } } if ($run_script_id) { //run script runScript($run_script_id); } elseif ($run_code) { //run code try { $code = $run_code; $success = eval($code); if ($success === false) { DebMes("Error in hosts online code: " . $code); registerError('ping_hosts', "Error in hosts online code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); registerError('ping_hosts', get_class($e) . ', ' . $e->getMessage()); } } } } }
/** * Title * * Description * * @access public */ function checkWatchFolder($id, $no_script = 0) { $rec = SQLSelectOne("SELECT * FROM watchfolders WHERE ID=" . (int) $id); if (!$rec['ID']) { return 0; } $res = $this->getTree($rec['FOLDER'], $rec['CHECK_SUB'], $rec['CHECK_MASK']); $rec['CHECK_LATEST'] = date('Y-m-d H:i:s'); if (!$rec['CHECK_INTERVAL']) { $rec['CHECK_INTERVAL'] = 60; } $rec['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $rec['CHECK_INTERVAL'] * 60); if ($rec['CHECK_RESULTS'] != serialize($res)) { $files_updated = 1; } else { $files_updated = 0; } if ($rec['CHECK_RESULTS']) { $last_check_results = unserialize($rec['CHECK_RESULTS']); } else { $last_check_results = array(); } $rec['CHECK_RESULTS'] = serialize($res); SQLUpdate('watchfolders', $rec); if ($files_updated && !$no_script && $rec['SCRIPT_ID'] && $rec['SCRIPT_TYPE']) { //checking for updated files $new_files = array(); foreach ($res as $k => $v) { if (!$last_check_results[$k] || $last_check_results[$k]['SIZE'] != $res[$k]['SIZE']) { $new_files[$k] = $v; } } //run script if set if ($rec['SCRIPT_TYPE'] == 2) { // run script for all files $params = array(); $params['FOLDER'] = $rec['FOLDER']; $params['FILES_UPDATED'] = $new_files; runScript($rec['SCRIPT_ID'], $params); } elseif ($rec['SCRIPT_TYPE'] == 1) { // run script for every new file foreach ($new_files as $k => $v) { $params = array(); $params['FOLDER'] = $rec['FOLDER']; $params['FILENAME'] = $k; runScript($rec['SCRIPT_ID'], $params); } } } }
$res = SQLInsert($sql); } else { $res = "Problème de suppression"; } echo $res; break; case 'modifierHeure': //"&start="+event.start+"&end="+event.end $res = NULL; if (($id = valider("id", "GET")) && ($start = valider("start", "GET")) && ($end = valider("end", "GET"))) { //UPDATE client SET DatePermis='" . $date_permis . "' WHERE idPersonne=" . $id; $start = str_replace("T", " ", $start); $end = str_replace("T", " ", $end); //UPDATE `pinf`.`choixsurplanning` SET `dateDebut` = '2015-02-04 09:10:00' WHERE `choixsurplanning`.`id` =21; $sql = "UPDATE choixsurplanning SET dateDebut ='{$start}', dateFin ='{$end}' WHERE id ={$id}"; $res = SQLUpdate($sql); } else { $res = "Problème d'update"; } echo $res; //echo($sql); break; case 'supprimerTout': $res = NULL; $sql = "DELETE FROM choixsurplanning"; $res = SQLInsert($sql); echo $res; break; /* *** FIN PLANNING *** */ /* *** PARTIE INFOS PRATIQUES *** */ /* Auteur : Maxence Delattre */
if ($res[0]['ID']) { $total = count($res); for ($i = 0; $i < $total; $i++) { // some action for every record if required // some action for every record if required if ($this->mode == 'update') { global ${'value_' . $res[$i]['ID']}; global ${'notes_' . $res[$i]['ID']}; $all_settings[$res[$i]['NAME']] = ${'value_' . $res[$i]['ID']}; $res[$i]['VALUE'] = ${'value_' . $res[$i]['ID']}; $res[$i]['NOTES'] = htmlspecialchars(${'notes_' . $res[$i]['ID']}); SQLUpdate('settings', $res[$i]); } if ($this->mode == 'reset') { $res[$i]['VALUE'] = $res[$i]['DEFAULTVALUE']; SQLUpdate('settings', $res[$i]); } if ($res[$i]['VALUE'] == $res[$i]['DEFAULTVALUE']) { $res[$i]['ISDEFAULT'] = '1'; } $res[$i]['VALUE'] = htmlspecialchars($res[$i]['VALUE']); } $out['RESULT'] = $res; } // some action for every record if required if ($this->mode == 'update') { if ($all_settings['GROWL_ENABLE']) { include_once ROOT . 'lib/growl/growl.gntp.php'; $growl = new Growl($all_settings['GROWL_HOST'], $all_settings['GROWL_PASSWORD']); $growl->setApplication('MajorDoMo', 'Notifications'); $growl->registerApplication('http://connect.smartliving.ru/img/logo.png');
/** * 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); } } } } } }
function supprimerMessage($idMesg) { // supprime une conversation et ses messages $SQL = "DELETE FROM messages WHERE id='{$idMesg}'"; SQLUpdate($SQL); }
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!")); } }
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; }
/** * BackEnd * * Module backend * * @access public */ function admin(&$out) { /* $this->getConfig(); if ($this->mode=='update') { global $path; $this->config['PATH']=$path; $this->saveConfig(); $out['OK']=1; } $out['PATH']=htmlspecialchars($this->config['PATH']); */ global $id; if ($this->view_mode=='delete') { $rec=SQLSelectOne("SELECT * FROM collections WHERE ID='".(int)$id."'"); SQLExec("DELETE FROM collections WHERE ID='".$rec['ID']."'"); $this->redirect("?"); } if ($this->view_mode=='edit') { $rec=SQLSelectOne("SELECT * FROM collections WHERE ID='".(int)$id."'"); if ($this->mode=='update_collection') { global $title; global $path; $rec['TITLE']=$title; $rec['PATH']=$path; if ($rec['TITLE'] && $rec['PATH']) { if ($rec['ID']) { SQLUpdate('collections', $rec); } else { $rec['ID']=SQLInsert('collections', $rec); } $this->redirect("?"); } } outHash($rec, $out); } $out['COLLECTIONS']=SQLSelect("SELECT * FROM collections ORDER BY TITLE"); }
} } } } } else { $sqlQuery = "SELECT *\n FROM gpslog\n WHERE DEVICE_ID = '" . $device['ID'] . "'\n AND ID != '" . $rec['ID'] . "'\n ORDER BY ADDED DESC\n LIMIT 1"; $tmp = SQLSelectOne($sqlQuery); if ($tmp['LOCATION_ID'] == $locations[$i]['ID']) { //Debmes("Device (" . $device['TITLE'] . ") LEFT location " . $locations[$i]['TITLE']); // left location $sqlQuery = "SELECT *\n FROM gpsactions\n WHERE LOCATION_ID = '" . $locations[$i]['ID'] . "'\n AND ACTION_TYPE = 0\n AND USER_ID = '" . $device['USER_ID'] . "'"; $gpsaction = SQLSelectOne($sqlQuery); if ($gpsaction['ID']) { $gpsaction['EXECUTED'] = date('Y-m-d H:i:s'); $gpsaction['LOG'] = $gpsaction['EXECUTED'] . " Executed\n" . $gpsaction['LOG']; SQLUpdate('gpsactions', $gpsaction); if ($gpsaction['SCRIPT_ID']) { runScript($gpsaction['SCRIPT_ID']); } elseif ($gpsaction['CODE']) { try { $code = $gpsaction['CODE']; $success = eval($code); if ($success === false) { DebMes("Error in GPS action code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); } } } }
/** * 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; }
$total=count($res); for($i=0;$i<$total;$i++) { // some action for every record if required $item=$res[$i]; if ($item['LINKED_PROPERTY']!='') { $lprop=getObject($item['LINKED_OBJECT'])->getProperty($item['LINKED_PROPERTY']); if ($item['TYPE']=='custom') { $field='DATA'; } else { $field='CUR_VALUE'; } if ($lprop!=$item[$field]) { $item[$field]=$lprop; SQLUpdate('commands', $item); $res[$i]=$item; } } if ($item['TYPE']=='timebox') { $tmp=explode(':', $item['CUR_VALUE']); $value1=(int)$tmp[0]; $value2=(int)$tmp[1]; for($h=0;$h<=23;$h++) { $v=$h; if ($v<10) { $v='0'.$v; }
$prec['TITLE'] = trim(${'ptitle_' . $properties[$i]['ID']}); if ($prec['ONLINE_INTERVAL'] != ${'pinterval_' . $properties[$i]['ID']}) { $prec['ONLINE_INTERVAL'] = (int) ${'pinterval_' . $properties[$i]['ID']}; if ($prec['ONLINE_INTERVAL']) { $prec['CHECK_NEXT'] = date('Y-m-d H:i:s'); } } $old_linked_object = $prec['LINKED_OBJECT']; $old_linked_property = $prec['LINKED_PROPERTY']; $prec['LINKED_OBJECT'] = trim(${'linked_object_' . $properties[$i]['ID']}); $prec['LINKED_PROPERTY'] = trim(${'linked_property_' . $properties[$i]['ID']}); $value_changed = 0; if (${'pvalue_' . $properties[$i]['ID']} != $prec['VALUE']) { $value_changed = 1; } SQLUpdate('snmpproperties', $prec); if ($prec['LINKED_OBJECT'] && $prec['LINKED_PROPERTY']) { addLinkedProperty($prec['LINKED_OBJECT'], $prec['LINKED_PROPERTY'], $this->name); } if ($old_linked_object && $old_linked_object != $prec['LINKED_OBJECT'] && $old_linked_property && $old_linked_property != $prec['LINKED_PROPERTY']) { removeLinkedProperty($old_linked_object, $old_linked_property, $this->name); } if ($value_changed) { $this->setProperty($properties[$i]['ID'], trim(${'pvalue_' . $properties[$i]['ID']})); } } global $oid_new; global $ptitle_new; global $pvalue_new; global $type_new; global $pinterval_new;
outHash($rec, $out); $out['LOG'] = nl2br($out['LOG']); if ($rec['ID']) { $properties = SQLSelect("SELECT * FROM owproperties WHERE DEVICE_ID='" . $rec['ID'] . "' ORDER BY SYSNAME"); if ($this->mode == 'update') { $total = count($properties); for ($i = 0; $i < $total; $i++) { global ${'linked_object' . $properties[$i]['ID']}; global ${'linked_property' . $properties[$i]['ID']}; if (${'linked_object' . $properties[$i]['ID']} && ${'linked_property' . $properties[$i]['ID']}) { $properties[$i]['LINKED_OBJECT'] = ${'linked_object' . $properties[$i]['ID']}; $properties[$i]['LINKED_PROPERTY'] = ${'linked_property' . $properties[$i]['ID']}; SQLUpdate('owproperties', $properties[$i]); } elseif ($properties[$i]['LINKED_OBJECT'] || $properties[$i]['LINKED_PROPERTY']) { $properties[$i]['LINKED_OBJECT'] = ''; $properties[$i]['LINKED_PROPERTY'] = ''; SQLUpdate('owproperties', $properties[$i]); } global ${'starred' . $properties[$i]['ID']}; if (${'starred' . $properties[$i]['ID']}) { $properties[$i]['STARRED'] = 1; SQLUpdate('owproperties', $properties[$i]); } else { $properties[$i]['STARRED'] = 0; SQLUpdate('owproperties', $properties[$i]); } } } $out['PROPERTIES'] = $properties; } $out['SCRIPTS'] = SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
/** * BackEnd * * Module backend * * @access public */ function admin(&$out) { global $session; if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) { $out['SET_DATASOURCE']=1; } global $delete_room; if ($delete_room!='' && LOGGED_USER) { $room=SQLSelectOne("SELECT * FROM shoutrooms WHERE ID='".(int)$delete_room."' AND ADDED_BY=".(int)$session->data['logged_user']); if ($room['ID']) { SQLExec("DELETE FROM shouts WHERE ROOM_ID=".$room['ID']); SQLExec("DELETE FROM shoutrooms WHERE ID='".$room['ID']."'"); } unset($session->data['SHOUT_ROOM_ID']); $this->redirect("/chat.html"); } global $change_visibility; if ($change_visibility && LOGGED_USER) { $room=SQLSelectOne("SELECT * FROM shoutrooms WHERE ID='".(int)$change_visibility."' AND ADDED_BY=".LOGGED_USER_ID); if ($room['ID']) { $room['IS_PUBLIC'] = $room['IS_PUBLIC']?0:1; SQLUpdate('shoutrooms',$room); } $this->redirect("/chat/room".$room['ID'].'.html'); } if ($this->mode=='newroom' && $session->data['logged_user']) { $rec=array(); global $room_title; global $make_public; $rec['TITLE']=htmlspecialchars($room_title); $rec['ADDED_BY']=$session->data['logged_user']; $rec['ADDED']=date('Y-m-d H:i:s'); $rec['IS_PUBLIC']=(int)$make_public; if ($rec['TITLE']) { $rec['ID']=SQLInsert('shoutrooms', $rec); $this->redirect("/chat/room".$rec['ID'].'.html'); } } if ($this->data_source=='shouts' || $this->data_source=='') { if ($this->view_mode=='' || $this->view_mode=='search_shouts') { $this->search_shouts($out); } if ($this->view_mode=='delete_shouts') { $this->delete_shouts($this->id); $this->redirect("?"); } } }
} $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"]++; } } } }
/** * 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); }