From 4e33d088badc961849ece7367170245e97c58d1c 2017-06-21 01:58:29 From: DarkMorford Date: 2017-06-21 01:58:29 Subject: [PATCH] Convert adminlog function to DBAL. --- diff --git a/include/error.php b/include/error.php index 3d6dc52..b9ad7d3 100644 --- a/include/error.php +++ b/include/error.php @@ -13,8 +13,7 @@ define('MTS_TYPE_META', 8); // Changes in the metatype manager define('MTS_TUMBLR', 10); - -define('MTA_ADD', 'create'); // Creation action +define('MTA_ADD', 'create'); // Creation action define('MTA_INSERT', 'create'); // Creation action define('MTA_DELETE', 'delete'); // Deletion action define('MTA_REMOVE', 'delete'); // Deletion action @@ -24,21 +23,29 @@ define('MTA_CHANGE', 'update'); // Modification action function adminlog($msg, $section, $action, $level=E_USER_NOTICE, $email=false) { - global $mtdb, $currentuser; + global $dbConnection, $currentuser; - $sql = sprintf('INSERT INTO admin_log (contributor, section, action, level, message) VALUES (%s, %d, "%s", %d, "%s")', - (is_numeric($currentuser->id) ? $currentuser->id : "NULL"), $section, mysqli_real_escape_string($mtdb->link, $action), $level, mysqli_real_escape_string($mtdb->link, $msg)); - $mtdb->query( $sql ) or die($sql."
".mysqli_error($mtdb->link)."
\n".var_export(debug_backtrace())); + $sql = 'INSERT INTO admin_log (contributor, section, action, level, message) VALUES (?, ?, ?, ?, ?)'; + $stmt = $dbConnection->prepare($sql); + $stmt->bindValue(1, is_numeric($currentuser->id) ? $currentuser->id : 'NULL'); + $stmt->bindValue(2, $section); + $stmt->bindValue(3, $action); + $stmt->bindValue(4, $level); + $stmt->bindValue(5, $msg); + $stmt->execute() or die($sql . '
' . $stmt->errorCode() . '
' . var_export(debug_backtrace())); // Log all important sorts of messages in the Apache log - if( $level & (E_USER_WARNING | E_USER_ERROR) ) { + if( $level & (E_USER_WARNING | E_USER_ERROR) ) + { error_log($msg, 0); } // Email critical messages and those for which email is requested - if($email || E_USER_ERROR == $level || E_ERROR == $level) { + if($email || E_USER_ERROR == $level || E_ERROR == $level) + { // Pretty printing - switch($level) { + switch($level) + { case E_USER_NOTICE: case E_NOTICE: $importance = 'Notice'; @@ -56,7 +63,8 @@ function adminlog($msg, $section, $action, $level=E_USER_NOTICE, $email=false) break; } - switch($section) { + switch($section) + { case MTS_LOGIN: $area = 'User login'; break; case MTS_USER: $area = 'Modify user'; break; case MTS_PAGE: $area = 'Modify page'; break;