| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- /**
- * @author Giancarlo Voci
- * @date 04/12/2018
- * @time 15:22
- */
- namespace OpenMind\Admin;
- use Base;
- use Exception;
- use OpenMind\FindBox\FindBoxCoreSystem;
- use OpenMind\FindBox\SmartESL;
- use OpenMind\System\Notifications;
- use OpenMind\System\User;
- use OpenMind\Web\Controller;
- use Template;
- class Pages extends Controller
- {
- private $findBoxCore = null;
- /**
- * Pages constructor.
- * @param Base $f3
- */
- public function __construct($f3)
- {
- parent::__construct($f3);
- try {
- $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
- } catch (Exception $e) {
- $ns = new Notifications();
- $ns->notify(Notifications::FB_ADMIN, $f3->clean($e->getMessage()));
- // IF can't connect to FINDBOX, reroute to OMLINK Page Settings to fast change settings
- if (!$f3->get('AJAX') && ($f3->get('PATTERN') != '/admin/omlsettings'))
- $f3->reroute('/admin/omlsettings');
- }
- // Set Admin F3 UI folder
- $f3->set('UI', 'ui/admin/');
- }
- public function Admin($f3)
- {
- echo Template::instance()->render('masterpage.tpl');
- }
- public function ESLStatus(Base $f3)
- {
- $eslStatus = $this->findBoxCore->GetAllESLStatus();
- $f3->set('STATUS_BADGE_COLOR', [
- 'OFFLINE' => 'warning',
- 'BLOCKED,FC' => 'danger',
- 'NO_STATUS' => 'light',
- 'OK' => 'success'
- ]);
- $f3->set('BATLEV_ICONS', [
- 'GOOD' => 'full', // 100% - 60%
- 'LOW' => 'half', // 60% - 30%
- 'BAD' => 'empty', // 30% - 0%
- ]);
- $f3->set('ESL_STATUS', $eslStatus);
- $f3->set('PAGENAME', 'Dashboard');
- $f3->set('CONTENT', 'labelstatus.tpl');
- echo Template::instance()->render('masterpage.tpl');
- }
- public function OML_Settings(Base $f3)
- {
- global $frameworkUtils;
- $path = 'cfg/config.bin';
- if (!file_exists($path))
- throw new Exception('Config file not found');
- $data = file_get_contents($path);
- $config = $frameworkUtils->Decrypt($data);
- $f3->set('PAGENAME', 'OM-Link Settings');
- $f3->set('CONTENT', 'omlsettings.tpl');
- $f3->set('CONFIG_TEXT', $config);
- echo Template::instance()->render('masterpage.tpl');
- }
- public function Config(Base $f3)
- {
- global $frameworkUtils;
- $config = $f3->get('BODY');
- if (strlen($config) == 0) {
- echo json_encode([
- "err" => "Empty body command"
- ]);
- return;
- }
- $configOBJ = json_decode($config);
- switch ($configOBJ->method) {
- case 'saveconfig':
- $newConfig = $frameworkUtils->Encrypt($configOBJ->value);
- @rename('cfg/config.bin', 'cfg/config.bin.old');
- @file_put_contents('cfg/config.bin', $newConfig);
- echo json_encode([
- "err" => "Configuration saved"
- ]);
- break;
- case 'loadconfig':
- $config = $frameworkUtils->Decrypt(file_get_contents('cfg/config.bin'));
- echo json_encode([
- "err" => "Configuration reloaded successfully",
- "value" => $config
- ]);
- break;
- case 'geteslstatus':
- $labelID = $configOBJ->label_id;
- $esl = new SmartESL($this->findBoxCore, [$labelID]);
- $status = $esl->GetStatus(true);
- $svgPath = $this->findBoxCore->GetTemplateImage($status[$configOBJ->label_id]['data']['template_id']);
- echo json_encode([
- "err" => "Status reloaded successfully",
- "value" => $status[$configOBJ->label_id],
- "svgPath" => $svgPath
- ]);
- break;
- case 'blinklabels':
- $esl = new SmartESL($this->findBoxCore, [$configOBJ->labelid]);
- $ret = $esl->BlinkSpecial(2, 1, 1000, 5, 0);
- if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
- if ($ret['value']['value'][$configOBJ->labelid])
- echo json_encode([
- "err" => 0,
- "value" => "{$configOBJ->labelid} blink successfull"
- ]);
- else
- echo json_encode([
- "err" => 1,
- "value" => "{$configOBJ->labelid} blink error"
- ]);
- }
- break;
- case 'unbind':
- $ret = $this->findBoxCore->UnBind($configOBJ->labelid);
- if ($ret['err'] != 0) {
- echo json_encode($ret);
- return;
- }
- echo json_encode([
- "err" => 0,
- "value" => "{$configOBJ->labelid} unbind successfull"
- ]);
- break;
- case 'resetfailcounter':
- $URI = "/1.0.0/index.php/smartesl.resetfailcounter/1.0.0/[[\"{$configOBJ->labelid}\"]]";
- $this->findBoxCore->CallAPI($URI, "");
- echo json_encode([
- "err" => 0,
- "value" => "{$configOBJ->labelid} Reset Fail Counter successfull"
- ]);
- break;
- case 'TemplateSelector':
- $this->TemplateSelector($f3, $configOBJ);
- break;
- case 'SetDisplay':
- foreach($configOBJ->labels as $labelID) {
- $esl = new SmartESL($this->findBoxCore, [$labelID]);
- $esl->Display($configOBJ->id, $labelID);
- }
- echo json_encode([
- "err" => "Display command successfull"
- ]);
- break;
- }
- return;
- }
- private function TemplateSelector(Base $f3, $Command)
- {
- global $frameworkUtils;
- $fb_template = $this->findBoxCore->CallAPI('/1.0.0/index.php/smartesl.gettemplates/1.0.0/', '[]');
- $templates = $this->findBoxCore->getLabelsFromResponse($fb_template);
- if ($Command->clearCache == 1)
- $frameworkUtils->rrmdir("fbtpl");
- $tplFileNames = [];
- if ($templates != null) {
- foreach($templates as $item) {
- if (!in_array($item['resolution'], $Command->resolution))
- continue;
- if (!file_exists("fbtpl/{$item['template_id']}.svg"))
- $this->findBoxCore->GetTemplateImage($item['template_id']);
- $tplFileNames[] = [
- "id" => $item['template_id'],
- "name" => $item['name'],
- "resolution" => $item['resolution'],
- "title" => $item['name'],
- "svg" => file_get_contents("fbtpl/{$item['template_id']}.svg")
- ];
- }
- }
- $f3->set('TPLOBJ', $tplFileNames);
- $tpl = Template::instance()->render('templates.tpl');
- echo json_encode([
- "err" => 0,
- "value" => $tpl
- ]);
- }
- public function Users(Base $f3)
- {
- $listaUtenti = new User('');
- $f3->set('USERLIST', $listaUtenti->find());
- $f3->set('PAGENAME', 'User Management');
- $f3->set('CONTENT', 'users.tpl');
- echo Template::instance()->render('masterpage.tpl');
- }
- }
|