return true;
}
-function db_create_db($connection)
-{
- $db = mysql_connect($connection["host"] ,
- $connection["dbuser"], $connection["dbpassword"]);
- if (!mysql_select_db($connection["dbname"], $db))
- {
- $sql = "CREATE DATABASE " . $connection["dbname"] . "";
- if (!mysql_query($sql))
- return 0;
- mysql_select_db($connection["dbname"], $db);
- }
- return $db;
-}
-
-function db_drop_db($connection)
-{
-
- if ($connection["tbpref"] == "")
- {
- $sql = "DROP DATABASE " . $connection["dbname"] . "";
- return mysql_query($sql);
- }
- else
- {
- $res = db_query("show table status");
- $all_tables = array();
- while($row = db_fetch($res))
- $all_tables[] = $row;
- // get table structures
- foreach ($all_tables as $table)
- {
- if (strpos($table['Name'], $connection["tbpref"]) === 0)
- db_query("DROP TABLE `".$table['Name'] . "`");
- }
- //deleting the tables, how??
- return true;
- }
-}
-
function db_import($filename, $connection, $force=true)
{
global $db, $go_debug;
return false;
}
- // if (mysql_error()) return "DB_ERROR";
- //@mysql_close($con);
-
//if ($zip == "zip")
// $zip = $time;
if (save_to_file($backupfile, $zip, $out))
global $db_connections, $db, $installed_extensions;
$theme = $installed_extensions[$id]['package'];
- $db_sav = $db;
+ $comp = user_company();
foreach ($db_connections as $n => $conn) {
- $db = $_SESSION["wa_current_user"]->get_db_connection($n);
+ $db = $_SESSION["wa_current_user"]->set_db_connection($n);
$sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
if (!db_query($sql, 'Cannot update user theme settings'))
return false;
}
- $db = $db_sav;
+ $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
+
$_SESSION['wa_current_user']->prefs->theme = 'default';
return true;
}
return $this->can_access($page_level);
}
- function get_db_connection($id=-1)
+ function set_db_connection($id = -1)
{
- global $db_connections;
-
- $this->cur_con = $id == -1 ? $this->company : $id;
- $connection = $db_connections[$this->cur_con];
-
- //print_r($connection);
-
- $db = mysql_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]);
- mysql_select_db($connection["dbname"], $db);
-
- return $db;
+ return set_global_connection($id);
}
function update_prefs($prefs)
function set_global_connection($company=-1)
{
- global $db, $transaction_level;
+ global $db, $transaction_level, $db_connections;
cancel_transaction(); // cancel all aborted transactions if any
$transaction_level = 0;
- $db = $_SESSION["wa_current_user"]->get_db_connection($company);
+ if ($company == -1)
+ $company = $_SESSION["wa_current_user"]->company;
+ $_SESSION["wa_current_user"]->cur_con = $company;
+
+ $connection = $db_connections[$company];
+
+ $db = mysql_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]);
+ mysql_select_db($connection["dbname"], $db);
return $db;
}
return mysql_affected_rows($db);
}
-?>
+function db_field_name($result, $n)
+{
+ return mysql_field_name($result, $n);
+}
+
+function db_create_db($connection)
+{
+ $db = mysql_connect($connection["host"] ,
+ $connection["dbuser"], $connection["dbpassword"]);
+ if (!mysql_select_db($connection["dbname"], $db))
+ {
+ $sql = "CREATE DATABASE " . $connection["dbname"] . "";
+ if (!mysql_query($sql) || !mysql_select_db($connection["dbname"], $db))
+ return 0;
+ }
+ return $db;
+}
+
+function db_drop_db($connection)
+{
+
+ if ($connection["tbpref"] == "")
+ {
+ $sql = "DROP DATABASE " . $connection["dbname"] . "";
+ return mysql_query($sql);
+ }
+ else
+ {
+ $res = db_query("show table status");
+ $all_tables = array();
+ while($row = db_fetch($res))
+ $all_tables[] = $row;
+ // get table structures
+ foreach ($all_tables as $table)
+ {
+ if (strpos($table['Name'], $connection["tbpref"]) === 0)
+ db_query("DROP TABLE `".$table['Name'] . "`");
+ }
+ //deleting the tables, how??
+ return true;
+ }
+}
+
+?>
\ No newline at end of file
$c = 0;
// add result field names to column defs for
// col value retrieve and sort purposes
- $cnt = min(mysql_num_fields($result), count($this->columns));
+ $cnt = min(db_num_fields($result), count($this->columns));
for ($c = $i = 0; $c < $cnt; $c++) {
if (!(isset($this->columns[$c]['insert']) && $this->columns[$c]['insert'])) {
// if (!@($this->columns[$c]['type']=='skip'))
- $this->columns[$c]['name']= mysql_field_name($result, $i);
+ $this->columns[$c]['name']= db_field_name($result, $i);
if (!@($this->columns[$c]['type']=='insert'))
$i++;
}
global $db;
$conn = $_SESSION['inst_set'];
-
- $db = mysql_connect($conn["host"] , $conn["dbuser"], $conn["dbpassword"]);
- if(!$db) {
- display_error('Cannot connect to database server. Host name, username and/or password incorrect.');
- return false;
- }
- if (!defined('TB_PREF'))
- define('TB_PREF', '&TB_PREF&');
- if (!mysql_select_db($conn["dbname"], $db)) {
- $sql = "CREATE DATABASE " . $conn["dbname"];
- if (!mysql_query($sql)) {
- display_error('Cannot create database. Check your permissions to database creation or selct already created database.');
- return false;
- }
- return mysql_select_db($conn["dbname"], $db);
+ $db = db_create_db($conn);
+ if (!$db) {
+ display_error(_("Cannot connect to database. User or password is invalid or you have no permittions to create database."));
}
- return true;
+ return $db;
}
function do_install() {