PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/perfil2/clases/dlm_muro.php

https://bitbucket.org/weddcam/develop_weddcam
PHP | 233 lines | 181 code | 16 blank | 36 comment | 13 complexity | 08b5a9abca93777367a1485a9f72df0c MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, MIT, LGPL-3.0, LGPL-2.1
  1. <?php
  2. include 'conexion_publico.php';
  3. class muro{
  4. //constructor
  5. function muro(){
  6. include 'conexion_publico.php';
  7. }
  8. function graba_foto( $user) {
  9. $dml = " INSERT INTO fotos "
  10. ." (id_usuario"
  11. .", path_foto"
  12. .", nombre_foto_weddcam"
  13. .", nombre_foto"
  14. .", titulo)"
  15. ." VALUES "
  16. ."('".$user['id_usuario']."'"
  17. .",'fotos/'"
  18. .",'".$user['nombre_foto_weddcam']."'"
  19. .",'".$user['nombre_foto']."'"
  20. .",'".$user['titulo']."'"
  21. .")";
  22. $result=mysql_query($dml) or die("error3-altafoto".mysql_error());
  23. if (!$result)
  24. {
  25. return false;
  26. }
  27. $id_foto=mysql_insert_id();
  28. $dml = " INSERT INTO rankingfotos "
  29. ." (id_foto"
  30. .", id_categoria"
  31. .", fecha_voto"
  32. .", numero_votos)"
  33. ." VALUES "
  34. ."('".$id_foto."'"
  35. .",'".$user['id_categoria']."'"
  36. .",'".$user['fecha_voto']."'"
  37. .",'".$user['n_votos']."'"
  38. .")";
  39. $result=mysql_query($dml) or die("error3-altarankingfotos".mysql_error());
  40. if (!$result)
  41. {
  42. return false;
  43. }
  44. mysql_close();
  45. return true;
  46. }
  47. function graba_muro( $user) {
  48. $id_foto=0;
  49. if ($user['tipo_publicacion']==="f") {
  50. $dml = " INSERT INTO fotos "
  51. ." (id_usuario"
  52. .", path_foto"
  53. .", nombre_foto_weddcam"
  54. .", nombre_foto"
  55. .", titulo)"
  56. ." VALUES "
  57. ."('".$user['id_usuario']."'"
  58. .",'fotos/'"
  59. .",'".$user['nombre_foto_weddcam']."'"
  60. .",'".$user['nombre_foto']."'"
  61. .",'".$user['titulo']."'"
  62. .")";
  63. $result=mysql_query($dml) or die("error3-altafoto".mysql_error());
  64. if (!$result)
  65. {
  66. return false;
  67. }
  68. $id_foto=mysql_insert_id();
  69. }
  70. $dml = " INSERT INTO muro "
  71. ." (id_usuario"
  72. .", tipo_publicacion"
  73. .", titulo"
  74. .", id_foto"
  75. .", nombre_foto_weddcam"
  76. .", txt_publicacion)"
  77. ." VALUES "
  78. ."('".$user['id_usuario']."'"
  79. .",'".$user['tipo_publicacion']."'"
  80. .",'".$user['titulo']."'"
  81. .",'".$id_foto."'"
  82. .",'".$user['nombre_foto_weddcam']."'"
  83. .",'".$user['txt_publicacion']."'"
  84. .")";
  85. $result=mysql_query($dml) or die("error3-altamuro".mysql_error());
  86. if (!$result)
  87. {
  88. return false;
  89. }
  90. $id_publicacion=mysql_insert_id();
  91. $dml = " INSERT INTO muro_relaciones "
  92. ."(id_usuario,id_destinatario,id_publicacion) values ('" .$user['id_usuario'] ."','" .$user['id_usuario'] ."','" .$id_publicacion. "')";
  93. $result=mysql_query($dml) or die("error3-altamuro".mysql_error());
  94. if (!$result)
  95. {
  96. return false;
  97. }
  98. //Esto hace que se guarde una relacion de la publicacion en todos los amigos
  99. $dml = " INSERT INTO muro_relaciones "
  100. ."(id_usuario,id_destinatario,id_publicacion) "
  101. ." SELECT id_usuario,id_usuario2,'".$id_publicacion ."'"
  102. ." FROM relaciones_usuarios "
  103. ." WHERE situacion = '1' and id_usuario ='" .$user['id_usuario'] ."'" ;
  104. $result=mysql_query($dml) or die("error3-altamuro".mysql_error());
  105. if (!$result)
  106. {
  107. return false;
  108. }
  109. mysql_close();
  110. return $id_publicacion;
  111. }
  112. function trae_publicaciones($dato)
  113. {
  114. //return mysql_query("SELECT * from muro where id_usuario='".$dato."' order by fecha_alta desc limit 20");
  115. return mysql_query("SELECT * from muro inner join muro_relaciones on muro.id_publicacion=muro_relaciones.id_publicacion where muro_relaciones.id_destinatario='".$dato."' order by fecha_alta desc limit 20");
  116. }
  117. function trae_publicidad(&$banner, &$empresa_banner, &$anuncio, &$empresa_anuncio)
  118. {
  119. if (isset($_SESSION['tramo_edad'])) { // estoy logueado
  120. // banner primero busco si hay alguno para con el filtro de este usuario
  121. $dml = " SELECT id_empresa, id_ficha_empresa, nombre_foto, id_publicidad "
  122. ." FROM v_empresas_publicidad"
  123. ." WHERE (tipo='banner' and estado='1') "
  124. ." AND ".$_SESSION['tramo_edad']."=if(filtro_edad=0,".$_SESSION['tramo_edad'].",filtro_edad)"
  125. ." AND ".$_SESSION['estado_weddcam']."=if(filtro_estado=0,".$_SESSION['estado_weddcam'].",filtro_estado)"
  126. ." AND '".$_SESSION['sexo']."'=if(filtro_sexo=0,'".$_SESSION['sexo']."',filtro_sexo)"
  127. ." AND ".$_SESSION['id_comunidad']."=if(filtro_comunidad=0,".$_SESSION['id_comunidad'].",filtro_comunidad)"
  128. ." AND '".$_SESSION['id_provincia']."'=if(filtro_provincia=0,'".$_SESSION['id_provincia']."',filtro_provincia)"
  129. ." order by stamp asc limit 1"
  130. ;
  131. $result = mysql_query($dml) or die("error1-coge_banner".$dml.mysql_error());
  132. if ($aRow = mysql_fetch_array( $result )) {
  133. $stamp= date("Y-m-d H:i:s");
  134. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  135. $banner ="../publicidad/".$aRow['nombre_foto'];
  136. $empresa_banner =$aRow['id_empresa'].",".$aRow['id_ficha_empresa'];
  137. }
  138. /*
  139. else { // no hay banners para el filtro de este usuario, cojo cualquier banner
  140. $dml = " SELECT id_empresa, nombre_foto, id_publicidad "
  141. ." FROM v_empresas_publicidad"
  142. ." WHERE (tipo='banner' and estado='1') "
  143. ." order by stamp asc limit 1"
  144. ;
  145. $result2 = mysql_query($dml) or die("error2-coge_banner".$dml.mysql_error());;
  146. if ($aRow = mysql_fetch_array( $result2 )) {
  147. $stamp= date("Y-m-d H:i:s");
  148. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  149. $banner = "../publicidad/".$aRow['nombre_foto'];
  150. $empresa_banner =$aRow['id_empresa'];
  151. }
  152. */
  153. // anuncios primero busco si hay alguno para con el filtro de este usuario
  154. $dml = " SELECT id_empresa, id_ficha_empresa, nombre_foto, id_publicidad "
  155. ." FROM v_empresas_publicidad"
  156. ." WHERE (tipo='anuncio' and estado='1')"
  157. ." AND ".$_SESSION['tramo_edad']."=if(filtro_edad=0,".$_SESSION['tramo_edad'].",filtro_edad)"
  158. ." AND ".$_SESSION['estado_weddcam']."=if(filtro_estado=0,".$_SESSION['estado_weddcam'].",filtro_estado)"
  159. ." AND '".$_SESSION['sexo']."'=if(filtro_sexo=0,'".$_SESSION['sexo']."',filtro_sexo)"
  160. ." AND ".$_SESSION['id_comunidad']."=if(filtro_comunidad=0,".$_SESSION['id_comunidad'].",filtro_comunidad)"
  161. ." AND '".$_SESSION['id_provincia']."'=if(filtro_provincia=0,'".$_SESSION['id_provincia']."',filtro_provincia)"
  162. ." order by stamp asc limit 1"
  163. ;
  164. $result = mysql_query($dml) or die("error1-coge_anuncio".$dml.mysql_error());;
  165. if ($aRow = mysql_fetch_array( $result )) {
  166. $stamp= date("Y-m-d H:i:s");
  167. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  168. $anuncio ="../publicidad/".$aRow['nombre_foto'];
  169. $empresa_anuncio =$aRow['id_empresa'].",".$aRow['id_ficha_empresa'];
  170. }
  171. /*
  172. else { // no hay banners para el filtro de este usuario, cojo cualquier banner
  173. $dml = " SELECT id_empresa, nombre_foto, id_publicidad "
  174. ." FROM v_empresas_publicidad"
  175. ." WHERE (tipo='anuncio' and estado='1') "
  176. ." order by stamp asc limit 1"
  177. ;
  178. $result2 = mysql_query($dml) or die("error2-coge_anuncio".$dml.mysql_error());;
  179. if ($aRow = mysql_fetch_array( $result2 )) {
  180. $stamp= date("Y-m-d H:i:s");
  181. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  182. $anuncio ="../publicidad/".$aRow['nombre_foto'];
  183. $empresa_anuncio =$aRow['id_empresa'];
  184. }
  185. */
  186. return true;
  187. } else { //acceso publico
  188. $dml = " SELECT id_empresa, id_ficha_empresa, nombre_foto, id_publicidad "
  189. ." FROM v_empresas_publicidad"
  190. ." WHERE (tipo='banner' and estado='1') "
  191. ." order by stamp asc limit 1"
  192. ;
  193. $result2 = mysql_query($dml) or die("error2-coge_banner".$dml.mysql_error());;
  194. if ($aRow = mysql_fetch_array( $result2 )) {
  195. $stamp= date("Y-m-d H:i:s");
  196. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  197. $banner = "../publicidad/".$aRow['nombre_foto'];
  198. $empresa_banner =$aRow['id_empresa'].",".$aRow['id_ficha_empresa'];
  199. }
  200. $dml = " SELECT id_empresa,id_ficha_empresa, nombre_foto, id_publicidad "
  201. ." FROM v_empresas_publicidad"
  202. ." WHERE (tipo='anuncio' and estado='1') "
  203. ." order by stamp asc limit 1"
  204. ;
  205. $result2 = mysql_query($dml) or die("error2-coge_anuncio".$dml.mysql_error());;
  206. if ($aRow = mysql_fetch_array( $result2 )) {
  207. $stamp= date("Y-m-d H:i:s");
  208. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  209. $anuncio ="../publicidad/".$aRow['nombre_foto'];
  210. $empresa_anuncio =$aRow['id_empresa'].",".$aRow['id_ficha_empresa'];
  211. }
  212. }
  213. return true;
  214. }
  215. // fin funciones
  216. }
  217. ?>