action) { return $this->doTree(); } $this->printHeader(); $this->printBody(); switch ($this->action) { case 'create_comp': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doCreateComposite(); } break; case 'create_enum': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doCreateEnum(); } break; case 'save_create': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doSaveCreate(); } break; case 'create': $this->doCreate(); break; case 'drop': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doDrop(false); } break; case 'confirm_drop': $this->doDrop(true); break; case 'properties': $this->doProperties(); break; default: $this->doDefault(); break; } return $this->printFooter(); } /** * Show default list of types in the database. * * @param mixed $msg */ public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTabs('schema', 'types'); $this->printMsg($msg); $types = $data->getTypes(); $columns = [ 'type' => [ 'title' => $this->lang['strtype'], 'field' => Decorator::field('typname'), 'url' => "types?action=properties&{$this->misc->href}&", 'vars' => ['type' => 'basename'], ], 'owner' => [ 'title' => $this->lang['strowner'], 'field' => Decorator::field('typowner'), ], 'flavour' => [ 'title' => $this->lang['strflavor'], 'field' => Decorator::field('typtype'), 'type' => 'verbatim', 'params' => [ 'map' => [ 'b' => $this->lang['strbasetype'], 'c' => $this->lang['strcompositetype'], 'd' => $this->lang['strdomain'], 'p' => $this->lang['strpseudotype'], 'e' => $this->lang['strenum'], ], 'align' => 'center', ], ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('typcomment'), ], ]; if (!isset($types->fields['typtype'])) { unset($columns['flavour']); } $actions = [ 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'types', 'urlvars' => [ 'action' => 'confirm_drop', 'type' => Decorator::field('basename'), ], ], ], ], ]; echo $this->printTable($types, $columns, $actions, 'types-types', $this->lang['strnotypes']); $navlinks = [ 'create' => [ 'attr' => [ 'href' => [ 'url' => 'types', 'urlvars' => [ 'action' => 'create', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strcreatetype'], ], 'createcomp' => [ 'attr' => [ 'href' => [ 'url' => 'types', 'urlvars' => [ 'action' => 'create_comp', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strcreatecomptype'], ], 'createenum' => [ 'attr' => [ 'href' => [ 'url' => 'types', 'urlvars' => [ 'action' => 'create_enum', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strcreateenumtype'], ], ]; if (!$data->hasEnumTypes()) { unset($navlinks['enum']); } $this->printNavLinks($navlinks, 'types-types', get_defined_vars()); } /** * Generate XML for the browser tree. */ public function doTree() { $data = $this->misc->getDatabaseAccessor(); $types = $data->getTypes(); $reqvars = $this->misc->getRequestVars('type'); $attrs = [ 'text' => Decorator::field('typname'), 'icon' => 'Type', 'toolTip' => Decorator::field('typcomment'), 'action' => Decorator::actionurl( 'types', $reqvars, [ 'action' => 'properties', 'type' => Decorator::field('basename'), ] ), ]; return $this->printTree($types, $attrs, 'types'); } /** * Show read only properties for a type. * * @param mixed $msg */ public function doProperties($msg = '') { $data = $this->misc->getDatabaseAccessor(); // Get type (using base name) $typedata = $data->getType($_REQUEST['type']); $this->printTrail('type'); $this->printTitle($this->lang['strproperties'], 'pg.type'); $this->printMsg($msg); $attPre = function (&$rowdata) use ($data) { $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); }; if ($typedata->recordCount() > 0) { $vals = false; switch ($typedata->fields['typtype']) { case 'c': $attrs = $data->getTableAttributes($_REQUEST['type']); $columns = [ 'field' => [ 'title' => $this->lang['strfield'], 'field' => Decorator::field('attname'), ], 'type' => [ 'title' => $this->lang['strtype'], 'field' => Decorator::field('+type'), ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('comment'), ], ]; $actions = []; echo $this->printTable($attrs, $columns, $actions, 'types-properties', $this->lang['strnodata'], $attPre); break; case 'e': $vals = $data->getEnumValues($typedata->fields['typname']); // no break default: $byval = $data->phpBool($typedata->fields['typbyval']); echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; if ($data->hasEnumTypes() && $vals) { $vals = $vals->getArray(); $nbVals = count($vals); echo "\n\t".PHP_EOL; echo "".PHP_EOL; for ($i = 1; $i < $nbVals; ++$i) { echo '".PHP_EOL; } } echo '
{$this->lang['strname']}', $this->misc->printVal($typedata->fields['typname']), '
{$this->lang['strinputfn']}', $this->misc->printVal($typedata->fields['typin']), '
{$this->lang['stroutputfn']}', $this->misc->printVal($typedata->fields['typout']), '
{$this->lang['strlength']}', $this->misc->printVal($typedata->fields['typlen']), '
{$this->lang['strpassbyval']}', ($byval) ? $this->lang['stryes'] : $this->lang['strno'], '
{$this->lang['stralignment']}', $this->misc->printVal($typedata->fields['typalign']), '
{$this->lang['strenumvalues']}{$vals[0]['enumval']}
{$vals[$i]['enumval']}
'.PHP_EOL; } $this->printNavLinks(['showall' => [ 'attr' => [ 'href' => [ 'url' => 'types', 'urlvars' => [ 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strshowalltypes'], ]], 'types-properties', get_defined_vars()); } else { $this->doDefault($this->lang['strinvalidparam']); } } /** * Show confirmation of drop and perform actual drop. * * @param mixed $confirm */ public function doDrop($confirm) { $data = $this->misc->getDatabaseAccessor(); if ($confirm) { $this->printTrail('type'); $this->printTitle($this->lang['strdrop'], 'pg.type.drop'); echo '

', sprintf($this->lang['strconfdroptype'], $this->misc->printVal($_REQUEST['type'])), '

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

".PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; } else { $status = $data->dropType($_POST['type'], isset($_POST['cascade'])); if (0 == $status) { $this->doDefault($this->lang['strtypedropped']); } else { $this->doDefault($this->lang['strtypedroppedbad']); } } } /** * Displays a screen where they can enter a new composite type. * * @param mixed $msg */ public function doCreateComposite($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'stage', 1); $this->coalesceArr($_REQUEST, 'name', ''); $this->coalesceArr($_REQUEST, 'fields', ''); $this->coalesceArr($_REQUEST, 'typcomment', ''); switch ($_REQUEST['stage']) { case 1: $this->printTrail('type'); $this->printTitle($this->lang['strcreatecomptype'], 'pg.type.create'); $this->printMsg($msg); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo '
{$this->lang['strname']}_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />
{$this->lang['strnumfields']}_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['fields']), "\" />
{$this->lang['strcomment']}
'.PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; break; case 2: // Check inputs $fields = trim($_REQUEST['fields']); if ('' == trim($_REQUEST['name'])) { $_REQUEST['stage'] = 1; $this->doCreateComposite($this->lang['strtypeneedsname']); return; } if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields < 1) { $_REQUEST['stage'] = 1; $this->doCreateComposite($this->lang['strtypeneedscols']); return; } $types = $data->getTypes(true, false, true); $this->printTrail('schema'); $this->printTitle($this->lang['strcreatecomptype'], 'pg.type.create'); $this->printMsg($msg); echo '
'.PHP_EOL; // Output table header echo ''.PHP_EOL; echo "\t"; echo "".PHP_EOL; for ($i = 0; $i < $_REQUEST['fields']; ++$i) { if (!isset($_REQUEST['field'][$i])) { $_REQUEST['field'][$i] = ''; } if (!isset($_REQUEST['length'][$i])) { $_REQUEST['length'][$i] = ''; } if (!isset($_REQUEST['colcomment'][$i])) { $_REQUEST['colcomment'][$i] = ''; } echo "\t\n\t\t'.PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t".PHP_EOL; // Output array type selector echo "\t\t".PHP_EOL; echo "\t\t'.PHP_EOL; echo "\t\t\n\t".PHP_EOL; } echo '
{$this->lang['strfield']}{$this->lang['strtype']}{$this->lang['strlength']}{$this->lang['strcomment']}
", $i + 1, '. _maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['field'][$i]), '" />\n\t\t\t\n\t\t\n\t\t\t\n\t\t
'.PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; break; case 3: // Check inputs $fields = trim($_REQUEST['fields']); if ('' == trim($_REQUEST['name'])) { $_REQUEST['stage'] = 1; $this->doCreateComposite($this->lang['strtypeneedsname']); return; } if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields <= 0) { $_REQUEST['stage'] = 1; $this->doCreateComposite($this->lang['strtypeneedscols']); return; } $status = $data->createCompositeType( $_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'], $_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['colcomment'], $_REQUEST['typcomment'] ); if (0 == $status) { $this->doDefault($this->lang['strtypecreated']); } elseif ($status == -1) { $_REQUEST['stage'] = 2; $this->doCreateComposite($this->lang['strtypeneedsfield']); return; } else { $_REQUEST['stage'] = 2; $this->doCreateComposite($this->lang['strtypecreatedbad']); return; } break; default: echo "

{$this->lang['strinvalidparam']}

".PHP_EOL; } } /** * Displays a screen where they can enter a new enum type. * * @param mixed $msg */ public function doCreateEnum($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'stage', 1); $this->coalesceArr($_REQUEST, 'name', ''); $this->coalesceArr($_REQUEST, 'values', ''); $this->coalesceArr($_REQUEST, 'typcomment', ''); switch ($_REQUEST['stage']) { case 1: $this->printTrail('type'); $this->printTitle($this->lang['strcreateenumtype'], 'pg.type.create'); $this->printMsg($msg); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo "\t\n\t\t".PHP_EOL; echo "\t\t\n\t".PHP_EOL; echo '
{$this->lang['strname']}_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />
{$this->lang['strnumvalues']}_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['values']), "\" />
{$this->lang['strcomment']}
'.PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; break; case 2: // Check inputs $values = trim($_REQUEST['values']); if ('' == trim($_REQUEST['name'])) { $_REQUEST['stage'] = 1; $this->doCreateEnum($this->lang['strtypeneedsname']); return; } if ('' == $values || !is_numeric($values) || $values != (int) $values || $values < 1) { $_REQUEST['stage'] = 1; $this->doCreateEnum($this->lang['strtypeneedsvals']); return; } $this->printTrail('schema'); $this->printTitle($this->lang['strcreateenumtype'], 'pg.type.create'); $this->printMsg($msg); echo '
'.PHP_EOL; // Output table header echo ''.PHP_EOL; echo "\t".PHP_EOL; for ($i = 0; $i < $_REQUEST['values']; ++$i) { if (!isset($_REQUEST['value'][$i])) { $_REQUEST['value'][$i] = ''; } echo "\t\n\t\t'.PHP_EOL; echo "\t\t\n\t".PHP_EOL; } echo '
{$this->lang['strvalue']}
", $i + 1, '. _maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['value'][$i]), "\" />
'.PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; break; case 3: // Check inputs $values = trim($_REQUEST['values']); if ('' == trim($_REQUEST['name'])) { $_REQUEST['stage'] = 1; $this->doCreateEnum($this->lang['strtypeneedsname']); return; } if ('' == $values || !is_numeric($values) || $values != (int) $values || $values <= 0) { $_REQUEST['stage'] = 1; $this->doCreateEnum($this->lang['strtypeneedsvals']); return; } $status = $data->createEnumType($_REQUEST['name'], $_REQUEST['value'], $_REQUEST['typcomment']); if (0 == $status) { $this->doDefault($this->lang['strtypecreated']); } elseif ($status == -1) { $_REQUEST['stage'] = 2; $this->doCreateEnum($this->lang['strtypeneedsvalue']); return; } else { $_REQUEST['stage'] = 2; $this->doCreateEnum($this->lang['strtypecreatedbad']); return; } break; default: echo "

{$this->lang['strinvalidparam']}

".PHP_EOL; } } /** * Displays a screen where they can enter a new type. * * @param mixed $msg */ public function doCreate($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_POST, 'typname', ''); $this->coalesceArr($_POST, 'typin', ''); $this->coalesceArr($_POST, 'typout', ''); $this->coalesceArr($_POST, 'typlen', ''); $this->coalesceArr($_POST, 'typdef', ''); $this->coalesceArr($_POST, 'typelem', ''); $this->coalesceArr($_POST, 'typdelim', ''); $this->coalesceArr($_POST, 'typalign', $data->typAlignDef); $this->coalesceArr($_POST, 'typstorage', $data->typStorageDef); // Retrieve all functions and types in the database $funcs = $data->getFunctions(true); $types = $data->getTypes(true); $this->printTrail('schema'); $this->printTitle($this->lang['strcreatetype'], 'pg.type.create'); $this->printMsg($msg); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo "'.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo '".PHP_EOL; echo ''; echo "".PHP_EOL; echo ''; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''; echo "".PHP_EOL; echo ''; echo "".PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; echo '
{$this->lang['strname']}_maxNameLen}\" value=\"", htmlspecialchars($_POST['typname']), '" />
{$this->lang['strinputfn']}
{$this->lang['stroutputfn']}
{$this->lang['strlength']}
{$this->lang['strdefault']}
{$this->lang['strelement']}
{$this->lang['strdelimiter']}
{$this->lang['stralignment']}
{$this->lang['strstorage']}
'.PHP_EOL; echo '

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

".PHP_EOL; echo '
'.PHP_EOL; } /** * Actually creates the new type in the database. */ public function doSaveCreate() { $data = $this->misc->getDatabaseAccessor(); // Check that they've given a name and a length. // Note: We're assuming they've given in and out functions here // which might be unwise... if ('' == $_POST['typname']) { $this->doCreate($this->lang['strtypeneedsname']); } elseif ('' == $_POST['typlen']) { $this->doCreate($this->lang['strtypeneedslen']); } else { $status = $data->createType( $_POST['typname'], $_POST['typin'], $_POST['typout'], $_POST['typlen'], $_POST['typdef'], $_POST['typelem'], $_POST['typdelim'], isset($_POST['typbyval']), $_POST['typalign'], $_POST['typstorage'] ); if (0 == $status) { $this->doDefault($this->lang['strtypecreated']); } else { $this->doCreate($this->lang['strtypecreatedbad']); } } } }