Ejemplo n.º 1
0
 public function add_bwlist(Request $request)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_BWLIST', $this->permission)) {
             $validate = \Validator::make($request->all(), ['name' => 'required']);
             if ($validate->passes()) {
                 if (User::isSuperAdmin()) {
                     $advertiser_obj = Advertiser::with('GetClientID')->find($request->input('advertiser_id'));
                 } else {
                     $usr_company = $this->user_company();
                     $advertiser_obj = Advertiser::whereHas('GetClientID', function ($p) use($usr_company) {
                         $p->whereIn('user_id', $usr_company);
                     })->find($request->input('advertiser_id'));
                 }
                 if ($advertiser_obj) {
                     $chk = BWList::where('advertiser_id', $request->input('advertiser_id'))->get();
                     //                        return dd($chk);
                     $flg = 0;
                     foreach ($chk as $index) {
                         if ($index->name == $request->input('name') and $index->list_type == $request->input('list_type')) {
                             $flg = 1;
                         }
                     }
                     if ($flg == 0) {
                         $active = 'Inactive';
                         if ($request->input('active') == 'on') {
                             $active = 'Active';
                         }
                         $key = new AuditsController();
                         $key = $key->generateRandomString();
                         $audit = new AuditsController();
                         $bwlist = new BWList();
                         $bwlist->name = $request->input('name');
                         $bwlist->status = $active;
                         $bwlist->list_type = $request->input('list_type');
                         $bwlist->advertiser_id = $request->input('advertiser_id');
                         $bwlist->save();
                         $audit->store('bwlist', $bwlist->id, null, 'add', $key);
                         $entries = explode(',', $request->input('domain_name'));
                         foreach ($entries as $index) {
                             $bwlistentries = new BWEntries();
                             $bwlistentries->domain_name = $index;
                             $bwlistentries->bwlist_id = $bwlist->id;
                             $bwlistentries->save();
                             $audit->store('bwlistentrie', $bwlistentries->id, null, 'add', $key);
                         }
                         return Redirect::to(url('/client/cl' . $advertiser_obj->GetClientID->id . '/advertiser/adv' . $request->input('advertiser_id') . '/bwlist/bwl' . $bwlist->id . '/edit'))->withErrors(['success' => true, 'msg' => "B/W List added successfully"]);
                     }
                     return Redirect::back()->withErrors(['success' => false, 'msg' => 'this name already existed !!!'])->withInput();
                 }
                 return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => $validate->messages()->all()])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('/user/login'));
 }