<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use Validator; use Redirect; use View; use Hash; class Suggestions extends Setup { public function __construct() { parent::__construct(); } public function view(Request $request) { $user_role = Session::get('user_role'); if(is_customer_user() === FALSE AND $user_role != 'SUPERADMIN' AND $user_role != 'ADMIN'){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $clients = array(); $user = Session::get('user_id'); $customer = get_active_customer(); if(is_customer_user() == FALSE) { $suggestions = DB::table('suggestions')->where('branch',$branch_id); } else { $suggestions = DB::table('suggestions')->where('branch',$branch_id)->where('user',$user); } if(!empty($request->from)){ $suggestions->where('created_at','>=',get_true_date($request->from).' 00:00:00'); } if(!empty($request->to)){ $suggestions->where('created_at','<=',get_true_date($request->to).' 23:59:59'); } $suggestions = json_decode(json_encode($suggestions->get()),true); $this->data["pageData"] = $suggestions; $this->data["search_from"] = $request->from; $this->data["search_to"] = $request->to; $this->data["title"] = print_lang($this->data["app_lang"],'mod_suggestions_view_title'); $this->data["clients"] = set_array_keys(fetch_all_clients(),'uid'); $this->data["users"] = set_array_keys(fetch_table('users'),'uid'); $this->data["pageToLoad"] = "suggestions/view.php"; $this->data["activeLink"] = "suggestions"; $this->load_view($this->data); } public function add(Request $request) { if(is_customer_user() === FALSE){ Redirect::to('/')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_suggestions_add_title'); $this->data["pageToLoad"] = "suggestions/add.php"; $this->data["activeLink"] = "suggestions"; $this->load_view($this->data); } public function save(Request $request) { $validator = Validator::make($request->request->all(), [ 'details' => 'required', ]); $user = Session::get('user_id'); $customer = get_active_customer(); $uid = getUniqueId('SUGG', 'suggestions', 'uid'); $db_array = array( 'uid' => $uid, 'branch' => active_branch_id(), 'details' => $request->details, 'user' => $user, 'customer' => $customer, ); insert_table('suggestions',$db_array); echo json_encode(array('status' => 'success', 'mood' => 'new', 'message_head' => print_lang($this->data["app_lang"],'mod_suggestions_added'), 'message_body' => print_lang($this->data["app_lang"],'mod_suggestions_save_successfully'))); } public function edit(Request $request, $uid) { if(is_customer_user() === FALSE){ Redirect::to('/')->send(); } $this->data["editing_data"] = fetch_table_where('suggestions','uid',$uid,true); if(!is_array($this->data["editing_data"])){ Redirect::to('/suggestions')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_suggestions_edit_title'); $this->data["pageToLoad"] = "suggestions/edit.php"; $this->data["activeLink"] = "suggestions"; $this->load_view($this->data); } public function update(Request $request, $uid) { $validator = Validator::make($request->request->all(), [ 'details' => 'required', ]); $validator->validate(); $db_array = array( 'details' => $request->details, ); update_table('suggestions','uid',$uid,$db_array); echo json_encode(array('status' => 'success', 'mood' => 'update', 'message_head' => print_lang($this->data["app_lang"],'mod_suggestions_update'), 'message_body' => print_lang($this->data["app_lang"],'mod_suggestions_update_successfully'))); } public function delete($uid) { delete_table('suggestions','uid',$uid); echo json_encode(array('status' => 'success', 'mode' => 'deleted')); } }