PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/register/register.php

https://gitlab.com/khairulcse76/exam
PHP | 261 lines | 207 code | 30 blank | 24 comment | 31 complexity | 6362f4b9d34b7082ca877c1f0e043427 MD5 | raw file
  1. <?php
  2. namespace examApps\register;
  3. use PDO;
  4. class register {
  5. public $bd_user = 'root';
  6. public $bd_pass = '';
  7. public $name = '';
  8. public $userName = '';
  9. public $password = '';
  10. public $email = '';
  11. public $unique_id = '';
  12. public $connection = '';
  13. public $contact = '';
  14. public $number = '';
  15. public function __construct() {
  16. session_start();
  17. date_default_timezone_set("Asia/Dhaka");
  18. $this->connection = new PDO('mysql:host=localhost;dbname=db_exam', $this->bd_user, '');
  19. }
  20. public function prepare($data = '') {
  21. // echo '<pre>';
  22. // print_r($data);
  23. if (array_key_exists('name', $data)) {
  24. $this->name = $data['name'];
  25. }
  26. if (array_key_exists('userName', $data)) {
  27. $this->userName = $data['userName'];
  28. }
  29. if (array_key_exists('password', $data)) {
  30. $this->password = $data['password'];
  31. }
  32. if (array_key_exists('email', $data)) {
  33. $this->email = $data['email'];
  34. }
  35. if (array_key_exists('contact', $data)) {
  36. $this->contact = $data['contact'];
  37. }
  38. if (array_key_exists('unique_id', $data)) {
  39. $this->unique_id = $data['unique_id'];
  40. }
  41. return $this;
  42. }
  43. public function registration() {
  44. try {
  45. $checkuser = "SELECT * FROM tbl_user WHERE userName=" . "'" . $this->userName . "'";
  46. $stmt = $this->connection->prepare($checkuser);
  47. $stmt->execute();
  48. $chkResult = $stmt->fetchAll();
  49. $checkemail = "SELECT * FROM tbl_user WHERE email=" . "'" . $this->email . "'";
  50. $emailstmt = $this->connection->prepare($checkemail);
  51. $emailstmt->execute();
  52. $emailResult = $emailstmt->fetchAll();
  53. if (!empty($chkResult) && isset($chkResult)) {
  54. echo '<span style="color: red;">User Name Already Exist</span>';
  55. exit();
  56. } else if (!empty($emailResult) && isset($emailResult)) {
  57. echo '<span style="color: red;">Email Already Exist</span>';
  58. exit();
  59. } else {
  60. $uniqueid = uniqid();
  61. $insertQuery = "INSERT INTO `tbl_user` (`unique_id`, `name`, `userName`, `email`, `userPass`,`Contact`,`status`, `is_delete`)
  62. VALUES('$uniqueid', '$this->name', '$this->userName', '$this->email', '$this->password','$this->contact', '1', '1')";
  63. // echo $insertQuery;
  64. // die();
  65. $smtminsert = $this->connection->prepare($insertQuery);
  66. $insertResult = $smtminsert->execute();
  67. if ($insertResult) {
  68. echo '<span style="color: Green;">Registration Successfull.</span>';
  69. } else {
  70. echo '<span style="color: red;">insert Error</span>';
  71. }
  72. }
  73. } catch (Exception $ex) {
  74. }
  75. }
  76. public function login() {
  77. if (empty($this->email) || empty($this->password)) {
  78. echo "empty";
  79. exit();
  80. } else {
  81. if (filter_var($this->email, FILTER_VALIDATE_EMAIL) === FALSE) {
  82. echo "email_error";
  83. exit();
  84. } else {
  85. try {
  86. $checkuserQuery = "SELECT * FROM tbl_user WHERE email=" . "'" . $this->email . "' and userPass=" . "'" . $this->password . "'";
  87. $checkuser = $this->connection->prepare($checkuserQuery);
  88. $checkuser->execute();
  89. $LoginResult = $checkuser->fetchAll();
  90. if ($LoginResult) {
  91. foreach ($LoginResult as $result) {
  92. if ($result['status'] == '0') {
  93. echo "disable";
  94. exit();
  95. } else {
  96. $_SESSION['user'] = $result['name'];
  97. $_SESSION['email'] = $result['email'];
  98. $_SESSION['id'] = $result['user_id'];
  99. }
  100. }
  101. // echo '<span style="color: Green;">Login Successfull.</span>';
  102. } else {
  103. echo 'error';
  104. exit();
  105. // echo '<span style="color: red;">E-mail or Password dose not Match....</span>';
  106. }
  107. } catch (Exception $ex) {
  108. }
  109. }
  110. }
  111. }
  112. public function logout() {
  113. unset($_SESSION['username']);
  114. unset($_SESSION['user']);
  115. unset($_SESSION['id']);
  116. header('location:index.php');
  117. }
  118. public function ProfileView() {
  119. $id = $_SESSION['id'];
  120. try {
  121. $query = "SELECT * FROM tbl_user WHERE user_id =$id ORDER BY user_id DESC";
  122. $stmt = $this->connection->prepare($query);
  123. $stmt->execute();
  124. $row = $stmt->fetchAll();
  125. // print_r($row);
  126. return $row;
  127. } catch (Exception $ex) {
  128. }
  129. }
  130. public function ProfileUpdate() {
  131. if (empty($this->userName) || empty($this->email)) {
  132. $_SESSION['empty'] = "<span style='color: red;'>Fill must be not empty...</span>";
  133. header("location:profileUpdate.php");
  134. } else {
  135. if (filter_var($this->email, FILTER_VALIDATE_EMAIL) === FALSE) {
  136. $_SESSION['empty'] = "<span style='color: red;'>Invalid Email Format</span>";
  137. header("location:profileUpdate.php");
  138. } else {
  139. try {
  140. // $updatecchekquery = "SELECT * FROM `tbl_user` WHERE unique_id =" . "'" . $this->unique_id . "' and `name` = '$this->name' and
  141. // `userName` = '$this->userName' and `email` = '$this->email' and `Contact` = '$this->contact'";
  142. //// echo $updatecchekquery; die();
  143. //
  144. //
  145. //
  146. // $stmtcheck = $this->connection->prepare($updatecchekquery);
  147. // $checkresult = $stmtcheck->execute();
  148. // $checkresult=$stmtcheck->fetchAl/**/l();
  149. //// print_r($checkresult);
  150. // die();
  151. // if ($checkresult=1) {
  152. // $_SESSION['empty'] = "<span style='color: #00cc66;'>Already up to date</span>";
  153. // header("location:profile.php");
  154. // } else {
  155. $query = "UPDATE `tbl_user` SET `name` = '$this->name', `userName` = '$this->userName', `email` = '$this->email',
  156. `Contact` = '$this->contact' WHERE unique_id =" . "'" . $this->unique_id . "'";
  157. // echo $query; die();
  158. $stmt = $this->connection->query($query);
  159. $update = $stmt->execute();
  160. if ($update) {
  161. $_SESSION['empty'] = "<span style='color: #00cc66;'>Successfully Profile updated</span>";
  162. header("location:profile.php");
  163. } else {
  164. $_SESSION['empty'] = "<span style='color: red;'>profile Update Fail.....!!!</span>";
  165. header("location:profileUpdate.php");
  166. }
  167. } catch (Exception $ex) {
  168. }
  169. }
  170. }
  171. }
  172. public function userdeactive() {
  173. $query = "UPDATE `tbl_user` SET `status` = '0' WHERE `tbl_user`.`unique_id` =" . "'" . $this->unique_id . "'";
  174. $stmt = $this->connection->prepare($query);
  175. $result = $stmt->execute();
  176. return $result;
  177. }
  178. public function userActive() {
  179. $query = "UPDATE `tbl_user` SET `status` = '1' WHERE `tbl_user`.`unique_id` =" . "'" . $this->unique_id . "'";
  180. // echo $query; die();
  181. $stmt = $this->connection->prepare($query);
  182. $result = $stmt->execute();
  183. return $result;
  184. }
  185. public function trush() {
  186. $query = "UPDATE `tbl_user` SET `is_delete` = '0' WHERE `tbl_user`.`unique_id` =" . "'" . $this->unique_id . "'";
  187. $stmt = $this->connection->prepare($query);
  188. $result = $stmt->execute();
  189. return $result;
  190. }
  191. public function RecycleBin() {
  192. $query = "UPDATE `tbl_user` SET `is_delete` = '0' WHERE `tbl_user`.`unique_id` =" . "'" . $this->unique_id . "'";
  193. $stmt = $this->connection->prepare($query);
  194. $result = $stmt->execute();
  195. return $result;
  196. }
  197. public function Restore() {
  198. $query = "UPDATE `tbl_user` SET `is_delete` = '1' WHERE `tbl_user`.`unique_id` =" . "'" . $this->unique_id . "'";
  199. $stmt = $this->connection->prepare($query);
  200. $result = $stmt->execute();
  201. return $result;
  202. }
  203. public function getquistion() {
  204. $query = "SELECT * FROM tbl_question";
  205. $stmt = $this->connection->prepare($query);
  206. $stmt->execute();
  207. $row = $stmt->fetch();
  208. return $row;
  209. }
  210. public function getrow() {
  211. $query = "SELECT count(*) FROM tbl_question";
  212. $stmt = $this->connection->query($query);
  213. $stmt->execute();
  214. $row = $stmt->fetchColumn();
  215. return $row;
  216. }
  217. public function getquistionbynum($number) {
  218. $query = "SELECT * FROM tbl_question WHERE questionNo=$number";
  219. $stmt = $this->connection->query($query);
  220. $stmt->execute();
  221. $row = $stmt->fetch();
  222. return $row;
  223. }
  224. public function getans($number) {
  225. $query = "SELECT * FROM tbl_ans WHERE questionNo=$number";
  226. $stmt = $this->connection->query($query);
  227. $stmt->execute();
  228. $row = $stmt->fetchAll();
  229. return $row;
  230. }
  231. }