Newer
Older
WebMCR / upload / blocks / 3_monitor.php
@Qexy Qexy on 26 Feb 2016 1 KB Big update to Beta 1.0
<?php

if(!defined("MCR")){ exit("Hacking Attempt!"); }

class block_monitor{
	private $core, $db, $user, $lng;

	public function __construct($core){
		$this->core	= $core;
		$this->db	= $core->db;
		$this->user	= $core->user;
		$this->lng	= $core->lng_b;
	}

	private function server_array(){
		$query = $this->db->query("SELECT id, title, `text`, ip, `port`, `status`, online, slots, players FROM `mcr_monitoring`");

		if(!$query || $this->db->num_rows($query)<=0){ return $this->lng['empty']; }

		ob_start();

		while($ar = $this->db->fetch_assoc($query)){

			$status = (intval($ar['status'])===1) ? 'progress-info' : 'progress-danger';
			$slots = intval($ar['slots']);
			$online = intval($ar['online']);

			$progress = ($online<=0) ? 0 : ceil(100 / ($slots / $online));

			if(intval($ar['status'])!=1){ $progress = 100; }

			$data = array(
				'ID' => intval($ar['id']),
				'TITLE' => $this->db->HSC($ar['title']),
				'TEXT' => $this->db->HSC($ar['text']),
				'IP' => $this->db->HSC($ar['ip']),
				'PORT' => intval($ar['port']),
				'PROGRESS' => $progress,
				'STATUS' => $status,
				'STATS' => (intval($ar['status'])===1) ? $online.' / '.$slots : $this->lng['offline'],
			);

			echo $this->core->sp(MCR_THEME_PATH."blocks/monitor/monitor-id.html", $data);
		}

		return ob_get_clean();
	}

	public function content(){
		if(!$this->core->is_access("sys_monitoring")){ return; }

		$data = array(
			'CONTENT' => $this->server_array(),
		);

		return $this->core->sp(MCR_THEME_PATH."blocks/monitor/main.html", $data);
	}
}

?>