function ehProcessFromJoins($tables) { // pop off the first element, make it the "FROM" $SQL_from = array_pop($tables); $SQL_Joins = array(); $tables_done = array($SQL_from); // Continue as long as we have more tables, or until // the joining fails (an error) $tabcount = count($tables); while (count($tables) > 0) { // try to match each remaining table to any table we've got // so far foreach ($tables as $table) { $table_par = ''; foreach ($tables_done as $table_done) { // if we got a match, take care of business $table_par = $this->ehProcessFromJoins_Match($table, $table_done); if ($table_par != '') { $table_chd = $table_par == $table_done ? $table : $table_done; $dd = dd_tableref($table_par); $apks = explode(',', $dd['pks']); $apks2 = array(); foreach ($apks as $apk) { $apks2[] = "{$table_chd}.{$apk} = {$table_par}.{$apk}"; } $SQL_Joins[$table] = implode(' AND ', $apks2); // Move over to the "done" pile $tables_done[] = $table; unset($tables[$table]); break; } } if ($table_par != '') { break; } } // This means we failed to join any of the tables to any // other table, so something has gone wrong if ($tabcount == count($tables)) { break; } } // Now join them all up and return $retval = "\n FROM {$SQL_from} "; foreach ($SQL_Joins as $table_id => $SQL_Join) { $retval .= "\n JOIN {$table_id} ON {$SQL_Join}"; } return $retval; }
function xAjaxColSave() { echo "xajaxm|"; $row = array('table_id' => gp('gp_table_id'), 'importmap' => gp('gp_map'), 'column_id' => gp('gp_xajax'), 'column_id_src' => gp('gp_xval')); $dd = dd_tableref('importmapcolumns'); SQLX_UpdateOrInsert($dd, $row); }
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>'; } }
/** * @deprecated */ function aColsModeProj(&$table, $mode, $projection = '') { if (!Is_array($table)) { $table = dd_tableref($table); } // begin with the info from the data dictionary $cols1 = aColInfoFromDD($table); // Combine the base parameters with the parameters // for a particular mode $keys = array_keys($cols1['base']); $cols2 = array(); foreach ($keys as $key) { $cols2[$key] = array_merge($cols1['base'][$key], $cols1[$mode][$key]); } // Make a javascript routine to calculate extended values // aColsModeProjcalcRow($table, $cols2); // Call out to the projection resolver, which includes // nifty row-level security, and get the list of // columns we will handle // $colsp = DDProjectionResolve($table, $projection); foreach ($colsp as $column_id) { $cols3[$column_id] = $cols2[$column_id]; // while we're going row by row, set some props. // This way downstream stuff doesn't need to be // told again what mode we are in. $cols3[$column_id]['mode'] = $mode; // KFD 3/1/08, correction for column security if (ArraySafe($table['flat'][$column_id], 'securero') == 'Y' && $mode != 'search') { $cols3[$column_id]['writable'] = false; } // KFD 3/21/08, add in a calculated tooltip, if option is set if (OPtionGet('TOOLTIP', 'N') != 'NONE') { if (ArraySafe($table['flat'][$column_id], 'tooltip') == '') { $tooltip = ''; $aid = trim($table['flat'][$column_id]['auto_formula']); switch (trim($table['flat'][$column_id]['automation_id'])) { case 'SEQUENCE': $tooltip = "This value is automatically generated"; break; case 'SUM': $tooltip = "This value is the calculated sum of " . $aid; break; case 'MAX': $tooltip = "This value is the calculated minimum from " . $aid; break; case 'MIN': $tooltip = "This value is the calculated minimum from " . $aid; break; } if ($tooltip != '') { $cols3[$column_id]['tooltip'] = $tooltip; } } } } return $cols3; }
function index_hidden_ajx1ctable() { // First fetch the values $table_id = gp('ajxc1table'); $colname = gp('ajxcol'); $colvalue = gp('ajxval'); $skey = gp('ajxskey'); // Now prepare the data dictionary and issue the update $dd = dd_tableref($table_id); $colvalue = SQL_Format($dd['flat'][$colname]['type_id'], $colvalue); SQL("UPDATE {$table_id} SET {$colname} = {$colvalue} WHERE skey = {$skey}"); // Errors will appear as a popup if (Errors()) { echo "echo|" . hErrors(); return; } // If they requested values back, provide those now if (gp('ajxlist') != '' && gp('ajxlist') != 'X') { // Initialize the array of information about the queries we will make $info = array($table_id => array('skey' => $skey)); // Split the list and build the arrays of information we need to // run queries and generate return values for display $raw = explode(',', gp('ajxlist')); $returns = array(); foreach ($raw as $rawone) { // Parse each value into the three values it contains list($control, $table, $column) = explode(".", $rawone); if ($control == '-skey-') { // this is magic value that tells us its the skey $info[$table]['skey'] = $column; //column actually is skey here } else { // normal case, we've been told a control, table, and column. // If no table given, assume the table we updated $table = $table == '' ? $table_id : $table; $info[$table]['columns'][] = $column; $info[$table]['controls'][] = $control; } } // Now go through each table, pull the data, and build the returns foreach ($info as $table => $tabinfo) { if (!isset($tabinfo['skey'])) { $returns[] = "echo|No skey passed for table {$table}"; } else { $sk = $tabinfo['skey']; $cols = implode(',', $tabinfo['columns']); $row = SQL_OneRow("SELECT {$cols} FROM {$table} WHERE skey = {$sk}"); foreach ($tabinfo['columns'] as $index => $colname) { $returns[] = '_value' . '|' . $tabinfo['controls'][$index] . '|' . $row[$colname]; } } } echo implode("|-|", $returns); } }