Example #1
0
    //$sqlQuery = Check::safeText($sqlQuery, false);
    echo HTML::start('form', array('method' => 'post', 'action' => $_SERVER['PHP_SELF']));
    $body = array();
    $body[] = Form::textArea("sql_query", $sqlQuery, array('rows' => 15, 'cols' => 75, 'readonly' => true));
    $foot = array(Form::button("install_file", _("Install file")) . Form::generateToken());
    echo Form::fieldset(_("Install file"), $body, $foot);
    echo HTML::end('form');
    echo HTML::para(HTML::link(_("Cancel"), './index.php'));
    include_once "../layout/footer.php";
    exit;
}
// end if
require_once "../model/Query.php";
$installQ = new Query();
$installQ->captureError(true);
if ($installQ->isError()) {
    echo HTML::para(_("The connection to the database failed with the following error:"));
    echo Msg::error($installQ->getDbError());
    echo HTML::rule();
    echo HTML::para(_("Please make sure the following has been done before running this install script."));
    $array = array(sprintf(_("Create OpenClinic database (%s of the install instructions)"), HTML::link(sprintf(_("step %d"), 4), '../install.html#step4')), sprintf(_("Create OpenClinic database user (%s of the install instructions)"), HTML::link(sprintf(_("step %d"), 5), '../install.html#step5')), sprintf(_("Update %s with your new database username and password (%s of the install instructions)"), HTML::tag('strong', 'openclinic/config/database_constants.php'), HTML::link(sprintf(_("step %d"), 8), '../install.html#step8')));
    echo HTML::itemList($array, null, true);
    echo HTML::para(sprintf(_("See %s for more details."), HTML::link(_("Install Instructions"), '../install.html')));
    include_once "../layout/footer.php";
    exit;
}
// end if
$installQ->close();
echo Msg::info(_("Database connection is good."));
echo HTML::start('form', array('method' => 'post', 'action' => $_SERVER['PHP_SELF'], 'enctype' => 'multipart/form-data'));
$body = array();
Example #2
0
/**
 * bool parseSql(string $text)
 *
 * Parses a SQL text
 *
 * @param string $text sentences to parse
 * @return bool false if an error occurs
 * @access public
 * @since 0.8
 */
function parseSql($text)
{
    $controlledErrors = array(1060, 1091);
    $installQ = new Query();
    $installQ->captureError(true);
    /**
     * reading through SQL text executing SQL only when ";" is encountered and if is out of brackets
     */
    $count = strlen($text);
    $sqlSentence = "";
    $outBracket = true;
    for ($i = 0; $i < $count; $i++) {
        $char = $text[$i];
        if ($char == "(") {
            $outBracket = false;
        }
        if ($char == ")") {
            $outBracket = true;
        }
        if ($char == ";" && $outBracket) {
            $result = $installQ->exec($sqlSentence);
            if ($installQ->isError() && !in_array($installQ->getDbErrno(), $controlledErrors)) {
                echo HTML::para(sprintf(_("Process sql [%s]"), $sqlSentence));
                $installQ->close();
                Error::query($installQ, false);
                echo Msg::error(sprintf(_("Error: %s"), $installQ->getDbError()));
                return false;
            }
            $sqlSentence = "";
        } else {
            $sqlSentence .= $char;
        }
    }
    $installQ->close();
    return true;
}