<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');
if('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
  array_walk($_GET, 'SiteLibs::ConvertArrayIconv', $MS_SP->Sp_Config['charset']);
  $VarWhereT = '';
  $VarWhereO = '';

  if (true === isset($_GET['term']) && '' != $_GET['term']){
    $VarWhereT .= SiteLibs::ConvertStringToSql('fullseek_'. $MS_SP->Sp_Lang, $_GET['term']);
    $VarWhereO .= SiteLibs::ConvertStringToSql('ourdocs_ond', $_GET['term']);
  }
  $VarWhereT = SiteLibs::StripAndOrFirst($VarWhereT);
  $VarWhereO = SiteLibs::StripAndOrFirst($VarWhereO);
//echo "VarWhereT: ". $VarWhereT ."<br />";
  $ObjObondMod = new ObondMod($MS_SP);
  $ArrObond = $ObjObondMod->GetFromDb('SqlAll', 'GetAll', $VarWhereT, '', '0, '. $MS_SP->Sp_Config['AutocompleteLimit']);
//SiteLibs::GetVarDump($ArrObond);
  $ObjOurDocsMod = new OurDocsMod($MS_SP);
  $ArrOurDocs = $ObjOurDocsMod->GetFromDb('SqlAll', 'GetAll', $VarWhereO, '', '0, '. $MS_SP->Sp_Config['AutocompleteLimit']);

  $ArrFields = array();
//  foreach ($ArrOurDocs AS $key => $row){
//    $ArrFields[] = array(
//        'id' => 'acido'. $row['ourdocs_id'], 
//        'label' => $row['ourdocs_ond'].'',
//        'value' => $row['ourdocs_ond'].'',
//        'category' => $MS_SP->Sp_LangMessage['script']['ScrOurDocs']
//    );
//  }
//  foreach ($ArrObond AS $key => $row){
//    echo $row['ond'].'===';
//  }
//  foreach ($ArrObond AS $key => $row){
//    $ArrFields[] = array(
//      'id' => 'acidt'. $row['idglobal'], 
//      'label' => $row['ond'].'',
//      'value' => $row['ond'].'',
//      'category' => $MS_SP->Sp_LangMessage['script']['ScrDocsNfTnpa']
//    );
//  }
  if (true === is_array($ArrOurDocs) && 1 <= count($ArrOurDocs)){
    foreach ($ArrOurDocs AS $key => $row){
      $ArrFields[] = array(
        'id' => 'acido'. $row['ourdocs_id'], 
        'label' => SiteLibs::ConvertArrayIconvBack($row['ourdocs_ond'], '', $MS_SP->Sp_Config['charset']).'',
        'value' => SiteLibs::ConvertArrayIconvBack($row['ourdocs_ond'], '', $MS_SP->Sp_Config['charset']).'',
        'category' => SiteLibs::ConvertArrayIconvBack($MS_SP->Sp_LangMessage['script']['ScrOurDocs'], '', $MS_SP->Sp_Config['charset'])
      );
    }
  }
  if (true === is_array($ArrObond) && 1 <= count($ArrObond)){
    foreach ($ArrObond AS $key => $row){
      $ArrFields[] = array(
        'id' => 'acidt'. $row['idglobal'], 
        'label' => SiteLibs::ConvertArrayIconvBack($row['ond'], '', $MS_SP->Sp_Config['charset']).'',
        'value' => SiteLibs::ConvertArrayIconvBack($row['ond'], '', $MS_SP->Sp_Config['charset']).'',
        'category' => SiteLibs::ConvertArrayIconvBack($MS_SP->Sp_LangMessage['script']['ScrDocsNfTnpa'], '', $MS_SP->Sp_Config['charset'])
      );
      //echo $MS_SP->Sp_LangMessage['script']['ScrDocsNfTnpa'];
    }//SiteLibs::ConvertArrayIconvBack($MS_SP->Sp_LangMessage['script']['ScrDocsNfTnpa'], '', $MS_SP->Sp_Config['charset'])
  }
  echo json_encode($ArrFields);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>