function ehHiddenAndData() { // Some parts of the framework create data that should // be sent out as hidden variables $x = vgfGet('gpControls', ''); if (is_array($x)) { hidden('gpControls', base64_encode(serialize($x))); } // Now take the prior request and pass it through $x = aFromgp('gp_'); foreach ($x as $key => $value) { if ($value != '') { hidden('gpx_' . $key, $value); } } echo "\n<!-- Hidden and Data value assignments-->\n"; $x = ArraySafe($GLOBALS['AG'], 'hidden', array()); foreach ($x as $key => $value) { echo '<input type="hidden" ' . ' name="' . $key . '" id="' . $key . '" ' . ' value="' . $value . "\"/>\n"; } $x = ArraySafe($GLOBALS['AG'], 'data', array()); echo "<script language=\"javascript\" type=\"text/javascript\">\n"; foreach ($x as $key => $value) { echo "ob('" . $key . "').value='" . $value . "';\n"; } echo "</script>\n"; echo "\n<!-- Hidden and Data value assignments (END)-->\n"; }
function save() { $table_id = gp('x6page'); $dd = ddTable($table_id); $row0 = aFromGP('x6v_'); $row1 = aFromgp('x6inp_' . $table_id . '_'); $row = array_merge($row0, $row1); if (arr($row, 'skey', 0) == 0) { unset($row['skey']); } # KFD 12/20/08, prevent ui saves if dd does not allow them if (!isset($row['skey'])) { $perm = $this->uiPerm(gp('x6page'), 'ins'); if (!$perm) { x6Error("Inserts not allowed from this screen"); return; } } else { $perm = $this->uiPerm(gp('x6page'), 'upd'); if (!$perm) { x6Error("Updates not allowed from this screen"); return; } } # Add in values from parent if (gp('tableIdPar', false)) { $vals2 = $this->fetchParent(); $row = array_merge($row, $vals2); } # KFD 12/8/08, More generalized code to allow for # inserts before or after a row. # # an skeyAfter value means we must find the queuepos # column in this table, and save a value of that # column equal to +1 of the value in row skeyAfter if (gp('queuepos', '') != '') { $queuepos = gp('queuepos'); $skeyBefore = gp('skeyBefore'); $skeyAfter = gp('skeyAfter'); $skey = 0; if ($skeyBefore != -1) { $skey = $skeyBefore; } if ($skeyAfter != -1) { $skey = $skeyAfter; } if ($skey == 0) { $row[$queuepos] = 1; } else { $qpvalue = SQL_OneValue($queuepos, "Select {$queuepos} from {$dd['viewname']}\n where skey = " . sqlfc($skey)); if ($skey == $skeyAfter) { $qpvalue++; } else { $qpvalue--; } $row[$queuepos] = $qpvalue; } } # KFD 6/28/08, a non-empty date must be valid $errors = false; foreach ($row as $col => $value) { if (!isset($dd['flat'][$col])) { unset($row[$col]); continue; } $ermsg = "Invalid date format for " . $dd['flat'][$col]['description']; $ermsg2 = "Invalid date value for " . $dd['flat'][$col]['description']; if ($dd['flat'][$col]['type_id'] == 'date') { if (trim($value) == '') { continue; } if (strpos($value, '/') === false && strpos($value, '-') === false) { x6Error($ermsg); $errors = true; continue; } if (strpos($value, '/') !== false) { $parsed = explode('/', $value); if (count($parsed) != 3) { $errors = true; x6Error($ermsg); continue; } if (!checkdate($parsed[0], $parsed[1], $parsed[2])) { x6Error($ermsg2); $errors = true; continue; } } if (strpos($value, '-') !== false) { $parsed = explode('-', $value); if (count($parsed) != 3) { $errors = true; x6Error($ermsg); continue; } if (!checkdate($parsed[1], $parsed[2], $parsed[0])) { x6Error($ermsg2); $errors = true; continue; } } } } if ($errors) { return; } if (!isset($row['skey'])) { # KFD 5/26/09 Google Feature #23, hook inserts $method = $table_id . "_before_insert"; if (method_exists($this, $method)) { $row = $this->{$method}($row); } # KFD 6/8/09 Google #30, no action if returns false if ($row) { $skey = SQLX_Insert($dd, $row); if (!errors()) { $row = SQL_OneRow("Select * FROM {$dd['viewname']} WHERE skey = {$skey}"); # KFD 5/26/09 Google Feature #23, hook inserts $method = $table_id . "_after_insert"; if (method_exists($this, $method)) { $row = $this->{$method}($row); } x6Data('row', $row); } } } else { # KFD 5/26/09 Google Feature #23, hook updates $method = $table_id . "_before_update"; if (method_exists($this, $method)) { $row = $this->{$method}($row); } # KFD 6/8/09 Google #30, no action if returns false if ($row) { SQLX_Update($dd, $row); if (!errors()) { $skey = $row['skey']; $row = SQL_OneRow("Select * FROM {$dd['viewname']} WHERE skey = {$skey}"); # KFD 5/26/09 Google Feature #23, hook updates $method = $table_id . "_after_update"; if (method_exists($this, $method)) { $row = $this->{$method}($row); } x6Data('row', $row); } } } if (vgfGet('x6') == true) { if ($table_id == 'configinst') { configWrite('inst'); } if ($table_id == 'configapp') { configWrite('app'); } } }
function mainDoit() { # Take the list of group assignments and reslot # them into kills and changes. $graw = aFromgp('grp_'); $gsame = array(); $gchg = array(); foreach ($graw as $from => $to) { if ($from == $to) { $gsame[] = "'{$to}'"; } else { $gchg[$from] = $to; } } # Step 1, make sure all users exist. Pull the ones # that don't and create them $users = SQL_AllRows("\n select user_id,member_password from users\n where COALESCE(member_password,'') <> ''\n AND not exists (\n select rolname from pg_roles\n where rolname = users.user_id::name\n )"); echo "<br/>Re-creating " . count($users) . " users."; foreach ($users as $user) { $pwd = $user['member_password']; SQL("create role {$user['user_id']} login password '{$pwd}'"); } # Step 1.5 set passwords and let them login $users = SQL_AllRows("select user_id,member_password from users"); foreach ($users as $user) { $pwd = $user['member_password']; SQL("alter role {$user['user_id']} login password '{$pwd}'"); } echo "<br/>Setting passwords for " . count($users) . " users."; # Step 2, for all assignments that do not change, # explicitly grant the role $slist = implode(',', $gsame); $assigns = SQL_AllRows("Select user_id,group_id \n from usersxgroups\n WHERE group_id in ({$slist})"); $count = 0; foreach ($assigns as $assign) { $count++; SQL("grant {$assign['group_id']} to {$assign['user_id']}"); } echo "<br/>{$count} users had existing permissions re-established"; errorsClear(); # Step 3, for all assignments that change, # copy rows in usersxgroups, which also # creates the role assignment foreach ($gchg as $from => $to) { $sql = "insert into usersxgroups (user_id,group_id)\n select user_id,'{$to}' FROM usersxgroups x\n where group_id = '{$from}'\n AND user_id in (Select rolname::varchar from pg_roles)\n and not exists (\n select * from usersxgroups x \n where user_id = x.user_id\n AND group_id= '{$to}'\n )"; SQL($sql); } echo "<br/>Migrated permissions for " . count($gchg) . " groups"; # Step 4, Delete all defunct user-group assignments foreach ($gchg as $from => $to) { SQL("Delete from usersxgroups where group_id = '{$from}'"); } echo "<br/>Deleted old user-group rows for " . count($gchg) . " groups"; # Step 5, delete all defunct groups echo "<br/>Deleted " . count($gchg) . " groups from old database"; foreach ($gchg as $from => $to) { SQL("Delete from permxtables where group_id = '{$from}'"); SQL("Delete from uimenugroups where group_id = '{$from}'"); SQL("Delete from permxmodules where group_id = '{$from}'"); SQL("Delete from groups where group_id = '{$from}'"); } }
function index_hidden_ajaxsql() { switch (gp('gp_ajaxsql')) { case 'update': $row = aFromgp('txt_'); foreach ($row as $key => $value) { if ($value == 'b:true') { $row[$key] = 'Y'; } if ($value == 'b:false') { $row[$key] = 'N'; } } $table_id = gp('gp_table'); SQLX_Update($table_id, $row); break; case 'insert': $row = aFromgp('txt_'); $table_id = gp('gp_table'); // XDB SQLX_Insert($table_id, $row); break; } if (Errors()) { echo 'echo|' . hErrors(); } }