From 691a223a4d9e3b9cbab345abe150f4b61d6e69fe Mon Sep 17 00:00:00 2001 From: Khalid Sadat Date: Thu, 31 Mar 2022 14:34:36 -0400 Subject: [PATCH] User can now generate baby reg link by clicking Share icon: #130 --- app/controllers/BabyRegistryController.php | 46 ++++++++++++ app/models/BabyRegistryToken.php | 50 +++++++++++++ app/views/baby_registry/index.php | 81 +++++++++++++++++---- app/views/include/footer.php | 40 ++++++++++ assets/icons/copy.png | Bin 0 -> 1193 bytes assets/icons/link.png | Bin 0 -> 3037 bytes assets/icons/option.png | Bin 0 -> 1003 bytes assets/icons/settings.png | Bin 0 -> 4219 bytes 8 files changed, 204 insertions(+), 13 deletions(-) create mode 100644 app/models/BabyRegistryToken.php create mode 100644 assets/icons/copy.png create mode 100644 assets/icons/link.png create mode 100644 assets/icons/option.png create mode 100644 assets/icons/settings.png diff --git a/app/controllers/BabyRegistryController.php b/app/controllers/BabyRegistryController.php index 564907a..7a7af2b 100644 --- a/app/controllers/BabyRegistryController.php +++ b/app/controllers/BabyRegistryController.php @@ -1,6 +1,50 @@ = $range); + return $min + $rnd; + } + + private function getToken($length=12){ + $token = ""; + $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $codeAlphabet.= "0123456789"; + for($i=0;$i<$length;$i++){ + $token .= $codeAlphabet[$this->crypto_rand_secure(0,strlen($codeAlphabet))]; + } + return $token; + } + + // Generate shareable uniqe key + public function generate() { + $data = []; + $token = $this->getToken(37); + + $baby_reg_id = $_POST['baby_registry_id']; + + // Baby reg token + $baby_reg_token = $this->model('BabyRegistryToken'); + $baby_reg_token->baby_registry_id = $baby_reg_id; + $baby_reg_token->token = $token; + $baby_reg_token->status = 1; + $baby_reg_token->insert(); + + $data['success'] = true; + $data['token'] = $token; + + echo json_encode($data); + } + // Function that shows the index page when you type 'localhost' public function index(){ @@ -12,4 +56,6 @@ public function add() { $this->view('BASE_STRUCTURES/empty_view'); } + + } \ No newline at end of file diff --git a/app/models/BabyRegistryToken.php b/app/models/BabyRegistryToken.php new file mode 100644 index 0000000..2a5f7ac --- /dev/null +++ b/app/models/BabyRegistryToken.php @@ -0,0 +1,50 @@ +prepare("SELECT * FROM baby_registry_tokens"); + $stmt->execute(); + $stmt->setFetchMode(PDO::FETCH_CLASS, 'BabyRegistryToken'); + return $stmt->fetchAll(); + } + + public function find($token_id){ + $stmt = self::$_connection->prepare("SELECT * FROM baby_registry_tokens WHERE token_id = :token_id"); + $stmt->execute(['token_id'=>$token_id]); + $stmt->setFetchMode(PDO::FETCH_CLASS, 'BabyRegistryToken'); + return $stmt->fetch(); + } + + public function findByBabyRegistryId($baby_registry_id){ + $stmt = self::$_connection->prepare("SELECT * FROM baby_registry_tokens WHERE baby_registry_id = :baby_registry_id"); + $stmt->execute(['baby_registry_id'=>$baby_registry_id]); + $stmt->setFetchMode(PDO::FETCH_CLASS, 'BabyRegistryToken'); + return $stmt->fetch(); + } + + public function insert(){ + $stmt = self::$_connection->prepare("INSERT INTO baby_registry_tokens(baby_registry_id, token, status) VALUES(:baby_registry_id, :token, :status)"); + $stmt->execute(['baby_registry_id'=>$this->baby_registry_id, + 'token'=>$this->token, + 'status'=>$this->status]); + $_SESSION['updated_address_id'] = self::$_connection->lastInsertId(); + } + + public function delete(){ + $stmt = self::$_connection->prepare("DELETE FROM baby_registry_tokens WHERE brand_id = :brand_id"); + $stmt->execute(['brand_id'=>$this->brand_id]); + } + + public function updateStatus(){ + $stmt = self::$_connection->prepare("UPDATE baby_registry_tokens SET brand_name = :brand_name WHERE brand_id = :brand_id"); + $stmt->execute(['brand_name'=>$this->brand_name, + 'brand_id'=>$this->brand_id]); + } + +} +?> \ No newline at end of file diff --git a/app/views/baby_registry/index.php b/app/views/baby_registry/index.php index fa3b10d..81dfed2 100644 --- a/app/views/baby_registry/index.php +++ b/app/views/baby_registry/index.php @@ -57,9 +57,6 @@ - @@ -72,19 +69,75 @@

My Baby Registry

- something +
-
-
-

Add Items

- - sometihng +
+
+ SETTINGS + - + + + + + + MORE +
+ +
+
+
+
+ +
+
+ +
+
+
+
+ + +
+ + +
+
+ Another Title +
+
+ + Created by Khalid on 1 February, 2022 + +
+
+
+ SETTINGS + + + + SHARE + + + + MORE +
+
+
@@ -103,6 +156,8 @@ + + view('include/footer'); diff --git a/app/views/include/footer.php b/app/views/include/footer.php index 4110df0..062d3fb 100644 --- a/app/views/include/footer.php +++ b/app/views/include/footer.php @@ -179,6 +179,46 @@ function shownTabsHandler(e) { + + + + + + +