/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $inputs = $request->all();
         unset($inputs['_token']);
         $device_tokens = Customer::where('platform', 'A')->lists('device_token');
         $is_sent = PnS::sendPnsToAndroidDevices($device_tokens, $inputs['body']);
         if ($is_sent) {
             $inputs['user_id'] = Auth::id();
             Notification::create($inputs);
         }
         return redirect()->to('/crm/notification/')->withMessage(Generate::success_message('Success', 'Sent Successfully'));
     } catch (Exception $e) {
         return redirect()->to('/crm/notification/')->withMessage(Generate::error_message('Failed', $e->getMessage()));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(CreatePostRequest $request)
 {
     try {
         $inputs = $request->all();
         unset($inputs['_token']);
         $photo = $request->file('photo');
         if ($photo) {
             //Upload Image
             $uploaded_path = FileUpload::upload($photo);
             $inputs['photo'] = $uploaded_path;
         }
         Post::create($inputs);
         return redirect()->to('/crm/post/')->withMessage(Generate::success_message('Success', 'Created Successfully'));
     } catch (Exception $e) {
         return redirect()->to('/crm/post/')->withMessage(Generate::error_message('Failed', $e->getMessage()));
     }
 }
 public function processChangePassword(Request $request)
 {
     try {
         $user_id = $request->get('user_id');
         $current_password = $request->get('current_password');
         $new_password = $request->get('new_password');
         $new_password_retype = $request->get('new_password_retype');
         if ($new_password != $new_password_retype) {
             return Redirect::to('/crm/profile')->withMessage(Generate::error_message('Fail', 'New password and retype password do not match.'));
         }
         $user = User::find($user_id);
         if (Hash::check($current_password, $user->password)) {
             $user->password = Hash::make($new_password);
             $user->save();
             return Redirect::to('/crm/profile')->withMessage(Generate::success_message('Success', 'Password Changed. Please login again.'));
         }
         return Redirect::to('/crm/profile')->withMessage(Generate::error_message('Fail', 'Wrong current password'));
     } catch (Exception $e) {
         return Redirect::to('/crm/profile')->withMessage(Generate::error_message('Fail', 'Failed to change password.'));
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     try {
         $inputs = $request->all();
         unset($inputs['_method']);
         unset($inputs['_token']);
         foreach ($inputs as $key => $value) {
             SysConfig::where('type', 'SystemPermissionPositionType')->where('key', $key)->update(['value' => $value]);
         }
         return Redirect::to('/crm/permission_pos_type')->withMessage(Generate::success_message('Success', 'Updated Successfully.'));
     } catch (Exception $e) {
         return Redirect::to('/crm/permission_pos_type')->withMessage(Generate::error_message('Fail', 'Failed to update.'));
     }
 }
示例#5
0
 public function assignRolePermission($rid)
 {
     $inputs = Input::all();
     //get all the permission that this role has.
     $current_permissions_id = Role::getPermissionsAssignedToCurrentRole($rid);
     foreach ($inputs as $key => $value) {
         $is_permission_added_in_current_role = false;
         if ($key == '_token') {
             continue;
         }
         $permission_id = explode("_", $key)[1];
         $is_permission_added_in_current_role = in_array($permission_id, $current_permissions_id);
         if (!$is_permission_added_in_current_role && $value == 'on') {
             echo 'ON';
             print_r($current_permissions_id);
             echo $permission_id . '->';
             echo $is_permission_added_in_current_role;
             echo '<br>';
             //if the permission is not exist, create new permission role record.
             $new_permission = new PermissionRole();
             $new_permission->role_id = $rid;
             $new_permission->permission_id = $permission_id;
             $new_permission->order = '1';
             $new_permission->save();
             //else since it is already exist, and it is on, no need to do anything.
         } else {
             if ($is_permission_added_in_current_role) {
                 if ($value == 'off') {
                     echo 'OFF';
                     print_r($current_permissions_id);
                     echo $permission_id . '->';
                     echo $is_permission_added_in_current_role;
                     echo '<br>';
                     //if permission record is exist (true), find and do a delete.
                     $perm = PermissionRole::where('role_id', $rid)->where('permission_id', $permission_id)->first();
                     if (isset($perm)) {
                         $perm->delete();
                     }
                     //else it is not exist, do nothing.
                 } else {
                     if ($value == 'on') {
                         //echo 'ON'; print_r ($current_permissions_id); echo $permission_id.'->'; echo $is_permission_added_in_current_role; echo '<br>';
                         //do nothing ....
                     }
                 }
             }
         }
     }
     //return '';
     return Redirect::to('/crm/role/' . $rid)->withMessage(Generate::message('Success', 'New Permissions Applied, please relogin to see the changes.'));
 }
 public function removeRoleUser($role_id, $user_id)
 {
     try {
         $user = User::find($user_id);
         $user->role_id = null;
         $user->save();
         return Redirect::to("/crm/role/{$role_id}")->withMessage(Generate::success_message('Success', 'Removed User Successfully'));
     } catch (Exception $e) {
         return Redirect::to("/crm/role/{$role_id}")->withMessage(Generate::error_message('Fail', 'Failed to remove user.'));
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     try {
         User::find($id)->delete();
         return Redirect::to('/crm/user/')->withMessage(Generate::success_message('Success', 'Deleted Successfully.'));
     } catch (Exception $e) {
         return Redirect::to('/crm/user/')->withMessage(Generate::error_message('Failed', $e->getMessage()));
     }
 }
 public function storePermission($fid, CreatePermissionFromRequest $request)
 {
     try {
         $inputs = Input::all();
         unset($inputs['_method']);
         unset($inputs['_token']);
         Permission::create($inputs);
         //redirect to the url you want along with the message
         return Redirect::to('/crm/feature/' . $fid)->withMessage(Generate::success_message('Success', 'Created Successfully.'));
     } catch (Exception $e) {
         //redirect to the url you wan along with the message
         return Redirect::to('/crm/feature/' . $fid)->withMessage(Generate::error_message('Fail', 'Failed to create.'));
     }
 }
示例#9
0
 public static function getNavTop($id)
 {
     $home_url = "";
     $company_name = "";
     $company_logo = "";
     $return = [];
     $home_url = SysConfig::where('type', 'SystemSettings')->where('key', 'crm-home-url')->first()->value;
     $company_name = SysConfig::where('type', 'SystemSettings')->where('key', 'crm-company-name')->first()->value;
     $company_logo = SysConfig::where('type', 'SystemSettings')->where('key', 'crm-company-logo-sm')->first()->value;
     //get user
     $user = User::find($id);
     $member_since = date_format($user->created_at, 'Y-M-d');
     $profile_functions = '/crm/profile';
     //for the data schema for the top navigation
     $return = ['home_url' => $home_url, 'company_name' => $company_name, 'company_logo' => $company_logo, 'user_image' => $user->display_image, 'user_name' => $user->display_name, 'member_since' => $member_since, 'profile_functions' => $profile_functions];
     return Generate::returnMsg('200', 'Success', $return);
 }