From e1ceb050e19c7574bca146a8da7047ee4ff456b5 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Sun, 10 Jul 2016 05:02:35 -0400
Subject: [PATCH] Merge branch 'stable-3.1'

---
 interface/web/sites/database_user_del.php |   50 ++++++++++++++++++++++++++++----------------------
 1 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/interface/web/sites/database_user_del.php b/interface/web/sites/database_user_del.php
index 9abcfd1..379a9a1 100644
--- a/interface/web/sites/database_user_del.php
+++ b/interface/web/sites/database_user_del.php
@@ -39,8 +39,8 @@
 * End Form configuration
 ******************************************/
 
-require_once('../../lib/config.inc.php');
-require_once('../../lib/app.inc.php');
+require_once '../../lib/config.inc.php';
+require_once '../../lib/app.inc.php';
 
 //* Check permissions for module
 $app->auth->check_module_permissions('sites');
@@ -50,29 +50,35 @@
 class page_action extends tform_actions {
 	function onBeforeDelete() {
 		global $app; $conf;
-		if($app->tform->checkPerm($this->id,'d') == false) $app->error($app->lng('error_no_delete_permission'));
-        
-        $old_record = $app->tform->getDataRecord($this->id);
-        $app->db->datalogDelete('web_database_user', 'database_user_id', $this->id);
-    }
-    
-    function onAfterDelete() { // this has to be done on AFTER delete, because we need the db user still in the database when the server plugin processes the datalog
-		global $app; $conf;
-		
-		//* Update all records that belog to this user
-        $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = '".$app->functions->intval($this->id)."'");
-        foreach($records as $rec) {
-            $app->db->datalogUpdate('web_database','database_user_id=NULL','database_id', $rec['database_id']);
-            
-        }
-        $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = '".$app->functions->intval($this->id)."'");
-        foreach($records as $rec) {
-            $app->db->datalogUpdate('web_database','database_ro_user_id=NULL','database_id', $rec['database_id']);
-        }
+		if($app->tform->checkPerm($this->id, 'd') == false) $app->error($app->lng('error_no_delete_permission'));
+
+		$old_record = $app->tform->getDataRecord($this->id);
+
+		/* we cannot use datalogDelete here, as we need to set server_id to 0 */
+		$app->db->query("DELETE FROM `web_database_user` WHERE `database_user_id` = ?", $this->id);
+		$new_rec = array();
+		$old_record['server_id'] = 0;
+		$app->db->datalogSave('web_database_user', 'DELETE', 'database_user_id', $this->id, $old_record, $new_rec);
 	}
+
+	function onAfterDelete() { // this has to be done on AFTER delete, because we need the db user still in the database when the server plugin processes the datalog
+		global $app; $conf;
+
+		//* Update all records that belog to this user
+		$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = ?", $this->id);
+		foreach($records as $rec) {
+			$app->db->datalogUpdate('web_database', array('database_user_id' => null), 'database_id', $rec['database_id']);
+
+		}
+		$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = ?", $this->id);
+		foreach($records as $rec) {
+			$app->db->datalogUpdate('web_database', array('database_ro_user_id' => null), 'database_id', $rec['database_id']);
+		}
+	}
+
 }
 
 $page = new page_action;
 $page->onDelete();
 
-?>
\ No newline at end of file
+?>

--
Gitblit v1.9.1