<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# add user to my network
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
$not_access=1;
$granted="I";

require_once('includes_mobile.php');
require_once('../../../../db_layer/'.__DBTYPE.'/enterprise.php');

$userId=$_SESSION['user_id'];
$id_friend=$_GET['id'];
$add=$_GET['add'];//if user choose to add or ban

if ($add==1)
{
	$DB->execute($scrnetworkadduser_addUser,$DB->escape($userId),$DB->escape($id_friend),"''");

	//-------------add keywords linked to user-----------
	if (isset($_POST['kw']))
	{
		$kw=$_POST['kw'];
		$kws=php_format_tag($kw);
		$keyword=explode(",",$kw);
		$keywordSimplified=explode(",",$kws);
		for ($i=0;$i<count($keyword);$i++)
		{
			$selkw=$keywordSimplified[$i];
			$DB->getResults($scrnetworkadduser_getKeyword,$DB->quote($selkw));
			if ($DB->nbResults()==0)
			{
				$DB->execute($scrnetworkadduser_addNewKeyword,$DB->quote($keyword[$i]),$DB->quote($selkw));
				$kwid=$DB->getId();
			}
			else
			{
				$row = $DB->fetch(0);
				$kwid=$row["id"];
			}
			$DB->freeResults();

			$DB->execute($scrnetworkadduser_insertKeyword,$DB->escape($userId),$DB->escape($id_friend),$kwid);
		}
	}
	//--------------------------------------------------
}
else if ($add==0)
{
	//remove user for the concerned network
	$DB->execute($scrnetworkremoveuser_removeUser,$DB->escape($userId),$DB->escape($id_friend));

	//remove keywords attached to this user
	$DB->execute($scrnetworkremoveuser_removeKeywords,$DB->escape($userId),$DB->escape($id_friend));
}

header('location:network.php');
?> 