
<?php
require_once("ajax_preload.php");

if ($httpreferer){
  if ($ajax_db->getErrorCode()==1){
    die;
  }else{

    $gep=$_REQUEST["gep"];
    $from=$_REQUEST["from"];
    $datum = substr($_REQUEST["datum"],0,10);
    $to=$_REQUEST["to"];
    $statusz=$_REQUEST["statusz"];
    $modultype=$_REQUEST["modultype"];

  if (@checkdate(substr($datum,5,2),substr($datum,8,2),substr($datum,0,4)) and (substr($datum,4,1)=="-" and substr($datum,7,1)=="-")){
    $datum.=' '.date("H:i:s");

    if ($modultype=='service'){
      $jogep=true;
    }else{
      $jogep=getKiadhatoGep($ajax_db,$gep);
    }

    if ($statusz==1){
      if ($jogep){
	$sql="INSERT INTO pg_gepnaplo (datum, id_pg_dolgozok, id_pg_dolgozok_atadva, id_pg_gepek) 
	      VALUES ('".$datum."', ".$from.", ".$to.", ".$gep.")";

	$id_pg_gepnaplo=$ajax_db->insertOne($sql);
	  if ($id_pg_gepnaplo>0){
		$sql="UPDATE pg_gepek SET id_pg_statusz='".$statusz."', id_pg_dolgozok='".$to."' where id_pg_gepek='".$gep."'";
		$update_gepek=$ajax_db->updateOne($sql);
		if ($update_gepek){
		  $content_popup=$config->getValue("gep_kiadva","");	  
		}else{
		  $content_popup=$config->getValue("gep_kiadas_nemsikerult","");
		}
	  }else{
	    $content_popup=$config->getValue("gep_kiadas_nemsikerult","");
	  }
      }else{
	$content_popup=$config->getValue("gep_marrosszkent","");
      }
    }else{
    	$content_popup=$config->getValue("gep_csakdolgstatus","");
    }
  }else{
    $content_popup=$config->getValue("datumhiba","");
  }
    $ajax_page->setTag("content_popup", $content_popup);
    $ajax_page->AppendTag("content", $ajax_page->getAppropriateTemplate($config->getValue("templates_path","")."/popup.tmpl.php"));
    
    $ajax_page->out();
  }
}
?>