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'];
$ids=search_ids($record,"").$record;
$idy=explode("||",$ids);
////////////////////////Contracts/////////////////////////
if($_GET['tab']=="Contracts" or $_GET['tab']=="All")
{
foreach($idy as $idx)
{
$z="select contract_id from ecmdocuments_contracts where ecmdocument_id='".$idx."' and deleted='0'";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
if($_GET['tab']=="Contracts")
{
if(mysql_num_rows(mysql_query("select id from contracts where id='".$r['contract_id']."' and name like '%".$_POST['name']."%' and kntr_description like '%".$_POST['kntr_description']."%' and group_name like '%".$_POST['group_name']."%' and contractant_name like '%".$_POST['contractant_name']."%' and signedon like '%".$_POST['signedon']."%' and deleted='0'"))>0)$contracts[]=$r['contract_id'];
}
else
{
if(mysql_num_rows(mysql_query("select id from contracts where id='".$r['contract_id']."' and name like '%".$_POST['name']."%' and kntr_description like '%".$_POST['description']."%' and deleted='0'"))>0)$contracts[]=$r['contract_id'];
}
}
}
$contractsw="";
$i=0;
if(count($contracts)>0)
{
foreach($contracts as $contract)
{
if($i==0)$or="";
else $or=" or";
$contractsw.=$or." id='".$contract."'";
$i++;
}
}
}
////////////////////////Correspondences/////////////////////////
if($_GET['tab']=="Correspondences" or $_GET['tab']=="All")
{
foreach($idy as $idx)
{
$z="select correspondence_id from ecmdocuments_correspondences where ecmdocument_id='".$idx."' and deleted='0'";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
if($_GET['tab']=="Correspondences")
{
if(mysql_num_rows(mysql_query("select id from correspondences where id='".$r['correspondence_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 krsp_description like '%".$_POST['krsp_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)$correspondences[]=$r['correspondence_id'];
}
else
{
if(mysql_num_rows(mysql_query("select id from correspondences where id='".$r['correspondence_id']."' and name like '%".$_POST['name']."%' and krsp_description like '%".$_POST['description']."%' and deleted='0'"))>0)$correspondences[]=$r['correspondence_id'];
}
}
}
$correspondencesw="";
$i=0;
if(count($correspondences)>0)
{
foreach($correspondences as $correspondence)
{
if($i==0)$or="";
else $or=" or";
$correspondencesw.=$or." id='".$correspondence."'";
$i++;
}
}
}
////////////////////////EcmInvoices/////////////////////////
if($_GET['tab']=="EcmInvoices" or $_GET['tab']=="All")
{
foreach($idy as $idx)
{
$z="select ecminvoice_id from ecmdocuments_ecminvoices where ecmdocument_id='".$idx."' and deleted='0'";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
if($_GET['tab']=="EcmInvoices")
{
if(mysql_num_rows(mysql_query("select id from ecminvoices where id='".$r['ecminvoice_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)$ecminvoices[]=$r['ecminvoice_id'];
}
else
{
if(mysql_num_rows(mysql_query("select id from ecminvoices where id='".$r['ecminvoice_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecminvoices[]=$r['ecminvoice_id'];
}
}
}
$ecminvoicesw="";
$i=0;
if(count($ecminvoices)>0)
{
foreach($ecminvoices as $ecminvoice)
{
if($i==0)$or="";
else $or=" or";
$ecminvoicesw.=$or." id='".$ecminvoice."'";
$i++;
}
}
}
////////////////////////Contracts/////////////////////////
if($_GET['tab']=="EcmFiles" or $_GET['tab']=="All")
{
foreach($idy as $idx)
{
$z="select ecmfile_id from ecmdocuments_ecmfiles where ecmdocument_id='".$idx."' and deleted='0'";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
if($_GET['tab']=="EcmFiles")
{
if(mysql_num_rows(mysql_query("select id from ecmfiles where id='".$r['ecmfile_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmfiles[]=$r['ecmfile_id'];
}
else
{
if(mysql_num_rows(mysql_query("select id from ecmfiles where id='".$r['ecmfile_id']."' and name like '%".$_POST['name']."%' and description like '%".$_POST['description']."%' and deleted='0'"))>0)$ecmfiles[]=$r['ecmfile_id'];
}
}
}
$ecmfilesw="";
$i=0;
if(count($ecmfiles)>0)
{
foreach($ecmfiles as $ecmfile)
{
if($i==0)$or="";
else $or=" or";
$ecmfilesw.=$or." id='".$ecmfile."'";
$i++;
}
}
}
?>
////////////////////////Contracts/////////////////////////
if($_GET['tab']=="Contracts" or $_GET['tab']=="All")
{
print 'Contracts List |  |
| Name |
Celtic Group |
Contractant |
Signed On |
';
if(!$contractsw)$contractsw="id='xxx'";
$z="select distinct * from contracts where ".$contractsw." order by name";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
print '
|
'.$r['name'].' |
'.$r['group_name'].' |
'.$r['contractant_name'].' |
'.$r['signedon'].' |
|
';
}
print '
';
}
////////////////////////Correspondences/////////////////////////
if($_GET['tab']=="Correspondences" or $_GET['tab']=="All")
{
print 'Correspondence List |  |
| Name |
From |
To |
Register Date |
';
if(!$correspondencesw)$correspondencesw="id='xxx'";
$z="select distinct * from correspondences where ".$correspondencesw." order by name";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
print '
|
'.$r['name'].' |
'.$r['account_name_from'].' |
'.$r['account_name_to'].' |
'.$r['reg_date'].' |
|
';
}
print '
';
}
////////////////////////EcmInvoices/////////////////////////
if($_GET['tab']=="EcmInvoices" or $_GET['tab']=="All")
{
print 'EcmInvoices List |  |
| Name |
From |
To |
Type |
';
if(!$ecminvoicesw)$ecminvoicesw="id='xxx'";
$z="select distinct * from ecminvoices where ".$ecminvoicesw." order by name";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
print '
|
'.$r['name'].' |
'.$r['from_name'].' |
'.$r['to_name'].' |
'.$r['invoice_type'].' |
|
';
}
print '
';
}
////////////////////////EcmFiles/////////////////////////
if($_GET['tab']=="EcmFiles" or $_GET['tab']=="All")
{
print 'EcmFiles List |  |
| Name |
';
if(!$ecmfilesw)$ecmfilesw="id='xxx'";
$z="select distinct * from ecmfiles where ".$ecmfilesw." order by name";
$w=mysql_query($z);
while($r=mysql_fetch_array($w))
{
print '
|
'.$r['name'].' |
|
';
}
print '
';
}
?>