public function delete($company_id) { $departments = Department::where('company_id', $company_id)->get(); if (Config::get('site-config.is_demo') && $company_id == 1) { Session::flash('error_msg', 'Demo : Feature is disabled'); return Redirect::to('/dashboard'); } foreach ($departments as $department) { if (!empty($department)) { $tickets = Tickets::where('department_id', $department->id)->get(); //Delete tickets foreach ($tickets as $ticket) { TicketAttachments::where('thread_id', $ticket->id)->delete(); MessageThread::where('id', $ticket->thread_id)->delete(); ThreadMessages::where('thread_id', $ticket->thread_id)->delete(); } Tickets::where('department_id', $department->id)->delete(); //Delete Chat and Conversations $online_users = OnlineUsers::where('department_id', $department->id)->get(); foreach ($online_users as $online_user) { MessageThread::where('id', $online_user->thread_id)->delete(); ThreadMessages::where('thread_id', $online_user->thread_id)->delete(); } OnlineUsers::where('department_id', $department->id)->delete(); $closed_conversations = ClosedConversations::where('department_id', $department->id)->get(); foreach ($closed_conversations as $closed_conversation) { MessageThread::where('id', $closed_conversation->thread_id)->delete(); ThreadMessages::where('thread_id', $closed_conversation->thread_id)->delete(); } ClosedConversations::where('department_id', $department->id)->delete(); $operators = OperatorsDepartment::where('department_id', $department->id)->lists('user_id'); if (sizeof($operators) > 0) { User::whereIn('id', $operators)->delete(); UsersGroups::whereIn('user_id', $operators)->delete(); } OperatorsDepartment::where('department_id', $department->id)->delete(); $department_admin = DepartmentAdmins::where('department_id', $department->id)->first(); if (!empty($department_admin)) { UsersGroups::where('user_id', $department_admin->user_id)->delete(); User::where("id", $department_admin->user_id)->delete(); CompanyDepartmentAdmins::where("user_id", $department_admin->user_id)->delete(); CannedMessages::where('operator_id', $operators)->delete(); } } DepartmentAdmins::where('department_id', $department->id)->delete(); Department::where('id', $department->id)->delete(); } $company = Company::where('id', $company_id)->first(); RecentActivities::createActivity("Company <a href='/companies/all'>" . $company->name . "</a> deleted by User Name " . Auth::user()->name . " User ID " . Auth::user()->id); Company::where('id', $company_id)->delete(); Session::flash('success_msg', trans('msgs.company_deleted_success')); return Redirect::to('/companies/all'); }
public function delete($user_id) { $tickets = Tickets::where('customer_id', $user_id)->get(); //Delete tickets foreach ($tickets as $ticket) { TicketAttachments::where('thread_id', $ticket->id)->delete(); MessageThread::where('id', $ticket->thread_id)->delete(); ThreadMessages::where('thread_id', $ticket->thread_id)->delete(); } Tickets::where('customer_id', $user_id)->delete(); //Delete Chat and Conversations $online_users = OnlineUsers::where('user_id', $user_id)->get(); foreach ($online_users as $online_user) { MessageThread::where('id', $online_user->thread_id)->delete(); ThreadMessages::where('thread_id', $online_user->thread_id)->delete(); } OnlineUsers::where('user_id', $user_id)->delete(); $closed_conversations = ClosedConversations::where('user_id', $user_id)->get(); foreach ($closed_conversations as $closed_conversation) { MessageThread::where('id', $closed_conversation->thread_id)->delete(); ThreadMessages::where('thread_id', $closed_conversation->thread_id)->delete(); } ClosedConversations::where('user_id', $user_id)->delete(); UsersGroups::where('user_id', $user_id)->delete(); CompanyCustomers::where("customer_id", $user_id)->delete(); User::where("id", $user_id)->delete(); RecentActivities::createActivity("Customer deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name); Session::flash('success_msg', trans('msgs.customer_deleted_success')); return Redirect::to('/customers/all'); }
public function accept($thread_id) { if (Utils::isOperator(Auth::user()->id)) { $canned_messages = CannedMessages::where('operator_id', Auth::user()->id); } else { $canned_messages = CannedMessages::all(); } $this->data['canned_messages'] = $canned_messages; $online_users = OnlineUsers::where('thread_id', $thread_id)->first(); if (empty($online_users)) { Session::flash('error_msg', trans('msgs.conversation_has_been_closed')); return Redirect::to('/conversations/all'); } if ($online_users->operator_id > 0 && $online_users->operator_id != Auth::user()->id) { Session::flash('error_msg', trans('msgs.another_operator_is_in_chat')); return Redirect::to('/conversations/all'); } if ($online_users->operator_id <= 0) { $online_users->operator_id = Auth::user()->id; $online_users->started_on = \Carbon\Carbon::now(); $online_users->locked_by_operator = 1; $online_users->save(); RecentActivities::createActivity("Online Conversation <a href='/conversations/all'>ID:" . $online_users->id . "</a> accepted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name); //If transfered and sitting alone ThreadMessages::where('thread_id', $thread_id)->where('sender_id', 0)->update(['sender_id' => Auth::user()->id]); $thread = MessageThread::find($thread_id); $thread->operator_id = Auth::user()->id; $thread->save(); } else { $thread = MessageThread::find($thread_id); } $messages = MessageThread::getServerMessages($thread_id, 0); $geo_info = ThreadGeoInfo::where('thread_id', $thread_id)->first(); $this->data['online'] = $online_users; $this->data['geo'] = $geo_info; $this->data['geo_pages'] = json_decode($geo_info->all_pages); $this->data['message_str'] = $messages["messages_str"]; $this->data['last_message_id'] = $messages["last_message_id"]; $this->data['thread'] = $thread; return View::make('conversations.messages', $this->data); }
public function masterRefresh() { if (Input::get('company_id', 0) > 0 && Input::get('department_id', 0) > 0) { $online_users = OnlineUsers::where('company_id', Input::get('company_id'))->where('department_id', Input::get('department_id'))->orderBy('id', 'desc')->get(); } else { $online_users = OnlineUsers::orderBy('id', 'desc')->get(); } $conversations_arr = []; foreach ($online_users as $online) { if (sizeof(User::where('id', $online->user_id)->get()) > 0) { $online->user = User::find($online->user_id); if ($online->operator_id > 0) { $online->operator = User::find($online->operator_id); } $single_conversation = []; $single_conversation[] = $online->user->name; $single_conversation[] = $online->user->email; if (!isset($online->operator)) { $single_conversation[] = '<td><a href="/conversations/accept/' . $online->thread_id . '" class="btn btn-success btn-sm"> <i class="icon-checkmark4"></i> ' . trans('msgs.accept') . ' </a></td>'; $conversations_arr[] = $single_conversation; } if (isset($online->operator) && $online->operator->id == Auth::user()->id) { $single_conversation[] = '<td><a href="/conversations/accept/' . $online->thread_id . '" class="btn btn-success btn-sm"> <i class="icon-checkmark4"></i> ' . trans('msgs.reply') . ' </a></td>'; $conversations_arr[] = $single_conversation; } } } $activities_arr = []; if (Utils::isAdmin(Auth::user()->id)) { $all_activities = RecentActivities::orderBy('id', 'desc')->limit(10)->get(); foreach ($all_activities as $activity) { $single_activity = []; $single_activity[] = $activity->message; $activities_arr[] = $single_activity; } } return json_encode(['onlineChats' => $conversations_arr, 'recentActivities' => $activities_arr]); }
public function delete($admin_id) { $department_admin = DepartmentAdmins::where("user_id", $admin_id)->first(); if (Config::get('site-config.is_demo') && $admin_id == 2) { Session::flash('error_msg', 'Demo : Feature is disabled'); return Redirect::to('/dashboard'); } if (!empty($department_admin)) { $department = Department::where('id', $department_admin->department_id)->first(); if (!empty($department)) { $company = Company::where('id', $department->company_id)->first(); //Change all conversations , tickets , threads , thread_messages operator_id OnlineUsers::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]); ClosedConversations::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]); MessageThread::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]); Tickets::where('operator_id', $admin_id)->update(['operator_id' => $company->user_id]); ThreadMessages::where('sender_id', $admin_id)->update(['sender_id' => $company->user_id]); } } CompanyDepartmentAdmins::where("user_id", $admin_id)->delete(); DepartmentAdmins::where('user_id', $admin_id)->delete(); UsersGroups::where('user_id', $admin_id)->delete(); User::where('id', $admin_id)->delete(); RecentActivities::createActivity("Department admin deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name); Session::flash('success_msg', trans('msgs.department_admin_deleted_success')); return Redirect::to('/departments/admins/all'); }
public function init_data() { $data = []; $data['in_conversation'] = 0; if (Input::has('token') && sizeof(OnlineUsers::where('token', Input::get('token'))->get()) > 0) { $data['in_conversation'] = 1; } $encoded_values = Settings::where('key', 'chat')->first(); $decoded_values = json_decode($encoded_values->value); $data['wrapper'] = View::make('conversations.stub-chat-wrapper', ['enable_attachments' => $decoded_values->enable_attachment_in_chat])->render(); return $data; }
public function delete($user_id) { $operators_department = OperatorsDepartment::where("user_id", $user_id)->first(); if (!empty($operators_department)) { $department_admin = DepartmentAdmins::where('department_id', $operators_department->department_id)->first(); if (!empty($department_admin)) { //Change all conversations , tickets , threads , thread_messages operator_id OnlineUsers::where('operator_id', $user_id)->update(['operator_id' => $department_admin->user_id]); ClosedConversations::where('operator_id', $user_id)->update(['operator_id' => $department_admin->user_id]); MessageThread::where('operator_id', $user_id)->update(['operator_id' => $department_admin->user_id]); Tickets::where('operator_id', $user_id)->update(['operator_id' => $department_admin->user_id]); ThreadMessages::where('sender_id', $user_id)->update(['sender_id' => $department_admin->user_id]); } } RecentActivities::createActivity("User " . User::where('id', $user_id)->pluck('name') . " deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name); User::find($user_id)->delete(); OperatorsDepartment::where("user_id", $user_id)->delete(); CannedMessages::where('operator_id', $user_id)->delete(); UsersGroups::where('user_id', $user_id)->delete(); Session::flash('success_msg', trans('msgs.operator_deleted_success')); return Redirect::to('/operators/all'); }