<?php
ini_set('include_path', '.');

require_once('env-parser.php');
require_once('file-util.php');
require_once('db-util.php');
require_once('app-util.php');
require_once('upgrade-app.php');



$config_files = array( '/' => array( array('config.php.in', 'conf/config.php')), '/cgi-bin' => array() );
$schema_files = array(  );
$reconf_schema_files = array(  );
$remove_schema_files = array(  );

$psa_params = array (  );
$db_ids = array (  );
$web_ids = array ( 'var', '/' );
$settings_params = array ( 'locale', 'bbc_custom_charset', 'bbc_maxtime', 'bbc_titlebar', 'bbc_detailed_stat_fields', 'bbc_show_config', 'bbc_maxvisible', 'bbc_maxbrowser', 'bbc_maxextension', 'bbc_maxos', 'bbc_maxrobot', 'bbc_maxhost', 'bbc_maxkey', 'bbc_maxorigin', 'bbc_maxpage', 'bbc_title_size', 'bbc_subtitle_size', 'bbc_text_size', 'bbc_num_size', 'bbc_time_offset', 'bbc_no_dns', 'bbc_no_hits', 'bbc_ignore_ip', 'bbc_ignore_refer', 'bbc_ignore_bots', 'bbc_ignore_agent', 'bbc_debug', 'bbc_developer_installation', 'bbc_kill_stats', 'bbc_use_lock', 'bbc_purge_single', 'bbc_protocol_usage' );
$settings_enum_params = array ( 'locale' => array( 'ar-EG' => 'ar', 'bg-BG' => 'bg', 'bs-BA' => 'bs', 'ca-ES' => 'ca', 'cs-CZ' => 'cs', 'zh-CN' => 'zh-cn', 'zh-TW' => 'zh-tw', 'da-DK' => 'da', 'nl-NL' => 'nl', 'en-UK' => 'en', 'fi-FI' => 'fi', 'fr-FR' => 'fr', 'de-DE' => 'de', 'el-GR' => 'el', 'hu-HU' => 'hu', 'it-IT' => 'it', 'id-ID' => 'id', 'ja-JP' => 'ja', 'ko-KP' => 'ko', 'lt-LT' => 'lt', 'mk-MK' => 'mk', 'nb-NO' => 'nb', 'pl-PL' => 'pl', 'pt-PT' => 'pt', 'pt-BR' => 'pt-br', 'ro-RO' => 'ro', 'ru-RU' => 'ru', 'sk-SK' => 'sk', 'sl-SI' => 'sl', 'es-ES' => 'es', 'sv-SE' => 'sv', 'th-TH' => 'th', 'tr-TR' => 'tr', 'uk-UA' => 'uk' ), 'bbc_show_config' => array( '1' => '1', '0' => '0' ), 'bbc_no_dns' => array( '1' => '1', '0' => '0' ), 'bbc_no_hits' => array( '1' => '1', '0' => '0' ), 'bbc_ignore_bots' => array( '2' => '2', '1' => '1', '0' => '0' ), 'bbc_ignore_agent' => array( '1' => '1', '0' => '0' ), 'bbc_debug' => array( '1' => '1', '0' => '0' ), 'bbc_developer_installation' => array( '1' => '1', '0' => '0' ), 'bbc_kill_stats' => array( '1' => '1', '0' => '0' ), 'bbc_use_lock' => array( 'flk' => 'flk', 'sem' => 'sem', 'dio' => 'dio' ), 'bbc_purge_single' => array( '1' => '1', '0' => '0' ), 'bbc_protocol_usage' => array( '1' => '1', '0' => '0' ) );
$crypt_settings_params = array (  );

$psa_modify_hash = get_psa_modify_hash($psa_params);
$db_modify_hash = get_db_modify_hash($db_ids);
$web_modify_hash = get_web_modify_hash($web_ids);
$settings_modify_hash = get_settings_modify_hash($settings_params);
$settings_enum_modify_hash = get_settings_enum_modify_hash($settings_enum_params);
$crypt_settings_modify_hash = get_crypt_settings_modify_hash($crypt_settings_params);

$additional_modify_hash = get_additional_modify_hash();

if(count($argv) < 2)
{
    print "Usage: configure (install | upgrade <version> | configure | remove)\n";
    exit(1);
}

$command = $argv[1];

if($command == "upgrade")
{
    if($argv[2] && $argv[3]){
	upgrade_app($argv[2], $argv[3], $config_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
	exit(0);
    }
    else{
	print "Error: upgrade version or release not specified.\n";
	exit(1);
    }
}

if($command == "install")
{
    configure($config_files, $schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

if($command == "remove")
{
    remove_app($remove_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

if($command == "configure")
{
    configure($config_files, $reconf_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash);
    exit(0);
}

print "Error: unknown command $command.\n";
exit(1);

?>