Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <?php
  2. /**
  3. * Energomera
  4. * @package project
  5. * @author Wizard <sergejey@gmail.com>
  6. * @copyright http://majordomo.smartliving.ru/ (c)
  7. * @version 0.1 (wizard, 16:09:07 [Sep 03, 2016])
  8. */
  9. include_once("iek61107.class.php");
  10.  
  11. class energomera extends module {
  12. /**
  13. * energomera
  14. *
  15. * Module class constructor
  16. *
  17. * @access private
  18. */
  19. function energomera() {
  20. $this->name="energomera";
  21. $this->title="Energomera";
  22. $this->module_category="<#LANG_SECTION_DEVICES#>";
  23. $this->checkInstalled();
  24. }
  25. /**
  26. * saveParams
  27. *
  28. * Saving module parameters
  29. *
  30. * @access public
  31. */
  32. function saveParams($data=0) {
  33. $p=array();
  34. if (IsSet($this->id)) {
  35. $p["id"]=$this->id;
  36. }
  37. if (IsSet($this->view_mode)) {
  38. $p["view_mode"]=$this->view_mode;
  39. }
  40. if (IsSet($this->edit_mode)) {
  41. $p["edit_mode"]=$this->edit_mode;
  42. }
  43. if (IsSet($this->tab)) {
  44. $p["tab"]=$this->tab;
  45. }
  46. return parent::saveParams($p);
  47. }
  48. /**
  49. * getParams
  50. *
  51. * Getting module parameters from query string
  52. *
  53. * @access public
  54. */
  55. function getParams() {
  56. global $id;
  57. global $mode;
  58. global $view_mode;
  59. global $edit_mode;
  60. global $tab;
  61. if (isset($id)) {
  62. $this->id=$id;
  63. }
  64. if (isset($mode)) {
  65. $this->mode=$mode;
  66. }
  67. if (isset($view_mode)) {
  68. $this->view_mode=$view_mode;
  69. }
  70. if (isset($edit_mode)) {
  71. $this->edit_mode=$edit_mode;
  72. }
  73. if (isset($tab)) {
  74. $this->tab=$tab;
  75. }
  76. }
  77. /**
  78. * Run
  79. *
  80. * Description
  81. *
  82. * @access public
  83. */
  84. function run() {
  85. global $session;
  86. $out=array();
  87. if ($this->action=='admin') {
  88. $this->admin($out);
  89. } else {
  90. $this->usual($out);
  91. }
  92. if (IsSet($this->owner->action)) {
  93. $out['PARENT_ACTION']=$this->owner->action;
  94. }
  95. if (IsSet($this->owner->name)) {
  96. $out['PARENT_NAME']=$this->owner->name;
  97. }
  98. $out['VIEW_MODE']=$this->view_mode;
  99. $out['EDIT_MODE']=$this->edit_mode;
  100. $out['MODE']=$this->mode;
  101. $out['ACTION']=$this->action;
  102. $this->data=$out;
  103. $p=new parser(DIR_TEMPLATES.$this->name."/".$this->name.".html", $this->data, $this);
  104. $this->result=$p->result;
  105. }
  106. /**
  107. * BackEnd
  108. *
  109. * Module backend
  110. *
  111. * @access public
  112. */
  113. function admin(&$out) {
  114. $this->getConfig();
  115. $out['E_SERIAL']=$this->config['E_SERIAL'];
  116. $out['E_INTERVAL']=$this->config['E_INTERVAL'];
  117. $out['DEVINFO'] = $this->config['DEVINFO'];
  118.  
  119. if ($this->view_mode=='update_settings') {
  120. global $e_serial;
  121. $this->config['E_SERIAL']=$e_serial;
  122.  
  123. global $e_interval;
  124. $this->config['E_INTERVAL']=$e_interval;
  125.  
  126. $this->saveConfig();
  127. $this->redirect("?");
  128. }
  129.  
  130. if ($this->view_mode=='' || $this->view_mode=='search') {
  131. $this->search($out);
  132. }
  133. if ($this->view_mode=='edit') {
  134. $this->edit($out, $this->id);
  135. }
  136. if ($this->view_mode=='delete') {
  137. $this->delete($this->id);
  138. $this->redirect( "?" );
  139. }
  140. }
  141. /**
  142. * Search
  143. *
  144. * @access public
  145. */
  146. function search(&$out) {
  147. require(DIR_MODULES.$this->name.'/search.inc.php');
  148. }
  149. /**
  150. * Edit/add
  151. *
  152. * @access public
  153. */
  154. function edit(&$out, $id) {
  155. require(DIR_MODULES.$this->name.'/edit.inc.php');
  156. }
  157. /**
  158. * Delete
  159. *
  160. * @access public
  161. */
  162. function delete($id) {
  163. $rec=SQLSelectOne("SELECT * FROM engmeraval WHERE ID='$id'");
  164. // some action for related tables
  165. SQLExec("DELETE FROM engmeraval WHERE ID='".$rec['ID']."'");
  166. }
  167. /**
  168. * FrontEnd
  169. *
  170. * Module frontend
  171. *
  172. * @access public
  173. */
  174. function usual(&$out) {
  175. $this->admin($out);
  176. }
  177.  
  178. function processCycle() {
  179. $this->getConfig();
  180.  
  181. $res=SQLSelect("SELECT * FROM engmeraval ORDER BY val;");
  182. $total=count($res);
  183. if ($total) {
  184. $dev = new iek61107( $this->config['E_SERIAL'] );
  185.  
  186. $ret = $dev->connect();
  187. if ($ret === false)
  188. return;
  189.  
  190. $ret = $dev->init();
  191. if ($ret === false)
  192. return;
  193.  
  194. $val = $dev->GetDevInfo();
  195. if ($val != $this->config['DEVINFO']){
  196. $this->config['DEVINFO'] = $val;
  197. $this->saveConfig();
  198. }
  199.  
  200. $cash = array();
  201. for($i=0;$i<$total;$i++) {
  202. // KEY
  203. $key = $res[$i]['VAL'];
  204. $keyn = $key;
  205.  
  206. $start = strpos($keyn, "(");
  207. if ($start)
  208. $keyn = substr($keyn, 0, $start);
  209.  
  210. if (array_key_exists($keyn, $cash))
  211. $ret = $cash[$keyn];
  212. else
  213. $ret = $dev->getValue( $key );
  214.  
  215. // IND
  216. $ind = $res[$i]['IND'];
  217. if ($ind == "") $ind = 0;
  218.  
  219. $ret = $ret[ $keyn ][(int)$ind];
  220. if (($ret === false) || ($ret == "")) continue;
  221.  
  222. setGlobal( $res[$i]['OBJECT'].".".$res[$i]['PROPERTY'], $ret );
  223. }
  224.  
  225. $dev->disconnect();
  226. }
  227.  
  228. return true;
  229. }
  230. /**
  231. * Install
  232. *
  233. * Module installation routine
  234. *
  235. * @access private
  236. */
  237. function install($data='') {
  238. parent::install();
  239. }
  240.  
  241. /**
  242. * dbInstall
  243. *
  244. * Database installation routine
  245. *
  246. * @access private
  247. */
  248. function dbInstall($data) {
  249.  
  250. // Send message
  251. $data = <<<EOD
  252. engmeraval: ID int(10) unsigned NOT NULL auto_increment
  253. engmeraval: VAL varchar(255) NOT NULL DEFAULT ''
  254. engmeraval: IND varchar(255) NOT NULL DEFAULT ''
  255. engmeraval: OBJECT varchar(255) NOT NULL DEFAULT ''
  256. engmeraval: PROPERTY varchar(255) NOT NULL DEFAULT ''
  257. EOD;
  258.  
  259. parent::dbInstall($data);
  260.  
  261. }
  262. // --------------------------------------------------------------------
  263. }
  264. /*
  265. *
  266. * TW9kdWxlIGNyZWF0ZWQgU2VwIDAzLCAyMDE2IHVzaW5nIFNlcmdlIEouIHdpemFyZCAoQWN0aXZlVW5pdCBJbmMgd3d3LmFjdGl2ZXVuaXQuY29tKQ==
  267. *
  268. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement