<?
header('Content-type: text/html; charset=utf-8');
session_start();
if($_SESSION['email_iddir'])$_REQUEST['record']=$_SESSION['email_iddir'];
if(!$_GET['tab'])$_GET['tab']="All";
require_once("../../config.php");
require_once("dirstree.php");
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
mysql_query("set charaecterset utf8");
if($_GET['tab']=="EcmContracts")
{
	foreach($_POST as $key=>$val)$_SESSION['ecmcontracts_'.$key]=$val;
}
if($_GET['tab']=="EcmCorrespondenceIns")
{
	foreach($_POST as $key=>$val)$_SESSION['ecmcorrespondenceins_'.$key]=$val;
}
if($_GET['tab']=="EcmCorrespondenceOuts")
{
	foreach($_POST as $key=>$val)$_SESSION['ecmcorrespondenceouts_'.$key]=$val;
}
if($_GET['tab']=="EcmInvoiceIns")
{
	foreach($_POST as $key=>$val)$_SESSION['ecminvoiceins_'.$key]=$val;
}
if($_GET['tab']=="EcmInvoiceOuts")
{
	foreach($_POST as $key=>$val)$_SESSION['ecminvoiceouts_'.$key]=$val;
}
if($_GET['tab']=="EcmDocs")
{
	foreach($_POST as $key=>$val)$_SESSION['ecmdocs_'.$key]=$val;
}
if($_GET['tab']=="All")
{
	foreach($_POST as $key=>$val)$_SESSION['all_'.$key]=$val;
}
if($_GET['reset']==1)
{
	$_SESSION['email_iddir']="";
	$tabs=array("ecmdoc","ecmcontract","ecmcorrespondencein","ecmcorrespondenceout","ecminvoicein","ecminvoiceout");
	foreach($tabs as $tab)$_SESSION[$tab.'_where']="";
}
print '<script type="text/javascript" src="../../include/javascript/popup_parent_helper.js?s={SUGAR_VERSION}&c={JS_CUSTOM_VERSION}"></script>';
function get_assigned_user_name_in_search($id)
{
	$r=mysql_fetch_array(mysql_query("select user_name from users where id='".$id."'"));
	return $r['user_name'];
}
function cut_name_in_search($t,$ile)
{
	if(strlen($t)>$ile)
	{
		for($i=0;$i<=$ile-1;$i++)
		{
			$text.=$t[$i];
		}
		return $text.="...";
	}
	else
	{
		return $t;
	}
}
function search_ids($id,$html="")
{
	$z="select id from ecmdocuments where iddir='".$id."' and deleted='0'";
	$w=mysql_query($z);
	while($r=mysql_fetch_array($w))
	{
		$html.=$r['id']."||";
		$html=search_ids($r['id'],$html);
	}
	return $html;
}	
$record=$_REQUEST['record'];
if($record=="")$record=0;
$ids=search_ids($record,"").$record;
$idy=explode("||",$ids);
//error_reporting(E_ALL);
////////////////////////EcmContracts/////////////////////////
if($_GET['tab']=="EcmContracts" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecmcontract_id from ecmdocuments_ecmcontracts where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmContracts")
			{
				if(mysql_num_rows(mysql_query("select id from ecmcontracts where id='".$r['ecmcontract_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and group_name like '%".$_POST['group_name']."%' and contractant_name like '%".$_POST['contractant_name']."%' and signedon like '%".$_POST['signedon']."%' and deleted='0'"))>0)$ecmcontracts[]=$r['ecmcontract_id'];
			}
			else 
			{
				if(mysql_num_rows(mysql_query("select id from ecmcontracts where id='".$r['ecmcontract_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmcontracts[]=$r['ecmcontract_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmContracts" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecmcontracts where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and group_name like '%".$_POST['group_name']."%' and contractant_name like '%".$_POST['contractant_name']."%' and signedon like '%".$_POST['signedon']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcontracts[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name'])$wws=mysql_query("select id from ecmcontracts where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecmcontracts where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcontracts[]=$rrs['id'];
			}
		}
	//}
	$ecmcontractsw="";
	$i=0;
	if(count($ecmcontracts)>0)
	{
		foreach($ecmcontracts as $ecmcontract)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecmcontractsw.=$or." id='".$ecmcontract."'";
			$i++;
		}
	}
}

////////////////////////EcmCorrespondenceIns/////////////////////////
if($_GET['tab']=="EcmCorrespondenceIns" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecmcorrespondencein_id from ecmdocuments_ecmcorrespondenceins where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmCorrespondenceIns")
			{
				if(mysql_num_rows(mysql_query("select id from ecmcorrespondenceins where id='".$r['ecmcorrespondencein_id']."' and name like '%".$_POST['name']."%' and account_name_from like '%".$_POST['account_name_from']."%' and account_name_to like '%".$_POST['account_name_to']."%' and description like '%".$_POST['description']."%' and document_date like '%".$_POST['document_date']."%' and delivery_date like '%".$_POST['delivery_date']."%' and stamp_date like '%".$_POST['stamp_date']."%' and reg_date like '%".$_POST['reg_date']."%' and deleted='0'"))>0)$ecmcorrespondenceins[]=$r['ecmcorrespondencein_id'];
			}
			else
			{
				if(mysql_num_rows(mysql_query("select id from ecmcorrespondenceins where id='".$r['ecmcorrespondencein_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmcorrespondenceins[]=$r['ecmcorrespondencein_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmCorrespondenceIns" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecmcorrespondenceins name like '%".$_POST['name']."%' and account_name_from like '%".$_POST['account_name_from']."%' and account_name_to like '%".$_POST['account_name_to']."%' and description like '%".$_POST['description']."%' and document_date like '%".$_POST['document_date']."%' and delivery_date like '%".$_POST['delivery_date']."%' and stamp_date like '%".$_POST['stamp_date']."%' and reg_date like '%".$_POST['reg_date']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcorrespondenceins[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name'])$wws=mysql_query("select id from ecmcorrespondenceins where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecmcorrespondenceins where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcorrespondenceins[]=$rrs['id'];
			}
		}
	//}
	$ecmcorrespondenceinsw="";
	$i=0;
	if(count($ecmcorrespondenceins)>0)
	{
		foreach($ecmcorrespondenceins as $ecmcorrespondencein)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecmcorrespondenceinsw.=$or." id='".$ecmcorrespondencein."'";
			$i++;
		}
	}
}
////////////////////////EcmCorrespondenceOuts/////////////////////////
if($_GET['tab']=="EcmCorrespondenceOuts" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecmcorrespondenceout_id from ecmdocuments_ecmcorrespondenceouts where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmCorrespondenceOuts")
			{
				if(mysql_num_rows(mysql_query("select id from ecmcorrespondenceouts where id='".$r['ecmcorrespondenceout_id']."' and name like '%".$_POST['name']."%' and account_from_name like '%".$_POST['account_from_name']."%' and account_to_name like '%".$_POST['account_to_name']."%' and document_date like '%".$_POST['document_date']."%' and deleted='0'"))>0)$ecmcorrespondenceouts[]=$r['ecmcorrespondenceout_id'];
			}
			else
			{
				if(mysql_num_rows(mysql_query("select id from ecmcorrespondenceouts where id='".$r['ecmcorrespondenceout_id']."' and name like '%".$_POST['name']."%' and deleted='0'"))>0)$ecmcorrespondenceouts[]=$r['ecmcorrespondenceout_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmCorrespondenceOuts" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecmcorrespondenceouts where name like '%".$_POST['name']."%' and account_from_name like '%".$_POST['account_from_name']."%' and account_to_name like '%".$_POST['account_to_name']."%' and document_date like '%".$_POST['document_date']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcorrespondenceouts[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name']!="")$wws=mysql_query("select id from ecmcorrespondenceouts where name like '%".$_POST['name']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecmcorrespondenceouts where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmcorrespondenceouts[]=$rrs['id'];
			}
		}
	//}
	$ecmcorrespondenceoutsw="";
	$i=0;
	if(count($ecmcorrespondenceouts)>0)
	{
		foreach($ecmcorrespondenceouts as $ecmcorrespondenceout)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecmcorrespondenceoutsw.=$or." id='".$ecmcorrespondenceout."'";
			$i++;
		}
	}
}

////////////////////////EcmInvoiceIns/////////////////////////
if($_GET['tab']=="EcmInvoiceIns" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecminvoicein_id from ecmdocuments_ecminvoiceins where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmInvoiceIns")
			{
				if(mysql_num_rows(mysql_query("select id from ecminvoiceins where id='".$r['ecminvoicein_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['ekmn_description']."%' and filename like '%".$_POST['ekmn_filename']."%' and from_name like '%".$_POST['from_name']."%' and to_name like '%".$_POST['to_name']."%' and deleted='0'"))>0)$ecminvoiceins[]=$r['ecminvoicein_id'];
			}
			else
			{
				if(mysql_num_rows(mysql_query("select id from ecminvoiceins where id='".$r['ecminvoicein_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecminvoiceins[]=$r['ecminvoicein_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmInvoiceIns" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecminvoiceins where name like '%".$_POST['name']."%' and description like '%".$_POST['ekmn_description']."%' and filename like '%".$_POST['ekmn_filename']."%' and from_name like '%".$_POST['from_name']."%' and to_name like '%".$_POST['to_name']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecminvoiceins[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name'])$wws=mysql_query("select id from ecminvoiceins where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecminvoiceins where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecminvoiceins[]=$rrs['id'];
			}
		}
	//}
	$ecminvoiceinsw="";
	$i=0;
	if(count($ecminvoiceins)>0)
	{
		foreach($ecminvoiceins as $ecminvoicein)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecminvoiceinsw.=$or." id='".$ecminvoicein."'";
			$i++;
		}
	}
}

////////////////////////EcmInvoiceOuts/////////////////////////
if($_GET['tab']=="EcmInvoiceOuts" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecminvoiceout_id from ecmdocuments_ecminvoiceouts where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmInvoiceOuts")
			{
				if(mysql_num_rows(mysql_query("select id from ecminvoiceouts where id='".$r['ecminvoiceout_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['ekmn_description']."%' and filename like '%".$_POST['ekmn_filename']."%' and from_name like '%".$_POST['from_name']."%' and to_name like '%".$_POST['to_name']."%' and deleted='0'"))>0)$ecminvoiceouts[]=$r['ecminvoiceout_id'];
			}
			else
			{
				if(mysql_num_rows(mysql_query("select id from ecminvoiceouts where id='".$r['ecminvoiceout_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecminvoiceouts[]=$r['ecminvoiceout_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmInvoiceOuts" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecminvoiceouts where name like '%".$_POST['name']."%' and description like '%".$_POST['ekmn_description']."%' and filename like '%".$_POST['ekmn_filename']."%' and from_name like '%".$_POST['from_name']."%' and to_name like '%".$_POST['to_name']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecminvoiceouts[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name'])$wws=mysql_query("select id from ecminvoiceouts where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecminvoiceouts where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecminvoiceouts[]=$rrs['id'];
			}
		}
	//}
	$ecminvoiceoutsw="";
	$i=0;
	if(count($ecminvoiceouts)>0)
	{
		foreach($ecminvoiceouts as $ecminvoiceout)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecminvoiceoutsw.=$or." id='".$ecminvoiceout."'";
			$i++;
		}
	}
}

////////////////////////EcmDocs/////////////////////////
if($_GET['tab']=="EcmDocs" or  $_GET['tab']=="All")
{
	//foreach($idy as $idx)
	//{
		if($_REQUEST['record'])
		{
		$z="select ecmdoc_id from ecmdocuments_ecmdocs where ecmdocument_id='".$_REQUEST['record']."' and deleted='0'";
		$w=mysql_query($z);
		while($r=mysql_fetch_array($w))
		{
			if($_GET['tab']=="EcmDocs")
			{
				if(mysql_num_rows(mysql_query("select id from ecmdocs where id='".$r['ecmdoc_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmdocs[]=$r['ecmdoc_id'];
			}
			else 
			{
				if(mysql_num_rows(mysql_query("select id from ecmdocs where id='".$r['ecmdoc_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmdocs[]=$r['ecmdoc_id'];
			}
		}
		}
		else
		{
			if($_GET['tab']=="EcmDocs" && $_GET['reset']!=1)
			{
				$wws=mysql_query("select id from ecmdocs where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmdocs[]=$rrs['id'];
			}
			if($_GET['tab']=="All" || $_GET['reset']==1)
			{
				if($_POST['name'])$wws=mysql_query("select id from ecmdocs where name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'");
				else $wws=mysql_query("select id from ecmdocs where deleted='0'");
				while($rrs=mysql_fetch_array($wws))$ecmdocs[]=$rrs['id'];
			}
		}
	//}
	$ecmdocsw="";
	$i=0;
	if(count($ecmdocs)>0)
	{
		foreach($ecmdocs as $ecmdoc)
		{
			if($i==0)$or="";
			else $or=" or";
			$ecmdocsw.=$or." id='".$ecmdoc."'";
			$i++;
		}
	}
}

?>
<script src="../../include/javascript/cookie.js?s=4.5.0g&c="></script>
<link rel="stylesheet" type="text/css" media="all" href="../../themes/Sugar/calendar-win2k-cold-1.css?s=4.5.0g&c=">
<script>jscal_today = 1.195210724E+012; if(typeof app_strings == "undefined") app_strings = new Array();</script>
<script src="../../jscalendar/calendar.js?s=4.5.0g&c="></script>
<script src="../../jscalendar/lang/calendar-en.js?s=4.5.0g&c="></script>
<script src="../../jscalendar/calendar-setup_3.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/YAHOO.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/log.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/dom.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/event.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/animation.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/connection.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/dragdrop.js?s=4.5.0g&c="></script>
<script src="../../include/javascript/yui/ygDDList.js?s=4.5.0g&c="></script>
<script type="text/javascript" language="javascript" src="mintajax.js"></script>
<script src="../../include/javascript/sugar_3.js?s=4.5.0g&c="></script><script type="text/javascript">
	var time_reg_format = '([0-9]{1,2}):([0-9]{1,2})';
	var date_reg_format = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})';
	var date_reg_positions = {'Y': 1,'m': 2,'d': 3};
	var time_separator = ':';
	var cal_date_format = '%Y-%m-%d';
	var time_offset = 0;
</script>
<script type="text/javascript" src="../../cache/jsLanguage/en_us.js?s=4.5.0g&c=&j=3"></script>
<script type="text/javascript" src="../../cache/jsLanguage/Contracts/en_us.js?s=4.5.0g&c=&j=3"></script>

<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN">
<html >
<style type="text/css">
<!--
body {
	margin-left: 20px;
	margin-top: 20px;
	margin-right: 20px;
	margin-bottom: 20px;
}
-->
</style>

<head >

<link REL="SHORTCUT ICON" HREF="include/images/sugar_icon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SugarCRM - Commercial Open Source CRM</title>

<link rel="stylesheet" type="text/css" href="../../themes/Sugar/navigation.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/style.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/colors.sugar.css?s=4.5.0g&c=" />
<link rel="stylesheet" type="text/css" href="../../themes/Sugar/fonts.normal.css?s=4.5.0g&c=" />
<link href="../../themes/Sugar/colors.sugar.css?s=4.5.0g&c=" rel="stylesheet" type="text/css" title="color:sugar" />
<link href="../../themes/Sugar/colors.blue.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:blue" />
<link href="../../themes/Sugar/colors.green.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:green" />
<link href="../../themes/Sugar/colors.purple.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:purple" />

<link href="../../themes/Sugar/colors.ocher.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="color:ocher" />
<link href="../../themes/Sugar/fonts.normal.css?s=4.5.0g&c=" rel="stylesheet" type="text/css" title="font:normal" />
<link href="../../themes/Sugar/fonts.larger.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="font:larger" />
<link href="../../themes/Sugar/fonts.largest.css?s=4.5.0g&c=" rel="alternate stylesheet" type="text/css" title="font:largest" />

<script language="javascript" src="../../themes/Sugar/menu.js?s=4.5.0g&c="></script>
<script language="javascript" src="../../themes/Sugar/cookie.js?s=4.5.0g&c="></script>
<script language="javascript" src="../../themes/Sugar/style.js?s=4.5.0g&c="></script>
</head>
<form id="Search" name="Search" method="post" action="SelectFile.php?target=<?print $_GET['target'];?>&record=<?print $_GET['record'];?>&tab=<?print $_GET['tab'];?>">
<ul class="tablist">

<li <?if($_GET['tab']=="All")print 'class="active"';?>><a <?if($_GET['tab']=="All")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=All&amp;start=1&amp;reset=1">All</a></li>	
<li <?if($_GET['tab']=="EcmDocs")print 'class="active"';?>><a <?if($_GET['tab']=="EcmDocs")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmDocs&amp;start=1&amp;reset=1">EcmDocs</a></li>	
<li <?if($_GET['tab']=="EcmCorrespondenceIns")print 'class="active"';?>><a <?if($_GET['tab']=="EcmCorrespondenceIns")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmCorrespondenceIns&amp;start=1&amp;reset=1">Correspondence In</a></li>		
<li <?if($_GET['tab']=="EcmCorrespondenceOuts")print 'class="active"';?>><a <?if($_GET['tab']=="EcmCorrespondenceOuts")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmCorrespondenceOuts&amp;start=1&amp;reset=1">Correspondence Out</a></li>		
<li <?if($_GET['tab']=="EcmContracts")print 'class="active"';?>><a <?if($_GET['tab']=="EcmContracts")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmContracts&amp;start=1&amp;reset=1">Contracts</a></li>
<li <?if($_GET['tab']=="EcmInvoiceIns")print 'class="active"';?>><a <?if($_GET['tab']=="EcmInvoiceIns")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmInvoiceIns&amp;start=1&amp;reset=1">Invoice In</a></li>	
<li <?if($_GET['tab']=="EcmInvoiceOuts")print 'class="active"';?>><a <?if($_GET['tab']=="EcmInvoiceOuts")print 'class="current"';?> href="SelectFile.php?target=<?print $_GET['target'];?>&amp;tab=EcmInvoiceOuts&amp;start=1&amp;reset=1">Invoice Out</a></li>	
</ul>
<?
if($_GET['tab']=="All")
{
	print ' 
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1">Name</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input value="'.$_SESSION['all_name'].'" name="name" type="text" tabindex="1" size="30" maxlength="50"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot`3`">Description</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot`3`b">
       <textarea name="description" cols="25" rows="4" id="description" tabindex="`3`" title="Description">'.$_SESSION['all_description'].'</textarea>
     </span sugar="slot"></td>
  </tr>
   </table>
  </td>
 </tr>
</table>';
}
if($_GET['tab']=="EcmContracts")
{
	print '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1"></span sugar="slot">Name</td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input name="name" type="text" tabindex="1" size="30" maxlength="50" value="'.$_SESSION['ecmcontracts_name'].'"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel">Signed On</td>
     <td width="30%" valign="top" class="dataField"><input name="signedon" id="signedon_field" onBlur="SugarWidgetScheduler.update_time();" tabindex="1" size="10" maxlength="11" type="text" value="'.$_SESSION['ecmcontracts_signedon'].'">
       <slot><img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="signedon_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span></slot>
       <script type="text/javascript">
Calendar.setup ({
		inputField : "signedon_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "signedon_trigger", singleClick : true, step : 1
});
       </script></td>
	</tr> 
    <tr>
	  <td rowspan="3" valign="top" class="dataLabel">Description</td>
	  <td width="30%" rowspan="2" valign="top" class="dataField"><span sugar="slot`3b">
	    <textarea name="description" title="Description" tabindex="`3`" cols="25" rows="4">'.$_SESSION['ecmcontracts_description'].'</textarea>
	  </span sugar="slot"></td>
	  <td class="dataLabel" valign="top">Celtic Group</td>
      <td class="dataField"><input name="group_name" type="text" id="group_name" tabindex="1" value="'.$_SESSION['ecmcontracts_group_name'].'" size="25" maxlength="50" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"group_name"}});\' /></td>
    </tr>
    <tr>
      <td valign="top" class="dataLabel">Contractant</td>
      <td class="dataField"><input name="contractant_name" type="text" id="contractant_name" tabindex="1" value="'.$_SESSION['ecmcontracts_contractant_name'].'" size="25" maxlength="50" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"contractant_name"}});\' /></td>
    </tr>
   </table>
  </td>
 </tr>
</table>
';
}
if($_GET['tab']=="EcmCorrespondenceIns")
{
	print '
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1">Name</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input name="name" type="text" tabindex="1" size="30" maxlength="50" value="'.$_SESSION['ecmcorrespondenceins_name'].'"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel">Register On </td>
     <td width="30%" valign="top" class="dataField"><input name="reg_date" id="reg_date_field" onBlur="SugarWidgetScheduler.update_time();" tabindex="1" size="10" maxlength="11" type="text" value="'.$_SESSION['ecmcorrespondenceins_reg_date'].'" />
       <img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="reg_date_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span>
       <script type="text/javascript">
Calendar.setup ({
		inputField : "reg_date_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "reg_date_trigger", singleClick : true, step : 1
});
       </script></td>
	 </tr>
    <tr>
	  <td valign="top"><span class="dataLabel">Account Name From </span></td><td valign="top"><span class="dataField">
	    <input name="account_name_from" type="text" id="account_name_from" tabindex="1" size="25" maxlength="50" value="'.$_SESSION['ecmcorrespondenceins_account_name_from'].'" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"account_name_from"}});\' />
	  </span></td>
      <td class="dataLabel" valign="top">Account Name To </td>
      <td class="dataField"><input name="account_name_to" type="text" id="account_name_to" tabindex="1" size="25" maxlength="50" value="'.$_SESSION['ecmcorrespondenceins_account_name_to'].'" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"account_name_to"}});\' /></td>
    </tr>
    <tr>
      <td valign="top"><span class="dataLabel">Document Date </span></td>
      <td valign="top"><input name="document_date" id="document_date_field" onblur="SugarWidgetScheduler.update_time();" tabindex="11" size="10" maxlength="11" type="text" value="'.$_SESSION['ecmcorrespondenceins_document_date'].'" />
        <img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="document_date_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span>
      <script type="text/javascript">
Calendar.setup ({
		inputField : "document_date_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "document_date_trigger", singleClick : true, step : 1
});
  </script></td>
	  <td rowspan="3" valign="top" class="dataLabel"><span sugar="slot`3`">Description</span sugar="slot"></td>
      <td rowspan="3" valign="top" class="dataField"><span sugar="slot`3`b">
        <textarea name="description" title="Description" tabindex="3" cols="25" rows="4">'.$_SESSION['ecmcorrespondenceins_description'].'</textarea>
      </span sugar="slot"></td>
    </tr>
    <tr>
      <td valign="top"><span class="dataLabel">Stamp Date </span></td>
      <td valign="top"><input name="stamp_date" id="stamp_date_field" onblur="SugarWidgetScheduler.update_time();" tabindex="11" size="10" maxlength="11" type="text" value="'.$_SESSION['ecmcorrespondenceins_stamp_date'].'" />
        <img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="stamp_date_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span>
      <script type="text/javascript">
Calendar.setup ({
		inputField : "stamp_date_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "stamp_date_trigger", singleClick : true, step : 1
});
  </script></td>
    </tr>
    <tr>
      <td valign="top"><span class="dataLabel">Delivery Date </span></td>
      <td valign="top"><input name="delivery_date" id="delivery_date_field" onblur="SugarWidgetScheduler.update_time();" tabindex="11" size="10" maxlength="11" type="text" value="'.$_SESSION['ecmcorrespondenceins_delivery_date'].'" />
        <img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="delivery_date_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span>
      <script type="text/javascript">
Calendar.setup ({
		inputField : "delivery_date_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "delivery_date_trigger", singleClick : true, step : 1
});
  </script></td>
	  </tr>
   </table>
  </td>
 </tr>
</table>';
}
if($_GET['tab']=="EcmCorrespondenceOuts")
{
	print '
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1">Name</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input name="name" type="text" tabindex="1" size="30" maxlength="50" value="'.$_SESSION['ecmcorrespondenceouts_name'].'"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel">Document Date </td>
     <td width="30%" valign="top" class="dataField"><input value="'.$_SESSION['ecmcorrespondenceouts_document_date'].'" name="document_date" id="document_date_field" onBlur="SugarWidgetScheduler.update_time();" tabindex="11" size="10" maxlength="11" type="text" />
       <img src="../../themes/Sugar/images/jscalendar.gif" alt="Enter Date"  id="document_date_trigger" align="absmiddle"/> <span class="dateFormat">(yyyy-mm-dd)</span>
       <script type="text/javascript">
Calendar.setup ({
		inputField : "document_date_field", ifFormat : "%Y-%m-%d", showsTime : false, button : "document_date_trigger", singleClick : true, step : 1
});
       </script></td>
	 </tr>
    <tr>
	  <td valign="top"><span class="dataLabel">Account Name From </span></td><td valign="top"><span class="dataField">
	    <input name="account_from_name" type="text" id="account_from_name" value="'.$_SESSION['ecmcorrespondenceouts_account_from_name'].'" tabindex="1" size="25" maxlength="50" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"account_from_name"}});\' />
	  </span></td>
      <td class="dataLabel" valign="top">Account Name To </td>
      <td class="dataField"><input value="'.$_SESSION['ecmcorrespondenceouts_account_to_name'].'" name="account_to_name" type="text" id="account_to_name" tabindex="1" size="25" maxlength="50" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"account_to_name"}});\' /></td>
    </tr>
   </table>
  </td>
 </tr>
</table>
';
}
if($_GET['tab']=="EcmInvoiceIns" || $_GET['tab']=="EcmInvoiceOuts")
{
	print ' 
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1">Name</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input value="'.$_SESSION['ecminvoiceins_name'].'" name="name" type="text" tabindex="1" size="30" maxlength="50"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel">Filename</td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b">
       <input value="'.$_SESSION['ecminvoiceins_ekmn_filename'].'" name="ekmn_filename" title="Filename" type="text" tabindex="1" maxlength="255">
     </span sugar="slot"></td>
  </tr>
  <tr>
    <td rowspan="3" valign="top"><span class="dataLabel"><span sugar="slot`3`">Description</span sugar="slot"></span></td><td rowspan="3" valign="top"><span class="dataField"><span sugar="slot`3`b">
      <textarea name="ekmn_description" title="Description" tabindex="`3`" cols="25" rows="4">'.$_SESSION['ecminvoiceins_ekmn_description'].'</textarea>
    </span sugar="slot"></span></td>
       
        	<td valign="top" class="dataLabel">From</td>
  	<td valign="top" class="dataField"><input value="'.$_SESSION['ecminvoiceins_from_name'].'" name="from_name" type="text" id="from_name" tabindex="1" title="From" maxlength="255" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"from_name"}});\' /></td>
        </tr>
  <tr>
    <td valign="top" class="dataLabel">To</td>
    <td valign="top" class="dataField"><input value="'.$_SESSION['ecminvoiceins_to_name'].'" name="to_name" type="text" id="to_name" tabindex="1" title="To" maxlength="255" /><input title="Select" accessKey="" type="button" tabindex="9" class="button" value="Select" name=btn1
  	  		       onclick=\'open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"Search","field_to_name_array":{"name":"to_name"}});\' /></td>
  </tr>
  <tr>
    <td valign="top" class="dataLabel">&nbsp;</td>
    <td valign="top" class="dataField">&nbsp;</td>
  </tr>
   </table>
  </td>
 </tr>
</table>';
}

if($_GET['tab']=="EcmDocs")
{
	print ' 
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px"   class="tabForm">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot1">Name</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot1b"><input value="'.$_SESSION['ecmdocs_name'].'" name="name" type="text" tabindex="1" size="30" maxlength="50"></span sugar="slot"></td>
     <td width="20%" valign="top" class="dataLabel"><span sugar="slot`3`">Description</span sugar="slot"></td>
     <td width="30%" valign="top" class="dataField"><span sugar="slot`3`b">
       <textarea name="description" cols="25" rows="4" id="description" tabindex="`3`" title="Description">'.$_SESSION['ecmdocs_description'].'</textarea>
     </span sugar="slot"></td>
  </tr>
   </table>
  </td>
 </tr>
</table>';
}
?>
<input type="submit" name="search" value="Search" class="button">
<input type="submit" name="clear" value="Clear" class="button">
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top"><br><?
	if($_GET['iddirs']=="")$_GET['iddirs']=$_SESSION['email_iddir'];
	print display_dir_data_email(0,"",$_SESSION['authenticated_user_id'],$_GET['target'],$_GET['tab']);?></td>
    <td valign="top"><?
////////////////////////EcmContracts/////////////////////////
if($_GET['tab']=="EcmContracts" or  $_GET['tab']=="All")
{
	if(!$_GET['ecmcontract_start'])$_GET['ecmcontract_start']=0;
	$il=10;
	if($_GET['ecmcontract_start']==0 || $_GET['ecmcontract_start']=="")
	{
		if(!$ecmcontractsw)$_SESSION['ecmcontract_where']="id='xxx'";
		else $_SESSION['ecmcontract_where']=$ecmcontractsw;
	}
	
	if(!$_GET['ecmcontracts_order_by'])$ecmcontracts_order_by="date_entered";
	else $ecmcontracts_order_by=$_GET['ecmcontracts_order_by'];
	
	if(!$_GET['ecmcontracts_sorder']){$_GET['ecmcontracts_sorder']="desc";$ecmcontracts_sorder="asc";}
	elseif($_GET['ecmcontracts_sorder']=="asc")$ecmcontracts_sorder="desc";
	elseif($_GET['ecmcontracts_sorder']=="desc")$ecmcontracts_sorder="asc";
	
	$z="select distinct * from ecmcontracts where ".$_SESSION['ecmcontract_where']." order by ".$ecmcontracts_order_by." ".$_GET['ecmcontracts_sorder']." limit ".$_GET['ecmcontract_start'].",".$il;
	$w=mysql_query($z);
	$ile=mysql_num_rows(mysql_query("select distinct id from ecmcontracts where ".$_SESSION['ecmcontract_where']." order by name"));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecmcontract_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecmcontract_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecmcontract_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcontract_start']+$il;
		$next='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecmcontract_start']>0 && $_GET['ecmcontract_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcontract_start']+$il;
		$next='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecmcontract_start']-$il;
		$previous='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecmcontract_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecmcontract_start']-$il;
		$previous='<a href="SelectFile.php?ecmcontracts_order_by='.$_GET['ecmcontracts_order_by'].'&ecmcontracts_sorder='.$_GET['ecmcontracts_sorder'].'&ecmcontract_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table width="100%" cellpadding="0" cellspacing="0" border="0" class="h3Row"><tr><td nowrap><h3>Contracts List</h3></td><td width="100%"><IMG height="1" width="1" src="include/images/blank.gif" alt=""></td></tr></table><table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table></td>
</tr>

	<tr height="20">
	<td scope="col" width="40%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcontracts_order_by=name&ecmcontracts_sorder='.$ecmcontracts_sorder.'">Name</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcontracts_order_by=signedon&ecmcontracts_sorder='.$ecmcontracts_sorder.'">Signed On</td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcontracts_order_by=group_name&ecmcontracts_sorder='.$ecmcontracts_sorder.'">Celtic Group</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcontracts_order_by=contractant_name&ecmcontracts_sorder='.$ecmcontracts_sorder.'">Contractant</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcontracts_order_by=relation&ecmcontracts_sorder='.$ecmcontracts_sorder.'">Assigned</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP>User</td>
	</tr>';
	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecmcontracts&relationid=ecmcontract_id&module=EcmContracts","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmContract_'.$r['id'].'\',\''.$r['name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmContract_'.$r['id'].'"  href="javascript:parent.opener.document.getElementById(\'documentName'.$_GET['target'].'\').value=\''.$fname.'\';parent.opener.document.getElementById(\'documentId'.$_GET['target'].'\').value=\''.$rr['id'].'\';window.close();" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap>'.$r['signedon'].'</td>
	
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmContract_'.$r['id'].'_group\',\''.$r['group_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmContract_'.$r['id'].'_group" href="../../index.php?action=DetailView&module=Accounts&record='.$r['group_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['group_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmContract_'.$r['id'].'_contractant\',\''.$r['contractant_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmContract_'.$r['id'].'_contractant" href="../../index.php?action=DetailView&module=Accounts&record='.$r['contractant_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['contractant_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.get_assigned_user_name_in_search($r['assigned_user_id']).'</td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
	}
	print '</table>';
}
////////////////////////EcmCorrespondenceIns/////////////////////////
if($_GET['tab']=="EcmCorrespondenceIns" or  $_GET['tab']=="All")
{
		if(!$_GET['ecmcorrespondencein_start'])$_GET['ecmcorrespondencein_start']=0;
	$il=10;
	if($_GET['ecmcorrespondencein_start']==0 || $_GET['ecmcorrespondencein_start']=="")
	{
		if(!$ecmcorrespondenceinsw)$_SESSION['ecmcorrespondencein_where']="id='xxx'";
		else $_SESSION['ecmcorrespondencein_where']=$ecmcorrespondenceinsw;
	}
	
	if(!$_GET['ecmcorrespondenceins_order_by'])$ecmcorrespondenceins_order_by="date_entered";
	else $ecmcorrespondenceins_order_by=$_GET['ecmcorrespondenceins_order_by'];
	
	if(!$_GET['ecmcorrespondenceins_sorder']){$_GET['ecmcorrespondenceins_sorder']="desc";$ecmcorrespondenceins_sorder="asc";}
	elseif($_GET['ecmcorrespondenceins_sorder']=="asc")$ecmcorrespondenceins_sorder="desc";
	elseif($_GET['ecmcorrespondenceins_sorder']=="desc")$ecmcorrespondenceins_sorder="asc";
	
	$z="select distinct * from ecmcorrespondenceins where ".$_SESSION['ecmcorrespondencein_where']." order by ".$ecmcorrespondenceins_order_by." ".$_GET['ecmcorrespondenceins_sorder']." limit ".$_GET['ecmcorrespondencein_start'].",".$il;
	$w=mysql_query($z);
	$ile=mysql_num_rows(mysql_query("select distinct id from ecmcorrespondenceins where ".$_SESSION['ecmcorrespondencein_where']." order by name"));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecmcorrespondencein_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecmcorrespondencein_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecmcorrespondencein_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcorrespondencein_start']+$il;
		$next='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecmcorrespondencein_start']>0 && $_GET['ecmcorrespondencein_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcorrespondencein_start']+$il;
		$next='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecmcorrespondencein_start']-$il;
		$previous='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecmcorrespondencein_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecmcorrespondencein_start']-$il;
		$previous='<a href="SelectFile.php?ecmcorrespondenceins_order_by='.$_GET['ecmcorrespondenceins_order_by'].'&ecmcorrespondenceins_sorder='.$_GET['ecmcorrespondenceins_sorder'].'&ecmcorrespondencein_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table width="100%" cellpadding="0" cellspacing="0" border="0" class="h3Row"><tr><td nowrap><h3>Correspondence In List</h3></td><td width="100%"><IMG height="1" width="1" src="include/images/blank.gif" alt=""></td></tr></table><table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table></td>
</tr>

	<tr height="20">
	<td scope="col" width="40%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceins_order_by=name&ecmcorrespondenceins_sorder='.$ecmcorrespondenceins_sorder.'">Name</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceins_order_by=reg_date&ecmcorrespondenceins_sorder='.$ecmcorrespondenceins_sorder.'">Register Date</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceins_order_by=account_name_from&ecmcorrespondenceins_sorder='.$ecmcorrespondenceins_sorder.'">From</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceins_order_by=account_name_to&ecmcorrespondenceins_sorder='.$ecmcorrespondenceins_sorder.'">To</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceins_order_by=relation&ecmcorrespondenceins_sorder='.$ecmcorrespondenceins_sorder.'">Assigned</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP>User</td>
	</tr>';
	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecmcorrespondenceins&relationid=ecmcorrespondencein_id&module=EcmCorrespondenceIns","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmCorrespondenceIn_'.$r['id'].'\',\''.$r['name'].'\',\''.$r['description'].'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceIn_'.$r['id'].'"  href="javascript:parent.opener.document.getElementById(\'documentName'.$_GET['target'].'\').value=\''.$fname.'\';parent.opener.document.getElementById(\'documentId'.$_GET['target'].'\').value=\''.$rr['id'].'\';window.close();" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
	
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap>'.$r['reg_date'].'</td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmCorrespondenceIn_'.$r['id'].'_from\',\''.$r['account_name_from'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceIn_'.$r['id'].'_from"  href="../../index.php?action=DetailView&module=Accounts&record='.$r['account_from'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['account_name_from'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmCorrespondenceIn_'.$r['id'].'_to\',\''.$r['account_name_to'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceIn_'.$r['id'].'_to"  href="../../index.php?action=DetailView&module=Accounts&record='.$r['account_to'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['account_name_to'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.get_assigned_user_name_in_search($r['assigned_user_id']).'</td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
		}
	print '</table>';
}
////////////////////////EcmCorrespondenceOuts/////////////////////////
if($_GET['tab']=="EcmCorrespondenceOuts" or  $_GET['tab']=="All")
{
		if(!$_GET['ecmcorrespondenceout_start'])$_GET['ecmcorrespondenceout_start']=0;
	$il=10;
	if($_GET['ecmcorrespondenceout_start']==0 || $_GET['ecmcorrespondenceout_start']=="")
	{
		if(!$ecmcorrespondenceoutsw)$_SESSION['ecmcorrespondenceout_where']="id='xxx'";
		else $_SESSION['ecmcorrespondenceout_where']=$ecmcorrespondenceoutsw;
	}
	
	if(!$_GET['ecmcorrespondenceouts_order_by'])$ecmcorrespondenceouts_order_by="date_entered";
	else $ecmcorrespondenceouts_order_by=$_GET['ecmcorrespondenceouts_order_by'];
	
	if(!$_GET['ecmcorrespondenceouts_sorder']){$_GET['ecmcorrespondenceouts_sorder']="desc";$ecmcorrespondenceouts_sorder="asc";}
	elseif($_GET['ecmcorrespondenceouts_sorder']=="asc")$ecmcorrespondenceouts_sorder="desc";
	elseif($_GET['ecmcorrespondenceouts_sorder']=="desc")$ecmcorrespondenceouts_sorder="asc";
	
	$z="select distinct * from ecmcorrespondenceouts where ".$_SESSION['ecmcorrespondenceout_where']." order by ".$ecmcorrespondenceouts_order_by." ".$_GET['ecmcorrespondenceouts_sorder']." limit ".$_GET['ecmcorrespondenceout_start'].",".$il;
	
	$w=mysql_query($z);
	$ile=mysql_num_rows(mysql_query("select distinct id from ecmcorrespondenceouts where ".$_SESSION['ecmcorrespondenceout_where']." order by name"));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecmcorrespondenceout_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecmcorrespondenceout_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecmcorrespondenceout_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcorrespondenceout_start']+$il;
		$next='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecmcorrespondenceout_start']>0 && $_GET['ecmcorrespondenceout_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmcorrespondenceout_start']+$il;
		$next='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecmcorrespondenceout_start']-$il;
		$previous='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecmcorrespondenceout_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecmcorrespondenceout_start']-$il;
		$previous='<a href="SelectFile.php?ecmcorrespondenceouts_order_by='.$_GET['ecmcorrespondenceouts_order_by'].'&ecmcorrespondenceouts_sorder='.$_GET['ecmcorrespondenceouts_sorder'].'&ecmcorrespondenceout_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table width="100%" cellpadding="0" cellspacing="0" border="0" class="h3Row"><tr><td nowrap><h3>Correspondence Out List</h3></td><td width="100%"><IMG height="1" width="1" src="include/images/blank.gif" alt=""></td></tr></table>
<table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table></td>
</tr>

	<tr height="20">
	<td scope="col" width="40%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceouts_order_by=name&ecmcorrespondenceouts_sorder='.$ecmcorrespondenceouts_sorder.'">Name</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceouts_order_by=reg_date&ecmcorrespondenceouts_sorder='.$ecmcorrespondenceouts_sorder.'">Registered On</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceouts_order_by=account_from_name&ecmcorrespondenceouts_sorder='.$ecmcorrespondenceouts_sorder.'">From</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceouts_order_by=account_to_name&ecmcorrespondenceouts_sorder='.$ecmcorrespondenceouts_sorder.'">To</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmcorrespondenceouts_order_by=relation&ecmcorrespondenceouts_sorder='.$ecmcorrespondenceouts_sorder.'">Assigned</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP>User</td>
	</tr>';
	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecmcorrespondenceouts&relationid=ecmcorrespondenceout_id&module=EcmCorrespondenceOuts","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmCorrespondenceOut_'.$r['id'].'\',\''.$r['name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceOut_'.$r['id'].'" href="javascript:parent.opener.document.getElementById(\'documentName'.$_GET['target'].'\').value=\''.$fname.'\';parent.opener.document.getElementById(\'documentId'.$_GET['target'].'\').value=\''.$rr['id'].'\';window.close();" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
	
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap>'.$r['document_date'].'</td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmCorrespondenceOut_'.$r['id'].'_from\',\''.$r['account_from_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceOut_'.$r['id'].'_from"  href="../../index.php?action=DetailView&module=Accounts&record='.$r['account_from'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['account_from_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmCorrespondenceOut_'.$r['id'].'_to\',\''.$r['account_to_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmCorrespondenceOut_'.$r['id'].'_to" href="../../index.php?action=DetailView&module=Accounts&record='.$r['account_to'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['account_to_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.get_assigned_user_name_in_search($r['assigned_user_id']).'</td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
	}
	print '</table>';
}
////////////////////////EcmInvoiceIns/////////////////////////
if($_GET['tab']=="EcmInvoiceIns" or  $_GET['tab']=="All")
{
	if(!$_GET['ecminvoicein_start'])$_GET['ecminvoicein_start']=0;
	$il=10;
	if($_GET['ecminvoicein_start']==0 || $_GET['ecminvoicein_start']=="")
	{
		if(!$ecminvoiceinsw)$_SESSION['ecminvoicein_where']="id='xxx'";
		else $_SESSION['ecminvoicein_where']=$ecminvoiceinsw;
	}
	
	if(!$_GET['ecminvoiceins_order_by'])$ecminvoiceins_order_by="date_entered";
	else $ecminvoiceins_order_by=$_GET['ecminvoiceins_order_by'];
	
	if(!$_GET['ecminvoiceins_sorder']){$_GET['ecminvoiceins_sorder']="desc";$ecminvoiceins_sorder="asc";}
	elseif($_GET['ecminvoiceins_sorder']=="asc")$ecminvoiceins_sorder="desc";
	elseif($_GET['ecminvoiceins_sorder']=="desc")$ecminvoiceins_sorder="asc";
	
	$z="select distinct * from ecminvoiceins where ".$_SESSION['ecminvoicein_where']." order by ".$ecminvoiceins_order_by." ".$_GET['ecminvoiceins_sorder']." limit ".$_GET['ecminvoicein_start'].",".$il;
	$w=mysql_query($z);
	$ile=mysql_num_rows(mysql_query("select distinct id from ecminvoiceins where ".$_SESSION['ecminvoicein_where']." order by name"));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecminvoicein_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecminvoicein_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecminvoicein_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecminvoicein_start']+$il;
		$next='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecminvoicein_start']>0 && $_GET['ecminvoicein_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecminvoicein_start']+$il;
		$next='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecminvoicein_start']-$il;
		$previous='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecminvoicein_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecminvoicein_start']-$il;
		$previous='<a href="SelectFile.php?ecminvoiceins_order_by='.$_GET['ecminvoiceins_order_by'].'&ecminvoiceins_sorder='.$_GET['ecminvoiceins_sorder'].'&ecminvoicein_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table width="100%" cellpadding="0" cellspacing="0" border="0" class="h3Row"><tr><td nowrap><h3>Invoice In List</h3></td><td width="100%"><IMG height="1" width="1" src="include/images/blank.gif" alt=""></td></tr></table><table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table>
</td>
</tr>

	<tr height="20">
	<td scope="col" width="40%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceins_order_by=name&ecminvoiceins_sorder='.$ecminvoiceins_sorder.'">Name</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceins_order_by=reg_date&ecminvoiceins_sorder='.$ecminvoiceins_sorder.'">Date</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceins_order_by=from_name&ecminvoiceins_sorder='.$ecminvoiceins_sorder.'">From</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceins_order_by=to_name&ecminvoiceins_sorder='.$ecminvoiceins_sorder.'">To</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceins_order_by=relation&ecminvoiceins_sorder='.$ecminvoiceins_sorder.'">Assigned</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP>User</td>
	</tr>';

	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<!-- BEGIN: row -->
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecminvoiceins&relationid=ecminvoicein_id&module=EcmInvoiceIns","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmInvoiceIn_'.$r['id'].'\',\''.$r['name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceIn_'.$r['id'].'"  href="index.php?action=DetailView&module=EcmInvoiceIns&record='.$r['id'].'&tab='.$_GET['tab'].'&fromsearch=1" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
	
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap>'.$r['reg_date'].'</td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmInvoiceIn_'.$r['id'].'_from\',\''.$r['from_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceIn_'.$r['id'].'_from" href="../../index.php?action=DetailView&module=Accounts&record='.$r['from_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['from_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmInvoiceIn_'.$r['id'].'_to\',\''.$r['to_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceIn_'.$r['id'].'_to" href="../../index.php?action=DetailView&module=Accounts&record='.$r['to_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['to_name'],20).'</a></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff"><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
	}
	print '</table>';
}
////////////////////////EcmInvoiceOuts/////////////////////////
if($_GET['tab']=="EcmInvoiceOuts" or  $_GET['tab']=="All")
{
	if(!$_GET['ecminvoiceout_start'])$_GET['ecminvoiceout_start']=0;
	$il=10;
	if($_GET['ecminvoiceout_start']==0 || $_GET['ecminvoiceout_start']=="")
	{
		if(!$ecminvoiceoutsw)$_SESSION['ecminvoiceout_where']="id='xxx'";
		else $_SESSION['ecminvoiceout_where']=$ecminvoiceoutsw;
	}
	
	if(!$_GET['ecminvoiceouts_order_by'])$ecminvoiceouts_order_by="date_entered";
	else $ecminvoiceouts_order_by=$_GET['ecminvoiceouts_order_by'];
	
	if(!$_GET['ecminvoiceouts_sorder']){$_GET['ecminvoiceouts_sorder']="desc";$ecminvoiceouts_sorder="asc";}
	elseif($_GET['ecminvoiceouts_sorder']=="asc")$ecminvoiceouts_sorder="desc";
	elseif($_GET['ecminvoiceouts_sorder']=="desc")$ecminvoiceouts_sorder="asc";
	
	
	$z="select distinct * from ecminvoiceouts where ".$_SESSION['ecminvoiceout_where']." order by ".$ecminvoiceouts_order_by." ".$_GET['ecminvoiceouts_sorder']." limit ".$_GET['ecminvoiceout_start'].",".$il;
	$w=mysql_query($z);
	$ile=mysql_num_rows(mysql_query("select distinct id from ecminvoiceouts where ".$_SESSION['ecminvoiceout_where']." order by name"));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecminvoiceout_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecminvoiceout_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecminvoiceout_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecminvoiceout_start']+$il;
		$next='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecminvoiceout_start']>0 && $_GET['ecminvoiceout_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecminvoiceout_start']+$il;
		$next='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecminvoiceout_start']-$il;
		$previous='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecminvoiceout_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecminvoiceout_start']-$il;
		$previous='<a href="SelectFile.php?ecminvoiceouts_order_by='.$_GET['ecminvoiceouts_order_by'].'&ecminvoiceouts_sorder='.$_GET['ecminvoiceouts_sorder'].'&ecminvoiceout_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table width="100%" cellpadding="0" cellspacing="0" border="0" class="h3Row"><tr><td nowrap><h3>Invoice Out List</h3></td><td width="100%"><IMG height="1" width="1" src="include/images/blank.gif" alt=""></td></tr></table>
<table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table>
</td>
</tr>

	<tr height="20">
	<td scope="col" width="40%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceouts_order_by=name&ecminvoiceouts_sorder='.$ecminvoiceouts_sorder.'">Name</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceouts_order_by=reg_date&ecminvoiceouts_sorder='.$ecminvoiceouts_sorder.'">Date</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceouts_order_by=from_name&ecminvoiceouts_sorder='.$ecminvoiceouts_sorder.'">From</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceouts_order_by=to_name&ecminvoiceouts_sorder='.$ecminvoiceouts_sorder.'">To</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecminvoiceouts_order_by=relation&ecminvoiceouts_sorder='.$ecminvoiceouts_sorder.'">Assigned</a></td>
	<td scope="col" width="15%" class="listViewThS1" NOWRAP>User</td>
	</tr>';
	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<!-- BEGIN: row -->
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecminvoiceouts&relationid=ecminvoiceout_id&module=EcmInvoiceOuts","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmInvoiceOut_'.$r['id'].'\',\''.$r['name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceOut_'.$r['id'].'"  href="javascript:parent.opener.document.getElementById(\'documentName'.$_GET['target'].'\').value=\''.$fname.'\';parent.opener.document.getElementById(\'documentId'.$_GET['target'].'\').value=\''.$rr['id'].'\';window.close();" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
	
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap>'.$r['reg_date'].'</td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmInvoiceOut_'.$r['id'].'_from\',\''.$r['from_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceOut_'.$r['id'].'_from" href="../../index.php?action=DetailView&module=Accounts&record='.$r['from_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['from_name'],20).'</a></td>
   		<td valign=TOP class="oddListRowS1" bgcolor="#ffffff" nowrap><a onmouseover="showdescription(\'EcmInvoiceOut_'.$r['id'].'_to\',\''.$r['to_name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmInvoiceOut_'.$r['id'].'_to"  href="../../index.php?action=DetailView&module=Accounts&record='.$r['to_id'].'" class="listViewTdLinkS1">'.cut_name_in_search($r['to_name'],20).'</a></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff"><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.get_assigned_user_name_in_search($r['assigned_user_id']).'</td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
	}
	print '</table>';
}
////////////////////////EcmDocs/////////////////////////
if($_GET['tab']=="EcmDocs" or  $_GET['tab']=="All")
{
	if(!$_GET['ecmdoc_start'])$_GET['ecmdoc_start']=0;
	$il=10;
	if($_GET['ecmdoc_start']==0 || $_GET['ecmdoc_start']=="")
	{
		if(!$ecmdocsw)$_SESSION['ecmdoc_where']="id='xxx'";
		else $_SESSION['ecmdoc_where']=$ecmdocsw;
	}
	
	if(!$_GET['ecmdocs_order_by'])$ecmdocs_order_by="date_entered";
	else $ecmdocs_order_by=$_GET['ecmdocs_order_by'];
	
	if(!$_GET['ecmdocs_sorder']){$_GET['ecmdocs_sorder']="desc";$ecmdocs_sorder="asc";}
	elseif($_GET['ecmdocs_sorder']=="asc")$ecmdocs_sorder="desc";
	elseif($_GET['ecmdocs_sorder']=="desc")$ecmdocs_sorder="asc";
	
	$z="select distinct * from ecmdocs where ".$_SESSION['ecmdoc_where']." order by ".$ecmdocs_order_by." ".$_GET['ecmdocs_sorder']." limit ".$_GET['ecmdoc_start'].",".$il;
	$w=mysql_query($z);
	
	$ile=mysql_num_rows(mysql_query("select distinct id from ecmdocs where ".$_SESSION['ecmdoc_where']." order by ".$ecmdocs_order_by." ".$ecmdocs_sorder));
	if($ile<$il)$ilenastronie=$ile;
	else $ilenastronie=$il;
	$od=$_GET['ecmdoc_start']+1;
	$do=$od+$il-1;
	$endl=floor($ile/$il);
	$endl=$endl*$il;
	if($ile==0)$od=0;
	if($_GET['ecmdoc_start']+$il>=$ile)$do=$ile;
	if($ile==0 || $ile<=$il)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
	}
	else
	{
	if($_GET['ecmdoc_start']==0)
	{
		$start='<img src="../../themes/Sugar/images/start_off.gif" alt="Start" align="absmiddle" border="0" width="13" height="11">';
		$previous='<img src="../../themes/Sugar/images/previous_off.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11">';
		$end='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmdoc_start']+$il;
		$next='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	if($_GET['ecmdoc_start']>0 && $_GET['ecmdoc_start']<$ile)
	{
		$start='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$endl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">End&nbsp;<img src="../../themes/Sugar/images/end.gif" alt="End" align="absmiddle" border="0" width="13" height="11"></a>';
		$nextl=$_GET['ecmdoc_start']+$il;
		$next='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$nextl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Next&nbsp;<img src="../../themes/Sugar/images/next.gif" alt="Next" align="absmiddle" border="0" width="8" height="11"></a>';
		$previousl=$_GET['ecmdoc_start']-$il;
		$previous='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	
	if($_GET['ecmdoc_start']+$il>=$ile)
	{
		$start='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start=0&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Start&nbsp;<img src="../../themes/Sugar/images/start.gif" alt="Start" align="absmiddle" border="0" width="13" height="11"></a>';
		$end='<img src="../../themes/Sugar/images/end_off.gif" alt="End" align="absmiddle" border="0" width="13" height="11">';
		$next='<img src="../../themes/Sugar/images/next_off.gif" alt="Next" align="absmiddle" border="0" width="8" height="11">';
		$previousl=$_GET['ecmdoc_start']-$il;
		$previous='<a href="SelectFile.php?ecmdocs_order_by='.$_GET['ecmdocs_order_by'].'&ecmdocs_sorder='.$_GET['ecmdocs_sorder'].'&ecmdoc_start='.$previousl.'&tab='.$_GET['tab'].'"  class="listViewPaginationLinkS1">Previous&nbsp;<img src="../../themes/Sugar/images/previous.gif" alt="Previous" align="absmiddle" border="0" width="8" height="11"></a>';
	}
	}
	print '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div></p><p><table class="h3Row" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td nowrap="nowrap"><h3>Files List</h3></td><td width="100%"><img src="index_files/blank.gif" alt="" height="1" width="1"></td>
	  </tr>
</tbody></table>
<table class="listView" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="20" align="right">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="left" class="listViewPaginationTdS1">&nbsp;</td>
					<td class="listViewPaginationTdS1" align="right" nowrap="nowrap" id="listViewPaginationButtons">						
													'.$start.'&nbsp;Start&nbsp;&nbsp;

																			'.$previous.'&nbsp;Previous&nbsp;
													<span class="pageNumbers">('.$od.' - '.$do.' of '.$ile.')</span>
													&nbsp;'.$next.'&nbsp;
																			'.$end.'</td>
											</td>
				</tr>
			</table>
</td>
</tr>

	<tr height="20">
	<td scope="col" width="35%" class="listViewThS1" nowrap="nowrap"><slot><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmdocs_order_by=name&ecmdocs_sorder='.$ecmdocs_sorder.'">Name</a></slot></td>
	<td scope="col" width="15%" class="listViewThS1" nowrap="nowrap"><slot><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmdocs_order_by=date_entered&ecmdocs_sorder='.$ecmdocs_sorder.'">Registered On</a></slot></td>
	<td scope="col" width="25%" class="listViewThS1" nowrap="nowrap"><slot><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmdocs_order_by=account_name&ecmdocs_sorder='.$ecmdocs_sorder.'">Account</a></slot></td>
	<td scope="col" width="15%" class="listViewThS1" nowrap="nowrap"><slot>Version</slot></td>
	<td scope="col" width="15%" class="listViewThS1" nowrap="nowrap"><slot><a class="listViewThLinkS1" href="SelectFile.php?tab='.$_REQUEST['tab'].'&ecmdocs_order_by=relation&ecmdocs_sorder='.$ecmdocs_sorder.'">Assigned</a></slot></td>
	<td scope="col" width="15%" class="listViewThS1" nowrap="nowrap"><slot>User</slot></td>
	</tr>';
	
	while($r=mysql_fetch_array($w))
	{
		$rr=mysql_fetch_array(mysql_query("select id,name from ecmfiles_versions where file_id='".$r['file_id']."'"));
		$filename=$rr['name'];
		$ext=explode(".",$filename);
		$roz=$ext[count($ext)-1];
		$fname=$r['name'].".".$roz;
		print '
<!-- BEGIN: row -->
<tr height="20">

	<td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">
	 <slot><div style="display:inline;" id="show_related_ecm'.$r['id'].'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><script language="javascript1.2">mintajaxget("show_related_ecm.php?name='.$r['name'].'&record='.$r['id'].'&relation=ecmdocuments_ecmdocs&relationid=ecmdoc_id&module=EcmDocs","show_related_ecm'.$r['id'].'");</script><a onmouseover="showdescription(\'EcmDoc_'.$r['id'].'\',\''.$r['name'].'\',\'\');" onmouseout="hidedescription();" id="link-EcmDoc_'.$r['id'].'"  href="javascript:parent.opener.document.getElementById(\'documentName'.$_GET['target'].'\').value=\''.$fname.'\';parent.opener.document.getElementById(\'documentId'.$_GET['target'].'\').value=\''.$rr['id'].'\';window.close();" class="listViewTdLinkS1">'.cut_name_in_search($r['name'],20).'</a></slot>	</td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.$r['date_entered'][0].$r['date_entered'][1].$r['date_entered'][2].$r['date_entered'][3].$r['date_entered'][4].$r['date_entered'][5].$r['date_entered'][6].$r['date_entered'][7].$r['date_entered'][8].$r['date_entered'][9].'</td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff"><a onmouseover="
		var t=\''.$r['account_name'].'\';
		if(t.length>20)
		{
			showdescription(\'EcmDoc_'.$r['id'].'\',\''.$r['account_name'].'\',\'\');
		}
		"
		onmouseout="
		var t=\''.$r['account_name'].'\';
		if(t.length>20)
		{
			hidedescription();
		}
		" id="link-EcmDoc_'.$r['id'].'" href="{URL_PREFIX}../../index.php?action=DetailView&module=Accounts&record='.$r['account_id'].'" class="listViewTdLinkS1"><script language="javascript">
	var text="";
	var t="";
	var i=0;
	t="'.$r['account_name'].'";
	if(t.length>20)
	{
		for(i=0;i<=19;i++)
		{
			text+=t.charAt(i);
		}
		text=text+"...";
	}
	else
	{
		text=t;
	}
	document.write(text);
</script></a></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff"><div id="version'.$r['id'].'"></div><script language="javascript">mintajaxget("../../modules/EcmDocs/show_version.php?file_id='.$r['file_id'].'","version'.$r['id'].'");</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff"><script language="javascript">
	var r="'.$r['relation'].'";
	if(r==1)document.write("yes");
	if(r==2)document.write("no");
</script></td>
	 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#ffffff">'.get_assigned_user_name_in_search($r['assigned_user_id']).'</td>

</tr>
<tr><td colspan="27" class="listViewHRS1"></td></tr>
	';
	}
	print '</table>';
}
mysql_close($sql);
?></td>
  </tr>
</table>
