diff --git a/assets/CaptureLogsAsset.php b/assets/CaptureLogsAsset.php new file mode 100644 index 00000000..3a4f911b --- /dev/null +++ b/assets/CaptureLogsAsset.php @@ -0,0 +1,23 @@ +request->post()) { + $post = Yii::$app->request->bodyParams; + $time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U'); + $key = $this->generateRandomString(); + $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; + $targetPath = $RootFolder . "/face"; + $fileName = "face_" . $key . "_" . $time . ".png"; + FileHelper::createDirectory($targetPath, 0777); + file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image'])); + + if ($post["id"] == 0) { + $model = new CaptureLogs(); + $model->create([ + "Time" => $time, + "Image" => $fileName + ]); + } + Yii::$app->response->format = "json"; + return ["status" => "success"]; + } + } + + public function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + } diff --git a/controllers/CaptureLogsController.php b/controllers/CaptureLogsController.php index eab57f64..f22cadf4 100644 --- a/controllers/CaptureLogsController.php +++ b/controllers/CaptureLogsController.php @@ -6,21 +6,14 @@ use Yii; use app\models\CaptureLogs; use app\models\CaptureLogsSearch; use yii\web\Controller; +use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; -use yii\helpers\Url; /** - * ScriptController implements the CRUD actions for Script model. + * CaptureLogsController implements the CRUD actions for CaptureLogs model. */ class CaptureLogsController extends Controller { - public function init() { - parent::init(); - if (Yii::$app->user->isGuest) { - return $this->redirect(['/site/login']); - } - } - /** * {@inheritdoc} */ @@ -35,20 +28,71 @@ class CaptureLogsController extends Controller { ]; } - /** - * Lists all Script models. - * @return mixed - */ - public function actionIndex() { - $this->view->title = "Ảnh mẫu"; + public function actionIndex($from = "", $to = "") { + $f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U'); + $t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U'); + if ($from !== "" && $to !== "") { + $f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U'); + $t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U'); + } + + $this->view->title = "Capture Log"; $searchModel = new CaptureLogsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]); + $dataProvider->query->orderBy(["time" => SORT_DESC]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, + 'statusArray' => CaptureLogs::$statusArray, + 'f' => $f, + 't' => $t ]); } - + public function actionView($id) { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + public function actionCreate() { + $model = new CaptureLogs(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + public function actionUpdate($id) { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + public function actionDelete($id) { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + protected function findModel($id) { + if (($model = CaptureLogs::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + } diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index 2522dd6f..610aac90 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -170,7 +170,7 @@ class ConfigController extends Controller { ] ]; $ip = "192.168.0.42"; - $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true); + $tempConfig = json_decode(file_get_contents("http://192.168.1.241:4004/ReadAPIConfig", false, stream_context_create($options)), true); if ($tempConfig['status']) { $t = json_decode($tempConfig['data'], true); $temp = explode("/", $t['url']); diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php new file mode 100644 index 00000000..0c66b873 --- /dev/null +++ b/controllers/ListManagementController.php @@ -0,0 +1,93 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actionIndex($from = "", $to = "") { + $f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U'); + $t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U'); + if ($from !== "" && $to !== "") { + $f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U'); + $t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U'); + } + $this->view->title = "List management"; + $searchModel = new ListManagementSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]); + $dataProvider->query->orderBy(["time" => SORT_DESC]); + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'f' => $f, + 't' => $t, + 'typeArray' => ListManagement::$typeArray + ]); + } + + public function actionView($id) { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + public function actionCreate() { + $model = new ListManagement(); + if (Yii::$app->request->post()) { + $data = Yii::$app->request->post(); + $data['image'] = \app\models\CaptureLogs::findOne($data['id'])->image; + return $model->create($data); + } + } + + public function actionUpdate($id) { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + public function actionDelete($id) { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + protected function findModel($id) { + if (($model = ListManagement::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + +} diff --git a/db/app.db b/db/app.db index aaf93d41..c5495dcc 100644 Binary files a/db/app.db and b/db/app.db differ diff --git a/helpers/CaptureLogsGrid.php b/helpers/CaptureLogsGrid.php index e54bb138..3837e52a 100644 --- a/helpers/CaptureLogsGrid.php +++ b/helpers/CaptureLogsGrid.php @@ -5,7 +5,6 @@ namespace app\helpers; use Yii; use yii\helpers\Html; use yii\helpers\Url; -use app\models\common; class CaptureLogsGrid { @@ -29,4 +28,38 @@ class CaptureLogsGrid { return "{update} {delete}"; } + public static function time() { + return function($model) { + return date("H:i:s d/m/Y", $model->time); + }; + } + + public static function image() { + return function($model) { + return Html::img("/BiFace/data/uploads/face/" . $model->image, [ + "class" => "img-thumbnail", + "style" => "width: 150px;height:150px;" + ]); + }; + } + + public static function status($statusArray) { + return function($model) use ($statusArray) { + return $statusArray[$model->status]; + }; + } + + public static function rows() { + return function($model, $index, $widget, $grid) { + return [ + "ondblclick" => "_form(this);", + "style" => "cursor: pointer;", + "data" => [ + "id" => $model->id, + "img" => "/BiFace/data/uploads/face/" . $model->image + ] + ]; + }; + } + } diff --git a/helpers/ListManagementGrid.php b/helpers/ListManagementGrid.php new file mode 100644 index 00000000..7e66248c --- /dev/null +++ b/helpers/ListManagementGrid.php @@ -0,0 +1,71 @@ +app->app_name; + }; + } + + public static function getLayout() { + return "{items}
{summary}
{pager}
"; + } + + public static function actionTemplate() { + return "{update} {delete}"; + } + + public static function time() { + return function($model) { + return date("H:i:s d/m/Y", $model->time); + }; + } + + public static function birthday() { + return function($model) { + return date("d/m/Y", $model->birthday); + }; + } + + public static function image() { + return function($model) { + return Html::img("/BiFace/data/uploads/face/" . $model->image, [ + "class" => "img-thumbnail", + "style" => "width: 150px;height:150px;" + ]); + }; + } + + public static function type($typeArray) { + return function($model) use ($typeArray) { + return $typeArray[$model->type]; + }; + } + + public static function rows() { + return function($model, $index, $widget, $grid) { + return [ + "ondblclick" => "_form(this);", + "style" => "cursor: pointer;", + "data" => [ + "id" => $model->id, + "img" => "/BiFace/data/uploads/face/" . $model->image + ] + ]; + }; + } + +} diff --git a/models/CaptureLogs.php b/models/CaptureLogs.php index 5a1aee14..e1478d33 100644 --- a/models/CaptureLogs.php +++ b/models/CaptureLogs.php @@ -7,44 +7,64 @@ use Yii; /** * This is the model class for table "capture_logs". * - * @property int $ID - * @property int $Time - * @property string $Image - * @property int $Status - * @property string $Remark + * @property int $id + * @property int $time + * @property string $image + * @property int $status + * @property string $remark */ -class CaptureLogs extends \yii\db\ActiveRecord -{ +class CaptureLogs extends \yii\db\ActiveRecord { + /** * {@inheritdoc} */ - public static function tableName() - { + public static function tableName() { return 'capture_logs'; } /** * {@inheritdoc} */ - public function rules() - { + public function rules() { return [ - [['Time', 'Status'], 'integer'], - [['Image', 'Remark'], 'string'], + [['time', 'status'], 'integer'], + [['image', 'remark'], 'string'], ]; } /** * {@inheritdoc} */ - public function attributeLabels() - { + public function attributeLabels() { return [ - 'ID' => 'ID', - 'Time' => 'Time', - 'Image' => 'Image', - 'Status' => 'Status', - 'Remark' => 'Remark', + 'id' => 'ID', + 'time' => 'Time', + 'image' => 'Image', + 'status' => 'Status', + 'remark' => 'Remark', ]; } + + public function create($data) { + $r = $this->load([ + 'time' => $data['Time'], + 'image' => $data["Image"], + 'status' => 0, + 'remark' => '' + ], ''); + if ($r) { + try { + $this->save(); + return $this->id; + } catch (\Exception $ex) { + return false; + } + } + } + + public static $statusArray = [ + 0 => "Unknown", + 1 => "List management" + ]; + } diff --git a/models/CaptureLogsSearch.php b/models/CaptureLogsSearch.php index 8c331ca7..91732989 100644 --- a/models/CaptureLogsSearch.php +++ b/models/CaptureLogsSearch.php @@ -18,8 +18,8 @@ class CaptureLogsSearch extends CaptureLogs public function rules() { return [ - [['ID', 'Time', 'Status'], 'integer'], - [['Image', 'Remark'], 'safe'], + [['id', 'time', 'status'], 'integer'], + [['image', 'remark'], 'safe'], ]; } @@ -59,13 +59,13 @@ class CaptureLogsSearch extends CaptureLogs // grid filtering conditions $query->andFilterWhere([ - 'ID' => $this->ID, - 'Time' => $this->Time, - 'Status' => $this->Status, + 'id' => $this->id, + 'time' => $this->time, + 'status' => $this->status, ]); - $query->andFilterWhere(['like', 'Image', $this->Image]) - ->andFilterWhere(['like', 'Remark', $this->Remark]); + $query->andFilterWhere(['like', 'image', $this->image]) + ->andFilterWhere(['like', 'remark', $this->remark]); return $dataProvider; } diff --git a/models/ListManagement.php b/models/ListManagement.php new file mode 100644 index 00000000..306c9fda --- /dev/null +++ b/models/ListManagement.php @@ -0,0 +1,82 @@ + 'ID', + 'type' => 'Type', + 'name' => 'Name', + 'image' => 'Registration Image', + 'gender' => 'Gender', + 'birthday' => 'Birthday', + 'telephone' => 'Telephone', + 'address' => 'Address', + 'time' => 'Registration time' + ]; + } + + public function create($data) { + $r = $this->load([ + 'type' => $data['type'], + 'name' => $data['name'], + 'image' => $data['image'], + 'gender' => $data['gender'], + 'birthday' => $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'), + 'telephone' => $data['telephone'], + 'address' => $data['address'], + 'time' => time() + ], ''); + if ($r) { + try { + $this->save(); + return $this->id; + } catch (\Exception $ex) { + return false; + } + } + } + + public static $typeArray = [ + "wl" => "Whitelist", + "bl" => "Blacklist" + ]; + +} diff --git a/models/ListManagementSearch.php b/models/ListManagementSearch.php new file mode 100644 index 00000000..d806c3d2 --- /dev/null +++ b/models/ListManagementSearch.php @@ -0,0 +1,72 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'birthday' => $this->birthday, + ]); + + $query->andFilterWhere(['like', 'type', $this->type]) + ->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'gender', $this->gender]) + ->andFilterWhere(['like', 'telephone', $this->telephone]) + ->andFilterWhere(['like', 'address', $this->address]); + + return $dataProvider; + } + +} diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index d6d16d66..86275d35 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,8 +1,8 @@ copy.src.files=false copy.src.on.open=false copy.src.target= -remote.connection=bf_local-799e1d +remote.connection=missing-config remote.directory=/BiFace_Server_Lite remote.upload=ON_SAVE -run.as=REMOTE +run.as=LOCAL url=http://localhost/ 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 21dda2c4..830e6c89 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 @@ -51,6 +51,16 @@ use yii\widgets\ActiveForm; Reset thiết bị +
  • + + List Management + +
  • +
  • + + Capture log + +