From b97693042347eb7be270e991ec3b71620732a2b1 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 30 Sep 2010 09:32:34 +0000 Subject: [PATCH] preventing invalid birthdays stored with the datastore such as 0000-00-00 or 0.0.00 to transform to a birthday --- calendar/inc/class.calendar_bo.inc.php | 16 ++++++++++++++++ phpgwapi/inc/class.contacts.inc.php | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index b9e2c2b4ae..5914b0ac9c 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -1632,6 +1632,22 @@ class calendar_bo usort($bdays,create_function('$a,$b','return (int) $a[\'bday\'] == (int) $b[\'bday\'] ? strcmp($a[\'bday\'],$b[\'bday\']) : (int) $a[\'bday\'] - (int) $b[\'bday\'];')); foreach($bdays as $pers) { + if (isset($pers['bday']) && ($pers['bday']=='0000-00-00 0' || $pers['bday']=='0000-00-00' || $pers['bday']=='0.0.00')) + { + //error_log(__METHOD__.__LINE__.' Entry with invalid birthday:'.array2string($pers)); + $pers['bday']=null; + } + if (isset($pers['contact_bday']) && ($pers['contact_bday']=='0000-00-00 0' || $pers['contact_bday']=='0000-00-00' || $pers['contact_bday']=='0.0.00')) + { + //error_log(__METHOD__.__LINE__.' Entry with invalid birthday:'.array2string($pers)); + $pers['contact_bday']=null; + } + if (empty($pers['bday']) && !empty($pers['contact_bday'])) $pers['bday'] = $pers['contact_bday']; + if (empty($pers['bday'])) + { + //error_log(__METHOD__.__LINE__.' Skipping entry for invalid birthday:'.array2string($pers)); + continue; + } $pers['bday'] = egw_time::to($pers['bday'],"m/d/Y"); list($m,$d,$y) = explode('/',$pers['bday']); if ($y > $year) continue; // not yet born diff --git a/phpgwapi/inc/class.contacts.inc.php b/phpgwapi/inc/class.contacts.inc.php index b456d1f04d..d04f2cce06 100644 --- a/phpgwapi/inc/class.contacts.inc.php +++ b/phpgwapi/inc/class.contacts.inc.php @@ -140,9 +140,22 @@ class contacts extends addressbook_bo if (isset($row['bday']) || isset($row['contact_bday'])) { + $bdayset=true; + if (isset($row['bday']) && ($row['bday']=='0000-00-00 0' || $row['bday']=='0000-00-00' || $row['bday']=='0.0.00')) + { + $rows[$n]['bday'] = $row['bday']=null; + $bdayset=false; + } + if (isset($row['contact_bday']) && ($row['contact_bday']=='0000-00-00 0' || $row['contact_bday']=='0000-00-00' || $row['contact_bday']=='0.0.00')) + { + $rows[$n]['contact_bday'] = $row['contact_bday']=null; + $bdayset=false; + } + if ($bdayset==false) continue; // dont try to make a date out of that $row['bday'] = egw_time::to((isset($row['bday'])?$row['bday']:$row['contact_bday']),"Y-m-d"); list($y,$m,$d) = explode('-',$row['bday']); $rows[$n]['bday'] = sprintf('%d/%d/%04d',$m,$d,$y); + } } }