Advertisement
Guest User

megad_class.php

a guest
May 26th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("config.php");
  4.  
  5. class megad extends conf
  6. {
  7. public $conf = array();
  8. public $id = 0;
  9.  
  10. public function __construct()
  11. {
  12. $conf_file = "dev_conf.json";
  13. $dev_conf = fopen($conf_file, "r");
  14. $conf_json = fread($dev_conf, filesize($conf_file));
  15. fclose($dev_conf);
  16.  
  17. $this->conf = json_decode($conf_json, TRUE);
  18.  
  19. if ( !empty($_REQUEST['id']) )
  20. $this->id = $_REQUEST['id'];
  21.  
  22. }
  23.  
  24. public function write_conf()
  25. {
  26. $json = json_encode($this->conf);
  27. $dev_conf = fopen("dev_conf.json", "w");
  28. fwrite($dev_conf, $json);
  29. fclose($dev_conf);
  30. }
  31.  
  32. public function menu()
  33. {
  34. $result = '<li><a href="index.php">В начало</a></li>';
  35. foreach ( $this->conf as $key => $val )
  36. {
  37. if ( $this->id == $key ) $selected = ' class="Selected"'; else $selected = "";
  38. $result .= "<li$selected><a href=\"control.php?id=$key\">".$this->conf[$key]['name']."</a></li>";
  39. }
  40.  
  41. if ( !empty($this->conf) )
  42. $result .= '<li><a href="control.php?all=1">Показать все</a></li>';
  43.  
  44. $result .= '<li><a href="edit.php?new=1">Добавить</a></li>';
  45.  
  46. return $result;
  47. }
  48.  
  49. public function control($id, $port, $state)
  50. {
  51. if ( $this->demo != "true" )
  52. file_get_contents("http://".$this->conf[$id]['ip']."/".$this->conf[$id]['pwd']."/?cmd=$port:$state");
  53. }
  54.  
  55. public function get($id, $port)
  56. {
  57. if ( $this->demo != "true" )
  58. {
  59. $state = file_get_contents("http://".$this->conf[$id]['ip']."/".$this->conf[$id]['pwd']."/?pt=$port&cmd=get");
  60. return $state;
  61. }
  62. return;
  63. }
  64. }
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement