Пример #1
0
function install_connect_db()
{
    global $db;
    $conn = $_SESSION['inst_set'];
    $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 $db;
}
Пример #2
0
function handle_submit()
{
    global $db_connections, $def_coy, $tb_pref_counter, $db, $comp_subdirs, $path_to_root, $selected_id;
    $error = false;
    if (!check_data()) {
        return false;
    }
    if ($selected_id == -1) {
        $selected_id = count($db_connections);
    }
    $new = !isset($db_connections[$selected_id]);
    if ((bool) $_POST['def'] == true) {
        $def_coy = $selected_id;
    }
    $db_connections[$selected_id]['name'] = $_POST['name'];
    if ($new) {
        $db_connections[$selected_id]['host'] = $_POST['host'];
        $db_connections[$selected_id]['dbuser'] = $_POST['dbuser'];
        $db_connections[$selected_id]['dbpassword'] = $_POST['dbpassword'];
        $db_connections[$selected_id]['dbname'] = $_POST['dbname'];
        if (is_numeric($_POST['tbpref'])) {
            $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'] == 1 ? $tb_pref_counter . "_" : '';
        } else {
            if ($_POST['tbpref'] != "") {
                $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'];
            } else {
                $db_connections[$selected_id]['tbpref'] = "";
            }
        }
        $conn = $db_connections[$selected_id];
        if (($db = db_create_db($conn)) == 0) {
            display_error(_("Error creating Database: ") . $conn['dbname'] . _(", Please create it manually"));
            $error = true;
        } else {
            if (!db_import($path_to_root . '/sql/' . get_post('coa'), $conn, $selected_id)) {
                display_error(_('Cannot create new company due to bugs in sql file.'));
                $error = true;
            } else {
                if (!isset($_POST['admpassword']) || $_POST['admpassword'] == "") {
                    $_POST['admpassword'] = "******";
                }
                update_admin_password($conn, md5($_POST['admpassword']));
            }
        }
        set_global_connection();
        if ($error) {
            remove_connection($selected_id);
            return false;
        }
    }
    $error = write_config_db($new);
    if ($error == -1) {
        display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
    } else {
        if ($error == -2) {
            display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
        } else {
            if ($error == -3) {
                display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
            }
        }
    }
    if ($error != 0) {
        return false;
    }
    if ($new) {
        create_comp_dirs(company_path($selected_id), $comp_subdirs);
    }
    $exts = get_company_extensions();
    write_extensions($exts, $selected_id);
    display_notification($new ? _('New company has been created.') : _('Company has been updated.'));
    return true;
}
Пример #3
0
/**
 * function for creating a database for creds in config.ini
 * @return int $res  the executed commands shell status 0 on success.
 */
function create_db($options = array())
{
    return db_create_db();
}
Пример #4
0
function handle_submit()
{
    global $db_connections, $def_coy, $tb_pref_counter, $db, $comp_path, $comp_subdirs;
    $new = false;
    if (!check_data()) {
        return false;
    }
    $id = $_GET['id'];
    $db_connections[$id]['name'] = $_POST['name'];
    $db_connections[$id]['host'] = $_POST['host'];
    $db_connections[$id]['dbuser'] = $_POST['dbuser'];
    $db_connections[$id]['dbpassword'] = $_POST['dbpassword'];
    $db_connections[$id]['dbname'] = $_POST['dbname'];
    if ((bool) $_POST['def'] == true) {
        $def_coy = $id;
    }
    if (isset($_GET['ul']) && $_GET['ul'] == 1) {
        $conn = $db_connections[$id];
        if (($db = db_create_db($conn)) == 0) {
            display_error(tr("Error creating Database: ") . $conn['dbname'] . tr(", Please create it manually"));
            remove_connection($id);
            set_global_connection();
            return false;
        }
        $filename = $_FILES['uploadfile']['tmp_name'];
        if (is_uploaded_file($filename)) {
            db_import($filename, $conn, $id);
            if (isset($_POST['admpassword']) && $_POST['admpassword'] != "") {
                db_query("UPDATE users set password = '******'admpassword']) . "' WHERE user_id = 'admin'");
            }
        } else {
            display_error(tr("Error uploading Database Script, please upload it manually"));
            set_global_connection();
            return false;
        }
        set_global_connection();
    }
    $error = write_config_db($new);
    if ($error == -1) {
        display_error(tr("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
    } else {
        if ($error == -2) {
            display_error(tr("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
        } else {
            if ($error == -3) {
                display_error(tr("The configuration file ") . $path_to_root . "/config_db.php" . tr(" is not writable. Change its permissions so it is, then re-run the operation."));
            }
        }
    }
    if ($error != 0) {
        return false;
    }
    $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
    if ($new) {
        $cdir = $comp_path . '/' . $id;
        @mkdir($cdir);
        save_to_file($cdir . '/' . 'index.php', 0, $index);
        foreach ($comp_subdirs as $dir) {
            @mkdir($cdir . '/' . $dir);
            save_to_file($cdir . '/' . $dir . '/' . 'index.php', 0, $index);
        }
    }
    return true;
}