<?php
include("postget.php");
include_once("common.php");
checklevel(3,$_REQUEST['clientid']);
$thisclient=1;


if($mergeclick==""._MERGE."")
{


	//////////////////////////// actualizar hd_history
	$query="UPDATE hd_history SET clientid=$destino WHERE clientid=$origen";
	if(!mysql_query($query,$db_link)) {	print(mysql_error()); exit;	}

	//////////////////////////// actualizar hd_clients_history
	$query="UPDATE hd_clients_history SET clientid=$destino WHERE clientid=$origen";
	if(!mysql_query($query,$db_link)) {	print(mysql_error()); exit;	}

	//////////////////////////// actualizar hd_tickets
	$query="UPDATE hd_tickets SET clientid=$destino WHERE clientid=$origen";
	if(!mysql_query($query,$db_link)) {	print(mysql_error()); exit;	}

	//////////////////////////// actualizar hd_tickets_replies
	$query="UPDATE hd_tickets_replies SET clientid=$destino WHERE clientid=$origen";
	if(!mysql_query($query,$db_link)) {	print(mysql_error()); exit;	}


		//////////////////////////// desactivar el cliente origen
	$query="UPDATE hd_clients SET active=-1 WHERE clientid=$origen LIMIT 1";
	if(!mysql_query($query,$db_link)) {	print(mysql_error()); exit;	}

	go2('tickets.php?clientid='.$destino);


}else{




	include("head_template.php");

	echo '
<div class="container">
	<div class="row">


<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';
	echo _MERGE_THIS_ACCOUNT_INSIDE_OTHER_ACCOUNT ;

echo '
		</td>
		</tr>
';	$imagenAmostrar = "Workspace_.png";
	
echo '
			<tr valign="top">
				<td>

';



	?>
	
	<form>
	<table cellspacing="4">
		<tr>
			<td><B><?php echo _TARGET_ACCOUNT ?>:</B></td>
	
			<td>
				<?php	
				$query="SELECT clientid, first, last FROM hd_clients WHERE clientid <> ".$_SESSION['hd_clientid']." AND active>=0 ORDER BY clientid";
				$Clientes=mysql_query($query,$db_link);
				echo "<select name=destino>";
				while($rowclients=mysql_fetch_array($Clientes)) {
				?>
				       <option value='<?php print($rowclients[clientid]); ?>' ><?php print(" [".$rowclients[clientid]."] ".$rowclients[first]." ".$rowclients[last]); ?></option>
				<?php
				};
				echo "</select>";
				?>		
			</td>
		</tr>
	</table>
	<input type=hidden name=origen value=<?php print($_SESSION['hd_clientid']);?> >
	<input type=hidden name=mergeclick value="<?php print(_MERGE);?>">
	<input type=submit name=mergeclick value="<?php print(_MERGE);?>">
	</form>
	<?php
echo '
		</td>
		</tr>
		</table>
</div>
</div>
';
	include("foot_template.php"); 
}

?>
