add jquery script, use it to autoload on xnet when xorg cookie is present
[platal.git] / modules / xnet.php
index 5f2564f..1f30778 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,29 +25,47 @@ 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),
 
             '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),
+            'autologin' => $this->make_hook('autologin', AUTH_MDP),
         );
     }
 
+    function handler_photo(&$page, $x = null)
+    {
+        if (is_null($x)) {
+            return PL_NOT_FOUND;
+        }
+
+        $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_index(&$page)
     {
         $page->nomenu = true;
         $page->changeTpl('xnet/index.tpl');
     }
 
-    function handler_login(&$page)
-    {
-        pl_redirect('');
-    }
-
     function handler_exit(&$page)
     {
+        XnetSession::killSuid();
         XnetSession::destroy();
         $page->changeTpl('xnet/deconnexion.tpl');
     }
@@ -64,7 +82,7 @@ class XnetModule extends PLModule
             $page->assign('nom', $nom);
             if ($id && Post::has('del')) {
                 XDB::query('DELETE FROM groupex.membres WHERE asso_id={?}', $id);
-                $page->trig('membres supprimés');
+                $page->trig('membres supprimés');
 
                 if ($domain) {
                     XDB::query('DELETE FROM  virtual_domains WHERE domain={?}', $domain);
@@ -78,12 +96,12 @@ class XnetModule extends PLModule
                         foreach ($listes as $l) {
                             $mmlist->delete_list($l['list'], true);
                         }
-                        $page->trig('mail lists surpprimées');
+                        $page->trig('mail lists surpprimées');
                     }
                 }
 
                 XDB::query('DELETE FROM groupex.asso WHERE id={?}', $id);
-                $page->trig("Groupe $nom supprimé");
+                $page->trig("Groupe $nom supprimé");
                 Get::kill('del');
             }
             if (!$id) {
@@ -179,6 +197,17 @@ class XnetModule extends PLModule
 
         $page->setType($cat);
     }
+    
+    function handler_autologin(&$page)
+    {
+        $allkeys = func_get_args();
+        unset($allkeys[0]);
+        $url = join('/',$allkeys);
+        header("Content-type: text/javascript; charset=utf-8");
+        echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});';
+        exit;
+    }
 }
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>