<?php
class Support{
static private $instance = NULL;
private $db;
public $type = array();
public function __construct(){
$this->db = DB::a()->d;
$this->type[1] = "Вопросы по игре";
$this->type[] = "Ошибки";
$this->type[] = "Предложения";
$this->type[] = "Покупка баксов";
}
static function a(){
if(self::$instance==NULL)self::$instance=new Support();
return self::$instance;
}
public function getSupportAdmin(){
$result = $this->db->query("SELECT `support`.*, ".User::a()->join."
FROM `support` JOIN `users`
ON `users`.`id` = `support`.`user`
ORDER BY `support`.`id` DESC")->fetchAll();
return $result;
}
public function getMessage($id){
$id = abs(intval($id));
$result = $this->db->query("SELECT `support`.*, ".User::a()->join."
FROM `support` JOIN `users`
ON `users`.`id` = `support`.`user`
WHERE `support`.`id` = '".$id."' LIMIT 1")->fetch();
return $result;
}
public function getSupportModer(){
$result = $this->db->query("SELECT `support`.*, ".User::a()->join."
FROM `support` JOIN `users`
ON `users`.`id` = `support`.`user`
WHERE `support`.`type` = '1'
ORDER BY `support`.`id` DESC")->fetchAll();
return $result;
}
public function add($text,$type){
$ins = $this->db->prepare("INSERT INTO `support` (`user`,`type`,`text`,`time`) VALUES ('".User::a()->user['id']."','".$type."', :text,'".time()."')");
$ins->bindParam(':text', $text ,PDO::PARAM_STR);
$ins->execute();
return $true;
}
public function delete($id){
$id = abs(intval($id));
$mess = $this->db->query("SELECT * FROM `support` WHERE `id` = '".$id."' LIMIT 1")->fetch();
if($mess === false)return false;
$this->db->query("DELETE FROM `support` WHERE `id` = '".$id."' LIMIT 1");
return $true;
}
}