コード例 #1
0
 public function return_view()
 {
     if (\Auth::check()) {
         return \View::make('add_delete')->with('roles_present', Roles::all())->with('operations_present', Operations::all())->with('resources_present', Resources::all());
     } else {
         \Session::flash('status', 'Please login!');
         return redirect('login');
     }
 }
コード例 #2
0
ファイル: RolesController.php プロジェクト: SAEMA/project
 public function update_roles(Request $request)
 {
     #acl work to check if the user is allowed to perform the updation
     #---------  extract the name of the file
     $path_parts = pathinfo($_SERVER['REQUEST_URI']);
     $resource_name = $path_parts['filename'];
     #--------- get the id of the role
     $resource_id = Resources::where('name', $resource_name)->first();
     #---------  get the user's privilegeid
     $user_type_id = \Auth::user()->privilegesid;
     #--------- get operationid from privileges where rolesid and resourceid match
     $get_info = array();
     $get_info = Privileges::where('rolesid', $user_type_id)->where('resourceid', $resource_id->id)->get();
     #---------  get id of update from operations table
     $update_id = Operations::where('actions', 'update')->first();
     #--------giving $value a default value
     $value = "";
     #-------- forecah loop for matching the data
     foreach ($get_info as $info) {
         if ($info->operationid == $update_id->id) {
             $value = "yes";
         }
     }
     #--------checking if $value is empty or not
     if ($value != "") {
         //===========================acl completed
         $username = $request->update;
         $reassign = $request->reassign;
         #-------query to get the id
         $type_id = DB::table('roles')->where('type', $reassign)->first();
         #-------query to update the user's table for the respective user
         DB::table('users')->where('name', $username)->update(['privilegesid' => $type_id->id]);
         return Redirect::to('roles')->with('message_for_roles', 'Successful update!');
     } else {
         return Redirect::to('roles')->with('message_for_roles', 'Extremely sorry you dont have permissions!');
     }
 }
コード例 #3
0
ファイル: PrivilegeController.php プロジェクト: SAEMA/project
 public function send_data(Request $request)
 {
     #----------- get the role name
     $arr = array();
     $arr['role_name'] = $request->selected;
     #----------- fetch the id of that role
     $id = Roles::where('type', $arr['role_name'])->first();
     #---------- fetch the operations and id of the operations
     $operations = Operations::all()->sort();
     #----------  fetch resources and id of resources
     $resources = Resources::all();
     #---------- for counting the number of rows that match the condition
     $count = Privileges::where('rolesid', $id->id)->count();
     #---------- fetching data upto count
     $privileges = Privileges::where('rolesid', $id->id)->take($count)->get();
     $str = "<div class = 'table'>";
     #----------  now loop that consists of other loops
     #----------  it loops around the number of resources
     foreach ($resources as $resource_info) {
         $i = 0;
         $str .= "<div class='row'>";
         $str .= "<br>" . "<div class='col-lg-4 '>";
         $str .= $resource_info->name . ":---->";
         $str .= "</div>";
         $oper_info = array();
         if (!empty($privileges)) {
             #--------to decide how many privileges will be there for a particular resource
             foreach ($privileges as $priv_info) {
                 if ($priv_info->resourceid == $resource_info->id) {
                     $oper_info[$i] = $priv_info->operationid;
                     $i++;
                 }
             }
             sort($oper_info);
             $number_of_actions = 0;
             $count_array = count($oper_info);
             $a = array();
             #------------it is necessary to check for non empty values
             if (!empty($oper_info)) {
                 foreach ($operations as $key => $value) {
                     $str .= "<div class='col-lg-2 '>";
                     if ($number_of_actions < $count_array && $value->id == $oper_info[$number_of_actions]) {
                         $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" checked = "checked" >-----';
                         if ($number_of_actions < $count_array) {
                             $number_of_actions++;
                         }
                     } else {
                         $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" >-----';
                     }
                     $str .= "</div>";
                 }
             } else {
                 foreach ($operations as $key => $value) {
                     $str .= "<div class='col-lg-2 '>";
                     $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" >-----';
                     $str .= "</div>";
                 }
             }
         }
         $str .= "<br>";
         $str .= "</div>";
     }
     $str .= '</div>';
     return response()->json($str);
 }