function setup() { $response = array(); $mysql_database = $_POST['dbName']; $mysql_username = $_POST['dbUser']; $mysql_password = $_POST['dbPass']; $mysql_host = $_POST['hostName']; $account_email = $_POST['account_email']; $account_pass = $_POST['account_pass']; $filename = dirname(__FILE__) . '/sql/linxbooks.sql'; //connect database $connect = @mysql_connect($mysql_host, $mysql_username, $mysql_password); if (!$connect) { $response['err'] = "Database connection failed"; $response['success'] = false; echo json_encode($response); return; } else { if ($connect) { //import database // $sql = "CREATE DATABASE ".$mysql_database; // if(mysql_query($sql) == 1) // { // mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error()); if (!mysql_select_db($mysql_database)) { $response_arr = array(); $response_arr['success'] = false; $response_arr['err'] = "Error selecting MySQL database: Unknown database \"" . $_POST['dbName'] . "\""; echo json_encode($response_arr); return; } $templine = ''; $lines = file($filename); foreach ($lines as $line) { if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; if (substr(trim($line), -1, 1) == ';') { mysql_query($templine) or print 'Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />'; $templine = ''; } } $response['success'] = 1; $file = fopen(dirname(__FILE__) . '/protected/config/db.php', 'r+'); $string = '<?php $dbConfig["connectionString"] = "mysql:host=' . $mysql_host . ';dbname=' . $mysql_database . '"; $dbConfig["username"] = "******"; $dbConfig["password"] = "******"; ?>'; fwrite($file, $string); //create account addInformation($mysql_host, $mysql_username, $mysql_password, $mysql_database, $account_email, $account_pass); } } echo json_encode($response); }
function setup() { $response = array(); $mysql_database = $_POST['dbName']; $mysql_username = $_POST['dbUser']; $mysql_password = $_POST['dbPass']; $mysql_host = $_POST['hostName']; $lang = 'en'; if ($_POST['lang']) { $lang = $_POST['lang']; } $account_email = $_POST['account_email']; $account_pass = $_POST['account_pass']; $filename = dirname(__FILE__) . '/sql/linxbooks.sql'; /* @var $financial_day type */ $financial_day = $_POST['financial_day']; $financial_month = $_POST['financial_month']; //value currency // $currency = $_POST['currency']; $currency_symbol = $_POST['currency_symbol']; $thousand_separator = $_POST['thousand_separator']; $decimal_separator = $_POST['decimal_separator']; //value tax $tax_name = $_POST['tax_name']; $tax_value = $_POST['tax_value']; $checkbox = $_POST['tax_checkbox']; if ($checkbox == true) { $tax_checkbox = 1; } else { $tax_checkbox = 0; } //value my company $company_name = $_POST['company_name']; $company_regis = $_POST['company_resgis']; $company_website = $_POST['company_website']; $company_address_1 = $_POST['company_address_1']; $compnay_address_2 = $_POST['company_address_2']; $company_city = $_POST['company_city']; $company_state = $_POST['company_state']; $company_country = $_POST['company_country']; $company_postal = $_POST['company_postal']; $company_phone = $_POST['company_phone']; $company_fax = $_POST['company_fax']; //connect database $connect = @mysql_connect($mysql_host, $mysql_username, $mysql_password); if (!$connect) { $response['err'] = "Database connection failed"; $response['success'] = false; echo json_encode($response); return; } else { if ($connect) { //import database // $sql = "CREATE DATABASE ".$mysql_database; // if(mysql_query($sql) == 1) // { // mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error()); if (!mysql_select_db($mysql_database)) { $response_arr = array(); $response_arr['success'] = false; $response_arr['err'] = "Error selecting MySQL database: Unknown database \"" . $_POST['dbName'] . "\""; echo json_encode($response_arr); return; } $templine = ''; $lines = file($filename); foreach ($lines as $line) { if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; if (substr(trim($line), -1, 1) == ';') { mysql_query($templine) or print 'Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />'; $templine = ''; } } $response['success'] = 1; $file = fopen(dirname(__FILE__) . '/protected/config/db.php', 'r+'); $string = '<?php $dbConfig["connectionString"] = "mysql:host=' . $mysql_host . ';dbname=' . $mysql_database . '"; $dbConfig["username"] = "******"; $dbConfig["password"] = "******"; ?>'; fwrite($file, $string); //create account addInformation($mysql_host, $mysql_username, $mysql_password, $mysql_database, $account_email, $account_pass, $lang, $financial_day, $financial_month, $currency_symbol, $thousand_separator, $decimal_separator, $tax_name, $tax_value, $tax_checkbox, $company_name, $company_regis, $company_website, $company_address_1, $compnay_address_2, $company_city, $company_country, $company_postal, $company_state, $company_phone, $company_fax); } } echo json_encode($response); }