Location: PHPKode > projects > HelpDesk Chat > helpdesk-chat/chat.class.php
<?php class chat {

//conexao provisoria
var $adminNick = 'igor';

    function queryRow($query){
define("host", "localhost");
define("login", "root");
define("senha", "qwerpo");
define("data", "chat");

    try{
    	$host = host;
    	$data = data;
             $connection = new PDO("mysql:host=$host;dbname=$data", login, senha);
             //$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             $result = $connection->prepare($query);
             $result->execute();
             return $result;
             
             $this->connection = $connection;
    }catch(PDOException $e){
    echo $e->getMessage();
    }
    }
    
      function close($connection){
	      $connection = null;
	      }
	function query($query){
	    $host = host;
	    $result = $this->queryRow($query);
	    $row = $result->fetch(PDO::FETCH_ASSOC);
	    $this->close($this->connection);
	    $this->query = $query;
	    return $row;
	    }
//fecha conexao provisoria

	
	function __construct(){
		if(isset($_POST['email'])){
			$this->logar($_POST['email']);
		}
	}
	function logar($email){
	$row = $this->query("SELECT sessao FROM log ORDER BY sessao DESC");
	$_SESSION['session'] = $row['sessao'] + 1;
	$_SESSION['email'] = $email;
	}
	function newMsg($msg){
		if(isset($_GET['admin'])){
		$session = 	$_GET['session'];
		$admin = 1;
		$email = $this->adminNick;
		
		}else{
		$session = $_SESSION['session'];
		$admin = 0;
		$email = $_SESSION['email'];
		}		
		$ip = $_SERVER['REMOTE_ADDR'];
		$time = date('Y-m-d H:i:s');
		
	$this->query("INSERT INTO log (email, sessao, ip, time, msg, status, admin) VALUES ('$email', '$session', '$ip', '$time', '$msg', 1, $admin)");
	}
	function showUsers(){
	$row = $this->queryRow("SELECT * FROM log WHERE status = 1 AND admin = 0 GROUP BY email");
	return $row;	
	}
	function showMsgs(){
	if(isset($_GET['admin'])){
		$session = 	$_GET['session'];
	}else{
		$session = $_SESSION['session'];
	}
	$row = $this->queryRow("SELECT * FROM log WHERE status = 1 AND sessao = $session ORDER BY time ASC");
	return $row;	
	}
	function clearStatus(){
		$this->query("UPDATE log SET status=0 ");
	}
	function refreshStatus(){
		$session = $_SESSION['session'];
		$this->query("UPDATE log SET status=1 WHERE sessao = $session");
	}
	function adress($file){
		if(isset($_GET['admin'])){
	$adress = $file."?admin=".$_GET['admin']."&session=".$_GET['session'];
	}else{
	$adress = $file;
	}
	return $adress;
	}
}
?>

</body>
</html>
Return current item: HelpDesk Chat