function setChatContacts($sender, $reciever) { $contactsData = getChatContacts(); if (!array_key_exists($sender, $contactsData) || !in_array(getChatId($sender, $reciever), $contactsData[$sender])) { $contactsData[$sender][] = getChatId($sender, $reciever); $contactsData[$reciever][] = getChatId($sender, $reciever); shm_put_var(getMemoryId(), 1, json_encode($contactsData)); } }
function getChatId($_user, $_targetGroup) { if (isset($_POST[POST_EXTERN_CHAT_ID])) { return secPrev($_POST[POST_EXTERN_CHAT_ID]); } else { $result = queryDB(true, "SELECT `chat_id` FROM `" . DB_PREFIX . DATABASE_INFO . "`"); $row = mysql_fetch_array($result, MYSQL_BOTH); $cid = $row["chat_id"] + 1; queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_INFO . "` SET `chat_id`='" . mysql_real_escape_string($cid) . "' WHERE `chat_id`='" . mysql_real_escape_string($row["chat_id"]) . "'"); if (mysql_affected_rows() == 0) { return getChatId(); } else { registerChat($cid, $_targetGroup); $_user->AddFunctionCall("lz_chat_set_id('" . $cid . "');", false); return $cid; } } }