2006 => 2007 Happy New Year\!
[platal.git] / modules / xnet.php
index 165ccf1..3690e88 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -25,67 +25,62 @@ class XnetModule extends PLModule
     {
         return array(
             'index'     => $this->make_hook('index',     AUTH_PUBLIC),
+            'login'     => $this->make_hook('login',     AUTH_MDP),
             'exit'      => $this->make_hook('exit',      AUTH_PUBLIC),
 
-            'about'     => $this->make_hook('about',     AUTH_PUBLIC),
-            'article12' => $this->make_hook('article12', AUTH_PUBLIC),
-            'article16' => $this->make_hook('article16', AUTH_PUBLIC),
-            'creategpx' => $this->make_hook('creategpx', AUTH_PUBLIC),
-            'services'  => $this->make_hook('services',  AUTH_PUBLIC),
-
             'admin'     => $this->make_hook('admin',     AUTH_MDP, 'admin'),
             'groups'    => $this->make_hook('groups',    AUTH_PUBLIC),
             'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC),
             'plan'      => $this->make_hook('plan',      AUTH_PUBLIC),
+            'photo'     => $this->make_hook('photo',     AUTH_MDP),
         );
     }
 
-    function handler_index(&$page)
-    {
-        $page->changeTpl('xnet/index.tpl');
-    }
-
-    function handler_exit(&$page)
-    {
-        XnetSession::destroy();
-        $page->changeTpl('xnet/deconnexion.tpl');
-        $page->useMenu();
-    }
-
-    function handler_about(&$page)
+    function handler_photo(&$page, $x = null)
     {
-        $page->changeTpl('xnet/apropos.tpl');
-        $page->useMenu();
-    }
+        if (is_null($x)) {
+            return PL_NOT_FOUND;
+        }
 
-    function handler_article12(&$page)
-    {
-        $page->changeTpl('xnet/article12.tpl');
-        $page->useMenu();
+        $res = XDB::query("SELECT attachmime, attach
+                             FROM aliases
+                       INNER JOIN photo ON(id = uid)
+                            WHERE alias = {?}", $x);
+
+        if ((list($type, $data) = $res->fetchOneRow())) {
+            Header("Content-type: image/$type");
+            echo $data;
+        } else {
+            Header('Content-type: image/png');
+            echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
+        }
+        exit;
     }
-
-    function handler_article16(&$page)
+    
+    function handler_index(&$page)
     {
-        $page->changeTpl('xnet/article16.tpl');
-        $page->useMenu();
+        $page->nomenu = true;
+        $page->changeTpl('xnet/index.tpl');
     }
 
-    function handler_creategpx(&$page)
+    function handler_login(&$page)
     {
-        $page->changeTpl('xnet/creation-groupex.tpl');
-        $page->useMenu();
+        $allkeys = func_get_args();
+        unset($allkeys[0]);
+        $url = join('/',$allkeys);
+        pl_redirect($url);
     }
 
-    function handler_services(&$page)
+    function handler_exit(&$page)
     {
-        $page->changeTpl('xnet/services.tpl');
-        $page->useMenu();
+        XnetSession::killSuid();
+        XnetSession::destroy();
+        $page->changeTpl('xnet/deconnexion.tpl');
     }
 
     function handler_admin(&$page)
     {
         new_admin_page('xnet/admin.tpl');
-        $page->useMenu();
 
         if (Get::has('del')) {
             $res = XDB::query('SELECT id, nom, mail_domain
@@ -104,11 +99,10 @@ class XnetModule extends PLModule
                                                 WHERE  alias LIKE {?}', '%@'.$domain);
                     $page->trig('suppression des alias mails');
 
-                    require_once('lists.inc.php');
-                    $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
-                    if ($listes = $client->get_lists()) {
+                    $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
+                    if ($listes = $mmlist->get_lists()) {
                         foreach ($listes as $l) {
-                            $client->delete_list($l['list'], true);
+                            $mmlist->delete_list($l['list'], true);
                         }
                         $page->trig('mail lists surpprimées');
                     }
@@ -172,7 +166,6 @@ class XnetModule extends PLModule
                   WHERE  FIND_IN_SET("Institutions", cat)
                ORDER BY  diminutif');
         $page->assign('inst', $res);
-        $page->useMenu();
     }
 
     function handler_groups2(&$page)
@@ -199,18 +192,17 @@ class XnetModule extends PLModule
         $page->assign('doms', $doms);
 
         if (empty($doms)) {
-            $res = XDB::query("SELECT diminutif, nom FROM groupex.asso
+            $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
                                    WHERE FIND_IN_SET({?}, cat)
                                 ORDER BY nom", $cat);
             $page->assign('gps', $res->fetchAllAssoc());
         } elseif (!is_null($dom)) {
-            $res = XDB::query("SELECT diminutif, nom FROM groupex.asso
+            $res = XDB::query("SELECT diminutif, nom, site FROM groupex.asso
                                 WHERE FIND_IN_SET({?}, cat) AND dom={?}
                              ORDER BY nom", $cat, $dom);
             $page->assign('gps', $res->fetchAllAssoc());
         }
 
-        $page->useMenu();
         $page->setType($cat);
     }
 }