+ foreach($_POST as $postkey=>$postval )
+ {
+ if (strpos($postkey, $prefix) === 0)
+ {
+ $id = substr($postkey, strlen($prefix));
+ return $numeric ? (int)$id : $id;
+ }
+ }
+ return $numeric ? -1 : null;
+}
+//------------------------------------------------------------------------------
+//
+// Helper function for simple db table editor pages
+//
+function simple_page_mode($numeric_id = true)
+{
+ global $Ajax, $Mode, $selected_id;
+
+ $default = $numeric_id ? -1 : '';
+ $selected_id = get_post('selected_id', $default);
+ foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET') as $m) {
+ if (isset($_POST[$m])) {
+ $Ajax->activate('_page_body');
+ if ($m == 'RESET')
+ $selected_id = $default;
+ $Mode = $m; return;
+ }
+ }
+ foreach (array('Edit', 'Delete') as $m) {
+ foreach ($_POST as $p => $pvar) {
+ if (strpos($p, $m) === 0) {
+// $selected_id = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
+ unset($_POST['_focus']); // focus on first form entry
+ $selected_id = quoted_printable_decode(substr($p, strlen($m)));
+ $Ajax->activate('_page_body');
+ $Mode = $m;
+ return;
+ }
+ }
+ }
+ $Mode = '';
+}