PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/views/SEIP1020/Book/index.php

https://gitlab.com/yameen15/CrudB22
PHP | 195 lines | 154 code | 28 blank | 13 comment | 10 complexity | 5053f1cc819340b2029b6eb4066e2304 MD5 | raw file
  1. <?php
  2. //var_dump($_POST);
  3. //die();
  4. session_start();
  5. include_once('../../../vendor/autoload.php');
  6. use App\Bitm\SEIP1020\Book\Book;
  7. use App\Bitm\SEIP1020\Utility\Utility;
  8. use App\Bitm\SEIP1020\Message\Message;
  9. $book= new Book();
  10. $availableTitle=$book->getAllTitle();
  11. $comma_separated= '"'.implode('","',$availableTitle).'"';
  12. //print_r($comma_separated);
  13. //Utility::d($allBook);
  14. if(array_key_exists('itemPerPage',$_SESSION)) {
  15. if (array_key_exists('itemPerPage', $_GET)) {
  16. $_SESSION['itemPerPage'] = $_GET['itemPerPage'];
  17. }
  18. }
  19. else{
  20. $_SESSION['itemPerPage']=5;
  21. }
  22. //Utility::dd($_SESSION['itemPerPage']);
  23. $itemPerPage=$_SESSION['itemPerPage'];
  24. $totalItem=$book->count();
  25. $totalPage=ceil($totalItem/$itemPerPage);
  26. //Utility::dd($itemPerPage);
  27. $pagination="";
  28. if(array_key_exists('pageNumber',$_GET)){
  29. $pageNumber=$_GET['pageNumber'];
  30. }else{
  31. $pageNumber=1;
  32. }
  33. for($i=1;$i<=$totalPage;$i++){
  34. $class=($pageNumber==$i)?"active":"";
  35. $pagination.="<li class='$class'><a href='index.php?pageNumber=$i'>$i</a></li>";
  36. }
  37. $pageStartFrom=$itemPerPage*($pageNumber-1);
  38. if(strtoupper($_SERVER['REQUEST_METHOD']=='GET')) {
  39. $allBook = $book->paginator($pageStartFrom, $itemPerPage);
  40. }
  41. if(strtoupper($_SERVER['REQUEST_METHOD']=='POST')) {
  42. $allBook = $book->prepare($_POST)->index();
  43. }
  44. if((strtoupper($_SERVER['REQUEST_METHOD']=='GET'))&& isset($_GET['search'])) {
  45. $allBook = $book->prepare($_GET)->index();
  46. }
  47. ?>
  48. <!DOCTYPE html>
  49. <html>
  50. <head>
  51. <meta name="viewport" content="width=device-width, initial-scale=1">
  52. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  53. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  54. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  55. <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
  56. <link rel="stylesheet" href="/resources/demos/style.css">
  57. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  58. <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
  59. </head>
  60. <body>
  61. <div class="container">
  62. <h2>All Book List</h2>
  63. <a href="create.php" class="btn btn-primary" role="button">Create again</a>
  64. <a href="trashed.php" class="btn btn-primary" role="button">View Trashed list</a>
  65. <a href="pdf.php" class="btn btn-primary" role="button">Download as PDF</a>
  66. <a href="xl.php" class="btn btn-primary" role="button">Download as XL</a>
  67. <a href="mail.php" class="btn btn-primary" role="button">Email to friend</a>
  68. <div id="message">
  69. <?php if((array_key_exists('message',$_SESSION)&& (!empty($_SESSION['message'])))) {
  70. echo Message::message();
  71. }
  72. ?>
  73. </div>
  74. <form role="form">
  75. <div class="form-group">
  76. <label for="sel1">Select homw many items you want to show (select one):</label>
  77. <select class="form-control" id="sel1" name="itemPerPage">
  78. <option>5</option>
  79. <option>10</option>
  80. <option selected>15</option>
  81. <option>20</option>
  82. <option>25</option>
  83. </select>
  84. <button type="submit">Go!</button>
  85. </div>
  86. </form>
  87. <form action="index.php" method="post">
  88. <label>Filter by Title</label>
  89. <input type="text" name="filterByTitle" value="" id="title">
  90. <label>Filter by Description</label>
  91. <input type="text" name="filterByDescription" value="">
  92. <button type="submit">Submit</button>
  93. </form>
  94. <form action="index.php" method="get">
  95. <label>Search</label>
  96. <input type="text" name="search" value="">
  97. <button type="submit">Search</button>
  98. </form>
  99. <div class="table-responsive">
  100. <table class="table">
  101. <thead>
  102. <tr>
  103. <th>#</th>
  104. <th>ID</th>
  105. <th>Book title</th>
  106. <th>Description</th>
  107. <th>Action</th>
  108. </tr>
  109. </thead>
  110. <tbody>
  111. <tr>
  112. <?php
  113. $sl=0;
  114. foreach($allBook as $book){
  115. $sl++; ?>
  116. <td><?php echo $sl+$pageStartFrom?></td>
  117. <td><?php echo $book-> id?></td>
  118. <td><?php echo $book->title?></td>
  119. <td><?php echo $book->description?></td>
  120. <td><a href="view.php?id=<?php echo $book-> id ?>" class="btn btn-primary" role="button">View</a>
  121. <a href="edit.php?id=<?php echo $book-> id ?>" class="btn btn-info" role="button">Edit</a>
  122. <a href="delete.php?id=<?php echo $book->id?>" class="btn btn-danger" role="button" id="delete" Onclick="return ConfirmDelete()">Delete</a>
  123. <a href="trash.php?id=<?php echo $book->id ?>" class="btn btn-info" role="button">Trash</a>
  124. </td>
  125. </tr>
  126. <?php }?>
  127. </tbody>
  128. </table>
  129. </div>
  130. <?php if(strtoupper($_SERVER['REQUEST_METHOD']=='GET')) { ?>
  131. <ul class="pagination">
  132. <li><a href="#">Prev</a></li>
  133. <?php echo $pagination?>
  134. <li><a href="#">Next</a></li>
  135. </ul>
  136. <?php } ?>
  137. </div>
  138. <script>
  139. $('#message').show().delay(2000).fadeOut();
  140. // $(document).ready(function(){
  141. // $("#delete").click(function(){
  142. // if (!confirm("Do you want to delete")){
  143. // return false;
  144. // }
  145. // });
  146. // });
  147. function ConfirmDelete()
  148. {
  149. var x = confirm("Are you sure you want to delete?");
  150. if (x)
  151. return true;
  152. else
  153. return false;
  154. }
  155. </script>
  156. <script>
  157. $( function() {
  158. var availableTags = [
  159. <?php echo $comma_separated?>
  160. ];
  161. $( "#title" ).autocomplete({
  162. source: availableTags
  163. });
  164. } );
  165. </script>
  166. </body>
  167. </html>