|
1 | 1 | <?php |
2 | 2 |
|
3 | | -if ($this->edit_mode=='delete_link') { |
| 3 | +if ($this->edit_mode == 'delete_link') { |
4 | 4 | global $link_id; |
5 | | - SQLExec("DELETE FROM security_rules WHERE OBJECT_TYPE='sdevice' AND OBJECT_ID=".(int)$link_id); |
6 | | - SQLExec("DELETE FROM devices_linked WHERE ID=".(int)$link_id); |
7 | | - $this->redirect("?id=".$rec['ID']."&tab=".$this->tab."&view_mode=".$this->view_mode); |
| 5 | + SQLExec("DELETE FROM security_rules WHERE OBJECT_TYPE='sdevice' AND OBJECT_ID=" . (int)$link_id); |
| 6 | + SQLExec("DELETE FROM devices_linked WHERE ID=" . (int)$link_id); |
| 7 | + $this->redirect("?id=" . $rec['ID'] . "&tab=" . $this->tab . "&view_mode=" . $this->view_mode); |
8 | 8 | } |
9 | 9 |
|
10 | | -if ($this->edit_mode=='edit_link') { |
| 10 | +if ($this->edit_mode == 'edit_link') { |
11 | 11 | global $link_name; |
12 | 12 | global $link_id; |
13 | 13 |
|
14 | | - $link_details=$this->getLinkDetails($link_name); |
| 14 | + $link_details = $this->getLinkDetails($link_name); |
15 | 15 |
|
16 | | - $link_rec=SQLSelectOne("SELECT * FROM devices_linked WHERE ID=".(int)$link_id); |
| 16 | + $link_rec = SQLSelectOne("SELECT * FROM devices_linked WHERE ID=" . (int)$link_id); |
17 | 17 | if (isset($link_rec['ID'])) { |
18 | | - $out['DEVICE2_ID']=$link_rec['DEVICE2_ID']; |
19 | | - $out['LINK_ID']=$link_rec['ID']; |
20 | | - $out['COMMENT']=$link_rec['COMMENT']; |
21 | | - $settings=unserialize($link_rec['LINK_SETTINGS']); |
| 18 | + $out['DEVICE2_ID'] = $link_rec['DEVICE2_ID']; |
| 19 | + $out['LINK_ID'] = $link_rec['ID']; |
| 20 | + $out['COMMENT'] = $link_rec['COMMENT']; |
| 21 | + $out['IS_ACTIVE'] = $link_rec['IS_ACTIVE']; |
| 22 | + $settings = unserialize($link_rec['LINK_SETTINGS']); |
22 | 23 | if (is_array($link_details['PARAMS'])) { |
23 | | - foreach($link_details['PARAMS'] as &$p) { |
24 | | - if (isset($settings[$p['PARAM_NAME']])) { |
25 | | - $p['VALUE']=$settings[$p['PARAM_NAME']]; |
26 | | - if ($p['PARAM_TYPE']=='duration') { |
27 | | - $p['VALUE'] = gmdate("H:i:s", $p['VALUE']); |
| 24 | + foreach ($link_details['PARAMS'] as &$p) { |
| 25 | + if (isset($settings[$p['PARAM_NAME']])) { |
| 26 | + $p['VALUE'] = $settings[$p['PARAM_NAME']]; |
| 27 | + if ($p['PARAM_TYPE'] == 'duration') { |
| 28 | + $p['VALUE'] = gmdate("H:i:s", $p['VALUE']); |
| 29 | + } |
28 | 30 | } |
29 | 31 | } |
30 | 32 | } |
31 | | - } |
| 33 | + } else { |
| 34 | + $out['IS_ACTIVE']=1; |
32 | 35 | } |
33 | 36 |
|
34 | | - if ($this->mode=='update') { |
35 | | - $ok=1; |
36 | | - $link_rec['DEVICE1_ID']=$rec['ID']; |
37 | | - $link_rec['LINK_TYPE']=$link_name; |
| 37 | + if ($this->mode == 'update') { |
| 38 | + $ok = 1; |
| 39 | + $link_rec['DEVICE1_ID'] = $rec['ID']; |
| 40 | + $link_rec['LINK_TYPE'] = $link_name; |
38 | 41 | global $device2_id; |
39 | | - $link_rec['DEVICE2_ID']=(int)$device2_id; |
| 42 | + $link_rec['DEVICE2_ID'] = (int)$device2_id; |
40 | 43 | if (!$link_rec['DEVICE2_ID']) { |
41 | | - $ok=0; |
| 44 | + $ok = 0; |
42 | 45 | } |
43 | 46 |
|
44 | | - global $comment; |
45 | | - $link_rec['COMMENT']=$comment; |
46 | 47 |
|
47 | | - $params=$link_details['PARAMS']; |
| 48 | + $link_rec['COMMENT'] = gr('comment'); |
| 49 | + $link_rec['IS_ACTIVE'] = gr('is_active', 'int'); |
| 50 | + |
| 51 | + $params = $link_details['PARAMS']; |
48 | 52 |
|
49 | | - $config=array(); |
| 53 | + $config = array(); |
50 | 54 | $total = count($params); |
51 | 55 | for ($i = 0; $i < $total; $i++) { |
52 | 56 | //global ${$params[$i]['PARAM_NAME'].'_value'}; |
53 | 57 | //$config[$params[$i]['PARAM_NAME']]=${$params[$i]['PARAM_NAME'].'_value'}; |
54 | | - $config[$params[$i]['PARAM_NAME']] = gr($params[$i]['PARAM_NAME'].'_value'); |
55 | | - if ($params[$i]['PARAM_TYPE']=='duration' && preg_match('/(\d+):(\d+):(\d+)/',$config[$params[$i]['PARAM_NAME']],$m)) { |
56 | | - $config[$params[$i]['PARAM_NAME']] = $m[1]*60*60+$m[2]*60+$m[3]; |
| 58 | + $config[$params[$i]['PARAM_NAME']] = gr($params[$i]['PARAM_NAME'] . '_value'); |
| 59 | + if ($params[$i]['PARAM_TYPE'] == 'duration' && preg_match('/(\d+):(\d+):(\d+)/', $config[$params[$i]['PARAM_NAME']], $m)) { |
| 60 | + $config[$params[$i]['PARAM_NAME']] = $m[1] * 60 * 60 + $m[2] * 60 + $m[3]; |
57 | 61 | } |
58 | 62 | } |
59 | | - $link_rec['LINK_SETTINGS']=serialize($config); |
| 63 | + $link_rec['LINK_SETTINGS'] = serialize($config); |
60 | 64 | if ($ok) { |
61 | 65 | if ($link_rec['ID']) { |
62 | | - SQLUpdate('devices_linked',$link_rec); |
| 66 | + SQLUpdate('devices_linked', $link_rec); |
63 | 67 | } else { |
64 | | - $link_rec['ID']=SQLInsert('devices_linked',$link_rec); |
| 68 | + $link_rec['ID'] = SQLInsert('devices_linked', $link_rec); |
65 | 69 | } |
66 | 70 | } |
67 | | - $this->redirect("?id=".$rec['ID']."&tab=".$this->tab."&view_mode=".$this->view_mode); |
| 71 | + $this->redirect("?id=" . $rec['ID'] . "&tab=" . $this->tab . "&view_mode=" . $this->view_mode); |
68 | 72 | } |
69 | 73 |
|
70 | | - foreach($link_details as $k=>$v) { |
71 | | - $out['LINK_DETAILS_'.$k]=$v; |
| 74 | + foreach ($link_details as $k => $v) { |
| 75 | + $out['LINK_DETAILS_' . $k] = $v; |
72 | 76 | } |
73 | | - $target_classes=explode(',',$link_details['TARGET_CLASS']); |
74 | | - $target_classes=array_map('trim',$target_classes); |
75 | | - $second_devices=array(); |
| 77 | + $target_classes = explode(',', $link_details['TARGET_CLASS']); |
| 78 | + $target_classes = array_map('trim', $target_classes); |
| 79 | + $second_devices = array(); |
76 | 80 |
|
77 | | - $other_devices=SQLSelect("SELECT * FROM devices WHERE ID!=".(int)$rec['ID']." ORDER BY TITLE"); |
| 81 | + $other_devices = SQLSelect("SELECT * FROM devices WHERE ID!=" . (int)$rec['ID'] . " ORDER BY TITLE"); |
78 | 82 | $total = count($other_devices); |
79 | 83 | for ($i = 0; $i < $total; $i++) { |
80 | | - $type_details=$this->getTypeDetails($other_devices[$i]['TYPE']); |
81 | | - if (in_array($type_details['CLASS'],$target_classes) || in_array($type_details['PARENT_CLASS'],$target_classes)) { |
82 | | - $second_devices[]=$other_devices[$i]; |
| 84 | + $type_details = $this->getTypeDetails($other_devices[$i]['TYPE']); |
| 85 | + if (in_array($type_details['CLASS'], $target_classes) || in_array($type_details['PARENT_CLASS'], $target_classes)) { |
| 86 | + $second_devices[] = $other_devices[$i]; |
83 | 87 | } |
84 | 88 | } |
85 | | - $out['SECOND_DEVICES']=$second_devices; |
| 89 | + $out['SECOND_DEVICES'] = $second_devices; |
86 | 90 |
|
87 | 91 | //print_r($link_details);exit; |
88 | 92 | } |
89 | 93 |
|
90 | | -$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"); |
| 94 | +$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"); |
91 | 95 | if (isset($links[0]['ID'])) { |
92 | 96 | $total = count($links); |
93 | 97 | for ($i = 0; $i < $total; $i++) { |
94 | | - $device1=SQLSelectOne("SELECT ID, TITLE FROM devices WHERE ID=".(int)$links[$i]['DEVICE1_ID']); |
95 | | - $links[$i]['DEVICE1_TITLE']=$device1['TITLE']; |
96 | | - if ($links[$i]['LINK_SETTINGS']!='') { |
97 | | - $settings=unserialize($links[$i]['LINK_SETTINGS']); |
98 | | - $new_settings=''; |
99 | | - foreach($settings as $k=>$v) { |
100 | | - if ($v=='' || $v=='0') continue; |
101 | | - $new_settings.=$k.': <i>'.$v.'</i>; '; |
| 98 | + $device1 = SQLSelectOne("SELECT ID, TITLE FROM devices WHERE ID=" . (int)$links[$i]['DEVICE1_ID']); |
| 99 | + $links[$i]['DEVICE1_TITLE'] = $device1['TITLE']; |
| 100 | + if ($links[$i]['LINK_SETTINGS'] != '') { |
| 101 | + $settings = unserialize($links[$i]['LINK_SETTINGS']); |
| 102 | + $new_settings = ''; |
| 103 | + foreach ($settings as $k => $v) { |
| 104 | + if ($v == '' || $v == '0') continue; |
| 105 | + $new_settings .= $k . ': <i>' . $v . '</i>; '; |
102 | 106 | } |
103 | | - $links[$i]['LINK_SETTINGS']=$new_settings; |
| 107 | + $links[$i]['LINK_SETTINGS'] = $new_settings; |
104 | 108 | } |
105 | | - $rule=SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='sdevice' AND OBJECT_ID=". $links[$i]['ID']); |
| 109 | + $rule = SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='sdevice' AND OBJECT_ID=" . $links[$i]['ID']); |
106 | 110 | if ($rule['ID']) { |
107 | | - $links[$i]['HAS_RULE']=1; |
| 111 | + $links[$i]['HAS_RULE'] = 1; |
108 | 112 | } |
109 | 113 | } |
110 | | - $out['LINKS']=$links; |
| 114 | + $out['LINKS'] = $links; |
111 | 115 | } |
112 | 116 |
|
113 | | -$avail_links=$this->getTypeLinks($rec['TYPE']); |
| 117 | +$avail_links = $this->getTypeLinks($rec['TYPE']); |
114 | 118 | if (isset($avail_links[0])) { |
115 | | - $out['AVAIL_LINKS']=$avail_links; |
| 119 | + $out['AVAIL_LINKS'] = $avail_links; |
116 | 120 | } |
117 | 121 |
|
0 commit comments