<commit_before><?php
	require 'checklogin.php';
	require 'establish_link.php';
	/**
	*	Function for removing a node from the database.
	*/
	function removeNode($node, $mapID, $linkID, $userID)
	{
		print "<BR>----Node found in XML";
		$attr = $node->attributes();
		$nID = mysql_real_escape_string($attr["ID"]);
		$query = "SELECT * FROM nodes WHERE node_id=$nID";
		$resultID = mysql_query($query, $linkID);
		$row = mysql_fetch_assoc($resultID);
		if($userID == $row["user_id"]){
			print "<BR>Now deleting....<BR>";
			$uquery = "UPDATE nodes SET modified_date=NOW(), is_deleted=1 WHERE node_id=$nID";
			print $uquery;
			$retval = mysql_query($uquery, $linkID);
			if(!$retval){
				return $retval;
			}			
			return $retval;
		}else{
			print "<BR>You are attempting to delete someone else's work or a nonexistent node. This is not permissible.";
			return false;
		}
	}
	/**
	*	Convenience function. Iterates throughout the database. Separated from main logic for clarity.
	*	http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
	*/
	function xmlToDB($xml, $mapID, $linkID, $userID)	
	{
		print "<BR>Now taking the XML and deleting things with it...";
		$children = $xml->children();
		$retval = true;
		foreach ($children as $child)
		{
			switch($child->getName())
			{
				case "textbox":
					//textboxToDB($child, $mapID, $linkID, $userID);
					break;
				case "node":
					$retval = removeNode($child, $mapID, $linkID, $userID);
					break;
				case "connection":
					//connectionToDB($child, $mapID, $linkID, $userID);
					break;
			}
			if($retval == false){  // We've already had one failure, no reason to continue
				return false;
			}
		}
		return true;
	}
	
	/**
	*	Highest level function. Handles SQL connection logic.
	*/
	function remove($xmlin, $userID, $pass_hash)
	{
	//Standard SQL connection stuff
		$linkID= establishLink();
		mysql_select_db("agora", $linkID) or die ("Could not find database");

		if(!checkLogin($userID, $pass_hash, $linkID)){
			print "Incorrect login!";
			return;
		}
		
		//Dig the Map ID out of the XML
		$xml = new SimpleXMLElement($xmlin);
		$mapID = $xml['ID'];
		$mapClause = mysql_real_escape_string("$mapID");
		$delMap = mysql_real_escape_string($xml['remove']);
		//Check to see if the map already exists
		$query = "SELECT * FROM maps INNER JOIN users ON users.user_id = maps.user_id WHERE map_id = $mapClause";
		$resultID = mysql_query($query, $linkID) or die ("Cannot get map!"); 
		$row = mysql_fetch_assoc($resultID);
		$UID = $row['maps.user_id'];
		if($delMap && $mapClause!=0){
			if($UID!=$userID){
				print "You cannot delete someone else's map!";
				return;
			}		
			$query = "UPDATE maps SET is_deleted=1, modified_date=NOW() WHERE map_id=$mapClause";
			$success = mysql_query($query, $linkID);
			if($success){
				print "Successfully deleted the map!";
			}else{
				print "Could not delete the map!";
			}
		}else if($mapClause==0 or mysql_num_rows($resultID)==0){
			print "This map does not exist, therefore you cannot remove things from this map.";
		}else{
			//the map exists, and now we operate on it
						
			//Transactions used for protecting maps from mass deletes that are partially illegal.
			mysql_query("START TRANSACTION");
			$success = xmlToDB($xml, $mapClause, $linkID, $userID);
			if($success===true){
				mysql_query("COMMIT");
				print "<BR>Query committed!<BR>";<commit_msg>Fix erroneous overspecification of db column<commit_after><?php
	require 'checklogin.php';
	require 'establish_link.php';
	/**
	*	Function for removing a node from the database.
	*/
	function removeNode($node, $mapID, $linkID, $userID)
	{
		print "<BR>----Node found in XML";
		$attr = $node->attributes();
		$nID = mysql_real_escape_string($attr["ID"]);
		$query = "SELECT * FROM nodes WHERE node_id=$nID";
		$resultID = mysql_query($query, $linkID);
		$row = mysql_fetch_assoc($resultID);
		if($userID == $row["user_id"]){
			print "<BR>Now deleting....<BR>";
			$uquery = "UPDATE nodes SET modified_date=NOW(), is_deleted=1 WHERE node_id=$nID";
			print $uquery;
			$retval = mysql_query($uquery, $linkID);
			if(!$retval){
				return $retval;
			}			
			return $retval;
		}else{
			print "<BR>You are attempting to delete someone else's work or a nonexistent node. This is not permissible.";
			return false;
		}
	}
	/**
	*	Convenience function. Iterates throughout the database. Separated from main logic for clarity.
	*	http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
	*/
	function xmlToDB($xml, $mapID, $linkID, $userID)	
	{
		print "<BR>Now taking the XML and deleting things with it...";
		$children = $xml->children();
		$retval = true;
		foreach ($children as $child)
		{
			switch($child->getName())
			{
				case "textbox":
					//textboxToDB($child, $mapID, $linkID, $userID);
					break;
				case "node":
					$retval = removeNode($child, $mapID, $linkID, $userID);
					break;
				case "connection":
					//connectionToDB($child, $mapID, $linkID, $userID);
					break;
			}
			if($retval == false){  // We've already had one failure, no reason to continue
				return false;
			}
		}
		return true;
	}
	
	/**
	*	Highest level function. Handles SQL connection logic.
	*/
	function remove($xmlin, $userID, $pass_hash)
	{
	//Standard SQL connection stuff
		$linkID= establishLink();
		mysql_select_db("agora", $linkID) or die ("Could not find database");

		if(!checkLogin($userID, $pass_hash, $linkID)){
			print "Incorrect login!";
			return;
		}
		
		//Dig the Map ID out of the XML
		$xml = new SimpleXMLElement($xmlin);
		$mapID = $xml['ID'];
		$mapClause = mysql_real_escape_string("$mapID");
		$delMap = mysql_real_escape_string($xml['remove']);
		//Check to see if the map already exists
		$query = "SELECT * FROM maps INNER JOIN users ON users.user_id = maps.user_id WHERE map_id = $mapClause";
		$resultID = mysql_query($query, $linkID) or die ("Cannot get map!"); 
		$row = mysql_fetch_assoc($resultID);
		$UID = $row['user_id'];
		if($delMap && $mapClause!=0){
			if($UID!=$userID){
				print "You cannot delete someone else's map!";
				return;
			}		
			$query = "UPDATE maps SET is_deleted=1, modified_date=NOW() WHERE map_id=$mapClause";
			$success = mysql_query($query, $linkID);
			if($success){
				print "Successfully deleted the map!";
			}else{
				print "Could not delete the map!";
			}
		}else if($mapClause==0 or mysql_num_rows($resultID)==0){
			print "This map does not exist, therefore you cannot remove things from this map.";
		}else{
			//the map exists, and now we operate on it
						
			//Transactions used for protecting maps from mass deletes that are partially illegal.
			mysql_query("START TRANSACTION");
			$success = xmlToDB($xml, $mapClause, $linkID, $userID);
			if($success===true){
				mysql_query("COMMIT");
				print "<BR>Query committed!<BR>";
{'fraction_non_alphanumeric': 0.15282246270839428, 'fraction_numerical': 0.0020473822755191578, 'mean_word_length': 3.792571829011913, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '2075985', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2303, 'n_words': 658}