Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. // We have 'tasks' table with PK 'sno'.
  2.  
  3. $e["on_update"] = array("log_data", null, true);
  4. $e["on_insert"] = array("log_data", null, true);
  5. $e["on_delete"] = array("log_data", null, true);
  6. $grid->set_events($e);
  7.  
  8. function log_data($data)
  9. {
  10.     $rs = mysql_fetch_assoc(mysql_query("SELECT * FROM tasks WHERE sno = {$data[sno]}"));
  11.     $data["old"] = $rs;
  12.    
  13.     if ($_POST["oper"] == "add") $oper = "Added";
  14.     else if ($_POST["oper"] == "edit") $oper = "Updated";
  15.     else if ($_POST["oper"] == "del") $oper = "Deleted";
  16.  
  17.     // here $data = new data, $data["old"] = old data and $oper is operation.
  18.    
  19.     $change_str = "";
  20.     if (!empty($data["old"]))
  21.     {
  22.         // changelog track
  23.         $changes = array();
  24.         foreach ($data["params"] as $k=>$v)
  25.             foreach ($data["old"] as $ok => $ov)
  26.                 if ($k == $ok && $v != $ov)
  27.                 {
  28.                     $ov = empty($ov) ? "(blank)" : $ov;
  29.                     $changes[] = "$k: $ov -> $v";
  30.                 }
  31.         $change_str = implode(", ",$changes);
  32.     }
  33.    
  34.     // execute the logging query
  35. }
  36.  
  37. // Note that with on_delete event, you only get $data["sno"] and no new data (due to obvious reason)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement