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);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public function conversationsRefresh()
 {
     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->id;
             $single_conversation[] = $online->user->name;
             $single_conversation[] = $online->user->email;
             $single_conversation[] = isset($online->operator) ? $online->operator->name : "<label class='label label-warning'>" . trans('msgs.none') . "</label>";
             $single_conversation[] = \KodeInfo\Utilities\Utils::prettyDate($online->requested_on, true);
             $single_conversation[] = \KodeInfo\Utilities\Utils::prettyDate($online->started_on, true);
             $single_conversation[] = $online->locked_by_operator == 1 ? "<label class='label label-warning'>" . trans('msgs.yes') . "</label>" : "<label class='label label-primary'>" . trans('msgs.no') . "</label>";
             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>';
             }
             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>';
             }
             if (isset($online->operator) && $online->operator->id != Auth::user()->id) {
                 $single_conversation[] = '<td><a disabled class="btn btn-success btn-sm"> <i class="icon-lock3"></i> ' . trans('msgs.accept') . ' </a></td>';
             }
             $single_conversation[] = '<td><a href="/conversations/transfer/' . $online->id . '" class="btn btn-warning btn-sm"> <i class="icon-share3"></i> ' . trans('msgs.transfer') . ' </a></td>';
             $single_conversation[] = '<td><a href="/conversations/close/' . $online->thread_id . '" class="btn btn-danger btn-sm"> <i class="icon-lock3"></i> ' . trans('msgs.close') . ' </a></td>';
             $conversations_arr[] = $single_conversation;
         }
     }
     return json_encode(['aaData' => $conversations_arr]);
 }
Exemplo n.º 4
0
        return Redirect::to('/login');
    }
});
Route::filter('admin', function () {
    //Someone is loggedin maybe admin / customer
    if (Auth::check()) {
        if (!\KodeInfo\Utilities\Utils::isAdmin(Auth::user()->id)) {
            Session::flash('error_msg', trans('msgs.access_denied_escalate_rights'));
            return Redirect::to('/dashboard');
        }
    } else {
        Session::flash('error_msg', trans('msgs.please_login_to_continue'));
        return Redirect::to('/login');
    }
});
Route::filter('operator', function () {
    if (Auth::check()) {
        if (!\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
            Session::flash('error_msg', trans('msgs.access_denied_escalate_rights'));
            return Redirect::to('/dashboard');
        }
    } else {
        Session::flash('error_msg', trans('msgs.please_login_to_continue'));
        return Redirect::to('/login');
    }
});
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
 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);
 }
Exemplo n.º 6
0
 static function object_to_array($obj)
 {
     if (is_object($obj)) {
         $obj = (array) $obj;
     }
     if (is_array($obj)) {
         $new = array();
         foreach ($obj as $key => $val) {
             $new[$key] = Utils::object_to_array($val);
         }
     } else {
         $new = $obj;
     }
     return $new;
 }
 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 update()
 {
     $v = Validator::make(["thread_id" => Input::get('thread_id'), "user_id" => Input::get('user_id'), "message" => Input::get('message'), "status" => Input::get('status'), 'attachment' => Input::get('attachment')], ["thread_id" => 'required', "user_id" => 'required', "message" => 'required', "status" => 'required', "attachment" => 'mimes:rar,zip|size:10000']);
     if ($v->passes()) {
         $ticket = Tickets::where('thread_id', Input::get('thread_id'))->first();
         $ticket->thread_id = Input::get('thread_id');
         $ticket->status = Input::get('status');
         $ticket->save();
         $thread_message = new ThreadMessages();
         $thread_message->thread_id = Input::get('thread_id');
         $thread_message->sender_id = Input::get('user_id');
         $thread_message->message = Input::get('message');
         $thread_message->save();
         $ticket_attachment = new TicketAttachments();
         $ticket_attachment->thread_id = Input::get('thread_id');
         $ticket_attachment->message_id = $thread_message->id;
         $ticket_attachment->has_attachment = Input::hasFile('attachment');
         $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : '';
         $ticket_attachment->save();
         if (!Utils::isBackendUser(Input::get('user_id'))) {
             $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
             $geo_info = ThreadGeoInfo::where('thread_id', Input::get('thread_id'))->first();
             $geo_info->ip_address = Input::get('ip', $geo_info->ip_address);
             $geo_info->country_code = Input::get('country', $geo_info->country_code);
             $geo_info->country = !empty($country) ? $country->countryName : "";
             $geo_info->provider = Input::get('provider');
             $geo_info->current_page = "";
             $geo_info->all_pages = "";
             $geo_info->save();
         }
         $customer = User::find($ticket->customer_id);
         $raw_settings = Settings::where('key', 'tickets')->pluck('value');
         $decode_settings = json_decode($raw_settings);
         if ($decode_settings->should_send_email_ticket_reply) {
             if (!$customer->is_online) {
                 $mailer_extra = ['ticket' => $ticket, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'operator_message' => $thread_message];
                 $this->ticketMailer->updated($customer->email, $customer->name, $mailer_extra);
             }
         } else {
             $mailer_extra = ['ticket' => $ticket, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'operator_message' => $thread_message];
             $this->ticketMailer->updated($customer->email, $customer->name, $mailer_extra);
         }
         return json_encode(['result' => 1, 'errors' => trans('msgs.ticket_updated_success')]);
     } else {
         return json_encode(['result' => 0, 'errors' => \KodeInfo\Utilities\Utils::buildMessages($v->messages()->all())]);
     }
 }
 public function all()
 {
     $user_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();
         $department_ids = Department::where('company_id', $department->company_id)->lists('id');
         $user_ids = DepartmentAdmins::whereIn('department_id', $department_ids)->lists('user_id');
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $department = Department::where('id', $department_admin->department_id)->first();
         $department_ids = Department::where('company_id', $department->company_id)->lists('id');
         $user_ids = DepartmentAdmins::whereIn('department_id', $department_ids)->lists('user_id');
     } else {
         $group = Groups::where("name", "department-admin")->first();
         $user_ids = UsersGroups::where("group_id", $group->id)->lists("user_id");
     }
     if (sizeof($user_ids) > 0) {
         $this->data["admins"] = User::whereIn("id", $user_ids)->orderBy('id', 'desc')->get();
     } else {
         $this->data["admins"] = [];
     }
     foreach ($this->data["admins"] as $admin) {
         $department_admin = DepartmentAdmins::where('user_id', $admin->id)->first();
         if (!empty($department_admin)) {
             $admin->department = Department::find($department_admin->department_id);
         }
         $company_id = CompanyDepartmentAdmins::where("user_id", $admin->id)->pluck('company_id');
         $admin->company = Company::find($company_id);
     }
     return View::make('department_admins.all', $this->data);
 }
 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);
 }