<?php                             

function menuCreate($db,$jogcsoport,$css_id,$parameter,$modultype,$main_title,$config){
	    $sql="SELECT funkcio
		  FROM pg_jogcsoport
		  JOIN pg_funkciok ON pg_funkciok.id_pg_funkciok=pg_jogcsoport.id_pg_funkciok
		  where id_pg_jogcsoporttipusok='".$jogcsoport."' and parameter='".$parameter."'";
	    $result=$db->getAll($sql);

      $return[1]=false;
	    if ($result){
                   
        $return[0]='<ul id="'.$css_id.'">
                   <li><a href="#" class="parent">'.$main_title.'</a>	
           		     <ul class="children">';  
                                     
    		foreach ($result as &$value) {
    		  if ($value["funkcio"]!=$modultype){
    		      $return[0].='<li><a href="javascript:void(0);"  onclick="top.location.href=\''.$config->getValue($value["funkcio"],"index").'\';">'.$config->getValue($value["funkcio"],"title").'</a></li>';                   		      		      
    		  }else{
    		      $return[1]=true;
    		  }
    		}
    		$return[0].='</ul>
           	        </li>
                    </ul> ';
                    
	    }
      return $return; 
}

function menuListaCreate($db,$jogcsoport,$css_id,$parameter,$main_title,$config){
	    $sql="SELECT funkcio
		  FROM pg_jogcsoport
		  JOIN pg_funkciok ON pg_funkciok.id_pg_funkciok=pg_jogcsoport.id_pg_funkciok
		  where id_pg_jogcsoporttipusok='".$jogcsoport."' and parameter='".$parameter."'";
	    $result=$db->getAll($sql);

	    if ($result){
                   
        $return='<ul id="'.$css_id.'">
                   <li><a href="#" class="parent">'.$main_title.'</a>	
           		     <ul class="children">';  
                                     
    		foreach ($result as &$value) {
    		  if ($value["funkcio"]=='szerviznaplo_list'){
    		    	$return.='<li><a href="javascript:void(0);"  onClick="getAjaxDataList(\''.$config->getValue("AjaxData","").'/get_hibajavmainlista.php\',\'ajaxdata\',\''.$config->getValue("AjaxData","").'/get_hibajavlista.php\',\'list_table\',\''.$config->getValue("loading_gif","").'\');">'.$config->getValue("szerviznaplo_list","title").'</a></li>';    		                         		      		      
    		  }elseif ($value["funkcio"]=='szolgnaplo_list'){
    		    	$return.='<li><a href="javascript:void(0);" id="forgnaplo_button" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_forgnaplo.php\',\'ajaxdata\',\''.$config->getValue("loading_gif","").'\',false,forgnaploParam());">'.$config->getValue("gep_kiad_vissza","naplo_button").'</a></li>';    		                         		      		      
    		  }elseif ($value["funkcio"]=='rosszgepek_list'){
    		    	$return.='<li><a href="javascript:void(0);" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_rosszgepek.php\',\'ajaxdata\',\''.$config->getValue("loading_gif","").'\',false,\'statusz=2;3;4\');">'.$config->getValue("gep_kiad_vissza","rosszgepek").'</a></li>';    		                         		      		      
    		  }elseif ($value["funkcio"]=='forgalmiban_list'){
    		    	$return.='<li><a href="javascript:void(0);" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_forgalmiban.php\',\'ajaxdata\',\''.$config->getValue("loading_gif","").'\',false,forgalmiGroupParam(9));">'.$config->getValue("gep_kiad_vissza","forgalmiban").'</a></li>';    		                         		      		      
    		  }elseif ($value["funkcio"]=='feladatok_list'){
    		    	$return.='<li><a href="javascript:void(0);" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/get_feladatok.php\',\'ajaxdata\',\''.$config->getValue("loading_gif","").'\',false,nullParam());">'.$config->getValue("gep_kiad_vissza","feladatok").'</a></li>';    		                         		      		      
    		  }    		          
                    		  
    		}
    		$return.='</ul>
           	      </li>
                  </ul> ';
                    
	    }
      return $return; 
}
                                   
function pager($options,$default,$id,$style,$ColumnSrc,$config,$div_id,$ajaxfile,$Ord,$AscDesc){
  $array=explode(";", $options);
  
  $onchange.='getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit=0\',\''.$id.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));';        		    
    		    
	$content='<select name="'.$id.'" id="'.$id.'" '.$style.' onchange="'.$onchange.'">';
	foreach ($array as &$value) {
	 if ($default==$value){
	      $content.='<option value="'.$value.'" selected="selected">'.$value.'</option>';
   }else{
        $content.='<option value="'.$value.'">'.$value.'</option>';
   }	 	      
	}
	$content.="</select>";
  return "egy lapon:&nbsp;".$content;  
}

function lapozo($ossz,$min,$limit,$linklimit,$config,$div_id,$ajaxfile,$pager,$ColumnSrc,$Ord,$AscDesc){ 
	
	$db=floor($ossz/$limit);	//hany lap lesz
	$akt=floor($min/$limit);	//akt lap
  if ($db==0){
    return '';
  }
	//BALRA LAPOZO

  $content='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_first.png" border="0"></a>&nbsp;&nbsp;';
	
	if($min==0){
		
		$content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_previous.png" border="0"></a>&nbsp;&nbsp;';
	}else{		
  	$content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($min-$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_first.png"" border="0"></a>&nbsp;&nbsp;';
	}
	$i=0;
	//KIMENET
		if(($szam%$limit)==0){
  		while($i<$db){
  		  if ($akt==$i){
  		    $style='style="color:#ff0000;"';
        }else{
          unset($style);
        }
  		  if ($i<$linklimit){	        
          $content.='<a href="javascript:void(0);" class="button_item" '.$style.' onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($i*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));">'.$i.'</a>&nbsp;&nbsp;';	    
    		    
        }elseif ($i>$db-$linklimit){
          $content.='<a href="javascript:void(0);" class="button_item" '.$style.' onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($i*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));">'.$i.'</a>&nbsp;&nbsp;';      
  			    
        }elseif($i==$linklimit){
          $content.=' ... ';
        }			
  			$i++;
  		}
		}else{
  		while($i<=$db){
  		  if ($akt==$i){
  		    $style='style="color:#ff0000;"';
        }else{
          unset($style);
        }  		
  		  if ($i<$linklimit){
          $content.='<a href="javascript:void(0);" class="button_item" '.$style.' onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($i*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));">'.$i.'</a>&nbsp;&nbsp;';        		    
    		    
        }elseif ($i>$db-$linklimit){
          $content.='<a href="javascript:void(0);" class="button_item" '.$style.' onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($i*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));">'.$i.'</a>&nbsp;&nbsp;';      
  			    
        }elseif($i==$linklimit){
          $content.=' ... ';
        }			
  			$i++;
  		}
		}
		

	//JOBBRA LAPOZO
	if($min==($db*$limit)){
		
		  $content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min=0&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_next.png" border="0"></a>&nbsp;&nbsp;';
	}else{
		
		  $content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($min+$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_next.png" border="0"></a>&nbsp;&nbsp;';
	}
	if(($ossz%$limit)==0){
		
			$content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.(($db-1)*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_last.png" border="0"></a>&nbsp;&nbsp;';
	}else{
		
			$content.='<a href="javascript:void(0);" class="button_item" onclick="getAjaxData(\''.$config->getValue("AjaxData","").'/'.$ajaxfile.'\',\''.$div_id.'\',\''.$config->getValue("loading_gif","").'\',false,siderParam(\'min='.($db*$limit).'&ajax=true&limit='.$limit.'\',\''.$pager.'\',\''.$ColumnSrc.'\',\''.$Ord.'\',\''.$AscDesc.'\'));"><img align="absmiddle" src="../_media/resultset_last.png" border="0"></a>&nbsp;&nbsp;';		
	}
  return iconv_iso88592_utf8("össz.: ").$ossz."  ".$content;
}

function iconv_utf8_iso88592($str){;
   $str=htmlspecialchars($str);
   return iconv("UTF-8","iso-8859-2//TRANSLIT//IGNORE",$str);
}

function iconv_iso88592_utf8($str){;
   $str=htmlspecialchars($str);
   return iconv("iso-8859-2","UTF-8//TRANSLIT//IGNORE",$str);
}

function getGepszamTmpl($db,$where){
	$sql="SELECT gepszam 
	      FROM pg_gepek ".$where." ORDER BY gepszam";

	$query=$db->getAll($sql);
	
  if ($query[0][0]!=''){
	$content="<table width=\"100%\" align=\"center\">";
	foreach ($query as &$value) {
	      $content.='<tr>
            			<td valign="top" align="left" class="function_table_in td_title" >
            			'.$value["gepszam"].'
            			</td>
            			</tr>';
      }
      $content.="</table>";
      return $content;
  }
  return '';
  
}

function setStornoGepnaplo($db,$gepnaplo_id){
  $sql_id="SELECT id_pg_hibanaplo,id_pg_gepek,atvett FROM pg_hibanaplo WHERE id_pg_gepnaplo='".$gepnaplo_id."'";
  $hibanaplo=$db->getOne($sql_id);
  if ($hibanaplo["atvett"]==0){
    $sql="UPDATE pg_hibanaplo SET storno='1' where id_pg_gepnaplo='".$gepnaplo_id."'";			   
    $update_hibanaplo=$db->updateOne($sql);
    $sql="UPDATE pg_hsnaplo SET storno='1' where id_pg_hibanaplo ='".$hibanaplo["id_pg_hibanaplo"]."'";
    $update_gepek=$db->updateOne($sql);
    $sql="UPDATE pg_gepnaplo SET storno='1' where id_pg_gepnaplo ='".$gepnaplo_id."'";
    $update_gepek=$db->updateOne($sql);    
	 $sql="SELECT id_pg_gepek FROM pg_gepnaplo where id_pg_gepnaplo ='".$gepnaplo_id."'";
	 $query=$db->getOne($sql);          
    $sql="UPDATE pg_gepek SET id_pg_statusz='1' where id_pg_gepek='".$query["id_pg_gepek"]."'";
    $update_gepek=$db->updateOne($sql);   
    return true;
  }else{
    return false;
  }
  
}

function getDolgozok($db){
	$sql="SELECT id_pg_dolgozok,nev
	      FROM pg_dolgozok";
	$query = $db->getAll($sql);
	if ($query){
	  foreach ($query as &$value) {
	    $keyquery[$value["id_pg_dolgozok"]]=$value["nev"];
	  }
	}
	return $keyquery;
}

function getForgnaplo($db,$dolgozo,$datum_from,$datum_to){
	$sql="SELECT id_pg_gepnaplo,pg_gepek.gepszam,datum,megnevezes,pg_gepek.id_pg_statusz as statusz,pg_gepnaplo.id_pg_dolgozok as from_dolgozo, pg_gepnaplo.id_pg_dolgozok_atadva as to_dolgozo,storno
	FROM pg_gepnaplo
	JOIN pg_gepek on pg_gepek.id_pg_gepek=pg_gepnaplo.id_pg_gepek
	JOIN pg_statusz on pg_statusz.id_pg_statusz=pg_gepek.id_pg_statusz
	WHERE (pg_gepnaplo.id_pg_dolgozok='".$dolgozo."' or pg_gepnaplo.id_pg_dolgozok_atadva='".$dolgozo."') and 
	      (datum>='".$datum_from."' and datum<='".$datum_to."')
	ORDER BY datum"; 	
	return $db->getAll($sql);
}

function getGepekTelepSzerint($db,$config,$from_ajax){

	$sql="SELECT pg_gepek.id_pg_szolghelyek as szolghelyid,pg_szolghelyek.telephely, pg_szolghelyek.megnevezes, count(pg_gepek.id_pg_szolghelyek) as darab 
	      FROM pg_gepek 
	      JOIN pg_szolghelyek ON pg_gepek.id_pg_szolghelyek = pg_szolghelyek.id_pg_szolghelyek 
	      GROUP BY pg_gepek.id_pg_szolghelyek";
	$query=$db->getAll($sql);

	$telep=$config->getValue("gep_gepektelepszerint","telep");
	$ossz=$config->getValue("gep_gepektelepszerint","ossz");
	$jo=$config->getValue("gep_gepektelepszerint","jo");
	$gyartonal=$config->getValue("gep_gepektelepszerint","gyarto");
	$rossz=$config->getValue("gep_gepektelepszerint","rossz");
	$szervizbenmarad=$config->getValue("gep_gepektelepszerint","szervizbenmarad");

	if ($from_ajax){
	    $telep=iconv_iso88592_utf8($telep);
	    $ossz=iconv_iso88592_utf8($ossz);
	    $jo=iconv_iso88592_utf8($jo);
	    $gyartonal=iconv_iso88592_utf8($gyartonal);
	    $rossz=iconv_iso88592_utf8($rossz);
	    $szervizbenmarad=iconv_iso88592_utf8($szervizbenmarad);
	}

	$content='<table border="0" width="100%" align="center">
		    <tr>					
		    <td class="td_medium" align="right" valign="top" colspan="6">
		    '.date("Y-m-d H:i:s").'
		    </td>
		    </tr>
		    <tr>
		    <td valign="top" align="left" class="td_medium" style="width: 133px;">
		     '.$telep.'
		    </td>
		    <td valign="top" align="left" class="td_medium" style="width: 40px;">
		     '.$ossz.'
		    </td>
		    <td valign="top" align="left" class="td_medium" style="width: 35px;">
		     '.$jo.'
		    </td>
		    <td valign="top" align="left" class="td_medium" style="width: 35px;">
		     '.$gyartonal.'
		    </td>
		    <td valign="top" align="left" class="td_medium" style="width: 35px;">
		     '.$rossz.'
		    </td>
		    <td valign="top" align="left" class="td_medium" >
		     '.$szervizbenmarad.'
		    </td>
		    </tr>';

	foreach ($query as &$value) {
	      unset($listaarray);
	      $sql_sz="SELECT pg_gepek.id_pg_statusz as statusz,pg_statusz.megnevezes,
	      count(pg_gepek.id_pg_statusz) as stdarab  
	      FROM pg_gepek 
	      JOIN pg_statusz ON pg_gepek.id_pg_statusz = pg_statusz.id_pg_statusz
	      where pg_gepek.id_pg_szolghelyek='".$value['szolghelyid']."'
	      GROUP BY pg_gepek.id_pg_statusz";
	      $query_sz=$db->getAll($sql_sz);
	      foreach ($query_sz as &$value_sz) {
		$listaarray[$value_sz['statusz']]=$value_sz['stdarab'];
	      }
	      $megnevezes=substr($value["megnevezes"],0,15);
	      if ($from_ajax){
		$megnevezes=iconv_iso88592_utf8($megnevezes);
	      }
	      $content.='<tr>
			 <td valign="top" align="left" class="function_table_in" colspan="6">
			    <table border="0" >
			    <tr>
			      <td valign="top" align="left" class="td_medium" style="width: 130px;">
			      '.$megnevezes.'
			      </td>
			      <td valign="top" align="left" class="td_medium" style="width: 40px;">
			      '.$value["darab"].'
			      </td>
			      <td class="td_medium" valign="top" align="left" style="width: 35px;">
			      '.$listaarray[1].'
			      </td>
			      <td class="td_medium" valign="top" align="left" style="width: 35px;">      
			      '.$listaarray[2].'
			      </td>	 
			      <td class="td_medium" valign="top" align="left" style="width: 35px;">      
			      '.$listaarray[3].'
			      </td>
			      <td class="td_medium" valign="top" align="left" >      
			      '.$listaarray[4].'
			      </td>
			    </tr>
			    </table>
			 </td>
			 </tr>';
	}
      $content.="</table>";
      return $content;
}


function ReinsertBeavAlkatr($request,$db,$hibanaplo_id,$config){

  $return='';

  $delete_hibajeljav="DELETE FROM pg_hibajeljavell WHERE id_pg_hibanaplo = '".$hibanaplo_id."'";
  if (!$db->deleteOne($delete_hibajeljav)){
    $return.="Delete error! hibajeljavell<br>";
  }

  $delete_alkatresz="DELETE FROM pg_alkatreszcsere WHERE id_pg_hibanaplo = '".$hibanaplo_id."'";
  if (!$db->deleteOne($delete_alkatresz)){
    $return.="Delete error! alkatreszcsere<br>";
  }

  $insert_hibajeljav="INSERT INTO pg_hibajeljavell (id_pg_hibanaplo, id_pg_beavatkozasok, beav_valasz) VALUES "; 
  $insert_alkatresz="INSERT INTO pg_alkatreszcsere (id_pg_hibanaplo, id_pg_alkatreszkod, mennyiseg, megjegyzes) VALUES ";

  $insert_hibajavellsub='';
  $insert_alkatreszsub='';
   foreach ($request as $key => $value) {
      $length=strlen($key);

      if (substr($key,0,11)=='beavatkozas'){
	if ($value=='checked'){
	  $insert_hibajavellsub.=" ('".$hibanaplo_id."', '".substr($key,11,$length)."', ''),";
	}else{	  
	  $insert_hibajavellsub.=" ('".$hibanaplo_id."', '".substr($key,11,$length)."', '".$value."'),";
	}
      }

      if (substr($key,0,9)=='alkatresz'){
	  $insert_alkatreszsub.=" ('".$hibanaplo_id."', '".substr($key,9,$length)."', '".(int)$value."', '".$megj."'),";
	  $alkatreszfelh[substr($key,9,$length)]=(int)$value;
      }
   }

  if ($insert_hibajavellsub!=''){
    $insert_hibajeljav.=substr($insert_hibajavellsub,0,-1);
    $lastid=$db->insertMore($insert_hibajeljav);
    if ($lastid=0){
      $return.="Insert error! hibajeljavell<br>";
    }
  }

  if ($insert_alkatreszsub!=''){
    $insert_alkatresz.=substr($insert_alkatreszsub,0,-1);
    $lastid=$db->insertMore($insert_alkatresz);
    if ($lastid=0){
      $return.="Insert error! alkatreszcsere<br>";
    }
  }
  if (isset($alkatreszfelh)){
    foreach ($alkatreszfelh as $key => $value) {
      if ((int)$value>0){
	$sql="SELECT id_pg_alkatreszkod, raktaron, megnevezes
	      FROM pg_alkatreszek
	      WHERE id_pg_alkatreszkod='".$key."'";
	      $result_alkatresz=$db->getOne($sql);
	      if ($result_alkatresz){
		$darab=($result_alkatresz["raktaron"]-$value);
		$sql="UPDATE pg_alkatreszek SET raktaron='".$darab."' where id_pg_alkatreszkod='".$key."'";
		$update_gepek=$db->updateOne($sql);
		if ($update_gepek){
		  if ((int)$darab<=0){
		    $return.=$result_alkatresz["megnevezes"]." ".$config->getValue("pgalkatresz_elfogyott","")."<br>";
		  }
		}
	      }
      }
    }
  }
  if ($return==''){
    return $config->getValue("gep_rogzitesok","");
  }else{
    return $return;
  }
}

function getHibanaplo($db,$hibanaplo_id){

    $sql="SELECT id_pg_hibanaplo, id_pg_gepek, jegysorszam, hibajelenseg, hibajavitasa, ellenorzes, lezart_osszeg, lezart_jegysorszam, id_pg_dolgozok_lezart, nyitott_osszeg, nyitott_jegysorszam, id_pg_dolgozok_nyitott 
	  FROM pg_hibanaplo
	  WHERE id_pg_hibanaplo=".$hibanaplo_id;
    return $db->getOne($sql);

}

function getHibajeljavell($db,$hibanaplo_id){

  $sql="SELECT 	pg_hibajeljavell.id_pg_beavatkozasok, beav_valasz     
	      FROM pg_hibajeljavell
	      WHERE id_pg_hibanaplo=".$hibanaplo_id;
  return $db->getAll($sql);

}

function getLikeHibajelConts($db,$like){
  if ($like!=''){
    
    $sql="SELECT pg_beavatkozasok.megnevezes, beav_valasz     
  	      FROM pg_hibajeljavell
  	      JOIN pg_beavatkozasok
  	         ON pg_beavatkozasok.id_pg_beavatkozasok=pg_hibajeljavell.id_pg_beavatkozasok 
             WHERE (pg_beavatkozasok.megnevezes LIKE '%".$like."%' OR beav_valasz LIKE '%".$like."%')";
  	         
  	$query=$db->getAll($sql);
  	return count($query);  	
  }else{
    return 1;
  }
}

function getHibanaploConts($db,$hibanaplo_id){

  $sql="SELECT pg_hsnaplo.bizonylat_szam, pg_hsnaplo.datum, pg_hsnaplo.jegysorszam, pg_statusz.megnevezes    
	      FROM pg_hsnaplo
	      JOIN pg_statusz
	         ON pg_statusz.id_pg_statusz=pg_hsnaplo.id_pg_statusz
        WHERE pg_hsnaplo.id_pg_hibanaplo='".$hibanaplo_id."'
        ORDER BY pg_hsnaplo.datum DESC";
	$query=$db->getAll($sql);
                     
	if (count($query)>1){
	  $content='<table align="left">';
    foreach ($query as &$value) {
      $content.='<tr class="td_medium">
                 <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 100px;" >'.substr($value["datum"],0,-3).'</div></td>
                 <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 80px;" >'.iconv_iso88592_utf8($value["megnevezes"]).'</div></td>
                 <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 50px;" >'.iconv_iso88592_utf8($value["bizonylat_szam"]).'</div></td>
                 <td align="left"><div style="overflow: hidden; white-space: nowrap; width: 50px;" >'.iconv_iso88592_utf8($value["jegysorszam"]).'</div></td>
                 </tr>';
    }
    $content.='</table>';   
  }else{
    $content='-';
  }
  
  return $content;
}

function getAlkatreszConts($db,$hibanaplo_id){

  $sql="SELECT pg_alkatreszcsere.mennyiseg, pg_alkatreszek.megnevezes    
	      FROM pg_alkatreszcsere
	      JOIN pg_alkatreszek
	         ON pg_alkatreszek.id_pg_alkatreszkod=pg_alkatreszcsere.id_pg_alkatreszkod
        WHERE pg_alkatreszcsere.id_pg_hibanaplo='".$hibanaplo_id."'";
	$query=$db->getAll($sql);
  
	if (count($query)>1){
    foreach ($query as &$value) {
      $valasz='('.iconv_iso88592_utf8($value["mennyiseg"]).' db.)';
      $content.='-'.iconv_iso88592_utf8($value["megnevezes"]).' '.$valasz.' <br />';
    }   
  }else{
    $content='-';
  }
  
  return $content;
}

function getHibajelConts($db,$hibanaplo_id, $type){

  $sql="SELECT pg_beavatkozasok.megnevezes, beav_valasz     
	      FROM pg_hibajeljavell
	      JOIN pg_beavatkozasok
	         ON pg_beavatkozasok.id_pg_beavatkozasok=pg_hibajeljavell.id_pg_beavatkozasok
        WHERE id_pg_hibanaplo='".$hibanaplo_id."' and id_pg_beavatkozas_tipusok='".$type."'";
	$query=$db->getAll($sql);
  
	if (count($query)>1){
    foreach ($query as &$value) {
    if ($value["beav_valasz"]!=''){
      $valasz='('.iconv_iso88592_utf8($value["beav_valasz"]).')';
    }else{
      unset($valasz);
    }
      $content.='-'.iconv_iso88592_utf8($value["megnevezes"]).' '.$valasz.' <br />';
    }   
  }else{
    $content='-';
  }
  
  return $content;

}

function getAlkatreszcsere($db,$hibanaplo_id){

  $sql="SELECT id_pg_alkatreszkod, 	mennyiseg, 	megjegyzes     
	      FROM pg_alkatreszcsere
	      WHERE id_pg_hibanaplo=".$hibanaplo_id;
  return $db->getAll($sql);

}

function getKiadhatoGep($db,$gep){
	$sql="SELECT id_pg_gepek
	      FROM pg_gepek
	      WHERE id_pg_gepek='".$gep."' and id_pg_statusz='1'";
	return $db->getAll($sql);
}

function getJavitasravarakozogepek($db){

	$sql="SELECT pg_gepek.gepszam, pg_hibanaplo.hibajelenseg, pg_hibanaplo.id_pg_hibanaplo
	      FROM pg_hibanaplo
	      JOIN pg_gepek on pg_hibanaplo.id_pg_gepek=pg_gepek.id_pg_gepek
	      WHERE atvett='0' and storno='0' 
	      ORDER BY gepszam ASC";
	return $db->getAll($sql);
}

function getOneGep($db,$gep){

    $sql="SELECT gepszam, gyariszam, pg_szolghelyek.telephely,pg_szolghelyek.megnevezes FROM pg_gepek
	  JOIN pg_szolghelyek on pg_szolghelyek.id_pg_szolghelyek=pg_gepek.id_pg_szolghelyek
	  Where id_pg_gepek=".$gep;

    return $db->getOne($sql);

}

function getOneDolg($db,$gkv){

    $sql="SELECT  kod, nev, tel, lakcim,
	  pg_szolghelyek.telephely,pg_szolghelyek.megnevezes 
	  FROM pg_dolgozok
	  JOIN pg_szolghelyek on pg_szolghelyek.id_pg_szolghelyek=pg_dolgozok.id_pg_szolghelyek
	  Where id_pg_dolgozok=".$gkv;

    return $db->getOne($sql);

}

function getDolgozoLista($db,$dolgtipus,$orderby,$type,$posinselect=0){
	$sql="SELECT id_pg_dolgozok,kod,nev,id_pg_szolghelyek,tel,lakcim,id_pg_dolgozoktipus,id_pg_jogcsoporttipusok
	      FROM pg_dolgozok
	      ".$dolgtipus." 
	      ORDER BY ".$orderby;
	$query=$db->getAll($sql);

	$content='<select name="'.$type.'" id="'.$type.'" style="width: 200px;">';
	$content.='<option></option>';
	foreach ($query as &$value) {
	  if ($dolgtipus<>9){
	    $content.='<option value="'.$value["id_pg_dolgozok"].'">'.$value["kod"].' '.$value["nev"].'</option>';
	  }else{
	    if ($posinselect==$value["id_pg_dolgozok"]){
	      $content.='<option value="'.$value["id_pg_dolgozok"].'" selected="selected">'.$value["nev"].'</option>';
	    }else{
	      $content.='<option value="'.$value["id_pg_dolgozok"].'">'.$value["nev"].'</option>';
	    }
	  }
	}
	      $content.="</select>";
	return $content;
}

function getAlkatreszekLista($db,$oszlopoksz,$config,$from_ajax) {

	$sql="SELECT id_pg_alkatreszkod, raktaron, megnevezes, nettoar
	      FROM pg_alkatreszek
	      ORDER BY megnevezes ASC";
	$query=$db->getAll($sql);
	$ov = 0;		
	$content="<table width=\"100%\" align=\"center\">";
	foreach ($query as &$value) {
	      if ($ov==$oszlopoksz){
		      $content.="<tr>";
	      }
	      $content.='<td valign="top" align="left" class="function_table_in">'
			.getOneAlkatresz($value,$config,$from_ajax).
			'</td>';
	      $ov++;
	      if ($ov==$oszlopoksz){
		      $content.="</tr>
				<tr>";
		      $ov=0;
	      }
      }
      $content.="</table>";
      return $content;
}

function getOneAlkatresz($value,$config,$from_ajax){
    $megnevezes=$value["megnevezes"];
    $kerdes=$config->getValue("gep_alkatreszcsere","kerdes");
    if ($from_ajax){
      $megnevezes=iconv_iso88592_utf8($megnevezes);
      $kerdes=iconv_iso88592_utf8($kerdes);      
    }

    $event="kerdes_beszur('".$kerdes."','alkatresz".$value["id_pg_alkatreszkod"]."','alkatresz".$value["id_pg_alkatreszkod"]."text');";
    if ($value["raktaron"]>0){
      $checkbox='<input name="alkatresz'.$value["id_pg_alkatreszkod"].'" id="alkatresz'.$value["id_pg_alkatreszkod"].'" value="'.$value["id_pg_alkatreszkod"].'" onclick="'.$event.'" type="checkbox">';
    }else{
      $checkbox='<img width="16" height="16" alt="" src="'.$config->getValue("media_path","").'/cross.png">';
    }
    $content='<table border="0" >';
    $content.='<tr>
		<td valign="middle" align="left" class="td_medium" style="width: 150px;">
		  <div id="alkatresz'.$value["id_pg_alkatreszkod"].'div" title="'.$megnevezes.'" style="overflow:hidden; white-space:nowrap; width:100px;">'.$megnevezes.'</div>      
		</td>
		<td valign="middle" align="right" class="td_medium" style="width: 16px;">
		  '.$checkbox.'
		</td>
		<td class="td_medium" valign="middle" align="left">
		  <input type="text" style="width: 25px;" name="alkatreszraktaron'.$value["id_pg_alkatreszkod"].'" id="alkatreszraktaron'.$value["id_pg_alkatreszkod"].'" value="'.$value["raktaron"].'" DISABLED />
		</td>
		<td class="td_medium" valign="middle" align="left">
		  <input type="text" style="width: 25px; color:#FF0000;" name="alkatresz'.$value["id_pg_alkatreszkod"].'text" id="alkatresz'.$value["id_pg_alkatreszkod"].'text" DISABLED />
		</td>	 
	       </tr>';
    $content.="</table>";
    return $content;
}



///////////
function getPenztargepLista($db){
	$sql="SELECT id_pg_gepek,gepszam
	      FROM pg_gepek		    
	      GROUP BY id_pg_gepek,gepszam
	      ORDER BY id_pg_gepek,gepszam ASC";
	$query=$db->getAll($sql);

	$content='<select name="gepszam" id="gepszam" style="width: 70px;">';
	$content.='<option></option>';
	foreach ($query as &$value) {
	  $content.='<option value="'.$value["id_pg_gepek"].'">'.substr($value["gepszam"],-4,4).'</option>';
	}
	      $content.="</select>";
	return $content;
}


function getStatuszLista($db,$jogcsoport){
	      $sql="SELECT pg_statusz.id_pg_statusz as id_statusz,pg_statusz.megnevezes as gep_statusz
		    FROM pg_jogcsstatusz 
		    JOIN pg_statusz ON pg_statusz.id_pg_statusz = pg_jogcsstatusz.id_pg_statusz 
		    WHERE pg_jogcsstatusz.id_pg_jogcsoporttipusok='".$jogcsoport."'";

	      $query=$db->getAll($sql);

	      $content='<select name="gep_statusz" id="gep_statusz" style="width: 90px;" onchange="enableHibajelenseg();">';
	      $content.='<option></option>';
	      foreach ($query as &$value) {
		$content.='<option value="'.$value["id_statusz"].'">'.$value["gep_statusz"].'</option>';
	      }
	      $content.="</select>";

	return $content;
}

function getHibaJavEllLista($db,$beavtype,$oszlopoksz) {

	$sql="SELECT id_pg_beavatkozasok, megnevezes, kerdes
	      FROM pg_beavatkozasok 
	      WHERE id_pg_beavatkozas_tipusok=".$beavtype."
	      order by megnevezes";

	$query=$db->getAll($sql);

	$ov = 0;		
	$content='<table width="100%" align="center" >';
	foreach ($query as &$value) {
	      if ($ov==$oszlopoksz){
		      $content.="<tr>";
	      }
	      $content.='<td valign="top" align="left" class="function_table_in" style="width:200px;">
			'.getOneHibaJavEllContent($value).'
			</td>';
		      $ov++;
	      if ($ov==$oszlopoksz){
		      $content.='</tr>
				             <tr>';
		      $ov=0;
	      }
      }
      $content.='</table>';
      return $content;
}

function getOneHibaJavEllContent($value){  
    $content='<table border="0" width="100%" >';

    if ($value["kerdes"]!=""){
      $event="kerdes_beszur('".$value["kerdes"]."','beavatkozas".$value["id_pg_beavatkozasok"]."','beavatkozas".$value["id_pg_beavatkozasok"]."text');";
      $answer='
	      <td valign="middle" align="right" style="width:50px;">
		      <input type="text" style="width:50px; color:#FF0000;" name="beavatkozas'.$value["id_pg_beavatkozasok"].'text" id="beavatkozas'.$value["id_pg_beavatkozasok"].'text" DISABLED/>
	      </td>
	      ';
	    $swidth="100px";
    }else{
      $event="check_color('beavatkozas".$value["id_pg_beavatkozasok"]."');";
      $answer="";
      $swidth="160px";
    }

    $function='<input name="beavatkozas'.$value["id_pg_beavatkozasok"].'" id="beavatkozas'.$value["id_pg_beavatkozasok"].'" value="'.$value["id_pg_beavatkozasok"].'" onclick="'.$event.'" type="checkbox">';	
    $content.='<tr>
		<td valign="middle" align="left" style="width:15px;">
		  '.$function.'					      
		</td>
		<td class="td_medium" valign="middle" align="left" style="width:150px;">
		  <div id="beavatkozas'.$value["id_pg_beavatkozasok"].'div" title="'.$value["megnevezes"].'" style="overflow:hidden; white-space:nowrap; width:'.$swidth.';">'.$value["megnevezes"].'</div>      
		</td>
		'.$answer.'
	       </tr>';
    $content.="</table>";
    return $content;
}

?>