forked from hiltonbruce/Igreja
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80150ef
commit 74687d4
Showing
24 changed files
with
1,045 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
CREATE TABLE IF NOT EXISTS `chat` ( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`from` varchar(255) NOT NULL DEFAULT '', | ||
`to` varchar(255) NOT NULL DEFAULT '', | ||
`message` text NOT NULL, | ||
`sent` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', | ||
`recd` int(10) unsigned NOT NULL DEFAULT '0', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=73 ; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS `login` ( | ||
`nome` varchar(20) NOT NULL, | ||
`tempo` varchar(20) NOT NULL, | ||
`status` int(1) NOT NULL COMMENT 'Vazio - Online, 1- Ausente, 2-desconectado, 3-Não pertube', | ||
PRIMARY KEY (`nome`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
<?php | ||
|
||
/* | ||
Copyright (c) 2009 Anant Garg (anantgarg.com | inscripts.com) | ||
This script may be used for non-commercial purposes only. For any | ||
commercial purposes, please contact the author at | ||
[email protected] | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
define ('DBPATH','localhost'); | ||
define ('DBUSER','igreja'); | ||
define ('DBPASS','G4Hd%VKC#yV5F!at8c'); | ||
define ('DBNAME','assembleia'); | ||
|
||
session_start(); | ||
|
||
global $dbh; | ||
$dbh = mysql_connect(DBPATH,DBUSER,DBPASS); | ||
mysql_selectdb(DBNAME,$dbh); | ||
|
||
|
||
require "../func_class/funcoes.php"; | ||
require "../func_class/classes.php"; | ||
|
||
conectar(); | ||
if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); } | ||
if ($_GET['action'] == "sendchat") { sendChat(); } | ||
if ($_GET['action'] == "closechat") { closeChat(); } | ||
if ($_GET['action'] == "startchatsession") { startChatSession(); } | ||
|
||
if (!isset($_SESSION['chatHistory'])) { | ||
$_SESSION['chatHistory'] = array(); | ||
} | ||
|
||
if (!isset($_SESSION['openChatBoxes'])) { | ||
$_SESSION['openChatBoxes'] = array(); | ||
} | ||
|
||
function chatHeartbeat() { | ||
|
||
$sql = "select * from chat where (chat.to = '".mysql_real_escape_string($_SESSION['username'])."' AND recd = 0) order by id ASC"; | ||
$query = mysql_query($sql); | ||
$items = ''; | ||
|
||
$chatBoxes = array(); | ||
|
||
while ($chat = mysql_fetch_array($query)) { | ||
|
||
if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) { | ||
$items = $_SESSION['chatHistory'][$chat['from']]; | ||
} | ||
|
||
$chat['message'] = sanitize($chat['message']); | ||
|
||
$items .= <<<EOD | ||
{ | ||
"s": "0", | ||
"f": "{$chat['from']}", | ||
"m": "{$chat['message']}" | ||
}, | ||
EOD; | ||
|
||
if (!isset($_SESSION['chatHistory'][$chat['from']])) { | ||
$_SESSION['chatHistory'][$chat['from']] = ''; | ||
} | ||
|
||
$_SESSION['chatHistory'][$chat['from']] .= <<<EOD | ||
{ | ||
"s": "0", | ||
"f": "{$chat['from']}", | ||
"m": "{$chat['message']}" | ||
}, | ||
EOD; | ||
|
||
unset($_SESSION['tsChatBoxes'][$chat['from']]); | ||
$_SESSION['openChatBoxes'][$chat['from']] = $chat['sent']; | ||
} | ||
|
||
if (!empty($_SESSION['openChatBoxes'])) { | ||
foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) { | ||
if (!isset($_SESSION['tsChatBoxes'][$chatbox])) { | ||
$now = time()-strtotime($time); | ||
$time = date('g:iA d/M', strtotime($time)); | ||
|
||
$message = "Enviado às: $time"; | ||
|
||
|
||
if ($now > 180) { | ||
$items .= <<<EOD | ||
{ | ||
"s": "2", | ||
"f": "$chatbox", | ||
"m": "{$message}" | ||
}, | ||
EOD; | ||
|
||
if (!isset($_SESSION['chatHistory'][$chatbox])) { | ||
$_SESSION['chatHistory'][$chatbox] = ''; | ||
} | ||
|
||
$_SESSION['chatHistory'][$chatbox] .= <<<EOD | ||
{ | ||
"s": "2", | ||
"f": "$chatbox", | ||
"m": "{$message}" | ||
}, | ||
EOD; | ||
$_SESSION['tsChatBoxes'][$chatbox] = 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
$sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['username'])."' and recd = 0"; | ||
$query = mysql_query($sql); | ||
|
||
if ($items != '') { | ||
$items = substr($items, 0, -1); | ||
} | ||
header('Content-type: application/json'); | ||
?> | ||
{ | ||
"items": [ | ||
<?php echo $items;?> | ||
] | ||
} | ||
|
||
<?php | ||
exit(0); | ||
} | ||
|
||
function chatBoxSession($chatbox) { | ||
|
||
$items = ''; | ||
|
||
if (isset($_SESSION['chatHistory'][$chatbox])) { | ||
$items = $_SESSION['chatHistory'][$chatbox]; | ||
} | ||
|
||
return $items; | ||
} | ||
|
||
function startChatSession() { | ||
$items = ''; | ||
if (!empty($_SESSION['openChatBoxes'])) { | ||
foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) { | ||
$items .= chatBoxSession($chatbox); | ||
} | ||
} | ||
|
||
|
||
if ($items != '') { | ||
$items = substr($items, 0, -1); | ||
} | ||
|
||
header('Content-type: application/json'); | ||
?> | ||
{ | ||
"username" : "<?php echo $_SESSION['username'];?>", | ||
"items": [ | ||
<?php echo $items;?> | ||
] | ||
} | ||
|
||
<?php | ||
|
||
|
||
exit(0); | ||
} | ||
|
||
function sendChat() { | ||
$from = $_SESSION['username']; | ||
$to = $_POST['to']; | ||
$message = $_POST['message']; | ||
|
||
$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time()); | ||
|
||
$messagesan = sanitize($message); | ||
|
||
if (!isset($_SESSION['chatHistory'][$_POST['to']])) { | ||
$_SESSION['chatHistory'][$_POST['to']] = ''; | ||
} | ||
|
||
$_SESSION['chatHistory'][$_POST['to']] .= <<<EOD | ||
{ | ||
"s": "1", | ||
"f": "{$to}", | ||
"m": "{$messagesan}" | ||
}, | ||
EOD; | ||
|
||
|
||
unset($_SESSION['tsChatBoxes'][$_POST['to']]); | ||
|
||
$sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())"; | ||
$query = mysql_query($sql); | ||
|
||
$sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['username'])."' and recd = 0"; | ||
$logado = "UPDATE login SET tempo ='".$_SERVER["REQUEST_TIME"]."' WHERE nome='{$_SESSION['username']}' "; | ||
$querylog = mysql_query($logado); | ||
echo "1"; | ||
exit(0); | ||
} | ||
|
||
function closeChat() { | ||
|
||
unset($_SESSION['openChatBoxes'][$_POST['chatbox']]); | ||
|
||
echo "1"; | ||
exit(0); | ||
} | ||
|
||
function sanitize($text) { | ||
$text = htmlspecialchars($text, ENT_QUOTES); | ||
$text = str_replace("\n\r","\n",$text); | ||
$text = str_replace("\r\n","\n",$text); | ||
$text = str_replace("\n","<br>",$text); | ||
return $text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#main_container { | ||
width:16%; | ||
background-color:#ffffff; /* DO NOT REMOVE THIS; or you'll have issue w/ the scrollbar, when the mouse pointer is on a white space */ | ||
overflow-x: hidden; | ||
overflow-y: scroll; | ||
height: auto; /* this will make sure that the height will extend at the bottom */ | ||
position:absolute; /* container div must be absolute, for our fixed bar to work */ | ||
font-size: 9px; | ||
text-align: left; | ||
} | ||
|
||
.chatbox { | ||
position: fixed; | ||
position:expression("absolute"); | ||
width: 225px; | ||
display:none; | ||
} | ||
|
||
.chatboxhead { | ||
background-color: #f99d39; | ||
padding:7px; | ||
color: #ffffff; | ||
|
||
border-right:1px solid #f99d39; | ||
border-left:1px solid #f99d39; | ||
} | ||
|
||
.chatboxblink { | ||
background-color: #176689; | ||
border-right:1px solid #176689; | ||
border-left:1px solid #176689; | ||
} | ||
|
||
.chatboxcontent { | ||
font-family: arial,sans-serif; | ||
font-size: 13px; | ||
color: #333333; | ||
height:215px; | ||
width:225px; | ||
overflow-y:auto; | ||
overflow-x:auto; | ||
padding:7px; | ||
border-left:1px solid #cccccc; | ||
border-right:1px solid #cccccc; | ||
border-bottom:1px solid #eeeeee; | ||
background-color: #ffffff; | ||
line-height: 1.3em; | ||
} | ||
|
||
.chatboxinput { | ||
padding: 5px; | ||
background-color: #ffffff; | ||
border-left:1px solid #cccccc; | ||
border-right:1px solid #cccccc; | ||
border-bottom:1px solid #cccccc; | ||
} | ||
|
||
.chatboxtextarea { | ||
width: 206px; | ||
height:44px; | ||
padding:3px 0pt 3px 3px; | ||
border: 1px solid #eeeeee; | ||
margin: 1px; | ||
overflow:hidden; | ||
} | ||
|
||
.chatboxtextareaselected { | ||
border: 2px solid #f99d39; | ||
margin:0; | ||
} | ||
|
||
.chatboxmessage { | ||
margin-left:1em; | ||
} | ||
|
||
.chatboxinfo { | ||
margin-left:-1em; | ||
color:#666666; | ||
|
||
} | ||
|
||
.chatboxmessagefrom { | ||
margin-left:-1em; | ||
font-weight: bold; | ||
} | ||
|
||
.chatboxmessagecontent { | ||
} | ||
|
||
.chatboxoptions { | ||
float: right; | ||
} | ||
|
||
.chatboxoptions a { | ||
text-decoration: none; | ||
color: white; | ||
font-weight:bold; | ||
font-family:Verdana,Arial,"Bitstream Vera Sans",sans-serif; | ||
} | ||
|
||
.chatboxtitle { | ||
float: left; | ||
} |
Oops, something went wrong.