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


$thisclient = 1;

include("head_template.php");

if ($_POST["changecomments"]==""._SAVE."") {
	$_POST[commentsnew] = strip_tags(nl2br($_POST['commentsnew']));
	$q="UPDATE hd_clients SET comments='$_POST[commentscolor]$_POST[commentsnew]' WHERE clientid=".$_SESSION['hd_clientid']."";
	if (!mysql_query($q,$db_link)) {echo mysql_error(); exit;}
	go2("clientdata.php?clientid=".$_SESSION['hd_clientid']."");
}


$query="SELECT * FROM hd_clients WHERE clientid=".$_SESSION['hd_clientid']."";
$result=mysql_query($query,$db_link);
$row = mysql_fetch_array($result);

$row[last]=stripslashes($row[last]);
$row[first]=stripslashes($row[first]);
$row[company]=stripslashes($row[company]);
$row[address]=stripslashes($row[address]);
$row[city]=stripslashes($row[city]);
$row[state]=stripslashes($row[state]);
$row[zip]=stripslashes($row[zip]);
$row[country]=stripslashes($row[country]);
$row[phone]=stripslashes($row[phone]);
$row[fax]=stripslashes($row[fax]);
$row[email]=stripslashes($row[email]);
$row[comments]=stripslashes($row[comments]);
$row[password]=stripslashes($row[password]);

$codigostate = $row[state];
$codigopais = $row[country];
$telefono = $row[phone];



$cliente = collectdata('client',$_SESSION['hd_clientid']);


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

$query="SELECT * FROM hd_clients_history WHERE clientid=".$_SESSION['hd_clientid']." ORDER BY modified ASC";
$result=mysql_query($query,$db_link);

print("<table class='table table-condensed'>");

while($row=mysql_fetch_array($result)) {

	if (!isset($prow)) {$prow = $row;}

	print("<tr><td colspan=9>");
	if ($row[modified]>0) {
		print("<font size=2><b>".ucfirst(_MODIFIED).":</b> ".date($df." G:i:s",$row[modified])." (".TimeAgo($row[modified],time()+$config[31][1]*3600).")</font>");
	}else{
		print("<font size=2>".date($df." G:i:s",$row[start])." (".TimeAgo($row[start],time()+$config[31][1]*3600).")</font>");
	}
	print("</td></tr>");

	print("<tr>");

	if($row[clientid]<>$prow[clientid]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_CLIENT_ID)).": </b>".$row[clientid]."</td>");
	print("<td>&nbsp;</td>");

	if($row[clientalias]<>$prow[clientalias]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_ALIAS)).": </b>".$row[clientalias]."</td>");
	print("<td>&nbsp;</td>");

	if($row[first]<>$prow[first]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_FIRST_NAME)).": </b>".$row[first]."</td>");
	print("<td>&nbsp;</td>");

	if($row[last]<>$prow[last]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_LAST_NAME)).": </b>".$row[last]."</td>");
	print("<td>&nbsp;</td>");

	if($row[company]<>$prow[company]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_COMPANY)).": </b>".$row[company]."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");

	if($row[phone]<>$prow[phone]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_PHONE)).": </b>".$row[phone]."</td>");
	print("<td>&nbsp;</td>");

	if($row[email]<>$prow[email]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_EMAIL)).": </b>".$row[email]."</td>");
	print("<td>&nbsp;</td>");

	if($row[password]<>$prow[password]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_PASSWORD)).": </b>".decrypt($row[password])."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");

	if($row[address]<>$prow[address]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_ADDRESS)).": </b>".$row[address]."</td>");
	print("<td>&nbsp;</td>");

	if($row[city]<>$prow[city]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_CITY)).": </b>".$row[city].($row[zip]?' ('.$row[zip].')':'')."</td>");
	print("<td>&nbsp;</td>");

	if($row[state]<>$prow[state]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_STATE)).": </b>".showstate($row[state])."</td>");
	print("<td>&nbsp;</td>");

	if($row[country]<>$prow[country]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_COUNTRY)).": </b>".showcountry($row[country])."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");


	if($config[41][1]) {
		if($row[personalized_1]<>$prow[personalized_1]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[41][1]).": </b>".$row[personalized_1]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[42][1]) {
		if($row[personalized_2]<>$prow[personalized_2]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[42][1]).": </b>".$row[personalized_2]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[43][1]) {
		if($row[personalized_3]<>$prow[personalized_3]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[43][1]).": </b>".$row[personalized_3]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[44][1]) {
		if($row[personalized_4]<>$prow[personalized_4]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[44][1]).": </b>".$row[personalized_4]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[45][1]) {
		if($row[personalized_5]<>$prow[personalized_5]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[45][1]).": </b>".$row[personalized_5]."</td>");
		print("<td>&nbsp;</td>");
	}


	print("</tr>");


	print("<tr><td colspan=9><br><hr><br></td></tr>");


	$prow = $row;
	$haymodificaciones = 1;
}


if ($haymodificaciones == 1) {
	$row = $cliente;
	$row[password] = encrypt($row[password]);
	$row[state] = $codigostate;
	$row[country] = $codigopais;
	$row[phone] = $telefono;

	print("<tr><td colspan=9>");
	if ($row[modified]>0) {
		print("<font size=2><b>".ucfirst(_MODIFIED).":</b> ".date($df." G:i:s",$row[modified])." (".TimeAgo($row[modified],time()+$config[31][1]*3600).")</font>");
	}else{
		print("<font size=2>".date($df." G:i:s",$row[start])." (".TimeAgo($row[start],time()+$config[31][1]*3600).")</font>");
	}
	print("</td></tr>");

	print("<tr>");

	if($row[clientid]<>$prow[clientid]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_CLIENT_ID)).": </b>".$row[clientid]."</td>");
	print("<td>&nbsp;</td>");

	if($row[clientalias]<>$prow[clientalias]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_ALIAS)).": </b>".$row[clientalias]."</td>");
	print("<td>&nbsp;</td>");

	if($row[first]<>$prow[first]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_FIRST_NAME)).": </b>".$row[first]."</td>");
	print("<td>&nbsp;</td>");

	if($row[last]<>$prow[last]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_LAST_NAME)).": </b>".$row[last]."</td>");
	print("<td>&nbsp;</td>");

	if($row[company]<>$prow[company]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_COMPANY)).": </b>".$row[company]."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");

	if($row[phone]<>$prow[phone]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_PHONE)).": </b>".$row[phone]."</td>");
	print("<td>&nbsp;</td>");

	if($row[email]<>$prow[email]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_EMAIL)).": </b>".$row[email]."</td>");
	print("<td>&nbsp;</td>");

	if($row[password]<>$prow[password]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_PASSWORD)).": </b>".decrypt($row[password])."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");

	if($row[address]<>$prow[address]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_ADDRESS)).": </b>".$row[address]."</td>");
	print("<td>&nbsp;</td>");

	if($row[city]<>$prow[city]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_CITY)).": </b>".$row[city].($row[zip]?' ('.$row[zip].')':'')."</td>");
	print("<td>&nbsp;</td>");

	if($row[state]<>$prow[state]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_STATE)).": </b>".showstate($row[state])."</td>");
	print("<td>&nbsp;</td>");

	if($row[country]<>$prow[country]){$clase = 'class=changedfields';}else{$clase = '';}
	print("<td align='left' $clase><b>".ucfirst(str_replace(' ','&nbsp;',_COUNTRY)).": </b>".showcountry($row[country])."</td>");

	print("<tr><td height='5'></td></tr></tr>");


	print("<tr>");


	if($config[41][1]) {
		if($row[personalized_1]<>$prow[personalized_1]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[41][1]).": </b>".$row[personalized_1]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[42][1]) {
		if($row[personalized_2]<>$prow[personalized_2]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[42][1]).": </b>".$row[personalized_2]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[43][1]) {
		if($row[personalized_3]<>$prow[personalized_3]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[43][1]).": </b>".$row[personalized_3]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[44][1]) {
		if($row[personalized_4]<>$prow[personalized_4]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[44][1]).": </b>".$row[personalized_4]."</td>");
		print("<td>&nbsp;</td>");
	}

	if($config[45][1]) {
		if($row[personalized_5]<>$prow[personalized_5]){$clase = 'class=changedfields';}else{$clase = '';}
		print("<td align='left' $clase><b>".str_replace(' ','&nbsp;',$config[45][1]).": </b>".$row[personalized_5]."</td>");
		print("<td>&nbsp;</td>");
	}


	print("</tr>");


	print("<tr><td colspan=9><br><hr><br></td></tr>");
}


print("</table>");


echo '</div>';
echo '</div>';


include("foot_template.php");

?>