public function insGroup() { $update = isset($_GET['update']) ? addslashes($_GET['update']) : 0; $gid = isset($_GET['gid']) ? addslashes($_GET['gid']) : 0; $gname = isset($_POST['gname']) ? addslashes($_POST['gname']) : die("no gname"); $arrMember = isset($_POST['arrMember']) ? addslashes($_POST['arrMember']) : die("no arrMember"); $exp = explode(",", $arrMember); if (count($exp) < 2) { //minimum of chat group = 2 $json['bool'] = 0; $json['err'] = Lang::t('Chat min 2 person'); echo json_encode($json); die; } //first insert group $g = new ChatGroup(); if ($update) { if ($gid > 0) { $g->getByID($gid); if ($g->inbox_from != Account::getMyID()) { die("hacking attempt"); } else { $g->load = 1; $cg = new ChatMember(); $cg->deleteMemberByGID($gid); } } else { die("hacking attempt 2"); } } $g->inbox_judul = $gname; $g->inbox_from = Account::getMyID(); if (!$update) { $g->inbox_createdate = leap_mysqldate(); } $g->inbox_changedate = leap_mysqldate(); $id = $g->save(); if ($id) { if ($update) { $id = $gid; } foreach ($exp as $mm) { if ($mm == "") { continue; } $m = new ChatMember(); $m->chat_member_id = $mm; $m->chat_group_id = $id; $m->save(); } } $json = array(); $json['bool'] = $id; echo json_encode($json); }
/** * Include a new user to the chat * * @param int|null $chatId Chat ID * @return Response */ public function includeUser($chatId = null) { if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) { if (!is_null($user = User::find((int) Input::get('user_id')))) { if (!$chat->hasMember($user->id)) { $chatMember = new ChatMember(); $chatMember->chat_id = $chatId; $chatMember->user_id = $user->id; $chatMember->save(); $this->setChatIsUpdated((int) $chatId); } return $this->respond(array('chat_id' => $chatId, 'owner_id' => $chat->owner_id, 'topic' => $chat->topic, 'timestamp' => $chat->getTimestamp(), 'users' => $chat->getUsersArray())); } else { return $this->respondWithError('User doesn\'t exist'); } } else { return $this->respondWithError('Chat doesn\'t exist'); } }