getType($_REQUEST['type']); $misc->printTrail('type'); $misc->printTitle($lang['strproperties'], 'pg.type'); $misc->printMsg($msg); function attPre(&$rowdata) { global $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 = array( 'field' => array( 'title' => $lang['strfield'], 'field' => field('attname'), ), 'type' => array( 'title' => $lang['strtype'], 'field' => field('+type'), ), 'comment' => array( 'title' => $lang['strcomment'], 'field' => field('comment'), ) ); $actions = array(); $misc->printTable($attrs, $columns, $actions, null, 'attPre'); break; case 'e': $vals = $data->getEnumValues($typedata->fields['typname']); default: $byval = $data->phpBool($typedata->fields['typbyval']); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($data->hasEnumTypes() && $vals) { $vals = $vals->getArray(); $nbVals = count($vals); echo "\n\t\n"; echo "\n"; for ($i=1; $i < $nbVals; $i++) echo "\n"; } echo "
{$lang['strname']}", $misc->printVal($typedata->fields['typname']), "
{$lang['strinputfn']}", $misc->printVal($typedata->fields['typin']), "
{$lang['stroutputfn']}", $misc->printVal($typedata->fields['typout']), "
{$lang['strlength']}", $misc->printVal($typedata->fields['typlen']), "
{$lang['strpassbyval']}", ($byval) ? $lang['stryes'] : $lang['strno'], "
{$lang['stralignment']}", $misc->printVal($typedata->fields['typalign']), "
{$lang['strenumvalues']}{$vals[0]['enumval']}
{$vals[$i]['enumval']}
\n"; } echo "

href}\">{$lang['strshowalltypes']}

\n"; } else doDefault($lang['strinvalidparam']); } /** * Show confirmation of drop and perform actual drop */ function doDrop($confirm) { global $data, $misc; global $lang; if ($confirm) { $misc->printTrail('type'); $misc->printTitle($lang['strdrop'], 'pg.type.drop'); echo "

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

\n"; echo "
\n"; echo "

\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

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

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

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

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "

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

{$lang['strinvalidparam']}

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

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

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

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "

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

{$lang['strinvalidparam']}

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

\n"; echo $misc->form; echo "\n"; echo "

\n"; echo "
\n"; } /** * Actually creates the new type in the database */ function doSaveCreate() { global $data; global $lang; // 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'] == '') doCreate($lang['strtypeneedsname']); elseif ($_POST['typlen'] == '') doCreate($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 ($status == 0) doDefault($lang['strtypecreated']); else doCreate($lang['strtypecreatedbad']); } } /** * Show default list of types in the database */ function doDefault($msg = '') { global $data, $conf, $misc; global $lang; $misc->printTrail('schema'); $misc->printTabs('schema','types'); $misc->printMsg($msg); $types = $data->getTypes(); $columns = array( 'type' => array( 'title' => $lang['strtype'], 'field' => field('typname'), 'url' => "types.php?action=properties&{$misc->href}&", 'vars' => array('type' => 'basename'), ), 'owner' => array( 'title' => $lang['strowner'], 'field' => field('typowner'), ), 'flavour' => array( 'title' => $lang['strflavor'], 'field' => field('typtype'), 'type' => 'verbatim', 'params'=> array( 'map' => array( 'b' => $lang['strbasetype'], 'c' => $lang['strcompositetype'], 'd' => $lang['strdomain'], 'p' => $lang['strpseudotype'], 'e' => $lang['strenum'], ), 'align' => 'center', ), ), 'actions' => array( 'title' => $lang['stractions'], ), 'comment' => array( 'title' => $lang['strcomment'], 'field' => field('typcomment'), ), ); if (!isset($types->fields['typtype'])) unset($columns['flavour']); $actions = array( 'drop' => array( 'title' => $lang['strdrop'], 'url' => "types.php?action=confirm_drop&{$misc->href}&", 'vars' => array('type' => 'basename'), ), ); $misc->printTable($types, $columns, $actions, $lang['strnotypes']); echo "\n"; } /** * Generate XML for the browser tree. */ function doTree() { global $misc, $data; $types = $data->getTypes(); $reqvars = $misc->getRequestVars('type'); $attrs = array( 'text' => field('typname'), 'icon' => 'Type', 'toolTip'=> field('typcomment'), 'action' => url('types.php', $reqvars, array( 'action' => 'properties', 'type' => field('basename') ) ) ); $misc->printTreeXML($types, $attrs); exit; } if ($action == 'tree') doTree(); $misc->printHeader($lang['strtypes']); $misc->printBody(); switch ($action) { case 'create_comp': if (isset($_POST['cancel'])) doDefault(); else doCreateComposite(); break; case 'create_enum': if (isset($_POST['cancel'])) doDefault(); else doCreateEnum(); break; case 'save_create': if (isset($_POST['cancel'])) doDefault(); else doSaveCreate(); break; case 'create': doCreate(); break; case 'drop': if (isset($_POST['cancel'])) doDefault(); else doDrop(false); break; case 'confirm_drop': doDrop(true); break; case 'properties': doProperties(); break; default: doDefault(); break; } $misc->printFooter(); ?>