/** * 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 unsubscribeFromEvent($module_name, $event_name = '') { $rec = SQLSelectOne("SELECT * FROM settings WHERE NAME LIKE 'HOOK_EVENT_'" . strtoupper($event_name) . " AND TYPE='json'"); if (isset($rec['ID'])) { $data = json_decode($rec['VALUE'], true); if (isset($data[$module_name])) { unset($data[$module_name]); $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; } }
function dump_events($ecode, $data, $server, $port) { // Search exist event $parent_class_rec = SQLSelectOne("SELECT ID FROM classes WHERE TITLE LIKE 'Telephony'"); if ($parent_class_rec['ID']) { $class_rec = SQLSelectOne("SELECT * FROM classes WHERE TITLE LIKE 'AsteriskAMI' AND PARENT_ID = '" . $parent_class_rec['ID'] . "'"); if ($class_rec['ID']) { $object_rec = SQLSelectOne("SELECT * FROM objects WHERE CLASS_ID='" . $class_rec['ID'] . "' AND TITLE = 'Asterisk'"); if ($object_rec['ID']) { $method_rec = SQLSelectOne("SELECT * FROM methods WHERE OBJECT_ID='" . $object_rec['ID'] . "' AND TITLE = 'Event" . $data['Event'] . "'"); if (!$method_rec['ID']) { // New event. Add method to class AsteriskAMI and object // Add class method echo date('Y-m-d H:i:s') . " : Receive new event. Add method Event" . $data['Event'] . "\n"; $class_method_rec['CLASS_ID'] = $class_rec['ID']; $class_method_rec['TITLE'] = 'Event' . $data['Event']; $class_method_rec['CODE'] = "echo date('Y-m-d H:i:s')" . ".\" : Event \"." . '$params[\'Event\']' . ".\" received. Process... \\n\"" . ";\n"; SQLInsert('methods', $class_method_rec); // Add object method $method_rec['OBJECT_ID'] = $object_rec['ID']; $method_rec['TITLE'] = 'Event' . $data['Event']; $method_rec['CALL_PARENT'] .= "1"; $method_rec['CODE'] .= "/**\n"; $method_rec['CODE'] .= "Array received form Asterisk:\n"; foreach ($data as $key => $value) { $method_rec['CODE'] .= "\t[" . $key . "] => " . $value . " \n"; } $method_rec['CODE'] .= "*/\n"; SQLInsert('methods', $method_rec); } else { // Event already exist. Process event $method = $object_rec['TITLE'] . ".Event" . $data['Event']; callMethod($method, $data); } } } } }
/** * 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; } }
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;
global $linked_property_new; global $condition_new; global $condition_value_new; global $condition_advanced_new; global $switch_scene_new; global $state_id; global $state_delete; global $state_clone; global $ext_url_new; global $homepage_id_new; global $open_scene_id_new; global $do_on_click_new; global $priority_new; global $code_new; if ($state_delete && $state_rec['ID']) { $state_rec = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $state_id . "'"); foreach ($state_rec as $k => $v) { $out['STATE_' . $k] = ''; } SQLExec("DELETE FROM elm_states WHERE ID='" . $state_rec['ID'] . "'"); } elseif ($state_title_new) { $state_rec['ELEMENT_ID'] = $element['ID']; $state_rec['TITLE'] = $state_title_new; $state_rec['IMAGE'] = $image_new; $state_rec['HTML'] = $html_new; $state_rec['IS_DYNAMIC'] = $is_dynamic_new; $state_rec['LINKED_OBJECT'] = $linked_object_new; $state_rec['LINKED_PROPERTY'] = $linked_property_new; $state_rec['CONDITION'] = $condition_new; $state_rec['CONDITION_VALUE'] = $condition_value_new; $state_rec['CONDITION_ADVANCED'] = $condition_advanced_new;
/** * zwave_devices delete record * * @access public */ function delete_zwave_devices($id) { $rec = SQLSelectOne("SELECT * FROM zwave_devices WHERE ID='{$id}'"); // some action for related tables SQLExec("DELETE FROM zwave_properties WHERE DEVICE_ID='" . $rec['ID'] . "'"); SQLExec("DELETE FROM zwave_devices WHERE ID='" . $rec['ID'] . "'"); }
// 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
} if ($this->owner->name!='panel') { $res[$i]['TITLE']=processTitle($res[$i]['TITLE'], $this); if ($res[$i]['TYPE']=='custom') { $res[$i]['DATA']=processTitle($res[$i]['DATA'], $this); } } foreach($res[$i] as $k=>$v) { if (!is_array($res[$i][$k]) && $k!='DATA') { $res[$i][$k]=addslashes($v); } } $tmp=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM commands WHERE PARENT_ID='".$res[$i]['ID']."'"); if ($tmp['TOTAL']) { $res[$i]['RESULT']=$tmp['TOTAL']; } } if ($this->action=='admin') { $res=$this->buildTree_commands($res); } $out['RESULT']=$res; } ?>
/** * events delete record * * @access public */ function delete_events($id) { $rec = SQLSelectOne("SELECT * FROM events WHERE ID='{$id}'"); // some action for related tables SQLExec("DELETE FROM events WHERE ID='" . $rec['ID'] . "'"); }
<? /* * @version 0.1 (wizard) */ if ($this->owner->name=='panel') { $out['CONTROLPANEL']=1; } $table_name='calendar_categories'; $rec=SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'"); if ($this->mode=='update') { $ok=1; //updating 'TITLE' (varchar, required) global $title; $rec['TITLE']=$title; if ($rec['TITLE']=='') { $out['ERR_TITLE']=1; $ok=0; } //updating 'ACTIVE' (int) global $active; $rec['ACTIVE']=(int)$active; //updating 'PRIORITY' (int) global $priority; $rec['PRIORITY']=(int)$priority; //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
/** * methods delete record * * @access public */ function delete_methods($id) { $rec=SQLSelectOne("SELECT * FROM methods WHERE ID='$id'"); // some action for related tables SQLExec("DELETE FROM methods WHERE ID='".$rec['ID']."'"); }
$total = count($pvalues); 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; } else { $out['ERR'] = 1; } } if (is_array($rec)) { foreach ($rec as $k => $v) { if (!is_array($v)) { $rec[$k] = htmlspecialchars($v); } } } outHash($rec, $out); global $overwrite; if ($overwrite) { $tmp = SQLSelectOne("SELECT * FROM properties WHERE ID='" . (int) $overwrite . "'"); unset($tmp['ID']); foreach ($tmp as $k => $v) { $out[$k] = htmlspecialchars($v); } }
$options = array('BACKUP_PATH' => 'Path to store backup'); foreach ($options as $k => $v) { $tmp = SQLSelectOne("SELECT ID FROM settings WHERE NAME LIKE '" . $k . "'"); if (!$tmp['ID']) { $tmp = array(); $tmp['NAME'] = $k; $tmp['TITLE'] = $v; $tmp['TYPE'] = 'text'; SQLInsert('settings', $tmp); } } } if ($this->filter_name == 'pushbullet' && !defined('SETTINGS_PUSHBULLET_PREFIX')) { $options = array('PUSHBULLET_KEY' => 'Pushbullet API Key', 'PUSHBULLET_LEVEL' => 'Pushbullet message minimum level', 'PUSHBULLET_DEVICE_ID' => 'Pushbullet Device ID (optional)', 'PUSHBULLET_PREFIX' => 'Pushbullet notifiaction prefix (optional)'); foreach ($options as $k => $v) { $tmp = SQLSelectOne("SELECT ID FROM settings WHERE NAME LIKE '" . $k . "'"); if (!$tmp['ID']) { $tmp = array(); $tmp['NAME'] = $k; $tmp['TITLE'] = $v; $tmp['TYPE'] = 'text'; if ($k == 'PUSHBULLET_LEVEL') { $tmp['VALUE'] = 1; $tmp['DEFAULTVALUE'] = 1; } SQLInsert('settings', $tmp); } } } // if (!empty($options)) { // }
/** * 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); }
global $code; $rec['CODE'] = $code; global $read_community; $rec['READ_COMMUNITY'] = trim($read_community); global $write_community; $rec['WRITE_COMMUNITY'] = trim($write_community); //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 $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM snmpdevices"); if ($tmp['TOTAL'] == 1) { @SaveFile(ROOT . 'reboot'); // first device added, need reboot } } //updating 'MIB_FILE' (file) global $mib_file; global $mib_file_name; global $delete_mib_file; if ($mib_file != "" && file_exists($mib_file) && !$delete_mib_file) { $filename = strtolower(basename($mib_file_name)); $ext = strtolower(end(explode(".", basename($mib_file_name)))); if (filesize($mib_file) <= 0 * 1024 || 0 == 0) { $filename = $rec["ID"] . "_mib_file_" . time() . "." . $ext; if ($rec["MIB_FILE"] != '') {
<? /* * @version 0.1 (auto-set) */ global $session; if ($this->owner->name=='panel') { $out['CONTROLPANEL']=1; } $qry="1"; // search filters if ($this->class_id) { $class=SQLSelectOne("SELECT * FROM classes WHERE ID='".$this->class_id."'"); if ($class['SUB_LIST']!='') { $qry.=" AND (CLASS_ID IN (".$class['SUB_LIST'].") OR CLASS_ID=".$class['ID'].")"; } else { $qry.=" AND 0"; } } // QUERY READY global $save_qry; if ($save_qry) { $qry=$session->data['objects_qry']; } else { $session->data['objects_qry']=$qry; } if (!$qry) $qry="1"; // FIELDS ORDER global $sortby;
DebMes("Error in GPS action code: " . $code); } } catch (Exception $e) { DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.'); } } } } } } } if ($user['LINKED_OBJECT'] && !$location_found) { setGlobal($user['LINKED_OBJECT'] . '.seenAt', ''); } $sqlQuery = "SELECT *, DATE_FORMAT(ADDED, '%H:%i') as DAT\n FROM shouts\n ORDER BY ADDED DESC\n LIMIT 1"; $tmp = SQLSelectOne($sqlQuery); if (!headers_sent()) { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); } if (defined('BTRACED')) { echo "OK"; } elseif ($tmp['MESSAGE'] != '') { echo ' ' . $tmp['DAT'] . ' ' . transliterate($tmp['MESSAGE']); } // closing database connection $db->Disconnect(); endMeasure('TOTAL'); // end calculation of execution time /** * Calculate distance between two GPS coordinates
/** * UnInstalling current module * * Removing information about module in project registry and * * @access private */ function uninstall() { $rec=SQLSelectOne("SELECT * FROM project_modules WHERE NAME='".$this->name."'"); if (IsSet($rec["ID"])) { SQLExec("DELETE FROM project_modules WHERE ID='".$rec["ID"]."'"); } if (file_exists(DIR_MODULES.$this->name."/installed")) { unlink(DIR_MODULES.$this->name."/installed"); } }
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; } else { $out['ERR'] = 1; } } if (is_array($rec)) { foreach ($rec as $k => $v) { if (!is_array($v)) { $rec[$k] = htmlspecialchars($v); } } } outHash($rec, $out); global $overwrite; if ($overwrite) { $tmp = SQLSelectOne("SELECT * FROM methods WHERE ID='" . (int) $overwrite . "'"); unset($tmp['ID']); foreach ($tmp as $k => $v) { $out[$k] = htmlspecialchars($v); } } $out['SCRIPTS'] = SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
function checkAccess($action = "", $log = 0) { global $session; if ($session->data['USER_ID'] == 1) { return 1; } $user = SQLSelectOne("SELECT ID FROM admin_users WHERE LOGIN='******'USER_NAME'] . "'"); if (!$user['ID']) { unset($session->data['AUTHORIZED']); unset($session->data['USER_NAME']); $this->redirect("?"); } if ($action != "") { $user = SQLSelectOne("SELECT ID FROM admin_users WHERE LOGIN='******'USER_NAME'] . "' AND (ACCESS LIKE '{$action}' OR ACCESS LIKE '{$action},%' OR ACCESS LIKE '%,{$action}' OR ACCESS LIKE '%,{$action},%')"); } if (isset($user['ID'])) { return 1; } return 0; }
} else { $qry.=" AND (commands.ID='".(int)$_GET['parent']."')"; } */ $out['IFRAME_MODE'] = 1; } if ($this->parent_item != '') { //$out['IFRAME_MODE']=1; $tmp = SQLSelectOne("SELECT ID FROM commands WHERE PARENT_ID='" . $_GET['parent'] . "'"); if ($tmp['ID']) { $qry .= " AND (commands.PARENT_ID='" . $this->parent_item . "')"; } else { $qry .= " AND (commands.ID='" . $this->parent_item . "')"; } //$qry.=" AND PARENT_ID='".$this->parent_item."'"; $parent_rec = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $this->parent_item . "'"); $parent_rec['TITLE'] = processTitle($parent_rec['TITLE'], $this); if ($paret_rec['SUB_PRELOAD']) { $parent_rec['ID'] = $parent_rec['PARENT_ID']; } foreach ($parent_rec as $k => $v) { $out['PARENT_' . $k] = $v; } } elseif ($this->id) { $qry .= " AND ID=" . (int) $this->id; $out['ONE_ITEM_MODE'] = 1; $this->pda = 1; $out['PDA'] = 1; } elseif (!$_GET['parent']) { $qry .= " AND PARENT_ID=0"; }
/* * @version 0.2 (wizard) */ if ($this->mode == 'setvalue') { global $prop_id; global $new_value; global $id; $this->setProperty($prop_id, $new_value); $this->redirect("?id=" . $id . "&view_mode=" . $this->view_mode . "&edit_mode=" . $this->edit_mode); } if ($this->owner->name == 'panel') { $out['CONTROLPANEL'] = 1; } $table_name = 'owdevices'; $rec = SQLSelectOne("SELECT * FROM {$table_name} WHERE ID='{$id}'"); if ($this->mode == 'update') { $ok = 1; //updating 'HOSTNAME' (varchar) global $title; $rec['TITLE'] = $title; global $code; $rec['CODE'] = $code; global $run_type; if ($run_type == 'script') { global $script_id; $rec['SCRIPT_ID'] = $script_id; } else { $rec['SCRIPT_ID'] = 0; } if ($rec['CODE'] != '' && $run_type == 'code') {
/** * Title * * Description * * @access public */ function getParents($parent_id) { if (!$parent_id) { return array(); } $res = array(); $rec = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $parent_id . "'"); if ($rec['PARENT_ID']) { $parents = $this->getParents($rec['PARENT_ID']); foreach ($parents as $v) { $res[] = $v; } } $res[] = $rec; return $res; }
/** * shopping_list_items delete record * * @access public */ function delete_shopping_list_items($id) { $rec = SQLSelectOne("SELECT * FROM shopping_list_items WHERE ID='{$id}'"); // some action for related tables SQLExec("DELETE FROM shopping_list_items WHERE ID='" . $rec['ID'] . "'"); }
function recLocalTime($table, $id, $gmt, $field = "ADDED") { // UPDATES TIMESTAMP FIELD USING GMT $rec = SQLSelectOne("SELECT ID, DATE_FORMAT({$field}, '%Y-%m-%d %H:%i') as DAT FROM {$table} WHERE ID='{$id}'"); if (isset($rec["ID"])) { $new_dat = setLocalTime($rec['DAT'], $gmt); SQLExec("UPDATE {$table} SET {$field}='{$new_dat}' WHERE ID='{$id}'"); } }
// 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']); } }
} $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"]++; } } } }
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; }