+
+ // on rajoute les numéros de tél
+ $adrid_index = array();
+ foreach ($array['adresse'] as $i => $a) $adrid_index[$a['adrid']] = $i;
+ // on rajoute les numéros de tels
+ $restel = XDB::iterator(
+ "SELECT t.tel, t.tel_type, t.adrid
+ FROM tels AS t
+ INNER JOIN adresses AS a ON (t.adrid = a.adrid AND t.uid = a.uid)
+ WHERE t.uid = {?} AND NOT FIND_IN_SET('pro', a.statut)", $uid);
+ while ($tel = $restel->next()) $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel;
+ foreach ($array['adresse'] as $i => $adr) {
+ unset($lasttel);
+ foreach($adr['tels'] as $j => $t){
+ if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) $array['adresse'][$i]['tel'] = $t['tel'];
+ elseif (!isset($array['adresse'][$i]['fax']) && (strpos($t['tel_type'], 'Fax') === 0)) $array['adresse'][$i]['fax'] = $t['tel'];
+ else $lasttel = $t['tel'];
+ if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) break;
+ }
+ if (!isset($array['adresse'][$i]['tel']) && isset($lasttel))
+ $array['adresse'][$i]['tel'] = $lasttel;
+ elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel))
+ $array['adresse'][$i]['fax'] = $lasttel;
+ unset($array['adresse'][$i]['adrid']);
+ unset($array['adresse'][$i]['tels']);
+ }