X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fprofil%2Fupdate_adresses.inc.php;h=103a2c2837eda689ab0e2a674baa7d1754ab4d3e;hb=509e6025de4089e96f8511032b55c8745919e8d1;hp=ad1e9d8f5add2c96dc1e95059a57cb36f223bb6e;hpb=08cce2ff528b38bde27cdec6d6bc28d6af4a42d4;p=platal.git diff --git a/include/profil/update_adresses.inc.php b/include/profil/update_adresses.inc.php index ad1e9d8..103a2c2 100644 --- a/include/profil/update_adresses.inc.php +++ b/include/profil/update_adresses.inc.php @@ -19,134 +19,111 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +global $adresses; reset($adresses); function insert_new_tel($adrid, $tel) { - global $globals; - if ($tel['tel'] == "") return; - XDB::execute( - "INSERT INTO tels SET - tel_type = {?}, - tel_pub = {?}, - tel = {?}, - uid = {?}, - adrid = {?}, - telid = {?}", - $tel['tel_type'], - $tel['tel_pub'], - $tel['tel'], - Session::getInt('uid', -1), - $adrid, - $tel['telid']); + if ($tel['tel'] == "") + return; + XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?}, + tel = {?}, uid = {?}, adrid = {?}, telid = {?}", + $tel['tel_type'], $tel['tel_pub'], $tel['tel'], + S::v('uid', -1), $adrid, $tel['telid']); } -foreach($adresses as $adrid => $adr){ +foreach ($adresses as $adrid => $adr) { - if($adr['nouvelle'] != 'new'){ // test si on vient de creer cette adresse dans verif_adresse.inc.php - - //construction des bits - $statut = ""; - if ($adr["secondaire"]) $statut .= 'res-secondaire,'; - if ($adr["courrier"]) $statut .= 'courrier,'; - if ($adr["active"]) $statut .= 'active,'; - if ($adr["temporaire"]) $statut .= 'temporaire,'; - if (! empty($statut)) $statut = substr($statut, 0, -1); + if ($adr['nouvelle'] != 'new') { + // test si on vient de creer cette adresse dans verif_adresse.inc.php - if ($adr["nouvelle"] == 'ajout') { - //nouvelle adresse - XDB::execute("INSERT INTO adresses SET - adr1 = {?}, - adr2 = {?}, - adr3 = {?}, - postcode = {?}, - city = {?}, - cityid = {?}, - country = {?}, - region = {?}, - regiontxt = {?}, - pub = {?}, - datemaj = NOW(), - statut = {?}, - uid = {?}, adrid = {?}", - $adr['adr1'], - $adr['adr2'], - $adr['adr3'], - $adr['postcode'], - $adr['city'], - $adr['cityid'], - $adr['country'], - $adr['region'], - $adr['regiontxt'], - $adr['pub'], - $statut, - Session::getInt('uid', -1), $adrid); - $telsvalues = ""; - foreach ($adr['tels'] as $tel) - insert_new_tel($adrid, $tel); - } - - else{ - //c'est une mise à jour - XDB::execute( - "UPDATE adresses SET - adr1 = {?}, - adr2 = {?}, - adr3 = {?}, - postcode = {?}, - city = {?}, - cityid = {?}, - country = {?}, - region = {?}, - regiontxt = {?}, - pub = {?}, - datemaj = NOW(), - statut = {?} - WHERE uid = {?} AND adrid = {?}", - $adr['adr1'], - $adr['adr2'], - $adr['adr3'], - $adr['postcode'], - $adr['city'], - $adr['cityid'], - $adr['country'], - $adr['region'], - $adr['regiontxt'], - $adr['pub'], - $statut, - Session::getInt('uid', -1), $adrid - ); - foreach ($adr['tels'] as $tel) { - if ($tel['new_tel']) - insert_new_tel($adrid, $tel); - else - if ($tel['tel'] != "") { - XDB::execute( - "UPDATE tels SET - tel_type = {?}, - tel_pub = {?}, - tel = {?} - WHERE - uid = {?} AND - adrid = {?} AND - telid = {?}", - $tel['tel_type'], - $tel['tel_pub'], - $tel['tel'], - Session::getInt('uid', -1), - $adrid, - $tel['telid']); - } else { - XDB::execute( - "DELETE FROM tels WHERE - uid = {?} AND - adrid = {?} AND - telid = {?}", - Session::getInt('uid', -1), - $adrid, - $tel['telid']); - } - } - }// fin nouvelle / ancienne adresse - }//fin if nouvellement crée + //construction des bits + $statut = ""; + if ($adr["secondaire"]) $statut .= 'res-secondaire,'; + if ($adr["courrier"]) $statut .= 'courrier,'; + if ($adr["active"]) $statut .= 'active,'; + if ($adr["temporaire"]) $statut .= 'temporaire,'; + if (! empty($statut)) $statut = substr($statut, 0, -1); + $precise_coords = ""; + if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) { + $precise_coords = ", glat = '".$adr['precise_lat']."'"; + $precise_coords .= ", glng = '".$adr['precise_lon']."'"; + } + + if ($adr["nouvelle"] == 'ajout') { + //nouvelle adresse + XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?}, + adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, + country = {?}, region = {?}, regiontxt = {?}, + pub = {?}, datemaj = NOW(), statut = {?}, uid = {?}, + adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'], + $adr['adr3'], $adr['postcode'], $adr['city'], + $adr['cityid'], $adr['country'], $adr['region'], + $adr['regiontxt'], $adr['pub'], $statut, + S::v('uid', -1), $adrid); + $telsvalues = ""; + foreach ($adr['tels'] as $tel) { + insert_new_tel($adrid, $tel); + } + } else { + //c'est une mise à jour + XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, + adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, + country = {?}, region = {?}, regiontxt = {?}, + pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords." + WHERE uid = {?} AND adrid = {?}", $adr['adr1'], + $adr['adr2'], $adr['adr3'], $adr['postcode'], + $adr['city'], $adr['cityid'], $adr['country'], + $adr['region'], $adr['regiontxt'], $adr['pub'], + $statut, S::v('uid', -1), $adrid); + foreach ($adr['tels'] as $tel) { + if ($tel['new_tel']) { + insert_new_tel($adrid, $tel); + } else { + if ($tel['tel'] != "") { + XDB::execute( + "UPDATE tels SET + tel_type = {?}, + tel_pub = {?}, + tel = {?} + WHERE + uid = {?} AND + adrid = {?} AND + telid = {?}", + $tel['tel_type'], + $tel['tel_pub'], + $tel['tel'], + S::v('uid', -1), + $adrid, + $tel['telid']); + } else { + XDB::execute( + "DELETE FROM tels WHERE + uid = {?} AND + adrid = {?} AND + telid = {?}", + S::v('uid', -1), + $adrid, + $tel['telid']); + } + } + } + }// fin nouvelle / ancienne adresse + }//fin if nouvellement crée }//fin foreach + + +//on vire les adresses vides : +if(isset($adresses)){ // s'il y en a + reset($adresses); + foreach($adresses as $adrid => $adr){ + // on vire les tels vides + foreach ($adr['tels'] as $telid => $tel) { + if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]); + } + if(is_adr_empty($adrid)){ + delete_address($adrid); + } + } +} + ?>