function browseFetch() { $mtime = microtime(true); $table_id = $this->dd['table_id']; $tabPar = gp('tableIdPar'); # This is the list of columns to return. Maybe override # if there is something specific named for this table $acols = explode(',', $this->dd['projections']['_uisearch']); if ($tabPar != '') { if (isset($this->dd['projections']['child_' . $tabPar])) { $acols = explode(',', $this->dd['projections']['child_' . $tabPar]); } } # By default the search criteria come from the # variables, unless it is a child table search $vals = aFromGP('x6w_'); $awhere = array(); $projSort = ''; if ($tabPar == '') { $vals2 = array(); } else { $vals2 = $this->fetchParent(); $vals = array_merge($vals, $vals2); # KFD 12/27/08, if the sortdesc flag has been set on any # columns in the projection, those columns # become the default sort. Work it up here # and set them aside. $proj = 'child_' . $tabPar; $aprojSort = array(); if (isset($this->dd['projdetails'][$proj])) { foreach ($this->dd['projdetails'][$proj] as $column => $sortasc) { if ($sortasc == 'Y') { $aprojSort[] = "+{$column}"; } if ($sortasc == 'N') { $aprojSort[] = "-{$column}"; } } } $projSort = implode(",", $aprojSort); } # Build the where clause # $this->flat = $this->dd['flat']; $allowNoFilters = false; foreach ($vals as $column_id => $colvalue) { if (!isset($this->flat[$column_id])) { continue; } if ($colvalue == '*') { $awhere = array(); # KFD 2/17/09 Sourceforge 2609083 # Doing this returned all rows on regular # searches. Whatever it was for, it cannot # be done here this way. #gpSet('xReturnAll','Y'); $allowNoFilters = true; break; } $colinfo = $this->flat[$column_id]; $exact = isset($vals2[$column_id]); $expre = gp('x6exactPre', 0); //$tcv = trim($colvalue); $tcv = $colvalue; $type = $colinfo['type_id']; if ($tcv != "") { if ($exact) { gpSet('x6exactPre', 1); } // trap for a % sign in non-string $xwhere = sqlFilter($this->flat[$column_id], $tcv); if ($xwhere != '') { $awhere[] = "({$xwhere})"; } if ($exact && $expre == 0) { gpUnset('x6exactpre'); } } } # <----- RETURN (MAYBE) # Sourceforge 2612788 - this is actually an exit, not # a return. if (count($awhere) == 0) { if (gp('xReturnAll', 'N') == 'N' && !$allowNoFilters) { exit; } } # Generate the limit $SLimit = ' LIMIT 100'; if ($tabPar != '') { if (a($this->dd['fk_parents'][$tabPar], 'uiallrows', 'N') == 'Y') { $SLimit = ' LIMIT 100'; } } if (gp('xReturnAll', 'N') == 'Y') { $SLimit = ''; } # Build the Order by # $ascDesc = gp('sortAD') == 'ASC' ? ' ASC' : ' DESC'; $aorder = array(); $searchsort = ''; if (gpExists('sortAsc')) { x6Debug(gp('sortAsc')); $ascDesc = gp('sortAsc') == 'true' ? ' ASC' : ' DESC'; $aorder[] = gp('sortCol') . ' ' . gp('sortAD'); } else { # KFD 12/27/08, Use the search sort that was # set aside above if it is there $searchsort = $projSort == '' ? trim(arr($this->dd, 'uisearchsort', '')) : $projSort; } if ($searchsort != '') { $aocols = explode(",", $searchsort); foreach ($aocols as $pmcol) { $char1 = substr($pmcol, 0, 1); $column_id = substr($pmcol, 1); if ($char1 == '+') { $aorder[] = $column_id . ' ASC'; } else { $aorder[] = $column_id . ' DESC'; } } $SQLOrder = " ORDER BY " . implode(',', $aorder); } else { # KFD 6/18/08, new routine that works out sort $aorder = sqlOrderBy($vals); if (count($aorder) == 0) { $SQLOrder = ''; } else { $SQLOrder = " ORDER BY " . implode(',', $aorder); } } # just before building the query, drop out # any columns that have a table_id_fko to the parent foreach ($acols as $idx => $column_id) { if ($this->flat[$column_id]['table_id_fko'] == $tabPar && $tabPar != '') { unset($acols[$idx]); } } // Build the where and limit if (count($awhere) == 0) { $SWhere = ''; } else { $SWhere = ' WHERE ' . implode(' AND ', $awhere); } // Retrieve data #$SQL ="SELECT skey,".implode(',',$acols) # KFD 11/15/08. We can actually select *, because the grid # works out what columns it needs, and we # don't want to accidentally reduce the column # list and exclude something it needs. $SQL = "SELECT * " . " FROM " . $this->dd['viewname'] . $SWhere . $SQLOrder . $SLimit; $answer = SQL_AllRows($SQL); # These parameters have to be sent from the back. They # figure everything out. $sortable = gp('xSortable', 'N') == 'Y'; $gridHeight = gp('xGridHeight', 500); $lookups = gp('xLookups', 'N') == 'Y'; $edit = 0; $childedit = in_array($this->dd['x6childwrites'], array('Y', 'grid')); if ($tabPar != '' && $childedit) { $edit = 1; } # The button bar is either a 1/0 or a list of buttons. # Make the simple setting first, then possibly override $bb = gp('xButtonBar', 'N') == 'Y' || $edit; if ($tabPar != '' && $this->dd['x6childwrites'] == 'detail') { $bb = 'new'; } # Now grab us a grid $grid = new androHTMLGrid($gridHeight, $table_id, $lookups, $sortable, $bb, $edit); $this->gridGeneric($grid, $this->dd, $tabPar, $vals2); $grid->addData($answer); $grid->hp['x6profile'] = 'grid'; # Put some important properties on the grid! $grid->ap['xGridHeight'] = $gridHeight; $grid->ap['xReturnAll'] = gp('xReturnAll', 'N'); if ($tabPar != '') { $grid->ap['x6tablePar'] = $tabPar; } # If they asked for the entire grid, send it back # as *MAIN* and let the browser put it where it belongs if (gp('sendGrid', 0) == 1) { if (count($answer) == 0) { $grid->noResults(); } x6html('*MAIN*', $grid->bufferedRender()); return; } # ..otherwise just send the body back. But kill # any script they created. if (count($answer) == 0) { $grid->noResults(); } $mtimer = microtime(true); $grid->dbody->render(); exit; }
function gpUnsetPrefix($prefix) { foreach ($GLOBALS['AG']['clean'] as $key => $value) { $len = substr($key, 0, strlen($prefix)); if ($len == $prefix) { gpUnset($key); } } }
function index_hidden_command() { // Get command, strip out multiple spaces, split up and // grab the command separate from the arguments # KFD 9/10/08. Unset pretty much everything we know about # so we can create a new get/post setup out # of the command. gpUnsetPrefix('gpx'); gpUnsetPrefix('gp_'); gpUnsetPrefix('x2t_'); gpUnset('gpContext'); $commands = gp('gp_command'); $commands = preg_replace('/\\s{2,}/', ' ', $commands); gpSet('gp_command', $commands); $args = explode(' ', $commands); $table_frag = array_shift($args); $table_frag = strtolower($table_frag); // If a special command was added, pull it out $dotcmd = ''; if (strpos($table_frag, '.') !== false) { list($table_frag, $dotcmd) = explode('.', $table_frag, 2); } // Now run through the list of pages looking for the first match, but // look at the aliases first if they exist $aliases = ArraySafe($GLOBALS, 'COMMAND_ALIASES', array()); foreach ($aliases as $alias => $page) { if (substr(strtolower($alias), 0, strlen($table_frag)) == $table_frag) { $table_id = $page; break; } } $PAGES = array(); include 'ddpages.php'; $pages = array_keys($PAGES); foreach ($pages as $page) { if (substr(strtolower($page), 0, strlen($table_frag)) == $table_frag) { $table_id = $page; break; } } $x4 = configGet('x4welcome', 'N') == 'Y' ? true : false; // Can't figure it, have to leave if (!isset($table_id)) { vgfSet('command_error', 'Unknown: ' . $table_frag); return; } // Now decide what to do. if ($dotcmd == 'new') { if ($x4) { gpSet('x4Page', $table_id); gpSet('x4Mode', 'new'); } else { gpSet('gp_mode', 'ins'); gpSet('gp_page', $table_id); } } else { if ($dotcmd != '') { vgfSet('command_error', 'Unknown Command: ' . $table_frag . '.' . $dotcmd); return; } else { // for now we assume everything else is a lookup if (count($args) == 0) { // No arguments means go to lookup mode gpSet('gp_mode', 'search'); gpSet('gp_page', $table_id); if ($x4) { gpSet('x4Page', $table_id); } } else { // Clear prior search results processPost_TableSearchResultsClear($table_id); // Re-write the query into a search // by setting our values as the search values gpSet('gp_page', $table_id); gpSet('gpx_page', $table_id); gpSet('gp_mode', 'browse'); gpSet('gpx_mode', 'search'); # KFD 8/18/08 MAJOR CHANGE. Loading this up w/old code caused # things like viewname not to exist #$dd=dd_tableRef($table_id); $dd = ddTable($table_id); # KFD 8/18/08 $cols = explode(',', $dd['projections']['_uisearch']); array_shift($cols); // pop off the first one, assume it is the pk/code gpUnsetPrefix('x2t_'); // clear troublesome values foreach ($cols as $i => $colname) { if (isset($args[$i])) { gpSet('x2t_' . $colname, $args[$i]); } } if ($x4) { gpSet('x4Page', $table_id); foreach ($cols as $i => $colname) { if (isset($args[$i])) { gpSet('pre_' . $colname, $args[$i]); } } } } } } }