diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 0b85df9d..04fabd48 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -882,4 +882,20 @@ class ApiController extends Controller { } } + public function actionCheckTimeEngine() { + Yii::$app->response->format = "json"; + $config_engine = ["start_at" => "00:00", "end_at" => "23:59"]; + $engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']); + if ($engine_time_config) + $config_engine = json_decode($engine_time_config->data, true); + + $start_at = date_format(date_create_from_format('H:i:s d/m/Y', $config_engine['start_at'] . ":00 " . date("d/m/Y")), 'U'); + $end_at = date_format(date_create_from_format('H:i:s d/m/Y', $config_engine['end_at'] . ":59 " . date("d/m/Y")), 'U'); + $now = time(); + if ($now < $start_at || $now > $end_at) + return ["status" => false]; + + return ["status" => true]; + } + } diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index 69727388..249d9649 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -161,6 +161,8 @@ class ConfigController extends Controller { $this->view->title = Yii::t("app", "CAU_HINH_MAY_CHU"); if (Yii::$app->params['type'] != "BiFace") return $this->redirect(['cau-hinh-ip']); + if (Yii::$app->user->identity->username != "admin") + return $this->redirect(['cau-hinh-nhan-dien']); $options = [ 'http' => [ 'header' => "Content-Type: application/json", @@ -421,6 +423,7 @@ class ConfigController extends Controller { if (!$checkConfig['status']) { return ['status' => false, 'text' => '']; } else { + @file_get_contents("http://localhost:4004/SetupMedia"); return ['status' => true, 'url' => Url::to(['cau-hinh-thiet-bi'])]; } } @@ -430,6 +433,8 @@ class ConfigController extends Controller { $this->view->title = Yii::t("app", "CAU_HINH_THIET_BI"); if (Yii::$app->params['type'] != "BiFace") return $this->redirect(['cau-hinh-ip']); + if (Yii::$app->user->identity->username != "admin") + return $this->redirect(['cau-hinh-nhan-dien']); $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ 'http' => [ @@ -588,4 +593,171 @@ class ConfigController extends Controller { } } + public function getConfigJson() { + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ])), true); + if (!$tempConfig['status']) + return $this->redirect(['/config']); + + $engineConfig = json_decode($tempConfig['data'], true); + if (count($engineConfig['data']['engines']) == 0) + return $this->redirect(['/config']); + + $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'] + ]) + ] + ])), true); + + if (!$checkConfig['status']) + return $this->redirect(['/config']); + + $config_json = $this->config_json; + if ($checkConfig['status']) + $config_json = json_decode($checkConfig['data'], true); + return $config_json; + } + + public function actionDieuKhienThietBi() { + $this->view->title = Yii::t("app", "DIEU_KHIEN_THIET_BI"); + $config_json = $this->getConfigJson(); + + $config_engine = ["start_at" => "00:00", "end_at" => "23:59"]; + $engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']); + if ($engine_time_config) + $config_engine = json_decode($engine_time_config->data, true); + return $this->render('dieu-khien-thiet-bi', [ + "background" => $config_json['background'], + "config_engine" => $config_engine, + "config_light" => isset($config_json['open_door']['light']) ? $config_json['open_door']['light'] : false, + "engineStatus" => json_decode(@file_get_contents("http://localhost:4004/EngineStatus"), true), + "menu" => $this->renderPartial("menu", ["tab" => "device_controller"]) + ]); + } + + public function actionControlEngine($status) { + if (Yii::$app->request->isAjax) { + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode(["action" => $status]), + ] + ]; + json_decode(@file_get_contents("http://localhost:4004/ControlEngine", false, stream_context_create($options)), true); + return $status; + } + } + + public function actionSaveTimeLightConfig() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->post(); + $config_json = $this->getConfigJson(); + $config_json['open_door']['light'] = [ + "enable" => $post['enable'], + "start_at" => $post['start_at'], + "end_at" => $post['end_at'] + ]; + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ]; + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create($options)), true); + + if (!$tempConfig['status']) + return false; + + $engineConfig = json_decode($tempConfig['data'], true); + $engineConfig['data']['engines'][0]['isConfig'] = "1"; + + file_get_contents("http://localhost:4004/SaveEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'], + 'config' => $engineConfig, + 'configEngine' => json_encode($config_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) + ]) + ] + ])); + return true; + } + } + + public function actionSaveTimeEngineConfig() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->post(); + $engine_time_config = \app\models\SyncUrl::findOne(['key_config' => 'engine_time_config']); + $config_engine = ["start_at" => $post['start_at'], "end_at" => $post['end_at']]; + if ($engine_time_config) { + $engine_time_config->data = json_encode($config_engine); + $engine_time_config->save(); + } else { + $model = new \app\models\SyncUrl(); + $model->create([ + 'key_config' => 'engine_time_config', + 'data' => json_encode($config_engine) + ]); + } + return true; + } + } + + public function actionBackground() { + if (Yii::$app->request->post()) { + $model = new \app\models\UploadForm(); + $path = "bg"; + $url = $model->UploadGlobal("image", ["PNG", "JPG", "JPEG", "GIF"], $path); + + $config_json = $this->getConfigJson(); + $config_json['background'] = "/uploads" . $url; + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ]; + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create($options)), true); + + if (!$tempConfig['status']) + return false; + + $engineConfig = json_decode($tempConfig['data'], true); + $engineConfig['data']['engines'][0]['isConfig'] = "1"; + + file_get_contents("http://localhost:4004/SaveEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'], + 'config' => $engineConfig, + 'configEngine' => json_encode($config_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) + ]) + ] + ])); + return true; + } + } + + public function actionSound() { + if (Yii::$app->request->post()) { + $model = new \app\models\UploadForm(); + $path = "audio"; + $model->UploadSound("sound", ["WAV"], $path); + return true; + } + } + } diff --git a/messages/en/app.php b/messages/en/app.php index 087bf973..6c33d7d5 100644 --- a/messages/en/app.php +++ b/messages/en/app.php @@ -8,14 +8,14 @@ return [ "CAU_HINH" => "Configuration", - "CAU_HINH_THIET_BI" => "Device Configuration", - "CAU_HINH_MAY_CHU" => "Server Configuration", - "CAU_HINH_NHAN_DIEN" => "Recognition Configuration", - "CAU_HINH_IP" => "IP Configuration", - "DEVICE_CONFIG" => "", - "SERVER_CONFIG" => "", - "ENGINE_CONFIG" => "", - "IP_CONFIG" => "", + "CAU_HINH_THIET_BI" => "Device Config", + "CAU_HINH_MAY_CHU" => "Server Config", + "CAU_HINH_NHAN_DIEN" => "Recognition Config", + "CAU_HINH_IP" => "IP Config", + "DEVICE_CONFIG" => " ", + "SERVER_CONFIG" => " ", + "ENGINE_CONFIG" => " ", + "IP_CONFIG" => " ", "SERVER_MQTT" => "server_mqtt", "URL" => "url", "LUU_LAI" => "Save", @@ -163,5 +163,18 @@ return [ "BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "Are you sure you want to change the device's IP address?", "THONG_TIN_HE_THONG" => "System Information", "REBOOT" => "Reboot", - "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "Are you sure you want to reboot?" + "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "Are you sure you want to reboot?", + "DIEU_KHIEN_THIET_BI" => "Device controller", + "DEVICE_CONTROLLER" => " ", + "DIEU_KHIEN_CHUONG_TRINH_NHAN_DIEN" => "Control recognition program", + "ON" => "On", + "OFF" => "Off", + "THOI_GIAN_HOAT_DONG_CUA_THIET_BI" => "Device operating time", + "THOI_GIAN_BAT_DEN" => "Time to turn on the light", + "BACKGROUND" => "Background", + "BACKGROUND_DESCRIPTION" => "Maximum size 3.5MB (recommended resolution 1280x640px)", + "AM_THANH" => "Sound", + "THOI_GIAN_KHONG_DUOC_DE_TRONG" => "Time cannot be left blank", + "THONG_TIN_DA_DUOC_LUU_LAI" => "The information has been saved", + "CHON_AM_THANH" => "Select sound" ]; diff --git a/messages/ja/app.php b/messages/ja/app.php index bbb8e3ec..7d1a6cba 100644 --- a/messages/ja/app.php +++ b/messages/ja/app.php @@ -163,5 +163,18 @@ return [ "BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "デバイスの IP アドレスを変更してもよろしいですか?", "THONG_TIN_HE_THONG" => "システムインフォメーション", "REBOOT" => "リブート", - "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "再起動してもよろしいですか?" + "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "再起動してもよろしいですか?", + "DIEU_KHIEN_THIET_BI" => "コントローラ", + "DEVICE_CONTROLLER" => "Device controller", + "DIEU_KHIEN_CHUONG_TRINH_NHAN_DIEN" => "制御認識プログラム", + "ON" => "On", + "OFF" => "Off", + "THOI_GIAN_HOAT_DONG_CUA_THIET_BI" => "デバイスの動作時間", + "THOI_GIAN_BAT_DEN" => "ライトをつける時間です", + "BACKGROUND" => "背景", + "BACKGROUND_DESCRIPTION" => "最大サイズ 3.5MB (推奨解像度 1280x640px)", + "AM_THANH" => "音", + "THOI_GIAN_KHONG_DUOC_DE_TRONG" => "時間を空白のままにすることはできません", + "THONG_TIN_DA_DUOC_LUU_LAI" => "情報が保存されました", + "CHON_AM_THANH" => "サウンドを選択する" ]; diff --git a/messages/vi/app.php b/messages/vi/app.php index e976dc30..ae474db6 100644 --- a/messages/vi/app.php +++ b/messages/vi/app.php @@ -163,5 +163,18 @@ return [ "BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG" => "Bạn có chắc chắn muốn thay đổi địa chỉ IP của thiết bị không?", "THONG_TIN_HE_THONG" => "Thông tin hệ thống", "REBOOT" => "Khởi động lại thiết bị", - "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "Bạn có chắc chắn muốn khởi động lại thiết bị không?" + "BAN_CO_CHAC_CHAN_MUON_REBOOT_KHONG" => "Bạn có chắc chắn muốn khởi động lại thiết bị không?", + "DIEU_KHIEN_THIET_BI" => "Điều khiển thiết bị", + "DEVICE_CONTROLLER" => "Device controller", + "DIEU_KHIEN_CHUONG_TRINH_NHAN_DIEN" => "Điều khiển chương trình nhận diện", + "ON" => "Bật", + "OFF" => "Tắt", + "THOI_GIAN_HOAT_DONG_CUA_THIET_BI" => "Thời gian hoạt động của thiết bị", + "THOI_GIAN_BAT_DEN" => "Thời gian bật đèn", + "BACKGROUND" => "Hình nền", + "BACKGROUND_DESCRIPTION" => "Kích thước tối đa 3.5MB (độ phân giải khuyến nghị 1280x640px)", + "AM_THANH" => "Âm thanh", + "THOI_GIAN_KHONG_DUOC_DE_TRONG" => "Thời gian không được để trống", + "THONG_TIN_DA_DUOC_LUU_LAI" => "Thông tin đã được lưu lại", + "CHON_AM_THANH" => "Chọn âm thanh" ]; diff --git a/models/UploadForm.php b/models/UploadForm.php index 89e7d257..098f583c 100644 --- a/models/UploadForm.php +++ b/models/UploadForm.php @@ -131,6 +131,33 @@ class UploadForm extends Model { } } + public function UploadSound($file, $fileTypes, $path) { + $root = \Yii::getAlias('@app') . '/web/data'; + $LocalPath = "/" . $path; + $RootFolder = $root . $LocalPath; + $destfile = "welcome_en.wav"; + if (!empty($_FILES)) { + $tempFile = $_FILES[$file]['tmp_name']; + $targetPath = $RootFolder; + if (!file_exists($targetPath)) { + @mkdir($targetPath, 0777, true); + } + $targetFile = $targetPath . '/' . $destfile; + $targetFileLocal = $LocalPath . '/' . $destfile; + $fileParts = pathinfo($_FILES[$file]['name']); + if (in_array(strtoupper($fileParts['extension']), $fileTypes)) { + move_uploaded_file($tempFile, $targetFile); + if (file_exists($targetFile)) { + return $targetFileLocal; + } else { + return false; + } + } else { + return 2; + } + } + } + //Move file public function MoveFile($file, $folder) { $currentStorage = Storage::findOne(['stt' => 1])->folder; diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index 1234423e..46169aaf 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -42,11 +42,13 @@ use yii\widgets\ActiveForm; params['type'] === "BiFace") { ?> -
{Yii::t("app","DIEU_KHIEN_CHUONG_TRINH_NHAN_DIEN")} | +
+
+
+
+
+ |
+
---|---|
{Yii::t("app","THOI_GIAN_HOAT_DONG_CUA_THIET_BI")} | +
+
+
+
+
+ {Yii::t("app","FROM")}
+
+ {Yii::t("app","TO")}
+
+
+
+
+ |
+
{Yii::t("app","THOI_GIAN_BAT_DEN")} | +
+
+
+
+
+
+
+
+
+ {Yii::t("app","FROM")}
+
+ {Yii::t("app","TO")}
+
+
+
+
+ |
+
{Yii::t("app","BACKGROUND")} | +
+
+
+
+ {if $background!=""}
+
+ |
+
{Yii::t("app","AM_THANH")} | +
+
+
+
+ welcome_en.wav
+
+ |
+