Add support for popup editing inside a live grid
[infodrom/hallinta] / ajax / ajax.php
index 5a7a1ec..2b84c0b 100644 (file)
@@ -528,6 +528,56 @@ function process_file($mask)
   exit;
 }
 
+function process_listedit($mask, $action)
+{
+  global $db;
+
+  if ($_REQUEST['second'] === true)
+    $list = $mask['second'];
+  else
+    $list = $mask['list'];
+
+  $values = array();
+  foreach ($_POST as $k => $v)
+    if (substr($k,0,10) == 'listinput_')
+      $values[substr($k,10)] = $v;
+
+  switch ($action) {
+  case 'upd':
+    $update = sprintf("sys_user='%s', sys_edit=now()", $_SESSION['sys']['login']);
+    foreach ($values as $c => $v)
+      $update .= sprintf(", %s = '%s'", $c, $v);
+    $sql = sprintf("UPDATE %s SET %s WHERE id = %d",
+                  $list['table_edit'],
+                  $update,
+                  $_POST['_k0']);
+
+    $db->query($sql);
+    break;
+  }
+}
+
+if (!empty($_REQUEST['_k0'])) {
+  db_connect();
+
+  foreach ($_POST as $k => $v)
+    if (substr($k,0,5) == 'grid_' && substr($k,-8) == '__action') {
+      $_REQUEST['source'] = substr($k,5,-8);
+      $action = $v;
+    }
+
+  if (substr($_REQUEST['source'],-8) == '__second') {
+    $_REQUEST['source'] = substr($_REQUEST['source'],0,-8);
+    $_REQUEST['second'] = true;
+  } else {
+    $_REQUEST['second'] = false;
+  }
+
+  if (load_mask($_REQUEST['source']) === false) exit;
+  process_listedit($mask, $action);
+  exit;
+}
+
 if (empty($_REQUEST['func']))
   exit;