From 39394cbf26da29148e104dac67b1e78f8359a62b Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Wed, 15 Dec 2010 01:06:45 +0100 Subject: [PATCH 1/1] Outputs csv of postal formatted addresses corresponding to an advanced query (#Closes 1365). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- include/userset.inc.php | 38 ++++++++++++++++++++++++++++++++++++++ modules/search.php | 6 ++++++ templates/search/adv.form.tpl | 4 ++++ 3 files changed, 48 insertions(+) diff --git a/include/userset.inc.php b/include/userset.inc.php index d4be83a..48c07b0 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -350,5 +350,43 @@ class GadgetView implements PlView } } +class AddressesView implements PlView +{ + private $set; + + public function __construct(PlSet &$set, array $params) + { + $this->set =& $set; + } + + public function apply(PlPage &$page) + { + $res = $this->set->get(new PlLimit()); + $visibility = new ProfileVisibility(ProfileVisibility::VIS_AX); + pl_content_headers('text/x-csv'); + + $csv = fopen('php://output', 'w'); + fputcsv($csv, array('adresses'), ';'); + foreach ($res as $profile) { + $addresses = $profile->getAddresses(Profile::ADDRESS_POSTAL); + if (!empty($addresses)) { + foreach ($addresses as $address) { + if ($visibility->isVisible($address->pub)) { + fputcsv($csv, array($profile->public_name, $address->postalText), ';'); + break; + } + } + } + } + fclose($csv); + exit(); + } + + public function args() + { + return $this->set->args(); + } +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/modules/search.php b/modules/search.php index 358db58..5548237 100644 --- a/modules/search.php +++ b/modules/search.php @@ -178,11 +178,17 @@ class SearchModule extends PLModule $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true)); // TODO: Reactivate when the new map is completed. // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv')); + if (S::user()->checkPerms(User::PERM_EDIT_DIRECTORY) || S::admin()) { + $view->addMod('addresses', 'Addresses postales', false); + } $view->apply('search/adv', $page, $model); $nb_tot = $view->count(); if ($nb_tot > $globals->search->private_max) { $this->form_prepare(); + if ($model != 'addresses' && (S::user()->checkPerms(User::PERM_EDIT_DIRECTORY) || S::admin())) { + $page->assign('suggestAddresses', true); + } $page->trigError('Recherche trop générale.'); } else if ($nb_tot == 0) { $this->form_prepare(); diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index b99d73d..167f8d4 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -22,6 +22,10 @@

Recherche dans l'annuaire

+{if hasPerm('edit_directory,admin') && t($suggestAddresses)} +

Voulez-vous télécharger le tableau des adresses postales pour la recette précédente ?

+{/if} + {javascript name=jquery.form}