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"; } }
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>'; } }