read.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. include_once('../../index.php');
  3. include_once('templates/core/Smarty.class.php');
  4. $smarty = new smarty();
  5. $isCookied = isset($_COOKIE['identify'], $_COOKIE['hash']);
  6. $isReceiveForm = count($_POST) > 0;
  7. $isIdentify = false;
  8. $message = '';
  9. //The user send correctly indentify and hash
  10. if (!$isCookied) {
  11. // This step is for when type directly /frontend/users/read
  12. header('Location: /');
  13. return;
  14. }
  15. if ($isCookied) {
  16. //index properties
  17. $post = new Post($db);
  18. $post->identify = $_COOKIE['identify'];
  19. $post->hash = $_COOKIE['hash'];
  20. $isIdentify = $post->identify();
  21. }
  22. //Is not identify user
  23. if (!$isIdentify) {
  24. //DECLARE FORM VARIABLES
  25. header('Location: /');
  26. return;
  27. }
  28. //Is superuser needed
  29. if ($isIdentify) {
  30. //SUPERUSER PROCESS
  31. $isSuperUser = $post->is_super_user();
  32. }
  33. //is_super_user process
  34. if (!$isSuperUser) {
  35. header('Location: /');
  36. return;
  37. }
  38. //read users
  39. $result = $post->read();
  40. //get the row count
  41. $num = $result->rowCount();
  42. if($num > 0) {
  43. $post_arr = array();
  44. $post_arr['data'] = array();
  45. while($row = $result->fetch(PDO::FETCH_ASSOC)) {
  46. extract($row);
  47. $post_item = array(
  48. 'id' => $id,
  49. 'rol' => $rol,
  50. 'name' => $name,
  51. 'softDelete' => $softDelete,
  52. 'createdAt' => $createdAt
  53. );
  54. array_push($post_arr['data'], $post_item);
  55. }
  56. $smarty = new smarty();
  57. $smarty->assign('users', $post_arr['data']);
  58. $smarty->assign('message', $message);
  59. $smarty->display("templates/{$_REQUEST['page']}.tpl");
  60. }
  61. else {
  62. $smarty = new smarty();
  63. $smarty->assign('users', '');
  64. $smarty->assign('message', 'Ocurrió algún error');
  65. $smarty->display("templates/{$_REQUEST['page']}.tpl");
  66. }
  67. ?>