Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. class Db {
  2.  
  3. Protected $conn;
  4. public $table;
  5. public $fields;
  6. public $values;
  7. public $sql;
  8. public $array_keys;
  9. public $array_values;
  10.  
  11.  
  12. //put your code here
  13. public function __construct() {
  14.  
  15. $servername = "localhost";
  16. $username = "root";
  17. $password = "abdullah123";
  18.  
  19. try {
  20. $this->conn = new PDO("mysql:host=$servername;dbname=Pathalogy_Lab", $username, $password);
  21. // set the PDO error mode to exception
  22. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  23. } catch (PDOException $e) {
  24. echo "Connection failed: " . $e->getMessage();
  25. }
  26. }
  27.  
  28. public function tableData($fields, $table) {
  29.  
  30. unset($fields['Patient_data']);
  31. unset($fields['logout']);
  32. unset($fields['insert_Report']);
  33.  
  34. $this->array_keys = array_keys($fields);
  35. $this->array_values = array_values($fields);
  36.  
  37. $this->table = $table;
  38.  
  39. $this->sqlQuery();
  40. }
  41.  
  42. public function tableColums() {
  43. return "`" . implode("`, `", $this->array_keys) . "`";
  44.  
  45. }
  46.  
  47. public function tableValues() {
  48. return "'" . implode("', '", $this->array_values) . "'";
  49. }
  50.  
  51. public function sqlQuery() {
  52.  
  53. $sql = "INSERT INTO `{$this->table}` (" . $this->tableColums() . ") VALUES (" . $this->tableValues() . ");";
  54. $stmt = $this->conn->prepare($sql);
  55. $stmt->execute();
  56.  
  57. if (Patient == $this->table) {
  58. $this->addPatient();
  59. } elseif (Reports == $this->table) {
  60. $this->addReport();
  61. }
  62. }
  63.  
  64.  
  65. public function addPatient() {
  66.  
  67. header('Location: ../FrontEndFiles/insert_report.php');
  68. }
  69.  
  70. public function addReport() {
  71.  
  72. header('Location: ../FrontEndFiles/Admin_Index.php');
  73. }
  74.  
  75. public function logout() {
  76. unset($_SESSION["dbuser_name"], $_SESSION["dbpassword"], $_SESSION["dbid"]);
  77. session_unset();
  78. Session_destroy();
  79.  
  80. if (!isset($_SESSION['dbuser_name']) || !isset($_SESSION['Patient_password']) || !isset($_SESSION['Patient_ID'])) {
  81. header('Location: ../FrontEndFiles/Index.php');
  82. exit();
  83. }
  84. }
  85.  
  86. }
  87.  
  88. class Admin extends Db {
  89.  
  90. public $data_id;
  91.  
  92. public function listRecord() {
  93.  
  94. if (isset($_SESSION['dbuser_name']) && isset($_SESSION['dbpassword'])) {
  95.  
  96.  
  97. $query = "select Patient_ID, Patient_name, Patient_Address, Patient_Phone from Patient where Role= 'u'";
  98. $result = $this->conn->prepare($query);
  99. $result->execute();
  100.  
  101. if ($row_count > 0) {
  102. // output data of each row
  103.  
  104. $this->detailsHeredocs();
  105. $nust = $result->fetchall();
  106.  
  107. foreach ($nust as $row1) {
  108.  
  109. echo"
  110. <tr>
  111. <td> $row1[Patient_name] </td>
  112. <td> $row1[Patient_Address] </td>
  113.  
  114. <td><a href='../Admin/AdminData.php?report_id=$row1[Patient_ID]'>Details</a></td>
  115.  
  116. </tr>";
  117. }
  118. echo <<<HTML
  119. </tbody>
  120. </table>
  121. </div>
  122. <script>
  123. $(document).ready(function(){
  124. $('#myTable').DataTable();
  125. });
  126. </script>
  127. </body>
  128. </html>
  129. HTML;
  130. }
  131. }
  132. }
  133.  
  134. public function Details($id) {
  135.  
  136. $this->data_id = $id;
  137.  
  138. if (isset($_SESSION['dbuser_name']) && isset($_SESSION['dbpassword'])) {
  139.  
  140. $query = "select Report_type, Report_Id, Report_Reults,Patient_name, Patient_Address, "
  141. . "Patient_Phone from Patient join Reports WHERE "
  142. . "Reports.Patient_ID=$this->data_id and Patient.Patient_ID=$this->data_id";
  143.  
  144. $result = $this->conn->prepare($query);
  145. $row = $result->execute();
  146. $row_count = $result->rowCount();
  147.  
  148. if ($row_count > 0) {
  149. // output data of each row
  150. $this->patientListHeredocs();
  151. $nust = $result->fetchAll();
  152. foreach ($nust as $row1) {
  153.  
  154. echo"
  155. <tr>
  156. <td> $row1[Patient_name] </td>
  157. <td> $row1[Patient_Address] </td>
  158. <td> $row1[Patient_Phone] </td>
  159. <td> $row1[Report_type] </td>
  160. <td> $row1[Report_Reults] </td>
  161. <td><a href='../Admin /AdminData.php?del_id=$row1[Report_Id]'>Delete</a></td>
  162. </tr>";
  163. }
  164. echo <<<HTML
  165. </tbody>
  166. </table>
  167. </div>
  168. <script>
  169. $(document).ready(function(){
  170. $('#myTable').DataTable();
  171. });
  172. </script>
  173. </body>
  174. </html>
  175. HTML;
  176. }
  177. }
  178. }
  179.  
  180. public function Delete($del) {
  181.  
  182. if (isset($_SESSION['dbuser_name']) && isset($_SESSION['dbpassword'])) {
  183.  
  184. $this->data_id = $del;
  185.  
  186. $query = "DELETE FROM Reports Where Report_Id=$this->data_id";
  187.  
  188. $result = $this->conn->prepare($query);
  189. $result->execute();
  190. $affected_rows = $result->rowCount();
  191. if ($affected_rows == 1) {
  192.  
  193. header('Location: ../FrontEndFiles/Admin_Index.php');
  194. } else {
  195.  
  196. echo 'No data DELEted';
  197. }
  198. }
  199. }
  200.  
  201. public function DeletePatient($param) {
  202.  
  203. if (isset($_SESSION['dbuser_name']) && isset($_SESSION['dbpassword'])) {
  204.  
  205. $this->data_id = $param;
  206. $query = "Delete from Patient WHERE Patient_ID=$this->data_id";
  207. $result = $this->conn->prepare($query);
  208. $result->execute();
  209.  
  210. header('Location: ../Admin/Admin_Index.php');
  211. }
  212. }
  213.  
  214. public function PatientList() {
  215.  
  216. if (isset($_SESSION['dbuser_name']) && isset($_SESSION['dbpassword'])) {
  217.  
  218. $query = "select Patient_ID, Patient_name, Patient_Address, Patient_Phone from Patient where Role= 'u'";
  219.  
  220. $result = $this->conn->prepare($query);
  221. $result->execute();
  222. $row_count = $result->rowCount();
  223.  
  224. if ($row_count > 0) {
  225. // output data of each row
  226. ob_start();
  227. include("../FrontEndFiles/navBar.html");
  228. include("../FrontEndFiles/sideBar.html");
  229. $include = ob_get_contents();
  230. ob_end_clean();
  231.  
  232. echo <<<HTML
  233. {$include}
  234.  
  235.  
  236. <div class="col-md-8">
  237. <h2> Data</h2>
  238. <table id="myTable" class="display">
  239. <thead>
  240. <tr>
  241. <th>Patient Name</th>
  242. <th>Action</th>
  243. </tr>
  244. </thead>
  245. <tbody>
  246. HTML;
  247. $nust = $result->fetchAll();
  248. foreach ($nust as $row1) {
  249. echo"
  250. <tr>
  251. <td> $row1[Patient_name] </td>
  252. <td><a href='../Admin/AdminData.php?deleteData=$row1[Patient_ID]'>Delete</a></td>
  253. </tr>";
  254. }
  255. echo <<<HTML
  256. </tbody>
  257. </table>
  258. </div>
  259. <script>
  260. $(document).ready(function(){
  261. $('#myTable').DataTable();
  262. });
  263. </script>
  264. </body>
  265. </html>
  266. HTML;
  267. }
  268. }
  269. }
  270.  
  271. public function loginAdmin($login_admin) {
  272.  
  273. if (!empty($login_admin[0]) || !empty($login_admin[1])) {
  274.  
  275. $query = "SELECT * FROM Patient WHERE Patient_name = '$login_admin[0]' and Patient_password = $login_admin[1] and Role = 'a'";
  276. $stmt = $this->conn->query($query);
  277. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  278. echo $row['Patient_name'];
  279. echo $row['Patient_password'];
  280. echo $row['Patient_ID'];
  281.  
  282. if ($row) {
  283.  
  284. $_SESSION["dbuser_name"] = $row['Patient_name'];
  285. $_SESSION["dbpassword"] = $row['Patient_password'];
  286. $_SESSION["dbid"] = $row['Patient_ID'];
  287.  
  288. header('Location: ../FrontEndFiles/Admin_Index.php');
  289. } else {
  290.  
  291. header('Location: ../FrontEndFiles/AdminLogin.php');
  292. }
  293. } else {
  294. header('Location: ../FrontEndFiles/AdminLogin.php');
  295. }
  296. }
  297.  
  298. public function detailsHeredocs() {
  299.  
  300. ob_start();
  301. include("../FrontEndFiles/navBar.html");
  302. include("../FrontEndFiles/sideBar.html");
  303. $include = ob_get_contents();
  304. ob_end_clean();
  305.  
  306. echo <<<HTML
  307. {$include}
  308.  
  309. <div class="col-md-8">
  310. <h2>Report's Data</h2>
  311. <table id="myTable" class="display">
  312. <thead>
  313. <tr>
  314. <th>Patient Name</th>
  315. <th>Patient Address</th>
  316. <th>Action</th>
  317. </tr>
  318. </thead>
  319. <tbody>
  320.  
  321. HTML;
  322. }
  323.  
  324. public function patientListHeredocs() {
  325. ob_start();
  326. include("../FrontEndFiles/navBar.html");
  327. include("../FrontEndFiles/sideBar.html");
  328. $include = ob_get_contents();
  329. ob_end_clean();
  330.  
  331. echo <<<HTML
  332. {$include}
  333.  
  334. <div class="col-md-8">
  335.  
  336. <h2>Data</h2>
  337. <table id="myTable" class="display">
  338. <thead>
  339. <tr>
  340. <th>Patient Name</th>
  341. <th>Patient Address</th>
  342. <th>Patient Phone</th>
  343. <th>Report Type</th>
  344. <th>Report Results</th>
  345. <th>Action</th>
  346. </tr>
  347. </thead>
  348. <tbody>
  349.  
  350.  
  351. HTML;
  352. }
  353.  
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement