update.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. include_once('../../index.php');
  3. include_once('templates/core/Smarty.class.php');
  4. $isCookied = isset($_COOKIE['identify'], $_COOKIE['hash']);
  5. $isReceiveForm = count($_POST) > 0;
  6. $isIdentify = false;
  7. $message = '';
  8. if (isset($_GET['update']) && $_GET['update'] == '0') {
  9. $message = '';
  10. }
  11. if (isset($_GET['update']) && $_GET['update'] == '1') {
  12. $message = 'Modificación exitosa';
  13. }
  14. if (isset($_GET['update']) && $_GET['update'] == '2') {
  15. $message = 'Contraseña no modificada';
  16. }
  17. if (isset($_GET['update']) && $_GET['update'] == '3') {
  18. $message = 'No se hicieron modificaciones';
  19. }
  20. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
  21. if ($isCookied) {
  22. //index properties
  23. $post = new Post($db);
  24. $post->identify = $_COOKIE['identify'];
  25. $post->hash = $_COOKIE['hash'];
  26. $isIdentify = $post->identify();
  27. }
  28. //Is not identify user
  29. if (!$isIdentify) {
  30. // return to login
  31. header('Location: users.php?page=login');
  32. return;
  33. }
  34. //Is superuser needed
  35. if ($isIdentify) {
  36. //SUPERUSER PROCESS
  37. $isSuperUser = $post->is_super_user();
  38. }
  39. if (!$isSuperUser) {
  40. header('Location: /');
  41. return;
  42. }
  43. if ($isReceiveForm) {
  44. $isUpdate = false;
  45. $post = new Post($db);
  46. $post->id = $id;
  47. $post->identify = $_COOKIE['identify'];
  48. $post->hash = $_COOKIE['hash'];
  49. if (isset($_POST['rol'])) {
  50. $post->rol = $_POST['rol'];
  51. $isUpdate = $post->update_rol();
  52. if (!$isUpdate) {
  53. header("Location: users.php?page=update&id={$id}&update=3");
  54. }
  55. if ($isUpdate) {
  56. header("Location: users.php?page=update&id={$id}&update=1");
  57. }
  58. }
  59. if (isset($_POST['softDelete'])) {
  60. $post->softDelete = $_POST['softDelete'];
  61. $isUpdate = $post->update_softDelete();
  62. if (!$isUpdate) {
  63. header("Location: users.php?page=update&id={$id}&update=3");
  64. }
  65. if ($isUpdate) {
  66. header("Location: users.php?page=update&id={$id}&update=1");
  67. }
  68. }
  69. if (isset($_POST['password']) && $_POST['password'] != '') {
  70. $post->password = hash('sha512', $_POST['password']);
  71. $isUpdate = $post->update_password();
  72. if (!$isUpdate) {
  73. header("Location: users.php?page=update&id={$id}&update=2");
  74. }
  75. if ($isUpdate) {
  76. header("Location: users.php?page=update&id={$id}&update=1");
  77. }
  78. }
  79. }
  80. //index properties
  81. $post = new Post($db);
  82. $post->id = $id;
  83. //read single user
  84. $post->read_single();
  85. $post_arr = array(
  86. 'rol' => $post->rol,
  87. 'name' => $post->name,
  88. 'softDelete' => $post->softDelete,
  89. );
  90. if($post_arr) {
  91. //DECLARE FORM VARIABLES
  92. $smarty = new smarty();
  93. $smarty->assign('id', $id);
  94. $smarty->assign('name', $post->name);
  95. $smarty->assign('rol', $post->rol);
  96. $smarty->assign('softDelete', $post->softDelete);
  97. $smarty->assign('password', '');
  98. $smarty->assign('message', $message);
  99. $smarty->display("templates/{$_REQUEST['page']}.tpl");
  100. }
  101. else {
  102. header('Location: users.php?page=read');
  103. }
  104. ?>