This topic is locked
[SOLVED]

 Adding an event to a day in the past

1/3/2014 5:44:00 PM
Calendar Template general questions
P
pwalkin author

I am trying to modify the calendar template to accept changes to a day in the past. When using the calendar for people that call out sick, the entry will likely be made after the date has passed.

Has anyone requested this or has this been done?

J
Jane 1/15/2014

Hi,
it's a normal Calendar behaviour. To allow to add events in the past open 'Before record added' event for caldaily view, find this code:



if(($values["Recurrence"]!=1 && strtotime(now())-strtotime($values["DateField"]." ".$values["TimeField"])>=0 || $values["Recurrence"]==1 && strtotime(date("Y-m-d"))-strtotime($values["DateField"])>0) && $values["DayEvent"]!=1 || (strtotime(date("Y-m-d"))-strtotime($values["DateField"]))/60*60*24>0 && $values["DayEvent"]==1 && $values["Recurrence"]!=1)

{

$message="<span style=\"color:red\" class=message>Invalid event date or time</span>";

return false;

}

else if ($values["Recurrence"]==1 && (strtotime($values["EndDate"])-strtotime($values["DateField"]))<0)

{

$message="<span style=\"color:red\" class=message>Invalid event end date or time</span>";

return false;

}


and replace it with this one:

if ($values["Recurrence"]==1 && (strtotime($values["EndDate"])-strtotime($values["DateField"]))<0)

{

$message="<span style=\"color:red\" class=message>Invalid event end date or time</span>";

return false;

}


To show Addlink for all dates on the monthly view find and comment this line in the List page: Before display event:

$xt->assign("row00AddHideM".($i+$wd)."value","style=\"display:none;\"");


To allow edit events in the past open List page: Before display event for monthly view, find this code:

if ($_SESSION["UserID"]=="Guest" || ((strtotime(now())-strtotime(date("Y-m-j",strtotime($datatmp2["DateField"]))." ".$datatmp2["TimeField"]))>=0 && $datatmp2["DayEvent"]!=1 || (strtotime(date("Y-m-d"))-strtotime($datatmp2["DateField"]))>0 && $datatmp2["DayEvent"]==1))

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=viewButton".$datatmp2["id"]." idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}

else

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=editButton".$datatmp2["id"]." recur='".$datatmp2["Recurrence"]."' idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}



and replace it with this one:

if ($_SESSION["UserID"]=="Guest")

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=viewButton".$datatmp2["id"]." idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}

else

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=editButton".$datatmp2["id"]." recur='".$datatmp2["Recurrence"]."' idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}
P
pwalkin author 2/6/2014



Hi,
it's a normal Calendar behaviour. To allow to add events in the past open 'Before record added' event for caldaily view, find this code:



if(($values["Recurrence"]!=1 && strtotime(now())-strtotime($values["DateField"]." ".$values["TimeField"])>=0 || $values["Recurrence"]==1 && strtotime(date("Y-m-d"))-strtotime($values["DateField"])>0) && $values["DayEvent"]!=1 || (strtotime(date("Y-m-d"))-strtotime($values["DateField"]))/60*60*24>0 && $values["DayEvent"]==1 && $values["Recurrence"]!=1)

{

$message="<span style=\"color:red\" class=message>Invalid event date or time</span>";

return false;

}

else if ($values["Recurrence"]==1 && (strtotime($values["EndDate"])-strtotime($values["DateField"]))<0)

{

$message="<span style=\"color:red\" class=message>Invalid event end date or time</span>";

return false;

}


and replace it with this one:

if ($values["Recurrence"]==1 && (strtotime($values["EndDate"])-strtotime($values["DateField"]))<0)

{

$message="<span style=\"color:red\" class=message>Invalid event end date or time</span>";

return false;

}


To show Addlink for all dates on the monthly view find and comment this line in the List page: Before display event:

$xt->assign("row00AddHideM".($i+$wd)."value","style=\"display:none;\"");


To allow edit events in the past open List page: Before display event for monthly view, find this code:

if ($_SESSION["UserID"]=="Guest" || ((strtotime(now())-strtotime(date("Y-m-j",strtotime($datatmp2["DateField"]))." ".$datatmp2["TimeField"]))>=0 && $datatmp2["DayEvent"]!=1 || (strtotime(date("Y-m-d"))-strtotime($datatmp2["DateField"]))>0 && $datatmp2["DayEvent"]==1))

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=viewButton".$datatmp2["id"]." idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}

else

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=editButton".$datatmp2["id"]." recur='".$datatmp2["Recurrence"]."' idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}



and replace it with this one:

if ($_SESSION["UserID"]=="Guest")

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=viewButton".$datatmp2["id"]." idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}

else

{

if($_REQUEST["a"]<>"year")

$strRow.="<a href=\"\" id=editButton".$datatmp2["id"]." recur='".$datatmp2["Recurrence"]."' idrec=".$datatmp2["id"]." days=".date("j",strtotime($datatmp2["DateField"]))." mon=".date("n",strtotime($datatmp2["DateField"]))." yr=".date("Y",strtotime($datatmp2["DateField"])).">"."\r\n";

$strRow.="<b>";

}


P
pwalkin author 2/6/2014

Thank you!

A
Anapolis 2/22/2014

Beautiful information and very timely for a project I am just starting to work on!
Thanks, Jane!