Outputs csv of postal formatted addresses corresponding to an advanced query (#Closes...
authorStéphane Jacob <sj@m4x.org>
Wed, 15 Dec 2010 00:06:45 +0000 (01:06 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 20 Dec 2010 17:47:24 +0000 (18:47 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/userset.inc.php
modules/search.php
templates/search/adv.form.tpl

index d4be83a..48c07b0 100644 (file)
@@ -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:
 ?>
index 358db58..5548237 100644 (file)
@@ -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();
index b99d73d..167f8d4 100644 (file)
 
 <h1>Recherche dans l'annuaire</h1>
 
+{if hasPerm('edit_directory,admin') && t($suggestAddresses)}
+<p class="center"><strong>Voulez-vous télécharger le <a href="{$globals->baseurl}/search/adv/addresses{$plset_args}">tableau des adresses postales</a> pour la recette précédente&nbsp;?</strong></p>
+{/if}
+
 {javascript name=jquery.form}
 
 <script type="text/javascript">// <!--