예제 #1
0
/**
 * Confirm and then actually add a PRIMARY KEY or UNIQUE constraint
 */
function addPrimaryOrUniqueKey($type, $confirm, $msg = '')
{
    global $data, $misc;
    global $lang;
    if (!isset($_POST['name'])) {
        $_POST['name'] = '';
    }
    if ($confirm) {
        if (!isset($_POST['name'])) {
            $_POST['name'] = '';
        }
        if (!isset($_POST['tablespace'])) {
            $_POST['tablespace'] = '';
        }
        $misc->printTrail('table');
        switch ($type) {
            case 'primary':
                $misc->printTitle($lang['straddpk'], 'pg.constraint.primary_key');
                break;
            case 'unique':
                $misc->printTitle($lang['stradduniq'], 'pg.constraint.unique_key');
                break;
            default:
                doDefault($lang['strinvalidparam']);
                return;
        }
        $misc->printMsg($msg);
        $attrs = $data->getTableAttributes($_REQUEST['table']);
        // Fetch all tablespaces from the database
        if ($data->hasTablespaces()) {
            $tablespaces = $data->getTablespaces();
        }
        $selColumns = new XHTML_select('TableColumnList', true, 10);
        $selColumns->set_style('width: 15em;');
        if ($attrs->recordCount() > 0) {
            while (!$attrs->EOF) {
                $selColumns->add(new XHTML_Option($attrs->fields['attname']));
                $attrs->moveNext();
            }
        }
        $selIndex = new XHTML_select('IndexColumnList[]', true, 10);
        $selIndex->set_style('width: 15em;');
        $selIndex->set_attribute('id', 'IndexColumnList');
        $buttonAdd = new XHTML_Button('add', '>>');
        $buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
        $buttonAdd->set_attribute('type', 'button');
        $buttonRemove = new XHTML_Button('remove', '<<');
        $buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
        $buttonRemove->set_attribute('type', 'button');
        echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"constraints.php\" method=\"post\">\n";
        echo "<table>\n";
        echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>";
        echo "<tr>";
        echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" value=\"", htmlspecialchars($_POST['name']), "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
        echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=\"data required\">{$lang['strindexcolumnlist']}</th></tr>\n";
        echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
        echo "<td class=\"data1\" style=\"text-align: center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
        echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
        // Tablespace (if there are any)
        if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
            echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strtablespace']}</th></tr>";
            echo "<tr><td class=\"data1\" colspan=\"3\"><select name=\"tablespace\">\n";
            // Always offer the default (empty) option
            echo "\t\t\t\t<option value=\"\"", $_POST['tablespace'] == '' ? ' selected="selected"' : '', "></option>\n";
            // Display all other tablespaces
            while (!$tablespaces->EOF) {
                $spcname = htmlspecialchars($tablespaces->fields['spcname']);
                echo "\t\t\t\t<option value=\"{$spcname}\"", $spcname == $_POST['tablespace'] ? ' selected="selected"' : '', ">{$spcname}</option>\n";
                $tablespaces->moveNext();
            }
            echo "</select></td></tr>\n";
        }
        echo "</table>\n";
        echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_primary_key\" />\n";
        echo $misc->form;
        echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
        echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($type), "\" />\n";
        echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
        echo "</form>\n";
    } else {
        // Default tablespace to empty if it isn't set
        if (!isset($_POST['tablespace'])) {
            $_POST['tablespace'] = '';
        }
        if ($_POST['type'] == 'primary') {
            // Check that they've given at least one column
            if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList']) || sizeof($_POST['IndexColumnList']) == 0) {
                addPrimaryOrUniqueKey($_POST['type'], true, $lang['strpkneedscols']);
            } else {
                $status = $data->addPrimaryKey($_POST['table'], $_POST['IndexColumnList'], $_POST['name'], $_POST['tablespace']);
                if ($status == 0) {
                    doDefault($lang['strpkadded']);
                } else {
                    addPrimaryOrUniqueKey($_POST['type'], true, $lang['strpkaddedbad']);
                }
            }
        } elseif ($_POST['type'] == 'unique') {
            // Check that they've given at least one column
            if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList']) || sizeof($_POST['IndexColumnList']) == 0) {
                addPrimaryOrUniqueKey($_POST['type'], true, $lang['struniqneedscols']);
            } else {
                $status = $data->addUniqueKey($_POST['table'], $_POST['IndexColumnList'], $_POST['name'], $_POST['tablespace']);
                if ($status == 0) {
                    doDefault($lang['struniqadded']);
                } else {
                    addPrimaryOrUniqueKey($_POST['type'], true, $lang['struniqaddedbad']);
                }
            }
        } else {
            doDefault($lang['strinvalidparam']);
        }
    }
}
예제 #2
0
파일: indexes.php 프로젝트: hardikk/HNH
/**
 * Displays a screen where they can enter a new index
 */
function doCreateIndex($msg = '')
{
    global $data, $misc;
    global $lang;
    if (!isset($_POST['formIndexName'])) {
        $_POST['formIndexName'] = '';
    }
    if (!isset($_POST['formIndexType'])) {
        $_POST['formIndexType'] = null;
    }
    if (!isset($_POST['formCols'])) {
        $_POST['formCols'] = '';
    }
    if (!isset($_POST['formWhere'])) {
        $_POST['formWhere'] = '';
    }
    if (!isset($_POST['formSpc'])) {
        $_POST['formSpc'] = '';
    }
    $attrs = $data->getTableAttributes($_REQUEST['table']);
    // Fetch all tablespaces from the database
    if ($data->hasTablespaces()) {
        $tablespaces = $data->getTablespaces();
    }
    $misc->printTrail('table');
    $misc->printTitle($lang['strcreateindex'], 'pg.index.create');
    $misc->printMsg($msg);
    $selColumns = new XHTML_select("TableColumnList", true, 10);
    $selColumns->set_style("width: 10em;");
    if ($attrs->recordCount() > 0) {
        while (!$attrs->EOF) {
            $selColumns->add(new XHTML_Option($attrs->fields['attname']));
            $attrs->moveNext();
        }
    }
    $selIndex = new XHTML_select("IndexColumnList[]", true, 10);
    $selIndex->set_style("width: 10em;");
    $selIndex->set_attribute("id", "IndexColumnList");
    $buttonAdd = new XHTML_Button("add", ">>");
    $buttonAdd->set_attribute("onclick", "buttonPressed(this);");
    $buttonAdd->set_attribute("type", "button");
    $buttonRemove = new XHTML_Button("remove", "<<");
    $buttonRemove->set_attribute("onclick", "buttonPressed(this);");
    $buttonRemove->set_attribute("type", "button");
    echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"indexes.php\" method=\"post\">\n";
    echo "<table>\n";
    echo "<tr><th class=\"data required\" colspan=\"3\">{$lang['strindexname']}</th></tr>";
    echo "<tr>";
    echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"formIndexName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formIndexName']), "\" /></td></tr>";
    echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th>";
    echo "<th class=\"data required\">{$lang['strindexcolumnlist']}</th></tr>\n";
    echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
    echo "<td class=\"data1\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
    echo "<td class=\"data1\">" . $selIndex->fetch() . "</td></tr>\n";
    echo "</table>\n";
    echo "<table> \n";
    echo "<tr>";
    echo "<th class=\"data left required\" scope=\"row\">{$lang['strindextype']}</th>";
    echo "<td class=\"data1\"><select name=\"formIndexType\">";
    foreach ($data->typIndexes as $v) {
        echo "<option value=\"", htmlspecialchars($v), "\"", $v == $_POST['formIndexType'] ? ' selected="selected"' : '', ">", htmlspecialchars($v), "</option>\n";
    }
    echo "</select></td></tr>\n";
    echo "<tr>";
    echo "<th class=\"data left\" scope=\"row\"><label for=\"formUnique\">{$lang['strunique']}</label></th>";
    echo "<td class=\"data1\"><input type=\"checkbox\" id=\"formUnique\" name=\"formUnique\"", isset($_POST['formUnique']) ? 'checked="checked"' : '', " /></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<th class=\"data left\" scope=\"row\">{$lang['strwhere']}</th>";
    echo "<td class=\"data1\">(<input name=\"formWhere\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formWhere']), "\" />)</td>";
    echo "</tr>";
    // Tablespace (if there are any)
    if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
        echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">\n";
        // Always offer the default (empty) option
        echo "\t\t\t\t<option value=\"\"", $_POST['formSpc'] == '' ? ' selected="selected"' : '', "></option>\n";
        // Display all other tablespaces
        while (!$tablespaces->EOF) {
            $spcname = htmlspecialchars($tablespaces->fields['spcname']);
            echo "\t\t\t\t<option value=\"{$spcname}\"", $spcname == $_POST['formSpc'] ? ' selected="selected"' : '', ">{$spcname}</option>\n";
            $tablespaces->moveNext();
        }
        echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
    }
    if ($data->hasConcurrentIndexBuild()) {
        echo "<tr>";
        echo "<th class=\"data left\" scope=\"row\"><label for=\"formConcur\">{$lang['strconcurrently']}</label></th>";
        echo "<td class=\"data1\"><input type=\"checkbox\" id=\"formConcur\" name=\"formConcur\"", isset($_POST['formConcur']) ? 'checked="checked"' : '', " /></td>";
        echo "</tr>";
    }
    echo "</table>";
    echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_index\" />\n";
    echo $misc->form;
    echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
    echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
    echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
    echo "</form>\n";
}