<?php
/*=======================================================================
 *
 * remote_function.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/


include_once ("../include/mcglobal.inc.php");
// include_once ("../include/auth.inc.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_html2pdf.inc.php");


getSecHttpVars("1",array("accessCode", "functionName", "par_01", "par_02", "par_03", "par_04", "par_05", "par_06", "par_07", "par_08", "par_09", "par_10"));

// Execution-Time for script
set_time_limit(30000);

$rfcLogActivated = true;

// Write LOG for CRON only
function rfcWriteToFile ($text) {
	global $logFile, $rfcLogActivated;
	if ($rfcLogActivated) :
     writeToFile($logFile, $text);
  endif;
}

function checkFunctionIsAllowed ($functionName) {
	$retBool = false;
	if ($functionName == "getDateTime") : $retBool = true; endif;
	if ($functionName == "getZipcodeServiceValuesByZipcodes") : $retBool = true; endif;
	if ($functionName == "myStrCheck") : $retBool = true; endif;
	if ($functionName == "removeFieldSigns") : $retBool = true; endif;
	return $retBool;
}

// Log file
$logFile = getParameterValue("0", "REMOTE_FUNCTION_CALL_LOGFILE", "0");
if ($logFile == "") : $logFile = "../log/remote_function_call.log"; endif;

// Init
$retVal = false;


if (checkFunctionIsAllowed($functionName) && $accessCode == "7hb75hf73bfgfh437fhefb4u3fze3fur4f7u4zhiiuhhd673gth4373bdg48992") :

   rfcWriteToFile("ACCESS_CODE=OK");

   if ($functionName != "") :

      // Current timestamp
      $currentTime = getDateTime("0");

      // INCLUDE FILES to find functions
      $includeArray = array("ftp", "image", "inc_calendar", "inc_customer", "inc_file", "inc_filters", "inc_group", "inc_job", "inc_parseXML", "inc_services", "inc_pnpoly", "inc_stock", "inc_vehicle", "services_func");
         // NOT in array: "inc_article"
      $includeArrayLen = count($includeArray);
      for ($i = 0; $i < $includeArrayLen; $i++) :
          include_once ("../include/" . $includeArray[$i] . ".inc.php");
      endfor;


      rfcWriteToFile("functionName=" . $functionName);

      if (function_exists($functionName)) :

         rfcWriteToFile("CALLED_FUNC_EXIST=YES");

         $argumentArray = array();
         for ($i = 1; $i <= 10; $i++) :
             $parValue = ${("par_" . pad($i, 2))};
             if ($parValue != "") :
                rfcWriteToFile("par_" . pad($i, 2) . "=" . $parValue);
             endif;
             array_push($argumentArray, $parValue);
         endfor;

         // Call function and get HTML output
         $retVal = call_user_func_array($functionName, $argumentArray);
      else :
         rfcWriteToFile("CALLED_FUNC_EXIST=NO");
      endif;
   else :
      rfcWriteToFile("CALLED_FUNC_EXIST=NOT_SPECIFIED");
   endif;
else :
   rfcWriteToFile("ACCESS_CODE=NOT_OK");
endif;
rfcWriteToFile("-----------------------------------------------------------------");

if (!is_array($retVal)) :
   $retVal = array($retVal);
endif;
$retVal = json_encode($retVal);
echo $retVal;


/*
HOW TO CALL!

function get_url($request_url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $request_url);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $response = curl_exec($ch);
  curl_close($ch);

  return $response;
}

$request_url = 'http://second-server-address/listening_page.php?function=somefunction&securityhash=HASH';
$response = get_url($request_url);

-------------------------

https://htm.assecutor.de/htm/tools/remote_function.php?accessCode=7hb75hf73bfgfh437fhefb4u3fze3fur4f7u4zhiiuhhd673gth4373bdg48992&functionName=getDateTime&par_01=0
*/
?>