migrate vcard.php
[platal.git] / modules / profile.php
index 2d12210..1f22180 100644 (file)
@@ -24,8 +24,12 @@ class ProfileModule extends PLModule
     function handlers()
     {
         return array(
-            'photo'  => $this->make_hook('photo',  AUTH_PUBLIC),
-            'trombi' => $this->make_hook('trombi', AUTH_COOKIE),
+            'photo'        => $this->make_hook('photo',        AUTH_PUBLIC),
+            'photo/change' => $this->make_hook('photo_change', AUTH_MDP),
+
+            'trombi'       => $this->make_hook('trombi',       AUTH_COOKIE),
+
+            'vcard'        => $this->make_hook('vcard',        AUTH_COOKIE),
         );
     }
 
@@ -82,12 +86,62 @@ class ProfileModule extends PLModule
                 echo $data;
             } else {
                 Header('Content-type: image/png');
-                echo file_get_contents(dirname(__FILE__).'../htdocs/images/none.png');
+                echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
             }
         }
         exit;
     }
 
+    function handler_photo_change(&$page)
+    {
+        global $globals;
+
+        $page->changeTpl('trombino.tpl');
+
+        require_once('validations.inc.php');
+
+        $trombi_x = '/home/web/trombino/photos'.Session::get('promo')
+                    .'/'.Session::get('forlife').'.jpg';
+
+        if (Env::has('upload')) {
+            $file = isset($_FILES['userfile']['tmp_name'])
+                    ? $_FILES['userfile']['tmp_name']
+                    : Env::get('photo');
+            if ($data = file_get_contents($file)) {
+                if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) {
+                    $myphoto->submit();
+                }
+            } else {
+                $page->trig('Fichier inexistant ou vide');
+            }
+        } elseif (Env::has('trombi')) {
+            $myphoto = new PhotoReq(Session::getInt('uid'),
+                                    file_get_contents($trombi_x));
+            if ($myphoto) {
+                $myphoto->commit();
+                $myphoto->clean();
+            }
+        } elseif (Env::get('suppr')) {
+            $globals->xdb->execute('DELETE FROM photo WHERE uid = {?}',
+                                   Session::getInt('uid'));
+            $globals->xdb->execute('DELETE FROM requests
+                                     WHERE user_id = {?} AND type="photo"',
+                                   Session::getInt('uid'));
+        } elseif (Env::get('cancel')) {
+            $sql = $globals->xdb->query('DELETE FROM requests 
+                                        WHERE user_id={?} AND type="photo"',
+                                        Session::getInt('uid'));
+        }
+
+        $sql = $globals->xdb->query('SELECT COUNT(*) FROM requests
+                                      WHERE user_id={?} AND type="photo"',
+                                    Session::getInt('uid'));
+        $page->assign('submited', $sql->fetchOneCell());
+        $page->assign('has_trombi_x', file_exists($trombi_x));
+
+        return PL_OK;
+    }
+
     function handler_trombi(&$page, $promo = null)
     {
         require_once 'trombi.inc.php';
@@ -114,6 +168,62 @@ class ProfileModule extends PLModule
 
         return PL_OK;
     }
+
+    function format_adr($params, &$smarty)
+    {
+        // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
+        extract($params['adr']);
+        $adr = $adr1;
+        $adr = trim("$adr\n$adr2");
+        $adr = trim("$adr\n$adr3");
+        return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
+    }
+
+    function handler_vcard(&$page, $x = null)
+    {
+        if (is_null($x)) {
+            return PL_NOT_FOUND;
+        }
+
+        global $globals;
+
+        if (substr($x, -4) == '.vcf') {
+            $x = substr($x, 0, strlen($x) - 4);
+        }
+
+        new_nonhtml_page('vcard.tpl', AUTH_COOKIE);
+        require_once 'xorg.misc.inc.php';
+        require_once 'user.func.inc.php';
+
+        $page->register_modifier('qp_enc', 'quoted_printable_encode');
+        $page->register_function('format_adr', array($this, 'format_adr'));
+
+        $login = get_user_forlife($x);
+        $user  = get_user_details($login);
+
+        // alias virtual
+        $res = $globals->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}'",
+                Session::getInt('uid'),
+                $user['forlife'].'@'.$globals->mail->domain,
+                $user['forlife'].'@'.$globals->mail->domain2);
+
+        $user['virtualalias'] = $res->fetchOneCell();
+
+        $page->assign_by_ref('vcard', $user);
+
+        header("Pragma: ");
+        header("Cache-Control: ");
+        header("Content-type: text/x-vcard\n");
+        header("Content-Transfer-Encoding: Quoted-Printable\n");
+
+        return PL_OK;
+    }
 }
 
 ?>