<commit_before><?php
include('header.php');

$userid=isloggedin();
if ($userid)
{	
	

	$endorsedproposals = $_POST['proposal'];
	if(!$endorsedproposals){$endorsedproposals=array();}
	$question = $_POST['question'];

	$sql2 = "SELECT roundid FROM questions WHERE id = ".$question." LIMIT 1 ";
	$response2 = mysql_query($sql2);
	while ($row2 = mysql_fetch_row($response2))
	{		
		$roundid =	$row2[0];
	}
	$nEndorsers=CountEndorsers($question,$roundid);

	$allproposals=array();	
	$sql = "SELECT  id FROM proposals WHERE  proposals.experimentid = " . $question . " AND proposals.roundid= ".$roundid." ";
	$response = mysql_query($sql);
	while ($row = mysql_fetch_row($response))	
	{	
		array_push($allproposals,$row[0]);
	}

	foreach ($allproposals as $p)
	{
		$sql = "SELECT  id FROM endorse WHERE  endorse.userid = " . $userid . " and endorse.proposalid = " . $p . " LIMIT 1";
		if(mysql_fetch_row(mysql_query($sql)))
		{
			if (!in_array($p,$endorsedproposals))
			{
				$sql = "DELETE FROM `endorse` WHERE  endorse.userid = " . $userid . " and endorse.proposalid = " . $p . " ";
				mysql_query($sql);		
			}
		}
		else
		{
			if (in_array($p,$endorsedproposals))
			{
				$sql = 'INSERT INTO `endorse` (`userid`, `proposalid`, `endorsementdate` ) VALUES (\'' . $userid . '\', \'' . $p. '\',NOW() );';
				mysql_query($sql);
			}
		}
	}
	
	$NEWnEndorsers=CountEndorsers($question,$roundid);
	if(	$nEndorsers< $NEWnEndorsers)
	{
		AwareAuthorOfNewEndorsement($question);
	}
	
	
	
	header("Location: viewquestion.php?q=".$question."");
}
else
{
		header("Location: login.php");
}
?> <commit_msg>Added correct version of file.<commit_after><?php
include('header.php');

$userid=isloggedin();
if ($userid)
{	
	

	$endorsedproposals = $_POST['proposal'];
	if(!$endorsedproposals){$endorsedproposals=array();}
	$question = $_POST['question'];

	$sql2 = "SELECT roundid FROM questions WHERE id = ".$question." LIMIT 1 ";
	$response2 = mysql_query($sql2);
	while ($row2 = mysql_fetch_row($response2))
	{		
		$roundid =	$row2[0];
	}
	$nEndorsers=CountEndorsers($question,$roundid);

	$allproposals=array();	
	$sql = "SELECT  id FROM proposals WHERE  proposals.experimentid = " . $question . " AND proposals.roundid= ".$roundid." ";
	$response = mysql_query($sql);
	while ($row = mysql_fetch_row($response))	
	{	
		array_push($allproposals,$row[0]);
	}

	foreach ($allproposals as $p)
	{
		$sql = "SELECT  id FROM endorse WHERE  endorse.userid = " . $userid . " and endorse.proposalid = " . $p . " LIMIT 1";
		if(mysql_fetch_row(mysql_query($sql)))
		{
			if (!in_array($p,$endorsedproposals))
			{
				$sql = "DELETE FROM `endorse` WHERE  endorse.userid = " . $userid . " and endorse.proposalid = " . $p . " ";
				mysql_query($sql);		
			}
		}
		else
		{
			if (in_array($p,$endorsedproposals))
			{
				$sql = 'INSERT INTO `endorse` (`userid`, `proposalid`, `endorsementdate` ) VALUES (\'' . $userid . '\', \'' . $p. '\',NOW() );';
				mysql_query($sql);
			}
		}
	}
	
	$NEWnEndorsers=CountEndorsers($question,$roundid);
	if(	$nEndorsers< $NEWnEndorsers)
	{
		AwareAuthorOfNewEndorsement($question);
	}
	
	$room = GetRoom($question);
	$urlquery = CreateQuestionURL($question, $room);
	
	header("Location: viewquestion.php".$urlquery);
}
else
{
		header("Location: login.php");
}
?> 
{'fraction_non_alphanumeric': 0.18925518925518925, 'fraction_numerical': 0.006105006105006105, 'mean_word_length': 4.15251572327044, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7015268', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1260, 'n_words': 213}