PageRenderTime 25ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/day34_final_project/Final_Project/Group-3_Tonmoy/Bitm-Course-Manager-master-tonmoy/Src/assign_course/AssignCourse.php

https://gitlab.com/redwan4re/web-apps-php-26
PHP | 329 lines | 273 code | 48 blank | 8 comment | 43 complexity | d73c19b864411a7dfb45298993705fee MD5 | raw file
  1. <?php
  2. namespace BitmCourseApp\assign_course;
  3. use PDO;
  4. include_once (dirname(__FILE__) . '/../DBConnection/DBConnection.php');
  5. class AssignCourse extends \DBConnection {
  6. public $id = '';
  7. public $coursetitle = '';
  8. public $batchno = '';
  9. public $leadtrai = '';
  10. public $assistrai = '';
  11. public $labassis = '';
  12. public $labid = '';
  13. public $startdate = '';
  14. public $enddate = '';
  15. public $starttime = '';
  16. public $endtime = '';
  17. public $day = '';
  18. public $data = '';
  19. public $data1 = '';
  20. public $data2 = '';
  21. public $data3 = '';
  22. public $data4 = '';
  23. public $data5 = '';
  24. public $viewby = '';
  25. public $action = '';
  26. public $error;
  27. public function prepare($data = '') {
  28. if (!empty($data['id'])) {
  29. $this->id = $data['id'];
  30. }
  31. if (!empty($data['course_title'])) {
  32. $this->coursetitle = $data['course_title'];
  33. }
  34. if (!empty($data['batch_no'])) {
  35. $this->batchno = $data['batch_no'];
  36. }
  37. if (!empty($data['lead_trainer'])) {
  38. $this->leadtrai = $data['lead_trainer'];
  39. }
  40. if (!empty($data['assistant_trainer'])) {
  41. $this->assistrai = $data['assistant_trainer'];
  42. }
  43. if (!empty($data['lab_assistant'])) {
  44. $this->labassis = $data['lab_assistant'];
  45. }
  46. if (!empty($data['Lab_Id'])) {
  47. $this->labid = $data['Lab_Id'];
  48. }
  49. if (!empty($data['start_date'])) {
  50. $this->startdate = $data['start_date'];
  51. }
  52. if (!empty($data['end_date'])) {
  53. $this->enddate = $data['end_date'];
  54. }
  55. if (!empty($data['start_time'])) {
  56. $this->starttime = $data['start_time'];
  57. }
  58. if (!empty($data['end_time'])) {
  59. $this->endtime = $data['end_time'];
  60. }
  61. if (!empty($data['day_session'])) {
  62. $this->day = $data['day_session'];
  63. }
  64. if (!empty($data['viewBy'])) {
  65. $this->viewby = $data['viewBy'];
  66. }
  67. if (!empty($data['action'])) {
  68. $this->action = $data['action'];
  69. }
  70. return $this;
  71. }
  72. public function assignCourseValidation() {
  73. $required = array(
  74. 'Course_Tilte' => $this->coursetitle,
  75. 'Batch_No' => $this->batchno,
  76. 'Lead_Trainer' => $this->leadtrai,
  77. 'Assis_Trainer' => $this->assistrai,
  78. 'Lab_Assis' => $this->assistrai,
  79. 'Lab_Id' => $this->labid,
  80. 'Start_Date' => $this->startdate,
  81. 'End_Date' => $this->enddate,
  82. 'Start_Time' => $this->starttime,
  83. 'End_Time' => $this->endtime,
  84. 'Day' => $this->day
  85. );
  86. foreach ($required as $key => $field) {
  87. if (empty($field)) {
  88. $_SESSION["$key"] = 'Required';
  89. $this->error = TRUE;
  90. }
  91. }
  92. }
  93. public function store() {
  94. if ($this->error == FALSE) {
  95. try {
  96. $query = "INSERT INTO `course_trainer_lab_mapping` (`id`, `course_id`, `batch_no`, `lead_trainer`, `asst_trainer`, `lab_asst`, `lab_id`, `start_date`, `ending_date`, `start_time`, `ending_time`, `day`, `is_running`, `assigned_by`, `created`, `updated`, `deleted`) VALUES ('', :courseid , :batchno, :leadtrainer , :assttrainer , :labasst , :labid , :startdate , :endingdate , :starttime , :endtime , :day , :isrunning , :assignby , :created , '', '')";
  97. $stmt = $this->conn->prepare($query);
  98. $stmt->execute(array(
  99. ':courseid' => $this->coursetitle,
  100. ':batchno' => $this->batchno,
  101. ':leadtrainer' => $this->leadtrai,
  102. ':assttrainer' => $this->assistrai,
  103. ':labasst' => $this->labassis,
  104. ':labid' => $this->labid,
  105. ':startdate' => $this->startdate,
  106. ':endingdate' => $this->enddate,
  107. ':starttime' => $this->starttime,
  108. ':endtime' => $this->endtime,
  109. ':day' => $this->day,
  110. ':isrunning' => 1,
  111. ':assignby' => $_SESSION['login_confirm']['username'],
  112. ':created' => date("Y-m-d h:i:s"),
  113. ));
  114. $_SESSION['message'] = "New Course Assigned Successfully.";
  115. } catch (PDOException $e) {
  116. echo 'Error: ' . $e->getMessage();
  117. }
  118. }
  119. header('location:assign_new_course.php');
  120. }
  121. public function viewAssignedCourse() {
  122. try {
  123. if ($this->viewby == 'running') {
  124. $vq = "SELECT * FROM `course_trainer_lab_mapping` WHERE is_running=1 ";
  125. } else {
  126. $vq = "SELECT * FROM `course_trainer_lab_mapping` WHERE is_running=0 ";
  127. }
  128. $view_query = $this->conn->prepare($vq);
  129. $view_query->execute();
  130. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  131. $this->data[] = $row;
  132. }
  133. return $this->data;
  134. } catch (Exception $ex) {
  135. }
  136. }
  137. public function showAssignedCourse() {
  138. try {
  139. $query = $this->conn->query("SELECT * FROM course_trainer_lab_mapping WHERE id='$this->id' ");
  140. $row = $query->fetch();
  141. return $row;
  142. } catch (Exception $ex) {
  143. }
  144. return $row;
  145. }
  146. public function courseTitle() {
  147. try {
  148. $vq = "SELECT * FROM `courses` ";
  149. $view_query = $this->conn->prepare($vq);
  150. $view_query->execute();
  151. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  152. $this->data1[] = $row;
  153. }
  154. return $this->data1;
  155. } catch (Exception $ex) {
  156. }
  157. }
  158. public function leadTrainer() {
  159. try {
  160. $vq = "SELECT * FROM `trainers` WHERE `trainer_status` = 'lead_trainer' ";
  161. $view_query = $this->conn->prepare($vq);
  162. $view_query->execute();
  163. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  164. $this->data2[] = $row;
  165. }
  166. return $this->data2;
  167. } catch (Exception $ex) {
  168. }
  169. }
  170. public function assitTrainer() {
  171. try {
  172. $vq = "SELECT * FROM `trainers` WHERE `trainer_status` = 'assist_trainer' ";
  173. $view_query = $this->conn->prepare($vq);
  174. $view_query->execute();
  175. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  176. $this->data3[] = $row;
  177. }
  178. return $this->data3;
  179. } catch (Exception $ex) {
  180. }
  181. }
  182. public function labAssit() {
  183. try {
  184. $vq = "SELECT * FROM `trainers` WHERE `trainer_status` = 'lab_assist' ";
  185. $view_query = $this->conn->prepare($vq);
  186. $view_query->execute();
  187. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  188. $this->data4[] = $row;
  189. }
  190. return $this->data4;
  191. } catch (Exception $ex) {
  192. }
  193. }
  194. public function labInfo() {
  195. try {
  196. $vq = "SELECT * FROM `labinfo` ";
  197. $view_query = $this->conn->prepare($vq);
  198. $view_query->execute();
  199. while ($row = $view_query->fetch(PDO::FETCH_ASSOC)) {
  200. $this->data5[] = $row;
  201. }
  202. return $this->data5;
  203. } catch (Exception $ex) {
  204. }
  205. }
  206. public function search($search = "")
  207. { //print_r($search);
  208. //die();
  209. if ($search['search_key'] == 'course' && !empty($search['var1'])) {
  210. $keywords = $search['var1'];
  211. //print_r($keywords);
  212. //die();
  213. $keywords = preg_split('/[\s]+/', $keywords);
  214. $totalKeywords = count($keywords);
  215. $query = "SELECT * FROM courses LEFT JOIN course_trainer_lab_mapping on courses.id = course_trainer_lab_mapping.course_id LEFT JOIN labinfo on courses.id = labinfo.course_id WHERE courses.title LIKE ?";
  216. for($i=1 ; $i < $totalKeywords; $i++){
  217. $query .= " AND title LIKE ? ";
  218. }
  219. $sql=$this->conn->prepare($query);
  220. foreach($keywords as $key => $keyword){
  221. $search = '%'.$keyword.'%';
  222. $sql->bindParam($key+1, $search);
  223. }
  224. $sql->execute ();
  225. if ($sql->rowCount() > 0) {
  226. while ($result=$sql->fetch(PDO::FETCH_ASSOC)) {
  227. //echo"<pre>".print_r($result,true)."</pre>";
  228. $this->data[] = $result;
  229. }
  230. } else {
  231. $_SESSION['msg'] = 'There was nothing to show. Please search with right keyword.';
  232. }
  233. //return $this->data;
  234. }
  235. elseif ($search['search_key'] == 'lab' && !empty($search['var1'])) {
  236. $keywords = $search['var1'];
  237. //print_r($keywords);
  238. //die();
  239. $keywords = preg_split('/[\s]+/', $keywords);
  240. $totalKeywords = count($keywords);
  241. $query = "SELECT * FROM labinfo LEFT JOIN course_trainer_lab_mapping on labinfo.id = course_trainer_lab_mapping.lab_id LEFT JOIN courses on course_trainer_lab_mapping.course_id = courses.id WHERE labinfo.lab_no LIKE ?";
  242. for($i=1 ; $i < $totalKeywords; $i++){
  243. $query .= " AND lab_no LIKE ? ";
  244. }
  245. $sql=$this->conn->prepare($query);
  246. foreach($keywords as $key => $keyword){
  247. $search = '%'.$keyword.'%';
  248. $sql->bindParam($key+1, $search);
  249. }
  250. $sql->execute ();
  251. if ($sql->rowCount() > 0) {
  252. while ($result=$sql->fetch(PDO::FETCH_ASSOC)) {
  253. //echo"<pre>".print_r($result,true)."</pre>";
  254. $this->data[] = $result;
  255. }
  256. } else {
  257. $_SESSION['msg'] = 'There was nothing to show. Please search with right keyword.';
  258. }
  259. }
  260. else {
  261. echo "Please search with right keyword";
  262. }
  263. return $this->data;
  264. }
  265. public function deleteAssigned() {
  266. try {
  267. if ($this->action == 'restore') {
  268. $query = "UPDATE `course_trainer_lab_mapping` SET `is_running` = '1', `deleted` = :date WHERE `course_trainer_lab_mapping`.`id` = $this->id";
  269. } else {
  270. $query = "UPDATE `course_trainer_lab_mapping` SET `is_running` = '0', `deleted` = :date WHERE `course_trainer_lab_mapping`.`id` = $this->id";
  271. }
  272. $stmt = $this->conn->prepare($query);
  273. $stmt->execute(array(
  274. ':date'=> date("Y-m-d h:i:s")
  275. ));
  276. header("location:view_assigned_course.php?viewBy=$this->viewby");
  277. } catch (PDOException $e) {
  278. echo 'Error: ' . $e->getMessage();
  279. }
  280. }
  281. }