diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index 2522dd6f..6f3b668f 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -34,7 +34,7 @@ class ConfigController extends Controller { } public $config_json = [ - "lang" => "vi", + "lang" => "vi", "camera" => [ "auto_check" => 1, "num_cam" => 2, @@ -162,7 +162,7 @@ class ConfigController extends Controller { * @return mixed */ public function actionIndex() { - $this->view->title = "Cấu hình thiết bị"; + $this->view->title = "Cấu hình máy chủ"; $options = [ 'http' => [ 'header' => "Content-Type: application/json", @@ -368,4 +368,42 @@ class ConfigController extends Controller { } } + public function actionCauHinhThietBi() { + $this->view->title = "Cấu hình thiết bị"; + return $this->render('device', [ + "server_api" => \app\models\SyncUrl::findOne(['key_config' => 'server_api']), + "device_id" => \app\models\SyncUrl::findOne(['key_config' => 'device_id']) + ]); + } + + public function actionSaveConfig() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->post(); + $server_api = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); + if ($server_api) { + $server_api->data = $post['server_api']; + $server_api->save(); + } else { + $model = new \app\models\SyncUrl(); + $model->create([ + 'key_config' => 'server_api', + 'data' => $post['server_api'] + ]); + } + + $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']); + if ($device_id) { + $device_id->data = $post['device_id']; + $device_id->save(); + } else { + $model = new \app\models\SyncUrl(); + $model->create([ + 'key_config' => 'device_id', + 'data' => $post['device_id'] + ]); + } + return true; + } + } + } diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 578dbe8c..7cc69312 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -270,12 +270,21 @@ class ListManagementController extends Controller { public function actionSyncFromServer() { if (Yii::$app->request->isAjax) { - $datas = json_decode(file_get_contents("https://dev-dc.beetai.com/api/oem/get_all_image", false, stream_context_create([ + $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); + $ip = "dev-dc.beetai.com"; + if ($server_ip) + $ip = $server_ip->data; + $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']); + $id_camera = 209; + if ($device_id) + $id_camera = intval($device_id->data); + + $datas = json_decode(file_get_contents("https://" . $ip . "/api/oem/get_all_image", false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", 'content' => json_encode([ - "id_camera" => 209, + "id_camera" => $id_camera, "ids_staff" => [] ]) ] @@ -293,12 +302,20 @@ class ListManagementController extends Controller { public function actionSyncFeature() { if (Yii::$app->request->post()) { Yii::$app->response->format = "json"; - $res = json_decode(file_get_contents("https://dev-dc.beetai.com/api/oem/get_all_image", false, stream_context_create([ + $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); + $ip = "dev-dc.beetai.com"; + if ($server_ip) + $ip = $server_ip->data; + $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']); + $id_camera = 209; + if ($device_id) + $id_camera = intval($device_id->data); + $res = json_decode(file_get_contents("https://" . $ip . "/api/oem/get_all_image", false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", 'content' => json_encode([ - "id_camera" => 209, + "id_camera" => $id_camera, "ids_staff" => [strval(Yii::$app->request->post("id"))] ]) ] diff --git a/db/app.db b/db/app.db index 5292374b..e054814e 100644 Binary files a/db/app.db and b/db/app.db differ diff --git a/models/SyncUrl.php b/models/SyncUrl.php index cbd78d6b..68459972 100644 --- a/models/SyncUrl.php +++ b/models/SyncUrl.php @@ -8,6 +8,7 @@ use Yii; * This is the model class for table "sync_url". * * @property int $id + * @property string $key_config * @property string $data */ class SyncUrl extends \yii\db\ActiveRecord { @@ -25,7 +26,7 @@ class SyncUrl extends \yii\db\ActiveRecord { public function rules() { return [ [['data'], 'required'], - [['data'], 'string'], + [['data', 'key_config'], 'string'], ]; } @@ -36,12 +37,14 @@ class SyncUrl extends \yii\db\ActiveRecord { return [ 'id' => 'ID', 'data' => 'Data', + 'key_config' => 'Key Config' ]; } public function create($data) { $r = $this->load([ - 'data' => $data['url'], + 'key_config' => $data['key_config'], + 'data' => $data['data'], ], ''); if ($r) { try { 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 65b2b99b..c52e5cfc 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 @@ -37,7 +37,7 @@ use yii\widgets\ActiveForm;