Ver Mensaje Individual
  #8 (permalink)  
Antiguo 24/05/2010, 13:17
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Butacas de una sala de cine

Hola

Como te comenté, está bastante en bruto

Cine.asp

Código Javascript:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <script type="text/javascript">
  7. var ns4 = (document.layers)? true:false
  8. var ie4 = (document.all)? true:false
  9. var ns6 = (document.getElementById)? true:false
  10.  
  11. function captura_objeto(idnombre) {
  12.     if (ns6) {
  13.     return document.getElementById(idnombre);
  14.     } else if (ie4) {
  15.     return document.all[idnombre];
  16.     } else if (ns4) {
  17.     return document.layers[idnombre];
  18.     } else{
  19.     return null;
  20.     }
  21. }
  22.  
  23.  
  24.  
  25. function creaAjax(){
  26. var ajax = false;
  27.           if (window.XMLHttpRequest) { // Mozilla, Safari,...
  28.         ajax = new XMLHttpRequest();
  29.  
  30.              if (ajax.overrideMimeType) {
  31.                     ajax.overrideMimeType('text/xml');
  32.              }
  33.           } else if (window.ActiveXObject) { // IE
  34.                  try {
  35.                         ajax = new ActiveXObject("Msxml2.XMLHTTP");
  36.                  } catch (e) {
  37.                     try {
  38.                            ajax = new ActiveXObject("Microsoft.XMLHTTP");
  39.                     } catch (e) {}
  40.                  }
  41.           }
  42.     return ajax;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. function Evento(elemento,nomevento,funcion) {
  50.       if (elemento.attachEvent) {
  51.               var f=function() {
  52.                 funcion.call(elemento,window.event);
  53.             }
  54.             elemento.attachEvent('on'+nomevento,f);
  55.             return true;
  56.       } else if (elemento.addEventListener) {
  57.               elemento.addEventListener(nomevento,funcion,false);
  58.               return true;
  59.         }else{
  60.               return false;
  61.     }
  62. }
  63.  
  64.  
  65.  
  66.  
  67. function init() {
  68. Evento(captura_objeto('hr'), 'change', function(){MuestraPatio(document.getElementById('fch').options[document.getElementById('fch').selectedIndex].value, document.getElementById('hr').options[document.getElementById('hr').selectedIndex].value)});
  69.  
  70. var img = captura_objeto('patio').getElementsByTagName('IMG');
  71.     for (i=0; i < img.length; i++) {
  72.                 Evento(captura_objeto(img[i].id), 'click', function(){MarcaButaca(this.id, document.getElementById('fch').options[document.getElementById('fch').selectedIndex].value, document.getElementById('hr').options[document.getElementById('hr').selectedIndex].value)});
  73.     }
  74. }
  75.  
  76.  
  77.  
  78. function MuestraPatio(fecha, hora) {
  79. var objetosel = '';
  80. var ajax = creaAjax();
  81. ajax.onreadystatechange = function() {
  82.  
  83.         if (ajax==null){
  84.         alert ('Tu navegador web no soporta AJAX!');
  85.         return;
  86.         }
  87.  
  88.      if (ajax.readyState==4){
  89.                        if(ajax.status==200){    
  90.             butacas = ajax.responseXML.documentElement.getElementsByTagName('butaca');
  91.    
  92.             for (i=0; i<butacas.length; i++) {
  93.                 objetosel = butacas[i].getElementsByTagName("reservada");
  94.                           window.document['butaca_libre_'+ objetosel[0].firstChild.nodeValue].src = './cine_ocupado.bmp';
  95.                 window.document['butaca_libre_'+ objetosel[0].firstChild.nodeValue].id = 'butaca_ocupada_'+ objetosel[0].firstChild.nodeValue;
  96.                   }
  97.                        }
  98.                        else if (ajax.status==404) {
  99.  
  100.                                     alert('La dirección no existe');
  101.         } else {
  102.                                     alert('Error: ' + ajax.status);
  103.                                     }
  104.                   }
  105. }
  106.     ajax.open('GET','cine_ajax.asp?butaca=&fecha='+fecha+'&hora='+hora,true);
  107.              ajax.send(null);
  108. }
  109.  
  110.  
  111.  
  112. function MarcaButaca(idbutaca, fecha, hora) {
  113. // Butaca ocupada
  114.     if (idbutaca.split('_')[1] == 'ocupada') {
  115.         alert('La butaca ' + idbutaca.split('_')[2] +' ya esta reservada')
  116.     } else {
  117. var objetosel = '';
  118. var ajax = creaAjax();
  119. ajax.onreadystatechange = function() {
  120.  
  121.         if (ajax==null){
  122.         alert ('Tu navegador web no soporta AJAX!');
  123.         return;
  124.         }
  125.  
  126.      if (ajax.readyState==4){
  127.                        if(ajax.status==200){    
  128.             butacas = ajax.responseXML.documentElement.getElementsByTagName('butaca');
  129.    
  130.             for (i=0; i<butacas.length; i++) {
  131.                 objetosel = butacas[i].getElementsByTagName('reservada');
  132.                           window.document['butaca_libre_'+ objetosel[0].firstChild.nodeValue].src = './cine_ocupado.bmp';
  133.                   }
  134.                        }
  135.                        else if (ajax.status==404) {
  136.  
  137.                                     alert('La dirección no existe');
  138.         } else {
  139.                                     alert('Error: ' + ajax.status);
  140.                                     }
  141.                   }
  142. }
  143.    
  144.     ajax.open('GET','cine_ajax.asp?butaca='+idbutaca.split("_")[2]+'&fecha='+fecha+'&hora='+hora,true);
  145.              ajax.send(null);
  146.     }
  147. }
  148.  
  149.  
  150. window.onload = init;
  151. </script>
  152. </head>
  153. <body>
  154. Reservar Butacas en el Cine<br /><br />
  155. fecha <select name="fch" id="fch">
  156. <option value="">Selecciona Fecha</option>
  157. <%
  158. For i = 0 to 31
  159. %>
  160. <option value="<%=Date()+i%>"><%=Date()+i%></option>
  161. <%
  162. Next 'i
  163. %>
  164. </select>
  165. <br /><br />
  166. hora <select name="hr" id="hr">
  167. <option value="">Selecciona Hora</option>
  168. <option value="1">10:00</option>
  169. <option value="2">11:00</option>
  170. <option value="3">12:00</option>
  171. <option value="4">13:00</option>
  172. </select>
  173. <br /><br /><br />
  174. Patio de Butacas<br />
  175. <div id="patio">
  176. <%
  177. For i = 1 to 25
  178. If i = 1 or i = 6 or i = 11 or i = 16 or i = 21 Then
  179. fila = (i / 5) +1
  180. Response.Write Int(fila) & " "
  181. End If
  182. Response.Write "<img src=""./cine_libre.bmp"" id=""butaca_libre_"&i&""" name=""butaca_libre_"&i&""" alt=""Butaca: "&i&""" title=""Butaca: "&i&""" />&nbsp;"
  183. If i = 5 or i = 10 or i = 15 or i = 20 or i = 25 Then
  184. Response.Write "<br />"
  185. End If
  186. Next 'i
  187. %>
  188. </div>
  189. </body>
  190. </html>


Cine_Ajax.asp

Código ASP:
Ver original
  1. <%
  2. Dim asiento, fch, hr, oConn, rs, SQL, registros, i
  3. Dim objStream
  4. Dim Butaca
  5. Butaca = 2
  6.  
  7. asiento = Request.QueryString("butaca")
  8. fch = Request.QueryString("fecha")
  9. hr = Request.QueryString("hora")
  10.  
  11. IF asiento = "" Then
  12.  
  13. ' Conexión a bd
  14. SQL ="SELECT Fecha, Hora, Butaca FROM Cine WHERE Fecha = #"&fch&"# AND Hora = "&hr&" ORDER BY Butaca ASC"
  15. set rs = oConn.Execute(SQL)
  16.  
  17. If rs.eof = True or rs.bof = True then
  18. Response.Write ""
  19. Else
  20. ' Recogemos los registros
  21. registros = rs.getrows()
  22. rs.Close
  23. Set rs = Nothing
  24. oConn.Close
  25. Set oConn = Nothing
  26. End If
  27.  
  28.  
  29. Response.Write "<?xml version=""1.0"" encoding=""UTF-8""?>"
  30. %>
  31. <anfiteatro>
  32. <%
  33. For i = 0 to UBound(registros,2)
  34. %>
  35. <butaca>
  36. <reservada><%=registros(Butaca,i)%></reservada>
  37. </butaca>
  38. <%
  39. Next 'i
  40. %>
  41. </anfiteatro>
  42. <%
  43.  
  44.  
  45. ELSE
  46.  
  47. 'Conexión bd
  48. SQL="INSERT INTO Cine (Fecha, Hora, Butaca) values (#"&fch&"#, "&hr&", "&asiento&")"
  49. oConn.Execute(SQL)
  50.  
  51. Response.Write "<?xml version=""1.0"" encoding=""UTF-8""?>"
  52. %>
  53. <anfiteatro>
  54. <butaca>
  55. <reservada><%=asiento%></reservada>
  56. </butaca>
  57. </anfiteatro>
  58. <%
  59. END IF
  60. %>

Como ves el ASP es fácilmente adaptable a PHP. Esta es básicamente la idea, ahora has de adaptarla a lo que te ocupa

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />