Changeset 566 for trunk/Modules/Log
- Timestamp:
- Aug 20, 2013, 11:37:30 PM (11 years ago)
- Location:
- trunk/Modules/Log
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Log/Log.php
r564 r566 1 1 <?php 2 2 3 include_once('includes/global.php'); 3 class ModuleLog extends AppModule 4 { 5 var $Excludes; 6 7 function __construct($System) 8 { 9 parent::__construct($System); 10 $this->Name = 'Log'; 11 $this->Version = '1.0'; 12 $this->Creator = 'Chronos'; 13 $this->License = 'GNU/GPL'; 14 $this->Description = 'Log various application events'; 15 $this->Dependencies = array(); 16 17 $this->Excludes = array(); 18 } 19 20 function Start() 21 { 22 $this->System->RegisterPage('log.php', 'PageLog'); 23 } 24 } 4 25 5 $Output = ''; 6 if(array_key_exists('rss', $_GET)) 26 function WriteLog($Text, $Type) 7 27 { 8 $Items = array(); 9 if(array_key_exists('type', $_GET)) $Where = ' WHERE `Type` = "'.($_GET['type'] * 1).'"'; 10 else $Where = ''; 11 $sql = 'SELECT *, UNIX_TIMESTAMP(`Date`) AS `TimeCreate`, (SELECT `User`.`Name` FROM `User` WHERE `User`.`ID` = `Log`.`User`) AS `UserName` FROM `Log`'.$Where.' ORDER BY `Date` DESC LIMIT 100'; 12 $DbResult = $System->Database->query($sql); 13 while($Line = $DbResult->fetch_assoc()) 28 global $System, $User; 29 30 if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole'; 31 else $IP = addslashes($_SERVER['REMOTE_ADDR']); 32 33 if(!is_null($User->Id)) $UserId = $User->Id; 34 else $UserId = 'NULL'; 35 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP` ) 36 VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'")'; 37 $System->Database->query($Query); 38 } 39 40 class PageLog extends Page 41 { 42 function ShowRSS() 14 43 { 15 $DbResult2 = $System->Database->query('SELECT * FROM `LogType` WHERE `Id`='.$Line['Type']); 16 $LogType = $DbResult2->fetch_assoc(); 44 $this->RawPage = true; 45 $Output = ''; 46 $Items = array(); 47 if(array_key_exists('type', $_GET)) $Where = ' WHERE `Type` = "'.($_GET['type'] * 1).'"'; 48 else $Where = ''; 49 $sql = 'SELECT *, UNIX_TIMESTAMP(`Date`) AS `TimeCreate`, (SELECT `User`.`Name` FROM `User` WHERE `User`.`ID` = `Log`.`User`) AS `UserName` FROM `Log`'.$Where.' ORDER BY `Date` DESC LIMIT 100'; 50 $DbResult = $this->System->Database->query($sql); 51 while($Line = $DbResult->fetch_assoc()) 52 { 53 $DbResult2 = $this->System->Database->query('SELECT * FROM `LogType` WHERE `Id`='.$Line['Type']); 54 $LogType = $DbResult2->fetch_assoc(); 55 56 if($Line['Type'] == LOG_TYPE_ERROR) $Line['Text'] = htmlspecialchars($Line['Text']); 57 $Line['Text'] = str_replace("\n", '<br>', $Line['Text']); 17 58 18 $Items[] = array 59 $Items[] = array 60 ( 61 'Title' => $LogType['Name'].' ('.$Line['UserName'].', '.$Line['IP'].')', 62 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/log.php'), 63 'Description' => $LogType['Name'].': '.$Line['Text'].' ('.$Line['UserName'].', '.$Line['IP'].')', 64 'Time' => $Line['TimeCreate'], 65 ); 66 } 67 68 $Output .= GenerateRSS(array 19 69 ( 20 'Title' => strip_tags($LogType['Name'].': '.$Line['Text'].' ('.$Line['UserName'].', '.$Line['IP'].')'), 21 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/log.php'), 22 'Description' => $LogType['Name'].': '.$Line['Text'].' ('.$Line['UserName'].', '.$Line['IP'].')', 23 'Time' => $Line['TimeCreate'], 70 'Title' => $this->System->Config['Web']['Title'], 71 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'), 72 'Description' => $this->System->Config['Web']['Title'], 73 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'], 74 'Items' => $Items, 75 )); 76 return($Output); 77 } 78 79 function Show() 80 { 81 if(array_key_exists('a', $_POST)) $Action = $_POST['a']; 82 else if(array_key_exists('a', $_GET)) $Action = $_GET['a']; 83 else $Action = ''; 84 if($Action == 'rss') $Output = $this->ShowRSS(); 85 if($Action == 'delerrlog') $Output = $this->DeleteErrorLog(); 86 else $Output = $this->ShowList(); 87 return($Output); 88 } 89 90 function ShowList() 91 { 92 global $TranslationTree; 93 94 $Output = ''; 95 if(array_key_exists('type', $_GET)) $_SESSION['type'] = $_GET['type'] * 1; 96 else if(!array_key_exists('type', $_SESSION)) $_SESSION['type'] = ''; 97 98 if(array_key_exists('group', $_GET)) $_SESSION['group'] = $_GET['group']; 99 100 if($_SESSION['type'] != '') $WhereType = ' `Type`='.$_SESSION['type']; 101 else $WhereType = '1=1'; 102 103 $RSSChannels = array( 104 array('Title' => 'Záznamy změn', 'Channel' => 'log&type='.$_SESSION['type']) 24 105 ); 25 } 106 107 if($this->System->User->Licence(LICENCE_MODERATOR)) 108 { 109 $Output = '<strong>Filtr: </strong>'. 110 '<span style="color:black"><a href="log.php?type=" title="Bez filtrování">Všechny</a></span> '; 111 $DbResult = $this->System->Database->query('SELECT * FROM `LogType`'); 112 while($LogType = $DbResult->fetch_assoc()) 113 { 114 $Output .= '<a href="log.php?type='.$LogType['Id'].'" style="color:'.$LogType['Color'].'" title="'.$LogType['Name'].'">'.$LogType['Name'].'</a> '; 115 } 116 // echo ' Formát: datum: text zprávy (uživatel, IP)<br /><br />'; 117 $Output .= '<br /><br />'; 26 118 27 $Output .= GenerateRSS(array 28 ( 29 'Title' => $Config['Web']['Title'], 30 'Link' => 'http://'.$Config['Web']['Host'].$System->Link('/'), 31 'Description' => $Config['Web']['Title'], 32 'WebmasterEmail' => $Config['Web']['AdminEmail'], 33 'Items' => $Items, 34 )); 35 echo($Output); 36 } else 37 { 38 if(array_key_exists('type', $_GET)) $_SESSION['type'] = $_GET['type'] * 1; 39 else if(!array_key_exists('type', $_SESSION)) $_SESSION['type'] = ''; 119 if(array_key_exists('type', $_SESSION)) $Where = ' WHERE '.$WhereType; 120 else 121 { 122 if(array_key_exists('group', $_SESSION)) $Where = ' WHERE `Text` LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 123 else $Where = ''; 124 } 125 //if(($Where != '') and (array_key_exists('group', $_SESSION))) $Where .= ' AND text LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 40 126 41 if(array_key_exists('group', $_GET)) $_SESSION['group'] = $_GET['group']; 42 43 if($_SESSION['type'] != '') $WhereType = ' `Type`='.$_SESSION['type']; 44 else $WhereType = '1=1'; 45 46 $RSSChannels = array( 47 array('Title' => 'Záznamy změn', 'Channel' => 'log&type='.$_SESSION['type']) 48 ); 127 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Log` '.$Where); 128 $DbRow = $DbResult->fetch_row(); 129 $PageList = GetPageList($DbRow[0]); 49 130 50 if($User->Licence(LICENCE_MODERATOR)) 131 $Output .= $PageList['Output']; 132 133 $TableColumns = array( 134 array('Name' => 'Date', 'Title' => 'Čas'), 135 array('Name' => 'LogName', 'Title' => 'Typ'), 136 array('Name' => 'Text', 'Title' => 'Text'), 137 array('Name' => 'UserName', 'Title' => 'Uživatel'), 138 array('Name' => 'IP', 'Title' => 'Adresa'), 139 ); 140 $Order = GetOrderTableHeader($TableColumns, 'date', 1); 141 $Output .= '<table width="98%" class="BaseTable">'. 142 $Order['Output']; 143 144 $sql = 'SELECT *, `LogType`.`Color` AS `LogColor`, `LogType`.`Name` AS `LogName`, '. 145 '(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']; 146 $DbResult = $this->System->Database->query($sql); 147 while($Line = $DbResult->fetch_assoc()) 148 { 149 if($Line['Type'] == LOG_TYPE_ERROR) $Line['Text'] = htmlspecialchars($Line['Text']); 150 $Line['Text'] = str_replace("\n", '<br>', $Line['Text']); 151 $Output .= '<tr><td>'.$Line['Date'].'</td>'. 152 '<td>'.$Line['LogName'].'</td>'. 153 '<td><span style="color: '.$Line['LogColor'].'">'.$Line['Text'].'</span></td>'. 154 '<td><a href="user.php?user='.$Line['User'].'">'.$Line['UserName'].'</a></td>'. 155 '<td>'.$Line['IP'].'</td></tr>'; 156 } 157 $Output .= '</table>'. 158 $PageList['Output']; 159 if($this->System->User->Licence(LICENCE_ADMIN)) 160 $Output .= '<div><a href="'.$this->System->Link('/log.php?a=delerrlog').'">Vymázání chybových záznamů</a></div>'; 161 } else $Output .= ShowMessage('Nemáte oprávnění.', MESSAGE_CRITICAL); 162 163 return($Output); 164 } 165 166 function DeleteErrorLog() 51 167 { 52 $Output = '<strong>Filtr: </strong>'. 53 '<span style="color:black"><a href="log.php?type=" title="Bez filtrování">Všechny</a></span> '; 54 $DbResult = $System->Database->query('SELECT * FROM `LogType`'); 55 while($LogType = $DbResult->fetch_assoc()) 56 { 57 $Output .= '<a href="log.php?type='.$LogType['Id'].'" style="color:'.$LogType['Color'].'" title="'.$LogType['Name'].'">'.$LogType['Name'].'</a> '; 58 } 59 // echo ' Formát: datum: text zprávy (uživatel, IP)<br /><br />'; 60 $Output .= '<br /><br />'; 61 62 if(array_key_exists('type', $_SESSION)) $Where = ' WHERE '.$WhereType; 63 else 64 { 65 if(array_key_exists('group', $_SESSION)) $Where = ' WHERE `Text` LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 66 else $Where = ''; 67 } 68 //if(($Where != '') and (array_key_exists('group', $_SESSION))) $Where .= ' AND text LIKE "%'.$TranslationTree[$_SESSION['group']]['Name'].'%"'; 69 70 $DbResult = $System->Database->query('SELECT COUNT(*) FROM `Log` '.$Where); 71 $DbRow = $DbResult->fetch_row(); 72 $PageList = GetPageList($DbRow[0]); 73 74 $Output .= $PageList['Output']; 75 76 $TableColumns = array( 77 array('Name' => 'Date', 'Title' => 'Čas'), 78 array('Name' => 'LogName', 'Title' => 'Typ'), 79 array('Name' => 'Text', 'Title' => 'Text'), 80 array('Name' => 'UserName', 'Title' => 'Uživatel'), 81 array('Name' => 'IP', 'Title' => 'Adresa'), 82 ); 83 $Order = GetOrderTableHeader($TableColumns, 'date', 1); 84 $Output .= '<table width="98%" class="BaseTable">'. 85 $Order['Output']; 86 87 $sql = 'SELECT *, `LogType`.`Color` AS `LogColor`, `LogType`.`Name` AS `LogName`, '. 88 '(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']; 89 $DbResult = $System->Database->query($sql); 90 while($Line = $DbResult->fetch_assoc()) 91 { 92 if($Line['Type'] == LOG_TYPE_ERROR) $Line['Text'] = htmlspecialchars($Line['Text']); 93 $Line['Text'] = str_replace("\n", '<br>', $Line['Text']); 94 $Output .= '<tr><td>'.$Line['Date'].'</td>'. 95 '<td>'.$Line['LogName'].'</td>'. 96 '<td><span style="color: '.$Line['LogColor'].'">'.$Line['Text'].'</span></td>'. 97 '<td><a href="user.php?user='.$Line['User'].'">'.$Line['UserName'].'</a></td>'. 98 '<td>'.$Line['IP'].'</td></tr>'; 168 if($this->System->User->Licence(LICENCE_ADMIN)) 169 { 170 $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Log` WHERE `Type`='.LOG_TYPE_ERROR); 171 $DbRow = $DbResult->fetch_row(); 172 $this->System->Database->query('DELETE FROM `Log` WHERE `Type`='.LOG_TYPE_ERROR); 173 WriteLog('Vymazány chybové záznamy', LOG_TYPE_ADMINISTRATION); 174 $Output = ShowMessage('Smazáno všech '.$DbRow[0].' chybových záznamů.'); 175 $Output .= $this->ShowList(); 176 return($Output); 177 } else $Output .= ShowMessage('Nemáte oprávnění.', MESSAGE_CRITICAL); 99 178 } 100 $Output .= '</table>'.101 $PageList['Output'];102 } else $Output .= ShowMessage('Nemáte oprávnění.', MESSAGE_CRITICAL);103 104 ShowPage($Output);105 179 }
Note:
See TracChangeset
for help on using the changeset viewer.