El problemana pagina calendario y a esta la llamo desde otra pagina donde la uso, si pruebo la pagina calendario la funcio ramdom color funciona ahora si la llamo a esta pagina calendario desde otra pagina mediante un requiere donde esta pagina nueva tiene sus codigos y archivos css no me funciona la funcion no me colorear. Y yo en vez de ponerle la funcion a la variable le doy un color fijo si, o sea claramente no funciona la funcion que cree en esta pagina. Me pordiran ayudan !!! gracias
Les dejo el codigo de la pagina calendario
Código PHP:
<?php require_once('Connections/reservas.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_reservas, $reservas);
$query_Recordset1 = "SELECT * FROM precios where id_hab='4'";
$Recordset1 = mysql_query($query_Recordset1, $reservas) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//funcion color
function random_color(){
mt_srand((double)microtime()*1000000);
$color2 = '';
while(strlen($color2)<6){
$color2 .= sprintf("%02X", mt_rand(0, 255));
}
return $color2;
}
//Variable para llevar la cuenta del dia actual
$dia_actual = 1;
function dame_nombre_mes($j){
switch ($j){
case 1:
$nombre_mes="Enero";
break;
case 2:
$nombre_mes="Febrero";
break;
case 3:
$nombre_mes="Marzo";
break;
case 4:
$nombre_mes="Abril";
break;
case 5:
$nombre_mes="Mayo";
break;
case 6:
$nombre_mes="Junio";
break;
case 7:
$nombre_mes="Julio";
break;
case 8:
$nombre_mes="Agosto";
break;
case 9:
$nombre_mes="Septiembre";
break;
case 10:
$nombre_mes="Octubre";
break;
case 11:
$nombre_mes="Noviembre";
break;
case 12:
$nombre_mes="Diciembre";
break;
}
return $nombre_mes;
}
//array y funcion
$rangos = array();
while ($row = mysql_fetch_array($Recordset1, MYSQL_NUM))
{
//Se van agregando a $rangos los rangos existentes en la BD
array_push($rangos,$row);
}
function rangos($rangos,$fecha)
{
foreach ($rangos as $row)
{
$fecha1=strtotime($row[3]);
$fecha2=strtotime($row[4]);
$precio1= $row[2];
if (($fecha >= $fecha1) && ($fecha <= $fecha2)) {
return true; }
}
return false;
}
function rangos2($rangos,$fecha,$precio1)
{
foreach ($rangos as $row)
{
$fecha1=strtotime($row[3]);
$fecha2=strtotime($row[4]);
$precio1= $row[2];
if (($fecha >= $fecha1) && ($fecha <= $fecha2)) {
return $precio1; }
}
return false;
}
$ano=date("Y");
//escribo la primera fila de la semana
echo "<table>";
echo "<tr>";
echo "<td>AÑO $ano</td>";echo "</tr>";
echo "<tr>";
echo "<td></td>";
for ($i=0;$i<31;$i++){
$color= "style=color:blue";
echo "<td align=center >".($dia_actual<10?"0$dia_actual":$dia_actual)."</td>";
$dia_actual++;
}
echo "</tr>";
function random_color(){
mt_srand((double)microtime()*1000000);
$color2 = '';
while(strlen($color2)<6){
$color2 .= sprintf("%02X", mt_rand(0, 255));
}
return $color2;
}
$mes=0;
for ($j=1 ;$j<=12;$j++){
$mes=$mes+1;
echo "<tr id=$j>";
echo "<td >"; echo dame_nombre_mes($j) ; echo "</td>";
for ($i=0;$i<31;$i++){
$fecha=strtotime("$ano-$j-$i");
if(rangos($rangos, $fecha)==true) {
$precio_ant = $precioo;
$precioo=rangos2($rangos,$fecha,$precio1);
$color_nuevo = random_color();
if ($precio_ant != $precioo or $precio_ant == NULL){
$color_precio = $color_nuevo;
$color_viejo = $color_nuevo;}else {$color_precio = $color_viejo;}
$color="style=color:white;background-color:$color_precio ";
}else {
$color="style=color:black";
}
echo "<td align=center width=25px $color id=$i>"; echo $precioo; echo" </td>"; }
$precio_ant = $precioo;
echo "</tr>";
}
//tabla año 2
$mes22="9";
if ( $mes22 > 8) {
$ano2=$ano+1;
echo "</table>";
echo "<table>";
echo "<tr>";
echo "<td></td>";
$dia_actual2=1;
for ($e=0;$e<31;$e++){
$color= "style=color:blue";
echo "<td align=center >".($dia_actual2<10?"0$dia_actual2":$dia_actual2)."</td>";
$dia_actual2++;
}
echo "</tr>";
$mes=0;
for ($g=1 ;$g<=12;$g++){
$mes=$mes+1;
$j=$g;
echo "<tr id=$g>";
echo "<td >"; echo dame_nombre_mes($g) ; echo "</td>";
for ($d=1;$d<=31;$d++){
$fecha=strtotime("$ano2-$g-$d");
if(rangos($rangos, $fecha)==true) {
$color_viejo1 = $color_viejo;
$precio_ant1 = $precioo1;
$precioo1=rangos2($rangos,$fecha,$precio1);
$color_nuevo1 = random_color();
if ($precio_ant1 != $precioo1 or $precioo != $precioo1 or $precio_ant1 == NULL ){
$color_precio1 = $color_nuevo1;
$color_viejo1 = $color_nuevo1;} else {$color_precio1 = $color_viejo1;}
$color1="style=color:black;background-color:$color_precio1 ";
}else {
$color1="style=color:blue";
$precioo1="";
}
echo "<td align=center width=25px $color1 id=$i>"; echo $precioo1; echo" </td>"; }
$precio_ant1 = $precioo1;
echo "</tr>";
}
$j=0;
echo "</table>";}
mysql_free_result($Recordset1);
?>