Pages.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 04/12/2018
  5. * @time 15:22
  6. */
  7. namespace OpenMind\Admin;
  8. use Exception;
  9. use OpenMind\FindBox\FindBoxCoreSystem;
  10. use OpenMind\FindBox\SmartESL;
  11. use OpenMind\Web\Controller;
  12. use Template;
  13. class Pages extends Controller
  14. {
  15. private $findBoxCore = null;
  16. public function __construct($f3)
  17. {
  18. parent::__construct($f3);
  19. $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
  20. // Set Admin F3 UI folder
  21. $f3->set('UI', 'ui/admin/');
  22. }
  23. public function Admin($f3)
  24. {
  25. echo Template::instance()->render('masterpage.tpl');
  26. }
  27. public function ESLStatus($f3)
  28. {
  29. $eslStatus = $this->findBoxCore->GetAllESLStatus();
  30. $f3->set('STATUS_BADGE_COLOR', [
  31. 'OFFLINE' => 'warning',
  32. 'BLOCKED,FC' => 'danger',
  33. 'NO_STATUS' => 'light',
  34. 'OK' => 'success'
  35. ]);
  36. $f3->set('BATLEV_ICONS', [
  37. 'GOOD' => 'full', // 100% - 60%
  38. 'LOW' => 'half', // 60% - 30%
  39. 'BAD' => 'empty', // 30% - 0%
  40. ]);
  41. $f3->set('ESL_STATUS', $eslStatus);
  42. $f3->set('PAGENAME', 'Dashboard');
  43. $f3->set('CONTENT', 'labelstatus.tpl');
  44. echo Template::instance()->render('masterpage.tpl');
  45. }
  46. public function OML_Settings($f3)
  47. {
  48. global $frameworkUtils;
  49. $path = 'cfg/config.bin';
  50. if (!file_exists($path))
  51. throw new Exception('Config file not found');
  52. $data = file_get_contents($path);
  53. $config = $frameworkUtils->Decrypt($data);
  54. $f3->set('PAGENAME', 'OM-Link Settings');
  55. $f3->set('CONTENT', 'omlsettings.tpl');
  56. $f3->set('CONFIG_TEXT', $config);
  57. echo Template::instance()->render('masterpage.tpl');
  58. }
  59. public function Config($f3)
  60. {
  61. global $frameworkUtils;
  62. $config = $f3->get('BODY');
  63. if (strlen($config) == 0) {
  64. echo json_encode([
  65. "err" => "Empty body command"
  66. ]);
  67. return;
  68. }
  69. $configOBJ = json_decode($config);
  70. switch ($configOBJ->method) {
  71. case 'saveconfig':
  72. $newConfig = $frameworkUtils->Encrypt($configOBJ->value);
  73. @rename('cfg/config.bin', 'cfg/config.bin.old');
  74. @file_put_contents('cfg/config.bin', $newConfig);
  75. echo json_encode([
  76. "err" => "Configuration saved"
  77. ]);
  78. break;
  79. case 'loadconfig':
  80. $config = $frameworkUtils->Decrypt(file_get_contents('cfg/config.bin'));
  81. echo json_encode([
  82. "err" => "Configuration reloaded successfully",
  83. "value" => $config
  84. ]);
  85. break;
  86. case 'geteslstatus':
  87. $labelID = $configOBJ->label_id;
  88. $esl = new SmartESL($this->findBoxCore, [$labelID]);
  89. $status = $esl->GetStatus(true);
  90. $svgPath = $this->findBoxCore->GetTemplateImage($status[$configOBJ->label_id]['data']['template_id']);
  91. echo json_encode([
  92. "err" => "Status reloaded successfully",
  93. "value" => $status[$configOBJ->label_id],
  94. "svgPath" => $svgPath
  95. ]);
  96. break;
  97. case 'blinklabels':
  98. $esl = new SmartESL($this->findBoxCore, [$configOBJ->labelid]);
  99. $ret = $esl->BlinkSpecial(2, 1, 1000, 5, 0);
  100. if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
  101. if ($ret['value']['value'][$configOBJ->labelid])
  102. echo json_encode([
  103. "err" => 0,
  104. "value" => "{$configOBJ->labelid} blink successfull"
  105. ]);
  106. else
  107. echo json_encode([
  108. "err" => 1,
  109. "value" => "{$configOBJ->labelid} blink error"
  110. ]);
  111. }
  112. break;
  113. case 'unbind':
  114. $ret = $this->findBoxCore->UnBind($configOBJ->labelid);
  115. if ($ret['err'] != 0) {
  116. echo json_encode($ret);
  117. return;
  118. }
  119. echo json_encode([
  120. "err" => 0,
  121. "value" => "{$configOBJ->labelid} unbind successfull"
  122. ]);
  123. break;
  124. case 'resetfailcounter':
  125. $URI = "/1.0.0/index.php/smartesl.resetfailcounter/1.0.0/[[\"{$configOBJ->labelid}\"]]";
  126. $this->findBoxCore->CallAPI($URI, "");
  127. echo json_encode([
  128. "err" => 0,
  129. "value" => "{$configOBJ->labelid} Reset Fail Counter successfull"
  130. ]);
  131. break;
  132. case 'TemplateSelector':
  133. $this->TemplateSelector($f3, $configOBJ);
  134. break;
  135. case 'SetDisplay':
  136. foreach($configOBJ->labels as $labelID) {
  137. $esl = new SmartESL($this->findBoxCore, [$labelID]);
  138. $esl->Display($configOBJ->id, $labelID);
  139. }
  140. echo json_encode([
  141. "err" => "Display command successfull"
  142. ]);
  143. break;
  144. }
  145. return;
  146. }
  147. private function TemplateSelector($f3, $Command)
  148. {
  149. global $f3, $frameworkUtils;
  150. $fb_template = $this->findBoxCore->CallAPI('/1.0.0/index.php/smartesl.gettemplates/1.0.0/', '[]');
  151. $templates = $this->findBoxCore->getLabelsFromResponse($fb_template);
  152. if ($Command->clearCache == 1)
  153. $frameworkUtils->rrmdir("fbtpl");
  154. $tplFileNames = [];
  155. if ($templates != null) {
  156. foreach($templates as $item) {
  157. if (!in_array($item['resolution'], $Command->resolution))
  158. continue;
  159. if (!file_exists("fbtpl/{$item['template_id']}.svg"))
  160. $this->findBoxCore->GetTemplateImage($item['template_id']);
  161. $tplFileNames[] = [
  162. "id" => $item['template_id'],
  163. "name" => $item['name'],
  164. "resolution" => $item['resolution'],
  165. "title" => $item['name'],
  166. "svg" => file_get_contents("fbtpl/{$item['template_id']}.svg")
  167. ];
  168. }
  169. }
  170. $f3->set('TPLOBJ', $tplFileNames);
  171. $tpl = Template::instance()->render('templates.tpl');
  172. echo json_encode([
  173. "err" => 0,
  174. "value" => $tpl
  175. ]);
  176. }
  177. }