Index: trunk/wp-content/plugins/xpressme/include/user_sync_xoops.php
===================================================================
--- trunk/wp-content/plugins/xpressme/include/user_sync_xoops.php	(revision 87)
+++ trunk/wp-content/plugins/xpressme/include/user_sync_xoops.php	(revision 95)
@@ -43,10 +43,11 @@
 	$db_groups_users_link = get_xoops_prefix() . 'groups_users_link';
 	$db_group_role = get_wp_prefix() . 'group_role';
+	$db_groups = get_xoops_prefix() . 'groups';
 	
 	$sql  = "SELECT * ";
 	$sql .= "FROM $db_groups_users_link ";
 	$sql .= "LEFT JOIN $db_group_role ON $db_groups_users_link.groupid = $db_group_role.groupid ";
+	$sql .= "LEFT JOIN $db_groups ON $db_groups_users_link.groupid = $db_groups.groupid ";
 	$sql .= "WHERE  uid = $uid";
-
 	$user_groups = $xoops_db->get_results($sql);
 	$ans['capabillities'] = '';
@@ -54,5 +55,11 @@
 	
 	foreach($user_groups as $user_group){
+		if ($user_group->group_type == 'Admin'){
+			$ans['capabillities'] = 'administrator';
+			$ans['allway_update'] = 0;
+			break;
+		}
 		$before_level = get_role_level($ans['capabillities']);
+		
 		$now_level = get_role_level($user_group->role);
 		if ($now_level > $before_level){
@@ -80,99 +87,96 @@
 function user_sync_to_wordpress($sync_uid = 0, &$message){
 	global $xoops_db;
-	global $xoopsModule;
-
-	if( is_object($xoopsModule)) {
-		$db_xoops_users = get_xoops_prefix() . 'users';
-		$db_xpress_users = get_wp_prefix() . 'users';
-
-		$message = 'Do Sync';
-	
-		if ($sync_uid == 0) {
-			$xu_sql  = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users";
+
+	$db_xoops_users = get_xoops_prefix() . 'users';
+	$db_xpress_users = get_wp_prefix() . 'users';
+
+	$message = 'Do Sync';
+
+	if ($sync_uid == 0) {
+		$xu_sql  = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users";
+	} else {
+		$xu_sql  = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users WHERE uid = $sync_uid";
+	}
+
+	$xoops_users = $xoops_db->get_results($xu_sql);
+	if (empty($xoops_users)){
+		$message .= '...ERR ('. $xu_sql . ')';
+		return false;
+	}
+
+	foreach($xoops_users as $xoops_user){
+		$role = get_xoops_group_role($xoops_user->uid);
+		$capabillities_name = $role['capabillities'];
+		$allway_update = $role['allway_update'];
+		if (empty($capabillities_name)){
+				$message .= "...PASS '" . $xoops_user->uname ."'[uid=".$xoops_user->uid ."](not xpress user)";
+			if ($sync_uid != 0){
+				$message .= '...NOT XPRESS USER ' . $xoops_user->uname;
+				return false;
+			}
 		} else {
-			$xu_sql  = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users WHERE uid = $sync_uid";
-		}
-
-		$xoops_users = $xoops_db->get_results($xu_sql);
-		if (empty($xoops_users)){
-			$message .= '...ERR ('. $xu_sql . ')';
-			return false;
-		}
-
-		foreach($xoops_users as $xoops_user){
-			$role = get_xoops_group_role($xoops_user->uid);
-			$capabillities_name = $role['capabillities'];
-			$allway_update = $role['allway_update'];
-			if (empty($capabillities_name)){
-					$message .= "...PASS '" . $xoops_user->uname ."'[uid=".$xoops_user->uid ."](not xpress user)";
-				if ($sync_uid != 0){
-					$message .= '...NOT XPRESS USER ' . $xoops_user->uname;
-					return false;
+			$user_regist_time = date('Y-m-d H:i:s' , $xoops_user->user_regdate);
+			$user_status = 0;
+			$user_display_name =empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ;
+
+			$is_update = false;
+			
+			$wp_user_id = get_wp_user_id($xoops_user->uname) ;
+			if ($wp_user_id){
+				$wu_sql  = 	"UPDATE $db_xpress_users ";
+				$wu_sql .= 	'SET ';
+				$wu_sql .=		"user_pass  = '$xoops_user->pass', ";
+				$wu_sql .=		"user_email = '$xoops_user->email', ";
+				$wu_sql .=		"user_url = '$xoops_user->url', ";
+				$wu_sql .=		"user_nicename = '$xoops_user->uname', ";
+				$wu_sql .=		"user_registered = '$user_regist_time', ";
+				$wu_sql .=		"user_status = 0 ";
+				$wu_sql .=	"WHERE (user_login = '$xoops_user->uname' )";
+
+				$xoops_db->query($wu_sql);
+				if ($allway_update){
+					$sycc_user = new WP_User($wp_user_id);
+					$sycc_user->set_role($capabillities_name);
+					$message .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')';
+
+				} else {
+					$message .= '...UPDATE ' . $user_login_name . '(Level Not Change)';
 				}
-			} else {
-				$user_regist_time = date('Y-m-d H:i:s' , $xoops_user->user_regdate);
-				$user_status = 0;
-				$user_display_name =empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ;
-
-				$is_update = false;
-				
-				$wp_user_id = get_wp_user_id($xoops_user->uname) ;
-				if ($wp_user_id){
-					$wu_sql  = 	"UPDATE $db_xpress_users ";
-					$wu_sql .= 	'SET ';
-					$wu_sql .=		"user_pass  = '$xoops_user->pass', ";
-					$wu_sql .=		"user_email = '$xoops_user->email', ";
-					$wu_sql .=		"user_url = '$xoops_user->url', ";
-					$wu_sql .=		"user_nicename = '$xoops_user->uname', ";
-					$wu_sql .=		"user_registered = '$user_regist_time', ";
-					$wu_sql .=		"user_status = 0 ";
-					$wu_sql .=	"WHERE (user_login = '$xoops_user->uname' )";
-
-					$xoops_db->query($wu_sql);
-					if ($allway_update){
-						$sycc_user = new WP_User($wp_user_id);
-						$sycc_user->set_role($capabillities_name);
-						$message .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')';
-
-					} else {
-						$message .= '...UPDATE ' . $user_login_name . '(Level Not Change)';
-					}
-				}else{
-					$wu_sql  =	"INSERT INTO $db_xpress_users ";
-					$wu_sql .=  	"(user_login , user_pass ,user_email , user_url , user_nicename " ;
-					$wu_sql .=		" , user_registered , user_status , display_name) ";
-					$wu_sql .=	"VALUES ";
-					$wu_sql .=		"('$xoops_user->uname', '$xoops_user->pass', '$xoops_user->email', '$xoops_user->url', '$xoops_user->uname' ";
-					$wu_sql .=		" , '$user_regist_time', $user_status, '$user_display_name')";
-					$xoops_db->query($wu_sql);
+			}else{
+				$wu_sql  =	"INSERT INTO $db_xpress_users ";
+				$wu_sql .=  	"(user_login , user_pass ,user_email , user_url , user_nicename " ;
+				$wu_sql .=		" , user_registered , user_status , display_name) ";
+				$wu_sql .=	"VALUES ";
+				$wu_sql .=		"('$xoops_user->uname', '$xoops_user->pass', '$xoops_user->email', '$xoops_user->url', '$xoops_user->uname' ";
+				$wu_sql .=		" , '$user_regist_time', $user_status, '$user_display_name')";
+				$xoops_db->query($wu_sql);
 //					$wp_user_id = get_wp_user_id($user_login_name) ;					
- 					$wp_user_id = mysql_insert_id();
-					$sycc_user = new WP_User($wp_user_id);
-					$sycc_user->set_role($capabillities_name);						
-					$message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')';
-				}
-				
-				$user_nickname =	empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ;
-				$user_rich_editing = 'true';
-				$user_first_name = 	$xoops_user->uname;
-				$user_last_name = 	'';
-				$user_description = '';
-				$user_jabber = 		'';
-
-				update_usermeta( $wp_user_id,'nickname',$user_nickname);
-				update_usermeta( $wp_user_id,'first_name',$user_first_name);
-				update_usermeta( $wp_user_id,'last_name',$user_last_name);
-				update_usermeta( $wp_user_id,'description',$user_description);
-				update_usermeta( $wp_user_id,'jabber',$user_jabber);
-				update_usermeta( $wp_user_id,'aim',$xoops_user->user_aim);
-				update_usermeta( $wp_user_id,'yim',$xoops_user->user_yim);
-				if ($is_update === false ) {
-					update_usermeta( $wp_user_id,'rich_editing',$user_rich_editing);
-				}			
-			}
-		}
-		$message .= "...END";
-		return true;
-	}
+				$wp_user_id = mysql_insert_id();
+				$sycc_user = new WP_User($wp_user_id);
+				$sycc_user->set_role($capabillities_name);						
+				$message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')';
+			}
+			
+			$user_nickname =	empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ;
+			$user_rich_editing = 'true';
+			$user_first_name = 	$xoops_user->uname;
+			$user_last_name = 	'';
+			$user_description = '';
+			$user_jabber = 		'';
+
+			update_usermeta( $wp_user_id,'nickname',$user_nickname);
+			update_usermeta( $wp_user_id,'first_name',$user_first_name);
+			update_usermeta( $wp_user_id,'last_name',$user_last_name);
+			update_usermeta( $wp_user_id,'description',$user_description);
+			update_usermeta( $wp_user_id,'jabber',$user_jabber);
+			update_usermeta( $wp_user_id,'aim',$xoops_user->user_aim);
+			update_usermeta( $wp_user_id,'yim',$xoops_user->user_yim);
+			if ($is_update === false ) {
+				update_usermeta( $wp_user_id,'rich_editing',$user_rich_editing);
+			}			
+		}
+	}
+	$message .= "...END";
+	return true;
 }
 
