<?php
$logFNsuffix = "-autosend";
//the lines below are important when running on WIN CMD, since sendFolder.php starts a session, so session changes made below are ignored. When running from BASH, session status is not PHP_SESSION_NONE, so session is not restarted and there is no problem 
if (session_status() == PHP_SESSION_NONE) {
	if(!isset($_SESSION)) session_start();
}
set_include_path("../..");
require('demosettings.php');
require('authorizations.php');
require('parseUtils.php');
echo "in auto send folder ";
//if($isFolderService != true){
//	write_to_log("ERROR", "Currently autoSendFolder is only supported with IVDocServer");
//	die("Currently autoSendFolder is only supported with IVDocServer");
//}
$action = filter_input(INPUT_GET,"Action");
if($action=="tools/cowitter/autoSendFolder.php"){
  $auto_send_target_folderPath = filter_input(INPUT_GET, "args");  
  write_to_log("TRACE", "in action autoSendFolder");
  echo "in action autoSendFolder";
}
if(!IS_CLI && empty($action)){
	die("Currently autoSendFolder is only supported in commandline");
}
function getCygwinCompatiblePath($arg)
{
	$arg = str_replace('/cygdrive/c/', 'c:/', $arg);
	$arg = str_replace('/cygdrive/d/', 'd:/', $arg);
	return $arg;
}

$auto_send_target_folderPath = $argv[1];
write_to_log("TRACE", "loading sendfolder $auto_send_target_folderPath");
if( empty($auto_send_target_folderPath) )
{
	return; //we could check here what folder is not in the db
}

$_SESSION["username"] = "crawler"; //make sure this user exists
$_SESSION["loggedIn"] = "yes";
//$_REQUEST["folderPath"] = "$auto_send_target_folderPath";
$folderPath = "$auto_send_target_folderPath";
$userAuth[CAN_ANALYZER_FOLDER] = true;
$xml_results_path = getCygwinCompatiblePath($xml_results_path);
$CURRENT_SOURCE_FOLDER = getCygwinCompatiblePath($CURRENT_SOURCE_FOLDER);

if( !is_dir('tmp') ) {
	mkdir('tmp');
}

require('sendFolder.php');
?>