PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Signup/src/bitm/seip14/Signup/Signup.php

https://gitlab.com/Zamal/My-Web2-php
PHP | 338 lines | 299 code | 28 blank | 11 comment | 42 complexity | bea7bb6eed528aeec0a4ce7ed431b32d MD5 | raw file
  1. <?php
  2. namespace App\bitm\seip14\Signup;
  3. use PDO;
  4. class Signup {
  5. public $username='';
  6. public $firstname='';
  7. public $lastname='';
  8. public $password='';
  9. public $repassword='';
  10. public $data='';
  11. public $alldata='';
  12. public $email='';
  13. public $id='';
  14. public $conn='';
  15. public $uname='root';
  16. public $passwrd='';
  17. public $verification_id = '';
  18. //
  19. public $fullname='';
  20. public $fathername='';
  21. public $mothername='';
  22. public $birthdate='';
  23. public $gender='';
  24. public $mobile='';
  25. public $occapation='';
  26. public $education='';
  27. public $religion='';
  28. public $merital='';
  29. public $currentstatus='';
  30. public $nationality='';
  31. public $interest= '';
  32. public $bio='';
  33. public $nid='';
  34. public $passportnum='';
  35. public $skillarea='';
  36. public $language='';
  37. public $bloodgroup='';
  38. public $faxnum='';
  39. public $height='';
  40. public $addres='';
  41. public $weburl='';
  42. public $profilepic='';
  43. public $image='';
  44. public $other='';
  45. public function __construct() {
  46. session_start();
  47. date_default_timezone_set('Asia/Dhaka');
  48. $this->conn = new PDO("mysql:host=localhost;dbname=form", $this->uname, $this->passwrd);
  49. // set the PDO error mode to exception
  50. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  51. }
  52. public function prepare( $data='')
  53. {
  54. // echo "<pre>";
  55. // print_r($data);
  56. // die();
  57. if(!empty($data['username'])){
  58. $this->username=$data['username'];
  59. }
  60. if(!empty($data['firstname'])){
  61. $this->firstname=$data['firstname'];
  62. }
  63. if(!empty($data['lastname'])){
  64. $this->lastname=$data['lastname'];
  65. }
  66. if(!empty($data['password'])){
  67. $this->password= md5($data['password']);
  68. }
  69. if(!empty($data['re_password'])){
  70. $this->repassword=md5($data['re_password']);
  71. }
  72. if(!empty($data['email'])){
  73. $this->email=$data['email'];
  74. }
  75. if (!empty($data['vid'])) {
  76. $this->verification_id = $data['vid'];
  77. }
  78. if (!empty($data['fullname'])) {
  79. $this->fullname=$data['fullname'];
  80. }
  81. if (!empty($data['fathername'])) {
  82. $this->fathername=$data['fathername'];
  83. }
  84. if (!empty($data['mothername'])) {
  85. $this->mothername=$data['mothername'];
  86. }
  87. if (!empty($data['birthdate'])) {
  88. $this->birthdate=$data['birthdate'];
  89. }
  90. if (!empty($data['gender'])) {
  91. $this->gender=$data['gender'];
  92. }
  93. if (!empty($data['mobile'])) {
  94. $this->mobile=$data['mobile'];
  95. }
  96. if (!empty($data['occapation'])) {
  97. $this->occapation=$data['occapation'];
  98. }
  99. if (!empty($data['edstatus'])) {
  100. $this->education=$data['edstatus'];
  101. }
  102. if (!empty($data['religion'])) {
  103. $this->religion=$data['religion'];
  104. }
  105. if (!empty($data['merital'])) {
  106. $this->merital=$data['merital'];
  107. }
  108. if (!empty($data['currentstatus'])) {
  109. $this->currentstatus=$data['currentstatus'];
  110. }
  111. if (!empty($data['nationality'])) {
  112. $this->nationality=$data['nationality'];
  113. }
  114. if (!empty($data['biography'])) {
  115. $this->bio=$data['biography'];
  116. }
  117. if (!empty($data['passport'])) {
  118. $this->passportnum=$data['passport'];
  119. }
  120. if (!empty($data['faxnum'])) {
  121. $this->faxnum=$data['faxnum'];
  122. }
  123. if (!empty($data['height'])) {
  124. $this->height=$data['height'];
  125. }
  126. if (!empty($data['nid'])) {
  127. $this->nid=$data['nid'];
  128. }
  129. if (!empty($data['address'])) {
  130. $this->addres=$data['address'];
  131. }
  132. if (!empty($data['weburl'])) {
  133. $this->weburl=$data['weburl'];
  134. }
  135. if (!empty($data['other'])) {
  136. $this->other=$data['other'];
  137. }
  138. if(!empty($data['image'])){
  139. $this->image = $data['image'];
  140. }
  141. if(array_key_exists('id', $data))
  142. {
  143. $this->id =$data['id'];
  144. }
  145. $_SESSION['data']=$data;
  146. return $this;
  147. }
  148. public function index(){
  149. $qr="SELECT * FROM `signup`";
  150. $query = $this->conn->prepare($qr);
  151. $query->execute();
  152. while ($result = $query->fetch(PDO::FETCH_ASSOC)) {
  153. $this->data[] = $result;
  154. }
  155. return $this->data;
  156. }
  157. public function show()
  158. {
  159. $query = "SELECT * FROM profiles WHERE user_id=".$_SESSION['user']['id'];
  160. $STH = $this->conn->prepare($query);
  161. $STH->execute();
  162. $result = $STH->fetch(PDO::FETCH_ASSOC);
  163. return $result;
  164. }
  165. public function signup(){
  166. try {
  167. $usrname = "'$this->username'";
  168. $qr = "SELECT * FROM signup WHERE user_name=" . $usrname;
  169. $STH = $this->conn->prepare($qr);
  170. $STH->execute();
  171. $user = $STH->fetch(PDO::FETCH_ASSOC);
  172. $email = "'$this->email'";
  173. $qr = "SELECT * FROM signup WHERE email=" . $email;
  174. $STH = $this->conn->prepare($qr);
  175. $STH->execute();
  176. $user2 = $STH->fetch(PDO::FETCH_ASSOC);
  177. if (!empty($user)) {
  178. $_SESSION['username'] = "Username already exists";
  179. header('location:register.php');
  180. } elseif (!empty($user2)) {
  181. $_SESSION['username'] = "Already register with this email";
  182. header('location:register.php');
  183. } else {
  184. $verification_code = uniqid();
  185. $query="INSERT INTO signup(id, unique_id, verification_id, user_name, firstname, lastname, password, email, is_active, is_admin, created, modify, deleted)
  186. VALUES(:id, :u_id, :v_id, :uname, :fname, :lname, :pword, :email, :is_active, :is_admin, :created, :modify, :deleted)";
  187. $statement = $this->conn->prepare($query);
  188. $result =$statement->execute(array(
  189. ":id" => NULL,
  190. ":u_id" => uniqid(),
  191. ":v_id" => $verification_code,
  192. ":uname" => $this->username,
  193. ":fname" => $this->firstname,
  194. ":lname" => $this->lastname,
  195. ":pword" => $this->password,
  196. ":email" => $this->email,
  197. ":is_active" =>"0",
  198. ":is_admin" =>"0",
  199. ":created" => date("Y-m-d H:i:s"),
  200. ":modify" =>'',
  201. ":deleted" =>'',
  202. )
  203. );
  204. $_SESSION['success']="Successfully Registration";
  205. $msg = "Click the below link for verify your email address.<br/> http://zamalhossain.cse@gmail.com/Views/verify.php?vid=$verification_code";
  206. $msg = wordwrap($msg, 70);
  207. mail("$this->email", "zamalhossain.cse@gmail.com", $msg);
  208. $last_id = $this->conn->lastInsertId();
  209. $query="INSERT INTO profiles(id, user_id)VALUES(:id, :u_id)";
  210. $statement = $this->conn->prepare($query);
  211. $statement->execute(array(
  212. ":id" => NULL,
  213. ":u_id" => $last_id ,
  214. )
  215. );
  216. header('location:register.php');
  217. }
  218. } catch (Exception $ex) {
  219. echo 'Error: ' . $e->getMessage();
  220. }
  221. }
  222. public function login()
  223. {
  224. $usrname = "'$this->username'";
  225. $password = "'$this->password'";
  226. $qr = "select * from signup where user_name = $usrname && password = $password";
  227. $STH = $this->conn->prepare($qr);
  228. $STH->execute();
  229. $user = $STH->fetch(PDO::FETCH_ASSOC);
  230. // echo "<pre>";
  231. // print_r($user);
  232. // die();
  233. if (isset($user) && !empty($user)) {
  234. if ($user['is_active'] == 0) {
  235. $_SESSION['Message'] = "<h3>Your account not verified yet. Check your email and verify</h3>";
  236. header('location:login.php');
  237. } else {
  238. $_SESSION['user'] = $user;
  239. $_SESSION['loginmsg'] ="login successfully";
  240. header('location:index.php');
  241. }
  242. } else {
  243. $_SESSION['Message'] = "<h3>invalid username or password</h3>";
  244. header('location:login.php');
  245. }
  246. }
  247. public function verification()
  248. {
  249. $verification_code = "'" . $this->verification_id . "'";
  250. $qr = "SELECT * FROM users WHERE verification_id = $verification_code";
  251. $STH = $this->conn->prepare($qr);
  252. $STH->execute();
  253. $user = $STH->fetch(PDO::FETCH_ASSOC);
  254. // echo "<pre>";
  255. // print_r($user);
  256. // die();
  257. if (isset($user['verification'])) {
  258. $verification_code = "'" . $this->verification_id . "'";
  259. $query = "UPDATE users SET is_active = 1 WHERE verification_id =" . $verification_code;
  260. $STH = $this->conn->prepare($query);
  261. if ($STH->execute()) {
  262. $_SESSION['Message'] = "<h1>You're verified now. Thank you !</h1>";
  263. header('location:login.php');
  264. }
  265. }
  266. }
  267. // public function getSession(){
  268. // return @$_SESSION['login'];
  269. // }
  270. public function profileupdate(){
  271. $query = "UPDATE profiles SET full_name = :fn, father_name = :fnn, mother_name = :fnn, birthdate = :bdate, gender = :gender , "
  272. . "mobile_num = :mobile, occapation = :0cc, education_status = :edstatus, religion = :religion,"
  273. . "merital_status = :mstatus, current_status = :cstatus,"
  274. . "nationality = :nationality, biography = :bio, national_id = :nid, passport_num = :pnum,"
  275. . "fax_num = :fnum, height = :height, addresses = :addres, web_url = :wurl, other = :other,"
  276. . "modify = :modify WHERE user_id =".$_SESSION['user']['id'];
  277. // echo $query;
  278. // die();
  279. $stmt = $this->conn->prepare($query);
  280. $stmt->execute(array(
  281. ':fn' => $this->fullname,
  282. ':fnn' => $this->fathername,
  283. ':fnn' => $this->mothername,
  284. ':bdate' => $this->birthdate,
  285. ':gender' => $this->gender,
  286. ':mobile' => $this->mobile,
  287. ':0cc' => $this->occapation,
  288. ':edstatus' => $this->education,
  289. ':religion' => $this->religion,
  290. ':mstatus' => $this->merital,
  291. ':cstatus' => $this->currentstatus,
  292. ':nationality' => $this->nationality,
  293. ':bio' => $this->bio,
  294. ':nid' => $this->nid,
  295. ':pnum' => $this->passportnum,
  296. ':fnum' => $this->faxnum,
  297. ':height' => $this->height,
  298. ':addres' => $this->addres,
  299. ':wurl' => $this->weburl,
  300. ':other' => $this->other,
  301. ":modify" => date("Y-m-d H:i:s"),
  302. ));
  303. $_SESSION['Message'] = "Profile Successfully updated";
  304. header('location:index.php');
  305. }
  306. }