Beispiel #1
0
 function processSubmit()
 {
     // Get the submitted data
     $table = gp('gp_table_upd', '');
     // Get the flat table def
     $table_dd = dd_TableRef($table);
     $tabflat = ArraySafe($table_dd, 'flat');
     //hprint_r($table);
     $row = aFromGP('gp_upd_');
     //hprint_r($row);
     //hprint_r($row);
     // Build a WHERE clause
     $where = array();
     foreach ($row as $col => $val) {
         if (ArraySafe($tabflat[$col], 'primary_key', 'N') != 'Y') {
             continue;
         }
         $where[] = $col . " = '" . $val . "'";
     }
     //hprint_r($where);
     $where = implode(' AND ', $where);
     // Build a SELECT
     $sql = "SELECT skey\n                 FROM " . ddTable_IDResolve($table) . "\n                WHERE " . $where;
     //hprint_r($sql);
     $records = SQL_AllRows($sql);
     if (count($records) != 1) {
         echo "Invalid or non-unique key supplied\n<br>";
         return;
     }
     // Well, we haven't failed yet, let's add the skey before the update, just to be safe.
     $row['skey'] = $records[0]['skey'];
     $skey = $records[0]['skey'];
     //hprint_r($row);
     SQLX_Update($table_dd, $row);
     if (Errors()) {
         echo hErrors();
     } else {
         echo "Update Successful.  <a href=\"?gp_page={$table}&gp_skey={$skey}\">View Record</a> <br>\n";
     }
 }
Beispiel #2
0
 /**
  *  Takes a list of tables and JOINs them together
  *  and builds the complete query for them.
  *
  *  Returns: A SQL SELECT statement
  */
 function genSQLSectionJoin($yamlP2)
 {
     $page = $this->page;
     $uifilter = a($this->yamlP2, 'uifilter', array());
     // Go get the joins
     $SQL_FROMJOINS = $this->genSQLFromJoins($yamlP2);
     $SQL_COLSWHA = array();
     // See if any of the columns have a GROUP setting,
     // if so, all others must get group: Y
     $yamlP2['groupby'] = array();
     $group = false;
     foreach ($yamlP2['table'] as $table_id => $tabinfo) {
         foreach ($tabinfo['column'] as $colname => $colinfo) {
             if (ArraySafe($colinfo, 'group', '') != '') {
                 $group = true;
                 break;
             }
         }
     }
     if ($group) {
         foreach ($yamlP2['table'] as $table_id => $tabinfo) {
             foreach ($tabinfo['column'] as $colname => $colinfo) {
                 if (ArraySafe($colinfo, 'group', '') == '') {
                     //if(ArraySafe($colinfo,'uino','N')=='N') {
                     $yamlP2['groupby'][] = "{$table_id}.{$colname}";
                     //}
                 }
             }
         }
     }
     // Build various lists of columns
     $SQL_COLSA = array();
     $SQL_COLSOBA = array();
     foreach ($yamlP2['table'] as $table => $table_info) {
         $table_dd = dd_TableRef($table);
         foreach ($table_info['column'] as $colname => $colinfo) {
             // order by
             if (ArraySafe($colinfo, 'order', 'N') == 'Y') {
                 $SQL_COLSOBA[] = "{$table}.{$colname}";
             }
             // comparison
             if (isset($colinfo['compare'])) {
                 $compare = $this->SQLCompare($table, $colname, $colinfo);
                 if ($compare != '') {
                     $SQL_COLSWHA[] = $compare;
                 }
             }
             // group by
             if (a($colinfo, 'group', '') != '') {
                 //$coldef = str_replace("as $colname","",$coldef);
                 $coldef = $colinfo['group'] . "({$table}.{$colname})";
             } else {
                 $coldef = "{$table}.{$colname}";
             }
             // If not in output, stop now
             // KFD 5/31/08, no, keep going and filter out at
             //     output.  We need all columns in case they
             //     are orderby columns
             if (a($colinfo, 'uino', 'N') == 'Y') {
                 continue;
             }
             // if a constant, add the constant and skip the rest
             $constant = a($colinfo, 'constant', '');
             if (ArraySafe($table_info, 'left_join', 'N') == 'Y') {
                 $z = SQL_Format($table_dd['flat'][$colname]['type_id'], '');
                 $cval = $constant == '' ? $coldef : "'{$constant}'";
                 $coldef = "COALESCE({$cval},{$z}) as {$colname}";
             } else {
                 $coldef = $constant == '' ? "{$coldef} as {$colname}" : "'{$constant}' as {$colname}";
             }
             $SQL_COLSA[] = $coldef;
         }
     }
     // Collapse the lists into strings
     $SQL_COLS = implode("\n       ,", $SQL_COLSA);
     # KFD 4/9/09.  Slip in skey and source from first table.
     $tables = array_keys($yamlP2['table']);
     $skeytable = $tables[0];
     $SQL_COLS = $skeytable . ".skey,'{$skeytable}' as _source," . $SQL_COLS;
     $SQL_COLSOB = '';
     if (isset($yamlP2['orderby'])) {
         $SQL_COLSOB = "\n ORDER BY " . $yamlP2['orderby'];
     } else {
         if (count($SQL_COLSOBA) > 0) {
             ksort($SQL_COLSOBA);
             $SQL_COLSOB = "\n ORDER BY " . implode(',', $SQL_COLSOBA);
         }
     }
     // For the UI Filter values, add in the values provided by the user
     $SQL_WHERE = '';
     if (count($SQL_COLSWHA) > 0) {
         $SQL_WHERE = "\n WHERE " . implode("\n   AND ", $SQL_COLSWHA);
     }
     // Collapse the group by
     $SQL_GROUPBY = '';
     if (count($yamlP2['groupby']) > 0) {
         $SQL_GROUPBY = "\n GROUP BY " . implode(',', $yamlP2['groupby']);
     }
     // Now build the final SQL
     $SQ = " SELECT " . $SQL_COLS . $SQL_FROMJOINS . $SQL_WHERE . $SQL_GROUPBY . $SQL_COLSOB;
     if (gp('gp_post') == 'onscreen') {
         $SQ .= " LIMIT 300";
     }
     return $SQ;
 }
Beispiel #3
0
 function DoTests(&$steps)
 {
     $this->error = '';
     // If they manually forced a rollback to an earlier step,
     //  we will catch it below
     $rb = gp('stepreset', '-1');
     // look for flags that indicate manual approval of steps
     if (gp('pgconfig') == 1) {
         sessionSet('pgconfig', true);
     }
     if (gp('pgsuper') == 1) {
         sessionSet('pgsuper', true);
     }
     // If they provided credentials, try to post them
     if (gpExists('loginUID')) {
         if (substr(strtolower(gp('loginUID')), 0, 5) == 'andro') {
             ErrorAdd("Superuser account may not begin with 'andro'");
         } else {
             SessionSet('xUID', gp('loginUID'));
             SessionSet('xPWD', gp('loginPWD'));
         }
     }
     $finished = false;
     foreach ($steps as $current_step => $step) {
         switch ($current_step) {
             case 0:
                 if (!function_exists('pg_connect')) {
                     $finished = true;
                 }
                 break;
             case 1:
                 // If forcing rollback to here, clear user credentials
                 if ($rb == 1) {
                     SessionUnset('xUID');
                     SessionUnSet('xPWD');
                 }
                 // Test if they gave us uid/pwd and if it works
                 if (SessionGet('xUID') == '') {
                     $finished = true;
                 } else {
                     $cs = SQL_ConnString(SessionGet('xUID'), SessionGet('xPWD'), 'postgres');
                     $this->dbx = @pg_connect($cs);
                     if (!$this->dbx) {
                         $this->error = "Could Not Connect with that Username/Password";
                         $finished = true;
                     }
                 }
                 break;
             case 2:
                 // Since we got a connection, try to get versions
                 $res = SQL2("Select version()", $this->dbx);
                 $row = SQL_Fetch_Array($res);
                 $x = explode(' ', $row['version']);
                 $this->pgversion = $x[0] . ' ' . $x[1];
                 $vers = explode('.', $x[1]);
                 $vers = $vers[0] . '.' . $vers[1];
                 if ($vers < 8.1) {
                     $finished = true;
                 }
                 break;
             case 3:
                 if ($rb == 3) {
                     $this->andro = 1;
                     $finished = true;
                     break;
                 }
                 $cs = SQL_ConnString(SessionGet('xUID'), SessionGet('xPWD'), 'andro');
                 $this->dba = @pg_connect($cs);
                 if (!$this->dba) {
                     $finished = true;
                     $this->andro = 0;
                 } else {
                     pg_close($this->dba);
                     $file = $GLOBALS['AG']['dirs']['generated'] . 'ddmodules.php';
                     if (!file_exists($file)) {
                         $finished = true;
                         $this->andro = 1;
                     }
                 }
                 break;
             case 4:
                 // Initialize the node manager
                 SessionSet('UID', SessionGet('xUID'));
                 SessionSet('PWD', SessionGet('xPWD'));
                 scDBConn_Push();
                 $dir_pub = realpath(dirname(__FILE__) . '/../..');
                 if (strpos(ArraySafe($_ENV, 'OS', ''), 'indows') !== false) {
                     $dir_pub = str_replace("\\", "\\\\", $dir_pub);
                 }
                 $row = array('webpath' => 'DEFAULT', 'dir_pub' => $dir_pub, 'description' => 'Default Web Path');
                 $table_dd = dd_TableRef('webpaths');
                 SQLX_UpdateorInsert($table_dd, $row);
                 /*               
                 $table_dd=dd_TableRef('nodes');
                                $row=array(
                                   'node'=>'DHOST2'
                                   ,'description'=>"Andromeda Master Node"
                                   ,'node_url'=>'dhost2.secdat.com'
                                );
                                SQLX_UpdateorInsert($table_dd,$row); 
                                $row=array(
                                   'node'=>'LOCAL'
                                   ,'description'=>"Local Node"
                                   ,'node_url'=>'localhost'
                                );
                                SQLX_UpdateorInsert($table_dd,$row); 
                 */
                 $table_dd = dd_TableRef('applications');
                 $row = array('application' => 'andro', 'description' => "Andromeda Node Manager", 'appspec' => 'andro.dd.yaml', 'node' => 'LOCAL', 'webpath' => 'DEFAULT');
                 SQLX_UpdateorInsert($table_dd, $row);
                 scDBConn_Pop();
                 SessionSet('UID', 'andro');
                 SessionSet('PWD', 'andro');
                 break;
             case 5:
                 break;
             default:
                 $finished = true;
         }
         // if we are clear, stop now
         if ($finished) {
             break;
         }
     }
     for ($x = 0; $x < $current_step; $x++) {
         $steps[$x][0] = true;
     }
     return $current_step;
 }
Beispiel #4
0
/**
* @deprecated
*/
function aColInfoFromDDColumns(&$table, &$retval)
{
    $perm_upd = DDUserPerm($table['table_id'], 'upd');
    // ----------------------------------------------
    // BIG DEAL A: Loop through each row
    // ----------------------------------------------
    foreach ($table['flat'] as $colname => $colinfo) {
        if (!isset($colinfo['uino'])) {
            # KFD 6/2/08, this line is required for some older programs
            # that SDS wrote that still use this family of routines.
            # Table constraints appear to be showing up as empty columns!
            if ($colname == '') {
                continue;
            }
            hprint_r("ERROR IN BUILD, PLEASE CONTACT SECURE DATA SOFTWARE");
            echo "Column {$colname}";
            hprint_r($colinfo);
            exit;
        }
        // Early return, if there is no UI, don't generate at all
        if ($colinfo['uino'] == 'Y') {
            continue;
        }
        // Clear out array
        $c = array();
        // Initialize a new array for the column, with some
        // basic info that is useful in all modes
        $c['base'] = array('type_id' => $colinfo['type_id'], 'formshort' => $colinfo['formshort'], 'column_id' => $colname, 'colprec' => $colinfo['colprec'], 'colscale' => $colinfo['colscale'], 'description' => $colinfo['description'], 'tooltip' => arraySafe($colinfo, 'tooltip'), 'pk_change' => ArraySafe($colinfo, 'pk_change', 'N'));
        $c['ins']['sequence'] = 0;
        $c['upd']['sequence'] = 0;
        // Load in any default snippets. As of this writing, 6/22/07, these
        // are not generated at build time, but can be added by
        // custom classes.
        $c['ins']['snippets'] = isset($colinfo['ins']['snippets']) ? $colinfo['ins']['snippets'] : array();
        $c['upd']['snippets'] = isset($colinfo['upd']['snippets']) ? $colinfo['upd']['snippets'] : array();
        // First property, writable.  Work this out for all
        // three modes.
        $c['search']['writable'] = true;
        $c['ins']['writable'] = true;
        $c['upd']['writable'] = $perm_upd;
        if ($colinfo['uiro'] == 'Y') {
            $c['ins']['writable'] = false;
            $c['upd']['writable'] = false;
        } else {
            $autos = array('seqdefault', 'fetchdef', 'default', 'blank', 'none', 'synch', '', 'queuepos', 'dominant');
            $auto = strtolower(trim($colinfo['automation_id']));
            //echo "the auto for $colname is -".$auto."-<br/>";
            if (!in_array($auto, $autos)) {
                $c['ins']['writable'] = false;
                $c['upd']['writable'] = false;
            }
            // override for primary key
            if ($colinfo['primary_key'] == 'Y') {
                $c['upd']['writable'] = false;
            }
        }
        // This is the default size and maxlength.  Notice that
        // we don't seet a maxlength in search mode.
        //
        $size = $colinfo['dispsize'] + 1;
        $maxl = $colinfo['dispsize'];
        if (ArraySafe($colinfo, 'colscale', 0) != 0) {
            $maxl += 1;
        }
        $c['search']['size'] = $size;
        $c['ins']['size'] = $size;
        $c['ins']['maxlength'] = $maxl;
        $c['upd']['size'] = $size;
        $c['upd']['maxlength'] = $maxl;
        // This is a feature that the column should be all
        // caps, currently done only for primary keys
        if ($table['capspk'] == 'Y' && $colinfo['primary_key'] == 'Y') {
            $snippet = 'javascript:this.value=this.value.toUpperCase()';
            $c['ins']['snippets']['onkeyup'][] = $snippet;
            $c['upd']['snippets']['onkeyup'][] = $snippet;
        }
        // set up foreign keys
        $c['search']['table_id_fko'] = '';
        $c['search']['fkdisplay'] = '';
        $c['ins']['table_id_fko'] = $colinfo['table_id_fko'];
        $c['upd']['table_id_fko'] = $colinfo['table_id_fko'];
        $c['ins']['fkdisplay'] = $colinfo['fkdisplay'];
        $c['upd']['fkdisplay'] = $colinfo['fkdisplay'];
        // If the foreign key is compound, give us the whole thing
        if (trim($colinfo['table_id_fko']) != '') {
            $tabfk = dd_TableRef(trim($colinfo['table_id_fko']));
            $c['upd']['fk_pks'] = $tabfk['pks'];
            $c['ins']['fk_pks'] = $tabfk['pks'];
        }
        // If this column forces calculations, set a flag
        $c['upd']['calcs'] = in_array($colname, $table['calcs']);
        $c['ins']['calcs'] = $c['upd']['calcs'];
        $c['search']['calcs'] = false;
        // Give the guy his chain information
        $c['upd']['chaincalc'] = ArraySafe($colinfo, 'chaincalc', array());
        $c['ins']['chaincalc'] = $c['upd']['chaincalc'];
        $c['search']['chaincalc'] = array();
        // Value min and max
        $c['search']['value_min'] = $colinfo['value_min'];
        $c['search']['value_max'] = $colinfo['value_max'];
        $c['upd']['value_min'] = $colinfo['value_min'];
        $c['upd']['value_max'] = $colinfo['value_max'];
        $c['ins']['value_min'] = $colinfo['value_min'];
        $c['ins']['value_max'] = $colinfo['value_max'];
        // uirows and uicols
        $c['upd']['uicols'] = $colinfo['uicols'];
        $c['upd']['uirows'] = $colinfo['uirows'];
        $c['ins']['uicols'] = $colinfo['uicols'];
        $c['ins']['uirows'] = $colinfo['uirows'];
        $c['search']['uicols'] = $colinfo['uicols'];
        $c['search']['uirows'] = $colinfo['uirows'];
        // defaults
        $c['upd']['default'] = null;
        $c['search']['default'] = null;
        $c['ins']['default'] = $colinfo['automation_id'] == 'DEFAULT' && $colinfo['auto_formula'] != '' ? $colinfo['auto_formula'] : null;
        // Add results into final array
        $retval['base'][$colname] = $c['base'];
        $retval['ins'][$colname] = $c['ins'];
        $retval['upd'][$colname] = $c['upd'];
        $retval['search'][$colname] = $c['search'];
    }
    //hprint_r($retval);
    return $retval;
}
Beispiel #5
0
function index_hidden_fetchrow()
{
    // Get the target table that we need
    $table_id = gp('gp_fetchrow');
    // Load the data dictionary and format the pk value.  Notice
    // that we assume a single-column pk, it will break otherwise.
    //
    $table_dd = dd_TableRef($table_id);
    $pkcol = $table_dd['pks'];
    $type_id = $table_dd['flat'][$pkcol]['type_id'];
    $pkval = SQL_Format($type_id, gp('gp_pk'));
    // Fetch the row
    $answers = SQL_AllRows("SELECT * from {$table_id} WHERE {$pkcol}={$pkval}");
    if (count($answers) == 0) {
        $row = array($pkcol => $pkval);
    } else {
        $row = $answers[0];
    }
    // Collapse the values
    $returns = array();
    foreach ($row as $colname => $colvalue) {
        if (is_numeric($colname)) {
            continue;
        }
        $returns[] = "_value|{$table_id}" . "_{$colname}|" . $colvalue;
    }
    echo implode("|-|", $returns);
    return;
}