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

/utilidades/GestionDenuncias.php

https://bitbucket.org/veroreinah/bookworm
PHP | 248 lines | 192 code | 47 blank | 9 comment | 21 complexity | 40b3fd3f9e9f00d65bc100ca2408c5b0 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. require_once 'conexion.php';
  3. require_once 'clases/Denuncia.php';
  4. require_once 'clases/Usuario.php';
  5. require_once 'clases/Libro.php';
  6. require_once 'GestionUsuarios.php';
  7. require_once 'GestionLibros.php';
  8. /*
  9. * To change this template, choose Tools | Templates
  10. * and open the template in the editor.
  11. */
  12. /**
  13. * Description of GestionDenuncias
  14. *
  15. * @author Vero
  16. */
  17. class GestionDenuncias {
  18. public static function crearDenuncia($denuncia) {
  19. global $conexion;
  20. $d = new Denuncia();
  21. $d = $denuncia;
  22. $usuario = new Usuario();
  23. $usuario = $d->getUsuario();
  24. $libro = new Libro();
  25. $libro = $d->getLibro();
  26. try {
  27. $query = "insert into t_denuncias
  28. (id_usuario, isbn, fecha, texto, vista)
  29. values ('" . $usuario->getId() . "',
  30. '" . $libro->getIsbn() . "',
  31. '" . $d->getFecha() . "',
  32. '" . mysql_escape_string($d->getTexto()) . "',
  33. 'false')";
  34. $result = mysql_query($query, $conexion);
  35. } catch (Exception $e) {
  36. $_SESSION["error"] = "No se ha podido enviar la denuncia. Inténtelo de nuevo más tarde.";
  37. }
  38. }
  39. public static function recuperarDenuncias() {
  40. global $conexion;
  41. $denuncias = array();
  42. try {
  43. $query = "select * from t_denuncias order by fecha desc";
  44. $result = mysql_query($query, $conexion);
  45. while($row = mysql_fetch_array($result)) {
  46. $denuncia = new Denuncia();
  47. $denuncia->setTexto($row["texto"]);
  48. $denuncia->setFecha($row["fecha"]);
  49. $denuncia->setVista($row["vista"]);
  50. $denuncia->setEnlace($row["enlace"]);
  51. $usuario = new Usuario();
  52. $usuario = GestionUsuarios::recuperarUsuario($row["id_usuario"]);
  53. $denuncia->setUsuario($usuario);
  54. $libro = new Libro();
  55. $libro = GestionLibros::recuperarLibro($row["isbn"]);
  56. $denuncia->setLibro($libro);
  57. $denuncias[] = $denuncia;
  58. }
  59. if ($denuncias != null && count($denuncias) > 0) {
  60. } else {
  61. $_SESSION["noHay"] = "Actualmente no existe ninguna denuncia en BookWorm.";
  62. }
  63. return $denuncias;
  64. } catch (Exception $e) {
  65. $_SESSION["error"] = "No se han podido recuperar las denuncias. Inténtelo de nuevo más tarde.";
  66. }
  67. }
  68. public static function recuperarDenuncia($enlace) {
  69. global $conexion;
  70. try {
  71. $query = "select * from t_denuncias
  72. where enlace = '" . $enlace . "'";
  73. $result = mysql_query($query, $conexion);
  74. $row = mysql_fetch_array($result);
  75. if(!$row) {
  76. $_SESSION["noHay"] = "No existe ninguna denuncia con ese identificador en BookWorm.";
  77. return 0;
  78. } else {
  79. $denuncia = new Denuncia();
  80. $denuncia->setTexto($row["texto"]);
  81. $denuncia->setFecha($row["fecha"]);
  82. $denuncia->setVista($row["vista"]);
  83. $denuncia->setEnlace($row["enlace"]);
  84. $us = new Usuario();
  85. $us = GestionUsuarios::recuperarUsuario($row["id_usuario"]);
  86. $denuncia->setUsuario($us);
  87. $li = new Libro();
  88. $li = GestionLibros::recuperarLibro($row["isbn"]);
  89. $denuncia->setLibro($li);
  90. return $denuncia;
  91. }
  92. } catch (Exception $e) {
  93. $_SESSION["error"] = "No se ha podido recuperar la denuncia. Inténtelo de nuevo más tarde.";
  94. }
  95. }
  96. public static function marcarComoVista($enlace) {
  97. global $conexion;
  98. try {
  99. $query = "update t_denuncias
  100. set vista = true
  101. where enlace = '" . $enlace . "'";
  102. $result = mysql_query($query, $conexion);
  103. } catch (Exception $e) {
  104. $_SESSION["error"] = "No se ha podido marcar la denuncia como vista. Inténtelo de nuevo más tarde.";
  105. }
  106. }
  107. public static function eliminarDenuncia($enlace) {
  108. global $conexion;
  109. try {
  110. $query = "delete from t_denuncias
  111. where enlace = '" . $enlace . "'";
  112. $result = mysql_query($query, $conexion);
  113. } catch (Exception $e) {
  114. $_SESSION["error"] = "No se ha podido eliminar la denuncia. Inténtelo de nuevo más tarde.";
  115. }
  116. }
  117. public static function recuperarDenunciasL($begin, $limit, $field="", $order="", $where="") {
  118. global $conexion;
  119. if ($begin != "" && $limit != "") {
  120. $l = " limit $begin, $limit ";
  121. }
  122. if ($field != "" && $order != "") {
  123. $orderBy = " order by $field $order ";
  124. }
  125. if ($where != "") {
  126. $w = " where l.isbn like '%$where%'
  127. or l.titulo like '%$where%'
  128. or u.nombre_usuario like '%$where%' ";
  129. }
  130. try {
  131. $query = "select d.*
  132. from t_denuncias as d inner join t_usuarios as u
  133. on d.id_usuario = u.id_usuario
  134. inner join t_libros as l
  135. on d.isbn = l.isbn";
  136. if (isset($w)) {
  137. $query = $query . $w;
  138. }
  139. if (isset($orderBy)) {
  140. $query = $query . $orderBy;
  141. }
  142. if (isset($l)) {
  143. $query = $query . $l;
  144. }
  145. $result = mysql_query($query, $conexion);
  146. $denuncias = array();
  147. while($row = mysql_fetch_array($result)) {
  148. $denuncia = new Denuncia();
  149. $denuncia->setTexto($row["texto"]);
  150. $denuncia->setFecha($row["fecha"]);
  151. $denuncia->setVista($row["vista"]);
  152. $denuncia->setEnlace($row["enlace"]);
  153. $usuario = new Usuario();
  154. $usuario = GestionUsuarios::recuperarUsuario($row["id_usuario"]);
  155. $denuncia->setUsuario($usuario);
  156. $libro = new Libro();
  157. $libro = GestionLibros::recuperarLibro($row["isbn"]);
  158. $denuncia->setLibro($libro);
  159. $denuncias[] = $denuncia;
  160. }
  161. return $denuncias;
  162. } catch (Exception $e) {
  163. $_SESSION["error"] = "No se han podido recuperar las denuncias. Inténtelo de nuevo más tarde.";
  164. }
  165. }
  166. public static function totalDenuncias() {
  167. global $conexion;
  168. try {
  169. $query = "select count(*) as total
  170. from t_denuncias";
  171. $result = mysql_query($query, $conexion);
  172. $row = mysql_fetch_array($result);
  173. $total = $row["total"];
  174. return $total;
  175. } catch (Exception $e) {
  176. $_SESSION["error"] = "No se han podido recuperar las denuncias. Inténtelo de nuevo más tarde.";
  177. }
  178. }
  179. public static function totalFiltered($where) {
  180. global $conexion;
  181. if ($where != "") {
  182. $w = " where l.isbn like '%$where%'
  183. or l.titulo like '%$where%'
  184. or u.nombre_usuario like '%$where%' ";
  185. }
  186. try {
  187. $query = "select count(d.isbn) as total
  188. from t_denuncias as d inner join t_usuarios as u
  189. on d.id_usuario = u.id_usuario
  190. inner join t_libros as l
  191. on d.isbn = l.isbn $w";
  192. $result = mysql_query($query, $conexion);
  193. $row = mysql_fetch_array($result);
  194. $total = $row["total"];
  195. return $total;
  196. } catch (Exception $e) {
  197. $_SESSION["error"] = "No se han podido recuperar las denuncias. Inténtelo de nuevo más tarde.";
  198. }
  199. }
  200. }
  201. ?>