PageRenderTime 22ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/views/SEIP136184/Book/index.php

https://gitlab.com/Jannatul_Huraon/Atomic_ProjectCRUD
PHP | 150 lines | 111 code | 30 blank | 9 comment | 12 complexity | 506965654a349ee6e69a48e353fba944 MD5 | raw file
  1. <?php
  2. session_start();
  3. include_once('../../../vendor/autoload.php');
  4. use App\BITM\SEIP136184\Book\Book;
  5. use App\BITM\SEIP136184\Utility\Utility;
  6. use App\BITM\SEIP136184\Message\Message;
  7. $book= new Book();
  8. if(array_key_exists('itemPerPage',$_SESSION)) {
  9. if (array_key_exists('itemPerPage', $_GET)) {
  10. $_SESSION['itemPerPage'] = $_GET['itemPerPage'];
  11. }
  12. }
  13. else{
  14. $_SESSION['itemPerPage']=5;
  15. }
  16. //Utility::dd($_SESSION['itemPerPage']);
  17. $itemPerPage=$_SESSION['itemPerPage'];
  18. $totalItem=$book->count();
  19. $totalPage=ceil($totalItem/$itemPerPage);
  20. //Utility::dd($itemPerPage);
  21. $pagination="";
  22. if(array_key_exists('pageNumber',$_GET)){
  23. $pageNumber=$_GET['pageNumber'];
  24. }else{
  25. $pageNumber=1;
  26. }
  27. for($i=1;$i<=$totalPage;$i++){
  28. $class=($pageNumber==$i)?"active":"";
  29. $pagination.="<li class='$class'><a href='index.php?pageNumber=$i'>$i</a></li>";
  30. }
  31. $pageStartFrom=$itemPerPage*($pageNumber-1);
  32. $allBook=$book->paginator($pageStartFrom,$itemPerPage);
  33. ?>
  34. <!DOCTYPE html>
  35. <html>
  36. <head>
  37. <meta name="viewport" content="width=device-width, initial-scale=1">
  38. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  39. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  40. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  41. </head>
  42. <body>
  43. <div align="right">
  44. <h3>Back to: </h3>
  45. <a href="../../../index.php" role="button">Atomic Project Index</a>
  46. </div>
  47. <div class="container">
  48. <h2>All Book List</h2>
  49. <a href="create.php" class="btn btn-primary" role="button">Create again</a> <a href="trashed.php" class="btn btn-primary" role="button">View Trashed list</a>
  50. </div>
  51. <form role="form">
  52. <div class="form-group">
  53. <label for="sel1">Select how many items you want to show (select one):</label>
  54. <select class="form-control" id="sel1" name="itemPerPage">
  55. <option <?php if($itemPerPage==5 ):?>selected<?php endif ?>>5</option>
  56. <option <?php if($itemPerPage==10 ):?>selected<?php endif ?>>10</option>
  57. <option <?php if($itemPerPage==15 ):?>selected<?php endif ?>>15</option>
  58. <option <?php if($itemPerPage==20 ):?>selected<?php endif ?>>20</option>
  59. <option <?php if($itemPerPage==25 ):?>selected<?php endif ?>>25</option>
  60. </select>
  61. <button type="submit">Go!</button>
  62. </div>
  63. </form>
  64. <div class="table-responsive">
  65. <table class="table">
  66. <thead>
  67. <tr>
  68. <th>#</th>
  69. <th>ID</th>
  70. <th>Book title</th>
  71. <th>Action</th>
  72. </tr>
  73. </thead>
  74. <tbody>
  75. <tr>
  76. <?php
  77. $sl=0;
  78. foreach($allBook as $book){
  79. $sl++; ?>
  80. <td><?php echo $sl+$pageStartFrom?></td>
  81. <td><?php echo $book-> id?></td>
  82. <td><?php echo $book->title?></td>
  83. <td><a href="view.php?id=<?php echo $book-> id ?>" class="btn btn-danger" role="button">View</a>
  84. <a href="edit.php?id=<?php echo $book-> id ?>" class="btn btn-info" role="button">Edit</a>
  85. <a href="delete.php?id=<?php echo $book->id?>" class="btn btn-danger" role="button" id="delete" Onclick="return ConfirmDelete()">Delete</a>
  86. <a href="trash.php?id=<?php echo $book->id ?>" class="btn btn-info" role="button">Trash</a>
  87. </td>
  88. </tr>
  89. <?php }?>
  90. </tbody>
  91. </table>
  92. </div>
  93. <ul class="pagination">
  94. <?php if($pageNumber>1):?>
  95. <li><a href="index.php?pageNumber=<?php echo $pageNumber-1?>">Prev</a></li><?php endif;?>
  96. <?php echo $pagination?>
  97. <?php if($pageNumber<$totalPage):?>
  98. <li><a href="index.php?pageNumber=<?php echo $pageNumber+1?>">next</a></li><?php endif;?>
  99. </ul>
  100. </div>
  101. <script>
  102. $('#message').show().delay(2000).fadeOut();
  103. // $(document).ready(function(){
  104. // $("#delete").click(function(){
  105. // if (!confirm("Do you want to delete")){
  106. // return false;
  107. // }
  108. // });
  109. // });
  110. function ConfirmDelete()
  111. {
  112. var x = confirm("Are you sure you want to delete?");
  113. if (x)
  114. return true;
  115. else
  116. return false;
  117. }
  118. </script>
  119. </body>
  120. </html>