PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/views/SEIP137959/City/index.php

https://gitlab.com/Emran04/atomic_project
PHP | 155 lines | 121 code | 34 blank | 0 comment | 18 complexity | f64d79a304062feac68b3096fb990934 MD5 | raw file
  1. <?php
  2. session_start();
  3. include_once '../../../vendor/autoload.php';
  4. use App\Bitm\SEIP137959\City\City;
  5. use App\Bitm\SEIP137959\Message\Message;
  6. $city = new City();
  7. if(!empty($_SESSION['message'])) {
  8. $message = Message::message();
  9. }
  10. if( array_key_exists("itemPerPage", $_SESSION) ) {
  11. if( array_key_exists("itemPerPage", $_GET) ) {
  12. $_SESSION['itemPerPage'] = $_GET['itemPerPage'];
  13. }
  14. } else {
  15. $_SESSION['itemPerPage'] = 5;
  16. }
  17. $itemsPerPage = $_SESSION['itemPerPage'];
  18. $totalItem = $city->count();
  19. $totalPages = ceil($totalItem / $itemsPerPage);
  20. if(isset($_GET) && array_key_exists("page", $_GET)) {
  21. $pageNumber = $_GET['page'];
  22. }else {
  23. $pageNumber = 1;
  24. }
  25. $pagination = "";
  26. for($i = 1; $i <= $totalPages; $i++) {
  27. $class = ($i == $pageNumber) ? "active" : "";
  28. $pagination .= "<li class='{$class}'><a href='index.php?page={$i}'>$i</a></li>";
  29. }
  30. $pageStartFrom = $itemsPerPage * ($pageNumber - 1);
  31. $cities = $city->paginator($pageStartFrom, $itemsPerPage);
  32. ?>
  33. <?php include_once '../../../includes/header.php' ?>
  34. <div class="container-fluid">
  35. <?php include_once '../../../includes/sidebar.php' ?>
  36. <div class="col-md-8 col-md-offset-1">
  37. <div class="page-header">
  38. <h1>Cities</h1>
  39. </div>
  40. <?php if(isset($message)) : ?>
  41. <div id="message" class="alert alert-<?php echo $message['lvl']; ?>" role="alert">
  42. <?php echo $message['message']; ?>
  43. </div>
  44. <?php endif; ?>
  45. <div class="row">
  46. <div class="col-md-6">
  47. <p>
  48. <a href="create.php" class="btn btn-primary">Create New City</a>
  49. </p>
  50. </div>
  51. <div class="col-md-6 itemsPPage">
  52. <form action="" method="get">
  53. <label for="num">Items Per Page:</label>
  54. <select class="form-control items" name="itemPerPage" id="num">
  55. <option <?php if($itemsPerPage == 5) echo "selected" ?>>5</option>
  56. <option <?php if($itemsPerPage == 10) echo "selected" ?>>10</option>
  57. <option <?php if ($itemsPerPage == 15) echo "selected" ?>>15</option>
  58. </select>
  59. <input type="submit" value="Go" class="btn btn-primary">
  60. </form>
  61. </div>
  62. </div>
  63. <table class="table table-bordered">
  64. <thead>
  65. <tr>
  66. <th>SL</th>
  67. <th>ID</th>
  68. <th>Name</th>
  69. <th class="actions">Actions</th>
  70. </tr>
  71. </thead>
  72. <tbody>
  73. <?php
  74. $sl = 0;
  75. foreach($cities as $city):
  76. $sl++; ?>
  77. <tr>
  78. <td><?= $sl + $pageStartFrom ?></td>
  79. <td><?= $city['id'] ?></td>
  80. <td><?= $city['city'] ?></td>
  81. <td class="actions">
  82. <a href="view.php?id=<?= $city['id'] ?>" class="btn btn-primary">View</a>
  83. <a href="edit.php?id=<?= $city['id'] ?>" class="btn btn-primary">Edit</a>
  84. <a href="delete.php?id=<?= $city['id'] ?>" class="btn btn-danger dl">Delete</a>
  85. <a href="trash.php?id=<?= $city['id'] ?>" class="btn btn-warning">Trash</a>
  86. </td>
  87. </tr>
  88. <?php endforeach; ?>
  89. </tbody>
  90. </table>
  91. <!-- Pagination -->
  92. <?php if($totalItem > $itemsPerPage) : ?>
  93. <nav>
  94. <ul class="pagination">
  95. <?php if($pageNumber > 1) : ?>
  96. <li>
  97. <a href="index.php?page=<?= ($pageNumber-1) ?>" aria-label="Previous">
  98. <span aria-hidden="true">Prev</span>
  99. </a>
  100. </li>
  101. <?php endif ?>
  102. <?= $pagination ?>
  103. <?php if($pageNumber < $totalPages): ?>
  104. <li>
  105. <a href="index.php?page=<?= ($pageNumber+ 1) ?>" aria-label="Next">
  106. <span aria-hidden="true">Next</span>
  107. </a>
  108. </li>
  109. <?php endif ?>
  110. </ul>
  111. </nav>
  112. <?php endif ?>
  113. <!-- End Pagination -->
  114. </div>
  115. </div>
  116. <?php include_once '../../../includes/footer.php' ?>
  117. <script>
  118. $('#message').delay(3000).fadeOut();
  119. </script>
  120. </body>
  121. </html>