<?php

/* 
 * 
 * 
 * 
 */
require_once 'asyncRequst.php';
require_once 'aSynchronousOsRequests.php';

class asyncWithPhp  implements aSynchronousOsRequests {
    
    public $path;
    
    function __construct() {
       $this->path = asyncRequst::getPath();
    }
    
    function getStatisticAsync($in_process, $username) {
        if ($in_process == 0) {
            $url = "http://$this->path/parseUtils.php";
            $params = array("Action" => "getStatistic", "username" => $username);
            asyncRequst::async_request("GET", $url, $params);
        }
    }

    function calcPie($pieName, $username) {     
        write_to_log("TRACE", "executing asyncPieCalc for pie: $pieName");
        $url = "http://$this->path/StatisticPageEng.php";
        $params = array("Action" => "asyncPieCalc", "pieName" => $pieName, "slices" => 500, "username" => $username, "file" => $str);
        asyncRequst::async_request("GET", $url, $params);       
    }

    function calulatePieWrapper($connection, $trendName, $in_process, $username) {
        CacheEng::update_process($connection, $username, $trendName, ++$in_process);
        write_to_log("TRACE", "executing asyncPieCalc for trend: $trendName");
        $url = "http://$this->path/proSentPageEng.php";
        $params = array("Action" => "asyncTrendCalc", "username" => $username, "trendName" => $trendName, 'isAdmin' => $isAdmin, "file" => $str);
        asyncRequst::async_request("GET", $url, $params);
    }

    function sendDocAsync($PHP_FOLDER, $i, $user, $serverIP, $port, $file_id, $isEmail) {
        $url = "http://$this->path/senddocEngAjx.php";
        write_to_log("TRACE", "executing async senddoc with URL=$url");
        $params["argv"] = array($PHP_FOLDER, $i, $user, $serverIP, $port, $file_id, 0, $isEmail);
        asyncRequst::async_request("GET", $url, $params);
    }

    function backgroundAsync($arr, $getmetadata) {
        global $PHP_FOLDER;
        $url = "http://$this->path/background.php";
        $params["argv"] = array($PHP_FOLDER, $arr["docId"], $getmetadata);
        write_to_log("INFO", "executing async background with URL=$url");
        asyncRequst::async_request("GET", $url, $params);
		return true;
    }

    function runPhpPage($pageName, $args, $isBackground) {
        $url = "http://$this->path/$pageName";
        //write_to_log("TRACE", "executing php url: $url");
        $params = array("Action" => "$pageName", "args" => $args);
        return asyncRequst::async_request("GET", "http://localhost/testint/allInOneWeb/tools/cowitter/autoSendFolder.php", $params);
    }
    
    function runLibraryFunc($php_files, $lib, $func, $params) {
        if(is_array($params)){
            $params = implode(",", $params);
        }
        $url = "http://$this->path/mainEng.php";
        $params = array("Action" => 'asyncPhpAction', "function_name" => "$lib::$func", 'func_params' => $params);
        asyncRequst::async_request("GET", $url, $params);
    }
   


}