Exemplo n.º 1
0
 /**
  * Generate search results for an x4browse/search
  *
  * @author: Kenneth Downs
  */
 function browseFetch()
 {
     #  This is the list of columns to return
     $acols = explode(',', $this->dd['projections']['_uisearch']);
     #  By default the search criteria come from the
     #  variables, unless it is a child table search
     $vals = aFromGP('x4w_');
     $awhere = array();
     $tabPar = gp('tableIdPar');
     if ($tabPar != '') {
         $ddpar = ddTable(gp('tableIdPar'));
         $pks = $ddpar['pks'];
         $stab = ddView(gp('tableIdPar'));
         $skey = SQLFN(gp('skeyPar'));
         $vals2 = SQL_OneRow("SELECT {$pks} FROM {$stab} WHERE skey = {$skey}");
         if (!$vals2) {
             $vals2 = array();
         }
         $vals = array_merge($vals, $vals2);
     }
     # Build the where clause
     #
     foreach ($vals as $column_id => $colvalue) {
         if (!isset($this->flat[$column_id])) {
             continue;
         }
         $colinfo = $this->flat[$column_id];
         $exact = isset($vals2[$column_id]);
         //$tcv  = trim($colvalue);
         $tcv = $colvalue;
         $type = $colinfo['type_id'];
         if ($tcv != "") {
             // trap for a % sign in non-string
             $xwhere = sqlFilter($this->flat[$column_id], $tcv);
             if ($xwhere != '') {
                 $awhere[] = "({$xwhere})";
             }
         }
     }
     # <----- RETURN
     if (count($awhere) == 0) {
         x4Debug("returning");
         return;
     }
     # Generate the limit
     # KFD 11/12/08, modified to respect sql_limit, with default of 100
     $SLimit = ' LIMIT ' . configGet('sql_limit', 100);
     if ($tabPar != '') {
         if (a($this->dd['fk_parents'][$tabPar], 'uiallrows', 'N') == 'Y') {
             $SLimit = '';
         }
     }
     #  Build the Order by
     #
     $ascDesc = gp('sortAD') == 'ASC' ? ' ASC' : ' DESC';
     $aorder = array();
     $searchsort = trim(a($this->dd, 'uisearchsort', ''));
     if (gpExists('sortAD')) {
         $aorder[] = gp('sortCol') . ' ' . gp('sortAD');
     }
     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
     $SWhere = ' WHERE ' . implode(' AND ', $awhere);
     // Retrieve data
     $SQL = "SELECT skey," . implode(',', $acols) . "  FROM " . $this->view_id . $SWhere . $SQLOrder . $SLimit;
     $answer = SQL_AllRows($SQL);
     $this->browseFetchModify($answer);
     x4Data('browseFetch', $answer);
     return;
 }
Exemplo n.º 2
0
 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;
 }