<file_sep><?php

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use WWII\Config\ConfigManager;
use WWII\Service\ServiceManager;
use WWII\Service\ServiceManagerInterface;

if (!isset($loader)) {
    $loader = include(__DIR__ . "/../autoload.php");
}

$loader->set("WWII\\Domain", __DIR__ . '/domain/src/');
$loader->register(true);
$loader->set("WWII\\Application", __DIR__ . '/application/src/');
$loader->register(true);
$loader->set("WWII\\Console", __DIR__ . '/console/src/');
$loader->register(true);
$loader->set("WWII\Common", __DIR__ . '/common/src');
$loader->register(true);
$loader->set("WWII\\", __DIR__ . '/core/src/');
$loader->register(true);

$isDevMode = true;
$configManager = ConfigManager::getInstance();
$config = Setup::createXMLMetadataConfiguration($configManager->get('doctrine_mappings'), $isDevMode);
$connection = $configManager->get('database');

$entityManager = EntityManager::create($connection, $config);
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

$serviceManager = new ServiceManager();
$serviceManager->setConfigManager($configManager);
<file_sep><?php
    // BEGIN: TITIP
    error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);

    $includePaths = array(
        __DIR__ . '/../../vendor',
        __DIR__ . '/../../vendor/wwii',
    );
    set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $includePaths));

    function __autoload($className)
    {
        if ($className === 'PEAR_Error') {
            return;
        }

        include($className . '.php');
    }

    include_once('init_autoload.php');

    if (isset($_GET['bypass']) || isset($_GET['print'])) {
        ob_start();
        session_start();
        require_once('bootstrap.php');
        ob_end_flush();
        return;
    }
    // END: TITIP

      ob_start();
      require_once("./libs/sesschk.php");
      require_once("./libs/lib_konci.php");
      include_once("./libs/myfunctions.php");
      include_once("./libs/agent.php");
      header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="<NAME>" />
        <title>
            <?php include("./includes/title.php");?>
        </title>
        <link href="./styles/arina.css" rel="stylesheet" type="text/css"/>
        <link href="./styles/form.css" rel="stylesheet" type="text/css"/>
        <link href="./styles/topmenu.css" rel="stylesheet" type="text/css"/>
        <link href="./styles/leftmenu2.css" rel="stylesheet" type="text/css"/>
        <script src="./libs/leftmenu2.js" type="text/javascript"></script>
        <?php
            sessionBreak($_SESSION['arinaSess']);
        ?>
    </head>
    <?php //$agent->init(); ?>
    <body>
    <div id="head">
        <div class="left">PT. <NAME> </div>
        <div class="right">Online Reporting System</div>
    </div>
    <div id="container">
        <div id="left">
            <div class="boxed">
                <div class="title">
                    <?php include("./includes/cp.php");?>
                </div>
                <?php
                    include("./includes/leftmenu.php");
                ?>
            </div>
        </div>
        <div id="content">
            <div id="topnavcontainer">
                <?php include("./includes/topmenu.php"); ?>
            </div>
            <div id="thecontent">
                <h3><?php echo $pageTitle;?></h3>
                <!-- CONTENT FILTER /-->
                <?php
                    if (! isset($_GET['c'])||$_GET['c']=="") {
                        include("./includes/home.php");
                    } elseif ($_GET['sub']=="svlk") {
                        //echo "<script type=text/javascript>";
                        //echo "window.location.href = http://192.168.0.1:8080/tri_svlk";
                        //echo "</script>";
                        header('location:http://192.168.0.1:8080/tri_svlk');
                    } else {
                        if (! file_exists("./includes/controller.php")) {
                            include("./includes/404.php");
                        } else {
                            //~echo '<img src="./images/icons/$_GET[c].png" width="64"'
                            echo '<img src="./images/icons/wwii.jpg" width="150"'
                                . ' height="50" align="right" style="padding: 20px;margin-top: -60px" />';
                            //~echo "$_GET[c]";
                            include("./includes/controller.php");
                        }
                    }
                ?>
                </div>
            </div>
        </div>
    </body>
</html>
<?php
ob_end_flush();
?>
<file_sep><?php

class DoctrineCLI
{
    protected $entityManagers = array();

    protected $activeEntityManager = null;

    protected $commands = array();

    protected $specialCommands = array();

    public function __construct()
    {
        $this->entityManagers[0]['key']    = '1';
        $this->entityManagers[0]['name']   = 'MySQL Entity Manager';
        $this->entityManagers[0]['active'] = true;

        $this->entityManagers[1]['key']  = '2';
        $this->entityManagers[1]['name'] = 'MsSQL Entity Manager';
        $this->entityManagers[1]['active'] = false;

        $this->commands[0]['key']  = '1';
        $this->commands[0]['name'] = 'Validate schema';

        $this->commands[1]['key']  = '2';
        $this->commands[1]['name'] = 'Dump Update Schema SQL';

        $this->commands[2]['key']  = '3';
        $this->commands[2]['name'] = 'Execute Update Schema SQL';

        $this->specialCommands[0]['key'] = 'b';
        $this->specialCommands[0]['name'] = 'Back';

        $this->specialCommands[1]['key'] = 'x';
        $this->specialCommands[1]['name'] = 'Exit';
    }

    public function run()
    {
        $this->displayMessages($this->getWelcomeMessages());

        while (true) {
            if ($this->activeEntityManager == null) {
                $message = $this->getPreSelectMessages()
                    . $this->getSelectMessages()
                    . $this->getSpecialCommandMessages(false)
                    . $this->getInputMessages();

                $input = $this->getInput($message);

                $this->translateInput($input);
            } else {
                $message = $this->getPreCommandMessages()
                    . $this->getCommandMessages()
                    . $this->getSpecialCommandMessages(true)
                    . $this->getInputMessages();

                $input = $this->getInput($message);

                $this->translateInput($input);
            }
        }
    }

    protected function getWelcomeMessages()
    {
        $message = PHP_EOL . 'Welcome to Doctrine Custom CLI.' . PHP_EOL . PHP_EOL;

        return $message;
    }

    protected function getPreSelectMessages()
    {
        $message = 'Select an Entity Manager:' . PHP_EOL;

        return $message;
    }

    protected function getSelectMessages()
    {
        $message = '';

        foreach ($this->entityManagers as $entityManager) {
            $message .= $entityManager['key'] . '. ' . $entityManager['name'] . PHP_EOL;
        }

        return $message;
    }

    protected function getPreCommandMessages()
    {
        $message = 'Active Entity Manager: ' . $this->activeEntityManager['name'] . PHP_EOL;

        return $message;
    }

    protected function getCommandMessages()
    {
        $message = '';

        foreach ($this->commands as $command) {
            $message .= $command['key'] . '. ' . $command['name'] . PHP_EOL;
        }

        return $message;
    }

    protected function getSpecialCommandMessages($includeBack = true)
    {
        $message = '';

        foreach ($this->specialCommands as $command) {
            if ($includeBack || (!$includeBack && $command['key'] != 'b')) {
                $message .= $command['key'] . '. ' . $command['name'] . PHP_EOL;
            }
        }

        return $message;
    }

    protected function getInputMessages()
    {
        $message = PHP_EOL . 'Choice : ';

        return $message;
    }

    protected function getMaintenanceMessages($target)
    {
        $message = $target['name'] . ' is under maintenance.' . PHP_EOL . PHP_EOL;

        return $message;
    }

    protected function getErrorMessages()
    {
        $message = 'Wrong choice...' . PHP_EOL . PHP_EOL;

        return $message;
    }

    protected function displayMessages($messages)
    {
        fwrite(STDOUT, $messages);
    }

    protected function getInput($message)
    {
        $this->displayMessages($message);
        $input = chop(fgets(STDIN));
        fwrite(STDOUT, PHP_EOL);

        return $input;
    }

    protected function translateInput($input)
    {
        if (empty($this->activeEntityManager)) {
            switch ($input) {
                case '1':
                case '2':
                    $activeEntityManager = null;
                    foreach ($this->entityManagers as $entityManager) {
                        if ($entityManager['key'] == $input) {
                            if ($entityManager['active']) {
                                $activeEntityManager = $entityManager;
                            } else {
                                $this->displayMessages($this->getMaintenanceMessages($entityManager));
                                return;
                            }
                        }
                    }

                    if ($activeEntityManager == null) {
                        $this->displayMessages($this->getErrorMessages());
                    } else {
                        $this->activeEntityManager = $activeEntityManager;
                    }
                    break;
                case 'x':
                    $this->terminate();
                    break;
                default:
                    $this->displayMessages($this->getErrorMessages());
                    break;
            }
        } else {
            chdir(dirname(__FILE__));

            switch ($input) {
                case '1':
                    $this->displayMessages('Please wait...' . PHP_EOL);
                    $this->displayMessages('==========================================================' . PHP_EOL . PHP_EOL);
                    system('doctrine.php.bat orm:validate-schema');
                    $this->displayMessages(PHP_EOL . '==========================================================' . PHP_EOL . PHP_EOL);
                    break;
                case '2':
                    $this->displayMessages('Please wait...' . PHP_EOL);
                    $this->displayMessages('==========================================================' . PHP_EOL);
                    system('doctrine.php.bat orm:schema-tool:update --dump-sql');
                    $this->displayMessages('==========================================================' . PHP_EOL . PHP_EOL);
                    break;
                case '3':
                    $this->displayMessages('Please wait...' . PHP_EOL);
                    $this->displayMessages('==========================================================' . PHP_EOL);
                    system('doctrine.php.bat orm:schema-tool:update --force');
                    $this->displayMessages('==========================================================' . PHP_EOL . PHP_EOL);
                    break;
                case 'b':
                    $this->activeEntityManager = null;
                    break;
                case 'x':
                    $this->terminate();
                    break;
            }
        }
    }

    protected function terminate($code = 0)
    {
        fwrite(STDOUT, 'Teriminating...' . PHP_EOL);
        $this->activeEntityManager = null;
        sleep(1);
        exit($code);
    }
}

$cli = new DoctrineCLI();
$cli->run();
<file_sep><?php
// Include the Console_CommandLine package.
require_once 'Console/CommandLine.php';
require_once __DIR__ . '/../wwii/bootstrap.php';

$config = include __DIR__ . '/../wwii/console/config/config.default.php';

$parser = new Console_CommandLine(array(
    'description' => 'WWII Console Application v-1.0.0',
    'version'     => '1.0.0'
));

$parser->addOption('verbose', array(
    'short_name'  => '-v',
    'long_name'   => '--verbose',
    'action'      => 'StoreTrue',
    'description' => 'turn on verbose output'
));

foreach ($config['console']['commands'] as $strCommand => $arrayCommand) {
    $command = $parser->addCommand($strCommand, array(
        'description' => $arrayCommand['description']
    ));

    if (isset($arrayCommand['options']) && ! empty($arrayCommand['options'])) {
        foreach ($arrayCommand['options'] as $strOption => $arrayOption) {
            $command->addOption($strOption, $arrayOption);
        }
    }

    if (isset($arrayCommand['arguments']) && ! empty($arrayCommand['arguments'])) {
        foreach ($arrayCommand['arguments'] as $strArgument => $arrayArgument) {
            $command->addArgument($strArgument, $arrayArgument);
        }
    }
}

try {
    $result = $parser->parse();

    $controllerName = $result->command_name;

    if (! empty($result->command)) {
        $controller = new $config['console']['commands'][$controllerName]['controller'](
            $serviceManager,
            $entityManager
        );

        $options = null;
        if (isset($result->command->options)) {
            $options = $result->command->options;
        }

        $args = null;
        if (isset($result->command->args)) {
            $args = $result->command->args;
        }

        $controller->run($options, $args);
    }
} catch (\Exception $e) {
    $parser->displayError($e->getMessage());
}
<file_sep><?php

include(__DIR__ . '/init_autoload.php');

if (php_sapi_name() === 'cli') {
    return false;
}

$application = new \WWII\Application();
$application->setEntityManager($entityManager);
$application->run();
