function run() { //if (preg_match('/~/', $this->src)) { // $this->src=preg_replace('/\/~(.+?)\//', '/', $this->src); //} if ($this->live) { $out['LIVE'] = $this->live; } if ($this->userpassword) { $this->userpassword = processTitle($this->userpassword); $tmp = explode(':', $this->userpassword); $this->username = $tmp[0]; $this->password = $tmp[1]; } if ($this->url) { $this->url = processTitle($this->url); $this->username = processTitle($this->username); $this->password = processTitle($this->password); $filename = 'thumb_' . md5($this->url) . basename(preg_replace('/\\W/', '', $this->url)); if (preg_match('/\\.cgi$/is', $filename)) { $filename = str_replace('.cgi', '.jpg', $filename); } $this->src = ROOT . 'cached/' . $filename; /* */ $this->src_def = urlencode('/cached/' . $filename); } else { preg_match('/(.*)?\\/.*$/', $_SERVER['PHP_SELF'], $match); $this->src_def = urlencode('http://' . $_SERVER['SERVER_NAME'] . $match[1] . $this->src); } $out['REQUESTED'] = $this->src; if (file_exists($this->src) || $this->url) { //$lst=GetImageSize($this->src); $out['REAL_WIDTH'] = $lst[0]; $out['REAL_HEIGHT'] = $lst[1]; $out['URL'] = base64_encode($this->url); $out['USERNAME'] = urlencode($this->username); $out['PASSWORD'] = urlencode($this->password); $image_format = $lst[2]; $out['UNIQ'] = rand(1, time()); $out['WIDTH'] = $this->width; $out['HEIGHT'] = $this->height; $out['MAX_HEIGHT'] = $this->max_height; $out['MAX_WIDTH'] = $this->max_width; $out['CLOSE'] = $this->close; /* $out['BGCOLOR']=(($this->bgcolor[0]='#')?substr($this->bgcolor,1):$this->bgcolor); $out['COLOR']=(($this->color[0]='#')?substr($this->color,1):$this->color); */ $out['ENLARGE'] = $this->enlarge; $out['SRC'] = urlencode($this->src); $out['SRC_REAL'] = $this->src_def; //echo $out['SRC_REAL']."<br>"; } $this->data = $out; $p = new parser(DIR_TEMPLATES . $this->name . "/" . $this->name . ".html", $this->data, $this); $this->result = $p->result; }
} else { $option['TITLE']=$option['VALUE']; } if ($option['VALUE']==$item['CUR_VALUE']) { $option['SELECTED']=1; } $item['OPTIONS'][]=$option; } } $res[$i]=$item; } 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']; } }
?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="../css/page.css" type="text/css" rel="stylesheet" /> <title>Result List</title> </head> <body > <div> <ul id="ul-geneNetwork"> <?php for ($i = 0; $i < count($urlList[0]); $i++) { ?> <li id="li-geneNetwork"><a href="<?php echo processUrl($urlList[0][$i]); ?> "><?php echo processTitle($titleList[0][$i]); ?> </a></li> <?php } ?> </ul> </div> </body> </html>
/** * 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()); } } } } }
/** * Title * * Description * * @access public */ function updateDisplay($id) { if (!defined('ONEWIRE_SERVER')) { return 0; } $rec = SQLSelectOne("SELECT * FROM owdisplays WHERE ID='" . $id . "'"); if (!$rec['ID']) { return 0; } $ow = new OWNet(ONEWIRE_SERVER); $device = '/' . $rec['UDID']; $rec['UPDATE_LATEST'] = time(); $rec['UPDATE_NEXT'] = time() + (int) $rec['UPDATE_INTERVAL']; $rec['VALUE'] = str_replace("\r", '', $rec['VALUE']); $text = explode("\n", $rec['VALUE']); for ($i = 1; $i <= $rec['ROWS']; $i++) { $line = $i . ",1:" . $text[$i - 1]; $line = processTitle($line); $ow->set($device . "/LCD_H/screenyx", str_pad($line, 40)); } SQLUpdate('owdisplays', $rec); }
/** * 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 getElements($qry = '1', $options = 0) { $elements = SQLSelect("SELECT * FROM elements WHERE {$qry} ORDER BY PRIORITY DESC, TITLE"); /* $totale=count($elements); $res2=array(); for($ie=0;$ie<$totale;$ie++) { if (checkAccess('scene_elements', $elements[$ie]['ID'])) { $res2[]=$elements[$ie]; } } $elements=$res2; */ $totale = count($elements); for ($ie = 0; $ie < $totale; $ie++) { if ($elements[$ie]['CSS_STYLE']) { $this->all_styles[$elements[$ie]['CSS_STYLE']] = 1; if (!is_array($options) || $options['ignore_css_image'] != 1) { $elements[$ie]['CSS_IMAGE'] = $this->getCSSImage($elements[$ie]['TYPE'], $elements[$ie]['CSS_STYLE']); } } if ($elements[$ie]['PRIORITY']) { $elements[$ie]['ZINDEX'] = round($elements[$ie]['PRIORITY'] / 10); } if ($elements[$ie]['TYPE'] == 'img') { $elements[$ie]['BACKGROUND'] = 0; } $positions[$elements[$ie]['ID']]['TOP'] = $elements[$ie]['TOP']; $positions[$elements[$ie]['ID']]['LEFT'] = $elements[$ie]['LEFT']; $states = SQLSelect("SELECT * FROM elm_states WHERE ELEMENT_ID='" . $elements[$ie]['ID'] . "' ORDER BY PRIORITY DESC, TITLE"); $total_s = count($states); for ($is = 0; $is < $total_s; $is++) { if ($elements[$ie]['TYPE'] == 'img') { unset($states[$is]['HTML']); } if ($states[$is]['HTML'] != '') { $states[$is]['HTML'] = processTitle($states[$is]['HTML']); } if (!is_array($options) || $options['ignore_state'] != 1) { startMeasure('checkstates'); $states[$is]['STATE'] = $this->checkState($states[$is]['ID']); endMeasure('checkstates'); } } $elements[$ie]['STATES'] = $states; if ($elements[$ie]['TYPE'] == 'container') { if (!is_array($options) || $options['ignore_sub'] != 1) { startMeasure('getSubElements'); $elements[$ie]['ELEMENTS'] = $this->getElements("CONTAINER_ID=" . (int) $elements[$ie]['ID'], $options); endMeasure('getSubElements'); } } } for ($ie = 0; $ie < $totale; $ie++) { if ($elements[$ie]['LINKED_ELEMENT_ID']) { $elements[$ie]['TOP'] = $positions[$elements[$ie]['LINKED_ELEMENT_ID']]['TOP'] + $elements[$ie]['TOP']; $elements[$ie]['LEFT'] = $positions[$elements[$ie]['LINKED_ELEMENT_ID']]['LEFT'] + $elements[$ie]['LEFT']; $positions[$elements[$ie]['ID']]['TOP'] = $elements[$ie]['TOP']; $positions[$elements[$ie]['ID']]['LEFT'] = $elements[$ie]['LEFT']; } } return $elements; }
$old_category = ''; if ($res[0]['ID']) { $total = count($res); for ($i = 0; $i < $total; $i++) { if (!$res[$i]['CATEGORY']) { $res[$i]['CATEGORY'] = LANG_OTHER; } $res[$i]['DESCRIPTION'] = nl2br(htmlspecialchars($res[$i]['DESCRIPTION'])); if ($res[$i]['CATEGORY'] != $old_category) { $out['TOTAL_CATEGORIES']++; $old_category = $res[$i]['CATEGORY']; $res[$i]['NEW_CATEGORY'] = 1; if ($i > 0) { echo '</category>' . "\n"; } echo '<category name="' . LANG_MODULE_SCRIPTS . ': ' . processTitle($res[$i]['CATEGORY']) . '">' . "\n"; } echo '<block type="majordomo_script_' . $res[$i]['ID'] . '"></block>' . "\n"; if ($i == $total - 1) { $res[$i]['LAST'] = 1; } } echo '</category>'; } ?> </xml> </body> </html> <?php $session->save();
$total = count($commands); for ($i = 0; $i < $total; $i++) { $cmd_values[$commands[$i]['ID']] = $commands[$i]['CUR_VALUE']; $cmd_titles[$commands[$i]['ID']] = $commands[$i]['RENDER_TITLE']; $cmd_data[$commands[$i]['ID']] = $commands[$i]['RENDER_DATA']; } } if (time() - $checked_time > 10) { $checked_time = time(); // update data $sqlQuery = "SELECT *\n FROM commands\n WHERE AUTO_UPDATE > 0\n AND (NOW() - RENDER_UPDATED) > AUTO_UPDATE"; $commands = SQLSelect($sqlQuery); $total = count($commands); for ($i = 0; $i < $total; $i++) { $commands[$i]['RENDER_TITLE'] = processTitle($commands[$i]['TITLE'], $connect); $commands[$i]['RENDER_DATA'] = processTitle($commands[$i]['DATA'], $connect); $commands[$i]['RENDER_UPDATED'] = date('Y-m-d H:i:s'); SQLUpdate('commands', $commands[$i]); $resultMessage = date('Y-m-d H:i:s'); $resultMessage .= ' Updating auto update item (id ' . $commands[$i]['ID']; $resultMessage .= ' time ' . $commands[$i]['AUTO_UPDATE'] . '): ' . $commands[$i]['TITLE'] . "\n"; echo $resultMessage; } // sending changes if any $sqlQuery = "SELECT *\n FROM commands"; $commands = SQLSelect($sqlQuery); $total = count($commands); $changed_data = array(); for ($i = 0; $i < $total; $i++) { if ($cmd_values[$commands[$i]['ID']] != $commands[$i]['CUR_VALUE']) { $cmd_values[$commands[$i]['ID']] = $commands[$i]['CUR_VALUE'];
/** * Title * * Description * * @access public */ function checkPattern($id, $from_user_id = 0) { global $session; global $pattern_matched; $this_pattern_matched = 0; $condition_matched = 0; $rec = SQLSelectOne("SELECT * FROM patterns WHERE ID='" . (int) $id . "'"); if ($rec['PATTERN_TYPE'] == 1) { //conditional pattern $value = getGlobal($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_PROPERTY']); $condition_value = $rec['CONDITION_VALUE']; if (($rec['CONDITION'] == 2 || $rec['CONDITION'] == 3) && $condition_value != '' && !is_numeric($condition_value) && !preg_match('/^%/', $condition_value)) { $condition_value = '%' . $condition_value . '%'; } if (is_integer(strpos($condition_value, "%"))) { $condition_value = processTitle($condition_value); } if ($rec['CONDITION'] == 1 && $value == $condition_value) { $status = 1; } elseif ($rec['CONDITION'] == 2 && (double) $value >= (double) $condition_value) { $status = 1; } elseif ($rec['CONDITION'] == 3 && (double) $value < (double) $condition_value) { $status = 1; } elseif ($rec['CONDITION'] == 4 && $value != $condition_value) { $status = 1; } else { $status = 0; } if ($status == 1 && !$rec['ACTIVE_STATE']) { $rec['ACTIVE_STATE'] = 1; SQLUpdate('patterns', $rec); $condition_matched = 1; } elseif ($status == 0 && $rec['ACTIVE_STATE']) { $rec['ACTIVE_STATE'] = 0; SQLUpdate('patterns', $rec); if ($rec['SCRIPT_EXIT']) { $this->runPatternExitAction($rec['ID'], $rec['SCRIPT_EXIT']); } //to-do: state exit script } } else { if ($rec['SKIPSYSTEM'] && !$from_user_id) { return 0; } if (!$rec['PATTERN']) { $pattern = $rec['TITLE']; } else { $pattern = $rec['PATTERN']; } $pattern = str_replace("\r", '', $pattern); if ($pattern == '') { return 0; } if ($rec['EXECUTED'] > 0 && $rec['TIME_LIMIT'] && time() - $rec['EXECUTED'] <= $rec['TIME_LIMIT']) { return 0; } $lines_pattern = explode("\n", $pattern); $total_lines = count($lines_pattern); if (!$rec['TIME_LIMIT']) { $messages = SQLSelect("SELECT MESSAGE FROM shouts ORDER BY ID DESC LIMIT " . (int) $total_lines); $messages = array_reverse($messages); } else { $start_from = time() - $rec['TIME_LIMIT']; $messages = SQLSelect("SELECT MESSAGE FROM shouts WHERE ADDED>=('" . date('Y-m-d H:i:s', $start_from) . "') ORDER BY ADDED"); } $total = count($messages); if (!$total) { return 0; } $lines = array(); for ($i = 0; $i < $total; $i++) { $lines[] = $messages[$i]['MESSAGE']; } $history = implode('@@@@', $lines); $check = implode('@@@@', $lines_pattern); if (preg_match('/' . $check . '/isu', $history, $matches)) { $condition_matched = 1; } } if ($condition_matched) { if (checkAccess('pattern', $rec['ID'])) { $is_common = 0; if ($rec['PARENT_ID']) { $parent_rec = SQLSelectOne("SELECT IS_COMMON_CONTEXT FROM patterns WHERE ID='" . $rec['PARENT_ID'] . "'"); $is_common = (int) $parent_rec['IS_COMMON_CONTEXT']; } if (context_getcurrent()) { $history = context_get_history() . ' ' . $history; } if ($rec['IS_CONTEXT']) { context_activate($rec['ID'], 1, $history); } elseif ($rec['MATCHED_CONTEXT_ID']) { context_activate($rec['MATCHED_CONTEXT_ID'], 0, $history); } elseif (!$is_common) { context_activate(0); } $rec['LOG'] = date('Y-m-d H:i:s') . ' Pattern matched' . "\n" . $rec['LOG']; $rec['EXECUTED'] = time(); SQLUpdate('patterns', $rec); $pattern_matched = 1; $this_pattern_matched = 1; $sub_patterns_matched = 0; if ($rec['IS_CONTEXT']) { $sub_patterns = SQLSelect("SELECT ID, IS_LAST FROM patterns WHERE PARENT_ID='" . $rec['ID'] . "' ORDER BY PRIORITY DESC, TITLE"); $total = count($sub_patterns); for ($i = 0; $i < $total; $i++) { if ($this->checkPattern($sub_patterns[$i]['ID'], $from_user_id)) { $sub_patterns_matched = 1; if ($sub_patterns[$i]['IS_LAST']) { break; } } } } if (!$sub_patterns_matched) { $this->runPatternAction($rec['ID'], $matches, $history, $from_user_id); } if ($rec['ONETIME']) { SQLExec("DELETE FROM patterns WHERE ID='" . $rec['ID'] . "'"); } } } else { $this_pattern_matched = 0; } return $this_pattern_matched; }
/** * Title * * Description * * @access public */ function processMenuItem($item_id, $set_value = false, $new_value = 0) { if (preg_match('/(\\d+)\\_(\\d+)/', $item_id, $m)) { $dynamic_item = 1; $real_part = $m[1]; $object_part = $m[2]; } else { $dynamic_item = 0; $real_part = $item_id; $object_part = 0; } $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $real_part . "'"); if ($object_part) { $object_rec = SQLSelectOne("SELECT ID, TITLE FROM objects WHERE ID=" . (int) $object_part); $item['DATA'] = str_replace('%' . $item['LINKED_OBJECT'] . '.', '%' . $object_rec['TITLE'] . '.', $item['DATA']); $item['TITLE'] = $object_rec['TITLE']; $item['LINKED_OBJECT'] = $object_rec['TITLE']; } if ($item['ID']) { $item['ID'] = $item_id; if ($object_part) { $data = getGlobal($object_rec['TITLE'] . '.' . $item['LINKED_PROPERTY']); } else { if ($set_value) { $item['CUR_VALUE'] = $new_value; } $data = $item['CUR_VALUE']; } $item['VALUE'] = $data; if ($item['TYPE'] == 'custom') { if (preg_match('/\\[#modul/is', $item['DATA'])) { unset($item['LABEL']); return $item; } //$item['DATA']=processTitle($item['DATA'], $this); $data = $item['DATA']; } else { //$item['TITLE']=processTitle($item['TITLE'], $this); $data = $item['TITLE']; } $data = processTitle($data, $this); if (preg_match('/#[\\w\\d]{6}/is', $data, $m)) { $color = $m[0]; $data = trim(str_replace($m[0], '<style>#item' . $item['ID'] . ' .ui-btn-active {background-color:' . $color . ';border-color:' . $color . '}</style>', $data)); } $item['LABEL'] = $data; } return $item; }
/** * BackEnd * * Module backend * * @access public */ function admin(&$out) { global $ajax; if ($ajax) { global $op; global $item_id; if ($op=='get_label') { $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'"); if ($item['ID']) { if ($item['TYPE']=='custom') { echo processTitle($item['DATA'], $this); } else { echo processTitle($item['TITLE'], $this); } exit; } } if ($op=='get_value') { $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'"); if ($item['ID']) { echo $item['CUR_VALUE']; exit; } } if ($op=='value_changed') { global $new_value; $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'"); if ($item['ID']) { $item['CUR_VALUE']=$new_value; SQLUpdate('commands', $item); if ($item['LINKED_PROPERTY']!='') { $old_value=gg($item['LINKED_OBJECT'].'.'.$item['LINKED_PROPERTY']); sg($item['LINKED_OBJECT'].'.'.$item['LINKED_PROPERTY'], $item['CUR_VALUE'], 1); //DebMes("setting property ".$item['LINKED_OBJECT'].".".$item['LINKED_PROPERTY']." to ".$item['CUR_VALUE']); } $params=array('VALUE'=>$item['CUR_VALUE']); if (isSet($old_value)) { $params['OLD_VALUE']=$old_value; } if ($item['ONCHANGE_METHOD']!='') { getObject($item['ONCHANGE_OBJECT'])->callMethod($item['ONCHANGE_METHOD'], $params); //DebMes("calling method ".$item['ONCHANGE_OBJECT'].".".$item['ONCHANGE_METHOD']." with ".$item['CUR_VALUE']); } if ($item['SCRIPT_ID']) { //DebMes('Running on_change script #'.$item['SCRIPT_ID']); runScript($item['SCRIPT_ID'], $params); } if ($item['CODE']) { //DebMes("Running on_change code"); eval($item['CODE']); } } echo "OK";exit; } } if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) { $out['SET_DATASOURCE']=1; } if ($this->data_source=='commands' || $this->data_source=='') { if ($this->view_mode=='' || $this->view_mode=='search_commands') { $this->search_commands($out); } if ($this->view_mode=='edit_commands') { $this->edit_commands($out, $this->id); } if ($this->view_mode=='delete_commands') { $this->delete_commands($this->id); $this->redirect("?"); } } }
/** * FrontEnd * * Module frontend * * @access public */ function usual(&$out) { global $ajax; if ($ajax) { global $op; header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); if ($op == 'checkAllStates') { $qry = "1"; if (preg_match('/(\\d+)\\.html/', $_SERVER["REQUEST_URI"], $m)) { $qry .= " AND scenes.ID='" . $m[1] . "'"; } $states = SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements WHERE elm_states.ELEMENT_ID=elements.ID AND {$qry}"); $total = count($states); for ($i = 0; $i < $total; $i++) { $states[$i]['STATE'] = $this->checkState($states[$i]['ID']); if ($states[$i]['TYPE'] == 'html') { $states[$i]['HTML'] = processTitle($states[$i]['HTML'], $this); } } echo json_encode($states); } if ($op == 'click') { global $id; $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'"); $params = array('STATE' => $state['TITLE']); if ($state['ACTION_OBJECT'] && $state['ACTION_METHOD']) { callMethod($state['ACTION_OBJECT'] . '.' . $state['ACTION_METHOD'], $params); } if ($state['SCRIPT_ID']) { runScript($state['SCRIPT_ID'], $params); } echo "OK"; } if ($op == 'position') { global $id; global $posx; global $posy; global $width; global $height; if ($id && $posx && $posy && $width && $height) { $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'"); $state['WINDOW_POSX'] = $posx; $state['WINDOW_POSY'] = $posy; $state['WINDOW_WIDTH'] = $width; $state['WINDOW_HEIGHT'] = $height; SQLUpdate('elm_states', $state); } // echo "OK"; } exit; } $this->admin($out); }
$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"; } }
/** * FrontEnd * * Module frontend * * @access public */ function usual(&$out) { global $ajax; if ($ajax) { global $op; header ("HTTP/1.0: 200 OK\n"); header ('Content-Type: text/html; charset=utf-8'); if ($op=='checkAllStates') { $states=SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements WHERE elm_states.ELEMENT_ID=elements.ID"); $total=count($states); for($i=0;$i<$total;$i++) { $states[$i]['STATE']=$this->checkState($states[$i]['ID']); if ($states[$i]['TYPE']=='html') { $states[$i]['HTML']=processTitle($states[$i]['HTML'], $this); } } echo json_encode($states); } if ($op=='click') { global $id; $state=SQLSelectOne("SELECT * FROM elm_states WHERE ID='".$id."'"); if ($state['SCRIPT_ID']) { $params=array('STATE'=>$state['TITLE']); runScript($state['SCRIPT_ID'], $params); echo "OK"; } } exit; } $this->admin($out); }
function processMenuElements(&$res) { startMeasure('processMenuElements'); startMeasure('processMenuElements ' . $_SERVER['REQUEST_URI']); if ($this->action != 'admin') { $total = count($res); $res2 = array(); for ($i = 0; $i < $total; $i++) { if (checkAccess('menu', $res[$i]['ID'])) { $res2[] = $res[$i]; } } $res = $res2; unset($res2); } $total = count($res); for ($i = 0; $i < $total; $i++) { // some action for every record if required if ($res[$i + 1]['INLINE']) { $res[$i]['INLINE'] = 1; } $item = $res[$i]; if ($item['VISIBLE_DELAY']) { $out['VISIBLE_DELAYS']++; } if ($item['EXT_ID'] && $this->action != 'admin') { $visible_delay = $item['VISIBLE_DELAY']; $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item['EXT_ID'] . "'"); if ($tmp['ID']) { $item = $tmp; $item['VISIBLE_DELAY'] = $visible_delay; $res[$i] = $item; } } elseif ($item['EXT_ID'] && $this->action == 'admin') { $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item['EXT_ID'] . "'"); if ($tmp['ID']) { $item['TITLE'] = $item['TITLE'] . ' (' . $tmp['TITLE'] . ')'; $res[$i] = $item; } } if ($item['LINKED_PROPERTY'] != '') { $lprop = getGlobal($item['LINKED_OBJECT'] . '.' . $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; } $selected = 0; if ($h == $value1) { $selected = 1; } $item['OPTIONS1'][] = array('VALUE' => $v, 'SELECTED' => $selected); } for ($h = 0; $h <= 59; $h++) { $v = $h; if ($v < 10) { $v = '0' . $v; } $selected = 0; if ($h == $value2) { $selected = 1; } $item['OPTIONS2'][] = array('VALUE' => $v, 'SELECTED' => $selected); } $res[$i] = $item; } if ($item['TYPE'] == 'switch') { if (trim($item['DATA'])) { $data = explode("\n", str_replace("\r", "", $item['DATA'])); $item['OFF_VALUE'] = trim($data[0]); $item['ON_VALUE'] = trim($data[1]); } else { $item['OFF_VALUE'] = 0; $item['ON_VALUE'] = 1; } $res[$i] = $item; } if ($item['TYPE'] == 'selectbox' || $item['TYPE'] == 'radiobox') { $data = explode("\n", str_replace("\r", "", $item['DATA'])); $item['OPTIONS'] = array(); $num = 1; foreach ($data as $line) { $line = trim($line); if ($line != '') { $option = array(); if (preg_match('/=/', $line)) { $tmp = explode('=', $line); } else { $tmp = explode('|', $line); } $option['VALUE'] = $tmp[0]; if ($tmp[1] != '') { $option['TITLE'] = $tmp[1]; } else { $option['TITLE'] = $option['VALUE']; } if ($option['VALUE'] == $item['CUR_VALUE']) { $option['SELECTED'] = 1; } $option['NUM'] = $num; $num++; $item['OPTIONS'][] = $option; } } $res[$i] = $item; } 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); } if (preg_match('/#[\\w\\d]{6}/is', $res[$i]['TITLE'], $m)) { $color = $m[0]; $res[$i]['TITLE'] = trim(str_replace($m[0], '<style>#item' . $res[$i]['ID'] . ' .ui-btn-active {background-color:' . $color . ';border-color:' . $color . '}</style>', $res[$i]['TITLE'])); } if ($res[$i]['RENDER_TITLE'] != $res[$i]['TITLE'] || $res[$i]['RENDER_DATA'] != $res[$i]['DATA']) { $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $res[$i]['ID'] . "'"); $tmp['RENDER_TITLE'] = $res[$i]['TITLE']; $tmp['RENDER_DATA'] = $res[$i]['DATA']; $tmp['RENDER_UPDATED'] = date('Y-m-d H:i:s'); SQLUpdate('commands', $tmp); } } if (preg_match('/<script/is', $res[$i]['DATA']) && $res[$i]['AUTO_UPDATE']) { $res[$i]['AUTO_UPDATE'] = 0; } $res[$i]['TITLE_SAFE'] = htmlspecialchars($res[$i]['TITLE']); /* 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_TOTAL'] = $tmp['TOTAL']; } if ($res[$i]['SUB_PRELOAD'] && $this->action != 'admin') { $children = SQLSelect("SELECT * FROM commands WHERE PARENT_ID='" . $res[$i]['ID'] . "' ORDER BY PRIORITY DESC, TITLE"); if ($children[0]['ID']) { $this->processMenuElements($children); if ($children[0]['ID']) { $res[$i]['RESULT'] = $children; } } } } endMeasure('processMenuElements ' . $_SERVER['REQUEST_URI'], 1); endMeasure('processMenuElements', 1); }
/** * FrontEnd * * Module frontend * * @access public */ function usual(&$out) { if ($this->ajax) { global $clicked; if ($clicked) { $item = SQLSelectOne("SELECT * FROM watchesmenu WHERE ID='" . (int) $clicked . "'"); if ($item['LINKED_OBJECT'] && $item['LINKED_METHOD']) { callMethod($item['LINKED_OBJECT'] . '.' . $item['LINKED_METHOD']); } if ($item['SCRIPT_ID']) { runScript($item['SCRIPT_ID']); } $result = array('RESULT' => 'OK'); header("Content-type:application/json"); echo json_encode($result); exit; } else { $items = SQLSelect("SELECT ID, TITLE, SUBTITLE FROM watchesmenu ORDER BY PRIORITY DESC, TITLE"); $res_items = array(); $total = count($items); for ($i = 0; $i < $total; $i++) { if (!checkAccess('watchesmenu', $items[$i]['ID'])) { continue; } $items[$i]['TITLE'] = processTitle($items[$i]['TITLE']); if ($items[$i]['SUBTITLE']) { $items[$i]['SUBTITLE'] = processTitle($items[$i]['SUBTITLE']); } $res_items[] = $items[$i]; } header("Content-type:application/json"); echo json_encode(array('items' => $res_items)); exit; } } }