コード例 #1
0
ファイル: ajax.php プロジェクト: NaveNO/WebMCR
 private function monitor()
 {
     if (!$this->core->is_access("sys_monitoring")) {
         $this->core->js_notify('Access Denied');
     }
     $query = $this->db->query("SELECT id, title, `text`, ip, `port` FROM `mcr_monitoring`");
     if (!$query || $this->db->num_rows($query) <= 0) {
         $this->core->js_notify('Нет доступных серверов');
     }
     $array = array();
     require_once MCR_TOOL_PATH . 'monitoring.class.php';
     $m = new monitoring($this->config->main['mon_type']);
     while ($ar = $this->db->fetch_assoc($query)) {
         $address = $this->db->HSC($ar['ip']);
         $port = intval($ar['port']);
         $m->connect($address, $port);
         $json = json_decode($m->data);
         if ($json->status == 'online') {
             $status = 'progress-info';
             $stats = $json->players . ' / ' . $json->slots;
             $progress = $json->players <= 0 ? 0 : ceil(100 / ($json->slots / $json->players));
         } else {
             $status = 'progress-danger';
             $stats = 'Сервер оффлайн';
             $progress = 100;
         }
         $data = array("ID" => intval($ar['id']), "TITLE" => $this->db->HSC($ar['title']), "TEXT" => $this->db->HSC($ar['text']), "STATUS" => $status, "STATS" => $stats);
         $array[] = array("id" => intval($ar['id']), "progress" => $progress, "form" => $this->core->sp(MCR_THEME_BLOCK . "monitor/monitor-id.html", $data));
     }
     $this->core->js_notify('Серверы успешно получены', true, $array);
 }