Esempio n. 1
0
/** 
 * Displays requested data
 */
function doBrowse($msg = '')
{
    global $data, $conf, $misc, $lang, $plugin_manager;
    $save_history = false;
    // If current page is not set, default to first page
    if (!isset($_REQUEST['page'])) {
        $_REQUEST['page'] = 1;
    }
    if (!isset($_REQUEST['nohistory'])) {
        $save_history = true;
    }
    if (isset($_REQUEST['subject'])) {
        $subject = $_REQUEST['subject'];
        if (isset($_REQUEST[$subject])) {
            $object = $_REQUEST[$subject];
        }
    } else {
        $subject = '';
    }
    $misc->printTrail(isset($subject) ? $subject : 'database');
    /* This code is used when browsing FK in pure-xHTML (without js) */
    if (isset($_REQUEST['fkey'])) {
        $ops = array();
        foreach ($_REQUEST['fkey'] as $x => $y) {
            $ops[$x] = '=';
        }
        $query = $data->getSelectSQL($_REQUEST['table'], array(), $_REQUEST['fkey'], $ops);
        $_REQUEST['query'] = $query;
    }
    if (isset($object)) {
        if (isset($_REQUEST['query'])) {
            $_SESSION['sqlquery'] = $_REQUEST['query'];
            $misc->printTitle($lang['strselect']);
            $type = 'SELECT';
        } else {
            $misc->printTitle($lang['strbrowse']);
            $type = 'TABLE';
        }
    } else {
        $misc->printTitle($lang['strqueryresults']);
        /*we comes from sql.php, $_SESSION['sqlquery'] has been set there */
        $type = 'QUERY';
    }
    $misc->printMsg($msg);
    // If 'sortkey' is not set, default to ''
    if (!isset($_REQUEST['sortkey'])) {
        $_REQUEST['sortkey'] = '';
    }
    // If 'sortdir' is not set, default to ''
    if (!isset($_REQUEST['sortdir'])) {
        $_REQUEST['sortdir'] = '';
    }
    // If 'strings' is not set, default to collapsed
    if (!isset($_REQUEST['strings'])) {
        $_REQUEST['strings'] = 'collapsed';
    }
    // Fetch unique row identifier, if this is a table browse request.
    if (isset($object)) {
        $key = $data->getRowIdentifier($object);
    } else {
        $key = array();
    }
    // Set the schema search path
    if (isset($_REQUEST['search_path'])) {
        if ($data->setSearchPath(array_map('trim', explode(',', $_REQUEST['search_path']))) != 0) {
            return;
        }
    }
    // Retrieve page from query.  $max_pages is returned by reference.
    $rs = $data->browseQuery($type, isset($object) ? $object : null, isset($_SESSION['sqlquery']) ? $_SESSION['sqlquery'] : null, $_REQUEST['sortkey'], $_REQUEST['sortdir'], $_REQUEST['page'], $conf['max_rows'], $max_pages);
    $fkey_information =& getFKInfo();
    // Build strings for GETs in array
    $_gets = array('server' => $_REQUEST['server'], 'database' => $_REQUEST['database']);
    if (isset($_REQUEST['schema'])) {
        $_gets['schema'] = $_REQUEST['schema'];
    }
    if (isset($object)) {
        $_gets[$subject] = $object;
    }
    if (isset($subject)) {
        $_gets['subject'] = $subject;
    }
    if (isset($_REQUEST['query'])) {
        $_gets['query'] = $_REQUEST['query'];
    }
    if (isset($_REQUEST['count'])) {
        $_gets['count'] = $_REQUEST['count'];
    }
    if (isset($_REQUEST['return'])) {
        $_gets['return'] = $_REQUEST['return'];
    }
    if (isset($_REQUEST['search_path'])) {
        $_gets['search_path'] = $_REQUEST['search_path'];
    }
    if (isset($_REQUEST['table'])) {
        $_gets['table'] = $_REQUEST['table'];
    }
    if (isset($_REQUEST['sortkey'])) {
        $_gets['sortkey'] = $_REQUEST['sortkey'];
    }
    if (isset($_REQUEST['sortdir'])) {
        $_gets['sortdir'] = $_REQUEST['sortdir'];
    }
    if (isset($_REQUEST['nohistory'])) {
        $_gets['nohistory'] = $_REQUEST['nohistory'];
    }
    $_gets['strings'] = $_REQUEST['strings'];
    if ($save_history && is_object($rs) && $type == 'QUERY') {
        //{
        $misc->saveScriptHistory($_REQUEST['query']);
    }
    if (is_object($rs) && $rs->recordCount() > 0) {
        // Show page navigation
        $misc->printPages($_REQUEST['page'], $max_pages, $_gets);
        echo "<table id=\"data\">\n<tr>";
        // Check that the key is actually in the result set.  This can occur for select
        // operations where the key fields aren't part of the select.  XXX:  We should
        // be able to support this, somehow.
        foreach ($key as $v) {
            // If a key column is not found in the record set, then we
            // can't use the key.
            if (!in_array($v, array_keys($rs->fields))) {
                $key = array();
                break;
            }
        }
        $buttons = array('edit' => array('content' => $lang['stredit'], 'attr' => array('href' => array('url' => 'display.php', 'urlvars' => array_merge(array('action' => 'confeditrow', 'strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page']), $_gets)))), 'delete' => array('content' => $lang['strdelete'], 'attr' => array('href' => array('url' => 'display.php', 'urlvars' => array_merge(array('action' => 'confdelrow', 'strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page']), $_gets)))));
        $actions = array('actionbuttons' => &$buttons, 'place' => 'display-browse');
        $plugin_manager->do_hook('actionbuttons', $actions);
        foreach (array_keys($actions['actionbuttons']) as $action) {
            $actions['actionbuttons'][$action]['attr']['href']['urlvars'] = array_merge($actions['actionbuttons'][$action]['attr']['href']['urlvars'], $_gets);
        }
        $edit_params = isset($actions['actionbuttons']['edit']) ? $actions['actionbuttons']['edit'] : array();
        $delete_params = isset($actions['actionbuttons']['delete']) ? $actions['actionbuttons']['delete'] : array();
        // Display edit and delete actions if we have a key
        $colspan = count($buttons);
        if ($colspan > 0 and count($key) > 0) {
            echo "<th colspan=\"{$colspan}\" class=\"data\">{$lang['stractions']}</th>\n";
        }
        /* we show OIDs only if we are in TABLE or SELECT type browsing */
        printTableHeaderCells($rs, $_gets, isset($object));
        echo "</tr>\n";
        $i = 0;
        reset($rs->fields);
        while (!$rs->EOF) {
            $id = $i % 2 == 0 ? '1' : '2';
            echo "<tr class=\"data{$id}\">\n";
            // Display edit and delete links if we have a key
            if ($colspan > 0 and count($key) > 0) {
                $keys_array = array();
                $has_nulls = false;
                foreach ($key as $v) {
                    if ($rs->fields[$v] === null) {
                        $has_nulls = true;
                        break;
                    }
                    $keys_array["key[{$v}]"] = $rs->fields[$v];
                }
                if ($has_nulls) {
                    echo "<td colspan=\"{$colspan}\">&nbsp;</td>\n";
                } else {
                    if (isset($actions['actionbuttons']['edit'])) {
                        $actions['actionbuttons']['edit'] = $edit_params;
                        $actions['actionbuttons']['edit']['attr']['href']['urlvars'] = array_merge($actions['actionbuttons']['edit']['attr']['href']['urlvars'], $keys_array);
                    }
                    if (isset($actions['actionbuttons']['delete'])) {
                        $actions['actionbuttons']['delete'] = $delete_params;
                        $actions['actionbuttons']['delete']['attr']['href']['urlvars'] = array_merge($actions['actionbuttons']['delete']['attr']['href']['urlvars'], $keys_array);
                    }
                    foreach ($actions['actionbuttons'] as $action) {
                        echo "<td class=\"opbutton{$id}\">";
                        $misc->printLink($action);
                        echo "</td>\n";
                    }
                }
            }
            print printTableRowCells($rs, $fkey_information, isset($object));
            echo "</tr>\n";
            $rs->moveNext();
            $i++;
        }
        echo "</table>\n";
        echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
        // Show page navigation
        $misc->printPages($_REQUEST['page'], $max_pages, $_gets);
    } else {
        echo "<p>{$lang['strnodata']}</p>\n";
    }
    // Navigation links
    $navlinks = array();
    $fields = array('server' => $_REQUEST['server'], 'database' => $_REQUEST['database']);
    if (isset($_REQUEST['schema'])) {
        $fields['schema'] = $_REQUEST['schema'];
    }
    // Return
    if (isset($_REQUEST['return'])) {
        $urlvars = $misc->getSubjectParams($_REQUEST['return']);
        $navlinks['back'] = array('attr' => array('href' => array('url' => $urlvars['url'], 'urlvars' => $urlvars['params'])), 'content' => $lang['strback']);
    }
    // Edit SQL link
    if ($type == 'QUERY') {
        $navlinks['edit'] = array('attr' => array('href' => array('url' => 'database.php', 'urlvars' => array_merge($fields, array('action' => 'sql', 'paginate' => 'on')))), 'content' => $lang['streditsql']);
    }
    // Expand/Collapse
    if ($_REQUEST['strings'] == 'expanded') {
        $navlinks['collapse'] = array('attr' => array('href' => array('url' => 'display.php', 'urlvars' => array_merge($_gets, array('strings' => 'collapsed', 'page' => $_REQUEST['page'])))), 'content' => $lang['strcollapse']);
    } else {
        $navlinks['collapse'] = array('attr' => array('href' => array('url' => 'display.php', 'urlvars' => array_merge($_gets, array('strings' => 'expanded', 'page' => $_REQUEST['page'])))), 'content' => $lang['strexpand']);
    }
    // Create view and download
    if (isset($_REQUEST['query']) && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
        // Report views don't set a schema, so we need to disable create view in that case
        if (isset($_REQUEST['schema'])) {
            $navlinks['createview'] = array('attr' => array('href' => array('url' => 'views.php', 'urlvars' => array_merge($fields, array('action' => 'create', 'formDefinition' => $_REQUEST['query'])))), 'content' => $lang['strcreateview']);
        }
        $urlvars = array();
        if (isset($_REQUEST['search_path'])) {
            $urlvars['search_path'] = $_REQUEST['search_path'];
        }
        $navlinks['download'] = array('attr' => array('href' => array('url' => 'dataexport.php', 'urlvars' => array_merge($fields, $urlvars))), 'content' => $lang['strdownload']);
    }
    // Insert
    if (isset($object) && (isset($subject) && $subject == 'table')) {
        $navlinks['insert'] = array('attr' => array('href' => array('url' => 'tables.php', 'urlvars' => array_merge($fields, array('action' => 'confinsertrow', 'table' => $object)))), 'content' => $lang['strinsert']);
    }
    // Refresh
    $navlinks['refresh'] = array('attr' => array('href' => array('url' => 'display.php', 'urlvars' => array_merge($_gets, array('strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page'])))), 'content' => $lang['strrefresh']);
    $misc->printNavLinks($navlinks, 'display-browse', get_defined_vars());
}
Esempio n. 2
0
/** 
 * Displays requested data
 */
function doBrowse($msg = '')
{
    global $data, $conf, $misc, $lang;
    $save_history = false;
    // If current page is not set, default to first page
    if (!isset($_REQUEST['page'])) {
        $_REQUEST['page'] = 1;
    }
    if (!isset($_REQUEST['nohistory'])) {
        $save_history = true;
    }
    if (isset($_REQUEST['subject'])) {
        $subject = $_REQUEST['subject'];
        if (isset($_REQUEST[$subject])) {
            $object = $_REQUEST[$subject];
        }
    } else {
        $subject = '';
    }
    $misc->printTrail(isset($subject) ? $subject : 'database');
    /* This code is used when browsing FK in pure-xHTML (without js) */
    if (isset($_REQUEST['fkey'])) {
        $ops = array();
        foreach ($_REQUEST['fkey'] as $x => $y) {
            $ops[$x] = '=';
        }
        $query = $data->getSelectSQL($_REQUEST['table'], array(), $_REQUEST['fkey'], $ops);
        $_REQUEST['query'] = $query;
    }
    if (isset($object)) {
        if (isset($_REQUEST['query'])) {
            $_SESSION['sqlquery'] = $_REQUEST['query'];
            $misc->printTitle($lang['strselect']);
            $type = 'SELECT';
        } else {
            if (isset($_REQUEST['report'])) {
                $misc->printTitle($lang['strselect']);
                $type = 'SELECT';
            } else {
                $misc->printTitle($lang['strbrowse']);
                $type = 'TABLE';
            }
        }
    } else {
        $misc->printTitle($lang['strqueryresults']);
        $type = 'QUERY';
    }
    $misc->printMsg($msg);
    // If 'sortkey' is not set, default to ''
    if (!isset($_REQUEST['sortkey'])) {
        $_REQUEST['sortkey'] = '';
    }
    // If 'sortdir' is not set, default to ''
    if (!isset($_REQUEST['sortdir'])) {
        $_REQUEST['sortdir'] = '';
    }
    // If 'strings' is not set, default to collapsed
    if (!isset($_REQUEST['strings'])) {
        $_REQUEST['strings'] = 'collapsed';
    }
    // Fetch unique row identifier, if this is a table browse request.
    if (isset($object)) {
        $key = $data->getRowIdentifier($object);
    } else {
        $key = array();
    }
    // Set the schema search path
    if (isset($_REQUEST['search_path'])) {
        if ($data->setSearchPath(array_map('trim', explode(',', $_REQUEST['search_path']))) != 0) {
            return;
        }
    }
    // Retrieve page from query.  $max_pages is returned by reference.
    $rs = $data->browseQuery($type, isset($object) ? $object : null, isset($_SESSION['sqlquery']) ? $_SESSION['sqlquery'] : null, $_REQUEST['sortkey'], $_REQUEST['sortdir'], $_REQUEST['page'], $conf['max_rows'], $max_pages);
    $fkey_information =& getFKInfo();
    // Build strings for GETs
    $gets = $misc->href;
    if (isset($object)) {
        $gets .= "&amp;" . urlencode($subject) . '=' . urlencode($object);
    }
    if (isset($subject)) {
        $gets .= "&amp;subject=" . urlencode($subject);
    }
    if (isset($_REQUEST['query'])) {
        $gets .= "&amp;query=" . urlencode($_REQUEST['query']);
    }
    if (isset($_REQUEST['report'])) {
        $gets .= "&amp;report=" . urlencode($_REQUEST['report']);
    }
    if (isset($_REQUEST['count'])) {
        $gets .= "&amp;count=" . urlencode($_REQUEST['count']);
    }
    if (isset($_REQUEST['return'])) {
        $gets .= "&amp;return=" . urlencode($_REQUEST['return']);
    }
    if (isset($_REQUEST['search_path'])) {
        $gets .= "&amp;search_path=" . urlencode($_REQUEST['search_path']);
    }
    if (isset($_REQUEST['table'])) {
        $gets .= "&amp;table=" . urlencode($_REQUEST['table']);
    }
    // This string just contains sort info
    $getsort = "sortkey=" . urlencode($_REQUEST['sortkey']) . "&amp;sortdir=" . urlencode($_REQUEST['sortdir']);
    if ($save_history && is_object($rs) && $type == 'QUERY') {
        //{
        $misc->saveScriptHistory($_REQUEST['query']);
    }
    if (is_object($rs) && $rs->recordCount() > 0) {
        // Show page navigation
        $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&amp;{$gets}&amp;{$getsort}&amp;nohistory=t&amp;strings=" . urlencode($_REQUEST['strings']));
        echo "<table id=\"data\">\n<tr>";
        // Check that the key is actually in the result set.  This can occur for select
        // operations where the key fields aren't part of the select.  XXX:  We should
        // be able to support this, somehow.
        foreach ($key as $v) {
            // If a key column is not found in the record set, then we
            // can't use the key.
            if (!in_array($v, array_keys($rs->fields))) {
                $key = array();
                break;
            }
        }
        // Display edit and delete actions if we have a key
        if (sizeof($key) > 0) {
            echo "<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
        }
        /* we show OIDs only if we are in TABLE or SELECT type browsing */
        printTableHeaderCells($rs, $gets, isset($object));
        echo "</tr>\n";
        $i = 0;
        reset($rs->fields);
        while (!$rs->EOF) {
            $id = $i % 2 == 0 ? '1' : '2';
            echo "<tr class=\"data{$id}\">\n";
            // Display edit and delete links if we have a key
            if (sizeof($key) > 0) {
                $key_str = '';
                $has_nulls = false;
                foreach ($key as $v) {
                    if ($rs->fields[$v] === null) {
                        $has_nulls = true;
                        break;
                    }
                    if ($key_str != '') {
                        $key_str .= '&amp;';
                    }
                    $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->fields[$v]);
                }
                if ($has_nulls) {
                    echo "<td colspan=\"2\">&nbsp;</td>\n";
                } else {
                    echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confeditrow&amp;strings=", urlencode($_REQUEST['strings']), "&amp;page=", urlencode($_REQUEST['page']), "&amp;{$key_str}&amp;{$gets}&amp;{$getsort}\">{$lang['stredit']}</a></td>\n";
                    echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confdelrow&amp;strings=", urlencode($_REQUEST['strings']), "&amp;page=", urlencode($_REQUEST['page']), "&amp;{$key_str}&amp;{$gets}&amp;{$getsort}\">{$lang['strdelete']}</a></td>\n";
                }
            }
            print printTableRowCells($rs, $fkey_information, isset($object));
            echo "</tr>\n";
            $rs->moveNext();
            $i++;
        }
        echo "</table>\n";
        echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
        // Show page navigation
        $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&amp;{$gets}&amp;{$getsort}&amp;strings=" . urlencode($_REQUEST['strings']));
    } else {
        echo "<p>{$lang['strnodata']}</p>\n";
    }
    // Navigation links
    echo "<ul class=\"navlink\">\n";
    // Return
    if (isset($_REQUEST['return'])) {
        $return_url = $misc->getHREFSubject($_REQUEST['return']);
        if ($return_url) {
            echo "\t<li><a href=\"{$return_url}\">{$lang['strback']}</a></li>\n";
        }
    }
    // Edit SQL link
    if (isset($_REQUEST['query'])) {
        echo "\t<li><a href=\"database.php?{$misc->href}&amp;action=sql&amp;paginate=on&amp;query=", urlencode($_REQUEST['query']), "\">{$lang['streditsql']}</a></li>\n";
    }
    // Expand/Collapse
    if ($_REQUEST['strings'] == 'expanded') {
        echo "\t<li><a href=\"display.php?{$gets}&amp;{$getsort}&amp;strings=collapsed&amp;page=", urlencode($_REQUEST['page']), "\">{$lang['strcollapse']}</a></li>\n";
    } else {
        echo "\t<li><a href=\"display.php?{$gets}&amp;{$getsort}&amp;strings=expanded&amp;page=", urlencode($_REQUEST['page']), "\">{$lang['strexpand']}</a></li>\n";
    }
    // Create report
    if (isset($_REQUEST['query']) && $subject !== 'report' && $conf['show_reports'] && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
        echo "\t<li><a href=\"reports.php?{$misc->href}&amp;action=create&amp;report_sql=", urlencode($_REQUEST['query']), "&amp;paginate=", isset($_REQUEST['paginate']) ? urlencode($_REQUEST['paginate']) : 'f', "\">{$lang['strcreatereport']}</a></li>\n";
    }
    // Create view and download
    if (isset($_REQUEST['query']) && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
        // Report views don't set a schema, so we need to disable create view in that case
        if (isset($_REQUEST['schema'])) {
            echo "\t<li><a href=\"views.php?action=create&amp;formDefinition=", urlencode($_REQUEST['query']), "&amp;{$misc->href}\">{$lang['strcreateview']}</a></li>\n";
        }
        echo "\t<li><a href=\"dataexport.php?query=", urlencode($_REQUEST['query']);
        if (isset($_REQUEST['search_path'])) {
            echo "&amp;search_path=", urlencode($_REQUEST['search_path']);
        }
        echo "&amp;{$misc->href}\">{$lang['strdownload']}</a></li>\n";
    }
    // Insert
    if (isset($object) && (isset($subject) && $subject == 'table')) {
        echo "\t<li><a href=\"tables.php?action=confinsertrow&amp;table=", urlencode($object), "&amp;{$misc->href}\">{$lang['strinsert']}</a></li>\n";
    }
    // Refresh
    echo "\t<li><a href=\"display.php?{$gets}&amp;{$getsort}&amp;strings=", urlencode($_REQUEST['strings']), "&amp;page=" . urlencode($_REQUEST['page']), "\">{$lang['strrefresh']}</a></li>\n";
    echo "</ul>\n";
}