[AppDB] Enable admins to view error logs online
Rosanne DiMesio
dimesio at earthlink.net
Thu Aug 10 10:08:40 CDT 2017
Removes the unused function to email admins error log entries
and adds functions needed to view them online in the admin control center.
Signed-off-by: Rosanne DiMesio <dimesio at earthlink.net>
---
admin.php | 8 ++-
include/error_log.php | 133 ++++++++++++++++++++++++++++++++++----------------
2 files changed, 97 insertions(+), 44 deletions(-)
diff --git a/admin.php b/admin.php
index b608019..5f89a4b 100644
--- a/admin.php
+++ b/admin.php
@@ -327,7 +327,9 @@ function showChoices()
echo '<a href="admin.php?sAction=purgeRejectedVendors" class="list-group-item"><h4>Purge rejected vendors</h4></a>';
- echo '<a href="admin.php?sAction=deleteOldErrorLogs" class="list-group-item"><h4>Delete Old Error Logs</h4></a>';
+ echo '<a href="admin.php?sAction=deleteOldErrorLogs" class="list-group-item"><h4>Delete old error logs</h4></a>';
+
+ echo '<a href ="'.BASE.'objectManager.php?sClass=error_log&sTitle=View+Error_log" class="list-group-item"><h4>View Error log entries</h4></a>';
echo '<a href="admin.php?sAction=updateVersionRatings" class="list-group-item"><h4>Update version ratings</h4></a>';
@@ -372,6 +374,10 @@ switch(getInput('sAction', $aClean))
case 'deleteOldErrorLogs':
deleteOldErrorLogs();
break;
+
+ case 'viewErrorLogEntries';
+ viewErrorLogEntries();
+ break;
case 'updateVersionRatings':
updateVersionRatings();
diff --git a/include/error_log.php b/include/error_log.php
index 73ea208..379e91c 100644
--- a/include/error_log.php
+++ b/include/error_log.php
@@ -41,17 +41,9 @@ class error_log
ob_end_clean();
error_log::log_error("general_error", $sDescription.' '.$sDebugOutput);
- }
-
- function getEntryCount()
- {
- $sQuery = "SELECT count(*) as cnt FROM error_log WHERE deleted = '0'";
- $hResult = query_parameters($sQuery);
- $oRow = query_fetch_object($hResult);
- return $oRow->cnt;
- }
-
- /* purge all of the current entries from the error log */
+ }
+
+ /* mark all of the current entries as deleted */
function flush()
{
$sQuery = "UPDATE error_log SET deleted='1'";
@@ -61,43 +53,98 @@ class error_log
else return false;
}
- function mail_admins_error_log($sSubject = "")
+ function objectGetId()
{
- $sSubject .= "Database Error log\r\n";
- $sEmail = user::getAdminEmails(); /* get list admins */
-
- $sQuery = "SELECT * from error_log WHERE deleted='0' ORDER BY submitTime";
- $hResult = query_parameters($sQuery);
-
- $bEmpty = false;
- if(query_num_rows($hResult) == 0)
- $bEmpty = true;
-
- $sMsg = "Log entries:\r\n";
- $sMsg.= "\r\n";
+ return $this->iId;
+ }
+
+ function objectGetState()
+ {
+ return 'accepted';
+ }
+
+ public function objectGetHeader()
+ {
+ return $oRow;
+ }
+
+ public function canEdit()
+ {
+ return $_SESSION['current']->hasPriv('admin');
+ }
+
+ function objectWantCustomDraw()
+ {
+ return true;
+ }
- $sMsg.= "Submit time userid type\r\n";
- $sMsg.= "log_text\r\n";
- $sMsg.= "request_text\r\n";
- $sMsg.="----------------------------------\r\n\r\n";
+ public function objectGetTableRow()
+ {
+ return $oRow;
+ }
- /* append each log entry to $sMsg */
+ public function objectDrawCustomTable($hResult)
+ {
+ echo html_frame_start("Error Log Entries","100%","",0);
+ echo '<table width="100%" border=0 cellpadding=3 cellspacing=0>';
+ echo '<tr class=color1>';
+ echo '<td>Id</td>';
+ echo '<td>Submit time</td>';
+ echo '<td>UserId</td>';
+ echo '<td>Type</td>';
+ echo '<td>Log text</td>';
+ echo '<td>Request text</td>';
+ echo '</tr>';
+
+ $i = 0;
while($oRow = query_fetch_object($hResult))
{
- $sMsg.=$oRow->submitTime." ".$oRow->userid." ".$oRow->type."\r\n";
- $sMsg.= "---------------------\r\n";
- $sMsg.=$oRow->log_text."\r\n";
- $sMsg.= "---------------------\r\n";
- $sMsg.=$oRow->request_text."\r\n\r\n";
- }
-
- /* if we had no entries we should indicate */
- /* that the error log is empty */
- if($bEmpty)
- $sMsg = "The error log is empty.\r\n";
-
- if($sEmail)
- mail_appdb($sEmail, $sSubject, $sMsg);
+ echo '<tr class=color0>';
+ echo '<td>'.$oRow->id.'</td>';
+ echo '<td>'.$oRow->submitTime.'</td>';
+ echo '<td>'.$oRow->userid.'</td>';
+ echo '<td>'.$oRow->type.'</td>';
+ echo '<td>'.$oRow->log_text.'</td>';
+ echo '<td>'.$oRow->request_text.'</td>';
+ $i++;
+ }
+ echo '</table>';
+ echo html_frame_end();
+
+ echo "Found $i entries. <br>";
+ }
+
+ function objectGetItemsPerPage($sState = 'accepted')
+ {
+ $aItemsPerPage = array(25, 50, 100, 200);
+ $iDefaultPerPage = 25;
+ return array($aItemsPerPage, $iDefaultPerPage);
+ }
+
+ public function objectGetEntries($sState, $iRows = null, $iStart = 0)
+ {
+ if(!$_SESSION['current']->hasPriv('admin'))
+ return false;
+
+ $sLimit = objectManager::getSqlLimitClause($iRows, $iStart, 'error_log');
+
+ $sQuery = "SELECT * FROM error_log ORDER BY id DESC $sLimit";
+ $hResult = query_parameters($sQuery);
+
+ return $hResult;
+ }
+
+ function objectGetEntriesCount()
+ {
+ $sQuery = "SELECT COUNT(DISTINCT id) as count FROM error_log";
+ $hResult = query_parameters($sQuery);
+
+ if(!$hResult)
+ return $hResult;
+
+ $oRow = query_fetch_object($hResult);
+
+ return $oRow->count;
}
}
--
2.12.3
More information about the wine-patches
mailing list