Пример #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
 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);
 }