/** * Dsiplay a screen where user can create a table from an existing one. * We don't have to check if pg supports schema cause create table like * is available under pg 7.4+ which has schema. */ function doCreateLike($confirm, $msg = '') { global $data, $misc, $lang; if (!$confirm) { include_once './classes/Gui.php'; if (!isset($_REQUEST['name'])) { $_REQUEST['name'] = ''; } if (!isset($_REQUEST['like'])) { $_REQUEST['like'] = ''; } if (!isset($_REQUEST['tablespace'])) { $_REQUEST['tablespace'] = ''; } $misc->printTrail('schema'); $misc->printTitle($lang['strcreatetable'], 'pg.table.create'); $misc->printMsg($msg); $tbltmp = $data->getTables(true); $tbltmp = $tbltmp->getArray(); $tables = array(); $tblsel = ''; foreach ($tbltmp as $a) { $data->fieldClean($a['nspname']); $data->fieldClean($a['relname']); $tables["\"{$a['nspname']}\".\"{$a['relname']}\""] = serialize(array('schema' => $a['nspname'], 'table' => $a['relname'])); if ($_REQUEST['like'] == $tables["\"{$a['nspname']}\".\"{$a['relname']}\""]) { $tblsel = htmlspecialchars($tables["\"{$a['nspname']}\".\"{$a['relname']}\""]); } } unset($tbltmp); echo "<form action=\"tables.php\" method=\"post\">\n"; echo "<table>\n\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strcreatetablelikeparent']}</th>\n"; echo "\t\t<td class=\"data\">"; echo GUI::printCombo($tables, 'like', true, $tblsel, false); echo "</td>\n\t</tr>\n"; if ($data->hasTablespaces()) { $tblsp_ = $data->getTablespaces(); if ($tblsp_->recordCount() > 0) { $tblsp_ = $tblsp_->getArray(); $tblsp = array(); foreach ($tblsp_ as $a) { $tblsp[$a['spcname']] = $a['spcname']; } echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n"; echo "\t\t<td class=\"data\">"; echo GUI::printCombo($tblsp, 'tablespace', true, $_REQUEST['tablespace'], false); echo "</td>\n\t</tr>\n"; } } echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stroptions']}</th>\n\t\t<td class=\"data\">"; echo "<label for=\"withdefaults\"><input type=\"checkbox\" id=\"withdefaults\" name=\"withdefaults\"", isset($_REQUEST['withdefaults']) ? ' checked="checked"' : '', "/>{$lang['strcreatelikewithdefaults']}</label>"; if ($data->hasCreateTableLikeWithConstraints()) { echo "<br /><label for=\"withconstraints\"><input type=\"checkbox\" id=\"withconstraints\" name=\"withconstraints\"", isset($_REQUEST['withconstraints']) ? ' checked="checked"' : '', "/>{$lang['strcreatelikewithconstraints']}</label>"; } if ($data->hasCreateTableLikeWithIndexes()) { echo "<br /><label for=\"withindexes\"><input type=\"checkbox\" id=\"withindexes\" name=\"withindexes\"", isset($_REQUEST['withindexes']) ? ' checked="checked"' : '', "/>{$lang['strcreatelikewithindexes']}</label>"; } echo "</td>\n\t</tr>\n"; echo "</table>"; echo "<input type=\"hidden\" name=\"action\" value=\"confcreatelike\" />\n"; echo $misc->form; echo "<p><input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; echo "</form>\n"; } else { global $_reload_browser; if (trim($_REQUEST['name']) == '') { doCreateLike(false, $lang['strtableneedsname']); return; } if (trim($_REQUEST['like']) == '') { doCreateLike(false, $lang['strtablelikeneedslike']); return; } if (!isset($_REQUEST['tablespace'])) { $_REQUEST['tablespace'] = ''; } $status = $data->createTableLike($_REQUEST['name'], unserialize($_REQUEST['like']), isset($_REQUEST['withdefaults']), isset($_REQUEST['withconstraints']), isset($_REQUEST['withindexes']), $_REQUEST['tablespace']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strtablecreated']); } else { doCreateLike(false, $lang['strtablecreatedbad']); return; } } }
/** * Display a wizard where they can enter a new view */ function doWizardCreate($msg = '') { global $data, $misc; global $lang; $tables = $data->getTables(true); $misc->printTrail('schema'); $misc->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); $misc->printMsg($msg); echo "<form action=\"views.php\" method=\"post\">\n"; echo "<table>\n"; echo "<tr><th class=\"data\">{$lang['strtables']}</th></tr>"; echo "<tr>\n<td class=\"data1\">\n"; $arrTables = array(); while (!$tables->EOF) { $arrTmp = array(); $arrTmp['schemaname'] = $tables->fields['nspname']; $arrTmp['tablename'] = $tables->fields['relname']; $arrTables[$tables->fields['nspname'] . '.' . $tables->fields['relname']] = serialize($arrTmp); $tables->moveNext(); } echo GUI::printCombo($arrTables, 'formTables[]', false, '', true); echo "</td>\n</tr>\n"; echo "</table>\n"; echo "<p><input type=\"hidden\" name=\"action\" value=\"set_params_create\" />\n"; echo $misc->form; echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n"; echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; echo "</form>\n"; }
/** * Displays a screen where one can enter a details of a new FTS dictionary */ function doCreateDict($msg = '') { global $data, $misc; global $lang; include_once './classes/Gui.php'; $server_info = $misc->getServerInfo(); if (!isset($_POST['formName'])) { $_POST['formName'] = ''; } if (!isset($_POST['formIsTemplate'])) { $_POST['formIsTemplate'] = false; } if (!isset($_POST['formTemplate'])) { $_POST['formTemplate'] = ''; } if (!isset($_POST['formLexize'])) { $_POST['formLexize'] = ''; } if (!isset($_POST['formInit'])) { $_POST['formInit'] = ''; } if (!isset($_POST['formOption'])) { $_POST['formOption'] = ''; } if (!isset($_POST['formComment'])) { $_POST['formComment'] = ''; } // Fetch all FTS dictionaries from the database $ftstpls = $data->getFtsDictionaryTemplates(); $misc->printTrail('schema'); // TODO: create doc links $misc->printTitle($lang['strftscreatedict'], 'pg.ftsdict.create'); $misc->printMsg($msg); echo "<form action=\"fulltext.php\" method=\"post\">\n"; echo "<table>\n"; echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formName']), "\" /> ", "<input type=\"checkbox\" name=\"formIsTemplate\" id=\"formIsTemplate\"", $_POST['formIsTemplate'] ? ' checked="checked" ' : '', " />\n", "<label for=\"formIsTemplate\">{$lang['strftscreatedicttemplate']}</label></td>\n\t</tr>\n"; // Template echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n"; echo "\t\t<td class=\"data1\">"; $tpls = array(); $tplsel = ''; while (!$ftstpls->EOF) { $data->fieldClean($ftstpls->fields['schema']); $data->fieldClean($ftstpls->fields['name']); $tplname = $ftstpls->fields['schema'] . '.' . $ftstpls->fields['name']; $tpls[$tplname] = serialize(array('name' => $ftstpls->fields['name'], 'schema' => $ftstpls->fields['schema'])); if ($_POST['formTemplate'] == $tpls[$tplname]) { $tplsel = htmlspecialchars($tpls[$tplname]); } $ftstpls->moveNext(); } echo GUI::printCombo($tpls, 'formTemplate', true, $tplsel, false); echo "\n\t\t</td>\n\t</tr>\n"; // TODO: what about maxlengths? // Lexize echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftslexize']}</th>\n"; echo "\t\t<td class=\"data1\"><input name=\"formLexize\" size=\"32\" maxlength=\"1000\" value=\"", htmlspecialchars($_POST['formLexize']), "\" ", isset($_POST['formIsTemplate']) ? '' : ' disabled="disabled" ', "/></td>\n\t</tr>\n"; // Init echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsinit']}</th>\n"; echo "\t\t<td class=\"data1\"><input name=\"formInit\" size=\"32\" maxlength=\"1000\" value=\"", htmlspecialchars($_POST['formInit']), "\"", @$_POST['formIsTemplate'] ? '' : ' disabled="disabled" ', "/></td>\n\t</tr>\n"; // Option echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsoptionsvalues']}</th>\n"; echo "\t\t<td class=\"data1\"><input name=\"formOption\" size=\"32\" maxlength=\"1000\" value=\"", htmlspecialchars($_POST['formOption']), "\" /></td>\n\t</tr>\n"; // Comment echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; echo "</table>\n"; echo "<p>\n"; echo "<input type=\"hidden\" name=\"action\" value=\"createdict\" />\n"; echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\" />\n"; echo $misc->form; echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; echo "</p>\n"; echo "</form>\n", "<script type=\"text/javascript\">\t\t\t\t\n\t\t\t\tfunction templateOpts() {\n\t\t\t\t\tisTpl = document.getElementsByName('formIsTemplate')[0].checked;\n\t\t\t\t\tdocument.getElementsByName('formTemplate')[0].disabled = isTpl;\n\t\t\t\t\tdocument.getElementsByName('formOption')[0].disabled = isTpl;\n\t\t\t\t\tdocument.getElementsByName('formLexize')[0].disabled = !isTpl;\n\t\t\t\t\tdocument.getElementsByName('formInit')[0].disabled = !isTpl;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tdocument.getElementsByName('formIsTemplate')[0].onchange = templateOpts;\n\n\t\t\t\ttemplateOpts();\n\t\t\t</script>\n"; }