Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php	(revision 516)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_class.php	(revision 518)
@@ -158,59 +158,94 @@
  		global $xoops_db;
 		
-		// table sync
 		$table = get_wp_prefix() . 'group_role';
-		$xoops_group = get_xoops_prefix() . 'groups';
-		$xoops_group_permission = get_xoops_prefix() . 'group_permission';
+		
+		$sql=  "SELECT * FROM $table";
+		$this->groupe_role =  $xoops_db->get_results($sql);
+	}
+
+	function GroupeRoleCheck() {
+ 		global $xoops_db;
 		
 		$module_id = get_xpress_modid();
 		
-		$sql=  "SELECT * FROM $table";
-		$before_groupes = $xoops_db->get_results($sql);
-		
-		$sql = "DELETE FROM $table";
-		$xoops_db->query($sql);
-		
-		$sql =  "SELECT *  FROM $xoops_group_permission WHERE gperm_itemid = $module_id";
+		$group_role_table = get_wp_prefix() . 'group_role';
+		$xoops_group_table = get_xoops_prefix() . 'groups';
+		$xoops_group_permission_table = get_xoops_prefix() . 'group_permission';
+		
+
+		
+		$sql =  "SELECT *  FROM $xoops_group_permission_table WHERE gperm_itemid = $module_id";
 		$gperms = $xoops_db->get_results($sql);
 		
-		$sql =  "SELECT * FROM $xoops_group WHERE group_type <> 'Anonymous'";
+		$sql =  "SELECT * FROM $xoops_group_table WHERE group_type <> 'Anonymous'";
 		$groupes = $xoops_db->get_results($sql);
-		$insert_sql = '';
+
+		// list of groups registered with XOOPS
+		$xoops_groupid_list = '';
 		foreach ($groupes as $groupe) {
-			$parmsql =  "SELECT *  FROM $xoops_group_permission WHERE gperm_itemid = $module_id AND gperm_groupid = $groupe->groupid";
-			$gperms = $xoops_db->get_results($parmsql);
-			$parmission = '';
+			if (!empty($xoops_groupid_list)) $xoops_groupid_list .= ',';
+			$xoops_groupid_list .= $groupe->groupid;
+		}
+		
+		// delete the group deleted by the XOOPS group from a group role database
+		if (!empty($xoops_groupid_list)){
+			$del_sql = "DELETE FROM $group_role_table WHERE groupid NOT IN ($xoops_groupid_list)";
+			$xoops_db->query($del_sql);
+		}
+		
+		$sql =  "SELECT *  FROM $group_role_table";
+		$groupes_role = $xoops_db->get_results($sql);
+		
+		foreach ($groupes as $groupe) {
+			//get group parmission
+			$group_type = '';
 			foreach ($gperms as $gperm) {
+				if ($gperm->gperm_groupid == $groupe->groupid){
+					$group_type = $gperm->gperm_name;
+					if ($group_type == 'module_admin') break;
+				}
+			}
+			if (empty($group_type)) $group_type = 'module_inhibit';
+			
+			$found = false;
+			foreach ($groupes_role as $groupe_role) {
+				if ($groupe_role->groupid == $groupe->groupid){
+					$role = $groupe_role->role;
+					if ($group_type == 'module_admin') $role = 'administrator';
+					if ($group_type == 'module_inhibit') $role = '';
+					$edit_sql = "UPDATE $group_role_table SET group_type='$group_type',role='$role' WHERE groupid = $groupe->groupid";
+					$found = true;
+					break;
+				}
+			}
+			if(!$found){
+				$role = '';
+				if ($group_type == 'module_admin') $role = 'administrator';
+
+				$edit_sql  = "INSERT INTO  $group_role_table ";
+				$edit_sql .= "(groupid , name , description , group_type , role , login_all) ";
+				$edit_sql .= "VALUES (";
+				$edit_sql .= $groupe->groupid . ', ';
+				$edit_sql .= "'" . $groupe->name . "' , ";
+				$edit_sql .= "'" . $groupe->description . "' , ";
+				$edit_sql .= "'" . $parmission . "' , ";
+				$edit_sql .= "'" . $role . "' , '";
+				$edit_sql .= $login_all . "')";
+			}
+			$xoops_db->query($edit_sql);
+		}
+		$this->GroupeRoleRead();
+	}
+	
+	function get_groupe_perm_for_modules($module_id ,$group_id)
+	{
+		$parmsql =  "SELECT *  FROM $xoops_group_permission WHERE gperm_itemid = $module_id AND gperm_groupid = $group_id";
+		$gperms = $xoops_db->get_results($parmsql);
+		$parmission = '';
+		foreach ($gperms as $gperm) {
 				$parmission = $gperm->gperm_name;
 				if ($parmission == 'module_admin') break;
-			}
-			
-			if (!empty($parmission)){
-				$role = ''; 
-				foreach ($before_groupes as $before_groupe) {
-					if ($groupe->groupid == $before_groupe->groupid) {
-						$role = $before_groupe->role;
-						$login_all = $before_groupe->login_all;
-					}
-				}
-				if ($parmission == 'module_admin') $role = 'administrator';
-				
-				$insert_sql  = "INSERT INTO  $table ";
-				$insert_sql .= "(groupid , name , description , group_type , role , login_all) ";
-				$insert_sql .= "VALUES (";
-				$insert_sql .= $groupe->groupid . ', ';
-				$insert_sql .= "'" . $groupe->name . "' , ";
-				$insert_sql .= "'" . $groupe->description . "' , ";
-				$insert_sql .= "'" . $parmission . "' , ";
-				$insert_sql .= "'" . $role . "' , '";
-				$insert_sql .= $login_all . "')";
-				$xoops_db->query($insert_sql);
-			}
-		}
-		
-		$sql=  "SELECT * FROM $table";
-		
-		$this->groupe_role =  $xoops_db->get_results($sql);
-			$sql=  "SELECT * FROM $table";	
+		}
+		return $parmission;
 	}
 	
@@ -474,4 +509,11 @@
 		$form .= '<tr><td>' . __('XOOPS Groupe', 'xpressme') . '</td><td>' . __('WordPress Role', 'xpressme') . '</td><td>' . __('Role is set at each login', 'xpressme') . "</td></tr>\n";
 		foreach ($this->groupe_role as $groupe) {
+			if ($groupe->group_type == 'module_inhibit'){
+				$form .= "<tr>";
+				$form .= "<td> $groupe->name </td>";
+				$form .= "<td>" .  __('module cannot be read', 'xpressme') . "</td>";
+				$form .= "</tr>\n";	
+				continue;
+			}
 			$form .= "<tr>";
 			$form .= "<td> $groupe->name </td>";
