From: Stéphane Jacob Date: Wed, 15 Dec 2010 00:06:45 +0000 (+0100) Subject: Outputs csv of postal formatted addresses corresponding to an advanced query (#Closes... X-Git-Tag: xorg/1.0.2~69 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;ds=sidebyside;h=39394cbf26da29148e104dac67b1e78f8359a62b;hp=861d4a73f8979b29e758a42f76feb52cd967c553;p=platal.git Outputs csv of postal formatted addresses corresponding to an advanced query (#Closes 1365). Signed-off-by: Stéphane Jacob --- 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}