Hi I do not understand why this function, which calculates the holidays with calc plugin only works in the insertion of the form "Calculation Ajax active" and when sending to record in the database crashes, returning blank page and not posting anything in the record. Could you help me please?
Thanks a lot.
$dal = ('{richiesta___dal}');
$al = ('{richiesta___al}');
$giorni_lavorativi = lavorativi($dal,$al,'giorni');
return "I giorni lavorativi sono: $giorni_lavorativi";
function lavorativi($dal,$al)
{
// Calcolo del giorno di Pasqua fino all'ultimo anno valido
for ($i=2015; $i<=2037; $i++) {
$pasqua = date("Y-m-d", easter_date($i));
$array_pasqua[] = $pasqua;
}
// Calcolo le rispettive pasquette
foreach($array_pasqua as $pasqua){
list ($anno,$mese,$giorno) = explode("-",$pasqua);
$pasquetta = mktime (0,0,0,date($mese),date($giorno)+1,date($anno));
$array_pasquetta[] = $pasquetta;
}
// questi giorni son sempre festivi a prescindere dall'anno
$giorniFestivi =
array(
"01-01",
"04-06",
"01-06",
"04-25",
"05-01",
"06-02",
"08-15",
"10-04",
"11-01",
"12-08",
"12-25",
"12-26",
);
$lavorativi = 0;
for($i = strtotime($dal); $i<=strtotime($al); $i = strtotime("+1 day",$i))
{
$giorno_data = date("w",$i); //verifico il giorno: da 0 (dom) a 6 (sab)
$mese_giorno = date('m-d',$i); // confronto con gg sempre festivi
// Infine verifico che il giorno non sia sabato,domenica,festivo fisso o festivo variabile (pasquetta);
if ($giorno_data !=0 && $giorno_data != 6 && !in_array($mese_giorno,$giorniFestivi) && !in_array($i,$array_pasquetta) )
{
$lavorativi++;
}
}
return $lavorativi;
}
Thanks a lot.
$dal = ('{richiesta___dal}');
$al = ('{richiesta___al}');
$giorni_lavorativi = lavorativi($dal,$al,'giorni');
return "I giorni lavorativi sono: $giorni_lavorativi";
function lavorativi($dal,$al)
{
// Calcolo del giorno di Pasqua fino all'ultimo anno valido
for ($i=2015; $i<=2037; $i++) {
$pasqua = date("Y-m-d", easter_date($i));
$array_pasqua[] = $pasqua;
}
// Calcolo le rispettive pasquette
foreach($array_pasqua as $pasqua){
list ($anno,$mese,$giorno) = explode("-",$pasqua);
$pasquetta = mktime (0,0,0,date($mese),date($giorno)+1,date($anno));
$array_pasquetta[] = $pasquetta;
}
// questi giorni son sempre festivi a prescindere dall'anno
$giorniFestivi =
array(
"01-01",
"04-06",
"01-06",
"04-25",
"05-01",
"06-02",
"08-15",
"10-04",
"11-01",
"12-08",
"12-25",
"12-26",
);
$lavorativi = 0;
for($i = strtotime($dal); $i<=strtotime($al); $i = strtotime("+1 day",$i))
{
$giorno_data = date("w",$i); //verifico il giorno: da 0 (dom) a 6 (sab)
$mese_giorno = date('m-d',$i); // confronto con gg sempre festivi
// Infine verifico che il giorno non sia sabato,domenica,festivo fisso o festivo variabile (pasquetta);
if ($giorno_data !=0 && $giorno_data != 6 && !in_array($mese_giorno,$giorniFestivi) && !in_array($i,$array_pasquetta) )
{
$lavorativi++;
}
}
return $lavorativi;
}