PageRenderTime 35ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/views/SEIP136184/Hobby/index.php

https://gitlab.com/Jannatul_Huraon/Atomic_ProjectCRUD
PHP | 155 lines | 122 code | 29 blank | 4 comment | 14 complexity | f2418ff799be0211a0803931b603a532 MD5 | raw file
  1. <?php
  2. session_start();
  3. include_once ('../../../vendor/autoload.php');
  4. use App\BITM\SEIP136184\Hobby\Hobby;
  5. use App\BITM\SEIP136184\Message\Message;
  6. use App\BITM\SEIP136184\Utility\Utility;
  7. $obj =new Hobby();
  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=$obj->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. $allHobby=$obj->paginator($pageStartFrom,$itemPerPage);
  33. //$obj->prepare($_POST);
  34. //$allHobby = $obj->index();
  35. ?>
  36. <!DOCTYPE html>
  37. <html lang="en">
  38. <head>
  39. <title>Bootstrap Example</title>
  40. <meta charset="utf-8">
  41. <meta name="viewport" content="width=device-width, initial-scale=1">
  42. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  43. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  44. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  45. </head>
  46. <body>
  47. <div align="right">
  48. <h3>Back to: </h3>
  49. <a href="../../../index.php" class="btn btn-success btn-lg" role="button">Atomic Project Index</a>
  50. </div>
  51. <div class="container">
  52. <center><h2>Subscribers Hobbies</h2></center>
  53. <!-- <p>
  54. Contextual classes can be used to color table rows or table cells.
  55. The classes that can be used are: .active, .success, .info, .warning, and .danger.
  56. </p> -->
  57. <a href="create.php" class="btn btn-primary" role="button">Create Again</a>
  58. <a href="trashlist.php" class="btn btn-primary" role="button">View Trash List</a>
  59. <div class="alert alert-info" id="message">
  60. <center><?php
  61. if(array_key_exists("message",$_SESSION) && (!empty($_SESSION['message'])))
  62. echo Message::message()
  63. ?></center>
  64. </div>
  65. <form role="form">
  66. <div class="form-group">
  67. <label for="sel1">Select how many items you want to show (select one):</label>
  68. <select class="form-control" id="sel1" name="itemPerPage">
  69. <option <?php if($itemPerPage==5):?>selected<?php endif ?>>5</option>
  70. <option <?php if($itemPerPage==10):?>selected<?php endif?>>10</option>
  71. <option <?php if($itemPerPage==15):?>selected<?php endif ?>>15</option>
  72. <option <?php if($itemPerPage==20):?>selected<?php endif ?>>20</option>
  73. <option <?php if($itemPerPage==25):?>selected<?php endif ?>>25</option>
  74. </select>
  75. <button type="submit">Go!</button>
  76. </div>
  77. </form>
  78. <table class="table">
  79. <thead>
  80. <tr>
  81. <th>SL</th>
  82. <th>ID</th>
  83. <th>Hobbies</th>
  84. <th>Action</th>
  85. </tr>
  86. </thead>
  87. <tbody>
  88. <?php
  89. $count =0 ;
  90. foreach ($allHobby as $item) { $count++;
  91. ?>
  92. <tr class="success">
  93. <td><?php echo $count?> </td>
  94. <td> <?php echo $item->id ?> </td>
  95. <td> <?php echo $item->hobby ?> </td>
  96. <td>
  97. <a href="view.php?id=<?php echo $item->id?>" class="btn btn-danger" role="button">View</a>
  98. <a href="edit.php?id=<?php echo $item->id?>" class="btn btn-info" role="button">Update</a>
  99. <a href="trash.php?id=<?php echo $item->id?>" class="btn btn-warning" role="button">Trash</a>
  100. <a href="delete.php?id=<?php echo $item->id?>" class="btn btn-danger" role="button" id="delete" Onclick="return ConfirmDelete()">Delete</a>
  101. </td>
  102. </tr>
  103. <?php } ?>
  104. </tbody>
  105. </table>
  106. </div>
  107. <ul class="pagination">
  108. <?php if($pageNumber>1):?>
  109. <li><a href="index.php?pageNumber=<?php echo $pageNumber-1 ?>">Previous</a></li><?php endif;?>
  110. <?php echo $pagination?>
  111. <?php if($pageNumber<$totalPage):?>
  112. <li><a href="index.php?pageNumber=<?php echo $pageNumber+1 ?>">Next</a></li><?php endif;?>
  113. </ul>
  114. <script>
  115. $('#message').show().delay(2840).fadeOut();
  116. function ConfirmDelete()
  117. {
  118. var x = confirm("Are you sure you want to delete?");
  119. if (x)
  120. return true;
  121. else
  122. return false;
  123. }
  124. </script>
  125. </body>
  126. </html>