function getAllChats() { global $user, $db; $q = "SELECT * FROM `chat_hashes` WHERE `from_id` = " . $user['id'] . " OR `to_id` = " . $user['id'] . ""; $ret = $db->query($q); //debug($ret); if (isset($ret[0])) { $chats = array(); foreach ($ret as $v) { $chats[] = getChatDialog($v->hash); } $out = $chats; } else { $out = false; } return $out; }
// если новый то смотрим нет ли уже такого или обратного if ($route->action == 'new') { $streightHash = md5('uid' . $user['id'] . 'uid' . $route->param); $reverseHash = md5('uid' . $route->param . 'uid' . $user['id']); $checkChat = $db->query("SELECT * FROM `chat_hashes` WHERE `hash` = '" . $streightHash . "' OR `hash` = '" . $reverseHash . "';"); // нашли уже готовый чат if (isset($checkChat[0])) { $route->param = $checkChat[0]->hash; $route->action = ''; } else { $db->query("INSERT INTO `chat_hashes` VALUES(NULL, '" . $streightHash . "', " . $user['id'] . ", " . $route->param . " );"); $route->param = $streightHash; } } } $chat = getChatDialog($route->param); //debug($chat); if (empty($chat)) { $chat = array(); } ?> <script> function sendMsg() { $.ajax({ url: '<?php echo $cfg['options']['siteurl']; ?> /gears/ajax.sendMsg.php', method: 'POST', dataType: 'JSON',