Foros del Web » Programando para Internet » PHP »

Coloreando un calendario...

Estas en el tema de Coloreando un calendario... en el foro de PHP en Foros del Web. Hola gente! estoy trabajando con un calendario en ajax+php...la base es el calendario que encontré en la web de bmgadg dot com la parte de ...
  #1 (permalink)  
Antiguo 05/04/2009, 12:00
 
Fecha de Ingreso: abril-2009
Mensajes: 38
Antigüedad: 10 años, 8 meses
Puntos: 1
Coloreando un calendario...

Hola gente!

estoy trabajando con un calendario en ajax+php...la base es el calendario que encontré en la web de bmgadg dot com

la parte de ajax va bien, pero al modificar la parte php para introducirle mysql y pintar un calendario tipico de disponibilidad hotelera (segun tablas de alquileres y temporadas) comienzan los problemas...intuyo que el problema está en que coje el primeri dia del bucle y ya me pinta todo el mes del mismo color...

además de este código que dejo aquí hay css y una clase javascript que controla la navegación entre los meses y los años...

al que se tome la molestía de intentar echarme un cable, muchas gracias de antemano

Código PHP:
<? 
session_start
();

                include (
"funciones.php");
                include (
"fecha.php");

$output '';
$month $_GET['month'];
$year $_GET['year'];
    
if(
$month == '' && $year == '') { 
    
$time time();
    
$month date('n',$time);
    
$year date('Y',$time);
}

$date getdate(mktime(0,0,0,$month,1,$year));
$today getdate();
$hours $today['hours'];
$mins $today['minutes'];
$secs $today['seconds'];

if(
strlen($hours)<2$hours="0".$hours;
if(
strlen($mins)<2$mins="0".$mins;
if(
strlen($secs)<2$secs="0".$secs;

                                            
$days=date("t",mktime(0,0,0,$month,1,$year));
                                            
$start $date['wday']+1;
                                            
$mes=$date['month'];
                                                if (
$mes=="January"$mes="Enero"
                                                if (
$mes=="February"$mes="Febrero";
                                                if (
$mes=="March"$mes="Marzo";
                                                if (
$mes=="April"$mes="Abril";
                                                if (
$mes=="May"$mes="Mayo"
                                                if (
$mes=="June"$mes="Junio"
                                                if (
$mes=="July"$mes="Julio"
                                                if (
$mes=="August"$mes="Agosto"
                                                if (
$mes=="September"$mes="Setiembre";
                                                if (
$mes=="October"$mes="Octubre"
                                                if (
$mes=="November"$mes="Noviembre"
                                                if (
$mes=="December"$mes="Diciembre";                                            
                                            
$name $mes;
                                            
$year2 $date['year'];
                                            
$offset $days $start 1;                                             
 
if(
$month==12) { 
    
$next=1
    
$nexty=$year 1
} else { 
    
$next=$month 1
    
$nexty=$year
}

if(
$month==1) { 
    
$prev=12
    
$prevy=$year 1
} else { 
    
$prev=$month 1
    
$prevy=$year
}

if(
$offset <= 28$weeks=28
elseif(
$offset 35$weeks 42
else 
$weeks 35

$output .= "
<table class='cal' cellspacing='1'>
<tr>
    <td colspan='7'>
        <table class='calhead'>
        <tr>
            <td>
                <a href='javascript:navigate($prev,$prevy)'><img src='img/prev.png' /></a></td><td><b>$name $year2</b></td><td><a href='javascript:navigate($next,$nexty)'><img src='img/next.png' /></a>
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr class='dayhead'>
    <td>S</td>
    <td>M</td>
    <td>T</td>
    <td>W</td>
    <td>T</td>
    <td>F</td>
    <td>S</td>
</tr>"
;

$col=1;
$cur=1;
$next=0;

        
$calcnx=conectar();
        
        
$s "select entrada, salida from registros where idapart = '".$_SESSION["id"]."'";
        
$forbook mysql_query($s,$calcnx) or die (mysql_error());    
        
$ss "select * from "$_SESSION["tablatemp"];
        
$fortemp mysql_query($ss,$calcnx) or die (mysql_error());
        
mysql_close($calcnx);
        
for(
$i=1;$i<=$weeks;$i++) { 
    if(
$next==3$next=0;
    if(
$col==1$output.="<tr class='dayrow'>"
      
    
$output.="<td valign='top' >";

                                                if(
$i <= ($days+($start-1)) && $i >= $start
                                                {
        /
booked=0;
        
$tempo=0;
        
        
//asi venía originalmente, y pintaba días unicamente en blanco, yo quiero colores
        
        //if($cur<10) {$curb="0".$cur;} else{$curb=$cur;}
        //if($month<10) {$monthb="0".$month;} else{$monthb=$month;}
        //$a=array ($year, $monthb, $curb);
        //$now=implode("-", $a);
        
        
$now=mktime(0,0,0,$month,$cur,$year);
                                                                            if (
mysql_num_rows($forbook) > 0)
                                                                            {
                                                                                while(
$filabook mysql_fetch_array($forbook))
                                                                                {
                                                                                        
$na explode("-",$filabook['entrada']);
                                                                                        
$lowDate=mktime(0,0,0,$na[1],$na[2],$na[0]);
                                                                                        
$nb explode("-",$filabook['salida']);
                                                                                        
$highDate=mktime(0,0,0,$nb[1],$nb[2],$nb[0]);
                                                                                        
                                                                                        if (
$now $lowDate && $now $highDate
                                                                                        {
                                                                                        
$booked=1;
                                                                                        break;
                                                                                        }
                                                                                }
                                                                            }
                                                            if (
$booked == 1)
                                                                    {
                                                                    
$output.="<div class='daybooked'>";
                                                                    
$output.="$cur</div></td>";
                                                                    
$cur++; 
                                                                    
$col++; 
                                                                    
$booked=0;
                                                                    }
                                                            else
                                                            {
                                                                            while(
$filatemp mysql_fetch_array($fortemp))
                                                                            {
                                                                                        
$na2 explode("-",$filatemp['principio']);
                                                                                        
$lowDatea=mktime(0,0,0,$na2[1],$na2[2],$na2[0]);
                                                                                        
$nb2 explode("-",$filatemp['final']);
                                                                                        
$highDatea=mktime(0,0,0,$nb2[1],$nb2[2],$nb2[0]);
                                                                                        
                                                                                if (
$now $lowDatea && $now $highDatea
                                                                                {
                                                                                
$tempo=$filatemp['temporada'];
                                                                                break;
                                                                                }
                                                                            }
                                                                            switch (
$tempo)
                                                                            {
                                                                            case 
1:
                                                                                    
$output.="<div class='daylow'>";
                                                                                    
$output.="$cur</div></td>";
                                                                                    
$cur++; 
                                                                                    
$col++;
                                                                                     break;
                                                                            case 
2:
                                                                                    
$output.="<div class='dayhigh'>";
                                                                                    
$output.="$cur</div></td>";
                                                                                    
$cur++; 
                                                                                    
$col++;
                                                                                      break;
                                                                            case 
3:
                                                                                    
$output.="<div class='dayspecial'>";
                                                                                    
$output.="$cur</div></td>";
                                                                                    
$cur++; 
                                                                                    
$col++;
                                                                                      break;
                                                                            default:
                                                                                    
$output.="<div class='daylow'>";
                                                                                    
$output.="$cur</div></td>";
                                                                                    
$cur++; 
                                                                                    
$col++;
                                                                                     break;
                                                                            }
                                                            }
                                                } else { 
                                                    
$output.="&nbsp;</td>"
                                                    
$col++; 
                                                }  
                                                    
                                                if(
$col==8) { 
                                                    
$output.="</tr>"
                                                    
$col=1
                                                }
                                            }
                                            
                                            
$output.="</table>";
                                            echo 
$output
    
///////// FIN ZONA CALENDARIO ?>

Última edición por kapitol; 05/04/2009 a las 12:06
  #2 (permalink)  
Antiguo 08/04/2009, 10:11
 
Fecha de Ingreso: abril-2009
Mensajes: 38
Antigüedad: 10 años, 8 meses
Puntos: 1
Respuesta: Coloreando un calendario...

solucionado !!

debía meter la llamda para "sacar" registros de la base de datos en cada una de las vueltas que da el bucle "for"..tb cambíe el menor o mayor que de los ifs que miran las tablas, por mayor o igual menor igual

anda perfecto...pedidme el codigo por M.P. si estais buscando algo parecido para hoteles y alquileres..un saludo gente !
  #3 (permalink)  
Antiguo 17/11/2015, 06:41
Avatar de midpunto  
Fecha de Ingreso: enero-2004
Ubicación: España Palma de mallorca
Mensajes: 118
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Coloreando un calendario...

Hola me interesa bastante el tema, podrías mostrar el código para ver como te ha quedado. Gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:55.