예제 #1
0
 static function getUpdatedFields($is_fake = false, $ticket_id = 0, $msg_id = 0)
 {
     if (!$is_fake) {
         $ticket = Tickets::where('id', $ticket_id)->first();
         $thread_message = ThreadMessages::where('id', $msg_id)->first();
         $ticket_attachment = TicketAttachments::where('message_id', $msg_id)->first();
         $customer = User::where('id', $ticket->customer_id)->first();
         $operator = User::where('id', $ticket->operator_id)->first();
         $company = Company::where('id', $ticket->company_id)->first();
         $department = Department::where('id', $ticket->department_id)->first();
         $receiver = Input::get('user_id') == $ticket->operator_id ? $customer : $operator;
         $mailer_extra = ['ticket_id' => $ticket->id, 'ticket_subject' => $ticket->subject, 'ticket_description' => $ticket->description, 'ticket_status' => $ticket->status, 'ticket_status_txt' => self::resolveStatus($ticket->status), 'ticket_priority' => $ticket->priority, 'ticket_priority_txt' => self::resolveStatus($ticket->priority), 'company_name' => $company->name, 'company_description' => $company->description, 'company_domain' => $company->domain, 'company_logo' => $company->logo, 'department_name' => $department->name, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'updated_message' => $thread_message->message, 'receiver_name' => $receiver->name, 'receiver_email' => $receiver->email];
     } else {
         $mailer_extra = ['ticket_id' => 1, 'ticket_subject' => "How can i use contact us form", 'ticket_description' => "Hi , Sir how can i use contact us form", 'ticket_status' => 1, 'ticket_status_txt' => self::resolveStatus(1), 'ticket_priority' => 1, 'ticket_priority_txt' => self::resolveStatus(1), 'company_name' => "KODEINFO", 'company_description' => "We are a small and dedicated team of designers/developers. This is our web design and development focused blog.We focus on pushing the boundaries of standards based web technologies.", 'company_domain' => "http://www.kodeinfo.com", 'company_logo' => "http://kodeinfo.com/img/shortlogo.png", 'department_name' => "General Queries", 'has_attachment' => false, 'attachment_path' => "", 'updated_message' => "This is a updated message from customer/operator", 'receiver_name' => "Imran", 'receiver_email' => "*****@*****.**"];
     }
     return $mailer_extra;
 }
 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 delete($thread_id)
 {
     Tickets::where('thread_id', $thread_id)->delete();
     TicketAttachments::where('thread_id', $thread_id)->delete();
     MessageThread::where('id', $thread_id)->delete();
     ThreadMessages::where('thread_id', $thread_id)->delete();
     ThreadGeoInfo::where('thread_id', $thread_id)->delete();
     RecentActivities::createActivity("Ticket deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name);
     Session::flash('success_msg', trans('msgs.ticket_deleted_success'));
     return Redirect::to('/tickets/all');
 }
 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 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');
 }