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); }
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(); } elseif (\KodeInfo\Utilities\Utils::isCustomer(Auth::user()->id)) { $company_customer = CompanyCustomers::where('customer_id', Auth::user()->id)->first(); $this->data['company'] = Company::where('id', $company_customer->company_id)->first(); $this->data["operator"] = User::where('id', Auth::user()->id)->first(); $this->data['departments'] = Department::where('company_id', $company_customer->company_id)->get(); } else { $companies = Company::all(); if (sizeof($companies) > 0) { $departments = Department::where('company_id', $companies[0]->id)->get(); } else { $departments = []; } $this->data['companies'] = $companies; $this->data['departments'] = $departments; } return View::make('tickets.create', $this->data); }
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; }
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(); $permissions_keys = explode(",", $this->data['department']); $permissions = Permissions::whereIn('key', $permissions_keys)->get(); $this->data['permissions'] = $permissions; } 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(); $permissions_keys = explode(",", $this->data['department']); $permissions = Permissions::whereIn('key', $permissions_keys)->get(); $this->data['permissions'] = $permissions; } else { $companies = Company::all(); $this->data['companies'] = $companies; if (sizeof($companies) > 0) { $department = Department::where("company_id", $companies[0]->id)->first(); if (empty($department)) { Session::flash('error_msg', trans('msgs.create_department_before_adding_operators')); return Redirect::back(); } $permissions_keys = explode(",", $department->permissions); $permissions = Permissions::whereIn('key', $permissions_keys)->get(); $this->data['permissions'] = $permissions; $this->data['departments'] = Department::where("company_id", $companies[0]->id)->get(); } else { $this->data['permissions'] = []; $this->data['departments'] = []; } } $this->data["countries"] = DB::table("countries")->remember(60)->get(); $this->data['timezones'] = Config::get("timezones"); return View::make('operators.create', $this->data); }
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); }
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 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); }