示例#1
0
 /**
  *  Entry point for all processing.  Assumes a file
  *  named "$page.page.yaml" is in the application
  *  directory.
  *
  *  @param string $page   Name of page.
  *  @access public
  */
 function main($page)
 {
     // Store the name of the page
     $this->page = $page;
     $filename = $GLOBALS['AG']['dirs']['root'] . "application/{$page}.page.yaml";
     include_once "spyc.php";
     $yamlRaw = Spyc::YAMLLoad($filename);
     $this->yamlP2 = $this->YAMLPass2($yamlRaw);
     # Route out to generate help text
     $this->mainHelp();
     // If there are no sections, take content and make a section,
     // so that downstream code can unconditionally work with sections
     // DO 7/31/2008 uifilter is not set in section, so if section is
     // set and uifilter is not set we need to create an empty one
     if (!isset($this->yamlP2['section'])) {
         $this->yamlP2['section'] = array('default' => array('table' => a($this->yamlP2, 'table', array()), 'union' => a($this->yamlP2, 'union', array()), 'uifilter' => a($this->yamlP2, 'uifilter', array())));
     } else {
         if (!isset($this->yamlP2['uifilter'])) {
             $this->yamlP2['uifilter'] = array();
         }
     }
     if (!isset($this->yamlP2['template'])) {
         $this->yamlP2['template'] = '';
     }
     // Go through filters and make them all uniform
     $filters = ArraySafe($this->yamlP2, 'uifilter', array());
     foreach ($filters as $id => $info) {
         // If a table is named, go for that
         if (isset($info['table'])) {
             $table_dd = dd_TableRef($info['table']);
             $column = ArraySafe($info, 'column', $id);
             $flat = $table_dd['flat'][$column];
             $filter =& $this->yamlP2['uifilter'][$id];
             $filter['type_id'] = $flat['type_id'];
             $filter['colprec'] = $flat['colprec'];
             $filter['colscale'] = $flat['colscale'];
             $filter['description'] = ArraySafe($filters[$id], 'description', $flat['description']);
         }
     }
     if (ArraySafe($this->yamlP2['options'], 'buffer', 'Y') == 'N') {
         $this->flag_buffer = false;
     }
     // Check to see if nofilter option is set
     if (ArraySafe($this->yamlP2['options'], 'nofilter') != '') {
         $this->yamlP2['options']['nofilter'] = $this->yamlP2['options']['nofilter'];
     } else {
         $this->yamlP2['options']['nofilter'] = 'N';
     }
     // KFD 4/21/08, determine when to display HTML and
     // when to run page
     $runHTML = true;
     if ($this->yamlP2['options']['nofilter'] == 'Y') {
         $runHTML = false;
     }
     if (gp('gp_post') != '' && gp('gp_post') != 'onscreen') {
         $runHTML = false;
     }
     if (gp('gp_post') == 'onscreen' && gpExists('x4Page')) {
         $runHTML = false;
     }
     if (gp('gp_post') == 'onscreen' && gpExists('x6page')) {
         $runHTML = false;
     }
     # KFD 9/10/08, don't run HTML if they are requesting Show sql
     if (gp('showsql') == 1) {
         $runHTML = false;
     }
     $runPage = true;
     x4Debug("gp post is " . gp('gp_post'));
     if (gp('gp_post') == '') {
         $runPage = false;
     }
     // DO 7/31/2008  If smarty template set && nofilter set just display the page.
     if ($this->yamlP2['template'] != '' && $this->yamlP2['options']['nofilter'] == 'Y') {
         $runPage = true;
     }
     // DO 7/31/2008 do not need form again for Smarty AndroPage
     if ($this->yamlP2['template'] == '' || gp('gp_post') == '') {
         if ($runHTML) {
             $this->x3HTML();
         }
     }
     if ($runPage) {
         $this->PassPage();
     }
 }
示例#2
0
/**
name:SQLX_Insert
parm:string/array table
parm:array Row
parm:bool Rewrite_Skey
parm:bool Clip_Fields
returns:int

In its most basic form, this routine accepts a [[Row Array]]
and attempts to insert it into a table.  Upon success, the routine
returns the skey value of the new row.

The first entry can be either a [[Table Reference]] or the name of
a table.  The second entry is always a [[Row Array]].  This function
makes use of the dictionary to determine the correct formatting of all
columns, and ignores any column in the [[Row Array]] that is not
in the table.

The third parameter is used by the framework, and should always be
false.  If the third parameter is set to true, then this routine
executes a [[gpSet]] with the value of skey for the new row, making
it look like this row came from the browser.

If the fourth parameter is true, values are clipped to column width
to prevent overflows.  This almost guarantees the insert will succeed,
but should only be done if it is acceptable to throw away the ends of
columns.
*/
function SQLX_Insert($table, $colvals, $rewrite_skey = true, $clip = false)
{
    # KFD 6/12/08, use new and improved
    errorsClear();
    if (!is_array($table)) {
        $table = DD_TableRef($table);
    }
    $table_id = $table["table_id"];
    $view_id = ddTable_idResolve($table_id);
    $tabflat =& $table["flat"];
    $new_cols = "";
    $new_vals = "";
    foreach ($tabflat as $colname => $colinfo) {
        if (isset($colvals[$colname])) {
            //if($colvals[$colname]<>'') {
            if (DD_ColInsertsOK($colinfo, 'db')) {
                # KFD 6/18/08, % signs really mess things up
                #if(strpos($colvals[$colname],'%')!==false) {
                #    ErrorAdd("The % sign may not be in a saved value");
                #    vgfSet('ErrorRow_'.$table_id,$colvals);
                #    return 0;
                #}
                $cliplen = $clip ? $colinfo['colprec'] : 0;
                $new_cols .= ListDelim($new_cols) . " " . $colname;
                $new_vals .= ListDelim($new_vals) . " " . SQL_FORMAT($colinfo["type_id"], $colvals[$colname], $cliplen);
            }
            //}
        }
    }
    if (!Errors()) {
        $sql = "INSERT INTO " . $view_id . " ({$new_cols}) VALUES ({$new_vals})";
    }
    x4Debug($sql);
    x4Debug(SessionGet('UID'));
    // ERRORROW CHANGE 5/30/07, big change, SQLX_* routines now save
    //  the row for the table if there was an error
    $errflag = false;
    SQL($sql, $errflag);
    if ($errflag) {
        vgfSet('ErrorRow_' . $table_id, $colvals);
    }
    $notices = pg_last_notice($GLOBALS["dbconn"]);
    $retval = 0;
    $matches = array();
    # KFD 10/18/08. This venerable line has been quietly working forever,
    #               until today!  The problem turned out to be the table
    #               name had a number in it, which screwed it up!  So
    #               I've changed one line here.
    #preg_match_all("/SKEY(\D*)(\d*);/",$notices,$matches);
    preg_match_all("/SKEY(.*\\s)(\\d*);/iu", $notices, $matches);
    if (isset($matches[2][0])) {
        $retval = $matches[2][0];
        if ($rewrite_skey) {
            gpSet("gp_skey", $matches[2][0]);
            gpSet("gp_action", "edit");
        }
    }
    // Possibly cache the row
    $cache_pkey0 = vgfget('cache_pkey', array());
    $cache_pkey = array_flip($cache_pkey0);
    if (isset($cache_pkey[$table_id])) {
        CacheRowPut($table, $colvals);
    }
    return $retval;
}
示例#3
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;
 }
示例#4
0
function searchBrowseOneCol($type, $colname, $tcv)
{
    $values = explode(',', $tcv);
    $sql_new = array();
    foreach ($values as $tcv) {
        if (trim($tcv) == '') {
            continue;
        }
        if ($tcv == '*') {
            $tcv = '%';
        }
        $tcv = trim(strtoupper($tcv));
        if (in_array($type, array('int', 'numb', 'date', 'time'))) {
            $tcv = preg_replace('/[^0-9]/', '', $tcv);
        }
        // This is a greater than/less than situation,
        // we ignore anything else they may have done
        if (substr($tcv, 0, 1) == '>' || substr($tcv, 0, 1) == '<') {
            $new = $colname . substr($tcv, 0, 1) . sqlFormat($type, substr($tcv, 1));
            $sql_new[] = "({$new})";
            continue;
        }
        if (strpos($tcv, '-') !== false && $type != 'ph12' && $type != 'ssn') {
            list($beg, $end) = explode('-', $tcv);
            x4Debug('-' . $end . '-');
            if (trim($end) == '') {
                $new = " UPPER({$colname}) like '" . strtoupper($beg) . "%'";
            } else {
                $slbeg = strlen($beg);
                $slend = strlen($end);
                $new = "SUBSTR({$colname},1,{$slbeg}) >= " . sqlFormat($type, $beg) . ' AND ' . "SUBSTR({$colname},1,{$slend}) <= " . sqlFormat($type, $end);
            }
            $sql_new[] = "({$new})";
            continue;
        }
        if (!isset($aStrings[$type]) && strpos($tcv, '%') !== false) {
            $new = "cast({$colname} as varchar) like '{$tcv}'";
        } else {
            $tcsql = sqlFormat($type, $tcv);
            if (substr($tcsql, 0, 1) != "'" || $type == 'date' || $type == 'dtime') {
                $new = $colname . "=" . $tcsql;
            } else {
                $tcsql = str_replace("'", "''", $tcv);
                $new = " UPPER({$colname}) like '" . strtoupper($tcsql) . "%'";
            }
        }
        $sql_new[] = "({$new})";
    }
    $retval = implode(" OR ", $sql_new);
    return $retval;
}