#!/usr/local/bin/php -q
<?php
//=======================================
//###################################
// Kayako Infotech Ltd. - SWIFT Framework
//
// Source Copyright 2001-2008 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                   www.kayako.com
//###################################
//=======================================

define("SWIFT_AREA", 60);

chdir(dirname(__FILE__)."/../");
require_once ("./includes/functions_cli.php");
$cli = new CLI;


if (in_array($argv[1], array('--help', '-help', '-h', '-?')))
{
	$cli->writeln($cli->green('===================='));
	$cli->writeln($cli->yellow("SWIFT CLI Debug"));
	$cli->writeln($cli->green('===================='));
	$cli->writeln();

	$result = $cli->prompt("", array("1" => "Check for Zend/ionCube Loader", "2" => "Exit"));
	if ($result == "1")
	{
		if (extension_loaded('Zend Optimizer'))
		{
			$cli->message("Zend Optimizer", CLI_OK);
		} else {
			$cli->message("Zend Optimizer", CLI_ERROR);
		}
		if (extension_loaded('ionCube Loader'))
		{
			$cli->message("ionCube Loader", CLI_OK);
		} else {
			$cli->message("ionCube Loader", CLI_ERROR);
		}
	}

} else if (in_array($argv[1], array('--rebuildindex', '-rebuildindex'))) {
	require_once ("./swift.php");

	$cli = new CLI;

	if (!$events->triggerEvent(EVENT_CLI)) {
		// Try to do a callback on tickets module for email piping, if unsuccesfull then display default message
		if (!$events->triggerCallback("tickets", "clirebuildindex"))
		{
			echo sprintf($_SWIFT["language"]["clidefault"], SWIFTPRODUCT, $settings->getKey("core", "version"), date("Y"));
		}
	}

} else {
	require_once ("./swift.php");

	if (in_array($argv[1], array('--debug', '-debug', '-d')) || in_array($argv[3], array('--debug', '-debug', '-d')))
	{
		$_SWIFT["clidebug"] = true;
		$_SWIFT["dbgfilename"] = "clidbg_".buildHash();
	}

	if (in_array($argv[1], array('--load', '-load', '-l')) && !empty($argv[2]))
	{
		$_SWIFT["clifileload"] = $argv[2];
	}

	if (!$events->triggerEvent(EVENT_CLI)) {
		// Try to do a callback on tickets module for email piping, if unsuccesfull then display default message
		if (!$events->triggerCallback("parser", "cliparser"))
		{
			echo sprintf($_SWIFT["language"]["clidefault"], SWIFTPRODUCT, $settings->getKey("core", "version"), date("Y"));		
		}
	}
}
?>