[Fusionforge-commits] r12497 - in trunk/src: common/import plugins/projectimport/common plugins/projectimport/www

Olivier Berger olberger at fusionforge.org
Tue Mar 1 21:57:44 CET 2011


Author: olberger
Date: 2011-03-01 21:57:44 +0100 (Tue, 01 Mar 2011)
New Revision: 12497

Modified:
   trunk/src/common/import/import_users.php
   trunk/src/plugins/projectimport/common/ProjectImporter.class.php
   trunk/src/plugins/projectimport/www/index.php
Log:
Now allows addition of imported/mapped users to project with choice of new role

Modified: trunk/src/common/import/import_users.php
===================================================================
--- trunk/src/common/import/import_users.php	2011-03-01 20:57:33 UTC (rev 12496)
+++ trunk/src/common/import/import_users.php	2011-03-01 20:57:44 UTC (rev 12497)
@@ -380,13 +380,15 @@
 
 /**
  * Insert users into the group
- * @param unknown_type $users 'user_name' => {'role': 'role_name' }
+ * @param unknown_type $users 'user_name' => {'role': role_id }
                   ... }
  * @param unknown_type $group_id group to insert users into
  * @param unknown_type $check
  */
 function user_fill($users, $group_id, $check=False){
-
+		global $feedback;
+		global $message;
+	
 	$group =& group_get_object($group_id);
 	if (!$group || !is_object($group)) {
 		exit_error('Error','Could Not Get Group');
@@ -395,14 +397,15 @@
 	}
 
 	foreach ($users as $user => $role){
-		global $feedback;
-		global $message;
 		$user_object = &user_get_object_by_name($user);
 		if (!$user_object) {
 			$feedback .= sprintf(_('Failed to find user %s'), $user);
 		} else {
 			$user_id = $user_object->getID();
-			$role_id = get_role_by_name($role['role'],$group_id);
+			
+			//$role_id = get_role_by_name($role['role'],$group_id);
+			$role_id = $role['role'];
+			
 			if(!$check) {
 				if (!$group->addUser($user,$role_id)) {
 					$feedback = $group->getErrorMessage();

Modified: trunk/src/plugins/projectimport/common/ProjectImporter.class.php
===================================================================
--- trunk/src/plugins/projectimport/common/ProjectImporter.class.php	2011-03-01 20:57:33 UTC (rev 12496)
+++ trunk/src/plugins/projectimport/common/ProjectImporter.class.php	2011-03-01 20:57:44 UTC (rev 12497)
@@ -34,12 +34,103 @@
 define('FORGEPLUCKER_NS', 'http://planetforge.org/ns/forgeplucker_dump/');
 define('PLANETFORGE_NS', 'http://coclico-project.org/ontology/planetforge#');
 
+class ImportedProject {
+	
+	function ImportedProject($res) {
+		$this->res = $res;
+/*		$this->name = $res->getPropValue('doap:name');
+		$this->description = $res->getPropValue('dcterms:description');
+		$this->homepage = $res->getPropValue('doap:homepage');
+		$this->hosted_by = $res->getPropValue('planetforge:hosted_by');
+		*/
+		$this->roles = array();
+		$roles = $res->getPropValues('sioc:scope_of');
+		foreach($roles as $role) {
+			$importer = ProjectImporter::getInstance();
+			$roleres = ProjectImporter::make_resource($role);
+			$role_obj = new ImportedProjectRole($this, $roleres);
+			$this->roles[] = $role_obj;
+		}
+	}
+	
+	/**
+	 * Returns a project's name
+	 */
+	function getName() {
+		return $this->res->getPropValue('doap:name');
+	}
+
+	/**
+	 * Return a project's description
+	 */
+	function getDescription() {
+		return $this->res->getPropValue('dcterms:description');
+	}
+
+	/**
+	 * Return the spaces used by a project
+	 * @param ARC2 resource $projectres
+	 * @return array of ARC2 resources
+	 */
+	function getSpaces() {
+		global $feedback;
+
+		$results = array();
+
+		$importer = ProjectImporter::getInstance();
+		
+		$spaces = $this->res->getPropValues('sioc:has_space');
+		foreach ($spaces as $space) {
+			$spaceres = ProjectImporter::make_resource($space);
+			$provider = $spaceres->getPropValue('planetforge:provided_by');
+			if (! $importer->supportsTool($provider))	{
+				$feedback .= 'error : no supported provider for '. $space .': '. $provider."!\n";
+			}
+			else {
+				$results[$space] = $spaceres;
+			}
+		}
+		return $results;
+	}
+	
+	function getRoles() {
+		return $this->roles;
+	}
+}
+
+class ImportedProjectRole {
+	protected $name;
+	protected $project;
+	protected $users;
+	
+	function ImportedProjectRole(& $project, $res) {
+		$this->project = $project;
+		$this->name = $res->getPropValue('sioc:name');
+		$this->users = $res->getPropValues('sioc:function_of');
+		//print_r('Role: ' .$this->name);
+		//print_r('Users: ');
+		//print_r($this->users);
+	}
+	
+	function getName() {
+		return $this->name;
+	}
+	
+	function getUsers() {
+		return $this->users;
+	}
+}
+
+class ImportedUser {
+	protected $initial_role;
+}
 /**
  * TODO Enter description here ...
  * @author Olivier Berger
  *
  */
 class ProjectImporter {
+	private static $_instance ;
 	
 	/**
 	 * Index of all triples imported
@@ -57,6 +148,8 @@
 	
 	protected $persons;
 	
+	protected $roles;
+	
 	/**
 	 * User names for the users found in the dump
 	 * @var array of strings (keys are URIs)
@@ -100,12 +193,27 @@
 				'sioc' => 'http://rdfs.org/sioc/ns#',
 				'planetforge' => PLANETFORGE_NS
 				);
+				
+	public static function getInstance() {
+		if (!isset(self::$_instance)) {
+			$c = __CLASS__;
+			self::$_instance = new $c;
+		}
+		
+		return self::$_instance;
+	}
+				
 	/**
 	 * TODO Enter description here ...
 	 * @param unknown_type $group_id
 	 */
-	function ProjectImporter($group_id) {
-	  $this->group_id = $group_id;
+	function ProjectImporter($the_group_id = FALSE) {
+		global $group_id;
+		if (! $the_group_id) {
+			$the_group_id = $group_id;
+		}
+		self::$_instance = $this;
+	  $this->group_id = $the_group_id;
 	  $this->index = False;
 	  
 	  
@@ -188,7 +296,9 @@
 	 * @param string $uri
 	 * @return ARC2 resource
 	 */
-	static function make_resource($index, $uri) {
+	static function make_resource($uri) {
+		$importer = ProjectImporter::getInstance();
+		$index = $importer->index;
 	  $conf = array('ns' => ProjectImporter::$ns);
 	  $res = ARC2::getResource($conf);
 	  $res->setIndex($index);
@@ -206,7 +316,7 @@
 
 			$dumpresuri = False;
 			foreach ($this->index as $uri => $resource) {
-				$res = $this->make_resource($this->index, $uri);
+				$res = ProjectImporter::make_resource($uri);
 				if ($res->hasPropValue('rdf:type', 'http://planetforge.org/ns/forgeplucker_dump/project_dump#')) {
 					//	    if ($this->is_project_dump($resource)) {
 					$dumpresuri = $uri;
@@ -216,7 +326,7 @@
 			// found a dump resource
 			if ($dumpresuri) {
 				//	    $dumpres = $this->index[$dumpresuri];Enter description here ...
-				$dumpres = $this->make_resource($this->index, $dumpresuri);
+				$dumpres = ProjectImporter::make_resource($dumpresuri);
 			}
 			$this->project_dump_res = $dumpres;
 		}
@@ -264,11 +374,34 @@
 		$html .= ' account name : '. $username .'<br />';
 		$html .= ' email : '. $email .'<br />';
 		$html .= ' owner : '. $name .'<br />';
+		$html .= ' initial role : '. $role .'<br />';
+		$html .= '<br/>';
+		
+		return $html;
+	}
+	
+	function display_role($role) {
+		$html = '';
+		
+		$username = $this->get_user_name($user);
+		$email = $this->get_user_email($user);
+		
+		$res = $this->users[$user];
+		$person = $res->getPropValue('sioc:account_of');
+		$res = $this->persons[$person];
+		$name = $res->getPropValue('foaf:name');
+		$role = $this->get_user_role($user);
+		
+		$html .= 'User :<br />';
+		$html .= ' account name : '. $username .'<br />';
+		$html .= ' email : '. $email .'<br />';
+		$html .= ' owner : '. $name .'<br />';
 		$html .= ' role : '. $role .'<br />';
 		$html .= '<br/>';
 		
 		return $html;
 	}
+	
 	/**
 	 * Extract users / persons from the dump
 	 * @param unknown_type $dumpres
@@ -285,7 +418,7 @@
 			$users = $dumpres->getPropValues('forgeplucker:users');
 			foreach ($users as $user) {
 				//	      print_r($this->index[$user]);
-				$res = $this->make_resource($this->index, $user);
+				$res = ProjectImporter::make_resource($user);
 				$accountName = $res->getPropValue('foaf:accountName');
 				$this->user_names[$user] = $accountName;
 				$this->users[$user] = $res;
@@ -297,7 +430,7 @@
 			// parse persons and link users to the persons
 			$persons = $dumpres->getPropValues('forgeplucker:persons');
 			foreach ($persons as $person) {
-				$res = $this->make_resource($this->index, $person);
+				$res = ProjectImporter::make_resource($person);
 				 
 				$this->persons[$person] = $res;
 				
@@ -321,24 +454,11 @@
 		}
 		return $this->users;
 	}
-
-	/**
-	 * Returns a project's name
-	 * @param ARC2 resource $projectres
-	 */
-	function get_project_name($projectres) {
-		return $projectres->getPropValue('doap:name');
+	function supportsTool($tool)
+	{
+		return in_array($tool, $this->providers);
 	}
-
 	/**
-	 * Return a project's description
-	 * @param ARC2 resource $projectres
-	 */
-	function get_project_description($projectres) {
-		return $projectres->getPropValue('dcterms:description');
-	}
-
-	/**
 	 * Analyze the tools description found in the dump
 	 */
 	function get_tools() {
@@ -352,11 +472,11 @@
 		//	    print_r($tools);
 		$providers = array();
 		foreach ($tools as $tool) {
-			$toolres = $this->make_resource($this->index, $tool);
+			$toolres = ProjectImporter::make_resource($tool);
 			//	      print_r($toolres->getProps()); echo "\n";
 			$provider = $toolres->getPropValue('planetforge:provided_by');
 			if ($provider) {
-				$providerres = $this->make_resource($this->index, $provider);
+				$providerres = ProjectImporter::make_resource($provider);
 				$types = $providerres->getPropValues('rdf:type');
 				foreach ($types as $type) {
 					if (!in_array($type, ProjectImporter::$allowedprovidertypes)) {
@@ -397,31 +517,30 @@
 		foreach ($projects as $project) {
 			//	      print 'Found project : '. $project . "\n";
 			//	      print_r($this->index[$project]);
-			$res = $this->make_resource($this->index, $project);
+			$res = ProjectImporter::make_resource($project);
 	      
 			//	      print_r($res->getProps());
-			$name = $res->getPropValue('doap:name');
-			$description = $res->getPropValue('dcterms:description');
-			$homepage = $res->getPropValue('doap:homepage');
-			$hosted_by = $res->getPropValue('planetforge:hosted_by');
-			//	      print 'Project: '. $name . ' - '. $description . ' ('. $homepage . ') hosted on: '. $hosted_by;
-//			$results[] = array($name, $description, $homepage, $hosted_by);
-			$results[] = $res;
+			//$name = $res->getPropValue('doap:name');
+			//$description = $res->getPropValue('dcterms:description');
+			//$homepage = $res->getPropValue('doap:homepage');
+			//$hosted_by = $res->getPropValue('planetforge:hosted_by');
+			
+			$project_obj = new ImportedProject($res);
+			
+			$results[] = $project_obj;
+			
 			// handle project's roles
 			$this->user_roles=array();
-			$roles = $res->getPropValues('sioc:scope_of');
-			foreach($roles as $role) {
-				$roleres = $this->make_resource($this->index, $role);
-				$name = $roleres->getPropValue('sioc:name');
-				$users = $roleres->getPropValues('sioc:function_of');
-				//		print_r($name);
-				//print_r($users);
-				foreach($users as $user) {
-					//echo "role : $name for $user ";
-				//	$this->user_roles[$this->user_names[$user]] = array('role' => $name);
+			
+			foreach($project_obj->getRoles() as $role) {
+				
+				$name = $role->getName();
+				foreach($role->getUsers() as $user) {
+					
 					$this->user_roles[$user] = $name;
 				}
 			}
+			//print_r($this->user_roles);
 			//	      print_r($user_roles);
 //			echo "creating roles of existing users in the project\n";
 //			echo "calling user_fill(".'$users'.", $this->group_id)\nwhere ".'$users'." is";
@@ -461,7 +580,7 @@
 				foreach ($artifacts as $artifact) {
 					// Decode ARTIFACTS
 					//			print 'Found tracker artifact :'. $artifact . "\n";
-					$cmres = $this->make_resource($this->index, $artifact);
+					$cmres = ProjectImporter::make_resource($artifact);
 					$tracker['artifacts'][] = array('uri' => $artifact,
 													'details' => $cmres->getProps());
 				}
@@ -477,30 +596,7 @@
 		}
 	}
 
-	/**
-	 * Return the spaces used by a project
-	 * @param ARC2 resource $projectres
-	 * @return array of ARC2 resources
-	 */
-	function project_get_spaces($projectres) {
-		global $feedback;
 
-		$results = array();
-
-		$spaces = $projectres->getPropValues('sioc:has_space');
-		foreach ($spaces as $space) {
-			$spaceres = $this->make_resource($this->index, $space);
-			$provider = $spaceres->getPropValue('planetforge:provided_by');
-			if (!in_array($provider, $this->providers)) {
-				$feedback .= 'error : no supported provider for '. $space .': '. $provider."!\n";
-			}
-			else {
-				$results[$space] = $spaceres;
-			}
-		}
-		return $results;
-	}
-
 }
 // Local Variables:
 // mode: php

Modified: trunk/src/plugins/projectimport/www/index.php
===================================================================
--- trunk/src/plugins/projectimport/www/index.php	2011-03-01 20:57:33 UTC (rev 12496)
+++ trunk/src/plugins/projectimport/www/index.php	2011-03-01 20:57:44 UTC (rev 12497)
@@ -17,6 +17,8 @@
 require_once('../../../www/env.inc.php');
 require_once $gfwww.'include/pre.php';
 
+require_once $gfwww.'include/role_utils.php';
+
 // don't include this in ProjectImporter, for unit test purposes, so do it here, in caller
 require_once $gfcommon.'import/import_users.php';
 //print_r($gfplugins.'projectimport/common/ProjectImporter.class.php');
@@ -44,6 +46,9 @@
 	// will contain mapping of imported users to forge users
 	protected $posted_user_mapping;
 
+	// will contain roles of users added to the project
+	protected $posted_new_member_roles;
+	
 	protected $form_header_already_displayed;
 	
 	protected $html_generator;
@@ -54,6 +59,7 @@
 		$this->form_header_already_displayed = false;
 		$this->importer = False;
 		$this->posted_user_mapping = array();
+		$this->posted_new_member_roles = array();
 		$this->posted_spaces_imported = array();
 	}
 
@@ -100,6 +106,20 @@
 					}
 				}
 			}
+			if (getStringFromPost('submit_new_roles')) {
+				foreach (array_keys($_POST) as $key) {
+					//					print_r('key : '. $key);
+					if(!strncmp($key, 'role_', 5)) {
+						$added_user = substr($key, 5);
+						$new_role = getStringFromPost($key);
+						// print_r('Mapped : '. $imported_user . ' to ' . $mapped_user);
+						//						echo '<br />';
+						if($new_role) {
+							$this->posted_new_member_roles[$added_user] = $new_role;
+						}
+					}
+				}
+			}
 			// Get the spaces checked as to be imported (if any)
 			if (getStringFromPost('submit_spaces')) {
 				foreach (array_keys($_POST) as $key) {
@@ -158,20 +178,65 @@
 	 */
 	function match_users($imported_users, $apply = FALSE)
 	{
-		global $group_id, $feedback;
+		global $group_id, $feedback, $message;
 		
 		$html = '';
 		$html_tbody = '';
 					
 		$needs_to_warn = FALSE;
 		
+		// if mapping has been provided for all imported users
 		$mapping_all_users_provided = TRUE;
 		
-		// displays all imported users with the found matching existing forge user if any
+		// if all mapped users are already in the project
+		$all_mapped_users_in_project = TRUE;
+		
+		// if all new project members roles posted by user
+		$all_new_project_members_roles_set = TRUE;
+		
+		// array of existing forge users and the imported users that have been mapped to it
+		$new_member_map_users = array();
+		
+		/*
+		$role_names = array();
+		$group_object = group_get_object($group_id);
+		$existing_roles = $group_object->getRoles();
+		foreach ($existing_roles as $role) {
+			$name = $role->getName();
+			$role_names[$name] = & $role;
+		}
+		*/
+		
+		// Load users members of the project (may be needed later for display of user mapping selection widgets)
+		$existing_users = array();
+		$active_users = user_get_active_users();
+		foreach($active_users as $user_object) {
+			$username = $user_object->getUnixName();
+			print_r('User : '.$username .'<br />');
+			$role = '';
+			if ($user_object->isMember($group_id)) {
+				print_r('member of project as ');
+				$role = $user_object->getRole($group_id);
+				if ($role) {
+					$role = $role->getName();
+					print_r($role . '<br />');
+				}
+				else {
+					print_r('dunno...<br />');				
+				}
+			}
+			else {
+				print_r('not member of project...<br />');	
+			}
+			$existing_users[] = array( 'name' => $username,
+											 'role' => $role);
+		}
+
+		// displays all imported users, with the found matching existing forge user, if any
 		foreach($imported_users as $user => $userres) {
 			
 			$imported_username = $this->importer->get_user_name($user);
-			$email = $this->importer->get_user_email($user);
+			$imported_email = $this->importer->get_user_email($user);
 			
 			$already_mapped = FALSE;
 			// check if the user already chose to map it
@@ -201,7 +266,7 @@
 				}
 				else {
 					// try to match by email
-					$emails = array(strtolower($email));
+					$emails = array(strtolower($imported_email));
 					$user_objects = user_get_objects_by_email($emails);
 					if (count($user_objects) == 1) {
 						$user_object=$user_objects[0];
@@ -210,7 +275,7 @@
 						if ($this->message) {
 							$this->message .= '<br />';
 						}
-						$this->message .= sprintf(_('Found matching existing forge user "%s" with same email "%s"'), $username, $email);
+						$this->message .= sprintf(_('Found matching existing forge user "%s" with same email "%s"'), $username, $imported_email);
 					}
 				}
 			}
@@ -221,55 +286,73 @@
 				$needs_to_warn = TRUE;
 			}
 			
+			// now construct mapping table to be displayed later
 			$html_tbody .= '<tr>';
 			$html_tbody .= '<td style="white-space: nowrap;">'. $imported_username .'</td>';
-			$html_tbody .= '<td style="white-space: nowrap;">'. $email .'</td>';
-			$html_tbody .= '<td><select name="map_'.$imported_username.'">';
-
-			if ($user_object) {
-				$html_tbody .= '<option value="0">'._('Optionally change for another existing user').'</option>';
-			}
-			else {
-				$html_tbody .= '<option value="0" selected="selected">'._('Select existing user').'</option>';
-			}
+			$html_tbody .= '<td style="white-space: nowrap;">'. $imported_email .'</td>';
+			$html_tbody .= '<td>'. $this->importer->get_user_role($user) . '</td>';
+			
+			// if not all mapping of users has been provided, then must display selection widgets
+			if (! $mapping_all_users_provided ) {
 				
-			// Load users members of the project
-			/*
-			$res_memb = db_query_params('SELECT users.realname,users.user_id,
-			users.user_name,user_group.admin_flags,user_group.role_id
-			FROM users,user_group
-			WHERE users.user_id=user_group.user_id
-			AND user_group.group_id=$1 ORDER BY users.realname',
-			array($group_id));
+				$html_tbody .= '<td><select name="map_'.$imported_username.'">';
 
-			$existing_users = array();
-			while ($row_memb=db_fetch_array($res_memb)) {
-			$existing_users[] = $row_memb['user_name'];
-			}*/
-			$active_users = user_get_active_users();
-		
-			$existing_users = array();
-			foreach($active_users as $user) {
-				//if ($user->isMember($group_id)) {
-					$existing_users[] = $user->getUnixName();
-				//}
+				if ($user_object) {
+					$html_tbody .= '<option value="0">'._('Optionally change for another existing user').'</option>';
+				}
+				else {
+					$html_tbody .= '<option value="0" selected="selected">'._('Select existing user').'</option>';
+				}
+				// TODO : use html_build_select_box_from_arrays(...); ?
+				foreach($existing_users as $existing_user) {
+					$name = $existing_user['name'];
+					$role = $existing_user['role'];
+					if ($role) {
+						$line = $name . ' (' . $role . ')';
+					} else {
+						$line = $name . ' ('. _('to be added to project') . ')';
+					}
+					if ( ($already_mapped && ($name == $already_mapped)) ||
+					($automatically_matched && ($name == $automatically_matched)) ) {
+						$html_tbody .= '<option value="'. $name .'" selected="selected">'. $line.'</option>';
+					}
+					else {
+						$html_tbody .= '<option value="'. $name .'">'. $line .'</option>';
+					}
+				}
+				$html_tbody .= '</select></td>';
 			}
-			
-			foreach($existing_users as $existing_user) {
-				if ( ($already_mapped && ($existing_user == $already_mapped)) ||
-					 ($automatically_matched && ($existing_user == $automatically_matched)) ) {
-					$html_tbody .= '<option value="'. $existing_user .'" selected="selected">'. $existing_user .'</option>';
+			else { // will display the mapped user anyway
+				$role = ' ('. _('need to add to project'). ')';
+				$user_object = user_get_object_by_name($already_mapped);
+				// if mapped user is already project member
+				if ($user_object->isMember($group_id)) {
+					$role = $user_object->getRole($group_id);
+					if ($role) {
+						$role = ' ('. $role->getName() . ')';
+					}
 				}
 				else {
-					$html_tbody .= '<option value="'. $existing_user .'">'. $existing_user .'</option>';
+					// memorize the list of users that need to be added to the project
+					if (! array_key_exists($already_mapped, $new_member_map_users)) {
+						$new_member_map_users[$already_mapped] = array();
+					}
+					$new_member_map_users[$already_mapped][] = $imported_username;
+					$all_mapped_users_in_project = FALSE;
+					
+					if ( ! array_key_exists($already_mapped, $this->posted_new_member_roles) ) {
+						$all_new_project_members_roles_set = FALSE;
+					}
 				}
+				$html_tbody .= '<td>'. $already_mapped . $role;
+				$html_tbody .= '<input type="hidden" name="map_'.$imported_username.'" value="'.$already_mapped.'" />';
+				$html_tbody .= '</td>';
 			}
-			$html_tbody .= '</select></td>';
 			$html_tbody .= '</tr>';
 
 		} // foreach
 
-		// OK, now, render the HTML
+		// OK, now, will be able to render the HTML
 
 		if (count($imported_users)) {
 
@@ -285,65 +368,127 @@
 				else {
 					$html .= '<p>'._('You may change some mappings and re-submit.');
 				}
-					
-					
-				$html .= $this->html_generator->boxTop(_("Matching imported users to existing forge users"));
-					
-				$html .= '<table width="100%"><thead><tr>';
-				$html .= '<th>'._('Imported user logname').'</th>';
-				$html .= '<th>'._('Imported user email').'</th>';
-				$html .= '<th>'._('To map to existing user').'</th>';
-				$html .= '</tr></thead><tbody>';
-				$html .= '<input type="hidden" name="submit_mappings" value="y" />';
+			}
 			
-				$html .= $html_tbody;
-		
-				// $html .= '</form>';
-				$html .= '</tbody></table>';
-				$html .= $this->html_generator->boxBottom();
+			// display users mapping table
+			$html .= $this->html_generator->boxTop(_("Matching imported users to existing forge users"));
+				
+			$html .= '<table width="100%"><thead><tr>';
+			$html .= '<th>'._('Imported user logname').'</th>';
+			$html .= '<th>'._('Imported user email').'</th>';
+			$html .= '<th>'._('Initial role').'</th>';
+			if (! $mapping_all_users_provided) {
+				$html .= '<th>'._('Map to existing user (role)').'</th>';
+			} else {
+				$html .= '<th>'._('Mapped to existing user').'</th>';
 			}
-			else {
+			$html .= '</tr></thead><tbody>';
+			$html .= '<input type="hidden" name="submit_mappings" value="y" />';
+				
+			$html .= $html_tbody;
+
+			$html .= '</tbody></table>';
+			$html .= $this->html_generator->boxBottom();
+			
+			
+			if ($mapping_all_users_provided) {
 				// the mapping must be applied as all users mapping has been posted
+				
 				//if ($apply) {
 				$can_proceed = TRUE;
+				
+				// now, need to check if new (mapped to) users need to be added to (roles of) the project
+				if ( ! $all_mapped_users_in_project ) {
+					
+					// if the new project members haven't been posted by the user display box
+					if ( ! $all_new_project_members_roles_set ) { 
+					
+						$html .= $this->html_generator->boxTop(_("Matching new project members roles"));
+							
+						$html .= '<table width="100%"><thead><tr>';
+						$html .= '<th>'._('New project member').'</th>';
+						$html .= '<th>'._('Imported users mapped to it').'</th>';
+						$html .= '<th>'._('New role').'</th>';
+							
+						$html .= '</tr></thead><tbody>';
+							
+						foreach($new_member_map_users as $new_member => $imported_users_mapped) {
+							$html .= '<tr>';
+							$html .= '<td>'. $new_member . '</td>';
+							$html .= '<td>'. implode(', ', $imported_users_mapped) . '</td>';
+
+							// TODO : use a more sophisticated select box maybe : the selection by default of the first may not be the right thing to suggest ?
+							$html .= '<td>'. role_box($group_id, 'role_'.$new_member) . '</td>';
+							$html .= '</tr>';
+						}
+							
+						$html .= '<input type="hidden" name="submit_new_roles" value="y" />';
+
+						$html .= '</tbody></table>';
+						$html .= $this->html_generator->boxBottom();
+					}
+				}
+
+				// Last check if we can proceed to the user's import
 				$users = array();
 				foreach ($imported_users as $user => $userres) {
+					
+					//print_r('Check for : '. $user. '<br />');
+					
 					$imported_username = $this->importer->get_user_name($user);
-					$username = $this->posted_user_mapping[$imported_username];
-					$user_object = user_get_object_by_name($username);
+					$mapped_to_username = $this->posted_user_mapping[$imported_username];
+					$user_object = user_get_object_by_name($mapped_to_username);
+					
 					if ($user_object) {
-						if ($this->message) {
-							$this->message .= '<br />';
-						}
-						if ( $user_object->isMember($group_id) ) {
+						if ( ! $user_object->isMember($group_id) ) {
 							// no need to add it, already in the group
-							$this->message .= sprintf(_('Imported user "%s", mapped as "%s" which is already in the project : no need to add it.'), $imported_username, $username);
-						}
-						else {
+							// $this->message .= sprintf(_('Imported user "%s", mapped as "%s" which is already in the project : no need to add it.'), $imported_username, $mapped_to_username);
+						
 							// need to add it to the group
-							$role = array();
-							$role['role'] = $this->importer->get_user_role($user);
-							$users[$username] = $role;
-							$this->message .= sprintf(_('Imported user "%s", mapped as "%s" which is not yet in the project : need to add it.'), $imported_username, $username);
+							if ( array_key_exists($mapped_to_username, $this->posted_new_member_roles) ) {
+								$role = $this->posted_new_member_roles[$mapped_to_username];
+								$rolename = $this->importer->get_user_role($user);
+								
+								$users[$mapped_to_username] = array( 'role' => $role );
+								
+								if ($this->message) {
+									$this->message .= '<br />';
+								}
+								$this->message .= sprintf(_('Imported user "%s" (role "%s"), mapped as "%s" which is not yet in the project : need to add it as role "%s".'), 
+												$imported_username, $rolename, $mapped_to_username, $role);
+							}
+							else {
+								$can_proceed = FALSE;
+							}
+							
 						}
 					}
 					else {
 						// user not found : probably messing with the form post
-						$feedback .= sprintf(_('Failed to find mapped user "%s"'), $username);
+						$feedback .= sprintf(_('Failed to find mapped user "%s"'), $mapped_to_username);
 						$can_proceed = FALSE;
 					}
-				}
+				} // foreach
+				
 				if($can_proceed) {
+					print_r('We can proceed !');
 					$check=TRUE;
 					if($apply) $check = FALSE;
-					$check = TRUE;
+					
+					// For security, for now : TODO to be removed later
+					//$check = TRUE;
 					user_fill($users, $group_id, $check);
+					$html .= $message;
 				}
+				else {
+					$feedback .= "Couldn't proceed!";
+				}
 				$html .= "All (mapped) imported users added to the group.";
 				// }
 			}
 			
 		}
+		
 		return $html;
 
 	}
@@ -378,7 +523,8 @@
 				
 				// Handle missing users, taking into account the user mapping form elements 
 				// that may have been provided
-				$html .= $this->match_users($imported_users);
+				$apply = TRUE;
+				$html .= $this->match_users($imported_users, $apply);
 				
 				// Then handle project(s)
 
@@ -401,12 +547,12 @@
 	                               <tr>
 		                             <td>
 			                            <h2>'._('Details of imported project : ').
-			                             '<pre>'.$this->importer->get_project_name($project).'</pre>
+			                             '<pre>'.$project->getName().'</pre>
 			                            </h2>
 			                            <h3>'._('Project summary').'</h3>';
-						$html .= '<p><pre>'.$this->importer->get_project_description($project).'</pre></p>';
+						$html .= '<p><pre>'.$project->getDescription().'</pre></p>';
 
-						$spaces = $this->importer->project_get_spaces($project);
+						$spaces = $project->getSpaces();
 
 						// if no spaces posted to be imported, display checkboxes to prompt user 
 						// for spaces to be imported for next POST 




More information about the Fusionforge-commits mailing list