Changeset 816 for trunk/Modules/Log
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Log/Log.php
r808 r816 3 3 class ModuleLog extends AppModule 4 4 { 5 6 5 var $Excludes; 6 7 7 function __construct($System) 8 8 { … … 14 14 $this->Description = 'Log various application events'; 15 15 $this->Dependencies = array('Error', 'News'); 16 16 17 17 $this->Excludes = array(); 18 18 } 19 19 20 20 function Start() 21 21 { 22 23 24 $this->System->ModuleManager->Modules['News']->RegisterRSS(array('Title' => T('Logs'),25 26 } 27 22 $this->System->RegisterPage('log.php', 'PageLog'); 23 $this->System->ModuleManager->Modules['Error']->OnError[] = array($this, 'DoAddItem'); 24 $this->System->ModuleManager->Modules['News']->RegisterRSS(array('Title' => T('Logs'), 25 'Channel' => 'log', 'Callback' => array('PageLog', 'ShowRSS'), 'Permission' => LICENCE_ADMIN)); 26 } 27 28 28 function DoAddItem($Message) 29 29 { 30 30 $this->WriteLog($Message, LOG_TYPE_ERROR); 31 31 } 32 32 33 33 function WriteLog($Text, $Type) 34 34 { 35 if(isset($this->System->User) and !is_null($this->System->User->Id))36 37 38 39 40 41 35 if(isset($this->System->User) and !is_null($this->System->User->Id)) 36 $UserId = $this->System->User->Id; 37 else $UserId = 'NULL'; 38 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP`, `URL` ) '. 39 'VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'. 40 GetRemoteAddress().'", "'.GetRequestURI().'")'; 41 $this->System->Database->query($Query); 42 42 } 43 43 } … … 55 55 define('LOG_TYPE_PAGE_NOT_FOUND', 15); 56 56 57 // TODO: Change global function to module class local method 57 // TODO: Change global function to module class local method 58 58 function WriteLog($Text, $Type) 59 59 { 60 61 62 63 64 65 60 global $System, $User; 61 62 if(isset($User) and !is_null($User->Id)) $UserId = $User->Id; 63 else $UserId = 'NULL'; 64 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP`, `URL` ) '. 65 'VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'. 66 66 GetRemoteAddress().'", "'.GetRequestURI().'")'; 67 67 $System->Database->query($Query); 68 68 } 69 69 … … 72 72 function ShowRSS() 73 73 { 74 75 74 $this->RawPage = true; 75 $Output = ''; 76 76 $Items = array(); 77 if(array_key_exists('type', $_GET)) $Where = ' WHERE `Type` = "'.($_GET['type'] * 1).'"'; 77 if(array_key_exists('type', $_GET)) $Where = ' WHERE `Type` = "'.($_GET['type'] * 1).'"'; 78 78 else $Where = ''; 79 79 $sql = 'SELECT *, UNIX_TIMESTAMP(`Date`) AS `TimeCreate`, (SELECT `User`.`Name` FROM `User` WHERE `User`.`ID` = `Log`.`User`) AS `UserName`, `Date` FROM `Log`'. 80 80 $Where.' ORDER BY `Date` DESC LIMIT 100'; 81 81 $DbResult = $this->System->Database->query($sql); 82 while($Line = $DbResult->fetch_assoc()) 82 while($Line = $DbResult->fetch_assoc()) 83 83 { 84 84 $DbResult2 = $this->System->Database->query('SELECT * FROM `LogType` WHERE `Id`='.$Line['Type']); 85 85 $LogType = $DbResult2->fetch_assoc(); 86 86 87 87 if($Line['Type'] == LOG_TYPE_ERROR) $Line['Text'] = htmlspecialchars($Line['Text']); 88 88 $Line['Text'] = str_replace("\n", '<br>', $Line['Text']); 89 89 90 90 $Items[] = array 91 91 ( … … 96 96 'Time' => $Line['TimeCreate'], 97 97 ); 98 } 98 } 99 99 100 100 $Output .= GenerateRSS(array … … 108 108 return($Output); 109 109 } 110 110 111 111 function Show() 112 112 { 113 114 115 else $Action = ''; 116 117 118 119 } 120 113 if(array_key_exists('a', $_POST)) $Action = $_POST['a']; 114 else if(array_key_exists('a', $_GET)) $Action = $_GET['a']; 115 else $Action = ''; 116 if($Action == 'delerrlog') $Output = $this->DeleteErrorLog(); 117 else $Output = $this->ShowList(); 118 return($Output); 119 } 120 121 121 function ShowList() 122 122 { 123 123 global $TranslationTree; 124 124 125 125 $this->Title = T('System log'); 126 126 $Output = ''; 127 if(array_key_exists('type', $_GET)) $_SESSION['type'] = $_GET['type'] * 1; 127 if(array_key_exists('type', $_GET)) $_SESSION['type'] = $_GET['type'] * 1; 128 128 else if(!array_key_exists('type', $_SESSION)) $_SESSION['type'] = ''; 129 129 130 130 if(array_key_exists('group', $_GET)) $_SESSION['group'] = $_GET['group']; 131 131 132 if($_SESSION['type'] != '') $WhereType = ' (`Type`='.$_SESSION['type'].')'; 132 if($_SESSION['type'] != '') $WhereType = ' (`Type`='.$_SESSION['type'].')'; 133 133 else $WhereType = '1=1'; 134 134 135 135 $RSSChannels = array( 136 136 array('Title' => 'Záznamy změn', 'Channel' => 'log&type='.$_SESSION['type']) 137 137 ); 138 138 139 139 // Show category filter 140 140 if($this->System->User->Licence(LICENCE_MODERATOR)) … … 154 154 $Output .= '<br /><br />'; 155 155 156 if(array_key_exists('type', $_SESSION)) $Where = ' WHERE '.$WhereType; 156 if(array_key_exists('type', $_SESSION)) $Where = ' WHERE '.$WhereType; 157 157 else 158 158 { 159 159 if(array_key_exists('group', $_SESSION)) $Where = ' WHERE `Text` LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 160 160 else $Where = ''; 161 } 161 } 162 162 //if(($Where != '') and (array_key_exists('group', $_SESSION))) $Where .= ' AND text LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 163 163 164 164 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Log` '.$Where); 165 165 $DbRow = $DbResult->fetch_row(); 166 $PageList = GetPageList($DbRow[0]); 167 166 $PageList = GetPageList($DbRow[0]); 167 168 168 $Output .= $PageList['Output']; 169 169 170 170 $TableColumns = array( 171 171 array('Name' => 'Date', 'Title' => 'Čas'), 172 172 ); 173 if($_SESSION['type'] == '') $TableColumns[] = 173 if($_SESSION['type'] == '') $TableColumns[] = 174 174 array('Name' => 'LogName', 'Title' => 'Typ'); 175 $TableColumns = array_merge($TableColumns, array( 176 array('Name' => 'Text', 'Title' => 'Text'),177 array('Name' => 'UserName', 'Title' => 'Uživatel'), 178 array('Name' => 'IP', 'Title' => 'Adresa'), 175 $TableColumns = array_merge($TableColumns, array( 176 array('Name' => 'Text', 'Title' => 'Text'), 177 array('Name' => 'UserName', 'Title' => 'Uživatel'), 178 array('Name' => 'IP', 'Title' => 'Adresa'), 179 179 array('Name' => 'URL', 'Title' => 'URL'), 180 180 )); … … 182 182 $Output .= '<table width="98%" class="BaseTable">'. 183 183 $Order['Output']; 184 184 185 185 $sql = 'SELECT *, `LogType`.`Color` AS `LogColor`, `LogType`.`Name` AS `LogName`, '. 186 186 '(SELECT `User`.`Name` FROM `User` WHERE `User`.`ID` = `Log`.`User`) AS `UserName` FROM `Log` LEFT JOIN `LogType` ON `LogType`.`Id`=`Log`.`Type` '.$Where.$Order['SQL'].$PageList['SQLLimit']; 187 187 $DbResult = $this->System->Database->query($sql); 188 while($Line = $DbResult->fetch_assoc()) 189 { 190 188 while($Line = $DbResult->fetch_assoc()) 189 { 190 if($Line['Type'] == LOG_TYPE_ERROR) $Line['Text'] = htmlspecialchars($Line['Text']); 191 191 $Line['Text'] = str_replace("\n", '<br>', $Line['Text']); 192 193 192 $Output .= '<tr><td>'.$Line['Date'].'</td>'; 193 if($_SESSION['type'] == '') $Output .= '<td>'.$Line['LogName'].'</td>'; 194 194 $Output .= '<td><span style="color: '.$Line['LogColor'].'">'.$Line['Text'].'</span></td>'. 195 195 '<td><a href="'.$this->System->Link('/user.php?user='.$Line['User']).'">'.$Line['UserName'].'</a></td>'. 196 196 '<td>'.$Line['IP'].'</td>'. 197 197 '<td>'.$Line['URL'].'</td></tr>'; 198 198 } 199 199 $Output .= '</table>'. … … 203 203 $Output .= '<div>Vymazat: <a href="'.$this->System->Link('/log.php?a=delerrlog&type='.LOG_TYPE_ERROR).'">Chybové záznamy</a> '. 204 204 '<a href="'.$this->System->Link('/log.php?a=delerrlog&type='.LOG_TYPE_PAGE_NOT_FOUND).'">Neznámé stránky</a></div>'; 205 } 205 } 206 206 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 207 208 return($Output); 209 } 210 207 208 return($Output); 209 } 210 211 211 function DeleteErrorLog() 212 212 { 213 if($this->System->User->Licence(LICENCE_ADMIN) and214 215 216 217 218 219 220 221 222 223 224 225 213 if($this->System->User->Licence(LICENCE_ADMIN) and 214 (($_GET['type'] == LOG_TYPE_ERROR) or ($_GET['type'] == LOG_TYPE_PAGE_NOT_FOUND))) 215 { 216 $DbResult = $this->System->Database->select('LogType', '*', 'Id='.$_GET['type']); 217 $LogType = $DbResult->fetch_assoc(); 218 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Log` WHERE `Type`='.$_GET['type']); 219 $DbRow = $DbResult->fetch_row(); 220 $this->System->Database->query('DELETE FROM `Log` WHERE `Type`='.$_GET['type']); 221 $this->System->ModuleManager->Modules['Log']->WriteLog('Vymazáno záznamů z '.$LogType['Description'].'.', LOG_TYPE_ADMINISTRATION); 222 $Output = ShowMessage('Smazáno všech '.$DbRow[0].' záznamů z '.$LogType['Description'].'.'); 223 $Output .= $this->ShowList(); 224 return($Output); 225 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 226 226 } 227 227 }
Note:
See TracChangeset
for help on using the changeset viewer.