Example #1
0
function step4($databasename, $newdatabasename)
{
    $host = $_SESSION['db_access']['host'];
    $user = $_SESSION['db_access']['user'];
    $password = $_SESSION['db_access']['password'];
    //display the form to return to the previous step.
    echo "<h3>" . __('Initialization of the database') . "</h3>";
    function prev_form($host, $user, $password)
    {
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='db_host' value='" . $host . "'>";
        echo "<input type='hidden' name='db_user' value='" . $user . "'>";
        echo " <input type='hidden' name='db_pass' value='" . rawurlencode($password) . "'>";
        echo "<input type='hidden' name='update' value='no'>";
        echo "<input type='hidden' name='install' value='Etape_2'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . __s('Back') . "'></p>";
        Html::closeForm();
    }
    //Display the form to go to the next page
    function next_form()
    {
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='install' value='Etape_4'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . __('Continue') . "'></p>";
        Html::closeForm();
    }
    //Check if the port is in url
    $hostport = explode(":", $host);
    if (count($hostport) < 2) {
        $link = new mysqli($hostport[0], $user, $password);
    } else {
        $link = new mysqli($hostport[0], $user, $password, '', $hostport[1]);
    }
    $databasename = $link->real_escape_string($databasename);
    $newdatabasename = $link->real_escape_string($newdatabasename);
    if (!empty($databasename)) {
        // use db already created
        $DB_selected = $link->select_db($databasename);
        if (!$DB_selected) {
            _e('Impossible to use the database:');
            echo "<br>" . sprintf(__('The server answered: %s'), $link->error);
            prev_form($host, $user, $password);
        } else {
            if (DBConnection::createMainConfig($host, $user, $password, $databasename)) {
                Toolbox::createSchema($_SESSION["glpilanguage"]);
                echo "<p>" . __('OK - database was initialized') . "</p>";
                next_form();
            } else {
                // can't create config_db file
                echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                prev_form($host, $user, $password);
            }
        }
    } else {
        if (!empty($newdatabasename)) {
            // create new db
            // Try to connect
            if ($link->select_db($newdatabasename)) {
                echo "<p>" . __('Database created') . "</p>";
                if (DBConnection::createMainConfig($host, $user, $password, $newdatabasename)) {
                    Toolbox::createSchema($_SESSION["glpilanguage"]);
                    echo "<p>" . __('OK - database was initialized') . "</p>";
                    next_form();
                } else {
                    // can't create config_db file
                    echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                    prev_form($host, $user, $password);
                }
            } else {
                // try to create the DB
                if ($link->query("CREATE DATABASE IF NOT EXISTS `" . $newdatabasename . "`")) {
                    echo "<p>" . __('Database created') . "</p>";
                    if ($link->select_db($newdatabasename) && DBConnection::createMainConfig($host, $user, $password, $newdatabasename)) {
                        Toolbox::createSchema($_SESSION["glpilanguage"]);
                        echo "<p>" . __('OK - database was initialized') . "</p>";
                        next_form();
                    } else {
                        // can't create config_db file
                        echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                        prev_form($host, $user, $password);
                    }
                } else {
                    // can't create database
                    echo __('Error in creating database!');
                    echo "<br>" . sprintf(__('The server answered: %s'), $link->error);
                    prev_form($host, $user, $password);
                }
            }
        } else {
            // no db selected
            echo "<p>" . __("You didn't select a database!") . "</p>";
            //prev_form();
            prev_form($host, $user, $password);
        }
    }
    $link->close();
}
function step4($databasename, $newdatabasename)
{
    $host = $_SESSION['db_access']['host'];
    $user = $_SESSION['db_access']['user'];
    $password = $_SESSION['db_access']['password'];
    //display the form to return to the previous step.
    echo "<h3>" . __('Initialization of the database') . "</h3>";
    function prev_form($host, $user, $password)
    {
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='db_host' value='" . $host . "'>";
        echo "<input type='hidden' name='db_user' value='" . $user . "'>";
        echo " <input type='hidden' name='db_pass' value='" . rawurlencode($password) . "'>";
        echo "<input type='hidden' name='update' value='no'>";
        echo "<input type='hidden' name='install' value='Etape_2'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . __s('Back') . "'></p>";
        Html::closeForm();
    }
    //Display the form to go to the next page
    function next_form()
    {
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='install' value='Etape_4'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . __('Continue') . "'></p>";
        Html::closeForm();
    }
    //Fill the database
    function fill_db()
    {
        global $CFG_GLPI, $DB;
        //include_once (GLPI_ROOT . "/inc/dbmysql.class.php");
        include_once GLPI_CONFIG_DIR . "/config_db.php";
        $DB = new DB();
        if (!$DB->runFile(GLPI_ROOT . "/install/mysql/glpi-0.85.3-empty.sql")) {
            echo "Errors occurred inserting default database";
        }
        // update default language
        Config::setConfigurationValues('core', array('language' => $_SESSION["glpilanguage"]));
        $query = "UPDATE `glpi_users`\n                SET `language` = NULL";
        $DB->queryOrDie($query, "4203");
    }
    //Check if the port is in url
    $hostport = explode(":", $host);
    if (count($hostport) < 2) {
        $link = new mysqli($hostport[0], $user, $password);
    } else {
        $link = new mysqli($hostport[0], $user, $password, '', $hostport[1]);
    }
    $databasename = $link->real_escape_string($databasename);
    $newdatabasename = $link->real_escape_string($newdatabasename);
    if (!empty($databasename)) {
        // use db already created
        $DB_selected = $link->select_db($databasename);
        if (!$DB_selected) {
            _e('Impossible to use the database:');
            echo "<br>" . sprintf(__('The server answered: %s'), $link->error);
            prev_form($host, $user, $password);
        } else {
            if (create_conn_file($host, $user, $password, $databasename)) {
                fill_db();
                echo "<p>" . __('OK - database was initialized') . "</p>";
                next_form();
            } else {
                // can't create config_db file
                echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                prev_form($host, $user, $password);
            }
        }
    } else {
        if (!empty($newdatabasename)) {
            // create new db
            // Try to connect
            if ($link->select_db($newdatabasename)) {
                echo "<p>" . __('Database created') . "</p>";
                if (create_conn_file($host, $user, $password, $newdatabasename)) {
                    fill_db();
                    echo "<p>" . __('OK - database was initialized') . "</p>";
                    next_form();
                } else {
                    // can't create config_db file
                    echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                    prev_form($host, $user, $password);
                }
            } else {
                // try to create the DB
                if ($link->query("CREATE DATABASE IF NOT EXISTS `" . $newdatabasename . "`")) {
                    echo "<p>" . __('Database created') . "</p>";
                    if ($link->select_db($newdatabasename) && create_conn_file($host, $user, $password, $newdatabasename)) {
                        fill_db();
                        echo "<p>" . __('OK - database was initialized') . "</p>";
                        next_form();
                    } else {
                        // can't create config_db file
                        echo "<p>" . __('Impossible to write the database setup file') . "</p>";
                        prev_form($host, $user, $password);
                    }
                } else {
                    // can't create database
                    echo __('Error in creating database!');
                    echo "<br>" . sprintf(__('The server answered: %s'), $link->error);
                    prev_form($host, $user, $password);
                }
            }
        } else {
            // no db selected
            echo "<p>" . __("You didn't select a database!") . "</p>";
            //prev_form();
            prev_form($host, $user, $password);
        }
    }
    $link->close();
}
Example #3
0
function step4($host, $user, $password, $databasename, $newdatabasename)
{
    global $LANG;
    //display the form to return to the previous step.
    echo "<h3>" . $LANG['install'][24] . "</h3>";
    function prev_form($host, $user, $password)
    {
        global $LANG;
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='db_host' value='" . $host . "'>";
        echo "<input type='hidden' name='db_user' value='" . $user . "'>";
        echo " <input type='hidden' name='db_pass' value='" . rawurlencode($password) . "'>";
        echo "<input type='hidden' name='update' value='no'>";
        echo "<input type='hidden' name='install' value='Etape_2'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . $LANG['buttons'][13] . "'></p>";
        echo "</form>";
    }
    //Display the form to go to the next page
    function next_form()
    {
        global $LANG;
        echo "<br><form action='install.php' method='post'>";
        echo "<input type='hidden' name='install' value='Etape_4'>";
        echo "<p class='submit'><input type='submit' name='submit' class='submit' value='" . $LANG['install'][26] . "'></p>";
        echo "</form>";
    }
    //Fill the database
    function fill_db()
    {
        global $LANG, $CFG_GLPI;
        include_once GLPI_ROOT . "/inc/dbmysql.class.php";
        include_once GLPI_CONFIG_DIR . "/config_db.php";
        $DB = new DB();
        if (!$DB->runFile(GLPI_ROOT . "/install/mysql/glpi-0.80.1-empty.sql")) {
            echo "Errors occurred inserting default database";
        }
        // update default language
        $query = "UPDATE `glpi_configs`\n                SET `language` = '" . $_SESSION["glpilanguage"] . "'";
        $DB->query($query) or die("4203 " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_users`\n                SET `language` = NULL";
        $DB->query($query) or die("4203 " . $LANG['update'][90] . $DB->error());
    }
    $link = mysql_connect($host, $user, $password);
    if (!empty($databasename)) {
        // use db already created
        $DB_selected = mysql_select_db($databasename, $link);
        if (!$DB_selected) {
            echo $LANG['install'][41];
            echo "<br>" . $LANG['install'][36] . " " . mysql_error();
            prev_form($host, $user, $password);
        } else {
            if (create_conn_file($host, $user, $password, $databasename)) {
                fill_db();
                echo "<p>" . $LANG['install'][43] . "</p>";
                next_form();
            } else {
                // can't create config_db file
                echo "<p>" . $LANG['install'][47] . "</p>";
                prev_form($host, $user, $password);
            }
        }
    } else {
        if (!empty($newdatabasename)) {
            // create new db
            // Try to connect
            if (mysql_select_db($newdatabasename, $link)) {
                echo "<p>" . $LANG['install'][82] . "</p>";
                if (create_conn_file($host, $user, $password, $newdatabasename)) {
                    fill_db();
                    echo "<p>" . $LANG['install'][43] . "</p>";
                    next_form();
                } else {
                    // can't create config_db file
                    echo "<p>" . $LANG['install'][47] . "</p>";
                    prev_form($host, $user, $password);
                }
            } else {
                // try to create the DB
                if (mysql_query("CREATE DATABASE IF NOT EXISTS `" . $newdatabasename . "`")) {
                    echo "<p>" . $LANG['install'][82] . "</p>";
                    if (mysql_select_db($newdatabasename, $link) && create_conn_file($host, $user, $password, $newdatabasename)) {
                        fill_db();
                        echo "<p>" . $LANG['install'][43] . "</p>";
                        next_form();
                    } else {
                        // can't create config_db file
                        echo "<p>" . $LANG['install'][47] . "</p>";
                        prev_form($host, $user, $password);
                    }
                } else {
                    // can't create database
                    echo $LANG['install'][48];
                    echo "<br>" . $LANG['install'][42] . mysql_error();
                    prev_form($host, $user, $password);
                }
            }
        } else {
            // no db selected
            echo "<p>" . $LANG['install'][49] . "</p>";
            //prev_form();
            prev_form($host, $user, $password);
        }
    }
    mysql_close($link);
}