<commit_before><?php
	/**
	AGORA - an interactive and web-based argument mapping tool that stimulates reasoning, 
			reflection, critique, deliberation, and creativity in individual argument construction 
			and in collaborative or adversarial settings. 
    Copyright (C) 2011 Georgia Institute of Technology

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
	*/
	
	/**
		List of variables for project creation:
		uid: ID number for the user
		pass_hash: The hash of the user's password
		projID: The ID of the project.
		mapID: The ID of the map.
		action: "add" or "remove". Pretty self-explanatory, really. Right now, there's no "create a new map as part of a project" function on the server, and doesn't actually need to be: the client can have a button which automatically calls insert.php followed by projmaps.php?action=add when it gets a successful result from insert.php.		
	**/
	require 'configure.php';
	require 'errorcodes.php';
	require 'establish_link.php';
	require 'utilfuncs.php';
	
	function addMap($mapID, $projID, $userID, $pass_hash, $output){
		$output->addAttribute("ID", $projID);
		global $dbName, $version;
		header("Content-type: text/xml");
		$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
		$output = new SimpleXMLElement($xmlstr);
		$linkID= establishLink();
		if(!$linkID){
			badDBLink($output);
			return $output;
		}
		$status=mysql_select_db($dbName, $linkID);
		if(!$status){
			 databaseNotFound($output);
			 return $output;
		}
		if(!checkLogin($userID, $pass_hash, $linkID)){
			incorrectLogin($output);
			return $output;
		}
		//Basic boilerplate is done. Next step is to add the map to the project.
		
		
		
		return $output;
	}
	
	function removeMap($mapID, $projID, $userID, $pass_hash, $output){
		$output->addAttribute("ID", $projID);
		global $dbName, $version;
		header("Content-type: text/xml");
		$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
		$output = new SimpleXMLElement($xmlstr);
		$linkID= establishLink();
		if(!$linkID){
			badDBLink($output);
			return $output;
		}
		$status=mysql_select_db($dbName, $linkID);
		if(!$status){
			 databaseNotFound($output);
			 return $output;
		}
		if(!checkLogin($userID, $pass_hash, $linkID)){
			incorrectLogin($output);
			return $output;
		}
		//Basic boilerplate is done. Next step is to remove the map from the project.
		
		
		
		
		
		return $output;
	}

	$userID = mysql_real_escape_string($_REQUEST['uid']);
	$pass_hash = mysql_real_escape_string($_REQUEST['pass_hash']);
	$projID = mysql_real_escape_string($_REQUEST['projID']);
	$mapID =  mysql_real_escape_string($_REQUEST['mapID']);
	$action = $_REQUEST['action'];
	
	header("Content-type: text/xml");
	$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
	$output = new SimpleXMLElement($xmlstr);

	if($action=="add"){
		$output=addMap($mapID, $projID, $userID, $pass_hash, $output);
	}else if($action=="remove"){
		$output=removeMap($mapID, $projID, $userID, $pass_hash, $output);
	}else{
		meaninglessQueryVariables($output, "The 'action' variable must be set to either add or remove.");
	}
	print $output->asXML();
	
?><commit_msg>Basic adding and deleting are complete. No test for user yet, but that will come shortly.<commit_after><?php
	/**
	AGORA - an interactive and web-based argument mapping tool that stimulates reasoning, 
			reflection, critique, deliberation, and creativity in individual argument construction 
			and in collaborative or adversarial settings. 
    Copyright (C) 2011 Georgia Institute of Technology

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
	*/
	
	/**
		List of variables for project creation:
		uid: ID number for the user
		pass_hash: The hash of the user's password
		projID: The ID of the project.
		mapID: The ID of the map.
		action: "add" or "remove". Pretty self-explanatory, really. Right now, there's no "create a new map as part of a project" function on the server, and doesn't actually need to be: the client can have a button which automatically calls insert.php followed by projmaps.php?action=add when it gets a successful result from insert.php.		
	**/
	require 'configure.php';
	require 'errorcodes.php';
	require 'establish_link.php';
	require 'utilfuncs.php';
	
	function addMap($mapID, $projID, $userID, $pass_hash, $output){
		$output->addAttribute("ID", $projID);
		global $dbName, $version;
		header("Content-type: text/xml");
		$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
		$output = new SimpleXMLElement($xmlstr);
		$linkID= establishLink();
		if(!$linkID){
			badDBLink($output);
			return $output;
		}
		$status=mysql_select_db($dbName, $linkID);
		if(!$status){
			 databaseNotFound($output);
			 return $output;
		}
		if(!checkLogin($userID, $pass_hash, $linkID)){
			incorrectLogin($output);
			return $output;
		}
		//Basic boilerplate is done. Next step is to add the map to the project.
		
		//First, we check whether the user has authority to move the map into the project. To prevent abuse, only the map's creator can move the map into the project, and then only if he is a user of the project.
		
		//check currently omitted for testing purposes: can't be done until projusers exists
		//TODO: add check once projusers is working properly
		
		$query = "INSERT INTO projmaps (proj_id, map_id) VALUES ($projID, $mapID)";
		$success = mysql_query($query, $linkID);
		if($success){
			$map=$output->addChild("map");
			$map->addAttribute("ID", $mapID);
			$map->addAttribute("added", true);
			return $output;
		}else{
			$map=$output->addChild("map");
			$map->addAttribute("ID", $mapID);
			$map->addAttribute("added", false);
			updateFailed($output, $query);
			return $output;
		}
		
		return $output;
	}
	
	function removeMap($mapID, $projID, $userID, $pass_hash, $output){
		$output->addAttribute("ID", $projID);
		global $dbName, $version;
		header("Content-type: text/xml");
		$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
		$output = new SimpleXMLElement($xmlstr);
		$linkID= establishLink();
		if(!$linkID){
			badDBLink($output);
			return $output;
		}
		$status=mysql_select_db($dbName, $linkID);
		if(!$status){
			 databaseNotFound($output);
			 return $output;
		}
		if(!checkLogin($userID, $pass_hash, $linkID)){
			incorrectLogin($output);
			return $output;
		}
		//Basic boilerplate is done. Next step is to remove the map from the project.
		//First, we check whether the user has authority to move the map out of the project. To prevent abuse, only the map's creator or a project administrator can move the map out of the project. The owner can do this even if he is no longer a user of the project. (Thinking: you can't kick me out of a project to take away my ability to work on my map.)
		
		//check currently omitted for testing purposes: can't be done until projusers exists
		//TODO: add check once projusers is working properly
		
		$query = "DELETE FROM projmaps WHERE proj_id=$projID AND map_id=$mapID";
		
		$success = mysql_query($query, $linkID);
		if($success){
			$map=$output->addChild("map");
			$map->addAttribute("ID", $mapID);
			$map->addAttribute("deleted", true);
			return $output;
		}else{
			$map=$output->addChild("map");
			$map->addAttribute("ID", $mapID);
			$map->addAttribute("deleted", false);
			updateFailed($output, $query);
			return $output;
		}
		
		return $output;
		
		
		
		
		return $output;
	}

	$userID = mysql_real_escape_string($_REQUEST['uid']);
	$pass_hash = mysql_real_escape_string($_REQUEST['pass_hash']);
	$projID = mysql_real_escape_string($_REQUEST['projID']);
	$mapID =  mysql_real_escape_string($_REQUEST['mapID']);
	$action = $_REQUEST['action'];
	
	header("Content-type: text/xml");
	$xmlstr = "<?xml version='1.0'?>\n<project version='$version'></project>";
	$output = new SimpleXMLElement($xmlstr);

	if($action=="add"){
		$output=addMap($mapID, $projID, $userID, $pass_hash, $output);
	}else if($action=="remove"){
		$output=removeMap($mapID, $projID, $userID, $pass_hash, $output);
	}else{
		meaninglessQueryVariables($output, "The 'action' variable must be set to either add or remove.");
	}
	print $output->asXML();
	
?>
{'fraction_non_alphanumeric': 0.12909379968203497, 'fraction_numerical': 0.0023317435082140965, 'mean_word_length': 4.298147108366086, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 6, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3049578', 'n_tokens_mistral': 3197, 'n_tokens_neox': 2848, 'n_words': 988}