Ver Mensaje Individual
  #32 (permalink)  
Antiguo 01/02/2012, 15:42
Avatar de function
function
 
Fecha de Ingreso: abril-2010
Mensajes: 278
Antigüedad: 14 años
Puntos: 13
Respuesta: desplear dias de la semana en concordancia

Andres Muchisimas Gracias por la respuesta,

He estado muy ocupado y no pude volver antes a este proyecto.

Bien pongo lo que tengo hasta el momento, funciona de maravilla
Código PHP:
Ver original
  1. <?php
  2. //Hacemos el if/else para ver si se han seteado en la url mediante GET los parametros wk = semana
  3. $week = isset($_GET['wk']) ? $_GET['wk'] : '';
  4. //Si es lunes calculamos a partir de la fecha actual
  5. if(date('w') == 1) {
  6.     //verificamos si la variable $week no esta vacia
  7.     if(!empty($week)){
  8.         //Si no esta vacia agregamos el valor de $week asignandole la marca de tiempo UNIX
  9.         $ul = strtotime("$week week", time());
  10.     } else {
  11.         //Si esta vacia simplemente le damos la marca de tiempo UNIX
  12.         $ul = time();
  13.     }
  14. } else {
  15.     if(!empty($week)){
  16.         $ul = strtotime("last monday $week week");
  17.     } else {
  18.         $ul = strtotime('last monday');
  19.     }
  20. }
  21. //Array con los dias de la semana
  22. $dias_semana = array('Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo');
  23. //Bucle para mostrar los 7 dias de la semana
  24. for($i=0;$i<7;$i++){
  25.     //Sumamos días a la fecha del lunes actual
  26.     $sd = strtotime("+$i day", $ul);
  27.     //comprobamos si la fecha del bucle es la fecha actual
  28.     if(date('Y-m-d', $sd) === date('Y-m-d')) {
  29.         //colocamos el dia actual en rojo y ponemos el array para mostrar los dias en español
  30.         echo '<font color="red">'.$dias_semana[$i].''.date("d", $sd).'</font> ';
  31.     } else {
  32.         //colocamos el el resto de los dias en gris y ponemos el array para mostrar los dias en español
  33.         echo '<font color="gray">'.$dias_semana[$i].''.date("d", $sd).'</font> ';
  34.     }
  35. }
  36. //agregamos los links de asignacion de cambo, es decir para pasar de una semana a otra
  37. echo '<br />';
  38. ?>
  39. <a href="index.php?wk=<?php echo $week-1; ?>">Semana Anterior</a>-<a href="index.php?wk=<?php echo $week+1; ?>">Semana Siguiente</a>

Ahora me pongo a implementarlo y sacar horas mediante bd el modelo a seguir es el siguiente
Código HTML:
Ver original
  1. <table cellspacing="3" cellpadding="2" border="0" bgcolor="#f00"    >
  2.     <tr>
  3.         <td colspan="7">
  4.             <!-- Table: Header -->
  5.             <table width="100%" cellspacing="2" cellpadding="2" border="0" bgcolor="#ccc">
  6.                 <tr>
  7.                     <td bgcolor="#fff">Mes - A&ntilde;o Anterior</td>
  8.                     <td>Mes A&ntilde;o</td>
  9.                     <td bgcolor="#fff">Mes - A&ntilde;o Siguiente</td>
  10.                 </tr>
  11.             </table>
  12.             <!-- Table: Header -->
  13.         </td>
  14.     </tr>
  15.     <tr>
  16.         <td width="12.5%"></td>
  17.         <td width="12.5%">Lunes</td>
  18.         <td width="12.5%">Martes</td>
  19.         <td width="12.5%">Miercoles</td>
  20.         <td width="12.5%">Jueves</td>
  21.         <td width="12.5%">Viernes</td>
  22.         <td width="12.5%">Sabado</td>
  23.         <td width="12.5%">Domingo</td>
  24.     </tr>
  25.     <tr>
  26.         <td width="12.5%">6:00</td>
  27.         <td width="12.5%">Reunion</td>
  28.     </tr>
  29.     <tr>
  30.         <td width="12.5%">7:00</td>
  31.     </tr>
  32.     <tr>
  33.         <td width="12.5%">8:00</td>
  34.     </tr>
  35.     <tr>
  36.         <td width="12.5%">9:00</td>
  37.     </tr>
  38.     <tr>
  39.         <td width="12.5%">10:00</td>
  40.     </tr>
  41.     <tr>
  42.         <td width="12.5%">11:00</td>
  43.     </tr>
  44.     <tr>
  45.         <td width="12.5%">12:00</td>
  46.     </tr>
  47.     <tr>
  48.         <td width="12.5%">13:00</td>
  49.     </tr>
  50.     <tr>
  51.         <td width="12.5%">14:00</td>
  52.     </tr>
  53.     <tr>
  54.         <td width="12.5%">15:00</td>
  55.     </tr>
  56.     <tr>
  57.         <td width="12.5%">16:00</td>
  58.     </tr>
  59.     <tr>
  60.         <td width="12.5%">17:00</td>
  61.     </tr>
  62.     <tr>
  63.         <td width="12.5%">18:00</td>
  64.     </tr>
  65.     <tr>
  66.         <td width="12.5%">19:00</td>
  67.     </tr>
  68.     <tr>
  69.         <td width="12.5%">20:00</td>
  70.     </tr>
  71.     <tr>
  72.         <td width="12.5%">21:00</td>
  73.     </tr>
  74.     </tr>

la implementacion con el codigo de los dias mas esto seria:
Código PHP:
Ver original
  1. <?php
  2. //DB connection
  3. include_once 'db_con.php';
  4.  
  5. //Hacemos el if/else para ver si se han seteado en la url mediante GET los parametros wk = semana
  6. $week = isset($_GET['wk']) ? $_GET['wk'] : '';
  7. //Si es lunes calculamos a partir de la fecha actual
  8. if(date('w') == 1) {
  9.     //verificamos si la variable $week no esta vacia
  10.     if(!empty($week)){
  11.         //Si no esta vacia agregamos el valor de $week asignandole la marca de tiempo UNIX
  12.         $ul = strtotime("$week week", time());
  13.     } else {
  14.         //Si esta vacia simplemente le damos la marca de tiempo UNIX
  15.         $ul = time();
  16.     }
  17. } else {
  18.     if(!empty($week)){
  19.         $ul = strtotime("last monday $week week");
  20.     } else {
  21.         $ul = strtotime('last monday');
  22.     }
  23. }
  24. //Array con los dias de la semana
  25. $dias_semana = array('Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo');
  26. //Array Horas del dia
  27. $hours = array("6:00", "7:00", "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00");
  28. ?>
  29. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml">
  31. <head>
  32. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  33. <title>Calendar Sample</title>
  34. <link rel="shortcut icon" href="icon" />
  35. <link href="styles.css" rel="stylesheet" type="text/css" />
  36. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  37. <script language="javascript" type="text/javascript">
  38. $(document).ready(function(){
  39.     var h = document.body.scrollHeight;
  40.     var nh = Math.round(h/17);
  41.     $('.tableheight').css({'height':h});
  42.     $('.trheight').css({'height':nh});
  43.    
  44. });
  45. </script>
  46. </head>
  47.  
  48. <body>
  49. <!-- Table: General -->
  50. <table class="tableheight" width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ddd"   >
  51.     <tr>
  52.         <td class="trheight"><a href="index.php?wk=<?php echo $week-1; ?>">Prev</a>-<a href="index.php?wk=<?php echo $week+1; ?>">Next</a></td>
  53.         <?php
  54.         //Bucle para mostrar los 7 dias de la semana
  55.         for($i=0;$i<7;$i++){
  56.             //Sumamos días a la fecha del lunes actual
  57.             $sd = strtotime("+$i day", $ul);
  58.             //comprobamos si la fecha del bucle es la fecha actual
  59.             if(date('Y-m-d', $sd) === date('Y-m-d')) { 
  60.                 //colocamos el dia actual en rojo y ponemos el array para mostrar los dias en español
  61.                 echo '<td width="12.5%"><font color="red">'.$dias_semana[$i].', '.date("d", $sd).'</font></td>';
  62.             } else {
  63.                 //colocamos el el resto de los dias en gris y ponemos el array para mostrar los dias en español
  64.                 echo '<td width="12.5%"><font color="black">'.$dias_semana[$i].', '.date("d", $sd).'</font></td>';
  65.             }
  66.         }
  67.         ?>
  68.     </tr>
  69. </table>
  70. </body>
  71. </html>


Como hago el para que las horas coincidan dentro de cada columna segun el dia, alguna idea???
__________________
~# echo Hemos logrado la independencia, pero no la libertad >> SimonBolivar