<?php
require_once("ajax_preload.php");      
      
if ($httpreferer){
  if ($ajax_db->getErrorCode()==1){
    die;
  }else{
  
//WHERE    
    $sWhere=' WHERE ';
    if (isset($_REQUEST["src0"])){
      $sWhere.="pg_hibanaplo.id_pg_hibanaplo LIKE '%".$_REQUEST["src0"]."%' and ";
    }
    if(isset($_REQUEST["src1"])){
      $sWhere.="pg_gepek.gepszam LIKE '%".$_REQUEST["src1"]."%' and ";
    }
    if(isset($_REQUEST["src2"])){
      $sWhere.="pg_hibanaplo.hibajelenseg LIKE '%".$_REQUEST["src2"]."%' and ";
    }
    if(isset($_REQUEST["src3"])){
      $sWhere.="pg_hibanaplo.hibajavitasa LIKE '%".$_REQUEST["src3"]."%' and ";
    }
    if(isset($_REQUEST["src4"])){
      $sWhere.="pg_hibanaplo.ellenorzes LIKE '%".$_REQUEST["src4"]."%' and ";
    }
    if ($sWhere!=' WHERE '){
      $sWhere=substr($sWhere,0,-4);
    }else{
      $sWhere='';
    }
//-vége- WHERE    
    
//ORDER
    if (!isset($_REQUEST["AscDesc"])){
      $AscDesc='asc';
      $DescAsc='desc';
    }else{
      $AscDesc=$_REQUEST["AscDesc"];
      if ($AscDesc=='asc'){
        $DescAsc='desc';  
      }else{
        $DescAsc='asc';
      }
    }
	
    $sOrder=' ORDER BY ';
        
    if (!isset($_REQUEST["ord"])){
      $sOrder.="pg_hibanaplo.id_pg_hibanaplo,";
      $Ord='ord0';
      $ord0_icon='<img width="16" height="16" src="'.$config->getValue("media_path","").'/arrow_'.$AscDesc.'.png">';
    }else{
      $Ord=$_REQUEST["ord"];
      if ($_REQUEST["ord"]=='ord0'){
        $sOrder.="pg_hibanaplo.id_pg_hibanaplo,";
        $ord0_icon='<img width="16" height="16" src="'.$config->getValue("media_path","").'/arrow_'.$AscDesc.'.png">';
      }
      if($_REQUEST["ord"]=='ord1'){
        $sOrder.="pg_gepek.gepszam,";
        $ord1_icon='<img width="16" height="16" src="'.$config->getValue("media_path","").'/arrow_'.$AscDesc.'.png">';
      }
    }
                                 
    
    if ($sOrder!=' ORDER BY '){
      $sOrder=substr($sOrder,0,-1).' '.$AscDesc;
    }else{
      $sOrder='';
    }    
//-vége-ORDER

	  $linklimit=6;
	  
	  if (!$_REQUEST['min']) 
      $min = 0; 
    else 
      $min = $_REQUEST['min'];

    if (!$_REQUEST["limit"]){
      $limit=10;  	 
  	}else{
      $limit=$_REQUEST["limit"];
    }

    if ($_REQUEST["side"]){
      $limit=$_REQUEST["side"];
    }	  	              
  	
  	$sQuery = "SELECT id_pg_hibanaplo
          		 FROM pg_hibanaplo   
               ".$sWhere;
    $rResultOssz = $ajax_db->getAll($sQuery);               
    $ossz=count($rResultOssz);
  	
    $sLimit=" limit ".$min.", ".$limit;
  	
    $sQuery = "SELECT id_pg_hibanaplo, pg_hibanaplo.hibajelenseg,	pg_hibanaplo.hibajavitasa,	pg_hibanaplo.ellenorzes, pg_gepek.gepszam, pg_hibanaplo.storno
          		 FROM pg_hibanaplo
          		 JOIN pg_gepek
                  ON pg_gepek.id_pg_gepek=pg_hibanaplo.id_pg_gepek   
               ".$sWhere.$sOrder.$sLimit;       
  	$rResult = $ajax_db->getAll($sQuery);
/*
echo $sQuery;
echo "<pre>";
print_r($_REQUEST);
echo "</pre>".$DescAsc;
*/ 
          
    $sOutput = '<table cellpadding="0" cellspacing="0" border="0" align="left" class="function_table">
             	    <tr style="height:30px">
                	 <td style="padding-left:5px;" class="td_big_title">'.iconv_iso88592_utf8('Szervíznapló').'</td>                                           
                	</tr> 
                	<tr>
                	<td align="left">
                	    <table cellpadding="0" cellspacing="0" border="0" align="left" width="100%" >           		     
                	      		<tr style="height:35px">
                	      			<td align="left"  style="padding-left:5px; width:130px;" class="td_title">
                              '.pager('all;10;25;50;100;250',$limit,'hibajavmainlista_pager','style="width: 50px;"',6,$config,'lista_content','get_hibajavlista.php',$Ord,$AscDesc).'
                              </td>
                	      			<td align="left" style="padding-left:5px; width:60px;" class="td_title" >
                                <a href="javascript:void(0);" class="button_item" align="left" style="width:100px;" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_hibajavlista.php\',\'lista_content\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit=10\',\'hibajavmainlista_pager\',\'6\',\''.$Ord.'\',\''.$AscDesc.'\'));">Keres</a>            
                              </td>
                	            <td align="left" style="padding-right:10px;" class="td_title">
                              '.lapozo($ossz,$min,$limit,$linklimit,$config,'lista_content','get_hibajavlista.php','hibajavmainlista_pager',6,$Ord,$AscDesc).'
                              </td>                                           
                	      		</tr>
                	    </table>
                	</td>
                	</tr>
                	
                	<tr>
                	<td align="left">
                  <table cellpadding="0" cellspacing="0" align="left" 
                      <tr>                                                                                     
                  			<td class="td_title" >
                          <a href="javascript:void(0);"  onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_hibajavlista.php\',\'lista_content\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit=10\',\'hibajavmainlista_pager\',\'6\',\'ord0\',\''.$DescAsc.'\'));">
                          <div style="overflow: hidden; white-space: nowrap; width: 45px;" >
                          '.$ord0_icon.'Id
                          </div>
                          </a>
                        </td>
                        
                  			<td class="td_title" >
                          <a href="javascript:void(0);"  onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_hibajavlista.php\',\'lista_content\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit=10\',\'hibajavmainlista_pager\',\'6\',\'ord1\',\''.$DescAsc.'\'));">
                          <div style="overflow: hidden; white-space: nowrap; width: 85px;" >
                          '.$ord1_icon.iconv_iso88592_utf8("Gépszám").'
                          </div>
                          </a>
                        </td>
                        
                        <td class="td_title" >
                          <div style="overflow: hidden; white-space: nowrap; width: 220px;" >
                          '.iconv_iso88592_utf8('Hibajelenség').'
                          </div>
                        </td>
                  			<td class="td_title" >
                          <div style="overflow: hidden; white-space: nowrap; width: 220px;" >
                          '.iconv_iso88592_utf8('Hibajavítás').'
                          </div>
                        </td>                         
                  			<td class="td_title" >
                  			  <div style="overflow: hidden; white-space: nowrap; width: 220px;" >
                          '.iconv_iso88592_utf8('Ellenőrzés').'
                          </div>
                        </td>
                        <td class="td_title" >
                          <div style="overflow: hidden; white-space: nowrap; width: 220px;" >
                          '.iconv_iso88592_utf8('Alkatrész').'
                          </div>  
                        </td>
                                                                    
                        <td class="td_title" colspan="2">'.iconv_iso88592_utf8('Napló').'</td>
                  		</tr>
                  		<tr style="height:30px;" class="td_title">
                  			<td style="width:60px;">
                          <input type="text" id="src0" name="src0" class="input" style="width: 45px;"  value="'.$_REQUEST["src0"].'">
                        </td>
                  			<td style="width:100px;">
                          <input type="text" id="src1" name="src1" class="input" style="width: 85px;"  value="'.$_REQUEST["src1"].'">
                        </td>
                        <td style="width:230px;">
                          <input type="text" id="src2" name="src2" class="input" style="width: 220px;" value="'.$_REQUEST["src2"].'">
                        </td>
                  			<td style="width:230px;">
                          <input type="text" id="src3" name="src3" class="input" style="width: 220px;" value="'.$_REQUEST["src3"].'">
                        </td>                         
                  			<td style="width:230px;">
                          <input type="text" id="src4" name="src4" class="input" style="width: 220px;" value="'.$_REQUEST["src4"].'">            
                        </td>
                        <td style="width:230px;">
                          <input type="text" id="src5" name="src5" class="input" style="width: 220px;" value="'.$_REQUEST["src5"].'">            
                        </td>                                            
                        <td>
                          <input type="text" id="src6" name="src6" class="input" style="width:295px;" value="'.$_REQUEST["src6"].'">            
                        </td>                                                                                        
                      </tr>
                      <tr>
                        <td class="td_title" colspan="7" align="right">
                          <table align="right">
                          <tr class="td_medium">
                            <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 100px;" >'.iconv_iso88592_utf8("dátum").'</div></td>
                            <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 80px;" >'.iconv_iso88592_utf8("megnevezés").'</div></td>
                            <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 50px;" >'.iconv_iso88592_utf8("bizonylat").'</div></td>
                            <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 50px;" >'.iconv_iso88592_utf8("jegysor.").'</div></td>
                          </tr>
                          </table>                                    
                        </td> 
                      </tr>';
            	
    if ($rResult[0][0]!=''){            	
      $counter=0;
    	foreach ($rResult as &$aRow) {
        if ($counter % 2 == 0){
          $bgcolor="#E5E5E5";  
        }else{
          $bgcolor="#D8D8D8";
        }        
        
        $hjel=getHibajelConts($ajax_db,$aRow["id_pg_hibanaplo"], '3');
        $hjav=getHibajelConts($ajax_db,$aRow["id_pg_hibanaplo"], '1');
        $ell=getHibajelConts($ajax_db,$aRow["id_pg_hibanaplo"], '2');
        $alkatr=getAlkatreszConts($ajax_db,$aRow["id_pg_hibanaplo"]);
        $naplo=getHibanaploConts($ajax_db,$aRow["id_pg_hibanaplo"]);
        
        if ($aRow["storno"]){
          $bgcolor="#FE2E2E";
          $function='<img width="16" height="16" a src="'.$config->getValue("media_path","").'/ikon_minusz.png">'.$aRow["id_pg_hibanaplo"];
        }else{
          $function='<a href="javascript:void(0);" onclick="TorolJavitasForm(); getHiddenAjaxData(\''.$config->getValue("AjaxData","").'/get_hibanaplo.php\',\'hibanaplo_id='.$aRow["id_pg_hibanaplo"].'\',\'hiddenajaxdata\',\''.$config->getValue("loading_gif","").'\',runFromHibanaplo(\'hiddenajaxdata\'));"><img width="16" height="16" src="'.$config->getValue("media_path","").'/ikon_szerkeszt.png">'.$aRow["id_pg_hibanaplo"].'</a>';
        }
    		$sOutput .= '<tr class="td_medium" style="background-color:'.$bgcolor.'; padding: 1px 3px;">'; 		                  
    		$sOutput .= '<td padding: 1px 3px;" >'.$function.'</td>';
    		$sOutput .= '<td padding: 1px 3px;" >'.addslashes(iconv_iso88592_utf8(substr($aRow['gepszam'],-4))).'</td>';
    		$sOutput .= '<td padding: 1px 3px;" >'.addslashes(iconv_iso88592_utf8($aRow['hibajelenseg'])).'<br />'.$hjel.'</td>';
    		$sOutput .= '<td padding: 1px 3px;" >'.addslashes(iconv_iso88592_utf8($aRow['hibajavitasa'])).'<br />'.$hjav.'</td>';
        $sOutput .= '<td padding: 1px 3px;" >'.addslashes(iconv_iso88592_utf8($aRow['ellenorzes'])).'<br />'.$hjav.'</td>';    				
        $sOutput .= '<td padding: 1px 3px;" >'.$alkatr.'</td>';
    		$sOutput .= '<td padding: 1px 3px;" >'.$naplo.'</td>';
    		$sOutput .= '</tr>';
    		
    		$counter++;
    	}    	
  	}
  	$sOutput .= '</table>
                 </td>
	               </tr>
	               </table>';
  	
    if ($_REQUEST["ajax"]){
    	echo $sOutput;
    }
  }
}