PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/exam7/crud/src/bitm/seip131181/semister/Semister.php

https://gitlab.com/mehedi-xion/web_apps_php_26
PHP | 164 lines | 86 code | 75 blank | 3 comment | 17 complexity | 07e2b79664be1a0699fa8b183ff1f745 MD5 | raw file
  1. <?php
  2. namespace SemisterApp\bitm\seip131181\mobile ;
  3. /**
  4. * class for Semister App
  5. */
  6. class Semister
  7. {
  8. public $id = '';
  9. public $name = '';
  10. public $semister = '';
  11. public $offer = '';
  12. public $cost = '';
  13. public $waiver = '';
  14. public $total = '';
  15. public $data = '';
  16. function __construct()
  17. {
  18. session_start();
  19. $sql_conn = mysql_connect('localhost', 'root', '') or die("ups! not connect to database");
  20. mysql_select_db('web_apps_php_26') or die("Wrong Database name");
  21. }
  22. public function prepare($data = ''){
  23. if(array_key_exists('fname', $data)){
  24. $this->name = $data['fname'];
  25. }
  26. if(array_key_exists('semister', $data)){
  27. $this->semister = $data['semister'];
  28. }
  29. if(array_key_exists('offer', $data)){
  30. $this->offer = $data['offer'];
  31. }
  32. if(array_key_exists('id', $data)){
  33. $this->id = $data['id'];
  34. }
  35. if($this->semister == '1st Semister'){ $this->cost = 8000;}
  36. if($this->semister == '2nd Semister'){ $this->cost = 12000;}
  37. if($this->semister == '3rd Semister'){ $this->cost = 16000;}
  38. if($this->offer == "offered"){$this->waiver = ($this->cost * 10)/100;}else{
  39. $this->offer = "Not Offered";
  40. $this->waiver = 0;
  41. }
  42. if ($this->offer == "Not Offered") {
  43. $this->waiver = 0;
  44. }
  45. $this->total = ($this->cost - $this->waiver);
  46. return $this ;
  47. }// prepare \\
  48. public function store(){
  49. $query = "INSERT INTO `web_apps_php_26`.`semister` (`id`, `name`, `semister`, `offer`, `cost`, `waiver`, `total`, `unique_id`) VALUES (NULL, '$this->name', '$this->semister', '$this->offer', '$this->cost', '$this->waiver', '$this->total','".uniqid()."')";
  50. if(mysql_query($query)){
  51. $_SESSION['Message'] = " Data Added Succesfully ";
  52. }
  53. header("location:creat.php");
  54. } // store \\
  55. public function index(){
  56. $query = "SELECT * FROM `semister` ";
  57. $result = mysql_query($query);
  58. while($row = mysql_fetch_assoc($result)){
  59. $this->data[] = $row;
  60. }
  61. return $this->data;
  62. } // index \\
  63. public function show(){
  64. $query = "SELECT * FROM `semister` WHERE unique_id = '".$this->id."' ";
  65. $result = mysql_query($query);
  66. $row = mysql_fetch_assoc($result);
  67. return $row;
  68. } // show \\
  69. public function update(){
  70. $query = "UPDATE `web_apps_php_26`.`semister` SET `name` = '$this->name', `semister` = '$this->semister', `offer` = '$this->offer', `cost` = '$this->cost', `waiver` = '$this->waiver', `total` = '$this->total' WHERE `semister`.`unique_id` = '".$this->id."'";
  71. if($result = mysql_query($query)){
  72. $_SESSION['UpdtMsg'] = "Data Updated Successfully";
  73. }
  74. header("location:edit.php?id=$this->id");
  75. }// update \\
  76. public function delete(){
  77. $query = "DELETE FROM `web_apps_php_26`.`semister` WHERE `semister`.unique_id = '".$this->id."' ";
  78. if($result = mysql_query($query)){
  79. $_SESSION['UpdtMsg'] = "Data Updated Successfully";
  80. }
  81. header("location:edit.php?id=$this->id");
  82. } // Delete\\
  83. }// class \\
  84. ?>
  85. <!DOCTYPE html>
  86. <html>
  87. <head>
  88. <!-- Latest compiled and minified CSS -->
  89. <link rel="stylesheet" href="../../../../style.css">