<?php

if(!is_dir('interface') && !is_dir('sql') && !is_dir('server')) die('Please enter the install sirectory before you execute the install.php script.'); 

// Copy the files
exec('chown -R ispconfig:ispconfig interface');
exec('cp -prf interface /usr/local/ispconfig');
exec('chmod 770 /usr/local/ispconfig/interface/invoices');
exec('chmod -R 770 /usr/local/ispconfig/interface/web/billing/lib/lang');
exec('chown ispconfig:ispconfig /usr/local/ispconfig/interface/invoices');
exec('chown -R ispconfig:ispconfig server');
exec('cp -prf server /usr/local/ispconfig');
exec('chmod 750 /usr/local/ispconfig/server/cron_daily_billing.sh');

// Execute the SQL
include_once('/usr/local/ispconfig/server/lib/config.inc.php');
include_once('/usr/local/ispconfig/server/lib/mysql_clientdb.conf');

if(substr(ISPC_APP_VERSION,0,5) != '3.0.5') die('This Billing Module version requires ISPConfig 3.0.5');

/*
$clientdb_host                  = 'localhost';
$clientdb_user                  = 'root';
$clientdb_password              = 'xxxxx';
*/

$db_database = $conf['db_database'];

$command = "mysql -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)."  ".escapeshellarg($db_database)." < sql/ispconfig3_billing.sql";
exec($command);

echo "ISPConfig Billing module has been installed.\n";

?>