/**
  *  In onscreen mode, end the HTML table.
  *
  *  In PDF mode, output the report and then issue an 
  *  "exit" to end all processing.
  *  Also issues an empty "Pragma" header which is apparently necessary
  *  on some IE systems to get a display, otherwise the user will 
  *  complain that it "doesn't work" and when you click on the link to
  *  generate the report nothing appears to happen.
  *
  *  @param string $name Name of report, defaults to 'report.pdf'
  *  @param string $nature "I" for inline (default) or "A" for attachment.
  *
  *  @since 12/16/07
  */
 function overAndOut($name = "report.pdf", $nature = 'I')
 {
     if ($this->format == 'csvexport') {
         header('Cache-Control: maxage=3600');
         //Adjust maxage appropriately
         header('Pragma:', true);
         // required to prevent caching
         // These are the normal ones
         header('Content-disposition: attachment; filename="export.csv"');
         #header('Content-Type: text/plain');
         header('Content-Type: application/vnd.ms-excel');
         echo $this->csvexport;
         exit;
         return;
     } elseif ($this->format == 'onscreen') {
         if ($this->x6) {
             #x4HTML('*MAIN*','message from ken');
             x6html('*MAIN*', $this->grid->bufferedRender());
         } else {
             echo "\n</table> <!-- androPageReport end -->";
         }
         return;
     }
     header('Pragma:', true);
     $this->Output($name, $nature);
     exit;
 }
Example #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;
 }
Example #3
0
function index_hidden_x6FETCH()
{
    $returns = array();
    # This is everything that *might* go back, make a place
    # for all of it
    $GLOBALS['AG']['x4'] = array('error' => array(), 'debug' => array(), 'notice' => array(), 'html' => array(), 'script' => array());
    // First fetch the values
    $table_id = gp('x6fetch');
    $dd = ddTable($table_id);
    $column = gp('x6col');
    $colvalue = gp('x6val');
    # Look for fetch columns that pull from this column's
    # table_id_fko
    $tfko = $dd['flat'][$column]['table_id_fko'];
    $cfko = $dd['flat'][$column]['column_id_fko'];
    $cols = array();
    foreach ($dd['flat'] as $fcol => $cdetails) {
        $arr = array('FETCH', 'FETCHDEF', 'DISTRIBUTE');
        if (in_array($cdetails['automation_id'], $arr)) {
            if ($cdetails['auto_table_id'] == $tfko) {
                $cols[$fcol] = $cdetails['auto_column_id'];
            }
        }
    }
    # We now have a list of source and destination
    # columns, build the query
    $sql = "Select " . implode(',', $cols) . " FROM {$tfko} WHERE {$cfko} = " . SQLFC($colvalue);
    $row = SQL_OneRow($sql);
    foreach ($cols as $fcol => $srccol) {
        $type = $dd['flat'][$fcol]['formshort'];
        if ($type == 'date') {
            x6html("x6inp_{$table_id}_{$fcol}", date("Y-m-d", dEnsureTs($row[$srccol])));
        } else {
            x6html("x6inp_{$table_id}_{$fcol}", $row[$srccol]);
        }
    }
    echo json_encode_safe($GLOBALS['AG']['x4']);
    exit;
}