diff --git a/core/trunk/core/class/BaseObject.php b/core/trunk/core/class/BaseObject.php
index 544d4eec0bb5e94c5c006be68ddcb086e165706e..980e21ea587c604b220ef231875cd0ea064d3c5a 100644
--- a/core/trunk/core/class/BaseObject.php
+++ b/core/trunk/core/class/BaseObject.php
@@ -19,33 +19,21 @@
 */
 
 /**
-* @brief  Contains the BaseObject object (Object used as a base for more advanced object as User, Usergroup, ...)
-* 
-* 
-* @file
-* @author Claire Figueras <dev@maarch.org>
-* @date $date$
-* @version $Revision$
-* @ingroup core
-*/
-
-
-/**
-* @brief BaseObject Object
-*
-* @ingroup core
-*/
-class BaseObject 
-{
-	/**
-	* Array of all the object properties (key => value)
-    */
-	private $data = array(); 
+ * This object aims at giving a 
+ * standard structure for objects
+ * that come directly from the 
+ * table of a database.
+ * 
+ * @author boulio
+ *
+ */
+class BaseObject {
+	protected $data = array(); 
 
 	/**
 	 * Initializes an object
 	 */
-	function __construct(){
+	public function __construct(){
 	}
 
 	/**
@@ -54,8 +42,7 @@ class BaseObject
 	 * @param string $name Name of property to set
 	 * @param object $value Value of property $name
 	 */
-	function __set($name, $value)
-	{
+	public function __set($name, $value){
 		$this->data[$name] = $value;
 	}
 
@@ -66,8 +53,7 @@ class BaseObject
 	 * @return string Value of $name  or null
 	 * @exception $e Exception Sent if $name does not exist
 	 */
-	function __get($name) 
-	{
+	public function __get($name) {
 		try {
 			return $this->data[$name];
 		} catch (Exception $e) {
@@ -98,19 +84,24 @@ class BaseObject
 	 */
 	public function getArray() 
 	{
-		return $this->data;
+		if(is_null($this->data))
+			return null;
+		else
+			return $this->data;
 	}
 	
-	/**
-	 * Sets values of all properties of the current object 
-	 * 
-	 * @param Array $array Array of the properties to set
-	 */
 	public function setArray($array) 
 	{
 		$this->data = $array;
 	}
 	
-	//abstract function toString();
+	public function getLabel($name){
+		if(in_array($name, array_keys($data))){
+			return eval("_".strtoupper($name));
+		} else {
+			return "";
+		}
+	}
+
 }
 ?>
diff --git a/core/trunk/core/class/ObjectControlerAbstract.php b/core/trunk/core/class/ObjectControlerAbstract.php
new file mode 100644
index 0000000000000000000000000000000000000000..9cbe81e9a77686a44d94ec6952f3c3ed46e631af
--- /dev/null
+++ b/core/trunk/core/class/ObjectControlerAbstract.php
@@ -0,0 +1,361 @@
+<?php
+
+define ("_DEBUG", false);
+define ("_ADVANCED_DEBUG",false);
+
+/**
+ * Implementing few generic features for controlers of type
+ * "all-the-properties-of-the-object-are-the-columns-of-the-
+ * database-table", i.e. BaseObject-kind.
+ * 
+ * @author boulio
+ *
+ */
+abstract class ObjectControler {
+	static protected $db;
+	static protected $computed_properties=array(
+							);
+	static protected $foolish_ids=array(); //"docserver_id","user_id","mr_owner_entity_id"
+	static protected $specific_id ;
+	
+	protected function set_foolish_ids($array)
+	{
+		if(isset($array) && is_array($array) && count($array) > 0 )
+			self::$foolish_ids = $array;
+	}
+	
+	protected function set_specific_id($id)
+	{
+		if(isset($id) && !empty($id) )
+			self::$specific_id = $id;
+	}
+	
+	/**
+	 * Insert given object in given table.
+	 * Return inserted object if succeeded.
+	 * @param unknown_type $object
+	 * @return unknown_type 
+	 */
+	protected function advanced_insert($object){
+		$table_name=get_class($object);
+		if(!isset($object) )
+			return false;
+			
+		// Inserting object
+		$preparation=self::insert_prepare($object, self::$computed_properties);
+		$query="insert into $table_name ("
+					.$preparation['properties']
+					.") values("
+					.$preparation['values']
+					.")";
+		self::$db=new dbquery();
+		self::$db->connect();
+		try{
+			if(_DEBUG){echo "insert: $query // ";}
+			self::$db->query($query);
+			$result=true;
+		} catch (Exception $e){
+			echo "Impossible to insert object ".$object->toString().' // ';
+			$result=false;
+		}
+		self::$db->disconnect();
+		return $result;
+	}
+
+	/**
+	 * Prepare two strings for insert query :
+	 * - 'properties' for properties field of insert query,
+	 * - 'values' for values field of insert query.
+	 * Needs list of values to _exclude_ of insert query (i.e. 
+	 * usually values computed in the get() function of controler).
+	 * Result in an array.
+	 * @param Any $object
+	 * @param string[] $computed_properties
+	 * @return string[]
+	 */
+	private function insert_prepare($object, $computed_properties){
+		$result=array();
+		$properties=array();
+		$values=array();
+		foreach($object->getArray() as $key => $value){
+			if(!in_array($key,$computed_properties)){
+				// Adding property
+				$properties[]=$key;
+				// Adding property value
+				if(substr_compare($key, "_id", -3)==0 || substr_compare($key, "_number", -7)==0){
+					if(in_array($key, self::$foolish_ids)){
+						/*
+						 * UNBELIEVABLE! THERE ARE IDS WHICH ARE NOT LONG INTEGERS!
+						 * A choice needs to be done, and if string is kept, random
+						 * generating must be implemented.
+						 */
+						$values[]="'".$value."'";
+					} else {
+						// Number
+						if(empty($value)){
+							// Default value
+							$value=0;
+						}
+						$values[]=$value;
+					}
+				} elseif(substr_compare($key, "is_", 0, 3)==0 || substr_compare($key, "can_", 0, 4)==0){
+					// Boolean
+					if($value===true){
+						$values[]="'true'";
+					} elseif($value===false) {
+						$values[]="'false'";
+					}
+				} else {
+					// Character or date
+					$values[]="'".$value."'";
+				}
+			}
+							
+		}
+		$result['properties']=implode(",",$properties);
+		$result['values']=implode(",",$values);
+		return $result;
+	}
+	
+	/**
+	 * Update given object in given table, according
+	 * with given table id name.
+	 * Return updated object if succeeded.
+	 * @param unknown_type $object
+	 * @return unknown_type
+	 */
+	protected function advanced_update($object){
+		if(!isset($object) )
+			return false;
+		
+		$table_name=get_class($object);
+		$table_id=$table_name."_id";
+		
+		if(isset(self::$specific_id) && !empty(self::$specific_id))
+			$table_id = self::$specific_id;
+			
+		if(in_array($table_id, self::$foolish_ids)){
+			$query="update $table_name set "
+						.self::update_prepare($object, self::$computed_properties)
+						." where $table_id='".$object->$table_id."'"; 
+		} else {
+			$query="update $table_name set "
+						.self::update_prepare($object, self::$computed_properties)
+						." where $table_id=".$object->$table_id;
+		}
+		self::$db=new dbquery();
+		self::$db->connect();
+		try{
+			if(_DEBUG){echo "update: $query // ";}
+			self::$db->query($query);
+			$result=true;
+		} catch (Exception $e){
+			echo "Impossible to update object ".$object->toString().' // ';
+			$result=false;
+		}
+		self::$db->disconnect();
+		return $result;
+	}
+	
+	/**
+	 * Prepare string for update query
+	 * @param Any $object
+	 * @param string[] $computed_properties
+	 * @return String
+	 */
+	private function update_prepare($object, $computed_properties){
+		$result=array();
+		foreach($object->getArray() as $key => $value){
+			if(!in_array($key,$computed_properties)){
+				if(substr_compare($key, "_id", -3)==0 || substr_compare($key, "_number", -7)==0){
+					if(in_array($key, self::$foolish_ids)){
+						$result[]=$key."='".$value."'";
+					} else {
+						// Number
+						if(empty($value)){
+							// Default value
+							$value=0;
+						}
+						$result[]=$key."=".$value;
+					}
+				} elseif(substr_compare($key, "is_", 0, 3)==0 || substr_compare($key, "can_", 0, 4)==0){
+					// Boolean
+					if($value===true){
+						$result[]=$key."=true";
+					} elseif($value===false) {
+						$result[]=$key."=false";
+					}
+				} else {
+					// Character or date
+					$result[]=$key."='".$value."'";
+				}
+			}
+		}
+		// Return created string minus last ", "
+		return implode(",",$result);
+	}
+
+	/**
+	 * Get object of given class with given id from 
+	 * good table and according with given class name.
+	 * Can return null if no corresponding object.
+	 * @param long $id Id of object to get
+	 * @param string $class_name
+	 * @return unknown_type 
+	 */
+	protected function advanced_get($id,$table_name) {
+		if(strlen($id)==0){
+			return null;
+		}
+		$table_id=$table_name."_id";
+		
+		if(isset(self::$specific_id) && !empty(self::$specific_id))
+			$table_id = self::$specific_id;
+			
+		self::$db=new dbquery();
+		self::$db->connect();
+		if(in_array($table_id, self::$foolish_ids)){
+			 $select="select * from $table_name where $table_id='$id'";
+		} else{
+			$select="select * from $table_name where $table_id=$id";
+		}
+		
+		try {
+			if(_DEBUG){echo "get: $select // ";}
+			self::$db->query($select);
+			if(self::$db->nb_result()==0){
+				return null;
+			} else {
+				// Constructing result
+				$object=new $table_name();
+				$queryResult=self::$db->fetch_object();
+				foreach((array)$queryResult as $key => $value){
+					if(_ADVANCED_DEBUG){
+						echo "Getting property: $key with value: $value // ";
+					}
+					if($value=='t') {			/* BUG FROM PGSQL DRIVER! */
+						$value=true;  			/*						  */
+					} elseif($value=='f') {		/*						  */
+						$value=false; 			/*						  */
+					}							/**************************/
+					$object->$key=$value;
+				}
+			}
+		} catch (Exception $e) {
+			echo "Impossible to get object $id // ";
+		}
+		
+		self::$db->disconnect();
+		return $object;
+	}
+	
+		/**
+	 * Delete given object from given table, according with
+	 * given table id name.
+	 * Return true if succeeded.
+	 * @param Any $object
+	 * @return boolean
+	 */
+	protected function advanced_delete($object){
+		if(!isset($object))
+			return false;
+			
+		$table_name=get_class($object);
+		$table_id=$table_name."_id";
+		
+		if(isset(self::$specific_id) && !empty(self::$specific_id))
+			$table_id = self::$specific_id;
+		
+		self::$db=new dbquery();
+		self::$db->connect();
+		if(in_array($table_id, self::$foolish_ids)){
+			 $query="delete from $table_name where $table_id='".$object->$table_id."'";
+		} else{
+			$query="delete from $table_name where $table_id=".$object->$table_id;
+		}
+		
+		try{
+			if(_DEBUG){echo "delete: $query // ";}
+			self::$db->query($query);
+			$result=true;
+		} catch (Exception $e){
+			echo "Impossible to delete object with id=".$object->$table_id." // ";
+			$result=false;
+		}
+		self::$db->disconnect();
+		return $result;
+	}
+
+	/**
+	 * Enable given object from given table, according with
+	 * given table id name.
+	 * Return true if succeeded.
+	 * @param Any $object
+	 * @return boolean
+	 */
+	protected function advanced_enable($object){
+		if(!isset($object))
+			return false;
+			
+		$table_name=get_class($object);
+		$table_id=$table_name."_id";
+		
+		if(isset(self::$specific_id) && !empty(self::$specific_id))
+			$table_id = self::$specific_id;
+		
+		self::$db=new dbquery();
+		self::$db->connect();
+		if(in_array($table_id, self::$foolish_ids)){
+			 $query="update $table_name set enabled = 'Y' where $table_id='".$object->$table_id."'";
+		} else{
+			$query="update $table_name set enabled = 'Y' where $table_id=".$object->$table_id;
+		}
+		try{
+			if(_DEBUG){echo "enable: $query // ";}
+			self::$db->query($query);
+			$result=true;
+		} catch (Exception $e){
+			echo "Impossible to enable object with id=".$object->$table_id." // ";
+			$result=false;
+		}
+		self::$db->disconnect();
+		return $result;
+	}
+
+	/**
+	 * Disable given object from given table, according with
+	 * given table id name.
+	 * Return true if succeeded.
+	 * @param Any $object
+	 * @return boolean
+	 */
+	protected function advanced_disable($object){
+		if(!isset($object))
+			return false;
+			
+		$table_name=get_class($object);
+		$table_id=$table_name."_id";
+		
+		if(isset(self::$specific_id) && !empty(self::$specific_id))
+			$table_id = self::$specific_id;
+		
+		self::$db=new dbquery();
+		self::$db->connect();
+		if(in_array($table_id, self::$foolish_ids)){
+			 $query="update $table_name set enabled = 'N' where $table_id='".$object->$table_id."'";
+		} else{
+			$query="update $table_name set enabled = 'N' where $table_id=".$object->$table_id;
+		}
+		try{
+			if(_DEBUG){echo "disable: $query // ";}
+			self::$db->query($query);
+			$result=true;
+		} catch (Exception $e){
+			echo "Impossible to disable object with id=".$object->$table_id." // ";
+			$result=false;
+		}
+		self::$db->disconnect();
+		return $result;
+	}
+
+}
diff --git a/core/trunk/core/class/ObjectControlerIF.php b/core/trunk/core/class/ObjectControlerIF.php
new file mode 100644
index 0000000000000000000000000000000000000000..63df6b13f7788203af4e1697ab3ea18718846cde
--- /dev/null
+++ b/core/trunk/core/class/ObjectControlerIF.php
@@ -0,0 +1,40 @@
+<?php
+
+try {
+	//require_once("modules/moreq/moreq_tables_definition.php");
+	require_once("core/class/class_db.php");
+} catch (Exception $e){
+	echo $e->getMessage().' // ';
+}
+
+/**
+ * Interface for standard object controlers
+ * @author boulio
+ *
+ */
+interface ObjectControlerIF {
+	/**
+	 * Save given object in database.
+	 * Return true if succeeded.
+	 * @param unknown_type $object
+	 * @return boolean
+	 */
+	function save($object);
+	
+	/**
+	 * Return object with given id 
+	 * if found.
+	 * @param $object_id
+	 */
+	function get($object_id);
+	
+	/**
+	 * Delete given object from 
+	 * database.
+	 * Return true if succeeded.
+	 * @param unknown_type $object
+	 * @return boolean
+	 */
+	function delete($object);
+	
+}
diff --git a/core/trunk/core/class/SecurityControler.php b/core/trunk/core/class/SecurityControler.php
index b7a416ac7bfb2cc6e2e37a47b4778511cc5c87e6..0ab6f9c593193c5be16994f835e99a8234073551 100644
--- a/core/trunk/core/class/SecurityControler.php
+++ b/core/trunk/core/class/SecurityControler.php
@@ -40,7 +40,7 @@ define("_CODE_INCREMENT",1);
 // Loads the required class
 try {
 	require_once("core/class/class_db.php");
-	require_once("core/class/UserControler.php");
+	require_once("core/class/users_controler.php");
 	require_once("core/class/Security.php");
 } catch (Exception $e){
 	echo $e->getMessage().' // ';
@@ -189,7 +189,7 @@ class SecurityControler
 	/**
 	* Inserts in the database (security table) a Security object
 	*
-	* @param  $security Security objectgetAccessForGroup($group_id)
+	* @param  $security Security object
 	* @return bool true if the insertion is complete, false otherwise
 	*/
 	private function insert($security)
@@ -342,7 +342,6 @@ class SecurityControler
 		return array('COLUMNS' => implode(",",$columns), 'VALUES' => implode(",",$values));
 	}
 	
-
 	// TO DO : USE TO CHECK WHERE CLAUSE
 	public function check_where_clause($coll_id, $target, $where_clause, $view, $user_id)
 	{
@@ -473,7 +472,7 @@ class SecurityControler
 		}
 		else
 		{
-			$groups = UserControler::getGroups($user_id);
+			$groups = users_controler::getGroups($user_id);
 
 			$access = array();
 			for($i=0; $i<count($groups); $i++)
@@ -562,5 +561,41 @@ class SecurityControler
 		return -1;
 	}
 
+
+/**
+	 * Give action bitmask for given $user_id over given
+	 * object
+	 * @param varchar(32) $user_id
+	 * @param bigint $object_id
+	 * @return bitmask
+	 */
+	public function getActions($user_id,$object_id){
+		// Select from security session table
+		
+		/********
+		 * FAKE *
+		 ********/
+		return ADD_RECORD+CREATE_CLASS+CREATE_OTHER_AGREGATION+DATA_MODIFICATION+DELETE_CLASS+DELETE_OTHER_AGREGATION;
+	}
+	
+	/**
+	 * Update security session table with
+	 * bitmask, according with given user 
+	 * and aggregation.
+	 * Return computed bitmask
+	 * @param varchar(32) $user_id
+	 * @param bigint $object_id
+	 * @return bitmask
+	 */
+	public function setActions($user_id,$object_id){
+		// Compute action bitmask 
+		
+		// Update security session table
+		
+		/********
+		 * FAKE *
+		 ********/
+		return ADD_RECORD+CREATE_CLASS+CREATE_OTHER_AGREGATION+DATA_MODIFICATION+DELETE_CLASS+DELETE_OTHER_AGREGATION;
+	}
 }
 ?>
diff --git a/core/trunk/core/class/ServiceControler.php b/core/trunk/core/class/ServiceControler.php
index 133631849c993ebd675245740bab4aa7d45aab00..b156e0b0685a85ba8afde3305d1851c75756dd1e 100644
--- a/core/trunk/core/class/ServiceControler.php
+++ b/core/trunk/core/class/ServiceControler.php
@@ -40,7 +40,7 @@ define("_CODE_INCREMENT",1);
 // Loads the required class
 try {
 	require_once("core/class/Service.php");
-	require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."UsergroupControler.php");
+	require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."usergroups_controler.php");
 } catch (Exception $e){
 	echo $e->getMessage().' // ';
 }
@@ -134,7 +134,7 @@ class ServiceControler
 					$find = false;
 					while($res = self::$db->fetch_object())
 					{
-						if(UsergroupControler::inGroup($user_id, $res->group_id) == true)
+						if(usergroups_controler::inGroup($user_id, $res->group_id) == true)
 						{
 							$find = true;
 							break;
diff --git a/core/trunk/core/class/class_core_tools.php b/core/trunk/core/class/class_core_tools.php
index 5db9a18c8dae62963d9bb8e3972f5828731c5867..d8482a9e1426419cf5848d6d69b016b576a03b99 100644
--- a/core/trunk/core/class/class_core_tools.php
+++ b/core/trunk/core/class/class_core_tools.php
@@ -945,7 +945,7 @@ class core_tools extends functions
 	public function load_html()
 	{
 		?>
-        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
+        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php  echo $_SESSION['config']['lang']; ?>" lang="<?php  echo $_SESSION['config']['lang']; ?>">
         <?php
 	}
diff --git a/core/trunk/core/class/class_security.php b/core/trunk/core/class/class_security.php
index 6e96ff3c7df0b8e05c70d9dd186aab24575ec130..eb0e5cec79ca85673ed41d1f14cac33a77f19607 100644
--- a/core/trunk/core/class/class_security.php
+++ b/core/trunk/core/class/class_security.php
@@ -73,7 +73,7 @@ class security extends dbquery
 	*/
 	public function login($s_login,$pass, $method = false)
 	{
-		require_once('core/class/UserControler.php');
+		require_once('core/class/users_controler.php');
 		if ($this->test_column($_SESSION['tablename']['users'], 'loginmode')) //Compatibility test, if loginmode column doesn't exists, Maarch can't crash
 		{
 			if ($method == 'activex')
@@ -83,14 +83,14 @@ class security extends dbquery
 		}
 		else
 			$comp = " and password = '".$pass."' and STATUS <> 'DEL'";
-			
-		$user = UserControler::get($s_login, $comp);
-	
+
+		$user = users_controler::get($s_login, $comp);
+
 		if(isset($user))
 		{
 			if($user->__get('enabled') == "Y")
 			{
-				require_once("core/class/UsergroupControler.php");
+				require_once("core/class/usergroups_controler.php");
 				require_once("core/class/ServiceControler.php");
 				$_SESSION['user']['change_pass'] = $user->__get('change_password');
 				$_SESSION['user']['UserId'] = $user->__get('user_id');
@@ -108,12 +108,12 @@ class security extends dbquery
 					$user->__set('cookie_date', 'SYSDATE');
 				else
 					$user->__set('cookie_date',date("Y-m-d")." ".date("H:m:i"));
-
-				UserControler::save($user, 'up');
-				setcookie("maarch", "UserId=".$_SESSION['user']['UserId']."&key=".$key,time()+($_SESSION['config']['cookietime']*1000));
 				
-				$_SESSION['user']['primarygroup'] = UsergroupControler::getPrimaryGroup($_SESSION['user']['UserId']);
+				users_controler::save($user, 'up');
+				setcookie("maarch", "UserId=".$_SESSION['user']['UserId']."&key=".$key,time()+($_SESSION['config']['cookietime']*1000));
+				$_SESSION['user']['primarygroup'] = usergroups_controler::getPrimaryGroup($_SESSION['user']['UserId']);
 				$tmp = SecurityControler::load_security($_SESSION['user']['UserId']);
+
 				$_SESSION['user']['collections'] = $tmp['collections'];
 				$_SESSION['user']['security'] = $tmp['security'];
 				
@@ -181,13 +181,13 @@ class security extends dbquery
 		
 		$comp = " and cookie_key = '".$s_key."' and STATUS <> 'DEL'";
 
-		$user = UserControler::get($s_login, $comp);
+		$user = users_controler::get($s_login, $comp);
 	
 		if(isset($user))
 		{
 			if($user->__get('enabled')  == "Y")
 			{
-				require_once("core/class/UsergroupControler.php");
+				require_once("core/class/usergroups_controler.php");
 				require_once("core/class/ServiceControler.php");
 				$_SESSION['user']['change_pass'] = $user->__get('change_password');
 				$_SESSION['user']['UserId'] = $user->__get('user_id');
@@ -206,10 +206,10 @@ class security extends dbquery
 				else
 					$user->__set('cookie_date',date("Y-m-d")." ".date("H:m:i"));
 
-				UserControler::save($user, 'up');
+				users_controler::save($user, 'up');
 				setcookie("maarch", "UserId=".$_SESSION['user']['UserId']."&key=".$key,time()+($_SESSION['config']['cookietime']*60));
 
-				$_SESSION['user']['primarygroup'] = UsergroupControler::getPrimaryGroup($_SESSION['user']['UserId']);
+				$_SESSION['user']['primarygroup'] = usergroups_controler::getPrimaryGroup($_SESSION['user']['UserId']);
 				
 				$tmp = SecurityControler::load_security($_SESSION['user']['UserId']);
 				$_SESSION['user']['collections'] = $tmp['collections'];
diff --git a/core/trunk/core/class/Usergroup.php b/core/trunk/core/class/usergroups.php
similarity index 97%
rename from core/trunk/core/class/Usergroup.php
rename to core/trunk/core/class/usergroups.php
index 906614c1b045ec70ef12ebd31cef86eb19eb2276..f9b3f564106d16bc85adbe6699d62e6963112ec3 100644
--- a/core/trunk/core/class/Usergroup.php
+++ b/core/trunk/core/class/usergroups.php
@@ -42,7 +42,7 @@ try {
 *
 * @ingroup core
 */
-class Usergroup  extends BaseObject
+class usergroups  extends BaseObject
 {
 	/**
 	* Returns the string representing the Usergroup object
diff --git a/core/trunk/core/class/UsergroupControler.php b/core/trunk/core/class/usergroups_controler.php
similarity index 55%
rename from core/trunk/core/class/UsergroupControler.php
rename to core/trunk/core/class/usergroups_controler.php
index f9c1b61378e077b1250a2cca8a551ce13f7601fc..0dc1ff4c8b2ea39715bcbd3ca82a1f98704e5493 100644
--- a/core/trunk/core/class/UsergroupControler.php
+++ b/core/trunk/core/class/usergroups_controler.php
@@ -19,7 +19,7 @@
 */
 
 /**
-* @brief  Contains the controler of the Usergroup Object (create, save, modify, etc...)
+* @brief  Contains the controler of the usergroups object (create, save, modify, etc...)
 * 
 * 
 * @file
@@ -39,130 +39,57 @@ define("_CODE_INCREMENT",1);
 
 // Loads the required class
 try {
-	require_once("core/class/class_db.php");
-	require_once("core/class/Usergroup.php");
+	require_once("core/core_tables.php");
+	require_once("modules/basket/basket_tables.php");
+	require_once("core/class/usergroups.php");
+	require_once("core/class/ObjectControlerAbstract.php");
+	require_once("core/class/ObjectControlerIF.php");
+	require_once("core/class/SecurityControler.php");
+	
 } catch (Exception $e){
 	echo $e->getMessage().' // ';
 }
 
 
 /**
-* @brief  Controler of the Usergroup Object 
+* @brief  Controler of the usergroups object 
 *
 *<ul>
-*  <li>Get an usergroup object from an id</li>
+*  <li>Get an usergroups object from an id</li>
 *  <li>Save in the database a usergroup</li>
 *  <li>Manage the operation on the usergroups related tables in the database (insert, select, update, delete)</li>
 *</ul>
 * @ingroup core
 */
-class UsergroupControler
+class usergroups_controler extends ObjectControler implements ObjectControlerIF
 {
+
 	/**
-	* Dbquery object used to connnect to the database
-    */
-	static $db;
-	
-	/**
-	* Usergroups table
-    */
-	static $usergroups_table;
-	
-	/**
-	* Usergroup_content table
-    */
-	static $usergroup_content_table;
-	
-	/**
-	* Groupbasket table
-    */
-	static $groupbasket_table ;
-	
-	/**
-	* Usergroups_services table
-    */
-	static $groups_services_table;
-	
-	
-	/**
-	* Opens a database connexion and values the tables variables
-	*/
-	public function connect()
-	{
-		$db = new dbquery();
-		$db->connect();
-		
-		self::$usergroups_table = $_SESSION['tablename']['usergroups'];
-		self::$usergroup_content_table = $_SESSION['tablename']['usergroup_content'];
-		self::$groupbasket_table = $_SESSION['tablename']['bask_groupbasket'];
-		self::$groups_services_table = $_SESSION['tablename']['usergroup_services'];
-		
-		self::$db=$db;
-	}	
-	
-	/**
-	* Close the database connexion
-	*/
-	public function disconnect()
-	{
-		self::$db->disconnect();
-	}	
-	
-	/**
-	* Returns an Usergroup Object based on a usegroup identifier
+	* Returns an usergroups object based on a usegroup identifier
 	*
 	* @param  $group_id string  Usergroup identifier
 	* @param  $can_be_disabled bool  if true gets the group even if it is disabled in the database (false by default)
-	* @return Usergroup object with properties from the database or null
+	* @return usergroups object with properties from the database or null
 	*/
 	public function get($group_id, $can_be_disabled = false)
 	{	
-		// If no group_id specified return null
-		if(empty($group_id))
-			return null;
-		
-		self::connect();
-		$query = "select * from ".self::$usergroups_table." where group_id = '".$group_id."' ";
-		
-		if(!$can_be_disabled)
-			$query .= " and enabled = 'Y'";
-
-		try{
-			if($_ENV['DEBUG'])
-				echo $query.' // ';
-			self::$db->query($query);
-		} catch (Exception $e){
-			echo _NO_GROUP_WITH_ID.' '.$group_id.' // ';
-		}
-		
-		if(self::$db->nb_result() > 0)
-		{
-			$group=new Usergroup();
-			$queryResult=self::$db->fetch_object();
-			foreach($queryResult as $key => $value){
-				$group->$key=$value;
-			}
-			self::disconnect();
-			return $group;
-		}
-		else
-		{
-			self::disconnect();
-			return null;
-		}
+		self::set_foolish_ids(array('group_id'));
+		self::set_specific_id('group_id');
+		return self::advanced_get($group_id,USERGROUPS_TABLE);	
 	}
 	
 	/**
-	* Returns all usergroups (enabled by default) from the database in an array of Usergroup Objects (ordered by group_desc by default)
+	* Returns all usergroups (enabled by default) from the database in an array of usergroups objects (ordered by group_desc by default)
 	*
 	* @param  $order_str string  Order string passed to the query ("order by group_desc asc" by default)
 	* @param  $enabled_only bool  if true returns only the enabled usergroups, otherwise returns even the disabled (true by default)
-	* @return Array of Usergroup objects with properties from the database
+	* @return Array of usergroups objects with properties from the database
 	*/
 	public function getAllUsergroups($order_str = "order by group_desc asc", $enabled_only = true)
 	{
-		self::connect();
-		$query = "select * from ".self::$usergroups_table." ";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select * from ".USERGROUPS_TABLE." ";
 		if($enabled_only)
 			$query .= "where enabled = 'Y'";
 		
@@ -177,12 +104,12 @@ class UsergroupControler
 		$groups = array();
 		while($res = self::$db->fetch_object())
 		{
-			$group=new Usergroup();
+			$group=new usergroups();
 			$tmp_array = array('group_id' => $res->group_id, 'group_desc' => $res->group_desc, 'enabled' => $res->enabled);
 			$group->setArray($tmp_array);
 			array_push($groups, $group);
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $groups;
 	}
 	
@@ -198,8 +125,9 @@ class UsergroupControler
 			return null;
 
 		$users = array();
-		self::connect();
-		$query = "select user_id from ".self::$usergroup_content_table." where group_id = '".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select user_id from ".USERGROUP_CONTENT_TABLE." where group_id = '".$group_id."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 					self::$db->query($query);
@@ -211,7 +139,7 @@ class UsergroupControler
 		{
 			array_push($users, $res->user_id);
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $users;
 	}
 	
@@ -227,8 +155,9 @@ class UsergroupControler
 			return null;
 
 		$users = array();
-		self::connect();
-		$query = "select group_id from ".self::$usergroup_content_table." where user_id = '".$user_id."' and primary_group = 'Y'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select group_id from ".USERGROUP_CONTENT_TABLE." where user_id = '".$user_id."' and primary_group = 'Y'";
 
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
@@ -239,7 +168,7 @@ class UsergroupControler
 		
 		$res = self::$db->fetch_object();
 		$group_id = $res->group_id;
-		self::disconnect();
+		self::$db->disconnect();
 		return $group_id;
 	}
 	
@@ -255,8 +184,9 @@ class UsergroupControler
 			return null;
 		
 		$baskets = array();
-		self::connect();
-		$query = "select basket_id from ".self::$groupbasket_table." where group_id = '".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select basket_id from ".GROUPBASKET_TABLE." where group_id = '".$group_id."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 					self::$db->query($query);
@@ -268,7 +198,7 @@ class UsergroupControler
 		{
 			array_push($baskets, $res->basket_id);
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $baskets;
 	}
 	
@@ -283,8 +213,9 @@ class UsergroupControler
 		if(empty($group_id))
 			return null;
 
-		self::connect();
-		$query = "select service_id from ".self::$groups_services_table." where group_id = '".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select service_id from ".USERGROUPS_SERVICES_TABLE." where group_id = '".$group_id."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 			self::$db->query($query);
@@ -297,119 +228,75 @@ class UsergroupControler
 		{
 			array_push($services,trim($queryResult->service_id));
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $services;
 	}
 	
 	/**
-	* Saves in the database a Usergroup object 
+	* Saves in the database a usergroups object 
 	*
-	* @param  $group Usergroup object to be saved
+	* @param  $group usergroups object to be saved
 	* @param  $mode string  Saving mode : add or up
 	* @return bool true if the save is complete, false otherwise
 	*/
-	public function save($group, $mode)
+	public function save($group)
 	{
 		if(!isset($group) )
 			return false;
-			
-		if($mode == "up")
+		
+		self::set_foolish_ids(array('group_id'));
+		self::set_specific_id('group_id');
+		if(self::groupExists($group->group_id))
 			return self::update($group);
-		elseif($mode =="add") 
+		else
 			return self::insert($group);
 		
 		return false;
 	}
 	
 	/**
-	* Inserts in the database (usergroups table) a Usergroup object
+	* Inserts in the database (usergroups table) a usergroups object
 	*
-	* @param  $group Usergroup object
+	* @param  $group usergroups object
 	* @return bool true if the insertion is complete, false otherwise
 	*/
 	private function insert($group)
 	{
-		if(!isset($group) )
-			return false;
-			
-		self::connect();
-		$prep_query = self::insert_prepare($group);
-		
-		// Inserting object
-		$query="insert into ".self::$usergroups_table." ("
-					.$prep_query['COLUMNS']
-					.") values("
-					.$prep_query['VALUES']
-					.")";
-		try{
-			if($_ENV['DEBUG']){ echo $query.' // '; }
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_INSERT_GROUP." ".$group->toString().' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		return self::advanced_insert($group);
 	}
 
 	/**
-	* Updates a usergroup in the database (usergroups table) with a Usergroup object
+	* Updates a usergroup in the database (usergroups table) with a usergroups object
 	*
-	* @param  $group Usergroup object
+	* @param  $group usergroups object
 	* @return bool true if the update is complete, false otherwise
 	*/
 	private function update($group)
 	{
-		if(!isset($group) )
-			return false;
-
-		self::connect();
-		$query="update ".self::$usergroups_table." set "
-					.self::update_prepare($group)
-					." where group_id='".$group->group_id."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_UPDATE_GROUP." ".$group->toString().' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		return self::advanced_update($group);
 	}
 	
 	/**
 	* Deletes in the database (usergroups related tables) a given usergroup (group_id)
 	*
-	* @param  $group_id string  Usergroup identifier
+	* @param  $group usergroups object
 	* @return bool true if the deletion is complete, false otherwise
 	*/
-	public function delete($group_id)
+	public function delete($group)
 	{
-		if(!isset($group_id)|| empty($group_id) )
-			return false;
-		if(! self::groupExists($group_id))
-			return false;
-			
-		self::connect();
-		$query="delete from ".self::$usergroups_table." where group_id='".$group_id."'";
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_DELETE_GROUP_ID." ".$group_id.' // ';
-			$ok = false;
-		}
-		self::disconnect();
+		self::set_foolish_ids(array('group_id'));
+		self::set_specific_id('group_id');
+		
+		$group_id = $group->__get('group_id');
+		$ok = self::advanced_delete($group);
 		if($ok)
 			$ok = self::cleanUsergroupContent($group_id);
 
 		if($ok)
 			$ok = self::deleteServicesForGroup($group_id);
+		
+		if($ok)
+			$ok = SecurityControler::deleteForGroup($group_id);
 
 		return $ok;
 	}
@@ -425,8 +312,9 @@ class UsergroupControler
 		if(!isset($group_id)|| empty($group_id) )
 			return false;
 		
-		self::connect();
-		$query="delete from ".self::$usergroup_content_table." where group_id='".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query="delete from ".USERGROUP_CONTENT_TABLE." where group_id='".$group_id."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 			self::$db->query($query);
@@ -439,103 +327,31 @@ class UsergroupControler
 		return $ok;
 	}
 	
-	/**
-	* Prepares the update query for a given Usergroup object
-	*
-	* @param  $group Usergroup object
-	* @return String containing the fields and the values 
-	*/
-	private function update_prepare($group)
-	{	
-		$result=array();
-		foreach($group->getArray() as $key => $value)
-		{
-			// For now all fields in the usergroups table are strings
-			if(!empty($value))
-			{
-				$result[]=$key."='".$value."'";
-			}
-		}
-
-		return implode(",",$result);
-	} 
-	
-	/**
-	* Prepares the insert query for a given Usergroup object
-	*
-	* @param  $group Usergroup object
-	* @return Array containing the fields and the values 
-	*/
-	private function insert_prepare($group)
-	{
-		$columns=array();
-		$values=array();
-		foreach($group->getArray() as $key => $value)
-		{
-			// For now all fields in the usergroups table are strings
-			if(!empty($value))
-			{
-				$columns[]=$key;
-				$values[]="'".$value."'";
-			}
-		}
-		return array('COLUMNS' => implode(",",$columns), 'VALUES' => implode(",",$values));
-	}
 	
 	/**
 	* Disables a given usergroup
 	* 
-	* @param  $group_id String Usergroup identifier
+	* @param  $group usergroups object
 	* @return bool true if the disabling is complete, false otherwise 
 	*/
-	public function disable($group_id)
+	public function disable($group)
 	{
-		if(!isset($group_id)|| empty($group_id) )
-			return false;
-		if(! self::groupExists($group_id))
-			return false;
-			
-		self::connect();
-		$query="update ".self::$usergroups_table." set enabled = 'N' where group_id='".$group_id."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_DISABLE_GROUP." ".$group_id.' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		self::set_foolish_ids(array('group_id'));
+		self::set_specific_id('group_id');
+		return self::advanced_disable($group);
 	}
 	
 	/**
 	* Enables a given usergroup
 	* 
-	* @param  $group_id String Usergroup identifier
+	* @param  $group usergroups object
 	* @return bool true if the enabling is complete, false otherwise 
 	*/
-	public function enable($group_id)
+	public function enable($group)
 	{
-		if(!isset($group_id)|| empty($group_id) )
-			return false;
-		if(! self::groupExists($group_id))
-			return false;
-			
-		self::connect();
-		$query="update ".self::$usergroups_table." set enabled = 'Y' where group_id='".$group_id."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_ENABLE_GROUP." ".$group_id.' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		self::set_foolish_ids(array('group_id'));
+		self::set_specific_id('group_id');
+		return self::advanced_enable($group);
 	}
 	
 	/**
@@ -549,8 +365,9 @@ class UsergroupControler
 		if(!isset($group_id) || empty($group_id))
 			return false;
 
-		self::connect();
-		$query = "select group_id from ".self::$usergroups_table." where group_id = '".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select group_id from ".USERGROUPS_TABLE." where group_id = '".$group_id."'";
 					
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
@@ -561,10 +378,10 @@ class UsergroupControler
 		
 		if(self::$db->nb_result() > 0)
 		{
-			self::disconnect();
+			self::$db->disconnect();
 			return true;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return false;
 	}
 	
@@ -578,8 +395,9 @@ class UsergroupControler
 	{
 		if(!isset($group_id)|| empty($group_id) )
 			return false;
-		self::connect();
-		$query="delete from ".self::$groups_services_table." where group_id='".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query="delete from ".USERGROUPS_SERVICES_TABLE." where group_id='".$group_id."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 			self::$db->query($query);
@@ -588,7 +406,7 @@ class UsergroupControler
 			echo _CANNOT_DELETE_GROUP_ID." ".$group_id.' // ';
 			$ok = false;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $ok;
 	}
 	
@@ -604,8 +422,9 @@ class UsergroupControler
 		if(!isset($group_id)|| empty($group_id) || !isset($service_id)|| empty($service_id) )
 			return false;
 			
-		self::connect();
-		$query = "insert into ".self::$groups_services_table." (group_id, service_id) values ('".$group_id."', '".$service_id."')";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "insert into ".USERGROUPS_SERVICES_TABLE." (group_id, service_id) values ('".$group_id."', '".$service_id."')";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 			self::$db->query($query);
@@ -614,7 +433,7 @@ class UsergroupControler
 			echo _CANNOT_INSERT." ".$group_id.' '.$service_id.' // ';
 			$ok = false;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $ok;
 	}
 	
@@ -630,8 +449,9 @@ class UsergroupControler
 		if(!isset($group_id)|| empty($group_id) || !isset($user_id)|| empty($user_id) )
 			return false;
 			
-		self::connect();
-		$query = "select user_id from ".self::$usergroup_content_table." where user_id ='".$user_id."' and group_id = '".$group_id."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select user_id from ".USERGROUP_CONTENT_TABLE." where user_id ='".$user_id."' and group_id = '".$group_id."'";
 
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
@@ -639,7 +459,7 @@ class UsergroupControler
 		} catch (Exception $e){
 			echo _CANNOT_FIND." ".$group_id.' '.$user_id.' // ';
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		
 		if(self::$db->nb_result() > 0)
 			return true;
@@ -656,9 +476,10 @@ class UsergroupControler
 	public function getUsergroupsCount($enabled_only = true)
 	{
 		$nb = 0;
-		self::connect();
+		self::$db=new dbquery();
+		self::$db->connect();
 		
-		$query = "select group_id from ".self::$usergroups_table." " ;
+		$query = "select group_id from ".USERGROUPS_TABLE." " ;
 		if($enabled_only)
 			$query .= "where enabled ='Y'";
 		
@@ -668,7 +489,7 @@ class UsergroupControler
 		} catch (Exception $e){}
 		
 		$nb = self::$db->nb_result();			
-		self::disconnect();
+		self::$db->disconnect();
 		return $nb;
 	}
 }
diff --git a/core/trunk/core/class/User.php b/core/trunk/core/class/users.php
similarity index 97%
rename from core/trunk/core/class/User.php
rename to core/trunk/core/class/users.php
index 8d2dda7d702d6930bbed90fef44f8c3543b161f5..030a6b34bc33cf9492d44d04c69e043cec215b4a 100644
--- a/core/trunk/core/class/User.php
+++ b/core/trunk/core/class/users.php
@@ -41,7 +41,7 @@ try {
 *
 * @ingroup core
 */
-class User extends BaseObject
+class users extends BaseObject
  {	
 	
 	/**
diff --git a/core/trunk/core/class/UserControler.php b/core/trunk/core/class/users_controler.php
similarity index 51%
rename from core/trunk/core/class/UserControler.php
rename to core/trunk/core/class/users_controler.php
index 5c583ae106638f6c5e9cdce5cb414f982e229ed1..ef882d42f63499044988026992cd818849ec92d2 100644
--- a/core/trunk/core/class/UserControler.php
+++ b/core/trunk/core/class/users_controler.php
@@ -38,8 +38,10 @@ define("_CODE_INCREMENT",1);
 
 // Loads the required class
 try {
-	require_once("core/class/class_db.php");
-	require_once("core/class/User.php");
+	require_once("core/core_tables.php");
+	require_once("core/class/users.php");
+	require_once("core/class/ObjectControlerAbstract.php");
+	require_once("core/class/ObjectControlerIF.php");
 } catch (Exception $e){
 	echo $e->getMessage().' // ';
 }
@@ -54,44 +56,8 @@ try {
 *</ul>
 * @ingroup core
 */
-class UserControler
+class users_controler extends ObjectControler implements ObjectControlerIF
 {
-	/**
-	* Dbquery object used to connnect to the database
-    */
-	private static $db;
-	
-	/**
-	* Users table
-    */
-	public static $users_table ;
-	
-	/**
-	* Usergroup_content table
-    */
-	public static $usergroup_content_table ;
-	
-	/**
-	* Opens a database connexion and values the tables variables
-	*/
-	public function connect()
-	{
-		$db = new dbquery();
-		$db->connect();
-		self::$users_table = $_SESSION['tablename']['users'];
-		self::$usergroup_content_table = $_SESSION['tablename']['usergroup_content'];
-		
-		self::$db=$db;
-	}	
-	
-	/**
-	* Close the database connexion
-	*/
-	public function disconnect()
-	{
-		self::$db->disconnect();
-	}	
-	
 	/**
 	* Returns an User Object based on a user identifier
 	*
@@ -102,37 +68,13 @@ class UserControler
 	*/
 	public function get($user_id, $comp_where = '', $can_be_disabled = false)
 	{
-		if(empty($user_id))
-			return null;
-
-		self::connect();
-		$query = "select * from ".self::$users_table." where user_id = '".functions::protect_string_db($user_id)."'";
-		if(!$can_be_disabled)
-			$query .= " and enabled = 'Y'";
-		$query .= $comp_where;
-		
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-		} catch (Exception $e){
-			echo _NO_USER_WITH_ID.' '.$user_id.' // ';
-		}
-		
-		if(self::$db->nb_result() > 0)
-		{
-			$user = new User();
-			$queryResult=self::$db->fetch_object();  // TO DO : rajouter les entités
-			foreach($queryResult as $key => $value){
-				$user->$key=$value;
-			}
-			self::disconnect();
+		self::set_foolish_ids(array('user_id'));
+		self::set_specific_id('user_id');
+		$user = self::advanced_get($user_id,USERS_TABLE);	
+		if($user->__get('status') == 'OK')
 			return $user;
-		}
 		else
-		{
-			self::disconnect();
 			return null;
-		}
 	}
 	
 	/**
@@ -147,8 +89,9 @@ class UserControler
 		if(empty($user_id))
 			return null;
 
-		self::connect();
-		$query = "select group_id, primary_group, role from ".self::$usergroup_content_table." where user_id = '".functions::protect_string_db($user_id)."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select group_id, primary_group, role from ".USERGROUP_CONTENT_TABLE." where user_id = '".functions::protect_string_db($user_id)."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 					self::$db->query($query);
@@ -160,7 +103,7 @@ class UserControler
 		{
 			array_push($groups, array('USER_ID' => $user_id, 'GROUP_ID' => $res->group_id, 'PRIMARY' => $res->primary_group, 'ROLE' => $res->role));
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $groups;
 	}
 	
@@ -171,14 +114,16 @@ class UserControler
 	* @param  $mode string  Saving mode : add or up
 	* @return bool true if the save is complete, false otherwise
 	*/
-	public function save($user, $mode)
+	public function save($user)
 	{
 		if(!isset($user) )
 			return false;
-			
-		if($mode == "up")
+		
+		self::set_foolish_ids(array('user_id'));
+		self::set_specific_id('user_id');
+		if(self::userExists($user->user_id))
 			return self::update($user);
-		elseif($mode =="add") 
+		else
 			return self::insert($user);
 		
 		return false;
@@ -192,27 +137,7 @@ class UserControler
 	*/
 	private function insert($user)
 	{
-		if(!isset($user) )
-			return false;
-			
-		self::connect();
-		$prep_query = self::insert_prepare($user);
-
-		$query="insert into ".self::$users_table." ("
-					.$prep_query['COLUMNS']
-					.") values("
-					.$prep_query['VALUES']
-					.")";
-		try{
-			if($_ENV['DEBUG']){ echo $query.' // '; }
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_INSERT_USER." ".$user->toString().' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		return self::advanced_insert($user);
 	}
 
 	/**
@@ -223,24 +148,7 @@ class UserControler
 	*/
 	private function update($user)
 	{
-		if(!isset($user) )
-			return false;
-			
-		self::connect();
-		$query="update ".self::$users_table." set "
-					.self::update_prepare($user)
-					." where user_id='".functions::protect_string_db($user->user_id)."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_UPDATE_USER." ".$user->toString().' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		return self::advanced_update($user);
 	}
 	
 	/**
@@ -253,11 +161,13 @@ class UserControler
 	{
 		if(!isset($user_id)|| empty($user_id) )
 			return false;
+		
 		if(! self::userExists($user_id))
 			return false;
 			
-		self::connect();
-		$query="update ".self::$users_table." set status = 'DEL' where user_id='".functions::protect_string_db($user_id)."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query="update ".USERS_TABLE." set status = 'DEL' where user_id='".functions::protect_string_db($user_id)."'";
 		// Logic deletion only , status becomes DEL to keep the user data
 		
 		try{
@@ -268,7 +178,7 @@ class UserControler
 			echo _CANNOT_DELETE_USER_ID." ".$user_id.' // ';
 			$ok = false;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		if($ok)
 			$ok = self::cleanUsergroupContent($user_id);
 		
@@ -286,8 +196,9 @@ class UserControler
 		if(!isset($user_id)|| empty($user_id) )
 			return false;
 		
-		self::connect();
-		$query="delete from ".self::$usergroup_content_table."  where user_id='".functions::protect_string_db($user_id)."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query="delete from ".USERGROUP_CONTENT_TABLE."  where user_id='".functions::protect_string_db($user_id)."'";
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
 			self::$db->query($query);
@@ -297,7 +208,7 @@ class UserControler
 			$ok = false;
 		}
 		
-		self::disconnect();
+		self::$db->disconnect();
 		return $ok;
 	}
 	
@@ -312,8 +223,9 @@ class UserControler
 		if(!isset($user_id) || empty($user_id))
 			return false;
 
-		self::connect();
-		$query = "select user_id from ".self::$users_table." where user_id = '".functions::protect_string_db($user_id)."'";
+		self::$db=new dbquery();
+		self::$db->connect();
+		$query = "select user_id from ".USERS_TABLE." where user_id = '".functions::protect_string_db($user_id)."'";
 					
 		try{
 			if($_ENV['DEBUG']){echo $query.' // ';}
@@ -324,112 +236,41 @@ class UserControler
 		
 		if(self::$db->nb_result() > 0)
 		{
-			self::disconnect();
+			self::$db->disconnect();
 			return true;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return false;
 	}
 	
-	/**
-	* Prepares the update query for a given User object
-	*
-	* @param  $user User object
-	* @return String containing the fields and the values 
-	*/
-	private function update_prepare($user)
-	{
-		$result=array();
-		foreach($user->getArray() as $key => $value)
-		{
-			// For now all fields in the users table are strings or dates
-			if(!empty($value))
-			{
-				$result[]=$key."='".functions::protect_string_db($value)."'";		
-			}
-		}
-		// Return created string minus last ", "
-		return implode(",",$result);
-	} 
-	
-	/**
-	* Prepares the insert query for a given User object
-	*
-	* @param  $user User object
-	* @return Array containing the fields and the values 
-	*/
-	private function insert_prepare($user)
-	{
-		$columns=array();
-		$values=array();
-		foreach($user->getArray() as $key => $value)
-		{
-			//For now all fields in the users table are strings or dates
-			if(!empty($value))
-			{
-				$columns[]=$key;
-				$values[]="'".functions::protect_string_db($value)."'";
-			}
-		}
-		return array('COLUMNS' => implode(",",$columns), 'VALUES' => implode(",",$values));
-	}
-	
+
 	/**
 	* Disables a given user
 	* 
-	* @param  $user_id String User identifier
+	* @param  $user Object User Object 
 	* @return bool true if the disabling is complete, false otherwise 
 	*/
-	public function disable($user_id)
+	public function disable($user)
 	{
-		if(!isset($user_id)|| empty($user_id) )
-			return false;
-		if(! self::userExists($user_id))
-			return false;
-			
-		self::connect();
-		$query="update ".self::$users_table." set enabled = 'N' where user_id='".functions::protect_string_db($user_id)."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_DISABLE_USER." ".$user_id.' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		self::set_foolish_ids(array('user_id'));
+		self::set_specific_id('user_id');
+		return self::advanced_disable($user);
 	}
 	
 	/**
 	* Enables a given user
 	* 
-	* @param  $user_id String User identifier
+	* @param  $user bject User Object 
 	* @return bool true if the enabling is complete, false otherwise 
 	*/
-	public function enable($user_id)
+	public function enable($user)
 	{
-		if(!isset($user_id)|| empty($user_id) )
-			return false;
-		if(! self::userExists($user_id))
-			return false;
-		
-		self::connect();
-		$query="update ".self::$users_table." set enabled = 'Y' where user_id='".functions::protect_string_db($user_id)."'"; 
-					
-		try{
-			if($_ENV['DEBUG']){echo $query.' // ';}
-			self::$db->query($query);
-			$ok = true;
-		} catch (Exception $e){
-			echo _CANNOT_ENABLE_USER." ".$user_id.' // ';
-			$ok = false;
-		}
-		self::disconnect();
-		return $ok;
+		self::set_foolish_ids(array('user_id'));
+		self::set_specific_id('user_id');
+		return self::advanced_enable($user);
 	}
 	
+	
 	/**
 	* Loads into the usergroup_content table the given data for a given user
 	* 
@@ -444,13 +285,14 @@ class UserControler
 		if(!isset($array) || count($array) == 0)
 			return false;
 			
-		self::connect();
+		self::$db=new dbquery();
+		self::$db->connect();
 		$ok = true;
 		for($i=0; $i < count($array ); $i++)
 		{
 			if($ok) 
 			{
-				$query = "INSERT INTO ".self::$usergroup_content_table." (user_id, group_id, primary_group, role) VALUES ('".functions::protect_string_db($user_id)."', '".functions::protect_string_db($array[$i]['GROUP_ID'])."', '".functions::protect_string_db($array[$i]['PRIMARY'])."', '".functions::protect_string_db($array[0]['ROLE'])."')";
+				$query = "INSERT INTO ".USERGROUP_CONTENT_TABLE." (user_id, group_id, primary_group, role) VALUES ('".functions::protect_string_db($user_id)."', '".functions::protect_string_db($array[$i]['GROUP_ID'])."', '".functions::protect_string_db($array[$i]['PRIMARY'])."', '".functions::protect_string_db($array[0]['ROLE'])."')";
 				try{
 					if($_ENV['DEBUG']){echo $query.' // ';}
 					self::$db->query($query);
@@ -462,7 +304,7 @@ class UserControler
 			else
 				break;
 		}
-		self::disconnect();
+		self::$db->disconnect();
 		return $ok;		
 	}
 }
diff --git a/core/trunk/core/sql/structure/core.mssql.sql b/core/trunk/core/sql/structure/core.mssql.sql
index 34fd85618da159e127f7b0f9aeecc1fa9925f840..f0b8067676eac4f042f47ee27d2c6d46a9ad3ce9 100644
Binary files a/core/trunk/core/sql/structure/core.mssql.sql and b/core/trunk/core/sql/structure/core.mssql.sql differ
diff --git a/core/trunk/core/sql/structure/core.mysql.sql b/core/trunk/core/sql/structure/core.mysql.sql
index 1fdf7ea058f2ab5a71f693a133b3aaea80769d9b..b04b14479f917d805ed544a789f3815d28037b9f 100644
--- a/core/trunk/core/sql/structure/core.mysql.sql
+++ b/core/trunk/core/sql/structure/core.mysql.sql
@@ -208,7 +208,7 @@ CREATE TABLE IF NOT EXISTS users (
   cookie_date datetime default NULL,
   enabled char(1) collate utf8_unicode_ci NOT NULL default 'Y',
   change_password char(1) collate utf8_unicode_ci NOT NULL default 'Y',
-  delay datetime default NULL,
+  delay_number int(8) default NULL,
   status varchar(10) NOT NULL DEFAULT 'OK',
   loginmode varying(50) collate utf8_unicode_ci default NULL,
   PRIMARY KEY  (user_id)
diff --git a/core/trunk/core/sql/structure/core.oracle.sql b/core/trunk/core/sql/structure/core.oracle.sql
index a126106127066a64045e8b755961ebd1f113edc1..e3902e81e6be5302413c73061aae5a2a7f0b8180 100644
--- a/core/trunk/core/sql/structure/core.oracle.sql
+++ b/core/trunk/core/sql/structure/core.oracle.sql
@@ -245,7 +245,7 @@
    ) ;
 
 --------------------------------------------------------
---  DDL for Table USERS
+--  DDL for Table USER
 --------------------------------------------------------
 
   CREATE TABLE "USERS"
@@ -263,7 +263,7 @@
 	"COOKIE_DATE" DATE DEFAULT sysdate,
 	"ENABLED" VARCHAR2(1) DEFAULT 'Y',
 	"CHANGE_PASSWORD" VARCHAR2(1) DEFAULT 'Y',
-	"DELAY" DATE DEFAULT sysdate,
+	"DELAY_NUMBER" NUMBER DEFAULT NULL,
 	"STATUS" VARCHAR2(10) DEFAULT 'OK',
 	"LOGINMODE" VARCHAR2(50) DEFAULT NULL,
 	
diff --git a/core/trunk/core/sql/structure/core.postgresql.sql b/core/trunk/core/sql/structure/core.postgresql.sql
index 56c29d590b9917f9752ba19ceca23b0967f308ea..a8378e009839609d36e4bc9b752efd904ca6a188 100644
--- a/core/trunk/core/sql/structure/core.postgresql.sql
+++ b/core/trunk/core/sql/structure/core.postgresql.sql
@@ -292,10 +292,10 @@ CREATE TABLE users
   cookie_date timestamp without time zone,
   enabled character(1) NOT NULL DEFAULT 'Y'::bpchar,
   change_password character(1) NOT NULL DEFAULT 'Y'::bpchar,
-  delay timestamp without time zone,
+  delay_number integer DEFAULT NULL,
   status character varying(10) NOT NULL DEFAULT 'OK'::character varying,
   loginmode character varying(50) DEFAULT NULL::character varying,
   CONSTRAINT users_pkey PRIMARY KEY (user_id)
 )
 WITH (OIDS=FALSE);
-ALTER TABLE users OWNER TO postgres;
+ALTER TABLE user OWNER TO postgres;