<?php
global $xajax;
$xajax -> register( XAJAX_FUNCTION, 'sendContactMsg' );

function sendContactMsg( $email, $name, $phone, $text, $check )
{
  global $lang;
  
  if ( !\System::checkEmail( $email ) || !$name || !$phone || !$text )
    $out = $lang -> getTrans( 'T_BRAK_WSZYSTKICH_DANYCH' );
  else
  {
    if ( \System::getSessionVar( 'check' ) == $check )
      $out = $lang -> getTrans( 'T_TEN_FORMULARZ_BYL_JUZ_WYSLANY' );
    else
    {
      \System::setSessionVar( 'check', $check );
      
      $text .= '<hr /><p>' . $lang -> getTrans( 'T_IMIE_I_NAZWISKO' ) . ': <b>' . $name . '</b></p>';
      $text .= '<p>' . $lang -> getTrans( 'T_TELEFON' ) . ': <b>' . $phone . '</b></p>';
      $text .= '<p>' . $lang -> getTrans( 'T_EMAIL' ) . ': <b>' . $email . '</b></p>';
      
      $admin_email = \admin\factory\Settings::getSystemSettings( 'admin_email' );
      \System::sendEmail( $admin_email, 'Zapytanie od ' . $name, $text, $email );
      $out = $lang -> getTrans( 'T_ZAPYTANIE_ZOSTALO_WYSLANE' );
    }
  }

  $objResponse = new xajaxResponse();
  $message = '$(".jqibox").css("display","none");';
  $message .= "$.prompt('" . $out . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });";
  $message .= 'setTimeout(function(){$(".jqibox").css("display","none");},3000);';
  $objResponse -> script( $message );
  return $objResponse;
}