Skip to content
Snippets Groups Projects
Forked from Eric Laufer / VMS-SUEE_2.0
89 commits behind, 12 commits ahead of the upstream repository.
chat.class.php 1.28 KiB
<?php

class chatClass{
    public static function getRestChatLines($id){
		$arr = array();
		$jsonData = '{"results":[';
		$db_connection = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_BASE );
		$db_connection->query( "SET NAMES 'UTF8'" );
		$statement = $db_connection->prepare( "SELECT id, absender, nachricht, time FROM vms_chat WHERE id > ? ");
		$statement->bind_param( 'i', $id);
		$statement->execute();
		$statement->bind_result( $id, $usrname, $chattext, $chattime);
		$line = new stdClass;
		while ($statement->fetch()) {
			$line->id = $id;
			$line->usrname = $usrname;
			$line->chattext = $chattext;
			$line->chattime = date('H:i:s', $chattime);
			$arr[] = json_encode($line);
		}
		$statement->close();
		$db_connection->close();
		$jsonData .= implode(",", $arr);
		$jsonData .= ']}';
		return $jsonData;
    }
    
    public static function setChatLines( $chattext, $usrname, $color) {
		$db_connection = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_BASE );
		$db_connection->query( "SET NAMES 'UTF8'" );
		$statement = $db_connection->prepare( "INSERT INTO chat( usrname, color, chattext) VALUES(?, ?, ?)");
		$statement->bind_param( 'sss', $usrname, $color, $chattext);
		$statement->execute();
		$statement->close();
		$db_connection->close();
    }
}
?>