diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php
index 166ceb88..46acb404 100644
--- a/controllers/DeviceController.php
+++ b/controllers/DeviceController.php
@@ -626,7 +626,9 @@ class DeviceController extends Controller {
$model = $this->findModel($id);
return json_decode(common::requestToCardService("/ControlDevice", [
"DeviceIP" => $model->ip_address,
- "DoorID" => $door
+ "DoorID" => [
+ "Door" . $door => "5"
+ ]
]), true);
}
}
@@ -722,4 +724,46 @@ class DeviceController extends Controller {
}
}
+ public function actionOpenAllDoors() {
+ if (Yii::$app->request->post()) {
+ Yii::$app->response->format = "json";
+ $post = Yii::$app->request->post();
+ $lists = $post["lists"];
+ if ($post["all"] === "true") {
+ $temp = [];
+ $devices = Device::find()->all();
+ foreach ($devices as $key => $value) {
+ $temp[] = $value->id;
+ }
+ $lists = $temp;
+ }
+ return [
+ "title" => Html::tag("i", "", ["class" => "fa fa-reply"]) . " Mở tất cả cửa",
+ "form" => $this->renderPartial("openDoor"),
+ "lists" => $lists
+ ];
+ }
+ }
+
+ public function actionOpenDoorsOfDevice() {
+ if (Yii::$app->request->post()) {
+ Yii::$app->response->format = "json";
+ $device = $this->findModel(Yii::$app->request->post("data"));
+ $doors = Door::find()->andWhere(['device_id' => $device->id])->all();
+ $doorOpen = [];
+ foreach ($doors as $key => $value) {
+ $doorOpen["Door" . $value->code] = "5";
+ }
+ $response = json_decode(common::requestToCardService("/ControlDevice", [
+ "DeviceIP" => $device->ip_address,
+ "DoorID" => $doorOpen
+ ]), true);
+ return [
+ "totals" => count($doors),
+ "IP" => $device->ip_address,
+ "response" => $response
+ ];
+ }
+ }
+
}
diff --git a/views/device/index.tpl b/views/device/index.tpl
index c9911ecf..de9aea23 100644
--- a/views/device/index.tpl
+++ b/views/device/index.tpl
@@ -8,6 +8,7 @@
+
@@ -50,6 +51,9 @@
Xuất
{/if}
+
diff --git a/views/device/openDoor.tpl b/views/device/openDoor.tpl
new file mode 100644
index 00000000..e6a98518
--- /dev/null
+++ b/views/device/openDoor.tpl
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/web/js/device.js b/web/js/device.js
index dbbb1f87..7aadd9cc 100644
--- a/web/js/device.js
+++ b/web/js/device.js
@@ -605,4 +605,71 @@ function changeDuration(e) {
common.ajaxError();
}
});
+}
+
+var progressOpenDoor = 0;
+var totalsDoor = 0;
+function openAllDoors(e) {
+ var all = false;
+ if ($("#checkbox-device-all:checked").length > 0)
+ all = true;
+ var lists = [];
+ $.each($("input[name='checkbox-device']:checked"), function () {
+ lists.push($(this).val());
+ });
+ if (lists.length == 0) {
+ alert("Vui lòng lựa chọn đối tượng!");
+ return;
+ }
+ common.modalBlock(true);
+ $.ajax({
+ url: $(e).attr('data-href'),
+ type: 'POST',
+ data: {
+ lists: lists,
+ all: all
+ },
+ success: function (data) {
+ common.modalBlock(false);
+ common.modalOpen(data.form, false, data.title);
+ $("#close-modal").attr("disabled", true);
+ $("#modalHeader").find("button").remove();
+ totalsDoor = data.lists.length;
+ for (var i = 0; i < data.lists.length; i++) {
+ openAllDoorOfDevice(data.lists[i]);
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.modalBlock(false);
+ common.ajaxError();
+ }
+ });
+}
+
+function openAllDoorOfDevice(data) {
+ $.ajax({
+ url: $("input[name='URL_open_door']").val(),
+ type: 'POST',
+ data: {
+ data: data
+ },
+ success: function (data) {
+ console.log(data.response);
+ var html = "";
+ html = "
Mở " + data.totals + " cửa từ thiết bị " + data.IP + ".";
+ $("#logs-response").prepend(html);
+ progressOpenDoor++;
+ var percent = parseInt(progressOpenDoor / totalsDoor * 100);
+ $("#progress").attr("aria-valuenow", percent);
+ $("#progress").attr("style", "width: " + percent + "%");
+ $("#progress").html(percent + "%");
+ if (percent >= 100) {
+ progressOpenDoor = 0;
+ $("#close-modal").attr("disabled", false);
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ common.ajaxError();
+ }
+ });
}
\ No newline at end of file