Foros del Web » Programando para Internet » PHP »

Problema con date_default_timezone_set

Estas en el tema de Problema con date_default_timezone_set en el foro de PHP en Foros del Web. Hola tengo el siguiente código que he encontrado en internet para hacer un calendario y me funciona perfectamente, el problema es que está en inglés, ...
  #1 (permalink)  
Antiguo 23/04/2009, 02:24
 
Fecha de Ingreso: septiembre-2008
Mensajes: 33
Antigüedad: 15 años, 7 meses
Puntos: 0
Problema con date_default_timezone_set

Hola tengo el siguiente código que he encontrado en internet para hacer un calendario y me funciona perfectamente, el problema es que está en inglés, y si cambio el timezone America/Los_Angeles por Europe/Madrid, tampoco me funciona, mi versión de php es 5.0.5, ¿alguien sabe como puedo solucionarlo?¿puedo utilizar otra función distinta a date_default_timezone_set para mostrarlo en español?.
Saludos y gracias.

Para llamar al calendario utilizo esto:
Código PHP:
require "calendar.php";
print 
calendar("""""testuser"01); 
y este el el archivo calendar.php
Código PHP:
$global "";
$field "";
$input "";
$text "";
$global['dbhost'] = "localhost";
$global['dbname'] = "tarjeta";
$global['dbuser'] = "tarjeto";
$global['dbpass'] = "tarjeta08";
$global['timezone'] = "Europe/Madrid"
$global['envself'] = $_SERVER['PHP_SELF'];
ini_set('error_reporting'E_ALL E_STRICT);
ini_set('display_errors''On');
#ini_set('log_errors', 'On');
#ini_set('error_log', 'errors.log');
if (isset($_GET['ajax'])) {
    
$input['ajax'] = mysql_escape_string($_GET['ajax']);
} else { 
$input['ajax'] = ""; }
if (
$input['ajax']=="1") {
    if (isset(
$global['dbname'])) {
    } else {
        if (
$global['dbname']=="") {
            exit;}
    }
    
$field['ajax_calendar_username'] = mysql_escape_string($_GET['u']);
    
$field['ajax_calendar_date'] = mysql_escape_string($_GET['d']);
    if (
$field['ajax_calendar_date']!="") {
    
$field['ajax_calendar_status'] = mysql_escape_string($_GET['s']);
    if (
$field['ajax_calendar_status']=="1") {
    
$query "INSERT INTO oc_calendar (start_date, end_date, username) VALUES ('$field[ajax_calendar_date] 00:01', '$field[ajax_calendar_date] 23:59', '$field[ajax_calendar_username]');";
        
$response "Event added.";
        } else {
            
$query "DELETE FROM oc_calendar WHERE start_date LIKE '$field[ajax_calendar_date]%' AND username = '$field[ajax_calendar_username]';";
            
$response "Event removed.";
        }
        
database($query);
    }
    print 
"<span class=\"text\">".$response."</span>";
    exit;}
function 
calendar($year ""$month ""$username "0"$small "0"$calendar_owner "0") {
global 
$global;
global 
$field;
global 
$input;
global 
$text;
if (isset(
$global['timezone'])) {
} else {
$global['timezone'] = "";}
if (
$global['timezone']=="") {
$global['timezone'] = "America/Los_Angeles";
}
if (
function_exists('date_default_timezone_set')) {
    
date_default_timezone_set($global['timezone']);}
if (
"$month"=="") {
    
$month date ("n");}
if (
"$year"=="") {
    
$year date ("Y");}
if (isset(
$_GET['m'])) {
    
$month mysql_escape_string($_GET['m']);}
if (isset(
$_GET['y'])) {
    
$year mysql_escape_string($_GET['y']);}
$last_year $year;
$last_month $month;
$last_month--;
if (
"$last_month"=="0") {
$last_year--;
$last_month "12";
}
$next_year $year;
$next_month $month;
$next_month++;
if (
"$next_month"=="13") {
$next_year++;
$next_month "1";
}
$timestamp mktime (000$month1$year);
$time date("H:i:s");
$monthname date("F"$timestamp);
if (
$calendar_owner=="1") {
print<<<END
<script type="text/javascript" src="functions.js"></script>
<script type="text/javascript" src="ajax_queue.js"></script>
<script type="text/javascript">
var calendar_status = new Array();
function calendar_date(id,status,username,default_color) {
    var dateid = document.getElementById(id);
    if (calendar_status[id]) {
    } else {
        calendar_status[id] = status;}
    if (calendar_status[id]=="0") {
        calendar_status[id] = "1";}
 else { calendar_status[id] = "0";}
SimpleAJAXCall('calendar.php?ajax=1&u=' + username + '&d=' + id + '&s=' + calendar_status[id],SimpleAJAXCallback, '', 'response');
    if (calendar_status[id]=="0") {
        dateid.style.background = "#" + default_color;
    } else {
        dateid.style.background = "#0067C9";
    }}
</script>
END;}
if ("$small"=="1") {
    $width = "18";
    $small = "_small";
} else {
    $width = "22";
    $small = "";
}
#<table cellpadding=1 cellspacing=0 border=0 class="rounded">
#<tr>
#    <td bgcolor="#000080">
#<table cellpadding=5 cellspacing=0 border=0 class="rounded">
#<tr>
#    <td bgcolor="#e7e7e7">
$output = <<<END
    <table border="0" cellpadding="3" cellspacing="2" class="rounded5">
        <tr>
        <td width=$width>
END;
if (
$small=="") {
$output .= <<<END
        <span class="calendar_navigation$small"><a href="$global[envself]?u=$username&y=$last_year&m=$last_month" class="calendar_navigation$small"><b>&lt;&lt;</b></a></span>
END;
}
$output .= <<<END
        </td>
        <td colspan="5" align="center">
    <span class="calendar_date$small"><b>$monthname $year</span>
        </td>
        <td width=$width align=right>
END;
if (
$small=="") {
$output .= <<<END
        <span class="calendar_navigation$small"><a href="$global[envself]?u=$username&y=$next_year&m=$next_month" class="calendar_navigation$small"><b>&gt;&gt;</b></a></span>
END;}
$output .= <<<END
        </td></tr>
        <tr>
        <td width=$width align=center bgcolor="#d7d7d7">
    <span class="calendar_day$small"><b>Su</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
    <span class="calendar_day$small"><b>M</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
        <span ="calendar_day$small"><b>Tu</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
        <span class="calendar_day$small"><b>W</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
        <span class="calendar_day$small"><b>Th</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
        <span class="calendar_day$small"><b>F</b></span></td>
        <td width=$width align=center bgcolor="#d7d7d7">
        <span class="calendar_day$small"><b>Sa</b></span></td>
        </tr></table>
    <table border="0" cellpadding="3" cellspacing="2" class="rounded5">
END;
            
$monthstart date("w"$timestamp);
            
//if ($monthstart == 0){
                //$monthstart = 7;
            //}
            
$lastday date("d"mktime (000$month 10$year));
            
$startdate = -$monthstart;

            
//Figure out how many rows we need.
            
$numrows ceil (((date("t",mktime (000$month 10$year)) + $monthstart) / 7));

            
//Let's make an appropriate number of rows...
            
for ($k 1$k <= $numrows$k++){
                
$output .= "<tr>";
                
//Use 7 columns (for 7 days)...
                
for ($i 0$i 7$i++){
                    
$startdate++;
                    if ((
$startdate <= 0) || ($startdate $lastday)){
                        
//If we have a blank day in the calendar.
                        
$output .= "<td><span class=\"calendar_date_number$small\">&nbsp;</span></td>";
                    } else {
if (
strlen($month) == "1") {
                            
$fmonth "0".$month;
                        } else {
                            
$fmonth $month;
                        }
                        if (
strlen($startdate) == "1") {
                            
$fstartdate "0".$startdate;
                        } else {
                            
$fstartdate $startdate;
                        }


                        
$lookup_date "$year"."-"."$fmonth"."-"."$fstartdate";
                        
$date_status "";

                        if ((
$username!="") && ($global['dbuser']!="")) {
$date_status date_status($lookup_date$username);
                        }

                        
$status_color "0067C9";
                        
$js_status "1";

                        if (
$startdate == date("j") && $month == date("n") && $year == date("Y")){
    if (
$date_status!="1") {
    
$status_color "CAD7F9";
    
$js_status "0";
                            }
$output .= "<td id=\"$year"."-"."$fmonth"."-"."$fstartdate\" width=$width valign=top align=center onclick=\"calendar_date('$year"."-"."$fmonth"."-"."$fstartdate','$js_status','$username','CAD7F9');\" bgcolor=\"#$status_color\">
<table width=\"100%\" cellpadding=2 cellspacing=0 border=0><tr><td align=center>
<span class=\"calendar_date_number$small\">$startdate</span>
</td></tr></table></td>"
;
} else {
    if (
$date_status!="1") {
    
$status_color "e7e7e7";
    
$js_status "0";
            }
$output .= "<td id=\"$year"."-"."$fmonth"."-"."$fstartdate\" width=$width valign=top align=center onclick=\"calendar_date('$year"."-"."$fmonth"."-"."$fstartdate','$js_status','$username','e7e7e7');\" bgcolor=\"#$status_color\">
<table width=\"100%\" cellpadding=2 cellspacing=0 border=0><tr><td align=center>
<span class=\"calendar_date_number$small\">$startdate</span>
</td></tr></table></td>"
;
                        }
                    }
                }
                
$output .= "</tr>";
            }
    
$output .= "</table>"# </td></tr></table></td></tr></table>
    
if ("$calendar_owner"=="1") {
    
$output "<div id=\"response\"></div>".$output;
    }
return 
$output;
}
function 
database($querydb) {
global 
$global;
global 
$field;
if (isset(
$global['queries'])) {
    
$global['queries']++;
} else {
    
$global['queries'] = "1";
}
$field['queries'] = $global['queries'];
if (isset(
$global['query_log'])) {
    
$global['query_log'] .= "\n<br>$querydb";
} else {
    
$global['query_log'] = "$querydb";
}
mysql_connect($global['dbhost'], $global['dbuser'], $global['dbpass']) or return_error("Unable to connect to host $global[dbhost]");
mysql_select_db($global['dbname']) or return_error("Unable to select database $global[dbname]");
$global['dbresult'] = mysql_query($querydb) or return_error("Query Error: $querydb");
if ((
substr($querydb,0,6)!="INSERT") && (substr($querydb,0,6)!="UPDATE") && (substr($querydb,0,6)!="DELETE")) {
    
$global['dbnumber'] = mysql_numrows($global['dbresult']);
}
return;
}
function 
return_error($error) {
print 
$error;
exit;
}
function 
date_status($date$username) {
global 
$global;
global 
$field;
global 
$input;
global 
$text;
$status "0";
if (
$username!="") {
    
$query "SELECT id, start_date, end_date FROM oc_calendar WHERE username = '$username' AND (date_format(start_date,'%Y-%m-%d') <= date_format('$date','%Y-%m-%d') AND date_format(end_date,'%Y-%m-%d') >= date_format('$date','%Y-%m-%d'))";
    
database($query);
    for (
$i 0$i $global['dbnumber']; $i++) {
        
$status "1";
        
$event_id mysql_result($global['dbresult'],$i,"id");
        
$event_start_date mysql_result($global['dbresult'],$i,"start_date");
        
$event_end_date mysql_result($global['dbresult'],$i,"end_date");
}}
return 
$status;} 
  #2 (permalink)  
Antiguo 23/04/2009, 09:21
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Problema con date_default_timezone_set

date_default_timezone_set solo te sirve para establecer el timezone, no para el idioma, si quieres cambiar el idioma tienes que usar setlocale().

Saludos.
  #3 (permalink)  
Antiguo 24/04/2009, 05:28
 
Fecha de Ingreso: septiembre-2008
Mensajes: 33
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Problema con date_default_timezone_set

Gracias, pero al ponerlo sólo me sale el mes actual, ¿dónde se supone que deberia ponerlo para que al cambiar de mes también me cambiara la fecha?

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 03:06.