/Src/Course/courses.php

https://gitlab.com/Sazzad_Ahmed/bitmlabmanagement · PHP · 220 lines · 177 code · 39 blank · 4 comment · 17 complexity · 5a5058c0cb6ffaaa6517b808b6316356 MD5 · raw file

  1. <?php
  2. namespace Apps\Course;
  3. use PDO;
  4. class courses {
  5. public $title,$duration,$description,$totalhours,$hoursperday,$daysperweek,$coursetype,$coursefee,$isactive,$isoffer;
  6. public $unique_id,$conn,$search,$email,$password;
  7. public function __construct() {
  8. @session_start();
  9. $host = 'localhost';
  10. $user = 'root';
  11. $password = '';
  12. $db = 'bitm';
  13. $this->conn = new PDO("mysql:host=$host;dbname=$db", "$user", "$password");
  14. }
  15. public function prepare($data) {
  16. //print_r($data);
  17. if(array_key_exists('email', $data))
  18. {
  19. $this->email=$data['email'];
  20. }
  21. if(array_key_exists('password', $data))
  22. {
  23. $this->password=$data['password'];
  24. }
  25. if(array_key_exists('unique_id', $data))
  26. {
  27. $this->unique_id=$data['unique_id'];
  28. }
  29. if(array_key_exists('title', $data))
  30. {
  31. $this->title=$data['title'];
  32. }
  33. if(array_key_exists('duration', $data))
  34. {
  35. $this->duration=$data['duration'];
  36. }
  37. if(array_key_exists('description', $data))
  38. {
  39. $this->description=$data['description'];
  40. }
  41. if(array_key_exists('totalhours', $data))
  42. {
  43. $this->totalhours=$data['totalhours'];
  44. }
  45. if(array_key_exists('hoursperday', $data))
  46. {
  47. $this->hoursperday=$data['hoursperday'];
  48. }
  49. if(array_key_exists('daysperweeeks', $data))
  50. {
  51. $this->daysperweeeks=$data['daysperweeeks'];
  52. }
  53. if(array_key_exists('coursetype', $data))
  54. {
  55. $this->coursetype=$data['coursetype'];
  56. if($this->coursetype=='paid')
  57. {
  58. $this->coursefee=$data['coursefee'];
  59. }
  60. else
  61. {
  62. $this->coursefee=0;
  63. }
  64. }
  65. if(array_key_exists('isactive', $data))
  66. {
  67. $this->isactive=$data['isactive'];
  68. }
  69. if(array_key_exists('isoffer', $data))
  70. {
  71. $this->isoffer=$data['isoffer'];
  72. }
  73. if(array_key_exists('search', $data))
  74. {
  75. $this->search=$data['search'];
  76. }
  77. //echo $this->unique_id;
  78. return $this;
  79. }
  80. public function store() {
  81. try {
  82. $sql = "INSERT INTO `courses`(`id`,`unique_id`,`title`,`duration`,`description`,`course_type`,`course_fee`,`is_offer`,`created`,`totalhour`)
  83. VALUES(:i,:ui,:un,:ps,:em,:vr,:ia,:cr,:tr,:th)";
  84. $query = $this->conn->prepare($sql);
  85. $query->execute(array(
  86. ':i' => NULL,
  87. ':ui' => uniqid(),
  88. ':un' => $this->title,
  89. ':ps' => $this->duration,
  90. ':em' => $this->description,
  91. ':vr' =>$this->coursetype ,
  92. ':ia' => $this->coursefee,
  93. ':cr' => $this->isoffer,
  94. ':tr'=>date('Y-m-d-h-i-s'),
  95. ':th'=> $this->totalhours
  96. ));
  97. header('Location:index.php');
  98. } catch (Exception $ex) {
  99. }
  100. }
  101. public function titleexist()
  102. {
  103. $sql = $this->conn->prepare("SELECT `title` FROM `courses` WHERE `title`='$this->title'");
  104. $sql->execute();
  105. return $sql->rowCount();
  106. }
  107. public function index() {
  108. $sql = $this->conn->prepare("SELECT * FROM `courses` ORDER BY `created` DESC");
  109. $sql->execute();
  110. while ($result = $sql->fetch(PDO::FETCH_ASSOC)) {
  111. $this->row[] = $result;
  112. }
  113. return $this->row;
  114. }
  115. public function delete() {
  116. echo $this->unique_id;
  117. $sql = "DELETE FROM `courses` WHERE `unique_id`= :filmID";
  118. $stmt = $this->conn->prepare($sql);
  119. $stmt->bindParam(':filmID', $this->unique_id, PDO::PARAM_INT);
  120. $stmt->execute();
  121. }
  122. public function show() {
  123. // echo $this->uniqe_id;
  124. $sql = $this->conn->prepare("SELECT * FROM `courses` WHERE `unique_id`='$this->unique_id'");
  125. $sql->execute();
  126. while ($result = $sql->fetch(PDO::FETCH_ASSOC)) {
  127. return $result;
  128. }
  129. }
  130. public function update()
  131. {
  132. $sql = "UPDATE courses SET title = :fn,duration = :dr,description= :des,course_type= :ct,course_fee= :cf,is_offer=:io,updated=:up WHERE unique_id = :un";
  133. $query = $this->conn->prepare($sql);
  134. $query->execute(array(
  135. ':fn' => $this->title,
  136. ':dr'=> $this->duration,
  137. ':des'=> $this->description,
  138. ':ct'=> $this->coursetype,
  139. ':cf'=> $this->coursefee,
  140. ':io'=> $this->isoffer,
  141. ':up'=>date('Y-m-d-h-i-s'),
  142. ':un'=>$this->unique_id
  143. ));
  144. //header('Location:index.php');
  145. }
  146. public function search()
  147. {
  148. $query = 'SELECT * FROM courses WHERE title LIKE :search';
  149. $stmt= $this->conn->prepare($query);
  150. $stmt->execute(array(':search' => '%'.$this->search.'%'));
  151. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  152. return $result;
  153. }
  154. public function numrowbyname()
  155. {
  156. $sql = $this->conn->prepare("SELECT * FROM `courses` WHERE `title`='$this->title'");
  157. $sql->execute();
  158. return $sql->rowCount();
  159. }
  160. public function login()
  161. {
  162. $sql = $this->conn->prepare("SELECT * FROM `users` WHERE `email`='$this->email' AND `password`='$this->password'");
  163. $sql->execute();
  164. $result = $sql->fetch(PDO::FETCH_ASSOC);
  165. if($sql->rowCount()!=0)
  166. {
  167. return $result;
  168. }
  169. else
  170. {
  171. return 0;
  172. }
  173. }
  174. public function databyemail()
  175. {
  176. $sql = $this->conn->prepare("SELECT * FROM `users` WHERE `email`='$this->email'");
  177. $sql->execute();
  178. $result = $sql->fetch(PDO::FETCH_ASSOC);
  179. return $result;
  180. }
  181. }