shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

log.php (3915B)


      1 <?php
      2 class ControllerToolLog extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {		
      6 		$this->load->language('tool/log');
      7 		
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		if (isset($this->session->data['error'])) {
     11 			$data['error_warning'] = $this->session->data['error'];
     12 
     13 			unset($this->session->data['error']);
     14 		} elseif (isset($this->error['warning'])) {
     15 			$data['error_warning'] = $this->error['warning'];
     16 		} else {
     17 			$data['error_warning'] = '';
     18 		}
     19 
     20 		if (isset($this->session->data['success'])) {
     21 			$data['success'] = $this->session->data['success'];
     22 
     23 			unset($this->session->data['success']);
     24 		} else {
     25 			$data['success'] = '';
     26 		}
     27 
     28 		$data['breadcrumbs'] = array();
     29 
     30 		$data['breadcrumbs'][] = array(
     31 			'text' => $this->language->get('text_home'),
     32 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     33 		);
     34 
     35 		$data['breadcrumbs'][] = array(
     36 			'text' => $this->language->get('heading_title'),
     37 			'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true)
     38 		);
     39 
     40 		$data['download'] = $this->url->link('tool/log/download', 'user_token=' . $this->session->data['user_token'], true);
     41 		$data['clear'] = $this->url->link('tool/log/clear', 'user_token=' . $this->session->data['user_token'], true);
     42 
     43 		$data['log'] = '';
     44 
     45 		$file = DIR_LOGS . $this->config->get('config_error_filename');
     46 
     47 		if (file_exists($file)) {
     48 			$size = filesize($file);
     49 
     50 			if ($size >= 5242880) {
     51 				$suffix = array(
     52 					'B',
     53 					'KB',
     54 					'MB',
     55 					'GB',
     56 					'TB',
     57 					'PB',
     58 					'EB',
     59 					'ZB',
     60 					'YB'
     61 				);
     62 
     63 				$i = 0;
     64 
     65 				while (($size / 1024) > 1) {
     66 					$size = $size / 1024;
     67 					$i++;
     68 				}
     69 
     70 				$data['error_warning'] = sprintf($this->language->get('error_warning'), basename($file), round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]);
     71 			} else {
     72 				$data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null);
     73 			}
     74 		}
     75 
     76 		$data['header'] = $this->load->controller('common/header');
     77 		$data['column_left'] = $this->load->controller('common/column_left');
     78 		$data['footer'] = $this->load->controller('common/footer');
     79 
     80 		$this->response->setOutput($this->load->view('tool/log', $data));
     81 	}
     82 
     83 	public function download() {
     84 		$this->load->language('tool/log');
     85 
     86 		$file = DIR_LOGS . $this->config->get('config_error_filename');
     87 
     88 		if (file_exists($file) && filesize($file) > 0) {
     89 			$this->response->addheader('Pragma: public');
     90 			$this->response->addheader('Expires: 0');
     91 			$this->response->addheader('Content-Description: File Transfer');
     92 			$this->response->addheader('Content-Type: application/octet-stream');
     93 			$this->response->addheader('Content-Disposition: attachment; filename="' . $this->config->get('config_name') . '_' . date('Y-m-d_H-i-s', time()) . '_error.log"');
     94 			$this->response->addheader('Content-Transfer-Encoding: binary');
     95 
     96 			$this->response->setOutput(file_get_contents($file, FILE_USE_INCLUDE_PATH, null));
     97 		} else {
     98 			$this->session->data['error'] = sprintf($this->language->get('error_warning'), basename($file), '0B');
     99 
    100 			$this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true));
    101 		}
    102 	}
    103 	
    104 	public function clear() {
    105 		$this->load->language('tool/log');
    106 
    107 		if (!$this->user->hasPermission('modify', 'tool/log')) {
    108 			$this->session->data['error'] = $this->language->get('error_permission');
    109 		} else {
    110 			$file = DIR_LOGS . $this->config->get('config_error_filename');
    111 
    112 			$handle = fopen($file, 'w+');
    113 
    114 			fclose($handle);
    115 
    116 			$this->session->data['success'] = $this->language->get('text_success');
    117 		}
    118 
    119 		$this->response->redirect($this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true));
    120 	}
    121 }