Hola, vengo con la siguiente duda:
quiero cambiar el comportamiento del ei_calendario de la siguiente manera
comportamiento actual:
Los dias que aparecen “cargados” seleccionables son hasta el dia actual, en adelante cuando posicionas el puntero del mouse no te da la posibilidad de seleccionar el dia
comportamiento deseado:
todo lo contrario al comportamiento actual, que los dias seleccionables sean de hoy en adelante
Esta particularidad se aplica muchos casos agendas,solicitudes etc,
saludos
Para hacer lo que estás queriendo vas a tener que extender la clase active calendar.
Para ello tenés que crear un archivo php y escribir, como mínimo el siguiente código:
<?php
require_once(toba_dir() . '/php/3ros/activecalendar/activecalendar.php');
class ext_clase_calendario extends toba_ei_calendario
{
function ini()
{
$this->_calendario = new calendario2();
}
}
class calendario2 extends activecalendar
{
protected $mostrar_semanas = true;
protected $mostrar_mes = true;
protected $solo_pasados = false;
protected $siempre_resalta_dia_actual = false;
function __construct($week=false,$year=false,$month=false,$day=false,$GMTDiff="none")
{
parent::__construct($week,$year,$month,$day,$GMTDiff);
}
/**
* Determina si se mostraran los numeros de semana en la presentacion del calendario
* @param boolean $mostrar
*/
function set_mostrar_semanas($mostrar)
{
$this->mostrar_semanas = $mostrar;
}
/**
* Determina si se muestra el mes actual
* @param boolean $mostrar
*/
function set_mostrar_mes_actual($mostrar)
{
$this->mostrar_mes = $mostrar;
}
/**
* Determina si puede seleccionar fechas a futuro o no
* @param boolean $seleccionar
*/
function set_seleccionar_solo_dias_pasados($seleccionar)
{
$this->solo_pasados = $seleccionar;
}
/**
* Determina si el dia seleccionado se mostrara con un estilo resaltado
* @param boolean $resaltar
*/
function set_resaltar_siempre_dia_actual($resaltar)
{
$this->siempre_resalta_dia_actual = $resaltar;
}
/**
* @ignore
*/
function updateCalendar($mes, $anio)
{
$this->setActMonth($mes);
$this->setActYear($anio);
$this->setSelectedMonth($mes);
$this->setSelectedYear($anio);
$this->has31days = checkdate($this->actmonth,31,$this->actyear);
$this->isSchalt = checkdate(2,29,$this->actyear);
if ($this->isSchalt == 1 && $this->actmonth == 2)
$this->maxdays = 29;
elseif ($this->isSchalt != 1 && $this->actmonth == 2)
$this->maxdays = 28;
elseif ($this->has31days == 1)
$this->maxdays = 31;
else $this->maxdays = 30;
$this->firstday = $this->mkActiveDate("w", $this->mkActiveTime(0,0,1,$this->actmonth,1,$this->actyear));
$this->firstdate = $this->mkActiveTime(0,0,1,$this->actmonth,1,$this->actyear);
}
/**
* @ignore
*/
function setEventContent($day, $content)
{
$eventContent[$day] = $content;
$this->calEventContent[] = $eventContent;
}
/**
* @ignore
*/
function getEventContent($day)
{
return $this->content($day);
}
/**
* @ignore
*/
function mkEventContent($var)
{
$day = $this->mkActiveDate("Y-m-d", $this->mkActiveTime(0,0,1,$this->actmonth,$var,$this->actyear));
$hasContent = $this->content($day);
$out="";
if ($hasContent)
{
foreach($hasContent as $content)
{
$out.="<table class=\"".$this->cssEventContent."\">";
$out.="<tr><td>".$content."</td></tr></table>";
}
}
return $out;
}
/**
* @ignore
*/
function content($var)
{
$hasContent = false;
if ($this->calEventContent)
{
for ($x=0; $x<count($this->calEventContent); $x++)
{
$eventContent = $this->calEventContent[$x];
foreach($eventContent as $eventTime => $eventContent)
{
if ($eventTime == $var)
$hasContent[] = $eventContent;
}
}
}
return $hasContent;
}
/**
* @ignore
*/
function showMonth($objeto_js, $eventos, $editor)
{
$out = $this->mkMonthHead();
$out .= $this->barra_editor($editor);
if ($this->mostrar_mes) {
$out .= $this->mkMonthTitle();
}
$out .= $this->mkDatePicker($objeto_js, $eventos);
$out .= $this->mkWeekDays();
$out .= $this->mkMonthBody($objeto_js, $eventos);
$out .= $this->mkMonthFoot();
return $out;
}
/**
* @ignore
*/
function barra_editor($html)
{
$pickerSpan = 8;
$out = '';
if($html) {
$out.="<tr><td class=\"".$this->cssPicker."\" colspan=\"".$pickerSpan."\">\n";
$out.=$html;
$out.="</td></tr>\n";
}
return $out;
}
/**
* @ignore
*/
function mkDatePicker($objeto_js, $eventos)
{
$pickerSpan = 8;
if ($this->datePicker)
{
$evento_js = toba_js::evento('cambiar_mes', $eventos["cambiar_mes"]);
$js = "{$objeto_js}.set_evento($evento_js);";
$out="<tr><td class=\"".$this->cssPicker."\" colspan=\"".$pickerSpan."\">\n";
$out.="<select name=\"".$this->monthID."\" id=\"".$this->monthID."\" class=\"".$this->cssPickerMonth."\" onchange=\"$js\">\n";
for ($z=1;$z<=12;$z++)
{
if ($z <= 9)
$z = "0$z";
if ($z==$this->actmonth)
$out.="<option value=\"".$z."\" selected=\"selected\" >".$this->getMonthName($z)."</option>\n";
else
$out.="<option value=\"".$z."\">".$this->getMonthName($z)."</option>\n";
}
$out.="</select>\n";
$out.="<select name=\"".$this->yearID."\" id=\"".$this->yearID."\" class=\"".$this->cssPickerYear."\" onchange=\"$js\">\n";
for ($z=$this->startYear;$z<=$this->endYear;$z++)
{
if ($z==$this->actyear)
$out.="<option value=\"".$z."\" selected=\"selected\">".$z."</option>\n";
else
$out.="<option value=\"".$z."\">".$z."</option>\n";
}
$out.="</select>\n";
# -- anulo el botoncito que dice "Ir" que sale al lado de mes y año seleccionados
# $out.="<input type=\"submit\" value=\"".$this->selBtn."\" class=\"".$this->cssPickerButton."\" style='cursor: pointer;;cursor:hand;' onclick=\"$js\"></input>\n";
$out.="</td></tr>\n";
}
return $out;
}
/**
* @ignore
*/
function mkMonthBody($objeto_js, $eventos)
{
$out="<tr>";
$monthday=0;
if ($this->mostrar_semanas) {
$out.=$this->mkWeek($this->firstdate, $objeto_js, $eventos);
}
for ($x=0; $x<=6; $x++)
{
if ($x>=$this->firstday)
{
$monthday++;
$out.=$this->mkDay($monthday, $objeto_js, $eventos);
}
else
$out .= "<td class=\"".$this->cssNoMonthDay."\"></td>";
}
$out.="</tr>\n";
$goon = $monthday + 1;
$stop=0;
for ($x=0; $x<=6; $x++)
{
if ($goon>$this->maxdays)
break;
if ($stop==1)
break;
$out.="<tr>";
$date = $this->mkActiveTime(0,0,1,$this->actmonth,$goon,$this->actyear);
if ($this->mostrar_semanas) {
$out.=$this->mkWeek($date, $objeto_js, $eventos);
}
for ($i=$goon; $i<=$goon+6; $i++)
{
if ($i>$this->maxdays)
{
$out.="<td class=\"".$this->cssNoMonthDay."\"></td>";
$stop=1;
}
else
$out.=$this->mkDay($i, $objeto_js, $eventos);
}
$goon=$goon+7;
$out.="</tr>\n";
}
return $out;
}
/**
* @ignore
*/
function mkWeekDays()
{
$out = '';
if ($this->startOnSun)
{
if ($this->mostrar_semanas) {
$out .="<tr class=\"".$this->cssWeekDay."\"><td bgcolor='#C58AFF'>"."Sem"."</td>";
}
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(0)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(1)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(2)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(3)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(4)."</td>";
$out.="<td bgcolor='#FFFF55'>".$this->getDayName(5)."</td>";
$out.="<td bgcolor='#FFFF55'>".$this->getDayName(6)."</td></tr>\n";
}
else
{
if ($this->mostrar_semanas) {
$out .="<tr class=\"".$this->cssWeekDay."\"><td bgcolor='#C58AFF'>"."Sem"."</td>";
}
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(1)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(2)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(3)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(4)."</td>";
$out.="<td bgcolor='#B3FFB3'>".$this->getDayName(5)."</td>";
$out.="<td bgcolor='#FFFF55'>".$this->getDayName(6)."</td>";
$out.="<td bgcolor='#FFFF55'>".$this->getDayName(0)."</td></tr>\n";
$this->firstday=$this->firstday-1;
if ($this->firstday<0)
$this->firstday=6;
}
return $out;
}
/**
* @ignore
*/
function viernes($semana, $anio)
{
$ts_semana = strtotime('+' . $semana . ' weeks', strtotime($anio . '0101'));
$ajuste = 5 - date('w', $ts_semana);
$ts_viernes = strtotime($ajuste . ' days', $ts_semana);
if (date('W', $ts_viernes) == $semana)
return $ts_viernes;
else //se pasó a la semana siguiente
return strtotime('-7 days', $ts_viernes);
}
/**
* @ignore
*/
function compare_week($week, $year)
{
$viernes = $this->viernes($week, $year);
return $this->compare_date($viernes);
}
/**
* @ignore
*/
function mkWeek($date, $objeto_js, $eventos)
{
$week = $this->weekNumber($date);
$year = $this->mkActiveDate("Y",$date);
if (!$this->weekLinks) {
if ($week == $this->getSelectedWeek() && $year == $this->getSelectedYear())
$out = "<td class=\"".$this->cssSelecDay."\">".$this->weekNumber($date)."</td>\n";
else
$out = "<td class=\"".$this->cssWeek."\">".$this->weekNumber($date)."</td>\n";
} else {
if ($this->compare_week($this->weekNumber($date),$this->actyear) == 1)
$out = "<td class=\"".$this->cssWeekNoSelec."\">".$this->weekNumber($date)."</td>\n";
else {
$evento_js = toba_js::evento('seleccionar_semana', $eventos["seleccionar_semana"], "{$this->weekNumber($date)}||{$this->mkActiveDate('Y',$date)}");
$js = "{$objeto_js}.set_evento($evento_js);";
if ($week == $this->getSelectedWeek() && $year == $this->getSelectedYear())
$out = "<td class=\"".$this->cssSelecDay."\" style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$this->weekNumber($date)."</td>\n";
else
$out = "<td class=\"".$this->cssWeek."\" style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$this->weekNumber($date)."</td>\n";
}
}
return $out;
}
/**
* @ignore
*/
function compare_date($day)
{
$fecha_hoy = $this->mkActiveTime(0,0,1,$this->monthtoday,$this->daytoday,$this->yeartoday);
if ($day < $fecha_hoy)
return -1;
elseif ($day > $fecha_hoy)
return 1;
else
return 0;
}
/**
* @ignore
*/
function mkDay($var, $objeto_js, $eventos)
{
if ($var <= 9)
$day = "0$var";
else
$day = $var;
$eventContent = $this->mkEventContent($var);
$content = ($this->showEvents) ? $eventContent : "";
$evento_js = toba_js::evento('seleccionar_dia', $eventos["seleccionar_dia"], "{$day}||{$this->actmonth}||{$this->actyear}");
$js = "{$objeto_js}.set_evento($evento_js);";
$day = $this->mkActiveTime(0,0,1,$this->actmonth,$var,$this->actyear);
$resalta_hoy = ($this->siempre_resalta_dia_actual || $this->getSelectedDay() < 0);
if ($this->solo_pasados && $this->compare_date($day) == 1) {
//Es una fecha futura y no se permite clickearla
$out="<td class=\"".$this->cssSunday."\">".$var.$content."</td>";
} elseif (($this->dayLinks) && ((!$this->enableSatSelection && ($this->getWeekday($var) == 0)) || ((!$this->enableSunSelection && $this->getWeekday($var) == 6)))) {
$out="<td bgcolor='#FFFF55' class=\"".$this->cssSunday."\">".$var."</td>";
} elseif ($var==$this->getSelectedDay() && $this->actmonth==$this->getSelectedMonth() && $this->actyear==$this->getSelectedYear()) {
if (!$this->dayLinks)
$out="<td class=\"".$this->cssSelecDay."\">".$var.$content."</td>";
else
$out="<td class=\"".$this->cssSelecDay."\"style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$var.$content."</td>";
} elseif ($var==$this->daytoday && $this->actmonth==$this->monthtoday && $this->actyear==$this->yeartoday && $resalta_hoy && $this->getSelectedMonth()==$this->monthtoday && $this->getSelectedWeek()<0) {
if (!$this->dayLinks)
$out="<td class=\"".$this->cssToday."\">".$var.$content."</td>";
else
$out="<td class=\"".$this->cssToday."\"style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$var.$content."</td>";
} elseif ($this->getWeekday($var) == 0 && $this->crSunClass){
if (!$this->dayLinks)
$out="<td class=\"".$this->cssSunday."\">".$var.$content."</td>";
else
$out="<td class=\"".$this->cssSunday."\"style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$var.$content."</td>";
} elseif ($this->getWeekday($var) == 6 && $this->crSatClass) {
if (!$this->dayLinks)
$out="<td class=\"".$this->cssSaturday."\">".$var.$content."</td>";
else
$out="<td class=\"".$this->cssSaturday."\"style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$var.$content."</td>";
} else {
if (!$this->dayLinks)
$out="<td class=\"".$this->cssMonthDay."\">".$var.$content."</td>";
else
$out="<td class=\"".$this->cssMonthDay."\"style='cursor: pointer;cursor:hand;' onclick=\"$js\">".$var.$content."</td>";
}
return $out;
}
?>
Espero que funcione
Esta es una extensión que personalicé copiando lo que hicieron los muchachos de Toba y modificando algunas cosas, especialmente para la salida html, de acuerdo a mis necesidades.
Podés estudiar el funcionamiento completo de la clase calendario en el archivo
toba_xxxx\php\nucleo\componentes\interface\toba_ei_calendario.php
Ahí tenés dos clases: toba_ei_calendario y calendario.
Esta última es la que copié y modifiqué.
Saludos.
buenisimo ! era los que buscaba,
saludos !!