PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/MiniProject/src/BITM/SimpleRegistrationForm/Registration.php

https://gitlab.com/swajib/MiniProject_Conception_B11
PHP | 284 lines | 178 code | 93 blank | 13 comment | 28 complexity | 99db1d3961892bfa67da5764d3a813e9 MD5 | raw file
  1. <?php
  2. namespace App\BITM\SimpleRegistrationForm;
  3. use App\Requered;
  4. use App\BITM\Utility\Utility;
  5. class Registration {
  6. public $id;
  7. public $fname;
  8. public $lname;
  9. public $birthday;
  10. public $email;
  11. public $cemail;
  12. public $phonenumber;
  13. public $city;
  14. public $religious;
  15. public $gender;
  16. public $aboutme;
  17. public $termandcondition;
  18. public $deleted_at;
  19. public function __construct($data = false) {
  20. if (is_array($data) && array_key_exists("id", $data) && !empty($data['id'])) {
  21. $this->id = $data['id'];
  22. }
  23. $this->fname = $data['fname'];
  24. $this->lname = $data['lname'];
  25. $this->birthday = $data['birthday'];
  26. $this->email = $data['email'];
  27. $this->cemail = $data['cemail'];
  28. $this->phonenumber = $data['phonenumber'];
  29. $this->city = $data['city'];
  30. $this->religious = $data['religious'];
  31. $this->gender = $data['gender'];
  32. $this->aboutme = $data['aboutme'];
  33. $this->termandcondition = $data['termandcondition'];
  34. }
  35. public function lists() {
  36. $registrations = array();
  37. $conn = mysql_connect("localhost", "root", "");
  38. $lnk = mysql_select_db("miniproject");
  39. $query = "SELECT * FROM `registrations` WHERE deleted_at IS NULL";
  40. $result = mysql_query($query);
  41. while ($row = mysql_fetch_object($result)) {
  42. $registrations [] = $row;
  43. }
  44. return $registrations;
  45. }
  46. public function show($id = null) {
  47. if (!$id) {
  48. Utility::massage("No id is avaiable!sorry");
  49. }
  50. $conn = mysql_connect("localhost", "root", "");
  51. $lnk = mysql_select_db("miniproject");
  52. $query = "SELECT * FROM `registrations` WHERE id=" . $id;
  53. $result = mysql_query($query);
  54. $row = mysql_fetch_object($result);
  55. return $row;
  56. }
  57. public function delete($id = false) {
  58. if (!$id) {
  59. Utility::massage("No id is avaiable!sorry");
  60. }
  61. $conn = mysql_connect("localhost", "root", "");
  62. $lnk = mysql_select_db("miniproject");
  63. $query = "DELETE FROM `miniproject`.`registrations` WHERE `registrations`.`id` =" . $id;
  64. $result = mysql_query($query);
  65. // var_dump($result);
  66. // die();
  67. if ($result) {
  68. Utility::massage("Data deletion succesfull");
  69. } else {
  70. Utility::massage("Cannot delete");
  71. }
  72. Utility::redirect("lists.php");
  73. }
  74. public function trash($id = false) {
  75. if (!$id) {
  76. Utility::massage("No id is avaiable!sorry");
  77. }
  78. //$this->id= $id;
  79. $this->deleted_at = time();
  80. $conn = mysql_connect("localhost", "root", "");
  81. $lnk = mysql_select_db("miniproject");
  82. $query = "UPDATE `miniproject`.`registrations` SET `deleted_at` = '" . $this->deleted_at . "' WHERE `registrations`.`id` =" . $id;
  83. $result = mysql_query($query);
  84. // var_dump($result);
  85. // die();
  86. if ($result) {
  87. Utility::massage("Data trashed succesfully");
  88. } else {
  89. Utility::massage("Cannot trash");
  90. }
  91. Utility::redirect("lists.php");
  92. }
  93. public function trashed() {
  94. $registrations = array();
  95. $conn = mysql_connect("localhost", "root", "");
  96. $lnk = mysql_select_db("miniproject");
  97. $query = "SELECT * FROM `registrations` WHERE deleted_at IS NOT NULL";
  98. $result = mysql_query($query);
  99. while ($row = mysql_fetch_object($result)) {
  100. $registrations [] = $row;
  101. }
  102. return $registrations;
  103. }
  104. public function recover($id = false) {
  105. if (!$id) {
  106. Utility::massage("No id is avaiable!sorry");
  107. }
  108. $conn = mysql_connect("localhost", "root", "");
  109. $lnk = mysql_select_db("miniproject");
  110. $query = "UPDATE `miniproject`.`registrations` SET `deleted_at` = NULL WHERE `registrations`.`id` =" . $id;
  111. $result = mysql_query($query);
  112. if ($result) {
  113. Utility::massage("Data recovered succesfully");
  114. } else {
  115. Utility::massage("Cannot recovered");
  116. }
  117. Utility::redirect("lists.php");
  118. }
  119. public function update() {
  120. if (!$id) {
  121. Utility::massage("No id is avaiable!sorry");
  122. }
  123. // $this->deleted_at = time();
  124. $conn = mysql_connect("localhost", "root", "");
  125. $lnk = mysql_select_db("miniproject");
  126. $query = "UPDATE `miniproject`.`registrations` SET `fname` = '" . $this->fname . "', `lname` = '" . $this->lname . "',"
  127. . " `birthday` = '" . $this->birthday . "', `email` = '" . $this->email . "', `cemail` = '" . $this->cemail . "', `phonenumber` = '" . $this->phonenumber . "',"
  128. . " `city` = '" . $this->city . "', `gender` = '" . $this->gender . "', `religious` = '" . $this->religious . "', `aboutme` = '" . $this->aboutme . " ' "
  129. ." WHERE `registrations`.`id` = " . $this->id;
  130. // var_dump($query);
  131. // die();
  132. $result = mysql_query($query);
  133. if ($result) {
  134. Utility::massage("Data is updated succesfully !!!");
  135. } else {
  136. Utility::massage("Sorry !! Cannot update");
  137. }
  138. Utility::redirect("lists.php");
  139. }
  140. public function store() {
  141. $conn = mysql_connect("localhost", "root", "");
  142. $lnk = mysql_select_db("miniproject");
  143. $query = "INSERT INTO `miniproject`.`registrations` ( `fname`, `lname`, `birthday`, `email`, `cemail`, `phonenumber`, `city`, `gender`, `religious`, `aboutme`, `termandcondition`) VALUES "
  144. . "('" . $this->fname . "','" . $this->lname . "','" . $this->birthday . "','" . $this->email . "','" . $this->cemail . "','" . $this->phonenumber . "','" . $this->city . "','" . $this->gender . "','" . $this->religious . "','" . $this->aboutme . "','" . $this->termandcondition . "')";
  145. $result = mysql_query($query);
  146. // var_dump($result);
  147. // die();
  148. if ($result) {
  149. Utility::massage("I am storing data succesfully");
  150. } else {
  151. Utility::massage("Data storing failed");
  152. }
  153. Utility::redirect("lists.php");
  154. }
  155. public function recoverall($ids = array()){
  156. // var_dump($ids);
  157. if(is_array($ids) && count($ids)>0){
  158. $_id = implode(", ", $ids);
  159. $query = "UPDATE `registrations` SET `deleted_at` = NULL WHERE `registrations`.`id` IN ($_id)";
  160. $result = mysql_query($query);
  161. if ($result) {
  162. Utility::massage("Data recovered succesfully");
  163. } else {
  164. Utility::massage("Cannot recovered");
  165. }
  166. Utility::redirect("lists.php");
  167. }
  168. }
  169. public function deleteall($ids = array()){
  170. if(is_array($ids) && count($ids)>0){
  171. $_id = implode(", ", $ids);
  172. $conn = mysql_connect("localhost", "root", "");
  173. $lnk = mysql_select_db("miniproject");
  174. $query = "DELETE FROM `miniproject`.`registrations` WHERE `registrations`.`id` IN($_id)";
  175. $result = mysql_query($query);
  176. // var_dump($result);
  177. // die();
  178. if ($result) {
  179. Utility::massage("Data deletion succesfull");
  180. } else {
  181. Utility::massage("Cannot delete");
  182. }
  183. Utility::redirect("lists.php");
  184. }
  185. }
  186. public function logout(){
  187. session_destroy();
  188. Requered::success_message("You are successfully logged out !!!");
  189. Requered::redirectout();
  190. }
  191. }