Move real deletion into function, allow external deletion function
authorJoey Schulze <joey@infodrom.org>
Thu, 13 May 2010 19:28:58 +0000 (21:28 +0200)
committerJoey Schulze <joey@infodrom.org>
Thu, 13 May 2010 19:28:58 +0000 (21:28 +0200)
ajax/ajax.php

index 18d3177..5b52733 100644 (file)
@@ -197,22 +197,11 @@ function insert($mask)
   return array('status' => true);
 }
 
   return array('status' => true);
 }
 
-function delete_or_copy($mask)
+function delete_or_copy_row($table,$id)
 {
 {
-  if (empty($_POST['id']))
-    return array('error' => 'Missing ID');
-
-  if (!empty($mask['edit_table']))
-    return array('error' => 'Cannot handle deletion for secondary table');
-
-  if (!empty($_POST['table']) && is_array($mask['tables_delete']) && in_array($_POST['table'], $mask['tables_delete']))
-    $table = $_POST['table'];
-  else
-    $table = $mask['table'];
-
   if (DELETE_COPY === true) {
     $sql = sprintf("INSERT INTO %s_deleted SELECT * FROM %s WHERE id = %d",
   if (DELETE_COPY === true) {
     $sql = sprintf("INSERT INTO %s_deleted SELECT * FROM %s WHERE id = %d",
-                  $table, $table, $_POST['id']);
+                  $table, $table, $id);
 
     $sth = pg_query($sql);
 
 
     $sth = pg_query($sql);
 
@@ -223,7 +212,7 @@ function delete_or_copy($mask)
     }
 
     $sql = sprintf("UPDATE %s_deleted SET sys_user='%s',sys_edit=now() WHERE id = %d",
     }
 
     $sql = sprintf("UPDATE %s_deleted SET sys_user='%s',sys_edit=now() WHERE id = %d",
-                  $table, $_SESSION['sys']['login'], $_POST['id']);
+                  $table, $_SESSION['sys']['login'], $id);
 
     $sth = pg_query($sql);
 
 
     $sth = pg_query($sql);
 
@@ -247,6 +236,20 @@ function delete_or_copy($mask)
   return array('status' => true);
 }
 
   return array('status' => true);
 }
 
+function delete_or_copy($mask)
+{
+  if (empty($_POST['id']))
+    return array('error' => 'Missing ID');
+
+  if (array_key_exists('delete', $mask))
+    return $mask['delete']($mask);
+
+  if (!empty($mask['edit_table']))
+    return array('error' => 'Cannot handle deletion for secondary table');
+
+  return delete_or_copy_row($mask['table'],$_POST['id']);
+}
+
 function set_variable($name,$mask)
 {
   if (!array_key_exists('variables',$mask))
 function set_variable($name,$mask)
 {
   if (!array_key_exists('variables',$mask))