Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/11/2011, 10:48
mysterio069
 
Fecha de Ingreso: abril-2010
Mensajes: 62
Antigüedad: 14 años
Puntos: 0
Pregunta Calendario con javascript y eventos php

Hola buenas tardes, hace un tiempo combine un calendario JavaScript con PHP para que me mostrara eventos que recogia de la base de datos y los marcaba en el calendario.
El problema es que el calendario no tiene la funcion de avanzar o retroceder de mes al hacer clic en algun boton, y no se me ocurre como hacerlo, necesito un poco de su tiempo ;)
Aqui el codigo para que lo revisen y por si alguien lo quiere utilizar:

Código Javascript:
Ver original
  1. <script LANGUAGE="JavaScript">
  2.  
  3. <!-- Begin
  4.  
  5. monthnames = new Array(
  6.  
  7. "Enero",
  8.  
  9. "Febrero",
  10.  
  11. "Marzo",
  12.  
  13. "Abril",
  14.  
  15. "Mayo",
  16.  
  17. "Junio",
  18.  
  19. "Julio",
  20.  
  21. "Agosto",
  22.  
  23. "Septiembre",
  24.  
  25. "Octubre",
  26.  
  27. "Noviembre",
  28.  
  29. "Diciembre");
  30.  
  31. var linkcount=0;
  32.  
  33. function addlink(month, day, href) {
  34.  
  35. var entry = new Array(3);
  36.  
  37. entry[0] = month;
  38.  
  39. entry[1] = day;
  40.  
  41. entry[2] = href;
  42.  
  43. this[linkcount++] = entry;
  44.  
  45. }
  46.  
  47. Array.prototype.addlink = addlink;
  48.  
  49. linkdays = new Array();
  50.  
  51. monthdays = new Array(12);
  52.  
  53. monthdays[0]=31;
  54.  
  55. monthdays[1]=28;
  56.  
  57. monthdays[2]=31;
  58.  
  59. monthdays[3]=30;
  60.  
  61. monthdays[4]=31;
  62.  
  63. monthdays[5]=30;
  64.  
  65. monthdays[6]=31;
  66.  
  67. monthdays[7]=31;
  68.  
  69. monthdays[8]=30;
  70.  
  71. monthdays[9]=31;
  72.  
  73. monthdays[10]=30;
  74.  
  75. monthdays[11]=31;
  76.  
  77. todayDate=new Date();
  78.  
  79. thisday=todayDate.getDay();
  80.  
  81. thismonth=todayDate.getMonth();
  82.  
  83. thisdate=todayDate.getDate();
  84.  
  85. thisyear=todayDate.getYear();
  86.  
  87. thisyear = thisyear % 100;
  88.  
  89. thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear));
  90.  
  91. if (((thisyear % 4 == 0)
  92.  
  93. && !(thisyear % 100 == 0))
  94.  
  95. ||(thisyear % 400 == 0)) monthdays[1]++;
  96.  
  97. startspaces=thisdate;
  98.  
  99. while (startspaces > 7) startspaces-=7;
  100.  
  101. startspaces = thisday - startspaces + 0;
  102.  
  103. if (startspaces < 0) startspaces+=7;
  104.  
  105.  
  106.  
  107. <?
  108.  
  109.  
  110.  
  111. $conexion=mysql_connect($mysql_server,$mysql_login,$mysql_pass) or die ("Error en la conexion");
  112.  
  113. mysql_select_db("bd",$conexion);
  114.  
  115. $diames = date(j);
  116.  
  117. $numeromes=date(n);
  118.  
  119. $sql="SELECT * FROM calendario";
  120.  
  121. $consulta=mysql_query($sql,$conexion);
  122.  
  123.  
  124.  
  125. while($fila=mysql_fetch_array ($consulta)){
  126.  
  127. $fecha=$fila['fecha'];
  128.  
  129. $dia=date("d",strtotime($fecha));
  130.  
  131. $mes=date("m",strtotime($fecha));
  132.  
  133. echo( "linkdays.addlink(".$mes.",".$dia.", 'eventos.php?&id=".$fila[0]."');" );
  134.  
  135. }
  136.  
  137. ?>
  138.  
  139. document.write('<table id="calendar" class="calendar" cellspacing="0" cellpadding="0" ');
  140.  
  141. document.write("<caption>"
  142.  
  143. + monthnames[thismonth] + " " + thisyear
  144.  
  145. + " </caption>");
  146.  
  147. document.write("<tr>");
  148.  
  149. document.write("<th scope='col'>Lu</th>");
  150.  
  151. document.write("<th scope='col'>Ma</th>");
  152.  
  153. document.write("<th scope='col'>Mi</th>");
  154.  
  155. document.write("<th scope='col'>Ju</th>");
  156.  
  157. document.write("<th scope='col'>Vi</th>");
  158.  
  159. document.write("<th scope='col'>Sa</th>");
  160.  
  161. document.write("<th scope='col'>Do</th>");
  162.  
  163. document.write("</tr>");
  164.  
  165. document.write("<tr>");
  166.  
  167. for (s=0;s<startspaces;s++) {
  168.  
  169. document.write("<td> </td>");
  170.  
  171. }
  172.  
  173. count=1;
  174.  
  175. no="";
  176.  
  177. while (count <= monthdays[thismonth]) {
  178.  
  179. for (b = startspaces;b<7;b++) {
  180.  
  181. linktrue=false;
  182.  
  183. document.write("<td");
  184.  
  185. for (c=0;c<linkdays.length;c++) {
  186.  
  187. if (linkdays[c] != null) {
  188.  
  189. if ((linkdays[c][0]==thismonth + 1) && (linkdays[c][1]==count)) {
  190.  
  191. if(count==thisdate){
  192.  
  193. document.write(" class='today'><a href=\"" + linkdays[c][2] + "\">");
  194.  
  195. linktrue=true;
  196.  
  197. no="no";
  198.  
  199. }
  200.  
  201. else{
  202.  
  203. document.write("><a href=\"" + linkdays[c][2] + "\">");
  204.  
  205. linktrue=true;}
  206.  
  207.       }
  208.  
  209.    }
  210.  
  211. }
  212.  
  213. if ((count==thisdate) && (no!="no")) {
  214.  
  215. document.write(" class='today'>" + count);
  216.  
  217. }
  218.  
  219. else{
  220.  
  221. if (count <= monthdays[thismonth]) {
  222.  
  223. document.write(">" + count);
  224.  
  225. }
  226.  
  227. else {
  228.  
  229. document.write(" ");
  230.  
  231. }
  232.  
  233. }
  234.  
  235. if (linktrue)
  236.  
  237. document.write("</a>");
  238.  
  239. document.write("</td>");
  240.  
  241. count++;
  242.  
  243. }
  244.  
  245. document.write("</tr>");
  246.  
  247. document.write("<tr>");
  248.  
  249. startspaces=0;
  250.  
  251. }
  252.  
  253. document.write("</table></p>");
  254.  
  255. // End -->
  256.  
  257. </script>