function rowsFromFilters(&$table, $filters, $cols, $matches = array()) { $tabflat = $table['flat']; $table_id = $table['table_id']; $view_id = DDTable_IDResolve($table_id); //echo SessionGet("GROUP_ID_EFF"); // Set user-requested filters $sw = array(); foreach ($tabflat as $colname => $colinfo) { if (isset($matches[$colname])) { $tcv = trim($matches[$colname]); if ($tcv != "") { $tcsql = SQL_Format($colinfo["type_id"], $tcv); $sw[] = $colname . "=" . $tcsql; //$sql_where.=ListDelim($sql_where," AND ").$colname."=".$tcsql; } } elseif (isset($filters[$colname])) { $tcv = trim($filters[$colname]); $tid = $colinfo['type_id']; if ($tid == 'dtime' || $tid == 'date') { $tcv = dEnsureTS($tcv); } if ($tcv != "") { // trap for a % sign in non-string $sw[] = '(' . sqlFilter($colinfo, $tcv) . ')'; } } } $sql_where = implode(' AND ', $sw); // Set identity-security filters // NOPE, Rem'd out 10/26/06 when moved server-side //$sql_where2 = S*QLX_Filters($tabflat); //if ($sql_where2!="") { // $sql_where.=ListDelim($sql_where," AND ").$sql_where2; //} if ($sql_where != "") { $sql_where = " WHERE " . $sql_where; } // KFD 10/24/07. ASC/DESC used to be after the clause below, // but we need to get it first because we have // to assign it to each column $obasc = ConGet("table", $table_id, "orderasc"); if ($obasc == "") { $obasc = "ASC"; ConSet("table", $table_id, "orderasc", $obasc); } $SQLOB = $obasc; // KFD: 10/24/07. Order by all columns, not just the // the selected one. But order by the selected one // first. $ob = ConGet("table", $table_id, "orderby"); $lob = explode(',', $table['projections']['_uisearch']); if ($ob == '') { foreach ($lob as $onecol) { $aid = $table['flat'][$onecol]['automation_id']; if (in_array($aid, array('SEQUENCE', 'SEQDEFAULT'))) { continue; } $ob = $onecol; ConSet('table', $table_id, 'orderby', $ob); } } $sob = $ob . ' ' . $obasc; foreach ($lob as $onecol) { $aid = $table['flat'][$onecol]['automation_id']; if (in_array($aid, array('SEQUENCE', 'SEQDEFAULT'))) { continue; } if ($onecol != $ob) { $sob .= "\n, " . $onecol . ' ' . $obasc; } } ConSet('table', $table_id, 'complex_orderby', $sob); // Retrieve the limit as a vgaget, defaulting to 300 // DJO 4-8-2008 Allow for system variable override, 0 would be all records /** * DJO 8-15-2008 No longer needed because of the Config System */ //$SQL_Limit = OptionGet( 'SQL_LIMIT', vgaGet( 'SQL_Limit', 300 ) ); $SQL_Limit = configGet('sql_limit', 300); // Execute the sql, pull down the skey values $skeys = array(); $sq = "SELECT " . $cols . " FROM " . $view_id . $sql_where . " ORDER BY " . $sob . ($SQL_Limit > 0 ? " LIMIT " . $SQL_Limit : ''); $rows = SQL_ALLRows($sq); $retval = $rows === false ? array() : $rows; return $retval; }
function hBoxes($mode) { // Obtain a row depending on the mode we are in. If there // wdas an error then reload the first row for this table if (is_array(vgfGet('ErrorRow_' . $this->table_id, ''))) { $row = vgfGet('ErrorRow_' . $this->table_id); $row['skey'] = gp('gpx_skey'); } else { switch ($mode) { case 'search': // if a previous search, use that, else fall through // to using current row $row = ConGet('table', $this->table_id, 'search', array()); if (count($row) != 0) { break; } case 'ins': $row = DrillDownMatches(); if (count($row) == 0) { $row = aFromGP('pre_'); } // KFD 8/13/07, part of COPY ability if (gp('gp_action') == 'copy') { $row2 = SQL_OneRow("SELECT * FROM " . $this->table_id . " where skey=" . SQLFN(gp('gp_skey'))); foreach ($row2 as $column_id => $colvalue) { if (is_numeric($column_id)) { continue; } if (!isset($this->table['flat'][$column_id])) { continue; } $aid = $this->table['flat'][$column_id]['automation_id']; if ($aid == 'SEQUENCE' || $column_id == gp('gp_exclude')) { unset($row2[$column_id]); } } $row = array_merge($row, $row2); } break; case 'upd': $skey = gp('gp_skey'); hidden('gp_skey', ''); if (trim($skey) == '') { $row = array(); } else { $skey = " WHERE skey=" . $skey; $sq = "Select * FROM " . $this->view_id . $skey; $row = SQL_OneRow($sq); } } } // Save the row for other routines $this->row = $row; // Find out what skey we are on, give a next/prev // kind of button for stuff like that. // Set the next/prev stuff based on rows $HTML_PagePrev = $HTML_PageNext = $HTML_ViewingPage = ""; if ($mode == "upd") { $lprev = $lnext = false; $skey = $this->row['skey']; $sess_skeys = ConGet("table", $this->table_id, "skeys", array()); if (count($sess_skeys) > 1) { $sess_srows = array_flip($sess_skeys); $sess_srow = $sess_srows[$row['skey']]; $lprev = $sess_srow == 0 ? false : true; $skeyf = $sess_srow == 0 ? 0 : $sess_skeys[0]; $skeyp = $sess_srow == 0 ? 0 : $sess_skeys[$sess_srow - 1]; $skeyn = $sess_srow >= count($sess_srows) - 1 ? 0 : $sess_skeys[$sess_srow + 1]; $skeyl = $sess_srow >= count($sess_srows) - 1 ? 0 : $sess_skeys[count($sess_srows) - 1]; $hprev = hLinkImage('first', 'First', 'gp_skey', $skeyf, $lprev) . hLinkImage('previous', 'Previous', 'gp_skey', $skeyp, $lprev); $lnext = $sess_srow < count($sess_srows) - 1 ? true : false; $hnext = hLinkImage('next', 'Next', 'gp_skey', $skeyn, $lnext) . hLinkImage('last', 'Last', 'gp_skey', $skeyl, $lnext); $HTML_ViewingPage = "Page " . ($sess_srow + 1) . " of " . count($sess_srows); } } // Output and save the navbar ob_start(); if ($HTML_ViewingPage != '') { $hprev = $this->hTextButton('\\First', 'gp_skey', $skeyf, $lprev) . $this->hTextButton('\\Previous', 'gp_skey', $skeyp, $lprev); $hnext = $this->hTextButton('Ne\\xt', 'gp_skey', $skeyn, $lnext) . $this->hTextButton('Las\\t', 'gp_skey', $skeyl, $lnext); if (vgfget('buttons_in_commands')) { $this->h['NavBar'] = ''; vgfSet('html_navbar', $hprev . $hnext); } else { $this->h['NavBar'] = "\n<div class=\"x2menubar\">\n" . $hprev . $HTML_ViewingPage . " " . $hnext . "\n</div><br>"; } } // Second output is main content // KFD 8/9/07, Project DUPECHECK // If a "dupecheck" projection exists, and they are // doing a new entry, we first ask them to enter // those values $dc = ArraySafe($this->table['projections'], 'dupecheck'); if ($dc != '' && $mode == 'ins' && !gpExists('gp_nodupecheck')) { hidden('gp_action', 'dupecheck'); $this->h['Content'] = $this->hBoxesX3($mode, 'dupecheck'); $this->h['Content'] .= '<br/><br/>' . '<button class="btn btn-primary id="object_for_enter" onclick="formSubmit()">(ENTER) Check For Duplicates</button>'; } else { $this->h['Content'] = $this->hBoxesDefault($mode); } }