From c6a7beb27785ec788a90d86124960b1b92d79cf4 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 30 Aug 2007 00:17:03 +0200 Subject: [PATCH] Can add/remove/edit addresses Signed-off-by: Florent Bruneau --- modules/profile.php | 23 ++++++ modules/profile/addresses.inc.php | 5 +- templates/geoloc/form.address.tpl | 2 +- templates/include/flags.radio.tpl | 6 +- templates/profile/adresses.address.tpl | 91 +++++++++++++++++++++ templates/profile/adresses.tel.tpl | 39 +++++++++ templates/profile/adresses.tpl | 142 ++++++++++++++++++--------------- 7 files changed, 238 insertions(+), 70 deletions(-) create mode 100644 templates/profile/adresses.address.tpl create mode 100644 templates/profile/adresses.tel.tpl diff --git a/modules/profile.php b/modules/profile.php index b649045..7e6b568 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -32,6 +32,8 @@ class ProfileModule extends PLModule 'profile/private' => $this->make_hook('profile', AUTH_COOKIE), 'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'), 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), + 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_PUBLIC, 'user', NO_AUTH), + 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH), 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), @@ -310,6 +312,8 @@ class ProfileModule extends PLModule // Misc checks // TODO: Block if birth date is missing ? + $page->addJsLink('ajax.js'); + $page->addJsLink('jquery.js'); $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true); require_once dirname(__FILE__) . '/profile/page.inc.php'; $wiz->addPage('ProfileGeneral', 'Général', 'general'); @@ -325,6 +329,25 @@ class ProfileModule extends PLModule $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); } + function handler_ajax_address(&$page, $adid) + { + $page->changeTpl('profile/adresses.address.tpl', NO_SKIN); + $page->assign('i', $adid); + $page->assign('adr', array()); + $page->assign('ajaxadr', true); + } + + function handler_ajax_tel(&$page, $adid, $telid) + { + $page->changeTpl('profile/adresses.tel.tpl', NO_SKIN); + $page->assign('i', $adid); + $page->assign('adid', "addresses_$adid"); + $page->assign('adpref', "addresses[$adid]"); + $page->assign('t', $telid); + $page->assign('tel', array()); + $page->assign('ajaxtel', true); + } + function handler_p_orange(&$page) { $page->changeTpl('profile/orange.tpl'); diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index e2360a8..c94e119 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -59,7 +59,7 @@ class ProfileAddress $address['datemaj'] = time(); } foreach ($address['tel'] as $t=>&$tel) { - if (@$tel['removed']) { + if (@$tel['removed'] || !trim($tel['tel'])) { unset($address['tel'][$t]); } else { $tel['pub'] = $this->pub->value($page, 'pub', $tel['pub'], $success); @@ -100,6 +100,9 @@ class ProfileAddress if (!$init) { $success = $success && $s; } + if (!trim($adr['text'])) { + unset($value[$key]); + } } return $value; } diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl index ab94e5b..9561af5 100644 --- a/templates/geoloc/form.address.tpl +++ b/templates/geoloc/form.address.tpl @@ -30,7 +30,7 @@ {/if} {if $adr.geoloc}