'; /** * Default method to render the controller according to the action parameter. */ public function render() { if ('tree' == $this->action) { return $this->doTree(); } $this->printHeader($this->headerTitle(), $this->scripts); $onloadInit = false; if ('create_index' == $this->action || 'save_create_index' == $this->action) { $onloadInit = true; } $this->printBody(true, 'detailbody', $onloadInit); switch ($this->action) { case 'cluster_index': if (isset($_POST['cluster'])) { $this->doClusterIndex(false); } else { $this->doDefault(); } break; case 'confirm_cluster_index': $this->doClusterIndex(true); break; case 'reindex': $this->doReindex(); break; case 'save_create_index': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doSaveCreateIndex(); } break; case 'create_index': $this->doCreateIndex(); break; case 'drop_index': if (isset($_POST['drop'])) { $this->doDropIndex(false); } else { $this->doDefault(); } break; case 'confirm_drop_index': $this->doDropIndex(true); break; default: $this->doDefault(); break; } return $this->printFooter(); } public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $lang = $this->lang; $indPre = function (&$rowdata, $actions) use ($data, $lang) { if ($data->phpBool($rowdata->fields['indisprimary'])) { $rowdata->fields['+constraints'] = $lang['strprimarykey']; $actions['drop']['disable'] = true; } elseif ($data->phpBool($rowdata->fields['indisunique'])) { $rowdata->fields['+constraints'] = $lang['struniquekey']; $actions['drop']['disable'] = true; } else { $rowdata->fields['+constraints'] = ''; } return $actions; }; $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($this->getRequestParam('subject', 'table')); $object = urlencode($this->getRequestParam($subject)); $this->printTrail($subject); $this->printTabs($subject, 'indexes'); $this->printMsg($msg); $indexes = $data->getIndexes($object); $columns = [ 'index' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('indname'), ], 'definition' => [ 'title' => $this->lang['strdefinition'], 'field' => Decorator::field('inddef'), ], 'constraints' => [ 'title' => $this->lang['strconstraints'], 'field' => Decorator::field('+constraints'), 'type' => 'verbatim', 'params' => ['align' => 'center'], ], 'clustered' => [ 'title' => $this->lang['strclustered'], 'field' => Decorator::field('indisclustered'), 'type' => 'yesno', ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('idxcomment'), ], ]; $url = \SUBFOLDER.'/src/views/indexes'; $actions = [ 'cluster' => [ 'content' => $this->lang['strclusterindex'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'confirm_cluster_index', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], 'reindex' => [ 'content' => $this->lang['strreindex'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'reindex', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'confirm_drop_index', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], ]; echo $this->printTable($indexes, $columns, $actions, 'indexes-indexes', $this->lang['strnoindexes'], $indPre); $this->printNavLinks([ 'create' => [ 'attr' => [ 'href' => [ 'url' => 'indexes', 'urlvars' => [ 'action' => 'create_index', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], $subject => $object, 'subject' => $subject, ], ], ], 'content' => $this->lang['strcreateindex'], ], ], 'indexes-indexes', get_defined_vars()); } public function doTree() { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$subject]); $indexes = $data->getIndexes($object); $getIcon = function ($f) { if ('t' == $f['indisprimary']) { return 'PrimaryKey'; } if ('t' == $f['indisunique']) { return 'UniqueConstraint'; } return 'Index'; }; $attrs = [ 'text' => Decorator::field('indname'), 'icon' => Decorator::callback($getIcon), ]; return $this->printTree($indexes, $attrs, 'indexes'); } /** * Show confirmation of cluster index and perform actual cluster. * * @param mixed $confirm */ public function doClusterIndex($confirm) { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$subject]); //$this->printTrail($subject); if ($confirm) { // Default analyze to on $_REQUEST['analyze'] = true; $this->printTrail('index'); $this->printTabs($subject, 'indexes'); $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); echo '

', sprintf($this->lang['strconfcluster'], $this->misc->printVal($_REQUEST['index'])), '

'.PHP_EOL; echo '
'.PHP_EOL; echo '

'; echo "

".PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo "lang['strclusterindex']}\" />".PHP_EOL; echo "lang['strcancel']}\" />".PHP_EOL; echo '
'.PHP_EOL; } else { set_time_limit(0); list($status, $sql) = $data->clusterIndex($object, $_POST['index']); if (0 == $status) { if (isset($_POST['analyze'])) { $status = $data->analyzeDB($object); if (0 == $status) { $this->doDefault($sql.'
'.$this->lang['strclusteredgood'].' '.$this->lang['stranalyzegood']); } else { $this->doDefault($sql.'
'.$this->lang['stranalyzebad']); } } else { $this->doDefault($sql.'
'.$this->lang['strclusteredgood']); } } else { $this->doDefault($sql.'
'.$this->lang['strclusteredbad']); } } } public function doReindex() { $data = $this->misc->getDatabaseAccessor(); set_time_limit(0); $status = $data->reindex('INDEX', $_REQUEST['index']); if (0 == $status) { $this->doDefault($this->lang['strreindexgood']); } else { $this->doDefault($this->lang['strreindexbad']); } } /** * Displays a screen where they can enter a new index. * * @param mixed $msg */ public function doCreateIndex($msg = '') { $data = $this->misc->getDatabaseAccessor(); $subject = urlencode($this->getRequestParam('subject', 'table')); $object = urlencode($this->getRequestParam($subject)); $formIndexName = $this->getPostParam('formIndexName', ''); $formIndexType = $this->getPostParam('formIndexType'); $formUnique = $this->getPostParam('formUnique'); $formConcur = $this->getPostParam('formConcur'); $formWhere = $this->getPostParam('formWhere', ''); $formSpc = $this->getPostParam('formSpc', ''); $tablespaces = null; $attrs = $data->getTableAttributes($object); // Fetch all tablespaces from the database if ($data->hasTablespaces()) { $tablespaces = $data->getTablespaces(); } $this->printTrail($subject); $this->printTabs($subject, 'indexes'); $this->printTitle($this->lang['strcreateindex'], 'pg.index.create'); $this->printMsg($msg); $selColumns = new \PHPPgAdmin\XHtml\XHtmlSelect('TableColumnList', true, 10); $selColumns->set_style('width: 14em;'); if ($attrs->recordCount() > 0) { while (!$attrs->EOF) { $attname = new \PHPPgAdmin\XHtml\XHtmlOption($attrs->fields['attname']); $selColumns->add($attname); $attrs->moveNext(); } } $selIndex = new \PHPPgAdmin\XHtml\XHtmlSelect('IndexColumnList[]', true, 10); $selIndex->set_style('width: 14em;'); $selIndex->set_attribute('id', 'IndexColumnList'); $buttonAdd = new \PHPPgAdmin\XHtml\XHtmlButton('add', '>>'); $buttonAdd->set_attribute('onclick', 'buttonPressed(this);'); $buttonAdd->set_attribute('type', 'button'); $buttonRemove = new \PHPPgAdmin\XHtml\XHtmlButton('remove', '<<'); $buttonRemove->set_attribute('onclick', 'buttonPressed(this);'); $buttonRemove->set_attribute('type', 'button'); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''; echo ''.PHP_EOL; echo ''; echo ''; echo ''.PHP_EOL; echo ''; echo ""; echo ''; echo ''; echo ''; echo ""; echo ''; echo ''; // Tablespace (if there are any) if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { echo ''.PHP_EOL; echo "".PHP_EOL; echo '\n\t".PHP_EOL; } if ($data->hasConcurrentIndexBuild()) { echo ''; echo ""; echo ''; echo ''; } echo '
'.$this->lang['strindexname'].'
'; echo 'Index name cannot exceed '.$data->_maxNameLen.' characters
'; echo ''; echo '
'.$this->lang['strtablecolumnlist'].' '.$this->lang['strindexcolumnlist'].'
'.$selColumns->fetch().''.$buttonRemove->fetch().$buttonAdd->fetch().''.$selIndex->fetch().'
'.$this->lang['strindextype'].'
{$this->lang['strwhere']}()
{$this->lang['strtablespace']}'; echo "\n\t\t\t\n\t\t
'; echo '

'.PHP_EOL; echo $this->misc->form; echo ''.PHP_EOL; echo ''.PHP_EOL; echo "lang['strcreate']}\" />".PHP_EOL; echo "lang['strcancel']}\" />

".PHP_EOL; echo '
'.PHP_EOL; } /** * Actually creates the new index in the database. * * @@ Note: this function can't handle columns with commas in them */ public function doSaveCreateIndex() { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_POST, 'subject', 'table'); $subject = urlencode($_POST['subject']); $object = urlencode($_POST[$subject]); // Handle databases that don't have partial indexes $formWhere = $this->getPostParam('formWhere', ''); // Default tablespace to null if it isn't set $formSpc = $this->getPostParam('formSpc'); $IndexColumnList = $this->getPostParam('IndexColumnList', ''); // Check that they've given a name and at least one column if ('' == $IndexColumnList) { $this->doCreateIndex($this->lang['strindexneedscols']); } else { list($status, $sql) = $data->createIndex( $this->getPostParam('formIndexName', ''), $object, $IndexColumnList, $this->getPostParam('formIndexType'), $this->getPostParam('formUnique'), $formWhere, $formSpc, $this->getPostParam('formConcur') ); if (0 == $status) { $this->doDefault($sql.'
'.$this->lang['strindexcreated']); } else { $this->doCreateIndex($this->lang['strindexcreatedbad']); } } } /** * Show confirmation of drop index and perform actual drop. * * @param mixed $confirm */ public function doDropIndex($confirm) { $data = $this->misc->getDatabaseAccessor(); $subject = urlencode($this->getRequestParam('subject', 'table')); $object = urlencode($this->getRequestParam($subject)); if ($confirm) { $this->printTrail('index'); $this->printTitle($this->lang['strdrop'], 'pg.index.drop'); echo '

', sprintf($this->lang['strconfdropindex'], $this->misc->printVal($this->getRequestParam('index'))), '

'.PHP_EOL; echo '
'.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo '

'; echo '

'.PHP_EOL; echo "lang['strdrop']}\" />".PHP_EOL; echo "lang['strcancel']}\" />".PHP_EOL; echo '
'.PHP_EOL; } else { try { list($status, $sql) = $data->dropIndex($this->getPostParam('index'), $this->getPostParam('cascade')); if (0 == $status) { $this->doDefault($sql.PHP_EOL.$this->lang['strindexdropped']); } else { $this->doDefault($sql.PHP_EOL.$this->lang['strindexdroppedbad']); } } catch (\PHPPgAdmin\ADOdbException $e) { $this->doDefault($this->lang['strindexdroppedbad']); } } } }