From 59e93729a9d25284b7966fb48dc03bbc1fbf9932 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Nana?= <sebastien.nana@maarch.org>
Date: Wed, 30 Mar 2011 16:07:13 +0000
Subject: [PATCH] Fix : notices errors Fix : conformity with coding standards
 in progress Fix : #145 => 50%

---
 core/trunk/core/class/SecurityControler.php   |  17 ++
 core/trunk/core/class/class_functions.php     |  74 +++--
 .../core/class/session_security_controler.php |  83 +++---
 core/trunk/core/core_tables.php               | 127 ++++++--
 core/trunk/core/docservers_tools.php          | 276 +++++++++---------
 core/trunk/core/manage_bitmask.php            |  16 +-
 6 files changed, 335 insertions(+), 258 deletions(-)

diff --git a/core/trunk/core/class/SecurityControler.php b/core/trunk/core/class/SecurityControler.php
index efbcb1c2bd4..cdeb498db7c 100644
--- a/core/trunk/core/class/SecurityControler.php
+++ b/core/trunk/core/class/SecurityControler.php
@@ -32,6 +32,7 @@
 // Loads the required class
 try {
     require_once 'core/core_tables.php';
+    require_once 'core/manage_bitmask.php';
     require_once 'core/class/class_db.php';
     require_once 'core/class/users_controler.php';
     require_once 'core/class/session_security_controler.php';
@@ -422,6 +423,8 @@ class SecurityControler
     */
     public function load_security($userId)
     {
+        require_once 'apps/' . $_SESSION['config']['app_id']
+            . '/security_bitmask.php';
         $tab['collections'] = array();
         $tab['security'] = array();
         $func = new functions();
@@ -437,6 +440,7 @@ class SecurityControler
                     	'label_coll' => $_SESSION['collections'][$i]['label'],
                     	'view'  => $_SESSION['collections'][$i]['view'],
                     	'where' => " (1=1) ",
+                        'securityBitmask' => MAX_BITMASK,
                     );
                 }
                 array_push(
@@ -459,6 +463,7 @@ class SecurityControler
                 $startDate = $access[$i]->__get('mr_start_date');
                 $stopDate = $access[$i]->__get('mr_stop_date');
 
+                $bitmask = $access[$i] ->__get('rights_bitmask');
                 $target = $access[$i]->__get('where_target');
                 $collId = $access[$i]->__get('coll_id');
                 $whereClause = $access[$i]->__get('where_clause');
@@ -484,6 +489,7 @@ class SecurityControler
                             	'label_coll'  => $_SESSION['collections'][$ind]['label'],
                             	'view'  => $_SESSION['collections'][$ind]['view'],
                             	'where'  => $where,
+                                'securityBitmask' => $bitmask,
                             );
                         }
                     } else {
@@ -492,6 +498,7 @@ class SecurityControler
                         	'label_coll'  => $_SESSION['collections'][$ind]['label'],
                         	'view'  => $_SESSION['collections'][$ind]['view'],
                         	'where'  => $where,
+                            'securityBitmask' => $bitmask,
                         );
                     }
                     array_push($tab['collections'], $collId);
@@ -499,6 +506,10 @@ class SecurityControler
                     if (isset($tab['security'][$collId][$target])
                         && count($tab['security'][$collId][$target]) > 0
                     ) {
+                        $tab['security'][ $collId][$target]['securityBitmask'] = set_right(
+                            $tab['security'][ $collId][$target]['securityBitmask'],
+                            $bitmask
+                        );
                         $tab['security'][ $collId][$target]['where'] .= " or "
                             . $where;
                     } else if ($target == 'ALL') {
@@ -506,6 +517,10 @@ class SecurityControler
                             if (isset($tab['security'][$collId][$key])
                                 && count($tab['security'][$collId][$key]) > 0
                             ) {
+                                $tab['security'][ $collId][$target]['securityBitmask'] = set_right(
+                                    $tab['security'][ $collId][$target]['securityBitmask'],
+                                    $bitmask
+                                );
                                 $tab['security'][$collId][$key]['where'] .= " or "
                                     . $where;
                             } else {
@@ -514,6 +529,7 @@ class SecurityControler
                                 	'label_coll'  => $_SESSION['collections'][$ind]['label'],
                                 	'view'  => $_SESSION['collections'][$ind]['view'],
                                 	'where'  => $where,
+                                    'securityBitmask' => $bitmask,
                                 );
                             }
                         }
@@ -523,6 +539,7 @@ class SecurityControler
                         	'label_coll'  => $_SESSION['collections'][$ind]['label'],
                         	'view'  => $_SESSION['collections'][$ind]['view'],
                         	'where'  => $where,
+                            'securityBitmask' => $bitmask,
                         );
                     }
                 }
diff --git a/core/trunk/core/class/class_functions.php b/core/trunk/core/class/class_functions.php
index 6db0ab060b2..dfbf119c81d 100644
--- a/core/trunk/core/class/class_functions.php
+++ b/core/trunk/core/class/class_functions.php
@@ -638,40 +638,38 @@ class functions
     * @param   $date  datetime The date to format
     * @return   datetime  The formatted date
     */
-    public function dateformat($date, $sep = '/')
+    public function dateformat($realDate, $sep='/')
     {
-        if($date <> "")
-        {
-            $ar_test = explode(" ",$date);
-            $date = $ar_test[0];
-            $time = $ar_test[1];
-            if(preg_match('/\./',$time)) // POSTGRES date
-            {
-                $tmp = explode('.', $time);
-                $time = $tmp[0];
-            }
-            else if(preg_match('/,/',$time)) // ORACLE date
-            {
-                $tmp = explode(',', $time);
-                $time = $tmp[0];
-            }
-            if(preg_match('/-/',$date))
-            {
-                $ar_date = explode("-",$date);
-            }
-            elseif(preg_match('@\/@',$date))
-            {
-                $ar_date = explode("/",$date);
+        if ($realDate <> '') {
+            if (preg_match('/ /', $realDate)) {
+                $hasTime = true;
+                $tmpArr = explode(" ", $realDate);
+                $date = $tmpArr[0];
+                $time = $tmpArr[1];
+                if (preg_match('/\./', $time)) {  // POSTGRES date
+                    $tmp = explode('.', $time);
+                    $time = $tmp[0];
+                } else if (preg_match('/,/', $time)) { // ORACLE date
+                    $tmp = explode(',', $time);
+                    $time = $tmp[0];
+                }
+            } else {
+                $hasTime = false;
+                $date = $realDate;
             }
-            if(substr($ar_test[1],0,2) == "00")
-            {
-                return $ar_date[2].$sep.$ar_date[1].$sep.$ar_date[0];
+            if (preg_match('/-/', $date)) {
+                $dateArr = explode("-", $date);
+            } else if (preg_match('@\/@', $date)) {
+                $dateArr = explode("/", $date);
             }
-            else
-            {
-                return $ar_date[2].$sep.$ar_date[1].$sep.$ar_date[0]." ".$time;
+            if (! $hasTime || substr($tmpArr[1], 0, 2) == "00") {
+                return $dateArr[2] . $sep . $dateArr[1] . $sep . $dateArr[0];
+            } else {
+                return $dateArr[2] . $sep . $dateArr[1] . $sep . $dateArr[0]
+                    . " " . $time;
             }
         }
+        return '';
     }
 
     /**
@@ -1317,23 +1315,23 @@ class functions
     */
     public function dateformaten($date)
     {
-        $ar_test = explode(" ",$date);
+        $tmpArr = explode(" ",$date);
 
-        $date = $ar_test[0];
-        $time = $ar_test[1];
-        $ar_date = explode("/",$date);
+        $date = $tmpArr[0];
+        $time = $tmpArr[1];
+        $dateArr = explode("/",$date);
         if(preg_match('/\./',$time))
         {
             $tmp = explode('.', $time);
             $time = $tmp[0];
         }
-        if(substr($ar_test[1],0,2) == "00")
+        if(substr($tmpArr[1],0,2) == "00")
         {
-            return $ar_date[1]."/".$ar_date[0]."/".$ar_date[2];
+            return $dateArr[1]."/".$dateArr[0]."/".$dateArr[2];
         }
         else
         {
-            return $ar_date[1]."/".$ar_date[0]."/".$ar_date[2]." ".$time;
+            return $dateArr[1]."/".$dateArr[0]."/".$dateArr[2]." ".$time;
         }
     }
 
@@ -1615,10 +1613,10 @@ class functions
         }
         return $foundDoc;
     }
-    
+
     //lgi tests
     function detectSmartphone() {
-        $mobile_browser = '0'; 
+        $mobile_browser = '0';
         if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
             $mobile_browser++;
         }
diff --git a/core/trunk/core/class/session_security_controler.php b/core/trunk/core/class/session_security_controler.php
index ac2dfd041bd..d79a99f0466 100644
--- a/core/trunk/core/class/session_security_controler.php
+++ b/core/trunk/core/class/session_security_controler.php
@@ -20,8 +20,8 @@
 
 /**
 * @brief  Contains the controler of the session_security object (create, save, modify, etc...)
-* 
-* 
+*
+*
 * @file
 * @author Claire Figueras <dev@maarch.org>
 * @date $date$
@@ -29,13 +29,6 @@
 * @ingroup core
 */
 
-// To activate de debug mode of the class
-$_ENV['DEBUG'] = false;
-/*
-define("_CODE_SEPARATOR","/");
-define("_CODE_INCREMENT",1);
-*/
-
 // Loads the required class
 try {
 	require_once("core/core_tables.php");
@@ -47,7 +40,7 @@ try {
 }
 
 /**
-* @brief  Controler of the session_security object 
+* @brief  Controler of the session_security object
 *
 *<ul>
 *  <li>Get an session_security object for a given user_id</li>
@@ -67,19 +60,19 @@ class session_security_controler extends ObjectControler implements ObjectContro
 	*/
 	public function get($user_id, $comp_where = '')
 	{
-		self::set_foolish_ids(array('user_id'));
-		self::set_specific_id('user_id');
-		$session_security = self::advanced_get($user_id,SESSION_SECURITY_TABLE);	
-		
+		$this->set_foolish_ids(array('user_id'));
+		$this->set_specific_id('user_id');
+		$session_security = $this->advanced_get($user_id,SESSION_SECURITY_TABLE);
+
 		if(isset($session_security) )
 			return $session_security;
 		else
 			return null;
 	}
-	
-	
+
+
 	/**
-	* Saves in the database a session_security object 
+	* Saves in the database a session_security object
 	*
 	* @param  $session_security session_security object to be saved
 	* @return bool true if the save is complete, false otherwise
@@ -88,17 +81,17 @@ class session_security_controler extends ObjectControler implements ObjectContro
 	{
 		if(!isset($session_security) )
 			return false;
-		
-		self::set_foolish_ids(array('user_id'));
-		self::set_specific_id('user_id');
-		if(self::sessionSecurityExists($session_security->user_id))
-			return self::update($session_security);
+
+		$this->set_foolish_ids(array('user_id'));
+		$this->set_specific_id('user_id');
+		if($this->sessionSecurityExists($session_security->user_id))
+			return $this->update($session_security);
 		else
-			return self::insert($session_security);
-		
+			return $this->insert($session_security);
+
 		return false;
 	}
-	
+
 	/**
 	* Inserts in the database (session_security table) a session_security object
 	*
@@ -107,7 +100,7 @@ class session_security_controler extends ObjectControler implements ObjectContro
 	*/
 	private function insert($session_security)
 	{
-		return self::advanced_insert($session_security);
+		return $this->advanced_insert($session_security);
 	}
 
 	/**
@@ -118,53 +111,53 @@ class session_security_controler extends ObjectControler implements ObjectContro
 	*/
 	private function update($session_security)
 	{
-		return self::advanced_update($session_security);
+		return $this->advanced_update($session_security);
 	}
-	
+
 	/**
-	* Deletes in the database a given session_security 
+	* Deletes in the database a given session_security
 	*
 	* @param  $session_security session_security object
 	* @return bool true if the deletion is complete, false otherwise
 	*/
 	public function delete($session_security)
 	{
-		self::set_foolish_ids(array('user_id'));
-		self::set_specific_id('user_id');
-		return self::advanced_delete($session_security);
+		$this->set_foolish_ids(array('user_id'));
+		$this->set_specific_id('user_id');
+		return $this->advanced_delete($session_security);
 	}
-	
-	
+
+
 	/**
 	* Asserts if a session_security exists in the database for a given user (user_id)
-	* 
+	*
 	* @param  $user_id String User identifier
-	* @return bool true if the user exists, false otherwise 
+	* @return bool true if the user exists, false otherwise
 	*/
 	public function sessionSecurityExists($user_id)
 	{
 		if(!isset($user_id) || empty($user_id))
 			return false;
 
-		self::$db=new dbquery();
-		self::$db->connect();
+		$this->$db=new dbquery();
+		$this->$db->connect();
 		$query = "select user_id from ".SESSION_SECURITY_TABLE." where user_id = '".functions::protect_string_db($user_id)."'";
-					
+
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
+			$this->$db->query($query);
 		} catch (Exception $e){
 			echo _UNKNOWN.' '._USER." ".$user_id.' // ';
 		}
-		
-		if(self::$db->nb_result() > 0)
+
+		if($this->$db->nb_result() > 0)
 		{
-			self::$db->disconnect();
+			$this->$db->disconnect();
 			return true;
 		}
-		self::$db->disconnect();
+		$this->$db->disconnect();
 		return false;
 	}
-	
+
 }
 ?>
diff --git a/core/trunk/core/core_tables.php b/core/trunk/core/core_tables.php
index f3688a7d284..88b14759451 100644
--- a/core/trunk/core/core_tables.php
+++ b/core/trunk/core/core_tables.php
@@ -1,29 +1,102 @@
 <?php
-if(!defined('ACTIONS_TABLE')) define( 'ACTIONS_TABLE', 'actions');
-if(!defined('AUTHORS_TABLE')) define( 'AUTHORS_TABLE', 'authors');
+/*
+*    Copyright 2008 - 2011 Maarch
+*
+*  This file is part of Maarch Framework.
+*
+*   Maarch Framework is free software: you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License as published by
+*   the Free Software Foundation, either version 3 of the License, or
+*   (at your option) any later version.
+*
+*   Maarch Framework is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*    along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-if(!defined('_DOCSERVERS_TABLE_NAME')) define('_DOCSERVERS_TABLE_NAME','docservers');
-if(!defined('_DOCSERVER_TYPES_TABLE_NAME')) define('_DOCSERVER_TYPES_TABLE_NAME','docserver_types');
-if(!defined('_DOCSERVER_LOCATIONS_TABLE_NAME')) define('_DOCSERVER_LOCATIONS_TABLE_NAME','docserver_locations');
-if(!defined('EXT_DOCSERVER_TABLE')) define( 'EXT_DOCSERVER_TABLE', 'ext_docserver');
-
-if(!defined('_LC_CYCLE_STEPS_TABLE_NAME')) define('_LC_CYCLE_STEPS_TABLE_NAME','lc_cycle_steps');
-if(!defined('_ADR_X_TABLE_NAME')) define('_ADR_X_TABLE_NAME','adr_x');
-
-if(!defined('DOCTYPES_TABLE')) define( 'DOCTYPES_TABLE', 'doctypes');
-if(!defined('FULLTEXT_TABLE')) define( 'FULLTEXT_TABLE', 'fulltext');
-if(!defined('GROUPSECURITY_TABLE')) define( 'GROUPSECURITY_TABLE', 'groupsecurity');
-if(!defined('HISTORY_TABLE')) define( 'HISTORY_TABLE', 'history');
-if(!defined('HISTORY_BATCH_TABLE')) define( 'HISTORY_BATCH_TABLE', 'history_batch');
-if(!defined('PARAM_TABLE')) define( 'PARAM_TABLE', 'parameters');
-if(!defined('RESGROUPS_TABLE')) define( 'RESGROUPS_TABLE', 'resgroups');
-if(!defined('RESGROUP_CONTENT_TABLE')) define( 'RESGROUP_CONTENT_TABLE', 'resgroup_content');
-if(!defined('SECURITY_TABLE')) define( 'SECURITY_TABLE', 'security');
-if(!defined('SESSION_SECURITY_TABLE')) define('SESSION_SECURITY_TABLE','session_security');
-if(!defined('STATUS_TABLE')) define( 'STATUS_TABLE', 'status');
-if(!defined('USERGROUPS_TABLE')) define( 'USERGROUPS_TABLE', 'usergroups');
-if(!defined('USERGROUP_CONTENT_TABLE')) define( 'USERGROUP_CONTENT_TABLE', 'usergroup_content');
-if(!defined('USERGROUPS_SERVICES_TABLE')) define( 'USERGROUPS_SERVICES_TABLE', 'usergroups_services');
-if(!defined('USERS_TABLE')) define( 'USERS_TABLE', 'users');
-
-?>
+/**
+* @brief Core tables declarations
+*
+*
+* @file
+* @author  Claire Figueras  <dev@maarch.org>
+* @date $date$
+* @version $Revision$
+* @ingroup core
+*/
+if (! defined('ACTIONS_TABLE')) {
+    define('ACTIONS_TABLE', 'actions');
+}
+if (! defined('AUTHORS_TABLE')) {
+    define('AUTHORS_TABLE', 'authors');
+}
+if (! defined('_DOCSERVERS_TABLE_NAME')) {
+    define('_DOCSERVERS_TABLE_NAME', 'docservers');
+}
+if (!defined('_DOCSERVER_TYPES_TABLE_NAME')) {
+    define('_DOCSERVER_TYPES_TABLE_NAME', 'docserver_types');
+}
+if (! defined('_DOCSERVER_LOCATIONS_TABLE_NAME')) {
+    define('_DOCSERVER_LOCATIONS_TABLE_NAME', 'docserver_locations');
+}
+if (! defined('EXT_DOCSERVER_TABLE')) {
+    define('EXT_DOCSERVER_TABLE', 'ext_docserver');
+}
+if (! defined('_LC_CYCLE_STEPS_TABLE_NAME')) {
+    define('_LC_CYCLE_STEPS_TABLE_NAME', 'lc_cycle_steps');
+}
+if (! defined('_ADR_X_TABLE_NAME')) {
+    define('_ADR_X_TABLE_NAME', 'adr_x');
+}
+if (! defined('DOCTYPES_TABLE')) {
+    define('DOCTYPES_TABLE', 'doctypes');
+}
+if (! defined('FULLTEXT_TABLE')) {
+    define('FULLTEXT_TABLE', 'fulltext');
+}
+if (! defined('GROUPSECURITY_TABLE')) {
+    define('GROUPSECURITY_TABLE', 'groupsecurity');
+}
+if (! defined('HISTORY_TABLE')) {
+    define('HISTORY_TABLE', 'history');
+}
+if (! defined('HISTORY_BATCH_TABLE')) {
+    define('HISTORY_BATCH_TABLE', 'history_batch');
+}
+if (! defined('PARAM_TABLE')) {
+    define('PARAM_TABLE', 'parameters');
+}
+if (! defined('SAVED_QUERIES')) {
+    define('SAVED_QUERIES', 'saved_queries');
+}
+if (! defined('RESGROUP_CONTENT_TABLE')) {
+    define('RESGROUP_CONTENT_TABLE', 'resgroup_content');
+}
+if (! defined('RESGROUPS_TABLE')) {
+    define('RESGROUPS_TABLE', 'resgroups');
+}
+if (! defined('SECURITY_TABLE')) {
+    define('SECURITY_TABLE', 'security');
+}
+if (! defined('SESSION_SECURITY_TABLE')) {
+    define('SESSION_SECURITY_TABLE', 'session_security');
+}
+if (! defined('STATUS_TABLE')) {
+    define('STATUS_TABLE', 'status');
+}
+if (! defined('USERGROUPS_TABLE')) {
+    define('USERGROUPS_TABLE', 'usergroups');
+}
+if (! defined('USERGROUP_CONTENT_TABLE')) {
+    define('USERGROUP_CONTENT_TABLE', 'usergroup_content');
+}
+if (! defined('USERGROUPS_SERVICES_TABLE')) {
+    define('USERGROUPS_SERVICES_TABLE', 'usergroups_services');
+}
+if (! defined('USERS_TABLE')) {
+    define('USERS_TABLE', 'users');
+}
diff --git a/core/trunk/core/docservers_tools.php b/core/trunk/core/docservers_tools.php
index 5d65ea431ce..6781d2f97ac 100644
--- a/core/trunk/core/docservers_tools.php
+++ b/core/trunk/core/docservers_tools.php
@@ -20,7 +20,7 @@
 */
 
 /**
-* @brief API to manage docservers 
+* @brief API to manage docservers
 *
 * @file
 * @author Laurent Giovannoni
@@ -41,14 +41,14 @@ try {
 /**
  * copy doc in a docserver.
  * @param   string $sourceFilePath collection resource
- * @param   array $infoFileNameInTargetDocserver infos of the doc to store, 
+ * @param   array $infoFileNameInTargetDocserver infos of the doc to store,
  *          contains : subdirectory path and new filename
  * @param   string $docserverSourceFingerprint
  * @return  array of docserver data for res_x else return error
  */
 function Ds_copyOnDocserver(
-    $sourceFilePath, 
-    $infoFileNameInTargetDocserver, 
+    $sourceFilePath,
+    $infoFileNameInTargetDocserver,
     $docserverSourceFingerprint='NONE'
 ) {
     $destinationDir = $infoFileNameInTargetDocserver['destinationDir'];
@@ -61,7 +61,7 @@ function Ds_copyOnDocserver(
     }
     $cp = copy($sourceFilePath, $destinationDir . $fileDestinationName);
     Ds_setRights(
-        $destinationDir . $fileDestinationName, 
+        $destinationDir . $fileDestinationName,
         $sourceFilePath
     );
     if ($cp == false) {
@@ -69,8 +69,8 @@ function Ds_copyOnDocserver(
         return $storeInfos;
     }
     Ds_controlFingerprint(
-        $sourceFilePath, 
-        $destinationDir . $fileDestinationName, 
+        $sourceFilePath,
+        $destinationDir . $fileDestinationName,
         $docserverSourceFingerprint
     );
     /*$ofile = fopen($destinationDir.$fileDestinationName, 'r');
@@ -80,20 +80,22 @@ function Ds_copyOnDocserver(
         $storeInfos = array('error' => _COPY_OF_DOC_NOT_COMPLETE);
         return $storeInfos;
     }*/
+    if (isset($GLOBALS['currentStep'])) {
+        $destinationDir = str_replace(
+            $GLOBALS['docservers'][$GLOBALS['currentStep']]['docserver']
+            ['path_template'],
+            '',
+            $destinationDir
+        );
+    }
     $destinationDir = str_replace(
-        $GLOBALS['docservers'][$GLOBALS['currentStep']]['docserver']
-        ['path_template'], 
-        '', 
-        $destinationDir
-    );
-    $destinationDir = str_replace(
-        DIRECTORY_SEPARATOR, 
-        '#', 
+        DIRECTORY_SEPARATOR,
+        '#',
         $destinationDir
     );
     $storeInfos = array(
-        'destinationDir' => $destinationDir, 
-        'fileDestinationName' => $fileDestinationName, 
+        'destinationDir' => $destinationDir,
+        'fileDestinationName' => $fileDestinationName,
         'fileSize' => filesize($sourceFilePath),
     );
     if ($GLOBALS['TmpDirectory'] <> '') {
@@ -107,7 +109,7 @@ function Ds_copyOnDocserver(
  * @param $docServer docservers path
  * @return @return array Contains 2 items : subdirectory path and error
  */
-function Ds_createPathOnDocServer($docServer) 
+function Ds_createPathOnDocServer($docServer)
 {
     if (!is_dir($docServer . date('Y') . DIRECTORY_SEPARATOR)) {
         mkdir($docServer . date('Y') . DIRECTORY_SEPARATOR, 0777);
@@ -116,40 +118,40 @@ function Ds_createPathOnDocServer($docServer)
         );
     }
     if (!is_dir(
-        $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m') 
+        $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m')
         . DIRECTORY_SEPARATOR
     )
     ) {
         mkdir(
-            $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m') 
-            . DIRECTORY_SEPARATOR, 
+            $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m')
+            . DIRECTORY_SEPARATOR,
             0777
         );
         Ds_setRights(
-            $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m') 
-            . DIRECTORY_SEPARATOR, 
+            $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m')
+            . DIRECTORY_SEPARATOR,
             $docServer
         );
     }
-    if ($GLOBALS['wb'] <> '') {
-        $path = $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m') 
+    if (isset($GLOBALS['wb']) && $GLOBALS['wb'] <> '') {
+        $path = $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m')
               . DIRECTORY_SEPARATOR . $GLOBALS['wb'] . DIRECTORY_SEPARATOR;
         if (!is_dir($path)) {
             mkdir($path, 0777);
             Ds_setRights($path, $docServer);
         } else {
             return array(
-                'destinationDir' => '', 
-                'error' => 'Folder alreay exists, workbatch already exist:' 
+                'destinationDir' => '',
+                'error' => 'Folder alreay exists, workbatch already exist:'
                 . $path,
             );
         }
     } else {
-        $path = $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m') 
+        $path = $docServer . date('Y') . DIRECTORY_SEPARATOR.date('m')
               . DIRECTORY_SEPARATOR;
     }
     return array(
-        'destinationDir' => $path, 
+        'destinationDir' => $path,
         'error' => '',
     );
 }
@@ -164,7 +166,7 @@ function Ds_createPathOnDocServer($docServer)
  *          $fingerprintMode
  * @return  array with path of the extracted doc
  */
-function Ds_extractArchive($fileInfos, $fingerprintMode) 
+function Ds_extractArchive($fileInfos, $fingerprintMode)
 {
     //var_dump($fileInfos);
     if (!isset($fileInfos['tmpDir']) || $fileInfos['tmpDir'] == '') {
@@ -172,19 +174,19 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
     } else {
         $tmp = $fileInfos['tmpDir'];
     }
-    $fileNameOnTmp = $tmp . rand() . '_' 
-                   . md5_file($fileInfos['path_to_file']) 
+    $fileNameOnTmp = $tmp . rand() . '_'
+                   . md5_file($fileInfos['path_to_file'])
                    . '_' . $fileInfos['filename'];
     $cp = copy($fileInfos['path_to_file'], $fileNameOnTmp);
     Ds_setRights($fileNameOnTmp, $fileInfos['path_to_file']);
     if ($cp == false) {
         $result = array(
-            'status' => 'ko', 
-            'path' => '', 
-            'mime_type' => '', 
-            'format' => '', 
-            'tmpArchive' => '', 
-            'fingerprint' => '', 
+            'status' => 'ko',
+            'path' => '',
+            'mime_type' => '',
+            'format' => '',
+            'tmpArchive' => '',
+            'fingerprint' => '',
             'error' => _TMP_COPY_ERROR,
         );
         return $result;
@@ -194,20 +196,20 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
         if (mkdir($tmp . $tmpArchive)) {
             //try to extract the offset if it's possible
             if (DIRECTORY_SEPARATOR == '/') {
-                $command = '7z x -y -o' 
-                         . escapeshellarg($tmp . $tmpArchive) . ' ' 
-                         . escapeshellarg($fileNameOnTmp) . ' ' 
+                $command = '7z x -y -o'
+                         . escapeshellarg($tmp . $tmpArchive) . ' '
+                         . escapeshellarg($fileNameOnTmp) . ' '
                          . escapeshellarg($fileNameOnTmp);
             } else {
-                $command = '"' 
+                $command = '"'
                     . str_replace(
-                        '\\', 
-                        '\\\\', 
+                        '\\',
+                        '\\\\',
                         $_SESSION['docserversFeatures']['DOCSERVERS']
                         ['PATHTOCOMPRESSTOOL']
-                    ) 
-                    . '" x -y -o' . escapeshellarg($tmp . $tmpArchive) 
-                    . ' ' . escapeshellarg($fileNameOnTmp) . ' ' 
+                    )
+                    . '" x -y -o' . escapeshellarg($tmp . $tmpArchive)
+                    . ' ' . escapeshellarg($fileNameOnTmp) . ' '
                     . escapeshellarg($fileNameOnTmp);
             }
             $tmpCmd = '';
@@ -216,32 +218,32 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
             if ($execError > 0) {
                 if (DIRECTORY_SEPARATOR == '/') {
                     //else try to extract only the first container
-                    $command = '7z x -y -o' 
-                             . escapeshellarg($tmp . $tmpArchive) . ' ' 
+                    $command = '7z x -y -o'
+                             . escapeshellarg($tmp . $tmpArchive) . ' '
                              . escapeshellarg($fileNameOnTmp);
                 } else {
-                    $command = '"' 
+                    $command = '"'
                         . str_replace(
-                            '\\', 
-                            '\\\\', 
+                            '\\',
+                            '\\\\',
                             $_SESSION['docserversFeatures']['DOCSERVERS']
                             ['PATHTOCOMPRESSTOOL']
-                        ) 
-                        . '" x -y -o' 
-                        . escapeshellarg($tmp . $tmpArchive) . ' ' 
+                        )
+                        . '" x -y -o'
+                        . escapeshellarg($tmp . $tmpArchive) . ' '
                         . escapeshellarg($fileNameOnTmp);
                 }
                 $tmpCmd = '';
                 exec($command, $tmpCmd, $execError);
                 if ($execError > 0) {
                     $result = array(
-                        'status' => 'ko', 
-                        'path' => '', 
-                        'mime_type' => '', 
-                        'format' => '', 
-                        'tmpArchive' => '', 
-                        'fingerprint' => '', 
-                        'error' => _PB_WITH_EXTRACTION_OF_CONTAINER . '#' 
+                        'status' => 'ko',
+                        'path' => '',
+                        'mime_type' => '',
+                        'format' => '',
+                        'tmpArchive' => '',
+                        'fingerprint' => '',
+                        'error' => _PB_WITH_EXTRACTION_OF_CONTAINER . '#'
                         . $execError,
                     );
                     return $result;
@@ -249,23 +251,23 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
             }
         } else {
             $result = array(
-                'status' => 'ko', 
-                'path' => '', 
-                'mime_type' => '', 
-                'format' => '', 
-                'tmpArchive' => '', 
-                'fingerprint' => '', 
-                'error' => _PB_WITH_EXTRACTION_OF_CONTAINER . '#' . $tmp 
+                'status' => 'ko',
+                'path' => '',
+                'mime_type' => '',
+                'format' => '',
+                'tmpArchive' => '',
+                'fingerprint' => '',
+                'error' => _PB_WITH_EXTRACTION_OF_CONTAINER . '#' . $tmp
                 . $tmpArchive,
             );
             return $result;
         }
         $format = substr(
-            $fileInfos['offset_doc'], 
+            $fileInfos['offset_doc'],
             strrpos($fileInfos['offset_doc'], '.') + 1
         );
         if (!file_exists(
-            $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
+            $tmp . $tmpArchive . DIRECTORY_SEPARATOR
             . $fileInfos['offset_doc']
         )
         ) {
@@ -279,44 +281,44 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
                         $execError = '';
                         $tmpArchiveBis = uniqid(rand());
                         if (mkdir(
-                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
+                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR
                             . $tmpArchiveBis
                         )
                         ) {
                             if (DIRECTORY_SEPARATOR == '/') {
-                                $commandBis = '7z x -y -o' 
+                                $commandBis = '7z x -y -o'
                                             . escapeshellarg(
-                                                $tmp . $tmpArchive 
-                                                . DIRECTORY_SEPARATOR 
+                                                $tmp . $tmpArchive
+                                                . DIRECTORY_SEPARATOR
                                                 . $tmpArchiveBis
                                             )
-                                            . ' ' 
+                                            . ' '
                                             . escapeshellarg(
-                                                $tmp . $tmpArchive 
-                                                . DIRECTORY_SEPARATOR 
+                                                $tmp . $tmpArchive
+                                                . DIRECTORY_SEPARATOR
                                                 . $fileScan
                                             )
                                             . ' ' .$fileInfos['offset_doc'];
                             } else {
-                                $commandBis = '"' 
+                                $commandBis = '"'
                                             . str_replace(
-                                                '\\', 
-                                                '\\\\', 
+                                                '\\',
+                                                '\\\\',
                                                 $_SESSION
                                                 ['docserversFeatures']
                                                 ['DOCSERVERS']
                                                 ['PATHTOCOMPRESSTOOL']
                                             )
-                                            . '" x -y -o' 
+                                            . '" x -y -o'
                                             . escapeshellarg(
-                                                $tmp . $tmpArchive 
-                                                . DIRECTORY_SEPARATOR 
+                                                $tmp . $tmpArchive
+                                                . DIRECTORY_SEPARATOR
                                                 . $tmpArchiveBis
                                             )
-                                            . ' ' 
+                                            . ' '
                                             . escapeshellarg(
-                                                $tmp . $tmpArchive 
-                                                . DIRECTORY_SEPARATOR 
+                                                $tmp . $tmpArchive
+                                                . DIRECTORY_SEPARATOR
                                                 . $fileScan
                                             )
                                             . ' ' .$fileInfos['offset_doc'];
@@ -326,55 +328,55 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
                             //echo $commandBis;exit;
                             if ($execError > 0) {
                                 $result = array(
-                                    'status' => 'ko', 
-                                    'path' => '', 
-                                    'mime_type' => '', 
-                                    'format' => '', 
-                                    'tmpArchive' => '', 
-                                    'fingerprint' => '', 
+                                    'status' => 'ko',
+                                    'path' => '',
+                                    'mime_type' => '',
+                                    'format' => '',
+                                    'tmpArchive' => '',
+                                    'fingerprint' => '',
                                     'error' =>
-                                    _PB_WITH_EXTRACTION_OF_CONTAINER . '#' 
+                                    _PB_WITH_EXTRACTION_OF_CONTAINER . '#'
                                     . $execError,
                                 );
                             }
                         } else {
                             $result = array(
-                                'status' => 'ko', 
-                                'path' => '', 
-                                'mime_type' => '', 
-                                'format' => '', 
-                                'tmpArchive' => '', 
-                                'fingerprint' => '', 
+                                'status' => 'ko',
+                                'path' => '',
+                                'mime_type' => '',
+                                'format' => '',
+                                'tmpArchive' => '',
+                                'fingerprint' => '',
                                 'error' => _PB_WITH_EXTRACTION_OF_CONTAINER
-                                . '#' . $tmp . $tmpArchive 
+                                . '#' . $tmp . $tmpArchive
                                 . DIRECTORY_SEPARATOR . $tmpArchiveBis,
                             );
                             return $result;
                         }
                         $path = str_replace(
-                            $fileScan, 
-                            '', 
-                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
-                            . $tmpArchiveBis . DIRECTORY_SEPARATOR 
+                            $fileScan,
+                            '',
+                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR
+                            . $tmpArchiveBis . DIRECTORY_SEPARATOR
                             . $fileInfos['offset_doc']
                         );
                         $path = str_replace(
-                            '#', 
-                            DIRECTORY_SEPARATOR, 
+                            '#',
+                            DIRECTORY_SEPARATOR,
                             $path
                         );
                         $result = array(
-                            'status' => 'ok', 
-                            'path' => $path, 
-                            'mime_type' => Ds_getMimeType($path), 
-                            'format' => $format, 
+                            'status' => 'ok',
+                            'path' => $path,
+                            'mime_type' => Ds_getMimeType($path),
+                            'format' => $format,
                             'fingerprint' =>
-                            Ds_doFingerprint($path, $fingerprintMode), 
-                            'tmpArchive' => $tmp . $tmpArchive, 
+                            Ds_doFingerprint($path, $fingerprintMode),
+                            'tmpArchive' => $tmp . $tmpArchive,
                             'error' => '',
                         );
                         unlink(
-                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
+                            $tmp . $tmpArchive . DIRECTORY_SEPARATOR
                             . $fileScan
                         );
                         break;
@@ -383,24 +385,24 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
             }
         } else {
             $result = array(
-                'status' => 'ok', 
-                'path' => $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
-                . $fileInfos['offset_doc'], 
+                'status' => 'ok',
+                'path' => $tmp . $tmpArchive . DIRECTORY_SEPARATOR
+                . $fileInfos['offset_doc'],
                 'mime_type' =>
                 Ds_getMimeType(
-                    $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
+                    $tmp . $tmpArchive . DIRECTORY_SEPARATOR
                     . $fileInfos['offset_doc']
                 )
-                , 
-                'format' => $format, 
-                'tmpArchive' => $tmp . $tmpArchive, 
+                ,
+                'format' => $format,
+                'tmpArchive' => $tmp . $tmpArchive,
                 'fingerprint' =>
                 Ds_doFingerprint(
-                    $tmp . $tmpArchive . DIRECTORY_SEPARATOR 
-                    . $fileInfos['offset_doc'], 
+                    $tmp . $tmpArchive . DIRECTORY_SEPARATOR
+                    . $fileInfos['offset_doc'],
                     $fingerprintMode
                 )
-                , 
+                ,
                 'error' => '',
             );
         }
@@ -414,7 +416,7 @@ function Ds_extractArchive($fileInfos, $fingerprintMode)
  * @param   string $fingerprintMode (md5, sha512, ...)
  * @return  string the fingerprint
  */
-function Ds_doFingerprint($path, $fingerprintMode) 
+function Ds_doFingerprint($path, $fingerprintMode)
 {
     if ($fingerprintMode == 'NONE' || $fingerprintMode == '') {
         return '0';
@@ -431,24 +433,24 @@ function Ds_doFingerprint($path, $fingerprintMode)
  * @return  array ok or ko with error
  */
 function Ds_controlFingerprint(
-    $pathInit, 
-    $pathTarget, 
+    $pathInit,
+    $pathTarget,
     $fingerprintMode='NONE'
 ) {
     $result = array();
     if (Ds_doFingerprint(
-        $pathInit, 
+        $pathInit,
         $fingerprintMode
     ) <> Ds_doFingerprint($pathTarget, $fingerprintMode)
     ) {
         $result = array(
-            'status' => 'ko', 
-            'error' => _PB_WITH_FINGERPRINT_OF_DOCUMENT . ' ' . $pathInit 
+            'status' => 'ko',
+            'error' => _PB_WITH_FINGERPRINT_OF_DOCUMENT . ' ' . $pathInit
             . ' '. _AND . ' ' . $pathTarget,
         );
     } else {
         $result = array(
-            'status' => 'ok', 
+            'status' => 'ok',
             'error' => '',
         );
     }
@@ -461,7 +463,7 @@ function Ds_controlFingerprint(
  * @param   string $source path of the resource 2
  * @return  nothing
  */
-function Ds_setRights($dest, $source) 
+function Ds_setRights($dest, $source)
 {
     //chown($dest, fileowner($source));
     //chgrp($dest, filegroup($source));
@@ -478,7 +480,7 @@ function Ds_setRights($dest, $source)
  * @param   string $source path of the resource 2
  * @return  nothing
  */
-function Ds_recurseSetRights($dest, $source) 
+function Ds_recurseSetRights($dest, $source)
 {
     $d = opendir($mypath);
     while (($file = readdir($d)) !== false) {
@@ -497,7 +499,7 @@ function Ds_recurseSetRights($dest, $source)
 * @param $filePath path of the file
 * @return string of the mime type
 */
-function Ds_getMimeType($filePath) 
+function Ds_getMimeType($filePath)
 {
     require_once 'MIME/Type.php';
     return MIME_Type::autoDetect($filePath);
@@ -509,7 +511,7 @@ function Ds_getMimeType($filePath)
  * @param   $contentOnly boolean true if only the content
  * @return  boolean
  */
-function Ds_washTmp($dir, $contentOnly=false) 
+function Ds_washTmp($dir, $contentOnly=false)
 {
     if (is_dir($dir)) {
         $objects = scandir($dir);
@@ -518,7 +520,7 @@ function Ds_washTmp($dir, $contentOnly=false)
                 if (
                     filetype($dir . DIRECTORY_SEPARATOR . $object) == 'dir'
                 ) {
-                    Ds_washTmp($dir . DIRECTORY_SEPARATOR . $object); 
+                    Ds_washTmp($dir . DIRECTORY_SEPARATOR . $object);
                 } else {
                     unlink($dir . DIRECTORY_SEPARATOR . $object);
                 }
@@ -537,7 +539,7 @@ function Ds_washTmp($dir, $contentOnly=false)
 * @param  $delay
 * @param  $pointer position in the file
 */
-function Ds_isCompleteFile($file, $delay=500, $pointer=0) 
+function Ds_isCompleteFile($file, $delay=500, $pointer=0)
 {
     if ($file == null) {
         return false;
diff --git a/core/trunk/core/manage_bitmask.php b/core/trunk/core/manage_bitmask.php
index cdda7eaa483..50375c62292 100644
--- a/core/trunk/core/manage_bitmask.php
+++ b/core/trunk/core/manage_bitmask.php
@@ -1,21 +1,15 @@
 <?php
 
-
-function check_right($int_to_check, $right)
+function check_right($intToCheck, $right)
 {
-	if($int_to_check & $right)
-	{
+	if ($intToCheck & $right) {
 		return true;
-	}
-	else
-	{
+	} else {
 		return false;
 	}
 }
 
-function set_right($int_to_set = 0, $right)
+function set_right($intToSet = 0, $right)
 {
-	return $int_to_set | $right;	
+	return $intToSet | $right;
 }
-
-?>
-- 
GitLab