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 "
{$lang['strname']} | \n"; echo "", $misc->printVal($typedata->fields['typname']), " |
---|---|
{$lang['strinputfn']} | \n"; echo "", $misc->printVal($typedata->fields['typin']), " |
{$lang['stroutputfn']} | \n"; echo "", $misc->printVal($typedata->fields['typout']), " |
{$lang['strlength']} | \n"; echo "", $misc->printVal($typedata->fields['typlen']), " |
{$lang['strpassbyval']} | \n"; echo "", ($byval) ? $lang['stryes'] : $lang['strno'], " |
{$lang['stralignment']} | \n"; echo "", $misc->printVal($typedata->fields['typalign']), " |
{$lang['strenumvalues']} | \n"; echo "{$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"; } 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"; 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"; 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"; 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"; 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"; } /** * 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 "