Can generate multi-user vcards:
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 22 Oct 2006 14:57:23 +0000 (14:57 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 22 Oct 2006 14:57:23 +0000 (14:57 +0000)
- add a vcard with all 'my contacts'
- add a vcard with all the members of a group

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1003 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
modules/carnet.php
modules/profile.php
modules/xnetgrp.php
templates/carnet/mescontacts.tpl
templates/vcard.tpl
templates/xnet/groupe/annuaire.tpl

index 9582d12..9186518 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,12 @@ New:
     * Admin:
         - Can add sorting key in Table Editor.                             -FRU
 
+    * Carnet:
+        - Add a vcard of all the contacts                                  -FRU
+
+    * Xnet:
+        - Add a vcard of all the members of a group                        -FRU
+
 Bug/Wish:
 
     * Admin:
index 6d05b68..88c1d84 100644 (file)
@@ -24,15 +24,16 @@ class CarnetModule extends PLModule
     function handlers()
     {
         return array(
-            'carnet'              => $this->make_hook('index',    AUTH_COOKIE),
-            'carnet/panel'        => $this->make_hook('panel',    AUTH_COOKIE),
-            'carnet/notifs'       => $this->make_hook('notifs',   AUTH_COOKIE),
+            'carnet'                => $this->make_hook('index',    AUTH_COOKIE),
+            'carnet/panel'          => $this->make_hook('panel',    AUTH_COOKIE),
+            'carnet/notifs'         => $this->make_hook('notifs',   AUTH_COOKIE),
 
-            'carnet/contacts'     => $this->make_hook('contacts', AUTH_COOKIE),
-            'carnet/contacts/pdf' => $this->make_hook('pdf',      AUTH_COOKIE),
+            'carnet/contacts'       => $this->make_hook('contacts', AUTH_COOKIE),
+            'carnet/contacts/pdf'   => $this->make_hook('pdf',      AUTH_COOKIE),
+            'carnet/contacts/ical'  => $this->make_hook('ical',     AUTH_COOKIE),
+            'carnet/contacts/vcard' => $this->make_hook('vcard',    AUTH_COOKIE),
 
-            'carnet/rss'          => $this->make_hook('rss',      AUTH_PUBLIC),
-            'carnet/ical'         => $this->make_hook('ical',     AUTH_PUBLIC),
+            'carnet/rss'            => $this->make_hook('rss',      AUTH_PUBLIC),
         );
     }
 
@@ -372,6 +373,16 @@ class CarnetModule extends PLModule
 
         header('Content-Type: text/calendar; charset=utf-8');
     }
+
+    function handler_vcard(&$page)
+    {
+        $res = XDB::query('SELECT contact
+                             FROM contacts
+                            WHERE uid = {?}', S::v('uid'));
+        require_once('vcard.inc.php');
+        $vcard = new VCard($res->fetchColumn());
+        $vcard->do_page(&$page);
+    }
 }
 
 ?>
index f32a683..d3a5530 100644 (file)
@@ -659,34 +659,6 @@ class ProfileModule extends PLModule
         }
     }
 
-    function vcard_escape($text)
-    {
-        return preg_replace('/[,;]/', '\\\\$0', $text);
-    }
-
-    function format_adr($params, &$smarty)
-    {
-        // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
-        extract($params['adr']);
-        $adr = trim($adr1);
-        $adr = trim("$adr\n$adr2");
-        $adr = trim("$adr\n$adr3");
-        return $this->vcard_text_encode(';;'
-                . $this->vcard_escape($adr) . ';' 
-                . $this->vcard_escape($city) . ';'
-                . $this->vcard_escape($region) . ';'
-                . $this->vcard_escape($postcode) . ';'
-                . $this->vcard_escape($country), false);
-    }
-
-    function vcard_text_encode($text, $escape = true)
-    {
-        if ($escape) {
-            $text = $this->vcard_escape($text);
-        }
-        return str_replace("\n", "\\n", $text); //implode('\n', explode("\n", $text));
-    }
-
     function handler_vcard(&$page, $x = null)
     {
         if (is_null($x)) {
@@ -699,49 +671,9 @@ class ProfileModule extends PLModule
             $x = substr($x, 0, strlen($x) - 4);
         }
 
-        $page->changeTpl('vcard.tpl', NO_SKIN);
-        require_once 'xorg.misc.inc.php';
-        require_once 'user.func.inc.php';
-
-        $page->register_modifier('vcard_enc', array($this, 'vcard_text_encode'));
-        $page->register_function('format_adr', array($this, 'format_adr'));
-
-        $login = get_user_forlife($x);
-        $user  = get_user_details($login);
-        
-        if (strlen(trim($user['freetext']))) {
-            $user['freetext'] = html_entity_decode($user['freetext']);
-        }
-
-        // alias virtual
-        $res = XDB::query(
-                "SELECT alias
-                   FROM virtual
-             INNER JOIN virtual_redirect USING(vid)
-             INNER JOIN auth_user_quick  ON ( user_id = {?} AND emails_alias_pub = 'public' )
-                  WHERE ( redirect={?} OR redirect={?} )
-                        AND alias LIKE '%@{$globals->mail->alias_dom}'",
-                S::v('uid'),
-                $user['forlife'].'@'.$globals->mail->domain,
-                $user['forlife'].'@'.$globals->mail->domain2);
-
-        $user['virtualalias'] = $res->fetchOneCell();
-        
-        // get photo
-        $res = XDB::query(
-                "SELECT attach, attachmime
-                   FROM photo   AS p
-             INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
-                  WHERE a.alias = {?}", $login);
-        if ($res->numRows()) {
-            $user['photo'] = $res->fetchOneAssoc();
-        }
-        $page->assign('users', array($user));
-
-        header("Pragma: ");
-        header("Cache-Control: ");
-        header("Content-type: text/x-vcard; charset=iso-8859-15");
-        header("Content-Transfer-Encoding: 8bit");
+        require_once('vcard.inc.php');
+        $vcard = new VCard($x);
+        $vcard->do_page($page);
     }
 
     function handler_admin_trombino(&$page, $uid = null, $action = null) {
index 522fbcc..0b3dc7d 100644 (file)
@@ -65,14 +65,15 @@ class XnetGrpModule extends PLModule
     function handlers()
     {
         return array(
-            '%grp'            => $this->make_hook('index',     AUTH_PUBLIC),
-            '%grp/asso.php'   => $this->make_hook('index',     AUTH_PUBLIC),
-            '%grp/logo'       => $this->make_hook('logo',      AUTH_PUBLIC),
-            '%grp/edit'       => $this->make_hook('edit',      AUTH_MDP),
-            '%grp/mail'       => $this->make_hook('mail',      AUTH_MDP),
-            '%grp/annuaire'   => $this->make_hook('annuaire',  AUTH_MDP),
-            '%grp/subscribe'  => $this->make_hook('subscribe', AUTH_MDP),
-            '%grp/paiement'   => $this->make_hook('paiement',  AUTH_MDP),
+            '%grp'                => $this->make_hook('index',     AUTH_PUBLIC),
+            '%grp/asso.php'       => $this->make_hook('index',     AUTH_PUBLIC),
+            '%grp/logo'           => $this->make_hook('logo',      AUTH_PUBLIC),
+            '%grp/edit'           => $this->make_hook('edit',      AUTH_MDP),
+            '%grp/mail'           => $this->make_hook('mail',      AUTH_MDP),
+            '%grp/annuaire'       => $this->make_hook('annuaire',  AUTH_MDP),
+            '%grp/annuaire/vcard' => $this->make_hook('vcard',     AUTH_MDP),
+            '%grp/subscribe'      => $this->make_hook('subscribe', AUTH_MDP),
+            '%grp/paiement'       => $this->make_hook('paiement',  AUTH_MDP),
 
             '%grp/admin/annuaire'
                  => $this->make_hook('admin_annuaire', AUTH_MDP),
@@ -326,6 +327,22 @@ class XnetGrpModule extends PLModule
         $page->assign('ann', $ann);
     }
 
+    function handler_vcard(&$page)
+    {
+        global $globals;
+
+        if (($globals->asso('pub') == 'public' && is_member()) || may_update()) {
+            $res = XDB::query('SELECT uid
+                                 FROM groupex.membres
+                                WHERE asso_id = {?}', $globals->asso('id'));
+            require_once('vcard.inc.php');
+            $vcard = new VCard($res->fetchColumn(), 'Membre du groupe ' . $globals->asso('nom'));
+            $vcard->do_page($page);
+        } else {
+            return PL_NOTALLOWED;
+        }
+    }
+
     function handler_subscribe(&$page, $u = null)
     {
         global $globals;
index e8bdbfe..d72736c 100644 (file)
@@ -54,18 +54,24 @@ Pour r
   [<a href="carnet/contacts/pdf/mescontacts.pdf" class='popup'><strong>tri par noms</strong></a>]
   </li>
 </ul>
-<table style="width: 100%">
-  <tr>
-    <td>
-      Tu peux récupérer un calendrier iCal avec l'anniversaire de tes contacts.
-    </td>
-    <td class="right">
-      <a href="carnet/ical/anniv-x.ics">
-        {icon name=calendar_view_day title='Anniversaires'}
-      </a>
-    </td>
-  </tr>
-</table>
+
+<p>
+  Tu peux télécharger une de tes contacts :
+</p>
+<ul>
+  <li>
+    {icon name=calendar_view_day title='Anniversaires'} 
+    <a href="carnet/contacts/ical/anniv-x.ics">
+      Le calendrier des anniversaires
+    </a>
+  </li>
+  <li>
+    {icon name=vcard title='Carte de visite'} 
+    <a href="carnet/contacts/vcard/MesContactsXorg.vcf">
+      La carte de visite permettant de les insérer dans ton carnet d'adresse
+    </a>
+  </li>
+</ul>
 
 {if $trombi}
 
index 01935f4..dd9ad0e 100644 (file)
@@ -80,6 +80,6 @@ PHOTO;ENCODING=b;TYPE={$vcard.photo.attachmime}:{$vcard.photo.attach|base64_enco
 {/if}
 SORT-STRING:{$vcard.nom|vcard_enc}
 REV:{$vcard.date|date_format:"%Y%m%dT000000Z"}
-END:VCARD
+END:VCARD{"\n"}
 {/foreach}
 {* vim:set et sw=2 sts=2 sws=2: *}
index 95e5d5a..83279bd 100644 (file)
@@ -30,15 +30,31 @@ Le groupe {$asso.nom} compte {$nb_tot} membres.
 Les membres extérieurs du groupe sont intégrés à cette liste, et repérés par l'inscription 'extérieur' dans la colonne promotion.
 </p>
 
-{if $admin}
 <p class="descr">
-Fonctionnalités visibles uniquement par les administrateurs :
+Tu peux également :
 </p>
 <ul class="descr">
-  <li><a href="{$platal->ns}member/new">Ajouter un membre</a></li>
-  <li><a href="{$platal->ns}admin/annuaire">Synchroniser annuaire et Listes de diffusion</a></li>
+  <li>
+    <a href="{$platal->ns}annuaire/vcard/{$asso.diminutif}.vcf">
+      {icon name=vcard title="Carte de visite"} 
+      Ajouter les membres à ton carnet d'adresse
+    </a>
+  </li>
+  {if $admin}
+  <li>
+    <a href="{$platal->ns}member/new">
+      {icon name=add title="Ajouter un membre"} 
+      Ajouter un membre
+    </a>
+  </li>
+  <li>
+    <a href="{$platal->ns}admin/annuaire">
+      {icon name=wand title="Synchroniser"} 
+      Synchroniser annuaire et Listes de diffusion
+    </a>
+  </li>
+  {/if}
 </ul>
-{/if}
 
 <p class="center">
 [<a href="{$platal->ns}annuaire?order={$smarty.request.order}" {if !$request_group}class="erreur"{/if}>tout</a>]