PageRenderTime 79ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/perfil/clases/dlm_evento.php

https://bitbucket.org/weddcam/develop_weddcam
PHP | 322 lines | 293 code | 27 blank | 2 comment | 33 complexity | 9041e63109d58fd2c224826adf53d5ed 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 evento{
  4. //constructor
  5. function evento(){
  6. include 'conexion_publico.php';
  7. }
  8. function trae_publicidad(&$banner, &$empresa_banner, &$anuncio, &$empresa_anuncio)
  9. {
  10. $dml = " SELECT id_empresa, nombre_foto, id_publicidad "
  11. ." FROM v_empresas_publicidad"
  12. ." WHERE (tipo='banner' and estado='1') "
  13. ." order by stamp asc limit 1"
  14. ;
  15. $result2 = mysql_query($dml) or die("error2-coge_banner".$dml.mysql_error());
  16. if ($aRow = mysql_fetch_array( $result2 )) {
  17. $stamp= date("Y-m-d H:i:s");
  18. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  19. $banner = "../publicidad/".$aRow['nombre_foto'];
  20. $empresa_banner =$aRow['id_empresa'];
  21. }
  22. $dml = " SELECT id_empresa, nombre_foto, id_publicidad "
  23. ." FROM v_empresas_publicidad"
  24. ." WHERE (tipo='anuncio' and estado='1') "
  25. ." order by stamp asc limit 1"
  26. ;
  27. $result2 = mysql_query($dml) or die("error2-coge_anuncio".$dml.mysql_error());
  28. if ($aRow = mysql_fetch_array( $result2 )) {
  29. $stamp= date("Y-m-d H:i:s");
  30. $result2 = mysql_query(" UPDATE empresas_publicidad SET stamp='".$stamp."' where id_publicidad='".$aRow['id_publicidad']."' ");
  31. $anuncio ="../publicidad/".$aRow['nombre_foto'];
  32. $empresa_anuncio =$aRow['id_empresa'];
  33. }
  34. return true;
  35. }
  36. function trae_paises()
  37. {
  38. return mysql_query("SELECT * from paises order by pais");
  39. }
  40. function trae_provincias()
  41. {
  42. return mysql_query("SELECT * from provincias order by provincia");
  43. }
  44. function dame_apellidos($dato)
  45. {
  46. $total=mysql_query("SELECT nombre, apellidos from usuarios where id_usuario='".$dato."'") or die("error2-comprueba_email".mysql_error());
  47. $aRow = mysql_fetch_array( $total );
  48. if(!$aRow)
  49. {
  50. $respuesta="";
  51. }
  52. else
  53. {
  54. $respuesta=trim($aRow['nombre'])." ".trim($aRow['apellidos']);
  55. }
  56. return $respuesta;
  57. }
  58. function comprueba_email($dato,$dato2)
  59. {
  60. $total=mysql_query("SELECT nick,nombre_foto_perfil,id_usuario from usuarios where e_mail='".$dato."'") or die("error2-comprueba_email".mysql_error());
  61. $aRow = mysql_fetch_array( $total );
  62. if(!$aRow)
  63. {
  64. $respuesta="NO@";
  65. }
  66. else
  67. {
  68. $apellidos1=$this->dame_apellidos($dato2);
  69. $apellidos2=$this->dame_apellidos($aRow['id_usuario']);
  70. $respuesta="SI@".$aRow['nick']."@".$aRow['id_usuario']."@".$aRow['nombre_foto_perfil']."@".$apellidos1.", ".$apellidos2;
  71. }
  72. mysql_close();
  73. return $respuesta;
  74. }
  75. function get_plantilla($plantilla)
  76. {
  77. $dml = "SELECT cabecera,cuerpo,pie FROM plantillas WHERE nombre='". $plantilla ."'";
  78. $result = mysql_query($dml) or die("error-leer_plantilla".mysql_error());
  79. if($row = mysql_fetch_array($result)) {
  80. return $row;
  81. }
  82. else {
  83. return 0;
  84. }
  85. }
  86. function graba_evento_con_id( $user, &$id_evento)
  87. {
  88. $result=true;
  89. $campos=""; $valores="";
  90. foreach ($user as $key=>$value){
  91. $campos .= "" .$key .",";
  92. $valores .= "'" .$user[$key] ."'," ;
  93. }
  94. $dml = " INSERT INTO eventos (" .substr($campos,0,-1) .") VALUES (". substr($valores,0,-1) .")" ;
  95. $result=mysql_query($dml) or die("error3-altaEventos".mysql_error());
  96. if (!$result)
  97. {
  98. return false;
  99. }
  100. $id_evento=mysql_insert_id();
  101. if (strlen($user['nombre_foto_evento'])>0) {
  102. $nombre_foto_evento="evento_".$id_evento.".jpg";
  103. $dml = " UPDATE eventos SET nombre_foto_evento='".$nombre_foto_evento."' where id_evento='".$id_evento."' ";
  104. $result=mysql_query($dml) or die("error4-altaEventos".mysql_error());
  105. }
  106. $dml = " UPDATE usuarios SET id_evento='".$id_evento."' where id_usuario='".$user['id_usuario1']."' ";
  107. $result=mysql_query($dml) or die("error5-altaEventos".mysql_error());
  108. $dml = " UPDATE usuarios SET id_evento='".$id_evento."' where id_usuario='".$user['id_usuario2']."' ";
  109. $result=mysql_query($dml) or die("error6-altaEventos".mysql_error());
  110. mysql_close();
  111. return true;
  112. }
  113. function borra_evento( $id_evento,$id_usuario)
  114. {
  115. $result=true;
  116. $result=mysql_query("DELETE from eventos WHERE id_evento='".$id_evento."'") or die("error-borrar-evento".mysql_error());
  117. if (!$result)
  118. {
  119. return false;
  120. }
  121. $dml = " UPDATE usuarios SET id_evento='0' where id_usuario='".$id_usuario."' ";
  122. $result=mysql_query($dml) or die("error3-altaEventos".mysql_error());
  123. mysql_close();
  124. return true;
  125. }
  126. function trae_evento($dato)
  127. {
  128. return mysql_query("SELECT * from eventos where id_evento='".$dato."' ");
  129. }
  130. function trae_usuario2($dato)
  131. {
  132. return mysql_query("SELECT nombre_foto_perfil,nick from usuarios where id_usuario='".$dato."' ");
  133. }
  134. function activa($clave1, &$clave2) {
  135. $pass=$clave2;
  136. $nick="I=P/(1.73*U*cosfi)=610/(";
  137. $nick = $this->desencriptar(base64_decode($clave2), $nick);
  138. $clave2=$nick;
  139. $result=mysql_query("SELECT estado from eventos where id_evento='".$nick."'") or die("error3-ActivaUsuarios".mysql_error());
  140. if (!$result) { return false; }
  141. if($row = mysql_fetch_array($result)) {
  142. if ($row['estado']=='1') return false; // SI VUELVEN A ACTIVAR DEVUELVE FALSE
  143. }
  144. return true;
  145. }
  146. function activa_evento($id_evento,&$phpid) {
  147. $result=mysql_query("SELECT * from eventos where id_evento='".$id_evento."'") or die("error4-ActivaUsuarios".mysql_error());
  148. if (!$result) { return false; }
  149. if($row = mysql_fetch_array($result)) {
  150. if ($row['estado']=='1') return false; // SI VUELVEN A ACTIVAR DEVUELVE FALSE
  151. $result1=mysql_query("SELECT * from usuarios where id_usuario='".$row['id_usuario1']."' ") or die("error5-ActivaUsuarios".mysql_error());
  152. if(!$user1 = mysql_fetch_array($result1)) { return false;}
  153. $result2=mysql_query("SELECT * from usuarios where id_usuario='".$row['id_usuario2']."' ") or die("error6-ActivaUsuarios".mysql_error());
  154. if(!$user2 = mysql_fetch_array($result2)) { return false;}
  155. $user=array();
  156. $user['nick']=$user1['nick']."-".$user2['nick'];
  157. $user['e_mail']="evento".$id_evento."@weddcam.es";
  158. $user['password']=md5("evento".$id_evento);
  159. $user['nombre_foto_perfil']=$row['nombre_foto_evento'];
  160. $user['nombre']=$row['nombre_pareja'];
  161. $user['apellidos']= $user1['apellidos'];
  162. $user['estado_weddcam']= $user1['estado_weddcam'];
  163. $user['sexo']= $user1['sexo'];
  164. $user['id_pais']= $user1['id_pais'];
  165. $user['id_provincia']= $row['id_provincia'];
  166. $user['id_poblacion']= "0";
  167. $user['poblacion']= $row['poblacion'];
  168. $user['cp']= $row['cp'];
  169. $user['fecha_nacimiento']=$user1['fecha_nacimiento'];
  170. $user['tipo_usuario']=0;
  171. $user['estado']=3; // estado 0-ok, 1-bloqueado, 2-inactivo 3-usuario evento
  172. $user['id_perfil']="0";
  173. $id_usuario="";
  174. $campos=""; $valores="";
  175. foreach ($user as $key=>$value){
  176. $campos .= "" .$key .",";
  177. $valores .= "'" .$user[$key] ."'," ;
  178. }
  179. $dml = " INSERT INTO usuarios (" .substr($campos,0,-1) .") VALUES (". substr($valores,0,-1) .")" ;
  180. $result4=mysql_query($dml) or die("error3-altausuario".$dml.mysql_error());
  181. if (!$result4)
  182. {
  183. return false;
  184. }
  185. $id_usuario=mysql_insert_id();
  186. $result5=mysql_query("UPDATE usuarios SET id_usuario_evento='".$id_usuario."' where id_usuario='".$row['id_usuario1']."'") or die("error8-ActivaUsuarios".mysql_error());
  187. if (!$result5) { return false; }
  188. $result6=mysql_query("UPDATE usuarios SET id_evento='".$id_evento."', id_usuario_evento='".$id_usuario."' where id_usuario='".$row['id_usuario2']."'") or die("erro9-ActivaUsuarios".mysql_error());
  189. if (!$result6) { return false; }
  190. $result7=mysql_query("UPDATE eventos SET estado='1', nick='".$user['nick']."', id_usuario_evento='".$id_usuario."' where id_evento='".$id_evento."'") or die("erro10-ActivaUsuarios".mysql_error());
  191. if (!$result7) { return false; }
  192. $phpid = $id_usuario.md5(chr(rand(97,122)).uniqid());
  193. session_name($phpid);
  194. session_start();
  195. $_SESSION['tipo_usuario'] = '1';
  196. $_SESSION['nick'] = $user1['nick'];
  197. $_SESSION['id_usuario'] = $id_usuario;
  198. $_SESSION['nombre'] = $user1['nombre'];
  199. $_SESSION['id_empresa'] = '0';
  200. $_SESSION['nombre_foto_perfil'] = $row['nombre_foto_evento'];
  201. $_SESSION['modo']="privado";
  202. $_SESSION['que_te_pires']=time() + 1200; //20 minutitos
  203. $tramo=$this->dame_edad($user1['fecha_nacimiento']);
  204. $_SESSION['edad']=$tramo;
  205. $_SESSION['tramo_edad']=$this->dame_tramo($tramo);
  206. $_SESSION['modalidad_contratacion'] = 0;
  207. $_SESSION['id_provincia'] =$row['id_provincia'];
  208. $_SESSION['id_comunidad'] = 0;
  209. $_SESSION['sexo'] = $user['sexo'];
  210. $_SESSION['estado_weddcam'] = $user['estado_weddcam'];
  211. $_SESSION['id_evento'] = $id_evento;
  212. $_SESSION['estado_evento'] = "1";
  213. session_commit();
  214. return true;
  215. }
  216. return false;
  217. }
  218. function actualiza_evento($user,$id_evento)
  219. {
  220. $result=true;
  221. $campos=""; $valores="";
  222. foreach ($user as $key=>$value){
  223. $campos .= "" . $key ."= '". $user[$key] ."'," ;
  224. }
  225. $dml = " UPDATE eventos SET " .substr($campos,0,-1) ." WHERE id_evento='" . $id_evento."'";
  226. $result=true;
  227. $result=mysql_query($dml) or die("error-actualizando-evento".mysql_error());
  228. if (!$result)
  229. return false;
  230. return true;
  231. }
  232. function graba_agenda_con_id( $user, &$id_agenda)
  233. {
  234. $result=true;
  235. $campos=""; $valores="";
  236. foreach ($user as $key=>$value){
  237. $campos .= "" .$key .",";
  238. $valores .= "'" .$user[$key] ."'," ;
  239. }
  240. $dml = " INSERT INTO eventos_agenda (" .substr($campos,0,-1) .") VALUES (". substr($valores,0,-1) .")" ;
  241. $result=mysql_query($dml) or die("error3-altaEventos_agenda".mysql_error());
  242. if (!$result)
  243. {
  244. return false;
  245. }
  246. $id_agenda=mysql_insert_id();
  247. if (isset($user['album'])) { // si han chequeado album, creamos un album
  248. $dml = " INSERT INTO eventos_album (id_evento, id_evento_agenda,titulo) VALUES ('".$user['id_evento']."','".$id_agenda."', '".$user['titulo_album']."')" ;
  249. $result=mysql_query($dml) or die("error4-altaEventos_agenda".mysql_error());
  250. if (!$result)
  251. {
  252. return false;
  253. }
  254. }
  255. mysql_close();
  256. return true;
  257. }
  258. function desencriptar($cadena, $clave)
  259. {
  260. $cifrado = MCRYPT_RIJNDAEL_256;
  261. $modo = MCRYPT_MODE_ECB;
  262. return mcrypt_decrypt($cifrado, $clave, $cadena, $modo, mcrypt_create_iv(mcrypt_get_iv_size($cifrado, $modo), MCRYPT_RAND));
  263. }
  264. function dame_edad($date)
  265. {
  266. $fecha=strftime('%d/%m/%Y',strtotime($date));
  267. $part=explode("/",$fecha);
  268. $b_day=$part[0];
  269. $b_month=$part[1];
  270. $b_year=$part[2];
  271. $time=time();
  272. $day=date("d",$time);
  273. $month=date("m",$time);
  274. $year=date("Y",$time);
  275. if ( $month >= $b_month AND $day >= $b_day ) $age = $year-$b_year;
  276. else $age = $year-$b_year-1;
  277. return $age;
  278. }
  279. function dame_tramo($tramo) {
  280. $rango=0;
  281. $edad=(int)$tramo;
  282. $consulta2 =mysql_query("SELECT * from rango_edad");
  283. if (!$consulta2) return $rango;
  284. while ( $aRow = mysql_fetch_array( $consulta2 ) )
  285. {
  286. if ( ($edad >= (int) $aRow['min']) && ($edad <= (int) $aRow['max'])) {
  287. $rango=$aRow['id_rango_edad'];
  288. break;
  289. }
  290. }
  291. return $rango;
  292. }
  293. // fin funciones
  294. }
  295. ?>