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

include_once ("../include/mcglobal.inc.php");


// if (isRunning(1)):
//    exit();
// endif;

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


function call_automailer7() {
  global $logFile, $path;

  $result = "";
  $cmd = "php " . $path . "/include/automailer7.php acapella7890 >" . $path . "/log/automailer7.stdout+err 2>&1 &";
  $ausgabe = system($cmd, $result);
}

// START SCRIPT

// $path = getParameterValue("0", "PATH_DOCROOT", "0");
$dirName = dirname(__FILE__);
$dirName = str_replace("\\", "/", $dirName);
$lastSlashPos = strrpos($dirName,"/");
$path = substr($dirName, 0, $lastSlashPos);

$logFile = getParameterValue("0", "AUTOMAILER_LOGFILE", "0");

$constAutomailerSleeptime = getParameterValue("0", "AUTOMAILER_SLEEP_TIME", "0");
if ($constAutomailerSleeptime == "" || !is_numeric($constAutomailerSleeptime) || $constAutomailerSleeptime < 2 || $constAutomailerSleeptime > 9) :
   $constAutomailerSleeptime = 4;
endif;

// Endless loop
while (TRUE):

  // Set execution time for keepalive
  $currentTime = getDateTime("0");
  updateStmt("keepalive", "ka_process", "automailer7", array("ka_lastexecutiontime", $currentTime),"");

  if (true) :
     call_automailer7();
  endif;

  sleep(10);

endwhile;  // Endless loop
?>
