Non significant spaces suck.
[platal.git] / include / xnet / session.inc.php
index 9ef0059..2159954 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   *
@@ -23,7 +23,8 @@ class XnetSession
 {
     // {{{ function init
 
-    public static function init() {
+    public static function init()
+    {
         global $globals;
 
         S::init();
@@ -41,6 +42,28 @@ class XnetSession
             $url .= "&url=".urlencode($returl);
             $_SESSION['loginX'] = $url;
         }
+
+        if (S::logged() && $globals->asso()) {
+            $perms = S::v('perms');
+            $perms->rmFlag('groupadmin');
+            $perms->rmFlag('groupmember');
+            $perms->rmFlag('groupannu');
+            if (may_update()) {
+                $perms->addFlag('groupadmin');
+                $perms->addFlag('groupmember');
+                $perms->addFlag('groupannu');
+            }
+            if (is_member()) {
+                $perms->addFlag('groupmember');
+                if ($globals->asso('pub') == 'public') {
+                    $perms->addFlag('groupannu');
+                }
+            }
+            if ($globals->asso('cat') == 'Promotions') {
+                $perms->addFlag('groupannu');
+            }
+            $_SESSION['perms'] = $perms;
+        }
     }
 
     // }}}
@@ -60,7 +83,7 @@ class XnetSession
      */
     public static function doAuth()
     {
-       if (S::identified()) { // ok, c'est bon, on n'a rien à faire
+       if (S::identified()) { // ok, c'est bon, on n'a rien à faire
                return true;
        }
 
@@ -81,7 +104,8 @@ class XnetSession
     // }}}
     // {{{ doAuthX
 
-    public static function doAuthX() {
+    public static function doAuthX()
+    {
         global $globals, $page;
 
         if (md5('1'.S::v('challenge').$globals->xnet->secret.Get::i('uid').'1') != Get::v('auth')) {
@@ -99,8 +123,12 @@ class XnetSession
              LIMIT  1", Get::i('uid'));
         $_SESSION = array_merge($_SESSION, $res->fetchOneAssoc());
         $_SESSION['auth'] = AUTH_MDP;
+        require_once 'xorg/session.inc.php';
+        $_SESSION['perms'] =& XorgSession::make_perms(S::v('perms'));
         S::kill('challenge');
         S::kill('loginX');
+        S::kill('may_update');
+        S::kill('is_member');
         Get::kill('auth');
         Get::kill('uid');
         $path = Get::v('n');
@@ -123,14 +151,15 @@ class XnetSession
         if (!S::has('suid')) {
             $_SESSION['suid'] = $_SESSION;
         }
-        $_SESSION['perms'] = 'user';
+        require_once 'xorg/session.inc.php';
+        $_SESSION['perms'] =& XorgSession::make_perms('user');
     }
 
     // }}}
     // {{{ killSuid
 
     public static function killSuid()
-    {   
+    {
         if (!S::has('suid')) {
             return;
         }
@@ -170,7 +199,7 @@ function may_update($force = false, $lose = false)
         $res = XDB::query("SELECT  perms
                              FROM  groupex.membres
                             WHERE  uid={?} AND asso_id={?}",
-                          S::v('uid'), $globals->asso('id'));
+                          S::v('uid'), $asso_id);
         $may_update[$asso_id] = ($res->fetchOneCell() == 'admin');
     }
     return $may_update[$asso_id];
@@ -182,7 +211,7 @@ function may_update($force = false, $lose = false)
 /** Get membership informations for the current asso
  * @param force Force membership to be read from database
  * @param lose  Force membership to be false
- */ 
+ */
 function is_member($force = false, $lose = false)
 {
     if (!isset($_SESSION['is_member'])) {
@@ -209,5 +238,5 @@ function is_member($force = false, $lose = false)
 }
 
 // }}}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>