<?php
/**
 * 2017-08-16 by a.binder - sync group get name to use in default group A_CLASSIFIED/A_ADM_COMPANY in instalation task
 * index.php?_route=Users&_task=syncGroup&idGroup=$argv[2]
 *
 */

ini_set('max_execution_time', 300);
ini_set('memory_limit', '512M');

define('DS', DIRECTORY_SEPARATOR);
define('APP_PATH_ROOT', dirname(__FILE__));
define('APP_PATH_WWW', dirname(__FILE__));
define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');

// set ini to log errors into error log file
ini_set('display_startup_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', '/var/log/apache2/error_log');// TODO: php.ini ?

require_once APP_PATH_ROOT . DS . 'se-lib' . DS . 'Lib.php';
Lib::loadClass('V');
Lib::loadClass('Config');
Lib::loadClass('DB');
Lib::loadClass('User');
// _ Lib::loadClass('UserStorageFactory');


if (isset($_SERVER["argv"][2])) {
	$_SERVER['SERVER_NAME']		 = $_SERVER["argv"][1];
	$usrLogin 					= $_SERVER["argv"][2];  //'ADM_ACCOUNT' => $usrLogin,
	$idGroup 					= $_SERVER["argv"][3];
	$idTelboxes					= $_SERVER["argv"][4];
	$ADM_ADMIN_LEVEL 			= $_SERVER["argv"][5]; //'ADM_ADMIN_LEVEL' => $ADM_ADMIN_LEVEL,
	$ADM_NAME 					= $_SERVER["argv"][6]; //					'ADM_NAME' => $ADM_NAME,
	$ADM_ADMIN_DESC				= $_SERVER["argv"][7]; //						'ADM_ADMIN_DESC' => $ADM_ADMIN_DESC,
	$EMPLOYEE_TYPE				= $_SERVER["argv"][8]; //						'EMPLOYEE_TYPE' => $EMPLOYEE_TYPE,
	$ADM_PASSWD 				= $_SERVER["argv"][9]; //						'ADM_PASSWD' => $ADM_PASSWD,
	$idGroup_A_ADM_COMPANY		= $_SERVER["argv"][10]; //					'A_ADM_COMPANY' => $A_ADM_COMPANY,
	$idGroup_A_CLASSIFIED		= $_SERVER["argv"][11]; //						'A_CLASSIFIED' => $A_CLASSIFIED	
	$idGroup_DEFAULT_ACL_GROUP	= $_SERVER["argv"][12]; //						'DEFAULT_ACL_GROUP' => $DEFAULT_ACL_GROUP	
}

else {
	die("\n The second argument should be server domain - e.g. biuro.biall-net.pl and third idGroup e.g. 3 \n");
}


$cronTaskName = 'AddUser';
$keyToken = 'bash_AddUser';
$token = Router::getRoute('Cron')->generateCliAuthToken($keyToken, $cronTaskName, 300 * 10);
$output = Router::getRoute('Cron')->executeCurlTastByToken($cronTaskName, $keyToken, $token, [ 'idGroup' => $groupID, 'usrLogin' => $usrLogin , 'idTelboxes' => $idTelboxes,  'ADM_ADMIN_LEVEL' => $ADM_ADMIN_LEVEL, 'ADM_NAME' => $ADM_NAME, 'ADM_ADMIN_DESC' => $ADM_ADMIN_DESC, 'EMPLOYEE_TYPE' => $EMPLOYEE_TYPE, 'ADM_PASSWD' => $ADM_PASSWD, 'idGroup_A_ADM_COMPANY' => $idGroup_A_ADM_COMPANY, 'idGroup_A_CLASSIFIED' => $idGroup_A_CLASSIFIED, 'idGroup_DEFAULT_ACL_GROUP' => $idGroup_DEFAULT_ACL_GROUP ]);
echo "DBG: output -----------------------\n{$output}\nEOF output---------------------------------\n";

die(".EOF - OK\n");

?>
