public function all()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $messages = CannedMessages::where('company_id', $company->id)->where('department_id', $department->id)->orderBy('id', 'desc')->get();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $messages = CannedMessages::where('company_id', $company->id)->where('department_id', $department->id)->where('operator_id', Auth::user()->id)->orderBy('id', 'desc')->get();
     } else {
         $messages = CannedMessages::orderBy('id', 'desc')->get();
     }
     foreach ($messages as $message) {
         $operator = User::find($message->operator_id);
         $department = Department::find($message->department_id);
         $company = Company::find($message->company_id);
         $message->operator = $operator;
         $message->department = $department;
         $message->company = $company;
     }
     $this->data['messages'] = $messages;
     return View::make('canned_messages.all', $this->data);
 }
示例#2
0
 static function operatorsOnline($company_id)
 {
     $response = 0;
     $department_admin_ids = CompanyDepartmentAdmins::where('company_id', $company_id)->lists('user_id');
     $company = Company::find($company_id);
     $user = User::find($company->user_id);
     if ($user->is_online == 1) {
         return 1;
     } else {
         foreach ($department_admin_ids as $admin_id) {
             if ($response == 0) {
                 $user = User::find($admin_id);
                 if ($user->is_online == 1) {
                     return 1;
                 } else {
                     $department_admin = DepartmentAdmins::where('user_id', $admin_id)->first();
                     if (!empty($department_admin)) {
                         $operators_ids = OperatorsDepartment::where('department_id', $department_admin->department_id)->lists('user_id');
                         foreach ($operators_ids as $operators_id) {
                             if (sizeof(User::where('id', $operators_id)->get()) > 0) {
                                 $user = User::find($operators_id);
                                 if ($user->is_online == 1) {
                                     return 1;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
 public function create()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_operator->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } else {
         $companies = Company::all();
         $this->data['departments'] = [];
         $this->data['companies'] = $companies;
         if (sizeof($companies) > 0) {
             $department_ids = Department::where('company_id', $companies[0]->id)->lists('id');
             if (sizeof($department_ids) > 0) {
                 foreach ($department_ids as $department_id) {
                     if (sizeof(DepartmentAdmins::where('department_id', $department_id)->get()) <= 0) {
                         array_push($this->data['departments'], Department::whereIn("id", $department_ids)->first());
                     }
                 }
             }
         }
     }
     $this->data["countries"] = DB::table("countries")->remember(60)->get();
     $this->data['timezones'] = Config::get("timezones");
     return View::make('department_admins.create', $this->data);
 }
示例#4
0
 static function getUniCompany()
 {
     $company_id = 0;
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company_id = $department->company_id;
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company_id = $department->company_id;
     }
     return $company_id;
 }
示例#5
0
 public static function getDepartmentOperatorsWithAdmin($department_id)
 {
     $operator_ids = OperatorsDepartment::where('department_id', $department_id)->lists('user_id');
     if (sizeof($operator_ids) > 0) {
         $admin_id = DepartmentAdmins::where('department_id', $department_id)->pluck('user_id');
         $users = User::whereIn('id', $operator_ids)->get();
         if (!empty($admin_id)) {
             $user = User::where('id', $admin_id)->first();
             $user->name = $user->name . " - " . trans('msgs.department_admin');
             $users[] = $user;
         }
         return $users;
     } else {
         return [];
     }
 }
 public function all()
 {
     $customer_ids = [];
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id');
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id');
     } else {
         $customer_ids = CompanyCustomers::lists('customer_id');
     }
     if (sizeof($customer_ids) > 0) {
         $this->data["customers"] = User::whereIn("id", $customer_ids)->orderBy('id', 'desc')->get();
     } else {
         $this->data["customers"] = [];
     }
     foreach ($this->data["customers"] as $customer) {
         $company_id = CompanyCustomers::where("customer_id", $customer->id)->pluck('company_id');
         $customer->company = Company::find($company_id);
         $customer->all_ticket_count = Tickets::where('customer_id', $customer->id)->count();
         $customer->pending_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_PENDING)->count();
         $customer->resolved_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_RESOLVED)->count();
     }
     return View::make('customers.all', $this->data);
 }
 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 all()
 {
     $online_users = OnlineUsers::all();
     foreach ($online_users as $user) {
         $user->user = User::find($user->user_id);
         if ($user->operator_id > 0) {
             $user->operator = User::find($user->operator_id);
         }
     }
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_operator->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
     }
     $this->data['online_users'] = $online_users;
     return View::make('conversations.all', $this->data);
 }
 function index()
 {
     if (\KodeInfo\Utilities\Utils::isCustomer(Auth::user()->id)) {
         return Redirect::to('/tickets/customer/all');
     }
     $past_hr = \Carbon\Carbon::now()->subHour();
     $today = \Carbon\Carbon::now()->subDay();
     $this_week = \Carbon\Carbon::now()->subWeek();
     $this_month = \Carbon\Carbon::now()->subMonth();
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_operator = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_operator->department_id)->first();
         $company = Company::where('id', $department->company_id)->first();
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->where('company_id', $company->id)->where('department_id', $department->id)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
         $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
         $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
         $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
         if (sizeof($operator_ids) > 0) {
             $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
             $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
         } else {
             $department->operators_online = 0;
             $department->operators_offline = 0;
         }
         $this->data['department_stats'] = $department;
     } else {
         $this->data['tickets_past_hr'] = DB::table('tickets')->where('requested_on', '>', $past_hr)->count();
         $this->data['tickets_today'] = DB::table('tickets')->where('requested_on', '>', $today)->count();
         $this->data['tickets_this_week'] = DB::table('tickets')->where('requested_on', '>', $this_week)->count();
         $this->data['tickets_this_month'] = DB::table('tickets')->where('requested_on', '>', $this_month)->count();
         $this->data['tickets_total'] = sizeof(DB::table('tickets')->get());
         $companies = Company::all();
         foreach ($companies as $company) {
             $departments = Department::where('company_id', $company->id)->get();
             foreach ($departments as $department) {
                 $department->all_tickets = sizeof(DB::table('tickets')->where('department_id', $department->id)->get());
                 $department->pending_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_PENDING)->where('department_id', $department->id)->get());
                 $department->resolved_tickets = sizeof(DB::table('tickets')->where('status', Tickets::TICKET_RESOLVED)->where('department_id', $department->id)->get());
                 $operator_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
                 if (sizeof($operator_ids) > 0) {
                     $department->operators_online = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 1)->get());
                     $department->operators_offline = sizeof(User::whereIn('id', $operator_ids)->where("is_online", 0)->get());
                 } else {
                     $department->operators_online = 0;
                     $department->operators_offline = 0;
                 }
             }
             $company->departments = $departments;
         }
         $this->data['department_stats'] = $companies;
     }
     return View::make('index', $this->data);
 }
 public function read($thread_id)
 {
     if (Utils::isOperator(Auth::user()->id)) {
         $canned_messages = CannedMessages::where('operator_id', Auth::user()->id)->get();
     } elseif (Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $operator_ids = OperatorsDepartment::where('department_id', $department_admin->department_id)->lists("user_id");
         if (sizeof($operator_ids) > 0) {
             $canned_messages = CannedMessages::whereIn('operator_id', $operator_ids)->get();
         } else {
             $canned_messages = [];
         }
     } else {
         $canned_messages = CannedMessages::all();
     }
     $this->data['canned_messages'] = $canned_messages;
     $ticket = Tickets::where('thread_id', $thread_id)->first();
     $thread = MessageThread::find($thread_id);
     if ($ticket->customer_id > 0) {
         $ticket->customer = User::find($ticket->customer_id);
     }
     $messages = MessageThread::getTicketMessages($thread_id, 0);
     $geo_info = ThreadGeoInfo::where('thread_id', $thread_id)->first();
     $this->data['geo'] = $geo_info;
     $this->data['message_str'] = $messages["messages_str"];
     $this->data['last_message_id'] = $messages["last_message_id"];
     $this->data['thread'] = $thread;
     $this->data['ticket'] = $ticket;
     return View::make('tickets.customers_read', $this->data);
 }
 public function checkNewMessages()
 {
     $v_data = ["user_id" => Input::get('user_id'), "thread_id" => Input::get('thread_id'), "company_id" => Input::get('company_id'), "last_message_id" => Input::get('last_message_id')];
     $v_rules = ["user_id" => 'required', "thread_id" => 'required', "company_id" => 'required', "last_message_id" => 'required'];
     //Check any operators online from company_id
     //Check if we have any messages from user_id , thread_id
     $v = Validator::make($v_data, $v_rules);
     $response['is_online'] = false;
     if ($v->passes()) {
         //check any operator online
         $response['is_online'] = Company::operatorsOnline(Input::get('company_id'));
         $response['success_msg'] = "";
         $company = Company::find(Input::get('company_id'));
         $response['departments'] = Department::where('company_id', Input::get('company_id'))->get();
         foreach ($response['departments'] as $department) {
             $department_admin = DepartmentAdmins::where('department_id', $department->id)->first();
             $status = trans('msgs._offline_');
             $admin = User::where('id', $company->user_id)->first();
             if (!empty($admin)) {
                 if ($admin->is_online == 1) {
                     $status = trans('msgs._online_');
                 }
             }
             if (!empty($department_admin)) {
                 $user = User::where('id', $department_admin->user_id)->first();
                 if (!empty($user) && $user->is_online == 1) {
                     $status = trans('msgs._online_');
                 }
             }
             $operators = OperatorsDepartment::where('department_id', $department->id)->get();
             foreach ($operators as $operator) {
                 if (sizeof(User::where('id', $operator->user_id)->get()) > 0) {
                     $user = User::find($operator->user_id);
                     if ($user->is_online == 1) {
                         $status = trans('msgs._online_');
                     }
                 }
             }
             $department->name = $department->name . $status;
         }
         if (Input::has('token') && sizeof(OnlineUsers::where('token', Input::get('token'))->get()) > 0) {
             $token = Input::get('token');
             $response['token'] = $token;
             $online_user = OnlineUsers::where('token', $token)->first();
             $response['in_conversation'] = 1;
             $response['conversation_closed'] = 0;
             $response['thread_id'] = $online_user->thread_id;
             $thread_geo_info = ThreadGeoInfo::where('thread_id', $online_user->thread_id)->first();
             $this->fillPage(Input::get('page'), $thread_geo_info);
             $response['user_id'] = $online_user->user_id;
             $response['messages'] = MessageThread::getClientMessages($online_user->thread_id, Input::get('last_message_id'));
         } else {
             $response['in_conversation'] = 0;
             $response['token'] = "";
             $response['messages'] = [];
             $response['conversation_closed'] = 0;
             //Is conversation already closed
             if (sizeof(ClosedConversations::where('thread_id', Input::get('thread_id'))->get()) > 0) {
                 $response['success_msg'] = trans('msgs.thanks_for_contacting_support');
                 $response['token'] = 0;
                 $response['in_conversation'] = 1;
                 $response['conversation_closed'] = 1;
                 $response['thread_id'] = 0;
                 $response['user_id'] = 0;
             }
         }
     }
     return $this->send($response);
 }
 public function online()
 {
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $user_ids = OperatorsDepartment::where('department_id', $department->id)->lists('user_id');
     } else {
         $group = Groups::where("name", "operator")->first();
         $user_ids = UsersGroups::where("group_id", $group->id)->lists("user_id");
     }
     if (sizeof($user_ids) > 0) {
         $this->data["operators"] = User::whereIn("id", $user_ids)->where("is_online", 1)->get();
     } else {
         $this->data["operators"] = [];
     }
     foreach ($this->data["operators"] as $operator) {
         $department_id = OperatorsDepartment::where('user_id', $operator->id)->pluck("department_id");
         $department = Department::find($department_id);
         $company = Company::find($department->company_id);
         $operator->department = $department;
         $operator->company = $company;
     }
     $this->data['permissions'] = Permissions::all();
     $this->data['departments'] = Department::all();
     return View::make('operators.all', $this->data);
 }