function checkDBFilesForChanges() { global $parm; $this->LogStage("Checking spec files for changes"); $changed = false; $checksums = array(); $specboot = $parm["SPEC_BOOT"] . ".add"; $checksums[] = array('file' => $specboot, 'md5' => md5_file($parm['DIR_PUB'] . "lib/" . $specboot), 'fullpath' => $parm['DIR_PUB'] . "lib/" . $specboot); if (isset($parm['INST'])) { $app = str_replace('_' . $parm['INST'], '', $parm['APP']); } else { $app = $parm['APP']; } if ($parm["SPEC_LIST"] != "") { $speclist = explode(",", $parm["SPEC_LIST"]); foreach ($speclist as $spec) { if (substr($spec, -5) != '.yaml') { $file = $spec . ".add"; } else { $file = $spec; } $checksums[] = array('file' => $file, 'md5' => md5_file($parm["DIR_PUB"] . "application/" . $file), 'fullpath' => $parm["DIR_PUB"] . "application/" . $file); } } $checkqry = "SELECT relname FROM pg_class WHERE relname='instance_spec_checksums'"; $checkrslts = SQL_AllRows($checkqry); if (count($checkrslts) == 0) { $this->LogEntry("Instance tracking table doesnt exist yet...ignoring until next build"); return true; } foreach ($checksums as $checksum) { $query = "SELECT checksum,skey FROM " . ddTable_idResolve('instance_spec_checksums') . " WHERE \n application=" . SQLFC($app) . " AND spec_name=" . SQLFC($checksum['file']) . (isset($parm['INST']) ? " AND instance=" . SQLFC($parm['INST']) : ''); $row = SQL_OneRow($query); if ($row) { $this->LogEntry('Entry for ' . $checksum['file'] . ' file found'); if ($row['checksum'] != $checksum['md5']) { $this->LogEntry("Spec File Changed: " . $checksum['file']); $changed = true; $checksum_update = array('skey' => $row['skey'], 'checksum' => md5_file($checksum['fullpath'])); SQLX_Update('instance_spec_checksums', $checksum_update); $this->LogEntry("Updating Entry"); } } else { $this->LogEntry('Entry for ' . $checksum['file'] . ' not found'); $checksum_entry = array('application' => $app, 'instance' => isset($parm['INST']) ? $parm['INST'] : '', 'spec_name' => $checksum['file'], 'checksum' => md5_file($checksum['fullpath'])); SQLX_Insert('instance_spec_checksums', $checksum_entry); $this->LogEntry("Spec File Changed: " . $checksum['file']); $changed = true; } } if ($changed) { $this->LogEntry('One or more spec files have changed: Proceeding with full build'); } else { $this->LogEntry('Spec files have not changed: Proceeding with mini build'); } return $changed; }
/** 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; }
/** * Go get FETCH values from other tables * */ function fetch() { // Get the list of columns from the dd $column_id = gp('column'); $table_id = $this->dd['table_id']; $table_id_fko = $this->dd['flat'][$column_id]['table_id_fko']; $match = $table_id . '_' . $table_id_fko . '_'; $collist = $this->dd['FETCHDIST'][$match]; // Build the SQL to fetch the row $colsc = array(); $colsp = array(); foreach ($collist as $idx => $info) { $colsp[] = $info['column_id_par'] . ' as ' . $info['column_id']; } $type_id = $this->dd['flat'][$column_id]['type_id']; $value = SQL_Format($type_id, gp('value')); $sql = "SELECT " . implode(',', $colsp) . " FROM " . ddTable_idResolve($table_id_fko) . " WHERE " . $this->dd['fk_parents'][$table_id_fko]['cols_par'] . "= {$value}"; $answer = SQL_OneRow($sql); x4Data('fetch', $answer); }
function hMover() { // Get the parent table, and the "left" side, which is us $dd = ContextGet('drilldown', array()); $tpar = $dd[0]['page']; $tleft = $this->table_id; // The right side we *assume* is the other parent table // of us that is not the drilldown source. Get it? It breaks // of course if this table has more than one parent $tables = array_keys($this->table['fk_parents']); unset($tables[$tpar]); $tright = array_pop($tables); // if > 1 parent, this won't work $dd_right = dd_tableref($tright); // Get match expression for left-hand side $matches = $dd[0]['parent']; $pmatch = ''; foreach ($matches as $key => $value) { $ileft = $key; $imatch = SQLFC($value); $pmatch .= $key . "='" . $value . "'"; } // Do an insert if coming through as ajax $sqins = ''; if (gpExists('moveradd')) { if (gp('moveradd') != '0') { $row1 = array($dd_right['pks'] => gp('moveradd')); $row2 = $dd[0]['parent']; $rowi = array_merge($row1, $row2); SQLX_Insert($this->table_id, $rowi); } else { $tab = $this->table_id; $cols = $this->table['pks']; $colr = $dd_right['pks']; $sqins = "insert into {$tab}\n ( {$cols} ) \n SELECT {$imatch}, {$colr} \n FROM {$tright}\n WHERE NOT EXISTS (\n SELECT * FROM {$tleft}\n WHERE {$tleft}.{$key} = {$imatch}\n AND {$tleft}.{$colr} = {$tright}.{$colr})"; SQL($sqins); } } // Do a delete if coming through as ajax $sqldel = 'hi'; if (gpExists('moverdel')) { $sqldel = 'moverdel exists'; if (gp('moverdel') != '0') { $sqldel = "delete from " . ddTable_idResolve($this->table_id) . " where skey=" . SQLFN(gp('moverdel')); //echo "echo|$sq"; } else { $sqldel = "delete from " . ddTable_idResolve($this->table_id) . " WHERE " . $pmatch; } SQL($sqldel); } # Pull the source table, the right-hand side # KFD 6/9/08, make left hand side sort by description # if present. $vright = ddTable_idResolve($tright); $vleft = ddTable_idResolve($tleft); $ob = $dd_right['pks']; $ljoin = ''; $lob = ''; if (isset($dd_right['flat']['description'])) { $ob = 'description'; $ljoin = " JOIN {$vright} r ON {$vleft}." . $dd_right['pks'] . '=r.' . $dd_right['pks']; $lob = ' ORDER BY r.description'; } $sq = "SELECT " . $dd_right['pks'] . " as pk\n ,description\n FROM " . ddTable_idResolve($tright) . "\n WHERE description <> ''\n ORDER BY {$ob}"; $rows_right = sql_allrows($sq, 'pk'); # Left side table. $sq = "SELECT {$vleft}." . $dd_right['pks'] . " as pk,{$vleft}.skey\n FROM " . ddTable_IDResolve($this->table_id) . $ljoin . ' ' . " WHERE {$pmatch} {$lob}"; $rows_left = sql_allrows($sq, 'pk'); // Convert the left hand side into options $ahl = array(); foreach ($rows_left as $row) { if (isset($rows_right[trim($row['pk'])])) { $ahl[] = "<OPTION " . ' VALUE="' . $row['skey'] . '"' . '>' . $rows_right[trim($row['pk'])]['description'] . '</option>'; } } // Convert the right hand side into options $ahr = array(); foreach ($rows_right as $row) { if (!isset($rows_left[trim($row['pk'])])) { $ahr[] = "<OPTION " . ' VALUE="' . $row['pk'] . '"' . '>' . $row['description'] . '</option>'; } } ob_start(); ?> <table class="table table-bordered table-striped table-condensed"> <tr> <td> <b>Selected Values</b><br/><br/> <select size=20 style="width: 250px" onclick="formPostAjax('&gp_xajax=1&moverdel='+this.value)" > <?php echo implode("\n", $ahl); ?> </select> <td style="padding:10px; vertical-align: top"> <br/> <br/> <button onclick="formPostAjax('&gp_xajax=1&moveradd=0')" ><< All</button> <br/> <br/> <button onclick="formPostAjax('&gp_xajax=1&moverdel=0')" >All >></button> <td> <b>Available Values</b><br/><br/> <select size=20 style="width: 250px" onclick="formPostAjax('&gp_xajax=1&moveradd='+this.value)" > <?php echo implode("\n", $ahr); ?> </select> </table> <?php $this->h['Content'] = ob_get_clean(); if (gpexists('gp_xajax')) { echo 'mover|' . $this->h['Content']; if (errors()) { echo "|-|echo|" . asErrors(); } exit; } else { $this->h['Content'] = '<div id="mover">' . $this->h['Content'] . '</div>'; } }