From 0f77a9ee5b64c78287027b09206b37a61da8e33e Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 27 Dec 2018 22:52:47 +0200 Subject: [PATCH 01/31] =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=A1=D0=95=D0=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/common.class.php b/lib/common.class.php index 9b84cb67c..ecfc095e8 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -166,9 +166,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '') setGlobal('lastSayTime', time()); setGlobal('lastSayMessage', $ph); - $details=array('level' => $level, 'message' => $ph, 'member_id' => $member_id); - processSubscriptionsSafe('SAY', $details); //, 'ignoreVoice'=>$ignoreVoice - + processSubscriptionsSafe('SAY', array('level' => $level, 'message' => $ph, 'member_id' => $member_id)); //, 'ignoreVoice'=>$ignoreVoice if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') { From 41d46be89cd627ece827e115beb28d8d3ee58cba Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Wed, 9 Jan 2019 18:08:03 +0300 Subject: [PATCH 02/31] Simple devices update * Switch_Timer action now works with OpenClose sensors * Switch_Timer timer name fix (to work correctly when fired from diffent sensors for the same device) * Slideshow fix for IP Cameras devices --- modules/devices/SCameras_updatePreview.php | 3 +- modules/devices/devices_links_actions.inc.php | 1 + .../devices/devices_structure_links.inc.php | 2 +- modules/thumb/thumb.class.php | 245 +++++++++--------- templates/thumb/thumb.html | 34 ++- 5 files changed, 160 insertions(+), 125 deletions(-) diff --git a/modules/devices/SCameras_updatePreview.php b/modules/devices/SCameras_updatePreview.php index b2bad4da0..3ea32350e 100644 --- a/modules/devices/SCameras_updatePreview.php +++ b/modules/devices/SCameras_updatePreview.php @@ -29,7 +29,8 @@ $thumb_params.= ' width="250"'; $thumb_params.= ' url="' . $streamURL . '"'; if ($this->getProperty('previewType')=='slideshow') { - $thumb_params.= ' live="1"'; + //$thumb_params.= ' live="1"'; + $thumb_params.= ' slideshow="1"'; } $streamTransport = $this->getProperty('streamTransport'); diff --git a/modules/devices/devices_links_actions.inc.php b/modules/devices/devices_links_actions.inc.php index 32053314b..05e37befc 100644 --- a/modules/devices/devices_links_actions.inc.php +++ b/modules/devices/devices_links_actions.inc.php @@ -129,6 +129,7 @@ $action_string = 'setTimeout(\'' . $timer_name . '\',\'' . $action_string . '\',' . (int)$settings['action_delay'] . ');'; } } elseif ($link_type=='switch_timer') { + $timer_name=$object.'_switch_timer'; $action_string=''; if ($settings['darktime']) { $action_string.='if (gg("DarknessMode.active")) {'; diff --git a/modules/devices/devices_structure_links.inc.php b/modules/devices/devices_structure_links.inc.php index 587bde7f6..7edac47de 100644 --- a/modules/devices/devices_structure_links.inc.php +++ b/modules/devices/devices_structure_links.inc.php @@ -1,7 +1,7 @@ device_links=array( - 'SMotions,SButtons'=>array( + 'SMotions,SButtons,SOpenClose'=>array( array( 'LINK_NAME'=>'switch_timer', 'LINK_TITLE'=>LANG_DEVICES_LINK_SWITCH_TIMER, diff --git a/modules/thumb/thumb.class.php b/modules/thumb/thumb.class.php index ee8ec8976..8753c3ef2 100644 --- a/modules/thumb/thumb.class.php +++ b/modules/thumb/thumb.class.php @@ -1,171 +1,176 @@ http://smartliving.ru/ -* @version 0.2 -*/ - -// -class thumb extends module { + * Thumbnail builder + * + * @package MajorDoMo + * @author Serge Dzheigalo http://smartliving.ru/ + * @version 0.2 + */ +// +class thumb extends module +{ // -------------------------------------------------------------------- -function __construct() { + function __construct() + { - // setting module name - $this->name="thumb"; - $this->title="<#LANG_MODULE_THUMB#>"; - $this->module_category="<#LANG_SECTION_SYSTEM#>"; + // setting module name + $this->name = "thumb"; + $this->title = "<#LANG_MODULE_THUMB#>"; + $this->module_category = "<#LANG_SECTION_SYSTEM#>"; - $this->checkInstalled(); + $this->checkInstalled(); -} + } // -------------------------------------------------------------------- -function run() { + function run() + { - //if (preg_match('/~/', $this->src)) { - // $this->src=preg_replace('/\/~(.+?)\//', '/', $this->src); - //} + //if (preg_match('/~/', $this->src)) { + // $this->src=preg_replace('/\/~(.+?)\//', '/', $this->src); + //} - if ($this->live) { - $out['LIVE']=$this->live; - } + 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->slideshow) { + $out['SLIDESHOW']=1; + } - if ($this->url) { - $this->url=processTitle($this->url); - $this->username=processTitle($this->username); - $this->password=processTitle($this->password); + if ($this->userpassword) { + $this->userpassword = processTitle($this->userpassword); + $tmp = explode(':', $this->userpassword); + $this->username = $tmp[0]; + $this->password = $tmp[1]; + } - $filename='thumb_'.md5($this->url).basename(preg_replace('/\W/', '', $this->url)); - if (preg_match('/\.cgi$/is', $filename)) { - $filename=str_replace('.cgi', '.jpg', $filename); - } + if ($this->url) { + $this->url = processTitle($this->url); + $this->username = processTitle($this->username); + $this->password = processTitle($this->password); - $this->src=ROOT.'cms/cached/'.$filename; + $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 . 'cms/cached/' . $filename; - $this->src_def=urlencode('/cms/cached/'.$filename); + /* + */ - } else { + $this->src_def = urlencode('/cms/cached/' . $filename); - preg_match('/(.*)?\/.*$/',$_SERVER['PHP_SELF'],$match); - $this->src_def=urlencode('http://'.$_SERVER['SERVER_NAME'].$match[1].$this->src); + } else { - } + preg_match('/(.*)?\/.*$/', $_SERVER['PHP_SELF'], $match); + $this->src_def = urlencode('http://' . $_SERVER['SERVER_NAME'] . $match[1] . $this->src); - $out['REQUESTED']=$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['TRANSPORT'] = urldecode($this->transport); - 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['TRANSPORT']=urldecode($this->transport); + $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'] = htmlspecialchars($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'] = (int)($this->enlarge); + $out['SRC'] = urlencode($this->src); + $out['SRC_REAL'] = $this->src_def; + //echo $out['SRC_REAL']."
"; + } - $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']=htmlspecialchars($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']=(int)($this->enlarge); - $out['SRC']=urlencode($this->src); - $out['SRC_REAL']=$this->src_def; - //echo $out['SRC_REAL']."
"; - } - - - $this->data=$out; - $p=new parser(DIR_TEMPLATES.$this->name."/".$this->name.".html", $this->data, $this); - $this->result=$p->result; -} + $this->data = $out; + $p = new parser(DIR_TEMPLATES . $this->name . "/" . $this->name . ".html", $this->data, $this); + $this->result = $p->result; + } - function resizeImage($filename, $new_width=0, $new_height=0) { + function resizeImage($filename, $new_width = 0, $new_height = 0) + { - if (file_exists($filename)) { + if (file_exists($filename)) { - $lst=GetImageSize($filename); - $image_width=$lst[0]; - $image_height=$lst[1]; - $image_format=$lst[2]; + $lst = GetImageSize($filename); + $image_width = $lst[0]; + $image_height = $lst[1]; + $image_format = $lst[2]; - $type=0; + $type = 0; - switch($type) - { - case 0: - if (($new_width!=0) && ($new_width<$image_width)) { - $image_height=(int)($image_height*($new_width/$image_width)); - $image_width=$new_width; - } - if (($new_height!=0) && ($new_height<$image_height)) { - $image_width=(int)($image_width*($new_height/$image_height)); - $image_height=$new_height; - } - break; + switch ($type) { + case 0: + if (($new_width != 0) && ($new_width < $image_width)) { + $image_height = (int)($image_height * ($new_width / $image_width)); + $image_width = $new_width; + } + if (($new_height != 0) && ($new_height < $image_height)) { + $image_width = (int)($image_width * ($new_height / $image_height)); + $image_height = $new_height; + } + break; - case 1: - $image_width=$new_width; - $image_height=$image_height; - break; - } + case 1: + $image_width = $new_width; + $image_height = $image_height; + break; + } - if ($image_format==1) { - $old_image=imagecreatefromgif($filename); - } elseif ($image_format==2) { - $old_image=imagecreatefromjpeg($filename); - } elseif ($image_format==3) { - $old_image=imagecreatefrompng($filename); - } else { - return 0; - } + if ($image_format == 1) { + $old_image = imagecreatefromgif($filename); + } elseif ($image_format == 2) { + $old_image = imagecreatefromjpeg($filename); + } elseif ($image_format == 3) { + $old_image = imagecreatefrompng($filename); + } else { + return 0; + } - $new_image=imageCreateTrueColor($image_width, $image_height); - $white = ImageColorAllocate($new_image, 255, 255, 255); - ImageFill($new_image, 0, 0, $white); + $new_image = imageCreateTrueColor($image_width, $image_height); + $white = ImageColorAllocate($new_image, 255, 255, 255); + ImageFill($new_image, 0, 0, $white); - /*imageCopyResized*/imagecopyresampled( $new_image, $old_image, 0, 0, 0, 0, $image_width, $image_height, imageSX($old_image), imageSY($old_image)); + /*imageCopyResized*/ + imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $image_width, $image_height, imageSX($old_image), imageSY($old_image)); - // Save to file - imageJpeg($new_image, $filename); - return 1; + // Save to file + imageJpeg($new_image, $filename); + return 1; - } else { - return 0; - } + } else { + return 0; + } - } + } } + ?> diff --git a/templates/thumb/thumb.html b/templates/thumb/thumb.html index 0061e8cb2..887781b56 100644 --- a/templates/thumb/thumb.html +++ b/templates/thumb/thumb.html @@ -2,10 +2,11 @@ @version 0.1 (auto-set) #--> [#if SRC!=""#] + [#if ENLARGE!="1"#] - + [#else#] - - + [#endif#] + +[#if SLIDESHOW="1"#] + +[#endif#] + [#else SRC#] image not found ([#REQUESTED#]) [#endif SRC#] \ No newline at end of file From 1086f108b70146bdc929d69aafbe11516479a84a Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Fri, 11 Jan 2019 18:33:58 +0300 Subject: [PATCH 03/31] Minor fixes * Simple Devices: minor update to devices links interface * Removed some debug outputs * Language minor tweaks --- command.php | 11 +- languages/ru.php | 4 +- lib/common.class.php | 20 +- lib/hooks.inc.php | 8 +- lib/session.class.php | 2 + modules/devices/devices_links.inc.php | 4 +- modules/devices/devices_search.inc.php | 2 +- modules/devices/processCommand.inc.php | 336 +++++++++++----------- scripts/cycle_execs.php | 4 +- templates/devices/devices_edit_links.html | 10 +- 10 files changed, 201 insertions(+), 200 deletions(-) diff --git a/command.php b/command.php index 47cb57b9d..d7143b322 100644 --- a/command.php +++ b/command.php @@ -16,7 +16,7 @@ if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) - header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); + header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); exit(0); } @@ -31,17 +31,20 @@ include_once("./load_settings.php"); +//DebMes("Command received: ".$qry,'debug1'); + Define('DEVIDER', 'и'); +/* $sqlQuery = "SELECT MESSAGE FROM shouts WHERE MEMBER_ID = 0 ORDER BY ID DESC LIMIT 1"; - $lastest_word = current(SQLSelectOne($sqlQuery)); +*/ -if ($qry != '' && $qry != $lastest_word) { +if ($qry != '') { // && $qry != $lastest_word $terminal = gr('terminal'); if ($terminal) { @@ -130,6 +133,8 @@ if ($source) { $say_source = $source; + } else { + $say_source = 'command.php'; } say(htmlspecialchars($qrys[$i]), 0, $user_id, $say_source); diff --git a/languages/ru.php b/languages/ru.php index 5b42ee433..eee62fd0a 100644 --- a/languages/ru.php +++ b/languages/ru.php @@ -1239,8 +1239,8 @@ 'DEVICES_COMMAND_CONFIRMATION' => 'Готово|Сделано|Как пожелаете|Хорошо', 'DEVICES_ROOMS_NOBODYHOME' => 'Никого нет.', - 'DEVICES_ROOMS_SOMEBODYHOME' => 'Кто-то есть.', - 'DEVICES_ROOMS_ACTIVITY' => 'Активность:', + 'DEVICES_ROOMS_SOMEBODYHOME' => 'Кто-то есть', + 'DEVICES_ROOMS_ACTIVITY' => 'Активность', 'DEVICES_PASSED_NOW' => 'только что', 'DEVICES_PASSED_SECONDS_AGO' => 'сек. назад', diff --git a/lib/common.class.php b/lib/common.class.php index b1a24b943..37cbab496 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -136,7 +136,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '') { verbose_log("SAY (level: $level; member: $member; source: $source): ".$ph); - DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say'); + //DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say'); $rec = array(); $rec['MESSAGE'] = $ph; @@ -756,24 +756,8 @@ function callScript($id, $params = '') } function getURLBackground($url, $cache = 0, $username = '', $password = '') { + //DebMes("URL: ".$url,'debug1'); getURL($url, $cache, $username, $password, true); - /* - if (strlen($url)>=255) { - getURL($url, $cache, $username, $password, true); - } else { - $data = array(); - if ($cache) { - $data['cache']=$cache; - } - if ($username) { - $data['username']=$username; - } - if ($password) { - $data['password']=$password; - } - addToOperationsQueue('getURLBackground',$url,json_encode($data),false,5*60); - } - */ } /** diff --git a/lib/hooks.inc.php b/lib/hooks.inc.php index 0df1c3826..28765b3f7 100644 --- a/lib/hooks.inc.php +++ b/lib/hooks.inc.php @@ -80,7 +80,7 @@ function processSubscriptionsSafe($event_name,$details='') { $data[session_name()]=session_id(); } $url=BASE_URL.'/objects/?'.http_build_query($data); - DebMes("URL: $url",'pattern'); + //DebMes("URL: $url",'process_subscriptions'); if (is_array($params)) { foreach($params as $k=>$v) { $url.='&'.$k.'='.urlencode($v); @@ -110,7 +110,7 @@ function processSubscriptions($event_name, $details = '') } $data = json_decode(constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)), true); - DebMes("Subscription data for ".'SETTINGS_HOOK_EVENT_' . strtoupper($event_name).": ".serialize($data),'process_subscription'); + //DebMes("Subscription data for ".'SETTINGS_HOOK_EVENT_' . strtoupper($event_name).": ".serialize($data),'process_subscription'); if (!is_array($data)) { DebMes("Incorrect data for ".'SETTINGS_HOOK_EVENT_' . strtoupper($event_name).':'.constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)),'process_subscription'); @@ -130,7 +130,7 @@ function processSubscriptions($event_name, $details = '') $module_name = $data2[$i]['module']; $filter_details = $data2[$i]['filter']; - DebMes("Post event ".$event_name." to module ".$module_name. " (details: ".json_encode($details).")",'process_subscription'); + //DebMes("Post event ".$event_name." to module ".$module_name. " (details: ".json_encode($details).")",'process_subscription'); $modulePath = DIR_MODULES . $module_name . '/' . $module_name . '.class.php'; @@ -147,7 +147,7 @@ function processSubscriptions($event_name, $details = '') } catch (Exception $e) { DebMes('Error in processing "%s": ' . $e->getMessage(),'process_subscription'); } - DebMes("$module_name.processSubscription ($event_name) DONE",'process_subscription'); + //DebMes("$module_name.processSubscription ($event_name) DONE",'process_subscription'); } else { DebMes("$module_name.processSubscription error (method not found)",'process_subscription'); } diff --git a/lib/session.class.php b/lib/session.class.php index 741d75e14..1c641929b 100644 --- a/lib/session.class.php +++ b/lib/session.class.php @@ -39,6 +39,8 @@ public function __construct($name) { $this->name = $name; + if ($_GET['no_session']) return false; + ini_set('session.use_only_cookies', '0'); //not only cookies if (!isset($_SERVER['HTTP_USER_AGENT']) || $this->checkBot($_SERVER['HTTP_USER_AGENT'])) diff --git a/modules/devices/devices_links.inc.php b/modules/devices/devices_links.inc.php index f72424a20..b2c39a0d7 100644 --- a/modules/devices/devices_links.inc.php +++ b/modules/devices/devices_links.inc.php @@ -79,10 +79,12 @@ //print_r($link_details);exit; } -$links=SQLSelect("SELECT devices_linked.*, devices.TITLE FROM devices_linked LEFT JOIN devices ON devices.ID=DEVICE2_ID WHERE DEVICE1_ID=".(int)$rec['ID']." ORDER BY ID"); +$links=SQLSelect("SELECT devices_linked.*, devices.TITLE FROM devices_linked LEFT JOIN devices ON devices.ID=DEVICE2_ID WHERE (DEVICE1_ID=".(int)$rec['ID']." OR DEVICE2_ID=".(int)$rec['ID'].") ORDER BY ID"); if ($links[0]['ID']) { $total = count($links); for ($i = 0; $i < $total; $i++) { + $device1=SQLSelectOne("SELECT ID, TITLE FROM devices WHERE ID=".(int)$links[$i]['DEVICE1_ID']); + $links[$i]['DEVICE1_TITLE']=$device1['TITLE']; if ($links[$i]['LINK_SETTINGS']!='') { $settings=unserialize($links[$i]['LINK_SETTINGS']); $new_settings=''; diff --git a/modules/devices/devices_search.inc.php b/modules/devices/devices_search.inc.php index ecd7ffb86..9b4785e87 100644 --- a/modules/devices/devices_search.inc.php +++ b/modules/devices/devices_search.inc.php @@ -70,7 +70,7 @@ $res[$i]['HTML']=$processed['HTML']; } $res[$i]['TYPE_TITLE']=$this->device_types[$res[$i]['TYPE']]['TITLE']; - $linked=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM devices_linked WHERE DEVICE1_ID=".$res[$i]['ID']); + $linked=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM devices_linked WHERE (DEVICE1_ID=".$res[$i]['ID']." OR DEVICE2_ID=".$res[$i]['ID'].")"); if ($linked['TOTAL']) { $res[$i]['LINKED']=$linked['TOTAL']; } diff --git a/modules/devices/processCommand.inc.php b/modules/devices/processCommand.inc.php index a9c614f09..bc8849e8d 100644 --- a/modules/devices/processCommand.inc.php +++ b/modules/devices/processCommand.inc.php @@ -1,6 +1,6 @@ $level, 'message' => $ph, 'member_id' => $member_id) @@ -11,40 +11,41 @@ $command = $details['message']; -$run_code=''; -$opposite_code=''; -$add_phrase=''; -$period_delay=0; -$period_run_for=0; - -if (preg_match('/'.LANG_PATTERN_DO_AFTER.' (\d+?) ('.LANG_PATTERN_SECOND.'|'.LANG_PATTERN_MINUTE.'|'.LANG_PATTERN_HOUR.')/uis',textToNumbers($command),$m)) { - $period_number=$m[1]; - $add_phrase=' '.$m[0]; - if (preg_match('/'.LANG_PATTERN_SECOND.'/uis',$m[2])) { - $period_delay=$period_number; - } elseif (preg_match('/'.LANG_PATTERN_MINUTE.'/uis',$m[2])) { - $period_delay=$period_number*60; - } elseif (preg_match('/'.LANG_PATTERN_HOUR.'/uis',$m[2])) { - $period_delay=$period_number*60*60; +$run_code = ''; +$opposite_code = ''; +$add_phrase = ''; +$period_delay = 0; +$period_run_for = 0; + +if (preg_match('/' . LANG_PATTERN_DO_AFTER . ' (\d+?) (' . LANG_PATTERN_SECOND . '|' . LANG_PATTERN_MINUTE . '|' . LANG_PATTERN_HOUR . ')/uis', textToNumbers($command), $m)) { + $period_number = $m[1]; + $add_phrase = ' ' . $m[0]; + if (preg_match('/' . LANG_PATTERN_SECOND . '/uis', $m[2])) { + $period_delay = $period_number; + } elseif (preg_match('/' . LANG_PATTERN_MINUTE . '/uis', $m[2])) { + $period_delay = $period_number * 60; + } elseif (preg_match('/' . LANG_PATTERN_HOUR . '/uis', $m[2])) { + $period_delay = $period_number * 60 * 60; } - $command=trim(str_replace($m[0],'',textToNumbers($command))); -} elseif (preg_match('/'.LANG_PATTERN_DO_FOR.' (\d+?) ('.LANG_PATTERN_SECOND.'|'.LANG_PATTERN_MINUTE.'|'.LANG_PATTERN_HOUR.')/uis',textToNumbers($command),$m)) { - $period_number=$m[1]; - $add_phrase=' '.$m[0]; - if (preg_match('/'.LANG_PATTERN_SECOND.'/uis',$m[2])) { - $period_run_for=$period_number; - } elseif (preg_match('/'.LANG_PATTERN_MINUTE.'/uis',$m[2])) { - $period_run_for=$period_number*60; - } elseif (preg_match('/'.LANG_PATTERN_HOUR.'/uis',$m[2])) { - $period_run_for=$period_number*60*60; + $command = trim(str_replace($m[0], '', textToNumbers($command))); +} elseif (preg_match('/' . LANG_PATTERN_DO_FOR . ' (\d+?) (' . LANG_PATTERN_SECOND . '|' . LANG_PATTERN_MINUTE . '|' . LANG_PATTERN_HOUR . ')/uis', textToNumbers($command), $m)) { + $period_number = $m[1]; + $add_phrase = ' ' . $m[0]; + if (preg_match('/' . LANG_PATTERN_SECOND . '/uis', $m[2])) { + $period_run_for = $period_number; + } elseif (preg_match('/' . LANG_PATTERN_MINUTE . '/uis', $m[2])) { + $period_run_for = $period_number * 60; + } elseif (preg_match('/' . LANG_PATTERN_HOUR . '/uis', $m[2])) { + $period_run_for = $period_number * 60 * 60; } - $command=trim(str_replace($m[0],'',textToNumbers($command))); + $command = trim(str_replace($m[0], '', textToNumbers($command))); } $processed = 0; $reply_confirm = 0; +$reply_say = ''; -$phpmorphy_loaded=0; +$phpmorphy_loaded = 0; if (file_exists(ROOT . "lib/phpmorphy/common.php")) { require_once(ROOT . "lib/phpmorphy/common.php"); @@ -69,18 +70,18 @@ die('Error occured while creating phpMorphy instance: ' . PHP_EOL . $e); } $words = explode(' ', $command); - $words_filtered=array(); - $filtered_count=0; + $words_filtered = array(); + $filtered_count = 0; $base_forms = array(); $base_forms_filtered = array(); $totals = count($words); for ($is = 0; $is < $totals; $is++) { - $filtered=0; - $upper=mb_strtoupper($words[$is], 'UTF-8'); - $len=mb_strlen($words[$is],'UTF-8'); - if ($len>=3) { - $words_filtered[]=$words[$is]; - $filtered=1; + $filtered = 0; + $upper = mb_strtoupper($words[$is], 'UTF-8'); + $len = mb_strlen($words[$is], 'UTF-8'); + if ($len >= 3) { + $words_filtered[] = $words[$is]; + $filtered = 1; $filtered_count++; } if (preg_match('/^(\d+)$/', $words[$is])) { @@ -93,15 +94,15 @@ $base_forms[$is] = array($words[$is]); } if ($filtered) { - $base_forms_filtered[$filtered_count-1]=$base_forms[$is]; + $base_forms_filtered[$filtered_count - 1] = $base_forms[$is]; } } $combos = $this->generate_combinations($base_forms); - if ($filtered_count<$totals) { + if ($filtered_count < $totals) { $add_combos = $this->generate_combinations($base_forms_filtered); - foreach($add_combos as $cmb) { - $combos[]=$cmb; + foreach ($add_combos as $cmb) { + $combos[] = $cmb; } } @@ -123,128 +124,127 @@ $lines[] = implode(' ', $combos[$is]); } //dprint($lines); - $phpmorphy_loaded=1; + $phpmorphy_loaded = 1; } $devices = SQLSelect("SELECT ID, TITLE, ALT_TITLES, TYPE, LINKED_OBJECT FROM devices"); -foreach($devices as $device) { - if (trim($device['ALT_TITLES'])!='') { - $nicknames=explode(',',trim($device['ALT_TITLES'])); - foreach($nicknames as $nickname) { - $add_rec=$device; - $add_rec['TITLE']=$nickname; +foreach ($devices as $device) { + if (trim($device['ALT_TITLES']) != '') { + $nicknames = explode(',', trim($device['ALT_TITLES'])); + foreach ($nicknames as $nickname) { + $add_rec = $device; + $add_rec['TITLE'] = $nickname; $devices[] = $add_rec; } } } $groups = SQLSelect("SELECT * FROM devices_groups"); $total = count($groups); -for($i=0;$i<$total;$i++) { - $add_rec=$groups[$i]; - $add_rec['TYPE']='group'; +for ($i = 0; $i < $total; $i++) { + $add_rec = $groups[$i]; + $add_rec['TYPE'] = 'group'; $devices[] = $add_rec; } -$rooms=SQLSelect("SELECT locations.ID, locations.TITLE, COUNT(*) as TOTAL FROM locations, devices WHERE locations.ID=devices.LOCATION_ID GROUP BY locations.ID"); -foreach($rooms as $room) { +$rooms = SQLSelect("SELECT locations.ID, locations.TITLE, COUNT(*) AS TOTAL FROM locations, devices WHERE locations.ID=devices.LOCATION_ID GROUP BY locations.ID"); +foreach ($rooms as $room) { //lights //if ($room['TITLE']=='Кабинет') { - $device_types=array(); - $room_devices=SQLSelect("SELECT * FROM devices WHERE LOCATION_ID=".$room['ID']." AND TYPE='relay'"); - foreach($room_devices as $device) { - $loadType=gg($device['LINKED_OBJECT'].'.loadType'); - $device_types[$loadType][]=$device; - } - if (isset($device_types['light'])) { - $add_rec=array(); - $add_rec['TYPE']='group'; - $add_rec['TITLE']=LANG_DEVICES_LOADTYPE_LIGHT.' '.$room['TITLE']; - $add_rec['DEVICES']=$device_types['light']; - $add_rec['APPLY_TYPES']='relay'; - $devices[]=$add_rec; - - $add_rec=array(); - $add_rec['TYPE']='group'; - $add_rec['TITLE']=LANG_DEVICES_LOADTYPE_LIGHT_ALT.' '.$room['TITLE']; - $add_rec['DEVICES']=$device_types['light']; - $add_rec['APPLY_TYPES']='relay'; - $devices[]=$add_rec; - } + $device_types = array(); + $room_devices = SQLSelect("SELECT * FROM devices WHERE LOCATION_ID=" . $room['ID'] . " AND TYPE='relay'"); + foreach ($room_devices as $device) { + $loadType = gg($device['LINKED_OBJECT'] . '.loadType'); + $device_types[$loadType][] = $device; + } + if (isset($device_types['light'])) { + $add_rec = array(); + $add_rec['TYPE'] = 'group'; + $add_rec['TITLE'] = LANG_DEVICES_LOADTYPE_LIGHT . ' ' . $room['TITLE']; + $add_rec['DEVICES'] = $device_types['light']; + $add_rec['APPLY_TYPES'] = 'relay'; + $devices[] = $add_rec; + + $add_rec = array(); + $add_rec['TYPE'] = 'group'; + $add_rec['TITLE'] = LANG_DEVICES_LOADTYPE_LIGHT_ALT . ' ' . $room['TITLE']; + $add_rec['DEVICES'] = $device_types['light']; + $add_rec['APPLY_TYPES'] = 'relay'; + $devices[] = $add_rec; + } //} } if ($phpmorphy_loaded) { - $total=count($devices); - $add_devices=array(); - for($i=0;$i<$total;$i++) { - $device_title = $devices[$i]['TITLE']; - $words = explode(' ', mb_strtoupper($device_title, 'UTF-8')); - $base_forms = array(); - $totals = count($words); - for ($is = 0; $is < $totals; $is++) { - if (preg_match('/^(\d+)$/', $words[$is])) { - $base_forms[$is] = array($words[$is]); - } elseif (!preg_match('/[\(\)\+\.]/', $words[$is])) { - $Word = mb_strtoupper($words[$is], 'UTF-8'); - $base_form = $morphy->getBaseForm($Word); - if (is_array($base_form)) { - $base_forms[$is]=$base_form; - } else { - $base_forms[$is]=array(); - } - if (!in_array($words[$is],$base_forms[$is])) { - $base_forms[$is][] = $words[$is]; - } + $total = count($devices); + $add_devices = array(); + for ($i = 0; $i < $total; $i++) { + $device_title = $devices[$i]['TITLE']; + $words = explode(' ', mb_strtoupper($device_title, 'UTF-8')); + $base_forms = array(); + $totals = count($words); + for ($is = 0; $is < $totals; $is++) { + if (preg_match('/^(\d+)$/', $words[$is])) { + $base_forms[$is] = array($words[$is]); + } elseif (!preg_match('/[\(\)\+\.]/', $words[$is])) { + $Word = mb_strtoupper($words[$is], 'UTF-8'); + $base_form = $morphy->getBaseForm($Word); + if (is_array($base_form)) { + $base_forms[$is] = $base_form; } else { - $base_forms[$is] = array($words[$is]); + $base_forms[$is] = array(); } - } - $combos = $this->generate_combinations($base_forms); - $phrases=array(); - foreach($combos as $combo) { - $mutations=$this->computePermutations($combo); - foreach($mutations as $m) { - $phrases[]=implode(' ',$m); + if (!in_array($words[$is], $base_forms[$is])) { + $base_forms[$is][] = $words[$is]; } + } else { + $base_forms[$is] = array($words[$is]); } - $device_titles = array(); - $totals = count($phrases); - for ($is = 0; $is < $totals; $is++) { - $new_title = $phrases[$is]; - $device_titles[]=$new_title; - $new_device=$devices[$i]; - $new_device['TITLE']=$new_title; - $new_device['ORIGINAL_TITLE']=$device_title; - $add_devices[]=$new_device; + } + $combos = $this->generate_combinations($base_forms); + $phrases = array(); + foreach ($combos as $combo) { + $mutations = $this->computePermutations($combo); + foreach ($mutations as $m) { + $phrases[] = implode(' ', $m); } } - foreach($add_devices as $device) { - $devices[]=$device; + $device_titles = array(); + $totals = count($phrases); + for ($is = 0; $is < $totals; $is++) { + $new_title = $phrases[$is]; + $device_titles[] = $new_title; + $new_device = $devices[$i]; + $new_device['TITLE'] = $new_title; + $new_device['ORIGINAL_TITLE'] = $device_title; + $add_devices[] = $new_device; + } + } + foreach ($add_devices as $device) { + $devices[] = $device; } } //dprint($lines,false); //dprint($devices); -$compare_title=$command; -if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $compare_title,$m)) { - $compare_title=trim(str_replace($m[0],' ',$compare_title)); +$compare_title = $command; +if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $compare_title, $m)) { + $compare_title = trim(str_replace($m[0], ' ', $compare_title)); } -if (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $compare_title,$m)) { - $compare_title=trim(str_replace($m[0],' ',$compare_title)); +if (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $compare_title, $m)) { + $compare_title = trim(str_replace($m[0], ' ', $compare_title)); } -$compare_title = trim(preg_replace('/^ть /','',$compare_title)); -$compare_title = trim(preg_replace('/^те /','',$compare_title)); +$compare_title = trim(preg_replace('/^ть /', '', $compare_title)); +$compare_title = trim(preg_replace('/^те /', '', $compare_title)); if ($compare_title == '') { return; } - $total = count($devices); for ($i = 0; $i < $total; $i++) { $device_matched = 0; @@ -271,38 +271,38 @@ //found device $device_id = $devices[$i]['ID']; $device_type = $devices[$i]['TYPE']; - if ($devices[$i]['ORIGINAL_TITLE']!='') { + if ($devices[$i]['ORIGINAL_TITLE'] != '') { $device_title = $devices[$i]['ORIGINAL_TITLE']; } else { $device_title = $devices[$i]['TITLE']; } - DebMes("Device found for $command ($device_title)",'simple_devices'); + DebMes("Device found for $command ($device_title)", 'simple_devices'); $linked_object = $devices[$i]['LINKED_OBJECT']; if ($device_type == 'sensor_percentage' || $device_type == 'sensor_humidity') { - sayReplySafe($device_title . ' ' . gg($linked_object . '.value') . '%', 2); + $reply_say = $device_title . ' ' . gg($linked_object . '.value') . '%'; $processed = 1; } elseif ($device_type == 'sensor_light') { - sayReplySafe($device_title . ' ' . gg($linked_object . '.value'), 2); + $reply_say = $device_title . ' ' . gg($linked_object . '.value'); $processed = 1; } elseif ($device_type == 'sensor_temp') { - sayReplySafe($device_title . ' ' . gg($linked_object . '.value') . ' ' . LANG_DEVICES_DEGREES, 2); + $reply_say = $device_title . ' ' . gg($linked_object . '.value') . ' ' . LANG_DEVICES_DEGREES; $processed = 1; } elseif (preg_match('/sensor/', $device_type)) { - sayReplySafe($device_title . ' ' . gg($linked_object . '.value') . '', 2); + $reply_say = $device_title . ' ' . gg($linked_object . '.value') . ''; $processed = 1; } elseif ($device_type == 'counter') { - sayReplySafe($device_title . ' ' . gg($linked_object . '.value') . ' ' . gg($linked_object . '.unit'), 2); + $reply_say = $device_title . ' ' . gg($linked_object . '.value') . ' ' . gg($linked_object . '.unit'); $processed = 1; } elseif ($device_type == 'openclose') { - sayReplySafe($device_title . ' ' . (gg($linked_object . '.status') ? LANG_DEVICES_STATUS_CLOSED : LANG_DEVICES_STATUS_OPEN), 2); + $reply_say = $device_title . ' ' . (gg($linked_object . '.status') ? LANG_DEVICES_STATUS_CLOSED : LANG_DEVICES_STATUS_OPEN); $processed = 1; } elseif ($device_type == 'smoke' || $device_type == 'leak') { - sayReplySafe($device_title . ' ' . (gg($linked_object . '.status') ? LANG_DEVICES_STATUS_ALARM : LANG_DEVICES_NORMAL_VALUE), 2); + $reply_say = $device_title . ' ' . (gg($linked_object . '.status') ? LANG_DEVICES_STATUS_ALARM : LANG_DEVICES_NORMAL_VALUE); $processed = 1; } elseif ($device_type == 'button') { - $run_code.="callMethodSafe('$linked_object.pressed');"; + $run_code .= "callMethodSafe('$linked_object.pressed');"; $processed = 1; $reply_confirm = 1; } elseif ($device_type == 'controller' || @@ -311,50 +311,50 @@ $device_type == 'rgb' ) { if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $command)) { - sayReplySafe(LANG_TURNING_ON.' '.$device_title.$add_phrase,2); - $run_code.="callMethodSafe('$linked_object.turnOn');"; - $opposite_code.="callMethodSafe('$linked_object.turnOff');"; + $reply_say = LANG_TURNING_ON . ' ' . $device_title . $add_phrase; + $run_code .= "callMethodSafe('$linked_object.turnOn');"; + $opposite_code .= "callMethodSafe('$linked_object.turnOff');"; $processed = 1; //$reply_confirm = 1; } elseif (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $command)) { - sayReplySafe(LANG_TURNING_OFF.' '.$device_title.$add_phrase,2); - $run_code.="callMethodSafe('$linked_object.turnOff');"; - $opposite_code.="callMethodSafe('$linked_object.turnOn');"; + $reply_say = LANG_TURNING_OFF . ' ' . $device_title . $add_phrase; + $run_code .= "callMethodSafe('$linked_object.turnOff');"; + $opposite_code .= "callMethodSafe('$linked_object.turnOn');"; $processed = 1; //$reply_confirm = 1; } } elseif ($device_type == 'group') { - $applies_to=explode(',',$devices[$i]['APPLY_TYPES']); + $applies_to = explode(',', $devices[$i]['APPLY_TYPES']); if (is_array($devices[$i]['DEVICES'])) { - $devices_in_group=array(); - foreach($devices[$i]['DEVICES'] as $group_device) { - $devices_in_group[]=$group_device['LINKED_OBJECT']; + $devices_in_group = array(); + foreach ($devices[$i]['DEVICES'] as $group_device) { + $devices_in_group[] = $group_device['LINKED_OBJECT']; } } else { - $devices_in_group=getObjectsByProperty('group'.$devices[$i]['SYS_NAME'],1); + $devices_in_group = getObjectsByProperty('group' . $devices[$i]['SYS_NAME'], 1); } //dprint($devices_in_group); if (!is_array($devices_in_group)) continue; - if (in_array('relay',$applies_to) || - in_array('dimmer',$applies_to) || - in_array('rgb',$applies_to) || + if (in_array('relay', $applies_to) || + in_array('dimmer', $applies_to) || + in_array('rgb', $applies_to) || 0 ) { if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $command)) { - sayReplySafe(LANG_TURNING_ON.' '.$device_title.$add_phrase,2); - foreach($devices_in_group as $linked_object) { - $run_code.="callMethodSafe('$linked_object.turnOn');"; - $opposite_code.="callMethodSafe('$linked_object.turnOff');"; + $reply_say = LANG_TURNING_ON . ' ' . $device_title . $add_phrase; + foreach ($devices_in_group as $linked_object) { + $run_code .= "callMethodSafe('$linked_object.turnOn');"; + $opposite_code .= "callMethodSafe('$linked_object.turnOff');"; } $processed = 1; //$reply_confirm = 1; } elseif (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $command)) { - sayReplySafe(LANG_TURNING_OFF.' '.$device_title.$add_phrase,2); - foreach($devices_in_group as $linked_object) { - $run_code.="callMethodSafe('$linked_object.turnOff');"; - $opposite_code.="callMethodSafe('$linked_object.turnOn');"; + $reply_say = LANG_TURNING_OFF . ' ' . $device_title . $add_phrase; + foreach ($devices_in_group as $linked_object) { + $run_code .= "callMethodSafe('$linked_object.turnOff');"; + $opposite_code .= "callMethodSafe('$linked_object.turnOn');"; } $processed = 1; //$reply_confirm = 1; @@ -362,12 +362,12 @@ } } - $addons_dir=DIR_MODULES.$this->name.'/addons'; + $addons_dir = DIR_MODULES . $this->name . '/addons'; if (is_dir($addons_dir)) { - $addon_files=scandir($addons_dir); - foreach($addon_files as $file) { - if (preg_match('/\_commands\.php$/',$file)) { - require($addons_dir.'/'.$file); + $addon_files = scandir($addons_dir); + foreach ($addon_files as $file) { + if (preg_match('/\_commands\.php$/', $file)) { + require($addons_dir . '/' . $file); } } } @@ -375,26 +375,30 @@ if ($processed) break; } -if ($run_code!='' && $period_delay>0) { - setTimeout('delay'.md5($run_code), $run_code, $period_delay); -} elseif ($run_code!='' && $period_run_for>0 && $opposite_code!='') { +if ($run_code != '' && $period_delay > 0) { + setTimeout('delay' . md5($run_code), $run_code, $period_delay); +} elseif ($run_code != '' && $period_run_for > 0 && $opposite_code != '') { eval($run_code); - setTimeout('opposite'.md5($run_code), $opposite_code, $period_run_for); -} elseif ($run_code!='') { + setTimeout('opposite' . md5($run_code), $opposite_code, $period_run_for); +} elseif ($run_code != '') { + //DebMes("Running: ".$run_code,'debug1'); eval($run_code); } +if ($reply_say != '') { + //DebMes("Replying: ".$reply_say,'debug1'); + sayReplySafe($reply_say, 2); +} + if ($reply_confirm) { $items = explode('|', LANG_DEVICES_COMMAND_CONFIRMATION); $items = array_map('trim', $items); - DebMes("Device reply for $event",'simple_devices'); sayReplySafe($items[array_rand($items)], 2); - DebMes("Device reply DONE for $event",'simple_devices'); } if ($processed) { $details['PROCESSED'] = 1; - $details['BREAK']=1; + $details['BREAK'] = 1; } else { //DebMes('Device not found for command: ['.$compare_title.']','devices'); } diff --git a/scripts/cycle_execs.php b/scripts/cycle_execs.php index 20b252f18..38b182bc0 100644 --- a/scripts/cycle_execs.php +++ b/scripts/cycle_execs.php @@ -53,11 +53,11 @@ SQLExec($sqlQuery); echo date("H:i:s") . " Executing (exclusive): " . $command . "\n"; - DebMes("Executing (exclusive): " . $command,'execs'); + //DebMes("Executing (exclusive): " . $command,'execs'); exec($command); if ($safe_execs[$i]['ON_COMPLETE']) { - DebMes("On complete code: ".$safe_execs[$i]['ON_COMPLETE'],'execs'); + //DebMes("On complete code: ".$safe_execs[$i]['ON_COMPLETE'],'execs'); eval($safe_execs[$i]['ON_COMPLETE']); } } diff --git a/templates/devices/devices_edit_links.html b/templates/devices/devices_edit_links.html index f9f77c75e..15f8eb581 100644 --- a/templates/devices/devices_edit_links.html +++ b/templates/devices/devices_edit_links.html @@ -4,14 +4,18 @@ [#begin LINKS#] - + [#end LINKS#] From 12f28d437ac9d89e021cef1d163c9cf6872f3922 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Sun, 13 Jan 2019 22:01:16 +0300 Subject: [PATCH 04/31] Updates * "callmethodsafe" removed where it's not required * get URL in background timeout increased * CONNECT service status removed when cloudsync is off --- lib/common.class.php | 3 ++- modules/devices/Rooms_onActivity.php | 6 +++--- modules/devices/Rooms_onIdle.php | 2 +- modules/devices/SPowerSensors_valueUpdated.php | 6 +++--- modules/devices/SSensors_valueUpdated.php | 2 +- modules/devices/SThermostats_tempDown.php | 2 +- modules/devices/SThermostats_tempUp.php | 2 +- modules/devices/SThermostats_turnOff.php | 2 +- modules/devices/SThermostats_turnOn.php | 2 +- modules/devices/SThermostats_valueUpdated.php | 2 +- modules/devices/processCommand.inc.php | 18 +++++++++--------- modules/objects/objects.class.php | 5 ++--- templates/connect/action_admin.html | 3 ++- 13 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/common.class.php b/lib/common.class.php index 37cbab496..bb4076716 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -770,6 +770,7 @@ function getURLBackground($url, $cache = 0, $username = '', $password = '') { */ function getURL($url, $cache = 0, $username = '', $password = '', $background = false) { + // DebMes($url,'urls'); $filename_part = preg_replace('/\W/is', '_', str_replace('http://', '', $url)); if (strlen($filename_part)>200) { $filename_part=substr($filename_part,0,200).md5($filename_part); @@ -797,7 +798,7 @@ function getURL($url, $cache = 0, $username = '', $password = '', $background = if ($background) { curl_setopt($ch, CURLOPT_NOSIGNAL, 1); - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 50); } if ($username != '' || $password != '') diff --git a/modules/devices/Rooms_onActivity.php b/modules/devices/Rooms_onActivity.php index 1997e430a..0042c6bfb 100644 --- a/modules/devices/Rooms_onActivity.php +++ b/modules/devices/Rooms_onActivity.php @@ -18,10 +18,10 @@ $activity_timeout=10*60; } clearTimeOut($ot."_activity_timeout"); -setTimeOut($ot."_activity_timeout","callMethodSafe('".$ot.".onIdle');",$activity_timeout); +setTimeOut($ot."_activity_timeout","callMethod('".$ot.".onIdle');",$activity_timeout); -$this->callMethodSafe("updateActivityStatus"); +$this->callMethod("updateActivityStatus"); if (getGlobal('NobodyHomeMode.active')) { - callMethodSafe('NobodyHomeMode.deactivate',array('sensor'=>$params['sensor'],'room'=>$ot)); + callMethod('NobodyHomeMode.deactivate',array('sensor'=>$params['sensor'],'room'=>$ot)); } diff --git a/modules/devices/Rooms_onIdle.php b/modules/devices/Rooms_onIdle.php index c3d84d80a..f69c74d8f 100644 --- a/modules/devices/Rooms_onIdle.php +++ b/modules/devices/Rooms_onIdle.php @@ -1,3 +1,3 @@ callMethodSafe("updateActivityStatus"); \ No newline at end of file +$this->callMethod("updateActivityStatus"); \ No newline at end of file diff --git a/modules/devices/SPowerSensors_valueUpdated.php b/modules/devices/SPowerSensors_valueUpdated.php index bc29c556d..160131614 100644 --- a/modules/devices/SPowerSensors_valueUpdated.php +++ b/modules/devices/SPowerSensors_valueUpdated.php @@ -27,16 +27,16 @@ if (!$status) { clearTimeout($timerOff); if (!timeOutExists($timerOn)) { - setTimeout($timerOn,'setGlobal("'.$ot.'.status",1);callMethodSafe("'.$ot.'.loadStatusChanged",array("status"=>1));',$onTimeout); + setTimeout($timerOn,'setGlobal("'.$ot.'.status",1);callMethod("'.$ot.'.loadStatusChanged",array("status"=>1));',$onTimeout); } } } elseif ($currentValue<$min_value) { if ($status) { clearTimeOut($timerOn); if (!timeOutExists($timerOff)) { - setTimeout($timerOff, 'setGlobal("' . $ot . '.status",0);callMethodSafe("' . $ot . '.loadStatusChanged",array("status"=>0));', $offTimeout); + setTimeout($timerOff, 'setGlobal("' . $ot . '.status",0);callMethod("' . $ot . '.loadStatusChanged",array("status"=>0));', $offTimeout); } } } -$this->callMethodSafe('statusUpdated'); +$this->callMethod('statusUpdated'); diff --git a/modules/devices/SSensors_valueUpdated.php b/modules/devices/SSensors_valueUpdated.php index 63dc842de..7defdc431 100644 --- a/modules/devices/SSensors_valueUpdated.php +++ b/modules/devices/SSensors_valueUpdated.php @@ -1,6 +1,5 @@ callMethodSafe('statusUpdated'); //$this->callMethod('logicAction'); $ot=$this->object_title; @@ -56,6 +55,7 @@ } } +$this->callMethod('statusUpdated'); /* include_once(DIR_MODULES.'devices/devices.class.php'); $dv=new devices(); diff --git a/modules/devices/SThermostats_tempDown.php b/modules/devices/SThermostats_tempDown.php index 4ce82da9f..47220f9db 100644 --- a/modules/devices/SThermostats_tempDown.php +++ b/modules/devices/SThermostats_tempDown.php @@ -16,4 +16,4 @@ $targetTemperature-=$threshold; $this->setProperty($targetTitle,$targetTemperature); -$this->callMethodSafe('valueUpdated'); +$this->callMethod('valueUpdated'); diff --git a/modules/devices/SThermostats_tempUp.php b/modules/devices/SThermostats_tempUp.php index 05dcee396..1fc3ba3be 100644 --- a/modules/devices/SThermostats_tempUp.php +++ b/modules/devices/SThermostats_tempUp.php @@ -16,4 +16,4 @@ $targetTemperature+=$threshold; $this->setProperty($targetTitle,$targetTemperature); -$this->callMethodSafe('valueUpdated'); +$this->callMethod('valueUpdated'); diff --git a/modules/devices/SThermostats_turnOff.php b/modules/devices/SThermostats_turnOff.php index 0f559fd28..9781957d7 100644 --- a/modules/devices/SThermostats_turnOff.php +++ b/modules/devices/SThermostats_turnOff.php @@ -1,4 +1,4 @@ setProperty('status', 0); -$this->callMethodSafe('enable'); \ No newline at end of file +$this->callMethod('enable'); \ No newline at end of file diff --git a/modules/devices/SThermostats_turnOn.php b/modules/devices/SThermostats_turnOn.php index 7fb177c32..ddfe6b712 100644 --- a/modules/devices/SThermostats_turnOn.php +++ b/modules/devices/SThermostats_turnOn.php @@ -1,4 +1,4 @@ setProperty('status', 1); -$this->callMethodSafe('enable'); \ No newline at end of file +$this->callMethod('enable'); \ No newline at end of file diff --git a/modules/devices/SThermostats_valueUpdated.php b/modules/devices/SThermostats_valueUpdated.php index 57f8203fb..a2c011e94 100644 --- a/modules/devices/SThermostats_valueUpdated.php +++ b/modules/devices/SThermostats_valueUpdated.php @@ -51,5 +51,5 @@ include_once(DIR_MODULES.'devices/devices.class.php'); $dv=new devices(); $dv->checkLinkedDevicesAction($this->object_title, $currentTemperature); - $this->callMethodSafe('logicAction'); + $this->callMethod('logicAction'); } diff --git a/modules/devices/processCommand.inc.php b/modules/devices/processCommand.inc.php index bc8849e8d..76cd8ea75 100644 --- a/modules/devices/processCommand.inc.php +++ b/modules/devices/processCommand.inc.php @@ -302,7 +302,7 @@ $reply_say = $device_title . ' ' . (gg($linked_object . '.status') ? LANG_DEVICES_STATUS_ALARM : LANG_DEVICES_NORMAL_VALUE); $processed = 1; } elseif ($device_type == 'button') { - $run_code .= "callMethodSafe('$linked_object.pressed');"; + $run_code .= "callMethod('$linked_object.pressed');"; $processed = 1; $reply_confirm = 1; } elseif ($device_type == 'controller' || @@ -312,14 +312,14 @@ ) { if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $command)) { $reply_say = LANG_TURNING_ON . ' ' . $device_title . $add_phrase; - $run_code .= "callMethodSafe('$linked_object.turnOn');"; - $opposite_code .= "callMethodSafe('$linked_object.turnOff');"; + $run_code .= "callMethod('$linked_object.turnOn');"; + $opposite_code .= "callMethod('$linked_object.turnOff');"; $processed = 1; //$reply_confirm = 1; } elseif (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $command)) { $reply_say = LANG_TURNING_OFF . ' ' . $device_title . $add_phrase; - $run_code .= "callMethodSafe('$linked_object.turnOff');"; - $opposite_code .= "callMethodSafe('$linked_object.turnOn');"; + $run_code .= "callMethod('$linked_object.turnOff');"; + $opposite_code .= "callMethod('$linked_object.turnOn');"; $processed = 1; //$reply_confirm = 1; } @@ -345,16 +345,16 @@ if (preg_match('/' . LANG_DEVICES_PATTERN_TURNON . '/uis', $command)) { $reply_say = LANG_TURNING_ON . ' ' . $device_title . $add_phrase; foreach ($devices_in_group as $linked_object) { - $run_code .= "callMethodSafe('$linked_object.turnOn');"; - $opposite_code .= "callMethodSafe('$linked_object.turnOff');"; + $run_code .= "callMethod('$linked_object.turnOn');"; + $opposite_code .= "callMethod('$linked_object.turnOff');"; } $processed = 1; //$reply_confirm = 1; } elseif (preg_match('/' . LANG_DEVICES_PATTERN_TURNOFF . '/uis', $command)) { $reply_say = LANG_TURNING_OFF . ' ' . $device_title . $add_phrase; foreach ($devices_in_group as $linked_object) { - $run_code .= "callMethodSafe('$linked_object.turnOff');"; - $opposite_code .= "callMethodSafe('$linked_object.turnOn');"; + $run_code .= "callMethod('$linked_object.turnOff');"; + $opposite_code .= "callMethod('$linked_object.turnOn');"; } $processed = 1; //$reply_confirm = 1; diff --git a/modules/objects/objects.class.php b/modules/objects/objects.class.php index 9ae9ca3c8..cf1389829 100644 --- a/modules/objects/objects.class.php +++ b/modules/objects/objects.class.php @@ -871,7 +871,6 @@ function setProperty($property, $value, $no_linked=0, $source='') { SQLInsert('phistory_queue', $q_rec); } - if (isset($prop['ONCHANGE']) && $prop['ONCHANGE']) { global $property_linked_history; if (!$property_linked_history[$property][$prop['ONCHANGE']]) { @@ -881,8 +880,8 @@ function setProperty($property, $value, $no_linked=0, $source='') { $params['NEW_VALUE']=(string)$value; $params['OLD_VALUE']=(string)$old_value; $params['SOURCE']=(string)$source; - //$this->callMethod($prop['ONCHANGE'], $params); - $this->callMethodSafe($prop['ONCHANGE'], $params); + $this->callMethod($prop['ONCHANGE'], $params); // + //$this->callMethodSafe($prop['ONCHANGE'], $params); unset($property_linked_history[$property][$prop['ONCHANGE']]); } } diff --git a/templates/connect/action_admin.html b/templates/connect/action_admin.html index 72df7e94a..edf661d6c 100644 --- a/templates/connect/action_admin.html +++ b/templates/connect/action_admin.html @@ -13,7 +13,7 @@ [#if TAB==""#] - +[#if CONNECT_SYNC="1"#]
[#module name="xray" action="service" cycle="connect"#] @@ -22,6 +22,7 @@  
+[#endif CONNECT_SYNC#]  
From 34e9c7dbda79210ab2b33686fb88185f655badb5 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Tue, 15 Jan 2019 02:48:39 +0300 Subject: [PATCH 05/31] Update objects.class.php OnChange method call fixed --- modules/objects/objects.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/objects/objects.class.php b/modules/objects/objects.class.php index cf1389829..0de4d18be 100644 --- a/modules/objects/objects.class.php +++ b/modules/objects/objects.class.php @@ -873,14 +873,14 @@ function setProperty($property, $value, $no_linked=0, $source='') { if (isset($prop['ONCHANGE']) && $prop['ONCHANGE']) { global $property_linked_history; - if (!$property_linked_history[$property][$prop['ONCHANGE']]) { - $property_linked_history[$property][$prop['ONCHANGE']]=1; + if (!$property_linked_history[$this->object_title.'.'.$property][$prop['ONCHANGE']]) { + $property_linked_history[$this->object_title.'.'.$property][$prop['ONCHANGE']]=1; $params=array(); $params['PROPERTY']=$property; $params['NEW_VALUE']=(string)$value; $params['OLD_VALUE']=(string)$old_value; $params['SOURCE']=(string)$source; - $this->callMethod($prop['ONCHANGE'], $params); // + $this->callMethod($prop['ONCHANGE'], $params); //$this->callMethodSafe($prop['ONCHANGE'], $params); unset($property_linked_history[$property][$prop['ONCHANGE']]); } From 55ae2eec3b77e0f5ff56d58f21a4abac7f4f4eb9 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Tue, 15 Jan 2019 23:25:04 +0300 Subject: [PATCH 06/31] Update objects.class.php Linked method bug fixed (problem with property update by MQTT module). --- modules/objects/objects.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/objects/objects.class.php b/modules/objects/objects.class.php index 0de4d18be..f3eeffd63 100644 --- a/modules/objects/objects.class.php +++ b/modules/objects/objects.class.php @@ -882,7 +882,7 @@ function setProperty($property, $value, $no_linked=0, $source='') { $params['SOURCE']=(string)$source; $this->callMethod($prop['ONCHANGE'], $params); //$this->callMethodSafe($prop['ONCHANGE'], $params); - unset($property_linked_history[$property][$prop['ONCHANGE']]); + unset($property_linked_history[$this->object_title.'.'.$property][$prop['ONCHANGE']]); } } From 9f87981fdef6bafa2f1dbbbc1acda3ba3d583d7d Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Thu, 17 Jan 2019 16:45:34 +0300 Subject: [PATCH 07/31] Updates * Settings: new Behavior section and ability to set timeout for NobodyHome mode (0 to disable) * Fixed simple device settings popup window --- languages/default.php | 3 + languages/ru.php | 3 + modules/devices/SDevices_statusUpdated.php | 10 +- modules/devices/SMotions_motionDetected.php | 74 ++++++------ modules/devices/SOpenClose_statusUpdated.php | 111 +++++++++--------- .../devices/SThermostats_statusUpdated.php | 10 +- modules/settings/settings_search.inc.php | 29 ++++- nf.php | 2 +- templates/panel.html | 3 +- 9 files changed, 149 insertions(+), 96 deletions(-) diff --git a/languages/default.php b/languages/default.php index bfab8d6c4..fafe58a76 100644 --- a/languages/default.php +++ b/languages/default.php @@ -984,6 +984,9 @@ 'SETTINGS_SECTION_' => 'General', 'SETTINGS_SECTION_HOOK' => 'Hooks', + 'SETTINGS_SECTION_BEHAVIOR' => 'Behavior', + 'SETTINGS_SECTION_BACKUP' => 'Backup', + 'SETTINGS_SECTION_SCENES' => 'Scenes', 'DEVICE_ID' => 'Device ID', 'REQUEST_TYPE' => 'Request type', diff --git a/languages/ru.php b/languages/ru.php index eee62fd0a..761d4cdc3 100644 --- a/languages/ru.php +++ b/languages/ru.php @@ -980,6 +980,9 @@ 'SETTINGS_SECTION_' => 'Общие', 'SETTINGS_SECTION_HOOK' => 'Обработчики', + 'SETTINGS_SECTION_BEHAVIOR' => 'Поведение', + 'SETTINGS_SECTION_BACKUP' => 'Резервное копирование', + 'SETTINGS_SECTION_SCENES' => 'Сцены', 'DEVICE_ID' => 'ID устройства', 'REQUEST_TYPE' => 'Тип запроса', diff --git a/modules/devices/SDevices_statusUpdated.php b/modules/devices/SDevices_statusUpdated.php index 0f8039bd1..547ddc405 100644 --- a/modules/devices/SDevices_statusUpdated.php +++ b/modules/devices/SDevices_statusUpdated.php @@ -25,8 +25,14 @@ } if ($params['NEW_VALUE'] && $linked_room && $this->getProperty('isActivity')) { - ClearTimeOut("nobodyHome"); - SetTimeOut("nobodyHome", "callMethodSafe('NobodyHomeMode.activate');", 1 * 60 * 60); + $nobodyhome_timeout=1*60*60; + if (defined('SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT')) { + $nobodyhome_timeout=SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT * 60; + } + if ($nobodyhome_timeout) { + ClearTimeOut("nobodyHome"); + SetTimeOut("nobodyHome", "callMethodSafe('NobodyHomeMode.activate');", $nobodyhome_timeout); + } if ($linked_room) { callMethodSafe($linked_room . '.onActivity', array('sensor' => $ot)); } else { diff --git a/modules/devices/SMotions_motionDetected.php b/modules/devices/SMotions_motionDetected.php index c064dab28..95604db4e 100644 --- a/modules/devices/SMotions_motionDetected.php +++ b/modules/devices/SMotions_motionDetected.php @@ -1,40 +1,46 @@ object_title; +$ot = $this->object_title; if (!isset($params['statusUpdated'])) { - setTimeout($ot.'_motion_timer_status', '', 3); -} - - if (isset($params['VALUE']) && !$params['VALUE'] && !isset($params['statusUpdated'])) { - $this->setProperty('status', 0); - return; - } - - $motion_timeout=$this->getProperty('timeout'); // seconds timeout - if (!$motion_timeout) { - $motion_timeout=20; // timeout by default - } - $nobodysHome=getGlobal('NobodyHomeMode.active'); - - if (!isset($params['statusUpdated'])) { - $this->setProperty('status', 1); - } - setTimeout($ot.'_motion_timer', 'setGlobal("'.$ot.'.status", 0);', $motion_timeout); - - if ($nobodysHome && $this->getProperty('ignoreNobodysHome')) { - return; - } - - //$this->callMethod('logicAction'); - ClearTimeOut("nobodyHome"); - SetTimeOut("nobodyHome","callMethodSafe('NobodyHomeMode.activate');", 1*60*60); - - $linked_room=$this->getProperty('linkedRoom'); - if ($linked_room) { - callMethodSafe($linked_room.'.onActivity', array('sensor'=>$ot)); - } elseif ($nobodysHome) { - callMethodSafe('NobodyHomeMode.deactivate', array('sensor'=>$ot, 'room'=>$linked_room)); - } + setTimeout($ot . '_motion_timer_status', '', 3); +} + +if (isset($params['VALUE']) && !$params['VALUE'] && !isset($params['statusUpdated'])) { + $this->setProperty('status', 0); + return; +} + +$motion_timeout = $this->getProperty('timeout'); // seconds timeout +if (!$motion_timeout) { + $motion_timeout = 20; // timeout by default +} +$nobodysHome = getGlobal('NobodyHomeMode.active'); + +if (!isset($params['statusUpdated'])) { + $this->setProperty('status', 1); +} +setTimeout($ot . '_motion_timer', 'setGlobal("' . $ot . '.status", 0);', $motion_timeout); + +if ($nobodysHome && $this->getProperty('ignoreNobodysHome')) { + return; +} + +//$this->callMethod('logicAction'); +$nobodyhome_timeout = 1 * 60 * 60; +if (defined('SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT')) { + $nobodyhome_timeout = SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT * 60; +} +if ($nobodyhome_timeout) { + ClearTimeOut("nobodyHome"); + SetTimeOut("nobodyHome", "callMethodSafe('NobodyHomeMode.activate');", $nobodyhome_timeout); +} + +$linked_room = $this->getProperty('linkedRoom'); +if ($linked_room) { + callMethodSafe($linked_room . '.onActivity', array('sensor' => $ot)); +} elseif ($nobodysHome) { + callMethodSafe('NobodyHomeMode.deactivate', array('sensor' => $ot, 'room' => $linked_room)); +} /* include_once(DIR_MODULES.'devices/devices.class.php'); diff --git a/modules/devices/SOpenClose_statusUpdated.php b/modules/devices/SOpenClose_statusUpdated.php index 492843dd9..721c6646f 100644 --- a/modules/devices/SOpenClose_statusUpdated.php +++ b/modules/devices/SOpenClose_statusUpdated.php @@ -1,66 +1,67 @@ object_title; - $ncno = $this->getProperty('ncno'); +$ot = $this->object_title; +$ncno = $this->getProperty('ncno'); - $tm=time(); - $this->setProperty('updated', $tm); - $this->callMethodSafe('setUpdatedText'); - $this->setProperty('alive', 1); +$tm = time(); +$this->setProperty('updated', $tm); +$this->callMethodSafe('setUpdatedText'); +$this->setProperty('alive', 1); - $alive_timeout=(int)$this->getProperty('aliveTimeout')*60*60; - if (!$alive_timeout) { - $alive_timeout=2*24*60*60; // 2 days alive timeout by default - } +$alive_timeout = (int)$this->getProperty('aliveTimeout') * 60 * 60; +if (!$alive_timeout) { + $alive_timeout = 2 * 24 * 60 * 60; // 2 days alive timeout by default +} - setTimeout($ot.'_alive_timer', 'setGlobal("'.$ot.'.alive", 0);', $alive_timeout); +setTimeout($ot . '_alive_timer', 'setGlobal("' . $ot . '.alive", 0);', $alive_timeout); - if ($this->getProperty('isActivity')) { - $linked_room=$this->getProperty('linkedRoom'); - if (getGlobal('NobodyHomeMode.active')) { - callMethodSafe('NobodyHomeMode.deactivate',array('sensor'=>$ot, 'room'=>$linked_room)); - } - ClearTimeOut("nobodyHome"); - SetTimeOut("nobodyHome","callMethodSafe('NobodyHomeMode.activate');", 1*60*60); - if ($linked_room) { - callMethodSafe($linked_room.'.onActivity', array('sensor'=>$ot)); - } - } - - $description = $this->description; - if (!$description) { - $description = $ot; - } - if ($this->getProperty('notify_status')) { - if (isset($params['NEW_VALUE'])) - { - if (($params['NEW_VALUE'] && $ncno=='no') || (!$params['NEW_VALUE'] && $ncno=='nc')) - say($description.' '.LANG_DEVICES_STATUS_OPEN, 2); - else - say($description.' '.LANG_DEVICES_STATUS_CLOSED, 2); - } - } - if ($this->getProperty('notify_nc')) { - if (isset($params['NEW_VALUE'])) - { - if (($params['NEW_VALUE'] && $ncno=='no') || (!$params['NEW_VALUE'] && $ncno=='nc')) - { - setTimeout($ot . '_notify_timer_1', "saySafe('".$description." ".LANG_DEVICES_STATUS_OPEN."!', 5);", 5*60); - setTimeout($ot . '_notify_timer_2', "saySafe('".$description." ".LANG_DEVICES_STATUS_OPEN."!', 5);", 10*60); - setTimeout($ot . '_notify_timer_3', "saySafe('".$description." ".LANG_DEVICES_STATUS_OPEN."!', 5);", 15*60); - } - else - { - clearTimeOut($ot . '_notify_timer_1'); - clearTimeOut($ot . '_notify_timer_2'); - clearTimeOut($ot . '_notify_timer_3'); - } - } - } +if ($this->getProperty('isActivity')) { + $linked_room = $this->getProperty('linkedRoom'); + if (getGlobal('NobodyHomeMode.active')) { + callMethodSafe('NobodyHomeMode.deactivate', array('sensor' => $ot, 'room' => $linked_room)); + } + $nobodyhome_timeout = 1 * 60 * 60; + if (defined('SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT')) { + $nobodyhome_timeout = SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT * 60; + } + if ($nobodyhome_timeout) { + ClearTimeOut("nobodyHome"); + SetTimeOut("nobodyHome", "callMethodSafe('NobodyHomeMode.activate');", $nobodyhome_timeout); + } + if ($linked_room) { + callMethodSafe($linked_room . '.onActivity', array('sensor' => $ot)); + } +} + +$description = $this->description; +if (!$description) { + $description = $ot; +} +if ($this->getProperty('notify_status')) { + if (isset($params['NEW_VALUE'])) { + if (($params['NEW_VALUE'] && $ncno == 'no') || (!$params['NEW_VALUE'] && $ncno == 'nc')) + say($description . ' ' . LANG_DEVICES_STATUS_OPEN, 2); + else + say($description . ' ' . LANG_DEVICES_STATUS_CLOSED, 2); + } +} +if ($this->getProperty('notify_nc')) { + if (isset($params['NEW_VALUE'])) { + if (($params['NEW_VALUE'] && $ncno == 'no') || (!$params['NEW_VALUE'] && $ncno == 'nc')) { + setTimeout($ot . '_notify_timer_1', "saySafe('" . $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 5 * 60); + setTimeout($ot . '_notify_timer_2', "saySafe('" . $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 10 * 60); + setTimeout($ot . '_notify_timer_3', "saySafe('" . $description . " " . LANG_DEVICES_STATUS_OPEN . "!', 5);", 15 * 60); + } else { + clearTimeOut($ot . '_notify_timer_1'); + clearTimeOut($ot . '_notify_timer_2'); + clearTimeOut($ot . '_notify_timer_3'); + } + } +} $this->callMethodSafe('logicAction'); -include_once(DIR_MODULES.'devices/devices.class.php'); -$dv=new devices(); +include_once(DIR_MODULES . 'devices/devices.class.php'); +$dv = new devices(); $dv->checkLinkedDevicesAction($this->object_title, $this->getProperty('status')); diff --git a/modules/devices/SThermostats_statusUpdated.php b/modules/devices/SThermostats_statusUpdated.php index d88f2382a..256da202a 100644 --- a/modules/devices/SThermostats_statusUpdated.php +++ b/modules/devices/SThermostats_statusUpdated.php @@ -20,8 +20,14 @@ if (getGlobal('NobodyHomeMode.active')) { callMethodSafe('NobodyHomeMode.deactivate'); } - ClearTimeOut("nobodyHome"); - SetTimeOut("nobodyHome","callMethodSafe('NobodyHomeMode.activate');", 1*60*60); + $nobodyhome_timeout = 1 * 60 * 60; + if (defined('SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT')) { + $nobodyhome_timeout = SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT * 60; + } + if ($nobodyhome_timeout) { + ClearTimeOut("nobodyHome"); + SetTimeOut("nobodyHome", "callMethodSafe('NobodyHomeMode.activate');", $nobodyhome_timeout); + } if ($linked_room) { callMethodSafe($linked_room.'.onActivity', array('sensor'=>$ot)); } diff --git a/modules/settings/settings_search.inc.php b/modules/settings/settings_search.inc.php index a0eca9218..defe90c0d 100644 --- a/modules/settings/settings_search.inc.php +++ b/modules/settings/settings_search.inc.php @@ -16,7 +16,7 @@ $sections=array(); - $filters=array('', 'scenes', 'calendar', 'hook', 'backup'); + $filters=array('','behavior', 'scenes', 'calendar', 'hook', 'backup'); $total=count($filters); for($i=0;$i<$total;$i++) { $rec=array(); @@ -56,6 +56,32 @@ } } + if ($this->filter_name=='behavior' && !defined('SETTINGS_BEHAVIOR_NOBODYHOME_TIMEOUT')) { + + $options=array( + 'BEHAVIOR_NOBODYHOME_TIMEOUT'=>array( + 'TITLE'=>'NobodyHome mode activation timeout (minutes)', + 'DEFAULTVALUE'=>60, + 'NOTES'=>'Set 0 to disable' + ) + ); + + 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['TITLE']; + $tmp['TYPE']='text'; + $tmp['DEFAULTVALUE']=$v['DEFAULTVALUE']; + $tmp['NOTES']=$v['NOTES']; + $tmp['DATA']=''; + SQLInsert('settings', $tmp); + } + } + + } + if ($this->filter_name=='hook' && !defined('SETTINGS_HOOK_BARCODE')) { //SETTINGS_HOOK_BEFORE_PLAYSOUND //SETTINGS_HOOK_AFTER_PLAYSOUND @@ -182,6 +208,7 @@ $out['FILTER_NAME']=$this->filter_name; } + if ($this->filter_exname!='') { $qry.=" AND NAME NOT LIKE '%".DBSafe($this->filter_exname)."%'"; $out['FILTER_EXNAME']=$this->filter_exname; diff --git a/nf.php b/nf.php index 73c274c51..61f9031eb 100644 --- a/nf.php +++ b/nf.php @@ -42,7 +42,7 @@ "/^\/panel\/command\/(\d+)\.html/is" => '?(panel:{action=commands})&md=commands&view_mode=edit_commands&id=\1', "/^\/panel\/xray\.html/is" => '?(panel:{action=xray})&md=xray', "/^\/panel\/linkedobject.html/is" => '?(panel:{action=linkedobject})', - "/^\/panel\/popup\/(.+?).html/is" => '?(panel:{action=\1})&print=1', + "/^\/panel\/popup\/(.+?).html/is" => '?(panel:{action=\1,print=1})&print=1', "/^\/panel\/class\/(\d+)\.html/is" => '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1', "/^\/panel\/class\/(\d+)\/properties\.html/is"=> '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1&tab=properties', "/^\/panel\/class\/(\d+)\/methods\.html/is"=> '?(panel:{action=classes})&md=classes&view_mode=edit_classes&id=\1&tab=methods', diff --git a/templates/panel.html b/templates/panel.html index 624669bd4..21847c8a8 100644 --- a/templates/panel.html +++ b/templates/panel.html @@ -605,10 +605,10 @@

[#endif PRINT#]
+ [#if PRINT!="1"#]
- <#LANG_YOU_ARE_HERE#>: <#LANG_CONTROL_PANEL#> [#if ACTION!=""#] / <#ACTION#> @@ -640,6 +640,7 @@

  + [#endif PRINT#] From 8d8687c4fc7d12040c1a9005c45ef24d18baeba5 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Sat, 19 Jan 2019 16:54:43 +0300 Subject: [PATCH 08/31] Updates * Recent devices section added to Simple Devices default interface app * Quick search in Control Panel now includes modules installed in results --- languages/default.php | 2 + languages/ru.php | 2 +- modules/devices/devices.class.php | 29 +- modules/inc_panel_ajax.php | 391 +++++++++++----------- templates/classes/views/SButtons.html | 5 +- templates/classes/views/SControllers.html | 6 +- templates/classes/views/SDimmers.html | 6 +- templates/classes/views/SThermostats.html | 22 +- 8 files changed, 259 insertions(+), 204 deletions(-) diff --git a/languages/default.php b/languages/default.php index fafe58a76..e89aee43a 100644 --- a/languages/default.php +++ b/languages/default.php @@ -1327,6 +1327,8 @@ 'MAINCYCLEDOWN' => 'Main cycle is down', 'MAINCYCLEDOWN_DETAILS' => 'Don\'t panic! :)
Looks like main MajorDoMo process is stopped.
This page should reload in few seconds and if there will be error message, please proceed with following options.', + 'RECENTLY_USED' => 'Recent', + 'TEST' => 'test' diff --git a/languages/ru.php b/languages/ru.php index 761d4cdc3..836deddd9 100644 --- a/languages/ru.php +++ b/languages/ru.php @@ -1328,7 +1328,7 @@ 'MAINCYCLEDOWN' => 'Остановлен главный цикл системы', // 'MAINCYCLEDOWN_DETAILS' => 'Без паники! :)
Остановлен главный процесс системы MajorDoMo.
Возможно, будет достаточно подождать несколько секунд и работа восстановится, но если ошибка остаётся, то воспользуйтесь пожалуйста одной из опций представленных ниже.', - + 'RECENTLY_USED' => 'Недавнее', /* end module names */ diff --git a/modules/devices/devices.class.php b/modules/devices/devices.class.php index 3a8410a03..ce015c180 100644 --- a/modules/devices/devices.class.php +++ b/modules/devices/devices.class.php @@ -458,10 +458,10 @@ function processSubscription($event, &$details) if ($diff < 0 || $diff >= 10 * 60) { continue; } - callMethodSafe($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_METHOD']); unset($rec['LINKED_OBJECT']); $rec['LATEST_RUN'] = date('Y-m-d H:i:s'); SQLUpdate('devices_scheduler_points', $rec); + callMethodSafe($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_METHOD']); } } } @@ -604,10 +604,16 @@ function usual(&$out) if ($this->ajax) { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); - global $op; - global $id; + $op=gr('op'); $res = array(); + if ($op == 'clicked') { + $object=gr('object'); + if ($object !='') { + SQLExec("UPDATE devices SET CLICKED=NOW() WHERE LINKED_OBJECT='".DBSafe($object)."'"); + } + } if ($op == 'get_device') { + $id=gr('id'); $res = $this->processDevice($id); } if ($op == 'loadAllDevicesHTML') { @@ -696,6 +702,7 @@ function usual(&$out) //$qry=" devices.FAVORITE=1"; $qry = "1"; $devices = SQLSelect("SELECT devices.*, locations.TITLE as LOCATION_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE $qry ORDER BY $orderby"); + $recent_devices=SQLSelect("SELECT devices.* FROM devices WHERE !IsNull(CLICKED) ORDER BY CLICKED DESC LIMIT 10"); } if ($devices[0]['ID']) { @@ -747,9 +754,24 @@ function usual(&$out) } } + + foreach ($warning_devices as $device) { $favorite_devices[] = $device; } + + if ($recent_devices[0]['ID']) { + $recent_devices[0]['NEW_SECTION']=1; + $recent_devices[0]['SECTION_TITLE']=LANG_RECENTLY_USED; + foreach($recent_devices as &$device) { + if ($device['LINKED_OBJECT']) { + $processed = $this->processDevice($device['ID']); + $device['HTML'] = $processed['HTML']; + } + $favorite_devices[] = $device; + } + } + foreach ($problem_devices as $device) { $favorite_devices[] = $device; } @@ -1305,6 +1327,7 @@ function dbInstall($data = '') devices: LINKED_OBJECT varchar(100) NOT NULL DEFAULT '' devices: LOCATION_ID int(10) unsigned NOT NULL DEFAULT 0 devices: FAVORITE int(3) unsigned NOT NULL DEFAULT 0 + devices: CLICKED datetime DEFAULT NULL devices: SYSTEM varchar(255) NOT NULL DEFAULT '' devices: SUBTYPE varchar(100) NOT NULL DEFAULT '' diff --git a/modules/inc_panel_ajax.php b/modules/inc_panel_ajax.php index cf2f6b2bd..3530bfdd2 100644 --- a/modules/inc_panel_ajax.php +++ b/modules/inc_panel_ajax.php @@ -1,210 +1,217 @@ ".$object['TITLE']."
"; - - $class=SQLSelectOne("SELECT * FROM classes WHERE ID='".$object['CLASS_ID']."'"); - if ($class['ID']) { - $res.=LANG_CLASS.' '.$class['TITLE']."
"; - } - - //properties and methods - $properties=SQLSelect("SELECT properties.ID, properties.TITLE, classes.TITLE as CLASS, objects.TITLE as OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN objects ON properties.OBJECT_ID=objects.ID WHERE (properties.OBJECT_ID = '".DBSafe($object['ID'])."' OR properties.CLASS_ID = '".DBSafe($object['CLASS_ID'])."') ORDER BY properties.TITLE"); - $total=count($properties); - $base_link='/panel/class/'.$object['CLASS_ID'].'/object/'.$object['ID'].'/properties.html'; - $res.=''.LANG_PROPERTIES.":
"; - for($i=0;$i<$total;$i++) { - $res.=''.$object['TITLE']; - $res.='.'.$properties[$i]['TITLE']; - $res.=' #'; - $res.="
"; - } - $methods=SQLSelect("SELECT methods.ID, methods.TITLE, methods.OBJECT_ID, methods.CLASS_ID, classes.TITLE as CLASS, objects.TITLE as OBJECT, objects.CLASS_ID as OBJECT_CLASS_ID FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.OBJECT_ID = '".DBSafe($object['ID'])."' OR methods.CLASS_ID = '".DBSafe($object['CLASS_ID'])."') ORDER BY methods.OBJECT_ID DESC, methods.TITLE"); - $total=count($methods); - $res.=''.LANG_METHODS.":
"; - for($i=0;$i<$total;$i++) { - $key=$object['TITLE'].'.'.$methods[$i]['TITLE']; - if ($seen[$key]) { - continue; - } - $seen[$key]=1; - if ($methods[$i]['OBJECT']) { - $res.=''.$methods[$i]['OBJECT']; +global $op; + +if (!headers_sent()) { + header("HTTP/1.0: 200 OK\n"); + header('Content-Type: text/html; charset=utf-8'); +} + +if ($op == 'console') { + global $command; + if (preg_match('/^\w+\.\w+$/', $command)) { + echo callMethod($command); + } elseif (preg_match('/;/', $command)) { + eval($command); } else { - $res.=''.$methods[$i]['CLASS']; + eval('echo ' . $command . ';'); } - $res.='.'.$methods[$i]['TITLE'].'
'; - } +} + +if ($op == 'filter') { + global $title; + + $object_title = ''; + $property_title = ''; + + if (preg_match('/^(.+)\.$/', $title, $m)) { + $object_title = $m[1]; + $object = SQLSelectOne("SELECT * FROM objects WHERE TITLE LIKE '" . DBSafe($object_title) . "'"); + if ($object['ID']) { + // OBJECT SELECTED + $res .= LANG_OBJECT . " " . $object['TITLE'] . "
"; + + $class = SQLSelectOne("SELECT * FROM classes WHERE ID='" . $object['CLASS_ID'] . "'"); + if ($class['ID']) { + $res .= LANG_CLASS . ' ' . $class['TITLE'] . "
"; + } + + //properties and methods + $properties = SQLSelect("SELECT properties.ID, properties.TITLE, classes.TITLE AS CLASS, objects.TITLE AS OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN objects ON properties.OBJECT_ID=objects.ID WHERE (properties.OBJECT_ID = '" . DBSafe($object['ID']) . "' OR properties.CLASS_ID = '" . DBSafe($object['CLASS_ID']) . "') ORDER BY properties.TITLE"); + $total = count($properties); + $base_link = '/panel/class/' . $object['CLASS_ID'] . '/object/' . $object['ID'] . '/properties.html'; + $res .= '' . LANG_PROPERTIES . ":
"; + for ($i = 0; $i < $total; $i++) { + $res .= '' . $object['TITLE']; + $res .= '.' . $properties[$i]['TITLE']; + $res .= ' #'; + $res .= "
"; + } + $methods = SQLSelect("SELECT methods.ID, methods.TITLE, methods.OBJECT_ID, methods.CLASS_ID, classes.TITLE AS CLASS, objects.TITLE AS OBJECT, objects.CLASS_ID AS OBJECT_CLASS_ID FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.OBJECT_ID = '" . DBSafe($object['ID']) . "' OR methods.CLASS_ID = '" . DBSafe($object['CLASS_ID']) . "') ORDER BY methods.OBJECT_ID DESC, methods.TITLE"); + $total = count($methods); + $res .= '' . LANG_METHODS . ":
"; + for ($i = 0; $i < $total; $i++) { + $key = $object['TITLE'] . '.' . $methods[$i]['TITLE']; + if ($seen[$key]) { + continue; + } + $seen[$key] = 1; + if ($methods[$i]['OBJECT']) { + $res .= '' . $methods[$i]['OBJECT']; + } else { + $res .= '' . $methods[$i]['CLASS']; + } + $res .= '.' . $methods[$i]['TITLE'] . '
'; + } + } + + $class = SQLSelectOne("SELECT * FROM classes WHERE TITLE LIKE '" . DBSafe($m[1]) . "'"); + if ($class['ID']) { + $res .= LANG_CLASS . " " . $class['TITLE'] . "
"; + + //properties and methods + $properties = SQLSelect("SELECT properties.ID, properties.TITLE, classes.TITLE AS CLASS, objects.TITLE AS OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN objects ON properties.OBJECT_ID=objects.ID WHERE (properties.CLASS_ID = '" . DBSafe($class['ID']) . "') ORDER BY properties.TITLE"); + $total = count($properties); + $res .= '' . LANG_PROPERTIES . ":
"; + for ($i = 0; $i < $total; $i++) { + $res .= '' . $class['TITLE']; + $res .= '.' . $properties[$i]['TITLE'] . '
'; + } + $methods = SQLSelect("SELECT methods.ID, methods.TITLE, classes.TITLE AS CLASS, objects.TITLE AS OBJECT FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.CLASS_ID = '" . DBSafe($class['ID']) . "') ORDER BY methods.OBJECT_ID DESC, methods.TITLE"); + $total = count($methods); + $res .= '' . LANG_METHODS . ":
"; + for ($i = 0; $i < $total; $i++) { + $key = $class['TITLE'] . '.' . $methods[$i]['TITLE']; + if ($seen[$key]) { + continue; + } + $seen[$key] = 1; + $res .= '' . $class['TITLE']; + $res .= '.' . $methods[$i]['TITLE'] . '
'; + } + + $res .= '' . LANG_OBJECTS . ":
"; + $objects = SQLSelect("SELECT ID, TITLE FROM objects WHERE (CLASS_ID = '" . $class['ID'] . "') ORDER BY TITLE"); + $total = count($objects); + for ($i = 0; $i < $total; $i++) { + $res .= '' . $objects[$i]['TITLE'] . '
'; + } + + } } - $class=SQLSelectOne("SELECT * FROM classes WHERE TITLE LIKE '".DBSafe($m[1])."'"); - if ($class['ID']) { - $res.=LANG_CLASS." ".$class['TITLE']."
"; - - //properties and methods - $properties=SQLSelect("SELECT properties.ID, properties.TITLE, classes.TITLE as CLASS, objects.TITLE as OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN objects ON properties.OBJECT_ID=objects.ID WHERE (properties.CLASS_ID = '".DBSafe($class['ID'])."') ORDER BY properties.TITLE"); - $total=count($properties); - $res.=''.LANG_PROPERTIES.":
"; - for($i=0;$i<$total;$i++) { - $res.=''.$class['TITLE']; - $res.='.'.$properties[$i]['TITLE'].'
'; - } - $methods=SQLSelect("SELECT methods.ID, methods.TITLE, classes.TITLE as CLASS, objects.TITLE as OBJECT FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.CLASS_ID = '".DBSafe($class['ID'])."') ORDER BY methods.OBJECT_ID DESC, methods.TITLE"); - $total=count($methods); - $res.=''.LANG_METHODS.":
"; - for($i=0;$i<$total;$i++) { - $key=$class['TITLE'].'.'.$methods[$i]['TITLE']; - if ($seen[$key]) { - continue; + //Project Modules + $items = SQLSelect("SELECT NAME,TITLE FROM project_modules WHERE TITLE LIKE '%".DBSafe($title)."%' AND HIDDEN=0"); + foreach($items as $item) { + $res.= ''.processTitle($item['TITLE']).'
'; } - $seen[$key]=1; - $res.=''.$class['TITLE']; - $res.='.'.$methods[$i]['TITLE'].'
'; - } - - $res.=''.LANG_OBJECTS.":
"; - $objects=SQLSelect("SELECT ID, TITLE FROM objects WHERE (CLASS_ID = '".$class['ID']."') ORDER BY TITLE"); - $total=count($objects); - for($i=0;$i<$total;$i++) { - $res.=''.$objects[$i]['TITLE'].'
'; - } - - } - - } - - //classes - $classes=SQLSelect("SELECT ID, TITLE FROM classes WHERE TITLE LIKE '%".DBSafe($title)."%' ORDER BY TITLE"); - $total=count($classes); - for($i=0;$i<$total;$i++) { - $res.='Class: '.$classes[$i]['TITLE'].'
'; - } - //objects - $objects=SQLSelect("SELECT ID, TITLE FROM objects WHERE (TITLE LIKE '%".DBSafe($title)."%' OR DESCRIPTION LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($objects); - for($i=0;$i<$total;$i++) { - $res.='Obj: '.$objects[$i]['TITLE'].'
'; - } - - //properties and methods - $qry="SELECT properties.ID, properties.CLASS_ID, properties.TITLE, objects.CLASS_ID as OBJECT_CLASS_ID, objects.ID as OBJECT_ID, classes.TITLE as CLASS, objects.TITLE as OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN pvalues ON (properties.ID=pvalues.PROPERTY_ID AND (properties.OBJECT_ID=pvalues.OBJECT_ID OR properties.OBJECT_ID=0)) LEFT JOIN objects ON (properties.OBJECT_ID=objects.ID OR pvalues.OBJECT_ID=objects.ID) WHERE (properties.TITLE LIKE '%".DBSafe($title)."%' OR pvalues.VALUE LIKE '%".DBSafe($title)."%') ORDER BY properties.TITLE"; - $properties=SQLSelect($qry); - $total=count($properties); - for($i=0;$i<$total;$i++) { - $res.='P: '; // - if ($properties[$i]['OBJECT']) { - $res.=''.$methods[$i]['OBJECT']; - $res.=$properties[$i]['OBJECT']; - } else { - $res.=''.$methods[$i]['OBJECT']; - $res.=$properties[$i]['CLASS']; + + //classes + $classes = SQLSelect("SELECT ID, TITLE FROM classes WHERE TITLE LIKE '%" . DBSafe($title) . "%' ORDER BY TITLE"); + $total = count($classes); + for ($i = 0; $i < $total; $i++) { + $res .= 'Class: ' . $classes[$i]['TITLE'] . '
'; } - $res.='.'.$properties[$i]['TITLE'].'
'; - } - - $methods=SQLSelect("SELECT methods.ID, methods.TITLE, methods.OBJECT_ID, objects.CLASS_ID as OBJECT_CLASS_ID, methods.CLASS_ID, classes.TITLE as CLASS, objects.TITLE as OBJECT FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.TITLE LIKE '%".DBSafe($title)."%' OR methods.CODE LIKE '%".DBSafe($title)."%') ORDER BY methods.TITLE"); - $total=count($methods); - for($i=0;$i<$total;$i++) { - $res.='M: '; // - if ($methods[$i]['OBJECT']) { - $res.=''.$methods[$i]['OBJECT']; - } else { - $res.=''.$methods[$i]['CLASS']; + //objects + $objects = SQLSelect("SELECT ID, TITLE FROM objects WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR DESCRIPTION LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($objects); + for ($i = 0; $i < $total; $i++) { + $res .= 'Obj: ' . $objects[$i]['TITLE'] . '
'; + } + + //properties and methods + $qry = "SELECT properties.ID, properties.CLASS_ID, properties.TITLE, objects.CLASS_ID AS OBJECT_CLASS_ID, objects.ID AS OBJECT_ID, classes.TITLE AS CLASS, objects.TITLE AS OBJECT FROM properties LEFT JOIN classes ON properties.CLASS_ID=classes.ID LEFT JOIN pvalues ON (properties.ID=pvalues.PROPERTY_ID AND (properties.OBJECT_ID=pvalues.OBJECT_ID OR properties.OBJECT_ID=0)) LEFT JOIN objects ON (properties.OBJECT_ID=objects.ID OR pvalues.OBJECT_ID=objects.ID) WHERE (properties.TITLE LIKE '%" . DBSafe($title) . "%' OR pvalues.VALUE LIKE '%" . DBSafe($title) . "%') ORDER BY properties.TITLE"; + $properties = SQLSelect($qry); + $total = count($properties); + for ($i = 0; $i < $total; $i++) { + $res .= 'P: '; // + if ($properties[$i]['OBJECT']) { + $res .= '' . $methods[$i]['OBJECT']; + $res .= $properties[$i]['OBJECT']; + } else { + $res .= '' . $methods[$i]['OBJECT']; + $res .= $properties[$i]['CLASS']; + } + $res .= '.' . $properties[$i]['TITLE'] . '
'; + } + + $methods = SQLSelect("SELECT methods.ID, methods.TITLE, methods.OBJECT_ID, objects.CLASS_ID AS OBJECT_CLASS_ID, methods.CLASS_ID, classes.TITLE AS CLASS, objects.TITLE AS OBJECT FROM methods LEFT JOIN classes ON methods.CLASS_ID=classes.ID LEFT JOIN objects ON methods.OBJECT_ID=objects.ID WHERE (methods.TITLE LIKE '%" . DBSafe($title) . "%' OR methods.CODE LIKE '%" . DBSafe($title) . "%') ORDER BY methods.TITLE"); + $total = count($methods); + for ($i = 0; $i < $total; $i++) { + $res .= 'M: '; // + if ($methods[$i]['OBJECT']) { + $res .= '' . $methods[$i]['OBJECT']; + } else { + $res .= '' . $methods[$i]['CLASS']; + } + $res .= '.' . $methods[$i]['TITLE'] . '
'; + } + //scripts + $scripts = SQLSelect("SELECT ID, TITLE FROM scripts WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR CODE LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($scripts); + for ($i = 0; $i < $total; $i++) { + $res .= 'Script: ' . $scripts[$i]['TITLE'] . '
'; } - $res.='.'.$methods[$i]['TITLE'].'
'; - } - //scripts - $scripts=SQLSelect("SELECT ID, TITLE FROM scripts WHERE (TITLE LIKE '%".DBSafe($title)."%' OR CODE LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($scripts); - for($i=0;$i<$total;$i++) { - $res.='Script: '.$scripts[$i]['TITLE'].'
'; - } - //patterns - $patterns=SQLSelect("SELECT ID, TITLE FROM patterns WHERE (TITLE LIKE '%".DBSafe($title)."%' OR SCRIPT LIKE '%".DBSafe($title)."%' OR PATTERN LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($patterns); - for($i=0;$i<$total;$i++) { - $res.='Pattern: '.$patterns[$i]['TITLE'].'
'; - } - //menu elements (to-do: content) - $commands=SQLSelect("SELECT ID, TITLE FROM commands WHERE (TITLE LIKE '%".DBSafe($title)."%' OR LINKED_OBJECT LIKE '%".DBSafe($title)."%' OR LINKED_PROPERTY LIKE '%".DBSafe($title)."%' OR ONCHANGE_METHOD LIKE '%".DBSafe($title)."%' OR CODE LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($commands); - for($i=0;$i<$total;$i++) { - $res.='Menu: '.$commands[$i]['TITLE'].'
'; - } - - //scene states - $states=SQLSelect("SELECT elm_states.ID, elm_states.TITLE, ELEMENT_ID, elements.SCENE_ID, elements.TITLE as ELEMENT_TITLE FROM elm_states LEFT JOIN elements ON elements.ID=elm_states.ELEMENT_ID WHERE (elm_states.LINKED_OBJECT LIKE '%".DBSafe($title)."%' OR elm_states.LINKED_PROPERTY LIKE '%".DBSafe($title)."%' OR elm_states.ACTION_METHOD LIKE '%".DBSafe($title)."%' OR elm_states.CONDITION_ADVANCED LIKE '%".DBSafe($title)."%' OR elm_states.CONDITION_VALUE LIKE '%".DBSafe($title)."%') AND elements.ID>0 ORDER BY elm_states.TITLE"); - $total=count($states); - for($i=0;$i<$total;$i++) { - $res.='Scene: '.$states[$i]['ELEMENT_TITLE'].'.'.$states[$i]['TITLE'].'
'; - } - //scene elements - $elements=SQLSelect("SELECT elements.ID, elements.SCENE_ID, elements.TITLE FROM elements WHERE (elements.LINKED_OBJECT LIKE '%".DBSafe($title)."%' OR elements.LINKED_PROPERTY LIKE '%".DBSafe($title)."%' OR elements.TITLE LIKE '%".DBSafe($title)."%') ORDER BY elements.TITLE"); - $total=count($elements); - for($i=0;$i<$total;$i++) { - $res.='Scene: '.$elements[$i]['TITLE'].'
'; - } - - //zwave devices - if (file_exists(DIR_MODULES.'zwave/zwave.class.php')) { - $devices=SQLSelect("SELECT ID, DEVICE_ID, TITLE FROM zwave_properties WHERE (TITLE LIKE '%".DBSafe($title)."%' OR LINKED_OBJECT LIKE '%".DBSafe($title)."%' OR LINKED_PROPERTY LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($devices); - for($i=0;$i<$total;$i++) { - $res.='ZWave: '.$devices[$i]['TITLE'].'
'; + //patterns + $patterns = SQLSelect("SELECT ID, TITLE FROM patterns WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR SCRIPT LIKE '%" . DBSafe($title) . "%' OR PATTERN LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($patterns); + for ($i = 0; $i < $total; $i++) { + $res .= 'Pattern: ' . $patterns[$i]['TITLE'] . '
'; } - } - if (file_exists(DIR_MODULES.'devices/devices.class.php')) { - $devices=SQLSelect("SELECT ID, TITLE FROM devices WHERE (TITLE LIKE '%".DBSafe($title)."%' OR LINKED_OBJECT LIKE '%".DBSafe($title)."%') ORDER BY TITLE"); - $total=count($devices); - for($i=0;$i<$total;$i++) { - $res.='Device: '.$devices[$i]['TITLE'].'
'; + //menu elements (to-do: content) + $commands = SQLSelect("SELECT ID, TITLE FROM commands WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR LINKED_OBJECT LIKE '%" . DBSafe($title) . "%' OR LINKED_PROPERTY LIKE '%" . DBSafe($title) . "%' OR ONCHANGE_METHOD LIKE '%" . DBSafe($title) . "%' OR CODE LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($commands); + for ($i = 0; $i < $total; $i++) { + $res .= 'Menu: ' . $commands[$i]['TITLE'] . '
'; } - } - - //zwave devices - if (file_exists(DIR_MODULES.'app_gpstrack/app_gpstrack.class.php')) { - $devices=SQLSelect("SELECT gpsactions.ID, gpslocations.TITLE, users.NAME FROM gpsactions LEFT JOIN users ON gpsactions.USER_ID=users.ID LEFT JOIN gpslocations ON gpsactions.LOCATION_ID=gpslocations.ID WHERE (TITLE LIKE '%".DBSafe($title)."%' OR CODE LIKE '%".DBSafe($title)."%') ORDER BY gpslocations.TITLE"); - $total=count($devices); - for($i=0;$i<$total;$i++) { - $res.='GPS: '.$devices[$i]['TITLE'].' - '.$devices[$i]['NAME'].'
'; + + //scene states + $states = SQLSelect("SELECT elm_states.ID, elm_states.TITLE, ELEMENT_ID, elements.SCENE_ID, elements.TITLE AS ELEMENT_TITLE FROM elm_states LEFT JOIN elements ON elements.ID=elm_states.ELEMENT_ID WHERE (elm_states.LINKED_OBJECT LIKE '%" . DBSafe($title) . "%' OR elm_states.LINKED_PROPERTY LIKE '%" . DBSafe($title) . "%' OR elm_states.ACTION_METHOD LIKE '%" . DBSafe($title) . "%' OR elm_states.CONDITION_ADVANCED LIKE '%" . DBSafe($title) . "%' OR elm_states.CONDITION_VALUE LIKE '%" . DBSafe($title) . "%') AND elements.ID>0 ORDER BY elm_states.TITLE"); + $total = count($states); + for ($i = 0; $i < $total; $i++) { + $res .= 'Scene: ' . $states[$i]['ELEMENT_TITLE'] . '.' . $states[$i]['TITLE'] . '
'; + } + //scene elements + $elements = SQLSelect("SELECT elements.ID, elements.SCENE_ID, elements.TITLE FROM elements WHERE (elements.LINKED_OBJECT LIKE '%" . DBSafe($title) . "%' OR elements.LINKED_PROPERTY LIKE '%" . DBSafe($title) . "%' OR elements.TITLE LIKE '%" . DBSafe($title) . "%') ORDER BY elements.TITLE"); + $total = count($elements); + for ($i = 0; $i < $total; $i++) { + $res .= 'Scene: ' . $elements[$i]['TITLE'] . '
'; + } + + //zwave devices + if (file_exists(DIR_MODULES . 'zwave/zwave.class.php')) { + $devices = SQLSelect("SELECT ID, DEVICE_ID, TITLE FROM zwave_properties WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR LINKED_OBJECT LIKE '%" . DBSafe($title) . "%' OR LINKED_PROPERTY LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($devices); + for ($i = 0; $i < $total; $i++) { + $res .= 'ZWave: ' . $devices[$i]['TITLE'] . '
'; + } + } + + //Simple Devices + if (file_exists(DIR_MODULES . 'devices/devices.class.php')) { + $devices = SQLSelect("SELECT ID, TITLE FROM devices WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR LINKED_OBJECT LIKE '%" . DBSafe($title) . "%') ORDER BY TITLE"); + $total = count($devices); + for ($i = 0; $i < $total; $i++) { + $res .= 'Device: ' . $devices[$i]['TITLE'] . '
'; + } + } + + //GPS + if (file_exists(DIR_MODULES . 'app_gpstrack/app_gpstrack.class.php')) { + $devices = SQLSelect("SELECT gpsactions.ID, gpslocations.TITLE, users.NAME FROM gpsactions LEFT JOIN users ON gpsactions.USER_ID=users.ID LEFT JOIN gpslocations ON gpsactions.LOCATION_ID=gpslocations.ID WHERE (TITLE LIKE '%" . DBSafe($title) . "%' OR CODE LIKE '%" . DBSafe($title) . "%') ORDER BY gpslocations.TITLE"); + $total = count($devices); + for ($i = 0; $i < $total; $i++) { + $res .= 'GPS: ' . $devices[$i]['TITLE'] . ' - ' . $devices[$i]['NAME'] . '
'; + } } - } - //to-do: webvars + //todo: webvars + //todo: patterns - echo $res; - } - exit; + echo $res; +} +exit; ?> \ No newline at end of file diff --git a/templates/classes/views/SButtons.html b/templates/classes/views/SButtons.html index 0cdaefc78..eacb61ad2 100644 --- a/templates/classes/views/SButtons.html +++ b/templates/classes/views/SButtons.html @@ -1,4 +1,7 @@ -
+
%.object_description%
diff --git a/templates/classes/views/SControllers.html b/templates/classes/views/SControllers.html index 659b7be28..c1f68784c 100644 --- a/templates/classes/views/SControllers.html +++ b/templates/classes/views/SControllers.html @@ -1,4 +1,8 @@ -
+
%.object_description%
diff --git a/templates/classes/views/SDimmers.html b/templates/classes/views/SDimmers.html index 58709a4a1..5608f4b09 100644 --- a/templates/classes/views/SDimmers.html +++ b/templates/classes/views/SDimmers.html @@ -8,6 +8,7 @@ dimmer%.object_id%Level=val; $('#dimmer%.object_id%_level').html(dimmer%.object_id%Level); sendNewLevel%.object_id%(); + $.get("/ajax/devices.html?op=clicked&object="+encodeURIComponent("%.object_title%")); } function dimmerChange%.object_id%(d) { if (d=='+') { @@ -28,7 +29,10 @@ }
-
+
%.object_description%
diff --git a/templates/classes/views/SThermostats.html b/templates/classes/views/SThermostats.html index 112ed991e..294d47bef 100644 --- a/templates/classes/views/SThermostats.html +++ b/templates/classes/views/SThermostats.html @@ -2,16 +2,28 @@
%.object_description%
<#LANG_DEVICES_THERMOSTAT_CURRENT_TARGET_TEMP#>:
- - + - %.currentTargetValue% - + + +
<#LANG_DEVICES_THERMOSTAT_CURRENT_TEMP#>: %.value% [<#LANG_HISTORY#>]
From cf2ea0d8f21640cddb6970c8a11197da460cd935 Mon Sep 17 00:00:00 2001 From: Andrey Isupov Date: Sat, 19 Jan 2019 20:38:15 +0300 Subject: [PATCH 09/31] API: add devices field favorite --- api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api.php b/api.php index 9e8cca86c..73b4a2e39 100644 --- a/api.php +++ b/api.php @@ -29,6 +29,7 @@ $device['title']=$devices[$i]['TITLE']; $device['object']=$devices[$i]['LINKED_OBJECT']; $device['type']=$devices[$i]['TYPE']; + $device['favorite']=$devices[$i]['FAVORITE']; $obj = getObject($device['object']); if (!isset($cached_properties[$obj->class_id])) { $cached_properties[$obj->class_id]=getClassProperties($obj->class_id); @@ -53,6 +54,7 @@ $device['title']=$devices[$i]['TITLE']; $device['object']=$devices[$i]['LINKED_OBJECT']; $device['type']=$devices[$i]['TYPE']; + $device['favorite']=$devices[$i]['FAVORITE']; $obj = getObject($device['object']); if (!isset($cached_properties[$obj->class_id])) { $cached_properties[$obj->class_id]=getClassProperties($obj->class_id); From 5d9d8b69ebd40c1ebf92afdd18a20093fc8e3cc3 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Mon, 21 Jan 2019 17:58:48 +0300 Subject: [PATCH 10/31] HomeKit: Thermostat support * Simple Devices: Thermostat device now syncs with HomeKit --- modules/devices/SThermostats_valueUpdated.php | 4 +- modules/devices/devices_edit.inc.php | 2 +- modules/devices/devices_links_actions.inc.php | 318 ++++++++++-------- modules/devices/devices_search.inc.php | 2 +- modules/devices/homebridgeSync.inc.php | 40 ++- modules/devices/processHomebridgeMQTT.inc.php | 23 ++ 6 files changed, 235 insertions(+), 154 deletions(-) diff --git a/modules/devices/SThermostats_valueUpdated.php b/modules/devices/SThermostats_valueUpdated.php index a2c011e94..3473f54ca 100644 --- a/modules/devices/SThermostats_valueUpdated.php +++ b/modules/devices/SThermostats_valueUpdated.php @@ -47,9 +47,9 @@ } //echo "current: $currentTemperature target: $targetTemperature action: $need_action
"; -if ($need_action) { +//if ($need_action) { include_once(DIR_MODULES.'devices/devices.class.php'); $dv=new devices(); $dv->checkLinkedDevicesAction($this->object_title, $currentTemperature); $this->callMethod('logicAction'); -} +//} diff --git a/modules/devices/devices_edit.inc.php b/modules/devices/devices_edit.inc.php index e25790e9b..88813d2ad 100644 --- a/modules/devices/devices_edit.inc.php +++ b/modules/devices/devices_edit.inc.php @@ -417,7 +417,7 @@ }); $out['TYPES']=$types; -$out['LOCATIONS']=SQLSelect("SELECT ID, TITLE FROM locations ORDER BY TITLE"); +$out['LOCATIONS']=SQLSelect("SELECT ID, TITLE FROM locations ORDER BY TITLE+0"); if ($rec['LOCATION_ID']) { $location_rec=SQLSelectOne("SELECT ID,TITLE FROM locations WHERE ID=".$rec['LOCATION_ID']); diff --git a/modules/devices/devices_links_actions.inc.php b/modules/devices/devices_links_actions.inc.php index 05e37befc..0593bb128 100644 --- a/modules/devices/devices_links_actions.inc.php +++ b/modules/devices/devices_links_actions.inc.php @@ -3,121 +3,141 @@ //DebMes("Checking linked actions for device ".$device1['ID']); if ($this->isHomeBridgeAvailable()) { - // send updated status to HomeKit - $payload=array(); - $payload['name']=$device1['LINKED_OBJECT']; - $payload['service_name']=$device1['TITLE']; - - switch($device1['TYPE']) { - case 'relay': - $load_type=gg($device1['LINKED_OBJECT'].'.loadType'); - if ($load_type=='light') $payload['service'] = 'Lightbulb'; - elseif ($load_type=='vent') $payload['service'] = 'Fan'; - elseif ($load_type=='switch') $payload['service'] = 'Switch'; - else $payload['service'] = 'Outlet'; - $payload['characteristic'] = 'On'; - if (gg($device1['LINKED_OBJECT'].'.status')) { - $payload['value']=true; - } else { - $payload['value']=false; - } - break; - case 'sensor_temp': - $payload['service']='TemperatureSensor'; - $payload['characteristic'] = 'CurrentTemperature'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); - break; - case 'sensor_humidity': - $payload['service']='HumiditySensor'; - $payload['characteristic'] = 'CurrentRelativeHumidity'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); - break; - case 'motion': - $payload['service']='MotionSensor'; - $payload['characteristic'] = 'MotionDetected'; - if (gg($device1['LINKED_OBJECT'].'.status')) { - $payload['value']=true; - } else { - $payload['value']=false; - } - break; - case 'sensor_light': - $payload['service']='LightSensor'; - $payload['characteristic'] = 'CurrentAmbientLightLevel'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); - break; - case 'openclose': - $payload['service']='ContactSensor'; - $payload['characteristic'] = 'ContactSensorState'; - $nc = gg($device1['LINKED_OBJECT'].'.ncno') == 'nc'; - $payload['value'] = $nc ? 1 - gg($device1['LINKED_OBJECT'].'.status') : gg($device1['LINKED_OBJECT'].'.status'); - break; - case 'rgb': - DebMes('Update '.$device1['TITLE'].' from MJD'); - $payload['service']='Lightbulb'; - sg('HomeBridge.to_add',json_encode($payload)); - - $payload['characteristic'] = 'On'; - if (gg($device1['LINKED_OBJECT'].'.status')) { - $payload['value']=true; - } else { - $payload['value']=false; - } - sg('HomeBridge.to_set',json_encode($payload)); - - $payload['characteristic'] = 'Hue'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.hue'); - sg('HomeBridge.to_set',json_encode($payload)); - - $payload['characteristic'] = 'Saturation'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.saturation'); - sg('HomeBridge.to_set',json_encode($payload)); - - $payload['characteristic'] = 'Brightness'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.brightness'); - sg('HomeBridge.to_set',json_encode($payload)); - break; - /* - case 'sensor_battery': - $payload['service']='BatteryService'; - sg('HomeBridge.to_add',json_encode($payload)); - // Characteristic.BatteryLevel; - // Characteristic.ChargingState; 0 - NOT_CHARGING, 1 - CHARGING, 2 - NOT_CHARGEABLE - // Characteristic.StatusLowBattery; - $payload['characteristic'] = 'BatteryLevel'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); - sg('HomeBridge.to_set',json_encode($payload)); - - $payload['characteristic'] = 'ChargingState'; - $payload['value']=2; - sg('HomeBridge.to_set',json_encode($payload)); - - $payload['characteristic'] = 'StatusLowBattery'; - $payload['value']=gg($device1['LINKED_OBJECT'].'.normalValue') ? 0 : 1; - sg('HomeBridge.to_set',json_encode($payload)); - - break; - */ - } - if (isset($payload['value'])) { - //DebMes('HB sending to_set: '.json_encode($payload)); - sg('HomeBridge.to_set',json_encode($payload)); - } + // send updated status to HomeKit + $payload = array(); + $payload['name'] = $device1['LINKED_OBJECT']; + $payload['service_name'] = $device1['TITLE']; + + switch ($device1['TYPE']) { + case 'relay': + $load_type = gg($device1['LINKED_OBJECT'] . '.loadType'); + if ($load_type == 'light') $payload['service'] = 'Lightbulb'; + elseif ($load_type == 'vent') $payload['service'] = 'Fan'; + elseif ($load_type == 'switch') $payload['service'] = 'Switch'; + else $payload['service'] = 'Outlet'; + $payload['characteristic'] = 'On'; + if (gg($device1['LINKED_OBJECT'] . '.status')) { + $payload['value'] = true; + } else { + $payload['value'] = false; + } + break; + case 'sensor_temp': + $payload['service'] = 'TemperatureSensor'; + $payload['characteristic'] = 'CurrentTemperature'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.value'); + break; + case 'sensor_humidity': + $payload['service'] = 'HumiditySensor'; + $payload['characteristic'] = 'CurrentRelativeHumidity'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.value'); + break; + case 'motion': + $payload['service'] = 'MotionSensor'; + $payload['characteristic'] = 'MotionDetected'; + if (gg($device1['LINKED_OBJECT'] . '.status')) { + $payload['value'] = true; + } else { + $payload['value'] = false; + } + break; + case 'sensor_light': + $payload['service'] = 'LightSensor'; + $payload['characteristic'] = 'CurrentAmbientLightLevel'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.value'); + break; + case 'openclose': + $payload['service'] = 'ContactSensor'; + $payload['characteristic'] = 'ContactSensorState'; + $nc = gg($device1['LINKED_OBJECT'] . '.ncno') == 'nc'; + $payload['value'] = $nc ? 1 - gg($device1['LINKED_OBJECT'] . '.status') : gg($device1['LINKED_OBJECT'] . '.status'); + break; + case 'rgb': + DebMes('Update ' . $device1['TITLE'] . ' from MJD'); + $payload['service'] = 'Lightbulb'; + sg('HomeBridge.to_add', json_encode($payload)); + + $payload['characteristic'] = 'On'; + if (gg($device1['LINKED_OBJECT'] . '.status')) { + $payload['value'] = true; + } else { + $payload['value'] = false; + } + sg('HomeBridge.to_set', json_encode($payload)); + + $payload['characteristic'] = 'Hue'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.hue'); + sg('HomeBridge.to_set', json_encode($payload)); + + $payload['characteristic'] = 'Saturation'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.saturation'); + sg('HomeBridge.to_set', json_encode($payload)); + + $payload['characteristic'] = 'Brightness'; + $payload['value'] = gg($device1['LINKED_OBJECT'] . '.brightness'); + sg('HomeBridge.to_set', json_encode($payload)); + break; + case 'thermostat': + $payload['characteristic'] = 'CurrentTemperature'; + $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); + sg('HomeBridge.to_set',json_encode($payload)); + + $payload['characteristic'] = 'TargetTemperature'; + $payload['value']=gg($device1['LINKED_OBJECT'].'.currentTargetValue'); + sg('HomeBridge.to_set',json_encode($payload)); + $payload['characteristic'] = 'CurrentHeatingCoolingState'; //off = 0, heat = 1, and cool = 2, auto = 3 + if (!gg($device1['LINKED_OBJECT'].'.disabled')) { + if (gg($device1['LINKED_OBJECT'].'.status')) { + $payload['value']=1; + } else { + $payload['value']=2; + } + } else { + $payload['value']=0; + } + sg('HomeBridge.to_set',json_encode($payload)); + break; + /* + case 'sensor_battery': + $payload['service']='BatteryService'; + sg('HomeBridge.to_add',json_encode($payload)); + // Characteristic.BatteryLevel; + // Characteristic.ChargingState; 0 - NOT_CHARGING, 1 - CHARGING, 2 - NOT_CHARGEABLE + // Characteristic.StatusLowBattery; + $payload['characteristic'] = 'BatteryLevel'; + $payload['value']=gg($device1['LINKED_OBJECT'].'.value'); + sg('HomeBridge.to_set',json_encode($payload)); + + $payload['characteristic'] = 'ChargingState'; + $payload['value']=2; + sg('HomeBridge.to_set',json_encode($payload)); + + $payload['characteristic'] = 'StatusLowBattery'; + $payload['value']=gg($device1['LINKED_OBJECT'].'.normalValue') ? 0 : 1; + sg('HomeBridge.to_set',json_encode($payload)); + + break; + */ + } + if (isset($payload['value'])) { + //DebMes('HB sending to_set: '.json_encode($payload)); + sg('HomeBridge.to_set', json_encode($payload)); + } } -$value = (float)gg($device1['LINKED_OBJECT'].'.value'); -$status = (float)gg($device1['LINKED_OBJECT'].'.status'); +$value = (float)gg($device1['LINKED_OBJECT'] . '.value'); +$status = (float)gg($device1['LINKED_OBJECT'] . '.status'); -$links=SQLSelect("SELECT devices_linked.*, devices.LINKED_OBJECT FROM devices_linked LEFT JOIN devices ON devices_linked.DEVICE2_ID=devices.ID WHERE DEVICE1_ID=".(int)$device1['ID']); +$links = SQLSelect("SELECT devices_linked.*, devices.LINKED_OBJECT FROM devices_linked LEFT JOIN devices ON devices_linked.DEVICE2_ID=devices.ID WHERE DEVICE1_ID=" . (int)$device1['ID']); $total = count($links); for ($i = 0; $i < $total; $i++) { - $link_type=$links[$i]['LINK_TYPE']; - $object=$links[$i]['LINKED_OBJECT']; - $settings=unserialize($links[$i]['LINK_SETTINGS']); - $timer_name='linkTimer'.$links[$i]['ID']; - $action_string=''; + $link_type = $links[$i]['LINK_TYPE']; + $object = $links[$i]['LINKED_OBJECT']; + $settings = unserialize($links[$i]['LINK_SETTINGS']); + $timer_name = 'linkTimer' . $links[$i]['ID']; + $action_string = ''; // ----------------------------------------------------------------- - if ($link_type=='switch_it') { + if ($link_type == 'switch_it') { if ($settings['action_type'] == 'turnoff') { $action_string = 'callMethod("' . $object . '.turnOff' . '");'; } elseif ($settings['action_type'] == 'turnon') { @@ -128,77 +148,77 @@ if ((int)$settings['action_delay'] > 0) { $action_string = 'setTimeout(\'' . $timer_name . '\',\'' . $action_string . '\',' . (int)$settings['action_delay'] . ');'; } - } elseif ($link_type=='switch_timer') { - $timer_name=$object.'_switch_timer'; - $action_string=''; + } elseif ($link_type == 'switch_timer') { + $timer_name = $object . '_switch_timer'; + $action_string = ''; if ($settings['darktime']) { - $action_string.='if (gg("DarknessMode.active")) {'; + $action_string .= 'if (gg("DarknessMode.active")) {'; } - $action_string.= 'callMethod("' . $object . '.turnOn' . '");'; - $action_string.= 'setTimeout(\'' . $timer_name . '\',\'' . 'callMethod("' . $object . '.turnOff' . '");' . '\',' . (int)$settings['action_delay'] . ');'; + $action_string .= 'callMethod("' . $object . '.turnOn' . '");'; + $action_string .= 'setTimeout(\'' . $timer_name . '\',\'' . 'callMethod("' . $object . '.turnOff' . '");' . '\',' . (int)$settings['action_delay'] . ');'; if ($settings['darktime']) { - $action_string.='}'; + $action_string .= '}'; } - } elseif ($link_type=='set_color') { - $action_string='callMethod("'.$object.'.setColor'.'",array("color"=>"'.$settings['action_color'].'"));'; - if ((int)$settings['action_delay']>0) { - $action_string='setTimeout(\''.$timer_name.'\',\''.$action_string.'\','.(int)$settings['action_delay'].');'; - } - // ----------------------------------------------------------------- - // ----------------------------------------------------------------- - } elseif ($link_type=='sensor_switch') { - if ($settings['action_type']=='turnoff' && gg($object.'.status')) { - $action_string='callMethod("'.$object.'.turnOff'.'");'; - } elseif ($settings['action_type']=='turnon' && !gg($object.'.status')) { - $action_string='callMethod("'.$object.'.turnOn'.'");'; + } elseif ($link_type == 'set_color') { + $action_string = 'callMethod("' . $object . '.setColor' . '",array("color"=>"' . $settings['action_color'] . '"));'; + if ((int)$settings['action_delay'] > 0) { + $action_string = 'setTimeout(\'' . $timer_name . '\',\'' . $action_string . '\',' . (int)$settings['action_delay'] . ');'; + } + // ----------------------------------------------------------------- + // ----------------------------------------------------------------- + } elseif ($link_type == 'sensor_switch') { + if ($settings['action_type'] == 'turnoff' && gg($object . '.status')) { + $action_string = 'callMethod("' . $object . '.turnOff' . '");'; + } elseif ($settings['action_type'] == 'turnon' && !gg($object . '.status')) { + $action_string = 'callMethod("' . $object . '.turnOn' . '");'; } - if ($settings['condition_type']=='above' && $value>=(float)$settings['condition_value']) { + if ($settings['condition_type'] == 'above' && $value >= (float)$settings['condition_value']) { //do the action - } elseif ($settings['condition_type']=='below' && $value<(float)$settings['condition_value']) { + } elseif ($settings['condition_type'] == 'below' && $value < (float)$settings['condition_value']) { //do the action } else { //do nothing - $action_string=''; + $action_string = ''; } - } elseif ($link_type=='sensor_pass') { - $action_string='sg("'.$object.'.value'.'","'.$value.'");'; - } elseif ($link_type=='thermostat_switch') { - $set_value=0; - $current_relay_status = gg($device1['LINKED_OBJECT'].'.relay_status'); - $ncno = gg($device1['LINKED_OBJECT'].'.ncno'); + } elseif ($link_type == 'sensor_pass') { + $action_string = 'sg("' . $object . '.value' . '","' . $value . '");'; + } elseif ($link_type == 'thermostat_switch') { + $set_value = 0; + $current_relay_status = gg($device1['LINKED_OBJECT'] . '.relay_status'); + $ncno = gg($device1['LINKED_OBJECT'] . '.ncno'); if ($ncno == 'no' && $current_relay_status) { $current_relay_status = 0; } elseif ($ncno == 'no' && !$current_relay_status) { $current_relay_status = 1; } - $current_target_status = gg($object.'.status'); + $current_target_status = gg($object . '.status'); //echo "status: $current_relay_status / $current_target_status
"; if (!$settings['invert_status'] && $current_relay_status) { // NC - $set_value=1; + $set_value = 1; } elseif ($settings['invert_status'] && !$current_relay_status) { - $set_value=1; + $set_value = 1; } if ($set_value && !$current_target_status) { // turn on - $action_string='callMethod("'.$object.'.turnOn'.'");'; + $action_string = 'callMethod("' . $object . '.turnOn' . '");'; } elseif (!$set_value && $current_target_status) { // turn off - $action_string='callMethod("'.$object.'.turnOff'.'");'; + $action_string = 'callMethod("' . $object . '.turnOff' . '");'; } } - $addons_dir=DIR_MODULES.$this->name.'/addons'; + $addons_dir = DIR_MODULES . $this->name . '/addons'; if (is_dir($addons_dir)) { - $addon_files=scandir($addons_dir); - foreach($addon_files as $file) { - if (preg_match('/\_links_actions\.php$/',$file)) { - require($addons_dir.'/'.$file); + $addon_files = scandir($addons_dir); + foreach ($addon_files as $file) { + if (preg_match('/\_links_actions\.php$/', $file)) { + require($addons_dir . '/' . $file); } } } // ----------------------------------------------------------------- - if ($action_string!='') { + if ($action_string != '') { //DebMes("Action string: ".$action_string); try { $code = $action_string; @@ -207,7 +227,7 @@ registerError('linked_device', sprintf('Error in linked device code "%s". Code: %s', $link_type, $code)); } } catch (Exception $e) { - registerError('linked_device', sprintf('Error in script "%s": '.$e->getMessage(), $link_type)); + registerError('linked_device', sprintf('Error in script "%s": ' . $e->getMessage(), $link_type)); } } diff --git a/modules/devices/devices_search.inc.php b/modules/devices/devices_search.inc.php index 9b4785e87..860ef0ca1 100644 --- a/modules/devices/devices_search.inc.php +++ b/modules/devices/devices_search.inc.php @@ -94,7 +94,7 @@ }); $out['TYPES']=$types; -$locations=SQLSelect("SELECT ID, TITLE FROM locations ORDER BY TITLE"); +$locations=SQLSelect("SELECT ID, TITLE FROM locations ORDER BY TITLE+0"); $total = count($locations); for ($i = 0; $i < $total; $i++) { $tmp=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM devices WHERE LOCATION_ID='".$locations[$i]['ID']."'"); diff --git a/modules/devices/homebridgeSync.inc.php b/modules/devices/homebridgeSync.inc.php index 4c78702c6..1498b44d6 100644 --- a/modules/devices/homebridgeSync.inc.php +++ b/modules/devices/homebridgeSync.inc.php @@ -95,7 +95,7 @@ sg('HomeBridge.to_set',json_encode($payload)); break; case 'rgb': - DebMes('Sync '.$devices[$i]['TITLE'].' from MJD'); + //DebMes('Sync '.$devices[$i]['TITLE'].' from MJD'); $payload['service']='Lightbulb'; sg('HomeBridge.to_add',json_encode($payload)); @@ -118,6 +118,44 @@ $payload['characteristic'] = 'Brightness'; $payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.brightness'); sg('HomeBridge.to_set',json_encode($payload)); + break; + case 'thermostat': + $payload['service']='Thermostat'; + sg('HomeBridge.to_add',json_encode($payload)); + + $payload['characteristic'] = 'CurrentTemperature'; + $payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.value'); + sg('HomeBridge.to_set',json_encode($payload)); + + $payload['characteristic'] = 'TargetTemperature'; + $payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.currentTargetValue'); + sg('HomeBridge.to_set',json_encode($payload)); + + /* + $payload['characteristic'] = 'TemperatureDisplayUnits'; + $payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.currentTargetValue'); + sg('HomeBridge.to_set',json_encode($payload)); + */ + $payload['characteristic'] = 'CurrentHeatingCoolingState'; //off = 0, heat = 1, and cool = 2 + //$payload['value']=3; + if (!gg($devices[$i]['LINKED_OBJECT'].'.disabled')) { + if (gg($devices[$i]['LINKED_OBJECT'].'.status')) { + $payload['value']=1; + } else { + $payload['value']=2; + } + } else { + $payload['value']=0; + } + sg('HomeBridge.to_set',json_encode($payload)); + //TargetHeatingCoolingState + + + //CoolingThresholdTemperature + //HeatingThresholdTemperature + //Name + + break; /* case 'sensor_battery': diff --git a/modules/devices/processHomebridgeMQTT.inc.php b/modules/devices/processHomebridgeMQTT.inc.php index ebd04fb6d..414724c9e 100644 --- a/modules/devices/processHomebridgeMQTT.inc.php +++ b/modules/devices/processHomebridgeMQTT.inc.php @@ -239,6 +239,29 @@ } } } + if ($device['TYPE']=='thermostat') { + if ($data['characteristic']=='TargetTemperature') { + sg($device['LINKED_OBJECT'].'.currentTargetValue', $data['value']); + if (gg($device['LINKED_OBJECT'].'.status')) { + sg($device['LINKED_OBJECT'].'.normalTargetValue', $data['value']); + } else { + sg($device['LINKED_OBJECT'].'.ecoTargetValue', $data['value']); + } + } + if ($data['characteristic']=='TargetHeatingCoolingState') { + if ($data['value']==0) { // off + sg($device['LINKED_OBJECT'].'.disabled', 1); + } elseif ($data['value']==1) { // heat + sg($device['LINKED_OBJECT'].'.disabled', 0); + sg($device['LINKED_OBJECT'].'.status', 1); + } elseif ($data['value']==2) { // cool + sg($device['LINKED_OBJECT'].'.disabled', 0); + sg($device['LINKED_OBJECT'].'.status', 0); + } elseif ($data['value']==3) { // auto + sg($device['LINKED_OBJECT'].'.disabled', 0); + } + } + } } /* From ca72ae0574863fba147396a469284d1b4075ee03 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Mon, 21 Jan 2019 18:13:30 +0300 Subject: [PATCH 11/31] Update Rooms_updateActivityStatus.php Nobody home mode was not setting correct, fixed. --- modules/devices/Rooms_updateActivityStatus.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/devices/Rooms_updateActivityStatus.php b/modules/devices/Rooms_updateActivityStatus.php index 181b75581..0959fa78b 100644 --- a/modules/devices/Rooms_updateActivityStatus.php +++ b/modules/devices/Rooms_updateActivityStatus.php @@ -17,16 +17,12 @@ $rooms[$i]['diff'] = time() - $rooms[$i]['time']; } -if (!function_exists('cmpRoomsActivity')) { - function cmpRoomsActivity($a, $b) - { - if ($a['diff'] == $b['diff']) { - return 0; - } - return ($a['diff'] < $b['diff']) ? -1 : 1; +usort($rooms, function ($a,$b) { + if ($a['diff'] == $b['diff']) { + return 0; } -} -usort($rooms, "cmpRoomsActivity"); + return ($a['diff'] < $b['diff']) ? -1 : 1; +}); if (getGlobal('NobodyHomeMode.active')) { $somebodyHomeText = LANG_DEVICES_ROOMS_NOBODYHOME." ".LANG_DEVICES_ROOMS_ACTIVITY." " . date('H:i', $rooms[0]['time']) . " (" . $rooms[0]['room'] . ")"; From fb6c9d31f8dd9fb8b90f40e0254306ef5ffedd71 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Tue, 22 Jan 2019 14:16:26 +0200 Subject: [PATCH 12/31] =?UTF-8?q?=D0=A3=D1=81=D0=BA=D0=BE=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit После продолжительного времени не использования --- modules/app_player/libs/castv2/Chromecast.php | 163 +++--------------- 1 file changed, 26 insertions(+), 137 deletions(-) diff --git a/modules/app_player/libs/castv2/Chromecast.php b/modules/app_player/libs/castv2/Chromecast.php index 76cdbcf18..b08205034 100644 --- a/modules/app_player/libs/castv2/Chromecast.php +++ b/modules/app_player/libs/castv2/Chromecast.php @@ -38,8 +38,8 @@ public function __construct($ip, $port) // use port forwarding! $contextOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, ]]; $context = stream_context_create($contextOptions); - if ($this->socket = @stream_socket_client('ssl://' . $ip . ":" . $port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context)) { - stream_set_timeout($this->socket,5); + if ($this->socket = @stream_socket_client('ssl://' . $ip . ":" . $port, $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context)) { + stream_set_timeout($this->socket,0,64); } else { throw new Exception("Failed to connect to remote Chromecast"); @@ -291,23 +291,12 @@ function testLive() { //return; // If there is a difference of 10 seconds or more between $this->lastactivetime and the current time, then we've been kicked off and need to reconnect - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
TESTLIVE ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } if ($this->lastip == "") { return; } $diff = time() - $this->lastactivetime; if ($diff > 15) { // Reconnect - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
RECONNECT ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - exit; - flush(); - flush(); - } $contextOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, ]]; $context = stream_context_create($contextOptions); if ($this->socket = stream_socket_client('ssl://' . $this->lastip . ":" . $this->lastport, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context)) { @@ -323,19 +312,15 @@ function testLive() function cc_connect($tl = 0) { - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
CC Connect ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + // CONNECT TO CHROMECAST // This connects to the chromecast in general. // Generally this is called by launch($appid) automatically upon launching an app // but if you want to connect to an existing running application then call this first, // then call getStatus() to make sure you get a transportid. - if ($tl == 0) { - $this->testLive(); - }; + //if ($tl == 0) { + // $this->testLive(); + //}; $c = new CastMessage(); $c->source_id = "sender-0"; $c->receiver_id = "receiver-0"; @@ -351,11 +336,7 @@ public function launch($appid) { // Launches the chromecast app on the connected chromecast // CONNECT - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo 'Launching '.$appid.'
' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + $this->cc_connect(); $this->getStatus(); // LAUNCH @@ -365,53 +346,31 @@ public function launch($appid) $c->urnnamespace = "urn:x-cast:com.google.cast.receiver"; $c->payloadtype = 0; $c->payloadutf8 = '{"type":"LAUNCH","appId":"' . $appid . '","requestId":' . $this->requestId . '}'; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
Sending launch: ' .$c->payloadutf8 . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + fwrite($this->socket, $c->encode()); fflush($this->socket); $this->lastactivetime = time(); $this->requestId++; $oldtransportid = $this->transportid; while ($this->transportid == "" || $this->transportid == $oldtransportid) { - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
Incorrect transport id '.$this->transportid.' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } $r = $this->getCastMessage(); - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
New castmessage '.$r.' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - sleep(1); + usleep(10); } } function getStatus() { - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
GETTING STATUS ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + // Get the status of the chromecast in general and return it // also fills in the transportId of any currently running app - $this->testLive(); + //$this->testLive(); $c = new CastMessage(); $c->source_id = "sender-0"; $c->receiver_id = "receiver-0"; $c->urnnamespace = "urn:x-cast:com.google.cast.receiver"; $c->payloadtype = 0; $c->payloadutf8 = '{"type":"GET_STATUS","requestId":' . $this->requestId . '}'; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
SENDING REQUEST '. $c->payloadutf8 . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + $c = fwrite($this->socket, $c->encode()); fflush($this->socket); $this->lastactivetime = time(); @@ -422,12 +381,9 @@ function getStatus() while ($this->transportid == "" && (time()-$wait_transport_started)<=$wait_transport) { //echo '
Waiting transport ID '.__FILE__.' ' .__LINE__.str_repeat(' ',2048);flush();flush(); $r = $this->getCastMessage(); + usleep(10); } - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
STATUS ' . $r . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + return $r; } @@ -435,9 +391,9 @@ function connect($tl = 0) { // This connects to the transport of the currently running app // (you need to have launched it yourself or connected and got the status) - if ($tl == 0) { - $this->testLive(); - }; + //if ($tl == 0) { + // $this->testLive(); + //}; $c = new CastMessage(); $c->source_id = "sender-0"; $c->receiver_id = $this->transportid; @@ -445,12 +401,6 @@ function connect($tl = 0) $c->payloadtype = 0; $c->payloadutf8 = '{"type":"CONNECT"}'; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
connect: ' . $c->payloadutf8 . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - fwrite($this->socket, $c->encode()); fflush($this->socket); $this->lastactivetime = time(); @@ -463,82 +413,33 @@ public function getCastMessage() // Later on we could update CCprotoBuf to decode this // but for now all we need is the transport id and session id if it is // in the packet and we can read that directly. - /* - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
getCastMessage ' . $message . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - */ - $this->testLive(); - /* - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
getCastMessage reading' . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - */ + //$this->testLive(); + $response = fread($this->socket, 2000); - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
msgresponse ' . $response . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } while (preg_match("/urn:x-cast:com.google.cast.tp.heartbeat/", $response) && preg_match("/\"PING\"/", $response)) { $this->pong(); //$this->getCastMessage(); - sleep(3); + usleep(10); $response = fread($this->socket, 2000); - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
msgresponse ' . $response . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + // Wait infinitely for a packet. //set_time_limit(30); } - /* - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
RESPONSE ' . $response . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - */ + if (preg_match("/transportId/s", $response)) { preg_match("/transportId\"\:\"([^\"]*)/", $response, $matches); $matches = $matches[1]; $this->transportid = $matches; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
Transport id set to ' . $this->transportid . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - } - /* - if (preg_match("/sessionId/s", $response)) { - preg_match("/\"sessionId\"\:\"([^\"]*)/", $response, $r); - $this->sessionid = $r[1]; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
Session id set to ' . $this->sessionid . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - } - */ if (preg_match("/mediaSessionId/s", $response)) { preg_match("/\"mediaSessionId\"\:(\d+)/", $response, $r); $this->sessionid = $r[1]; - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
Media Session id set to ' . $this->sessionid . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } + } return $response; } @@ -546,12 +447,8 @@ public function getCastMessage() public function sendMessage($urn, $message) { // Send the given message to the given urn - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
SENDING MESSAGE ' . $message . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - $this->testLive(); + + //$this->testLive(); $c = new CastMessage(); $c->source_id = "sender-0"; $c->receiver_id = $this->transportid; @@ -601,18 +498,10 @@ public function pong() $c->urnnamespace = "urn:x-cast:com.google.cast.tp.heartbeat"; $c->payloadtype = 0; $c->payloadutf8 = '{"type":"PONG"}'; - - if (Defined('CHROMECAST_DEBUG') && CHROMECAST_DEBUG) { - echo '
PONG ' . $c->payloadutf8 . ' ' . __FILE__ . ' ' . __LINE__ .' '. __METHOD__. str_repeat(' ', 2048); - flush(); - flush(); - } - - fwrite($this->socket, $c->encode()); fflush($this->socket); $this->lastactivetime = time(); $this->requestId++; } } -?> \ No newline at end of file +?> From 43ab2a107bfb47edcb78f2573c0c852a230af4c9 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Wed, 23 Jan 2019 07:46:37 +0200 Subject: [PATCH 13/31] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B2=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/devices/SCameras_motionDetected.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/devices/SCameras_motionDetected.php b/modules/devices/SCameras_motionDetected.php index 3e672d853..04042dc66 100644 --- a/modules/devices/SCameras_motionDetected.php +++ b/modules/devices/SCameras_motionDetected.php @@ -1,11 +1,2 @@ object_title; - -$this->setProperty('status', 1); -$this->setProperty('activeHTML', $this->getProperty('previewHTML')); - -$motion_timeout=20; // seconds timeout -setTimeout($ot.'_motion_timer', 'setGlobal("'.$ot.'.status", 0);setGlobal("'.$ot.'.activeHTML", \'\');', $motion_timeout); - -$this->callMethodSafe('logicAction'); +require(DIR_MODULES.'devices/SMotions_motionDetected.php'); From d993951aad2c877d0622bc3b4002dbcf999bb82a Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Wed, 23 Jan 2019 07:48:59 +0200 Subject: [PATCH 14/31] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D1=8B=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BA=D0=B0=D0=BC=D0=B5=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/devices/devices_structure.inc.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/devices/devices_structure.inc.php b/modules/devices/devices_structure.inc.php index a24f7b140..fc1152ec4 100644 --- a/modules/devices/devices_structure.inc.php +++ b/modules/devices/devices_structure.inc.php @@ -176,6 +176,8 @@ 'snapshotPreviewURL'=>array('DESCRIPTION'=>'Snapshot Preview URL'), 'previewHTML'=>array('DESCRIPTION'=>'Preview HTML',), 'activeHTML'=>array('DESCRIPTION'=>'Active HTML',), + 'ignoreNobodysHome'=>array('DESCRIPTION'=>LANG_DEVICES_MOTION_IGNORE,'_CONFIG_TYPE'=>'yesno','_CONFIG_HELP'=>'SdIgnoreNobodysHome'), + 'timeout'=>array('DESCRIPTION'=>LANG_DEVICES_MOTION_TIMEOUT,'_CONFIG_TYPE'=>'num','_CONFIG_HELP'=>'SdMotionTimeout') ), 'METHODS'=>array( 'motionDetected'=>array('DESCRIPTION'=>'Motion Detected'), From 6206ea7ea4e66e625d4ba621b689899273332307 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Wed, 23 Jan 2019 07:53:52 +0200 Subject: [PATCH 15/31] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=BC=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D1=83=D1=81=D1=82=D1=80=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/devices/devices_structure_links.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/devices/devices_structure_links.inc.php b/modules/devices/devices_structure_links.inc.php index 7edac47de..1e6f047a8 100644 --- a/modules/devices/devices_structure_links.inc.php +++ b/modules/devices/devices_structure_links.inc.php @@ -1,7 +1,7 @@ device_links=array( - 'SMotions,SButtons,SOpenClose'=>array( + 'SMotions,SButtons,SOpenClose,SCameras'=>array( array( 'LINK_NAME'=>'switch_timer', 'LINK_TITLE'=>LANG_DEVICES_LINK_SWITCH_TIMER, @@ -134,4 +134,4 @@ require($addons_dir.'/'.$file); } } -} \ No newline at end of file +} From 179d7708443e76f749d1eaf54dd0c8d3aa311af7 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Wed, 23 Jan 2019 10:34:00 +0200 Subject: [PATCH 16/31] Add icon for Optimiser --- img/modules/optimizer.png | Bin 0 -> 3531 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 img/modules/optimizer.png diff --git a/img/modules/optimizer.png b/img/modules/optimizer.png new file mode 100644 index 0000000000000000000000000000000000000000..c7a5f23612c98fbfb5fae69719cef9e1fbcc0717 GIT binary patch literal 3531 zcmW+(dpy(KAOFtQES5`4EcLi_QJd&y6NV! z(i2jRsEeh>ZHmnCwc~*0{~6TQiA~{r3R`=M2yQ{E&%ZST9W+WP1V@=xaXn2 z0N~dBnLZM71d;9k7t5;e(KnkbC#;Ra88>e*Jo2 zIS5Kz5)u**7tRzH7iVQ=K7Rbz@8)=Na&k^~j`i7AaC%REem?$|$i>BF@t0HZo%y~G zJ4SkU{T_9sQd0yUckI75?pGou5C}c*Z06(RiA3U-xc9r_-+lM@Ur0!>jINE3j~@&O z_%*P5;Cr9)%xUqELkH7Rap}^x-p`WQ*umYqg`pwbj<$UlTO*GjSNixUj~(;!^0G?o z!KZe%9`f6lC75z|-xU3NEF$8wuP?*f+n)MENuem?RKX>B9 zR7^~}hevVVMle17)Ia|)aJUhFe;lc2CNvb9cec+OudCXo39q0{?~ZJgFHyS zH|xLY;+OqlnJm`LoBf}2o(Bg@Yihvz_uK>i{r<<=$SNg&Y&Nn&vM@4||A_hf`}h7& zaSGIO9-DnQvGP;*<7Q^|qL|3~H0Bz0CybcGJ$aJbe3<{)cX6K0d-7zKM!S$z_M@ms zHkV!9^dqulptvBORp${`yZD>Q*l4z`oHHYnetG(`sjZ$qK2oEQK6;#%nrmp7Q1y$~ z%bBRH-Lm)0i^|BGp`kgM-ih%C^8d8$99n3ts8|#SZ_SYjN4xpq*s9w(>_+0hr&pJp zKi_+GgASgy$I)rFWV4d_ry>k{ED$TExPTz2N`4LB{~iE<#tttx7yrcmh_G@U0HL!y zQ#S*zVxaYnuoSVwLmGNg3f@PlA#`kKwD2pVE^!rdjL>&gI0cAc-`|@_o09sL8RDxK z4Og=tk+C4?dU%7n~@#T)KJE&;6=DB z=3u+JBndMh|)62$2G z=<8(T;K?m{MRUU(hfFJHz@$;IqwSJ{Yqd_%ML`G;_!P})XCyeQqo{p3=-#{c09e{7 z7Vec%mpw$foUYbgPiPuITiNZA%R&$a^w?u5_OX0uFdYR)=Q{7 z`WU;K?hwySw-<6<0zLEmWN7%_`4!RCoc)$X4K&83-vN_O_=~OApH(vRMSv2}acQi5fdse?`L>a;mBnx;i~7=SW< zaLde8GO7&dtdYFP#Tq0JOf;-5?jzek7v6IcE)JR_UqN-nMMZ%OE8^md>TM-6!w*v+ zH`4iXDWHZbIcWgdKIQu<=k$sai^z&8CzkYYxLuDOawl?>?;1x&lrdi?rMl#dlyTw6 zIGk$hDc^Sux28n!eaS^DLIbc>kPU`}G&7dr5HY z=`6Uh*`fTB>57{EVj7`Q)XEc~(a)w{`unQr;D`pVn!Ohj+aTrWx9YRD99gbam(dEF_8)PwmV%iecYPi)Zbs${A)yI+d6Tk?&@`yEf-xYcB?iX(vx`88Pc zpbcf3N5g4xL(Cce#LW#wM@d_s@Ri)ohdS+0sd6<&)9#y($@5ES0EWtUw_A0M86#GEw|%0-_8As}w0M%J z@A^J&zhEe1_sj#OK`jtN|Ho{|zOh#M0}dKv;YzcnFYMGXBr+D1@(rFJWX+C*30wzx zkZh{40)|qh6@QstuYTxNCg9eNn>bdbz4oBzcT^)g-duRLV zaPl8Hy9;fRZNcOz)Q_l_J~F`GxK*t|SXh+LIy#AT#}KYLrUF-< zsfVb@!mt*zb7p4xARI}-Y=!v?NWO!tXSZqOxFkp>)HVZMe1IpQwo1s+h1hGN)K%Rn zLwqc#Jf8TThzPW&CniT?{TYHEY$hKGL))CCha%J0K$hnVaQq-FsHSO#r2j#;1XbdTF>~6RG+QXw zw?cs+2Jt%Q`b<}ch)IH(>lGN~xyh#>sHUkBJ%m2-#X)r}>bVwj-a3})khIPc2k!m! zXrWP?OoF15q$>l{t!+}8B;RXdhL{9Utr&;{>N#-Lc?4@=TW(Rm%;E(0iW%w?@J^(4RcPchaq%&$as9p3K@!PYPrmL+j1QpZGFY8=%F;mjd5Jwxo}{p zG1LAjOr`E=c;FN@6W*-hp9^RAeyE|O+zwiHm#WmC#G4~C0v;n(8iFag%AhO5(~G26 zVW)ayjitD6S>+ahMXuGy|RKTWSr!KwE0!m|pODInEil>ppzoajA|@${S;p=20YmQv^x<3uuI- zXf0a`htYheeOrf8?~_JymQ@PuM*FVox1*NCA*~>f2mirknK!ddQ0=z#%C2o4#x2}7 zR`$sih$V<_(CqJ?0Tq|?$A#p~3j&gwrY25G$kS}0YIUVwW(firEm-mrTg8-2(^M7E-X(Im+r+e0_(3MCCDG!HT{ zaXX7Z8N02YSl3DuiS}62kHVuHa}}ap=U*^J6cu3l)yp${f~Uz$q3#WrT?pJca)Eyt!;}rSDG^W2+Kr57djis)7IyRZ)9Dw`B0&_j!X{XDfCJ2 zl|sA9gDU1(WST7tC~-v(IIEbv*-RqW8m^6D?JpP+Nky!)8O2kU!&1n#juCfu;D|sm zqgCJlsAcMUXdleHy{z94SYs}c3)RCL3~9@LHh_deCaX2U=z7D_8UhY8`A44Z1tt>{ z4z{s6XQV4qb%a7(uI>^ry6b%16N5AC$8h^cktpLEuNi{ib$_igrkJ?{FgI(}%k7G; cGX(~`{+A;E!=*G^_3;9{_W8I~yN0Fw4@$fFF#rGn literal 0 HcmV?d00001 From 18395898e135b74c4dde761b47f67ad7b075082a Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Fri, 25 Jan 2019 20:46:31 +0300 Subject: [PATCH 17/31] Updates * Simple Devices: Theromstat linked relay turnon/off fixed * Link to Panel from APPs screen --- modules/application.class.php | 4 +- modules/apps.php | 78 +++++++++++++------------ modules/devices/Rooms_onActivity.php | 3 +- modules/devices/devices.class.php | 4 +- templates/locations/locations_edit.html | 2 +- 5 files changed, 48 insertions(+), 43 deletions(-) diff --git a/modules/application.class.php b/modules/application.class.php index 087e4b9cd..f38ed9629 100644 --- a/modules/application.class.php +++ b/modules/application.class.php @@ -190,7 +190,10 @@ function sortFiles($a, $b) { if ($this->app_action) { $out['APP_ACTION']=1; } + } + if ($this->app_action=='panel') { + $this->redirect(ROOTHTML.'admin.php'); } @@ -281,7 +284,6 @@ function sortFiles($a, $b) { Define('USER_AVATAR', ''); } - if ($out["DOC_NAME"]) { //$doc=SQLSelectOne("SELECT ID FROM cms_docs WHERE NAME LIKE '".DBSafe($out['DOC_NAME'])."'"); if ($doc['ID']) { diff --git a/modules/apps.php b/modules/apps.php index f39daebdb..07f89b41f 100644 --- a/modules/apps.php +++ b/modules/apps.php @@ -2,55 +2,59 @@ if ($this->app_action) { - $out['APP_ACTION']=$this->app_action; - $rec=SQLSelectOne("SELECT * FROM project_modules WHERE NAME LIKE '".DBSafe($this->app_action)."'"); + $out['APP_ACTION'] = $this->app_action; + $rec = SQLSelectOne("SELECT * FROM project_modules WHERE NAME LIKE '" . DBSafe($this->app_action) . "'"); if ($rec['ID']) { - $out['APP_TITLE']=$rec['TITLE']; - if ($this->app_action=='devices') { - $out['APP_TITLE']=''; + $out['APP_TITLE'] = $rec['TITLE']; + if ($this->app_action == 'devices') { + $out['APP_TITLE'] = ''; } } } else { -$files=scandir(DIR_MODULES,0); -$total = count($files); -$apps=array(); -for ($i = 0; $i < $total; $i++) { - if ($files[$i]=='.' || $files[$i]=='..' || !is_dir(DIR_MODULES.$files[$i])) continue; - if (file_exists(DIR_MODULES.$files[$i].'/app')) { - //echo $files[$i]."!
"; - $apps[]=$files[$i]; - } else { - //echo $files[$i]."
"; + $files = scandir(DIR_MODULES, 0); + $total = count($files); + $apps = array(); + for ($i = 0; $i < $total; $i++) { + if ($files[$i] == '.' || $files[$i] == '..' || !is_dir(DIR_MODULES . $files[$i])) continue; + if (file_exists(DIR_MODULES . $files[$i] . '/app')) { + //echo $files[$i]."!
"; + $apps[] = $files[$i]; + } else { + //echo $files[$i]."
"; + } } -} -$project_modules=SQLSelect("SELECT * FROM project_modules"); -$modules=array(); -foreach($project_modules as $k=>$v) { - $modules[$v['NAME']]=$v; -} + $apps[]='panel'; -$res=array(); -$total = count($apps); -for ($i = 0; $i < $total; $i++) { - $rec=array(); - $rec['NAME']=$apps[$i]; - if (isset($modules[$rec['NAME']])) { - $rec['TITLE']=$modules[$rec['NAME']]['TITLE']; - } else { - $rec['TITLE']=$rec['NAME']; + $project_modules = SQLSelect("SELECT * FROM project_modules"); + $modules = array(); + foreach ($project_modules as $k => $v) { + $modules[$v['NAME']] = $v; } - if (file_exists(ROOT.'img/modules/'.$rec['NAME'].'.png')) { - $rec['ICON']=$rec['NAME'].'.png'; - } else { - $rec['ICON']='default.png'; + + $res = array(); + $total = count($apps); + for ($i = 0; $i < $total; $i++) { + $rec = array(); + $rec['NAME'] = $apps[$i]; + if (isset($modules[$rec['NAME']])) { + $rec['TITLE'] = $modules[$rec['NAME']]['TITLE']; + } elseif ($rec['NAME']=='panel') { + $rec['TITLE'] = LANG_CONTROL_PANEL; + } else { + $rec['TITLE'] = $rec['NAME']; + } + if (file_exists(ROOT . 'img/modules/' . $rec['NAME'] . '.png')) { + $rec['ICON'] = $rec['NAME'] . '.png'; + } else { + $rec['ICON'] = 'default.png'; + } + $res[] = $rec; } - $res[]=$rec; -} -$out['APPS']=$res; + $out['APPS'] = $res; } diff --git a/modules/devices/Rooms_onActivity.php b/modules/devices/Rooms_onActivity.php index 0042c6bfb..5b0189341 100644 --- a/modules/devices/Rooms_onActivity.php +++ b/modules/devices/Rooms_onActivity.php @@ -10,6 +10,7 @@ if (!$this->getProperty('SomebodyHere')) { $this->setProperty('SomebodyHere',1); + $this->callMethod("updateActivityStatus"); } if ($this->getProperty("IdleDelay")) { @@ -20,8 +21,6 @@ clearTimeOut($ot."_activity_timeout"); setTimeOut($ot."_activity_timeout","callMethod('".$ot.".onIdle');",$activity_timeout); -$this->callMethod("updateActivityStatus"); - if (getGlobal('NobodyHomeMode.active')) { callMethod('NobodyHomeMode.deactivate',array('sensor'=>$params['sensor'],'room'=>$ot)); } diff --git a/modules/devices/devices.class.php b/modules/devices/devices.class.php index ce015c180..f6d650cb8 100644 --- a/modules/devices/devices.class.php +++ b/modules/devices/devices.class.php @@ -719,7 +719,7 @@ function usual(&$out) $out['DEVICES'] = $devices; } - $locations = SQLSelect("SELECT ID, TITLE FROM locations ORDER BY PRIORITY DESC, TITLE"); + $locations = SQLSelect("SELECT ID, TITLE FROM locations ORDER BY PRIORITY DESC, TITLE+0"); $total_devices = count($devices); if ($total_devices) { $favorite_devices = array(); @@ -1269,7 +1269,7 @@ function checkLinkedDevicesAction($object_title, $value = 0) if (!$device1['ID']) { return 0; } - include_once(DIR_MODULES . 'devices/devices_links_actions.inc.php'); + require (DIR_MODULES . 'devices/devices_links_actions.inc.php'); return 1; } diff --git a/templates/locations/locations_edit.html b/templates/locations/locations_edit.html index 60c385a05..ea7e8e905 100644 --- a/templates/locations/locations_edit.html +++ b/templates/locations/locations_edit.html @@ -31,7 +31,7 @@
-
+
From 6a0309965aaa92a2a0ee3e6b1f9f2c80d11a4d52 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Tue, 29 Jan 2019 07:52:46 +0200 Subject: [PATCH 18/31] Update terminals.class.php --- modules/terminals/terminals.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/terminals/terminals.class.php b/modules/terminals/terminals.class.php index d11740d9c..10454fa76 100644 --- a/modules/terminals/terminals.class.php +++ b/modules/terminals/terminals.class.php @@ -390,7 +390,7 @@ function terminalSayByCacheQueue($target, $levelMes, $cached_filename, $ph) { if (!$chek_restore ) { $played = getPlayerStatus($target['NAME']); if (($played['state']=='playing') and (stristr($played['file'], 'cms\cached\voice') === FALSE)) { - addScheduledJob('allsay-target-'.$target['TITLE'].'-number-99999999998', "playMedia('".$played['file']."', '".$target['TITLE']."',1);", time()+100, 3); + addScheduledJob('allsay-target-'.$target['TITLE'].'-number-99999999998', "playMedia('".$played['file']."', '".$target['TITLE']."',1);", time()+100, 4); addScheduledJob('allsay-target-'.$target['TITLE'].'-number-99999999999', "seekPlayerPosition('".$target['TITLE']."',".$played['time'].");", time()+110, 4); } } From 9d7e65c2b62176b10a5532f76431fb42b795eb87 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Wed, 30 Jan 2019 09:46:08 +0300 Subject: [PATCH 19/31] Fixes * Minor bug-fixing --- index.php | 9 +++++---- lib/session.class.php | 2 +- lib/utils/postprocess_result.inc.php | 2 +- modules/application.class.php | 14 +++++++++----- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index b9f5c2562..48dc06a82 100644 --- a/index.php +++ b/index.php @@ -97,12 +97,13 @@ function echobig($string, $bufferSize = 8192) startMeasure('final_echo'); -if (!headers_sent()) -{ +if (!headers_sent()) { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); - header('Access-Control-Allow-Origin: *'); - if(!ob_start("ob_gzhandler")) ob_start(); + header('Access-Control-Allow-Origin: *'); + if (!ob_get_length()) { + if(!ob_start("ob_gzhandler")) ob_start(); + } } echobig($result); diff --git a/lib/session.class.php b/lib/session.class.php index 1c641929b..9c3517204 100644 --- a/lib/session.class.php +++ b/lib/session.class.php @@ -39,7 +39,7 @@ public function __construct($name) { $this->name = $name; - if ($_GET['no_session']) return false; + if (isset($_GET['no_session'])) return false; ini_set('session.use_only_cookies', '0'); //not only cookies diff --git a/lib/utils/postprocess_result.inc.php b/lib/utils/postprocess_result.inc.php index 75a4de409..9574761e1 100644 --- a/lib/utils/postprocess_result.inc.php +++ b/lib/utils/postprocess_result.inc.php @@ -18,7 +18,7 @@ // END: begincut endcut placecut // BEGIN: filter output -if ($filterblock != '') +if (isset($filterblock) && $filterblock != '') { $matchPattern = '/(.*?)/is'; preg_match($matchPattern, $result, $match); diff --git a/modules/application.class.php b/modules/application.class.php index f38ed9629..3111ee53c 100644 --- a/modules/application.class.php +++ b/modules/application.class.php @@ -22,15 +22,19 @@ function __construct() { function saveParams($data = 1) { $p=array(); - $p["action"]=$this->action; - $p['doc_name']=$this->doc_name; - if ($this->ajax) { + if (isset($this->action) && $this->action) { + $p["action"]=$this->action; + } + if (isset($this->doc_name) && $this->doc_name) { + $p['doc_name']=$this->doc_name; + } + if (isset($this->ajax) && $this->ajax) { $p['ajax']=$this->ajax; } - if ($this->popup) { + if (isset($this->popup) && $this->popup) { $p['popup']=$this->popup; } - if ($this->app_action) { + if (isset($this->app_action) && $this->app_action) { $p['app_action']=$this->app_action; } return parent::saveParams($p); From dde85aa0126d06ac863210492f83f1edc4378171 Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Thu, 31 Jan 2019 16:39:38 +0300 Subject: [PATCH 20/31] Minor updates * Simple Devices: List similar devices in Control Panel (edit device mode) --- modules/devices/SDevices_statusUpdated.php | 5 ----- modules/devices/devices_edit.inc.php | 5 +++++ modules/devices/devices_links_actions.inc.php | 2 +- templates/devices/action_admin.html | 9 +++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/devices/SDevices_statusUpdated.php b/modules/devices/SDevices_statusUpdated.php index 547ddc405..1d21561c6 100644 --- a/modules/devices/SDevices_statusUpdated.php +++ b/modules/devices/SDevices_statusUpdated.php @@ -43,11 +43,6 @@ } if ($need_call_logic_action) { - /* - if ($this->class_title == 'SRelays') { - DebMes($this->object_title.' '.$params['NEW_VALUE'],'logic_test'); - } - */ $this->callMethod('logicAction'); include_once(DIR_MODULES . 'devices/devices.class.php'); $dv = new devices(); diff --git a/modules/devices/devices_edit.inc.php b/modules/devices/devices_edit.inc.php index 88813d2ad..134ab4f5b 100644 --- a/modules/devices/devices_edit.inc.php +++ b/modules/devices/devices_edit.inc.php @@ -424,4 +424,9 @@ $out['LOCATION_TITLE']=processTitle($location_rec['TITLE']); $other_devices=SQLSelect("SELECT ID, TITLE FROM devices WHERE LOCATION_ID=".(int)$rec['LOCATION_ID']); $out['OTHER_DEVICES']=$other_devices; +} + +if ($rec['TYPE']) { + $other_devices_type=SQLSelect("SELECT ID, TITLE FROM devices WHERE TYPE='".$rec['TYPE']."'"); + $out['OTHER_DEVICES_TYPE']=$other_devices_type; } \ No newline at end of file diff --git a/modules/devices/devices_links_actions.inc.php b/modules/devices/devices_links_actions.inc.php index 0593bb128..6f6f369e7 100644 --- a/modules/devices/devices_links_actions.inc.php +++ b/modules/devices/devices_links_actions.inc.php @@ -219,7 +219,7 @@ // ----------------------------------------------------------------- if ($action_string != '') { - //DebMes("Action string: ".$action_string); + //DebMes("Action string: ".$action_string,'logic_test'); try { $code = $action_string; $success = eval($code); diff --git a/templates/devices/action_admin.html b/templates/devices/action_admin.html index 380b9f6b8..2eed629e8 100644 --- a/templates/devices/action_admin.html +++ b/templates/devices/action_admin.html @@ -104,12 +104,21 @@ [#endif SHOW_METHODS#] [#if OTHER_DEVICES#] +

[#LOCATION_TITLE#]

[#begin OTHER_DEVICES#]
[#end OTHER_DEVICES#] [#endif#] + [#if OTHER_DEVICES_TYPE#] +
+

[#TYPE#]

+ [#begin OTHER_DEVICES_TYPE#] +
[#if ID!="<#ID#>"#][#else#][#endif#][#TITLE#]
+ [#end OTHER_DEVICES_TYPE#] + [#endif#] +
[#endif#]
From 384855ae22543e7337ae601a773c7f340ea75471 Mon Sep 17 00:00:00 2001 From: olehs Date: Thu, 7 Feb 2019 23:08:37 +0200 Subject: [PATCH 21/31] fixed Navbar overlapped Left Menu see http://majordomo.smartliving.ru/forum/viewtopic.php?f=7&t=1871&start=1340#p96266 --- templates/panel.html | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/templates/panel.html b/templates/panel.html index 21847c8a8..954c05edd 100644 --- a/templates/panel.html +++ b/templates/panel.html @@ -424,7 +424,7 @@ -
[#TITLE#] + [#DEVICE1_TITLE#] + → + [#TITLE#] + [#if COMMENT!=""#][#COMMENT#]
[#endif#] [#LINK_TYPE#] ([#LINK_SETTINGS#])
- - + +
{$position}: {$line_abbr} 0, {$char_abbr} 0 {$total}: {$line_abbr} 0, {$char_abbr} 0 resize
{$processing}
{$search} {$close_popup}
{$replace} {$move_popup}

{$find_next} {$replace} {$replace_all}
{$close_popup}

Editarea [__EA_VERSION__]


{$shortcuts}:

{$tab}: {$add_tab}
{$shift}+{$tab}: {$remove_tab}
{$ctrl}+f: {$search_command}
{$ctrl}+r: {$replace_command}
{$ctrl}+h: {$highlight}
{$ctrl}+g: {$go_to_line}
{$ctrl}+z: {$undo}
{$ctrl}+y: {$redo}
{$ctrl}+e: {$help}
{$ctrl}+q, {$esc}: {$close_popup}
{$accesskey} E: {$toggle}

{$about_notice}
"; -editAreaLoader.iframe_css= ""; diff --git a/js/edit_area/edit_area_functions.js b/js/edit_area/edit_area_functions.js deleted file mode 100644 index 4067b03a0..000000000 --- a/js/edit_area/edit_area_functions.js +++ /dev/null @@ -1,1202 +0,0 @@ - //replace tabulation by the good number of white spaces - EditArea.prototype.replace_tab= function(text){ - return text.replace(/((\n?)([^\t\n]*)\t)/gi, editArea.smartTab); // slower than simple replace... - }; - - // call by the replace_tab function - EditArea.prototype.smartTab= function(){ - val=" "; - return EditArea.prototype.smartTab.arguments[2] + EditArea.prototype.smartTab.arguments[3] + val.substr(0, editArea.tab_nb_char - (EditArea.prototype.smartTab.arguments[3].length)%editArea.tab_nb_char); - }; - - EditArea.prototype.show_waiting_screen= function(){ - width = this.editor_area.offsetWidth; - height = this.editor_area.offsetHeight; - if( !(this.isIE && this.isIE<6) ) - { - width -= 2; - height -= 2; - } - this.processing_screen.style.display= "block"; - this.processing_screen.style.width = width+"px"; - this.processing_screen.style.height = height+"px"; - this.waiting_screen_displayed = true; - }; - - EditArea.prototype.hide_waiting_screen= function(){ - this.processing_screen.style.display="none"; - this.waiting_screen_displayed= false; - }; - - EditArea.prototype.add_style= function(styles){ - if(styles.length>0){ - newcss = document.createElement("style"); - newcss.type="text/css"; - newcss.media="all"; - if(newcss.styleSheet){ // IE - newcss.styleSheet.cssText = styles; - } else { // W3C - newcss.appendChild(document.createTextNode(styles)); - } - document.getElementsByTagName("head")[0].appendChild(newcss); - } - }; - - EditArea.prototype.set_font= function(family, size){ - var t=this, a=this.textarea, s=this.settings, elem_font, i, elem; - // list all elements concerned by font changes - var elems= ["textarea", "content_highlight", "cursor_pos", "end_bracket", "selection_field", "selection_field_text", "line_number"]; - - if(family && family!="") - s["font_family"]= family; - if(size && size>0) - s["font_size"] = size; - if( t.isOpera && t.isOpera < 9.6 ) // opera<9.6 can't manage non monospace font - s['font_family']="monospace"; - - // update the select tag - if( elem_font = _$("area_font_size") ) - { - for( i = 0; i < elem_font.length; i++ ) - { - if( elem_font.options[i].value && elem_font.options[i].value == s["font_size"] ) - elem_font.options[i].selected=true; - } - } - - /* - * somethimes firefox has rendering mistake with non-monospace font for text width in textarea vs in div for changing font size (eg: verdana change between 11pt to 12pt) - * => looks like a browser internal random bug as text width can change while content_highlight is updated - * we'll check if the font-size produce the same text width inside textarea and div and if not, we'll increment the font-size - * - * This is an ugly fix - */ - if( t.isFirefox ) - { - var nbTry = 3; - do { - var div1 = document.createElement( 'div' ), text1 = document.createElement( 'textarea' ); - var styles = { - width: '40px', - overflow: 'scroll', - zIndex: 50, - visibility: 'hidden', - fontFamily: s["font_family"], - fontSize: s["font_size"]+"pt", - lineHeight: t.lineHeight+"px", - padding: '0', - margin: '0', - border: 'none', - whiteSpace: 'nowrap' - }; - var diff, changed = false; - for( i in styles ) - { - div1.style[ i ] = styles[i]; - text1.style[ i ] = styles[i]; - } - // no wrap for this text - text1.wrap = 'off'; - text1.setAttribute('wrap', 'off'); - t.container.appendChild( div1 ); - t.container.appendChild( text1 ); - // try to make FF to bug - div1.innerHTML = text1.value = 'azertyuiopqsdfghjklm'; - div1.innerHTML = text1.value = text1.value+'wxcvbn^p*ù$!:;,,'; - diff = text1.scrollWidth - div1.scrollWidth; - - // firefox return here a diff of 1 px between equals scrollWidth (can't explain) - if( Math.abs( diff ) >= 2 ) - { - s["font_size"]++; - changed = true; - } - t.container.removeChild( div1 ); - t.container.removeChild( text1 ); - nbTry--; - }while( changed && nbTry > 0 ); - } - - - // calc line height - elem = t.test_font_size; - elem.style.fontFamily = ""+s["font_family"]; - elem.style.fontSize = s["font_size"]+"pt"; - elem.innerHTML = "0"; - t.lineHeight = elem.offsetHeight; - - // update font for all concerned elements - for( i=0; i tags - t.add_style("pre{font-family:"+s["font_family"]+"}"); - - // old opera and IE>=8 doesn't update font changes to the textarea - if( ( t.isOpera && t.isOpera < 9.6 ) || t.isIE >= 8 ) - { - var parNod = a.parentNode, nxtSib = a.nextSibling, start= a.selectionStart, end= a.selectionEnd; - parNod.removeChild(a); - parNod.insertBefore(a, nxtSib); - t.area_select(start, end-start); - } - - // force update of selection field - this.focus(); - this.update_size(); - this.check_line_selection(); - }; - - EditArea.prototype.change_font_size= function(){ - var size=_$("area_font_size").value; - if(size>0) - this.set_font("", size); - }; - - - EditArea.prototype.open_inline_popup= function(popup_id){ - this.close_all_inline_popup(); - var popup= _$(popup_id); - var editor= _$("editor"); - - // search matching icon - for(var i=0; i lines.length) - start= this.textarea.value.length; - else{ - for(var i=0; i0){ - //alert(miss_top); - zone.scrollTop= zone.scrollTop + miss_top; - }else if( zone.scrollTop > cursor_pos_top){ - // when erase all the content -> does'nt scroll back to the top - //alert("else: "+cursor_pos_top); - zone.scrollTop= cursor_pos_top; - } - - // manage left scroll - //var cursor_pos_left= parseInt(_$("cursor_pos").style.left.replace("px","")); - var cursor_pos_left= _$("cursor_pos").cursor_left; - var max_width_visible= zone.clientWidth + zone.scrollLeft; - var miss_left= cursor_pos_left + 10 - max_width_visible; - if(miss_left>0){ - zone.scrollLeft= zone.scrollLeft + miss_left + 50; - }else if( zone.scrollLeft > cursor_pos_left){ - zone.scrollLeft= cursor_pos_left ; - }else if( zone.scrollLeft == 45){ - // show the line numbers if textarea align to it's left - zone.scrollLeft=0; - } - }; - - EditArea.prototype.check_undo= function(only_once){ - if(!editAreas[this.id]) - return false; - if(this.textareaFocused && editAreas[this.id]["displayed"]==true){ - var text=this.textarea.value; - if(this.previous.length<=1) - this.switchClassSticky(_$("undo"), 'editAreaButtonDisabled', true); - - if(!this.previous[this.previous.length-1] || this.previous[this.previous.length-1]["text"] != text){ - this.previous.push({"text": text, "selStart": this.textarea.selectionStart, "selEnd": this.textarea.selectionEnd}); - if(this.previous.length > this.settings["max_undo"]+1) - this.previous.shift(); - - } - if(this.previous.length >= 2) - this.switchClassSticky(_$("undo"), 'editAreaButtonNormal', false); - } - - if(!only_once) - setTimeout("editArea.check_undo()", 3000); - }; - - EditArea.prototype.undo= function(){ - //alert("undo"+this.previous.length); - if(this.previous.length > 0) - { - this.getIESelection(); - // var pos_cursor=this.textarea.selectionStart; - this.next.push( { "text": this.textarea.value, "selStart": this.textarea.selectionStart, "selEnd": this.textarea.selectionEnd } ); - var prev= this.previous.pop(); - if( prev["text"] == this.textarea.value && this.previous.length > 0 ) - prev =this.previous.pop(); - this.textarea.value = prev["text"]; - this.last_undo = prev["text"]; - this.area_select(prev["selStart"], prev["selEnd"]-prev["selStart"]); - this.switchClassSticky(_$("redo"), 'editAreaButtonNormal', false); - this.resync_highlight(true); - //alert("undo"+this.previous.length); - this.check_file_changes(); - } - }; - - EditArea.prototype.redo= function(){ - if(this.next.length > 0) - { - /*this.getIESelection();*/ - //var pos_cursor=this.textarea.selectionStart; - var next= this.next.pop(); - this.previous.push(next); - this.textarea.value= next["text"]; - this.last_undo= next["text"]; - this.area_select(next["selStart"], next["selEnd"]-next["selStart"]); - this.switchClassSticky(_$("undo"), 'editAreaButtonNormal', false); - this.resync_highlight(true); - this.check_file_changes(); - } - if( this.next.length == 0) - this.switchClassSticky(_$("redo"), 'editAreaButtonDisabled', true); - }; - - EditArea.prototype.check_redo= function(){ - if(editArea.next.length == 0 || editArea.textarea.value!=editArea.last_undo){ - editArea.next= []; // undo the ability to use "redo" button - editArea.switchClassSticky(_$("redo"), 'editAreaButtonDisabled', true); - } - else - { - this.switchClassSticky(_$("redo"), 'editAreaButtonNormal', false); - } - }; - - - // functions that manage icons roll over, disabled, etc... - EditArea.prototype.switchClass = function(element, class_name, lock_state) { - var lockChanged = false; - - if (typeof(lock_state) != "undefined" && element != null) { - element.classLock = lock_state; - lockChanged = true; - } - - if (element != null && (lockChanged || !element.classLock)) { - element.oldClassName = element.className; - element.className = class_name; - } - }; - - EditArea.prototype.restoreAndSwitchClass = function(element, class_name) { - if (element != null && !element.classLock) { - this.restoreClass(element); - this.switchClass(element, class_name); - } - }; - - EditArea.prototype.restoreClass = function(element) { - if (element != null && element.oldClassName && !element.classLock) { - element.className = element.oldClassName; - element.oldClassName = null; - } - }; - - EditArea.prototype.setClassLock = function(element, lock_state) { - if (element != null) - element.classLock = lock_state; - }; - - EditArea.prototype.switchClassSticky = function(element, class_name, lock_state) { - var lockChanged = false; - if (typeof(lock_state) != "undefined" && element != null) { - element.classLock = lock_state; - lockChanged = true; - } - - if (element != null && (lockChanged || !element.classLock)) { - element.className = class_name; - element.oldClassName = class_name; - } - }; - - //make the "page up" and "page down" buttons works correctly - EditArea.prototype.scroll_page= function(params){ - var dir= params["dir"], shift_pressed= params["shift"]; - var lines= this.textarea.value.split("\n"); - var new_pos=0, length=0, char_left=0, line_nb=0, curLine=0; - var toScrollAmount = _$("result").clientHeight -30; - var nbLineToScroll = 0, diff= 0; - - if(dir=="up"){ - nbLineToScroll = Math.ceil( toScrollAmount / this.lineHeight ); - - // fix number of line to scroll - for( i = this.last_selection["line_start"]; i - diff > this.last_selection["line_start"] - nbLineToScroll ; i-- ) - { - if( elem = _$('line_'+ i) ) - { - diff += Math.floor( ( elem.offsetHeight - 1 ) / this.lineHeight ); - } - } - nbLineToScroll -= diff; - - if(this.last_selection["selec_direction"]=="up"){ - for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]-nbLineToScroll, lines.length); line_nb++){ - new_pos+= lines[line_nb].length + 1; - } - char_left=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]-1); - if(shift_pressed) - length=this.last_selection["selectionEnd"]-new_pos-char_left; - this.area_select(new_pos+char_left, length); - view="top"; - }else{ - view="bottom"; - for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+this.last_selection["line_nb"]-1-nbLineToScroll, lines.length); line_nb++){ - new_pos+= lines[line_nb].length + 1; - } - char_left=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]-1); - if(shift_pressed){ - //length=this.last_selection["selectionEnd"]-new_pos-char_left; - start= Math.min(this.last_selection["selectionStart"], new_pos+char_left); - length= Math.max(new_pos+char_left, this.last_selection["selectionStart"] )- start ; - if(new_pos+char_left < this.last_selection["selectionStart"]) - view="top"; - }else - start=new_pos+char_left; - this.area_select(start, length); - - } - } - else - { - var nbLineToScroll= Math.floor( toScrollAmount / this.lineHeight ); - // fix number of line to scroll - for( i = this.last_selection["line_start"]; i + diff < this.last_selection["line_start"] + nbLineToScroll ; i++ ) - { - if( elem = _$('line_'+ i) ) - { - diff += Math.floor( ( elem.offsetHeight - 1 ) / this.lineHeight ); - } - } - nbLineToScroll -= diff; - - if(this.last_selection["selec_direction"]=="down"){ - view="bottom"; - for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+this.last_selection["line_nb"]-2+nbLineToScroll, lines.length); line_nb++){ - if(line_nb==this.last_selection["line_start"]-1) - char_left= this.last_selection["selectionStart"] -new_pos; - new_pos+= lines[line_nb].length + 1; - - } - if(shift_pressed){ - length=Math.abs(this.last_selection["selectionStart"]-new_pos); - length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"]); - //length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, char_left); - this.area_select(Math.min(this.last_selection["selectionStart"], new_pos), length); - }else{ - this.area_select(new_pos+char_left, 0); - } - - }else{ - view="top"; - for(line_nb=0; line_nb< Math.min(this.last_selection["line_start"]+nbLineToScroll-1, lines.length, lines.length); line_nb++){ - if(line_nb==this.last_selection["line_start"]-1) - char_left= this.last_selection["selectionStart"] -new_pos; - new_pos+= lines[line_nb].length + 1; - } - if(shift_pressed){ - length=Math.abs(this.last_selection["selectionEnd"]-new_pos-char_left); - length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, this.last_selection["curr_pos"])- char_left-1; - //length+=Math.min(lines[Math.min(lines.length-1, line_nb)].length, char_left); - this.area_select(Math.min(this.last_selection["selectionEnd"], new_pos+char_left), length); - if(new_pos+char_left > this.last_selection["selectionEnd"]) - view="bottom"; - }else{ - this.area_select(new_pos+char_left, 0); - } - - } - } - //console.log( new_pos, char_left, length, nbLineToScroll, toScrollAmount, _$("result").clientHeigh ); - this.check_line_selection(); - this.scroll_to_view(view); - }; - - EditArea.prototype.start_resize= function(e){ - parent.editAreaLoader.resize["id"] = editArea.id; - parent.editAreaLoader.resize["start_x"] = (e)? e.pageX : event.x + document.body.scrollLeft; - parent.editAreaLoader.resize["start_y"] = (e)? e.pageY : event.y + document.body.scrollTop; - if(editArea.isIE) - { - editArea.textarea.focus(); - editArea.getIESelection(); - } - parent.editAreaLoader.resize["selectionStart"] = editArea.textarea.selectionStart; - parent.editAreaLoader.resize["selectionEnd"] = editArea.textarea.selectionEnd; - parent.editAreaLoader.start_resize_area(); - }; - - EditArea.prototype.toggle_full_screen= function(to){ - var t=this, p=parent, a=t.textarea, html, frame, selStart, selEnd, old, icon; - if(typeof(to)=="undefined") - to= !t.fullscreen['isFull']; - old = t.fullscreen['isFull']; - t.fullscreen['isFull']= to; - icon = _$("fullscreen"); - selStart = t.textarea.selectionStart; - selEnd = t.textarea.selectionEnd; - html = p.document.getElementsByTagName("html")[0]; - frame = p.document.getElementById("frame_"+t.id); - - if(to && to!=old) - { // toogle on fullscreen - - t.fullscreen['old_overflow'] = p.get_css_property(html, "overflow"); - t.fullscreen['old_height'] = p.get_css_property(html, "height"); - t.fullscreen['old_width'] = p.get_css_property(html, "width"); - t.fullscreen['old_scrollTop'] = html.scrollTop; - t.fullscreen['old_scrollLeft'] = html.scrollLeft; - t.fullscreen['old_zIndex'] = p.get_css_property(frame, "z-index"); - if(t.isOpera){ - html.style.height = "100%"; - html.style.width = "100%"; - } - html.style.overflow = "hidden"; - html.scrollTop = 0; - html.scrollLeft = 0; - - frame.style.position = "absolute"; - frame.style.width = html.clientWidth+"px"; - frame.style.height = html.clientHeight+"px"; - frame.style.display = "block"; - frame.style.zIndex = "999999"; - frame.style.top = "0px"; - frame.style.left = "0px"; - - // if the iframe was in a div with position absolute, the top and left are the one of the div, - // so I fix it by seeing at witch position the iframe start and correcting it - frame.style.top = "-"+p.calculeOffsetTop(frame)+"px"; - frame.style.left = "-"+p.calculeOffsetLeft(frame)+"px"; - - // parent.editAreaLoader.execCommand(t.id, "update_size();"); - // var body=parent.document.getElementsByTagName("body")[0]; - // body.appendChild(frame); - - t.switchClassSticky(icon, 'editAreaButtonSelected', false); - t.fullscreen['allow_resize']= t.resize_allowed; - t.allow_resize(false); - - //t.area_select(selStart, selEnd-selStart); - - - // opera can't manage to do a direct size update - if(t.isFirefox){ - p.editAreaLoader.execCommand(t.id, "update_size();"); - t.area_select(selStart, selEnd-selStart); - t.scroll_to_view(); - t.focus(); - }else{ - setTimeout("parent.editAreaLoader.execCommand('"+ t.id +"', 'update_size();');editArea.focus();", 10); - } - - - } - else if(to!=old) - { // toogle off fullscreen - frame.style.position="static"; - frame.style.zIndex= t.fullscreen['old_zIndex']; - - if(t.isOpera) - { - html.style.height = "auto"; - html.style.width = "auto"; - html.style.overflow = "auto"; - } - else if(t.isIE && p!=top) - { // IE doesn't manage html overflow in frames like in normal page... - html.style.overflow = "auto"; - } - else - { - html.style.overflow = t.fullscreen['old_overflow']; - } - html.scrollTop = t.fullscreen['old_scrollTop']; - html.scrollLeft = t.fullscreen['old_scrollLeft']; - - p.editAreaLoader.hide(t.id); - p.editAreaLoader.show(t.id); - - t.switchClassSticky(icon, 'editAreaButtonNormal', false); - if(t.fullscreen['allow_resize']) - t.allow_resize(t.fullscreen['allow_resize']); - if(t.isFirefox){ - t.area_select(selStart, selEnd-selStart); - setTimeout("editArea.scroll_to_view();", 10); - } - - //p.editAreaLoader.remove_event(p.window, "resize", editArea.update_size); - } - - }; - - EditArea.prototype.allow_resize= function(allow){ - var resize= _$("resize_area"); - if(allow){ - - resize.style.visibility="visible"; - parent.editAreaLoader.add_event(resize, "mouseup", editArea.start_resize); - }else{ - resize.style.visibility="hidden"; - parent.editAreaLoader.remove_event(resize, "mouseup", editArea.start_resize); - } - this.resize_allowed= allow; - }; - - - EditArea.prototype.change_syntax= function(new_syntax, is_waiting){ - // alert("cahnge to "+new_syntax); - // the syntax is the same - if(new_syntax==this.settings['syntax']) - return true; - - // check that the syntax is one allowed - var founded= false; - for(var i=0; i"; - elem.innerHTML= "*"+ this.files[id]['title'] + close +""; - _$('tab_browsing_list').appendChild(elem); - var elem= document.createElement('text'); - this.update_size(); - } - - // open file callback (for plugin) - if(id!="") - this.execCommand('file_open', this.files[id]); - - this.switch_to_file(id, true); - return true; - } - else - return false; - }; - - // close the given file - EditArea.prototype.close_file= function(id){ - if(this.files[id]) - { - this.save_file(id); - - // close file callback - if(this.execCommand('file_close', this.files[id])!==false) - { - // remove the tab in the toolbar - var li= _$(this.files[id]['html_id']); - li.parentNode.removeChild(li); - // select a new file - if(id== this.curr_file) - { - var next_file= ""; - var is_next= false; - for(var i in this.files) - { - if( is_next ) - { - next_file = i; - break; - } - else if( i == id ) - is_next = true; - else - next_file = i; - } - // display the next file - this.switch_to_file(next_file); - } - // clear datas - delete (this.files[id]); - this.update_size(); - } - } - }; - - // backup current file datas - EditArea.prototype.save_file= function(id){ - var t= this, save, a_links, a_selects, save_butt, img, i; - if(t.files[id]) - { - var save= t.files[id]; - save['last_selection'] = t.last_selection; - save['last_text_to_highlight'] = t.last_text_to_highlight; - save['last_hightlighted_text'] = t.last_hightlighted_text; - save['previous'] = t.previous; - save['next'] = t.next; - save['last_undo'] = t.last_undo; - save['smooth_selection'] = t.smooth_selection; - save['do_highlight'] = t.do_highlight; - save['syntax'] = t.settings['syntax']; - save['text'] = t.textarea.value; - save['scroll_top'] = t.result.scrollTop; - save['scroll_left'] = t.result.scrollLeft; - save['selection_start'] = t.last_selection["selectionStart"]; - save['selection_end'] = t.last_selection["selectionEnd"]; - save['font_size'] = t.settings["font_size"]; - save['font_family'] = t.settings["font_family"]; - save['word_wrap'] = t.settings["word_wrap"]; - save['toolbar'] = {'links':{}, 'selects': {}}; - - // save toolbar buttons state for fileSpecific buttons - a_links= _$("toolbar_1").getElementsByTagName("a"); - for( i=0; i