alterDomain($_POST['domain'], $_POST['domdefault'], isset($_POST['domnotnull']), $_POST['domowner']); if ($status == 0) doProperties($lang['strdomainaltered']); else doAlter($lang['strdomainalteredbad']); } /** * Allow altering a domain */ function doAlter($msg = '') { global $data, $misc; global $lang; $misc->printTrail('domain'); $misc->printTitle($lang['stralter'],'pg.domain.alter'); $misc->printMsg($msg); // Fetch domain info $domaindata = $data->getDomain($_REQUEST['domain']); // Fetch all users $users = $data->getUsers(); if ($domaindata->recordCount() > 0) { if (!isset($_POST['domname'])) { $_POST['domtype'] = $domaindata->fields['domtype']; $_POST['domdefault'] = $domaindata->fields['domdef']; $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']); if ($domaindata->fields['domnotnull']) $_POST['domnotnull'] = 'on'; $_POST['domowner'] = $domaindata->fields['domowner']; } // Display domain info echo "
\n"; } else echo "{$lang['strnodata']}
\n"; } /** * Confirm and then actually add a CHECK constraint */ function addCheck($confirm, $msg = '') { global $data, $misc; global $lang; if (!isset($_POST['name'])) $_POST['name'] = ''; if (!isset($_POST['definition'])) $_POST['definition'] = ''; if ($confirm) { $misc->printTrail('domain'); $misc->printTitle($lang['straddcheck'],'pg.constraint.check'); $misc->printMsg($msg); echo "\n"; } else { if (trim($_POST['definition']) == '') addCheck(true, $lang['strcheckneedsdefinition']); else { $status = $data->addDomainCheckConstraint($_POST['domain'], $_POST['definition'], $_POST['name']); if ($status == 0) doProperties($lang['strcheckadded']); else addCheck(true, $lang['strcheckaddedbad']); } } } /** * Show confirmation of drop constraint and perform actual drop */ function doDropConstraint($confirm, $msg = '') { global $data, $misc; global $lang; if ($confirm) { $misc->printTrail('domain'); $misc->printTitle($lang['strdrop'],'pg.constraint.drop'); $misc->printMsg($msg); echo "", sprintf($lang['strconfdropconstraint'], $misc->printVal($_REQUEST['constraint']), $misc->printVal($_REQUEST['domain'])), "
\n"; echo "\n"; } else { $status = $data->dropDomainConstraint($_POST['domain'], $_POST['constraint'], isset($_POST['cascade'])); if ($status == 0) doProperties($lang['strconstraintdropped']); else doDropConstraint(true, $lang['strconstraintdroppedbad']); } } /** * Show properties for a domain. Allow manipulating constraints as well. */ function doProperties($msg = '') { global $data, $misc; global $lang; $misc->printTrail('domain'); $misc->printTitle($lang['strproperties'],'pg.domain'); $misc->printMsg($msg); $domaindata = $data->getDomain($_REQUEST['domain']); if ($domaindata->recordCount() > 0) { // Show comment if any if ($domaindata->fields['domcomment'] !== null) echo "", $misc->printVal($domaindata->fields['domcomment']), "
\n"; // Display domain info $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']); echo "{$lang['strname']} | \n"; echo "", $misc->printVal($domaindata->fields['domname']), " |
---|---|
{$lang['strtype']} | \n"; echo "", $misc->printVal($domaindata->fields['domtype']), " |
{$lang['strnotnull']} | \n"; echo "", ($domaindata->fields['domnotnull'] ? 'NOT NULL' : ''), " |
{$lang['strdefault']} | \n"; echo "", $misc->printVal($domaindata->fields['domdef']), " |
{$lang['strowner']} | \n"; echo "", $misc->printVal($domaindata->fields['domowner']), " |
{$lang['strname']} | {$lang['strdefinition']} | {$lang['stractions']} | \n"; $i = 0; while (!$domaincons->EOF) { $id = (($i % 2 ) == 0 ? '1' : '2'); echo "
---|---|---|
", $misc->printVal($domaincons->fields['conname']), " | "; echo ""; echo $misc->printVal($domaincons->fields['consrc']); echo " | "; echo ""; echo "href}&constraint=", urlencode($domaincons->fields['conname']), "&domain=", urlencode($_REQUEST['domain']), "&type=", urlencode($domaincons->fields['contype']), "\">{$lang['strdrop']} |
{$lang['strnodata']}
\n"; echo "", sprintf($lang['strconfdropdomain'], $misc->printVal($_REQUEST['domain'])), "
\n"; echo "\n"; } else { $status = $data->dropDomain($_POST['domain'], isset($_POST['cascade'])); if ($status == 0) doDefault($lang['strdomaindropped']); else doDefault($lang['strdomaindroppedbad']); } } /** * Displays a screen where they can enter a new domain */ function doCreate($msg = '') { global $data, $misc; global $lang; if (!isset($_POST['domname'])) $_POST['domname'] = ''; if (!isset($_POST['domtype'])) $_POST['domtype'] = ''; if (!isset($_POST['domlength'])) $_POST['domlength'] = ''; if (!isset($_POST['domarray'])) $_POST['domarray'] = ''; if (!isset($_POST['domdefault'])) $_POST['domdefault'] = ''; if (!isset($_POST['domcheck'])) $_POST['domcheck'] = ''; $types = $data->getTypes(true); $misc->printTrail('schema'); $misc->printTitle($lang['strcreatedomain'],'pg.domain.create'); $misc->printMsg($msg); echo "\n"; } /** * Actually creates the new domain in the database */ function doSaveCreate() { global $data, $lang; if (!isset($_POST['domcheck'])) $_POST['domcheck'] = ''; // Check that they've given a name and a definition if ($_POST['domname'] == '') doCreate($lang['strdomainneedsname']); else { $status = $data->createDomain($_POST['domname'], $_POST['domtype'], $_POST['domlength'], $_POST['domarray'] != '', isset($_POST['domnotnull']), $_POST['domdefault'], $_POST['domcheck']); if ($status == 0) doDefault($lang['strdomaincreated']); else doCreate($lang['strdomaincreatedbad']); } } /** * Show default list of domains in the database */ function doDefault($msg = '') { global $data, $conf, $misc; global $lang; $misc->printTrail('schema'); $misc->printTabs('schema','domains'); $misc->printMsg($msg); $domains = $data->getDomains(); $columns = array( 'domain' => array( 'title' => $lang['strdomain'], 'field' => field('domname'), 'url' => "domains.php?action=properties&{$misc->href}&", 'vars' => array('domain' => 'domname'), ), 'type' => array( 'title' => $lang['strtype'], 'field' => field('domtype'), ), 'notnull' => array( 'title' => $lang['strnotnull'], 'field' => field('domnotnull'), 'type' => 'bool', 'params'=> array('true' => 'NOT NULL', 'false' => ''), ), 'default' => array( 'title' => $lang['strdefault'], 'field' => field('domdef'), ), 'owner' => array( 'title' => $lang['strowner'], 'field' => field('domowner'), ), 'actions' => array( 'title' => $lang['stractions'], ), 'comment' => array( 'title' => $lang['strcomment'], 'field' => field('domcomment'), ), ); $actions = array( 'alter' => array( 'title' => $lang['stralter'], 'url' => "domains.php?action=alter&{$misc->href}&", 'vars' => array('domain' => 'domname'), ), 'drop' => array( 'title' => $lang['strdrop'], 'url' => "domains.php?action=confirm_drop&{$misc->href}&", 'vars' => array('domain' => 'domname'), ), ); if (!$data->hasAlterDomains()) unset($actions['alter']); $misc->printTable($domains, $columns, $actions, $lang['strnodomains']); echo "\n"; } /** * Generate XML for the browser tree. */ function doTree() { global $misc, $data; $domains = $data->getDomains(); $reqvars = $misc->getRequestVars('domain'); $attrs = array( 'text' => field('domname'), 'icon' => 'Domain', 'toolTip'=> field('domcomment'), 'action' => url('domains.php', $reqvars, array( 'action' => 'properties', 'domain' => field('domname') ) ) ); $misc->printTreeXML($domains, $attrs); exit; } if ($action == 'tree') doTree(); $misc->printHeader($lang['strdomains']); $misc->printBody(); switch ($action) { case 'add_check': addCheck(true); break; case 'save_add_check': if (isset($_POST['cancel'])) doProperties(); else addCheck(false); break; case 'drop_con': if (isset($_POST['drop'])) doDropConstraint(false); else doProperties(); break; case 'confirm_drop_con': doDropConstraint(true); break; case 'save_create': if (isset($_POST['cancel'])) doDefault(); else doSaveCreate(); break; case 'create': doCreate(); break; case 'drop': if (isset($_POST['drop'])) doDrop(false); else doDefault(); break; case 'confirm_drop': doDrop(true); break; case 'save_alter': if (isset($_POST['alter'])) doSaveAlter(); else doProperties(); break; case 'alter': doAlter(); break; case 'properties': doProperties(); break; default: doDefault(); break; } $misc->printFooter(); ?>