<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use Validator; use Redirect; class Vcategories extends Setup { public function __construct() { parent::__construct(); } public function view(Request $request) { if(check_user_access('view_assets_categories_right') === FALSE){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $assets_categories = DB::table('assets_categories')->where('branch',$branch_id); $assets_categories = $assets_categories->get(); $assets_categories = json_decode(json_encode($assets_categories),true); $this->data["pageData"] = $assets_categories; $this->data["title"] = print_lang($this->data["app_lang"],'mod_assets_cat_view_title'); $this->data["pageToLoad"] = "assets_categories/view.php"; $this->data["activeLink"] = "settings"; $this->load_view($this->data); } public function add(Request $request) { if(check_user_access('add_assets_categories_right') === FALSE){ Redirect::to('/')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_assets_cat_add_title'); $this->data["pageToLoad"] = "assets_categories/add.php"; $this->data["activeLink"] = "settings"; $this->load_view($this->data); } public function save(Request $request) { $validator = Validator::make($request->request->all(), [ 'name' => 'required', ]); $validator->validate(); $uid = getUniqueId('CPCT', 'assets_categories', 'uid'); $db_array = array( 'uid' => $uid, 'branch' => active_branch_id(), 'name' => $request->name, ); insert_table('assets_categories',$db_array); echo json_encode(array('status' => 'success', 'mood' => 'new', 'message_head' => print_lang($this->data["app_lang"],'mod_assets_cat_category_added'), 'message_body' => print_lang($this->data["app_lang"],'mod_assets_cat_save_successfully'))); } public function edit(Request $request, $uid) { if(check_user_access('edit_assets_categories_right') === FALSE){ Redirect::to('/')->send(); } $this->data["editing_data"] = fetch_table_where('assets_categories','uid',$uid,true); if(!is_array($this->data["editing_data"])){ Redirect::to('/assets-categories')->send(); } $this->data["title"] = print_lang($this->data["app_lang"],'mod_assets_cat_edit_title'); $this->data["pageToLoad"] = "assets_categories/edit.php"; $this->data["activeLink"] = "settings"; $this->load_view($this->data); } public function update(Request $request, $uid) { $validator = Validator::make($request->request->all(), [ 'name' => 'required', ]); $validator->validate(); $db_array = array( 'name' => $request->name, ); update_table('assets_categories','uid',$uid,$db_array); update_table('assets','type',$uid,['type_name' => $db_array['name']]); echo json_encode(array('status' => 'success', 'mood' => 'update', 'message_head' => print_lang($this->data["app_lang"],'mod_assets_cat_update'), 'message_body' => print_lang($this->data["app_lang"],'mod_assets_cat_update_successfully'))); } public function delete($uid) { if(check_user_access('delete_assets_categories_right') === FALSE){ Redirect::to('/')->send(); } delete_table('assets_categories','uid',$uid); echo json_encode(array('status' => 'success', 'mode' => 'deleted')); } }