Inheritance: extends Controller
 public function UploadCampaign(Request $request)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CAMPAIGN', $this->permission)) {
             if ($request->hasFile('upload')) {
                 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) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($advertiser_obj) {
                     $destpath = public_path();
                     $extension = $request->file('upload')->getClientOriginalExtension();
                     // getting image extension
                     $fileName = str_random(32) . '.' . $extension;
                     $request->file('upload')->move($destpath . '/cdn/test/', $fileName);
                     Config::set('excel.import.startRow', 12);
                     $upload = Excel::load('public/cdn/test/' . $fileName, function ($reader) {
                     })->get();
                     $t = array();
                     foreach ($upload[0] as $key => $value) {
                         array_push($t, $key);
                     }
                     if ($t[1] != 'name' or $t[2] != 'max_impression' or $t[3] != 'daily_max_impression' or $t[4] != 'max_budget' or $t[5] != 'daily_max_budget' or $t[6] != 'cpm' or $t[7] != 'advertiser_domain_name' or $t[8] != 'status' or $t[9] != 'start_date' or $t[10] != 'end_date') {
                         File::delete($destpath . '/cdn/test/' . $fileName);
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please be sure that file is correct'])->withInput();
                     }
                     $bad_input = array();
                     $count = 0;
                     //                        return dd();
                     foreach ($upload as $test) {
                         $flg = 0;
                         $campaign = new Campaign();
                         if ($test['name'] == '' or $test['max_impression'] == '' or $test['daily_max_impression'] == '' or $test['max_budget'] == '' or $test['daily_max_budget'] == '' or $test['cpm'] == '' or $test['advertiser_domain_name'] == '' or $test['status'] == '' or $test['status'] == '' or $test['end_date'] == '') {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (!is_numeric($test['max_impression']) or !is_numeric($test['daily_max_impression']) or !is_numeric($test['max_budget']) or !is_numeric($test['daily_max_budget']) or !is_numeric($test['cpm'])) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (strcasecmp($test['status'], 'active') != 0 and strcasecmp($test['status'], 'inactive') != 0) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         $campaign->name = $test['name'];
                         $campaign->max_impression = $test['max_impression'];
                         $campaign->daily_max_impression = $test['daily_max_impression'];
                         $campaign->max_budget = $test['max_budget'];
                         $campaign->daily_max_budget = $test['daily_max_budget'];
                         $campaign->cpm = $test['cpm'];
                         $campaign->start_date = $test['start_date'];
                         $campaign->end_date = $test['end_date'];
                         $campaign->advertiser_domain_name = $test['advertiser_domain_name'];
                         $campaign->status = ucwords(strtolower($test['status']));
                         $campaign->advertiser_id = $request->input('advertiser_id');
                         //                            return dd('dd1');
                         $count++;
                         $campaign->save();
                     }
                     $audit = new AuditsController();
                     $audit->store('campaign', 0, $count, 'bulk_add');
                     $msg = "Campaigns added successfully";
                     if (count($bad_input) > 0) {
                         $msg .= " exept: ";
                         foreach ($bad_input as $index) {
                             $msg .= $index . ',';
                         }
                     }
                     return Redirect::back()->withErrors(['success' => true, 'msg' => $msg]);
                 }
                 return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select Advertiser First'])->withInput();
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select a file'])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('/user/login'));
 }
 public function ChangeStatus($id)
 {
     if (Auth::check()) {
         if (User::isSuperAdmin()) {
             $entity = Inventory::find($id);
         }
         if ($entity) {
             $data = array();
             $audit = new AuditsController();
             if ($entity->status == 'Active') {
                 array_push($data, 'status');
                 array_push($data, $entity->status);
                 array_push($data, 'Inactive');
                 $entity->status = 'Inactive';
                 $msg = 'disable';
             } elseif ($entity->status == 'Inactive') {
                 array_push($data, 'status');
                 array_push($data, $entity->status);
                 array_push($data, 'Active');
                 $entity->status = 'Active';
                 $msg = 'actived';
             }
             $audit->store('inventory', $id, $data, 'edit');
             $entity->save();
             return $msg;
         }
         return 'please Select your Client';
     }
     return Redirect::to(url('user/login'));
 }
 public function jqgrid(Request $request)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_ADVERTISER', $this->permission)) {
             $validate = \Validator::make($request->all(), ['name' => 'required']);
             if ($validate->passes()) {
                 $adver_id = substr($request->input('id'), 3);
                 if (User::isSuperAdmin()) {
                     $adver = Advertiser::find($adver_id);
                 } else {
                     $usr_company = $this->user_company();
                     $adver = Advertiser::whereHas('GetClientID', function ($p) use($usr_company) {
                         $p->whereIn('user_id', $usr_company);
                     })->with('Campaign')->with('Model')->with('GeoSegment')->with('BWList')->with('Creative')->with('GetClientID')->find($adver_id);
                 }
                 if ($adver) {
                     $data = array();
                     $audit = new AuditsController();
                     if ($adver->name != $request->input('name')) {
                         array_push($data, 'Name');
                         array_push($data, $adver->name);
                         array_push($data, $request->input('name'));
                         $adver->name = $request->input('name');
                     }
                     $audit->store('advertiser', $adver_id, $data, 'edit');
                     $adver->save();
                     return $msg = ['success' => true, 'msg' => "your Advertiser name Saved successfully"];
                 }
                 return $msg = ['success' => false, 'msg' => "Please Select an Advertiser First"];
             }
             return $msg = ['success' => false, 'msg' => "Please fill all Fields"];
         }
         return $msg = ['success' => false, 'msg' => "You don't have permission"];
     }
     return Redirect::to(url('user/login'));
 }
 public function ChangeStatus($id)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_GEOSEGMENTLIST', $this->permission)) {
             if (User::isSuperAdmin()) {
                 $entity = GeoSegmentList::find($id);
             } else {
                 $usr_company = $this->user_company();
                 $entity = GeoSegmentList::whereHas('getAdvertiser', function ($q) use($usr_company) {
                     $q->whereHas('GetClientID', function ($p) use($usr_company) {
                         $p->whereIn('user_id', $usr_company);
                     });
                 })->find($id);
             }
             if ($entity) {
                 $data = array();
                 $audit = new AuditsController();
                 if ($entity->status == 'Active') {
                     array_push($data, 'status');
                     array_push($data, $entity->status);
                     array_push($data, 'Inactive');
                     $entity->status = 'Inactive';
                     $msg = 'disable';
                 } elseif ($entity->status == 'Inactive') {
                     array_push($data, 'status');
                     array_push($data, $entity->status);
                     array_push($data, 'Active');
                     $entity->status = 'Active';
                     $msg = 'actived';
                 }
                 $audit->store('geosegment', $id, $data, 'edit');
                 $entity->save();
                 return $msg;
             }
             return 'please Select your Client';
         }
         return "You don't have permission";
     }
     return Redirect::to(url('user/login'));
 }
Example #5
0
 public function jqgrid(Request $request)
 {
     //return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_USER', $this->permission)) {
             $validate = \Validator::make($request->all(), ['name' => 'required']);
             if ($validate->passes()) {
                 $user_id = substr($request->input('id'), 3);
                 if (User::isSuperAdmin()) {
                     $user = User::find($user_id);
                 } else {
                     $usr_company = $this->user_company();
                     $user = User::where('company_id', Auth::user()->company_id)->find($user_id);
                     if (!$user) {
                         return $msg = ['success' => false, 'msg' => "Some things went wrong"];
                     }
                 }
                 if ($user) {
                     $data = array();
                     $audit = new AuditsController();
                     if ($user->name != $request->input('name')) {
                         array_push($data, 'Name');
                         array_push($data, $user->name);
                         array_push($data, $request->input('name'));
                         $user->name = $request->input('name');
                     }
                     $audit->store('user', $user_id, $data, 'edit');
                     $user->save();
                     return $msg = ['success' => true, 'msg' => "your User Saved successfully"];
                 }
                 return $msg = ['success' => false, 'msg' => "Please Select a User First"];
             }
             return $msg = ['success' => false, 'msg' => "Please Check your field"];
         }
         return $msg = ['success' => false, 'msg' => "You don't have permission"];
     }
     return Redirect::to(url('/user/login'));
 }
Example #6
0
 public function ChangeStatus($id)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CLIENT', $this->permission)) {
             $client_id = $id;
             if (User::isSuperAdmin()) {
                 $client = Client::find($client_id);
             } else {
                 $usr_company = $this->user_company();
                 $client = Client::whereIn('user_id', $usr_company)->find($id);
             }
             if ($client) {
                 $data = array();
                 $audit = new AuditsController();
                 if ($client->status == 'Active') {
                     array_push($data, 'status');
                     array_push($data, $client->status);
                     array_push($data, 'Inactive');
                     $client->status = 'Inactive';
                     $msg = 'disable';
                 } elseif ($client->status == 'Inactive') {
                     array_push($data, 'status');
                     array_push($data, $client->status);
                     array_push($data, 'Active');
                     $client->status = 'Active';
                     $msg = 'actived';
                 }
                 $audit->store('client', $client_id, $data, 'edit');
                 $client->save();
                 return $msg;
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('user/login'));
 }
Example #7
0
 public function getAudit($id, $entity_id = null)
 {
     if (Auth::check()) {
         $query = '1';
         switch ($id) {
             case 'user':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'user' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'user')";
                 }
                 break;
             case 'company':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'company' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'company')";
                 }
                 break;
             case 'inventory':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'inventory' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'inventory')";
                 }
                 break;
             case 'client':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'client' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'client')";
                 }
                 break;
             case 'advertiser':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'advertiser' and entity_id = '" . $entity_id . "') or (entity_type = 'advertiser_model_map' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'advertiser' or entity_type = 'advertiser_model_map')";
                 }
                 break;
             case 'campaign':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'campaign' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'campaign')";
                 }
                 break;
             case 'creative':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'creative' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'creative')";
                 }
                 break;
             case 'offer':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'offer' and entity_id = '" . $entity_id . "') or (entity_type = 'offer_pixel_map' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'offer' or entity_type = 'offer_pixel_map')";
                 }
                 break;
             case 'pixel':
                 if (!is_null($entity_id)) {
                     $query .= " and (entity_type = 'pixel' and entity_id = '" . $entity_id . "')";
                 } else {
                     $query .= " and (entity_type = 'pixel')";
                 }
                 break;
             case 'targetgroup':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'targetgroup' and entity_id = '" . $entity_id . "')\n                        or (entity_type = 'targetgroup_creative_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_geolocation_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_segment_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_geosegment_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_bwlist_map' and after_value='" . $entity_id . "' )\n                        or (entity_type = 'targetgroup_bidprofile_map' and after_value='" . $entity_id . "' ))";
                 } else {
                     $query .= " and (entity_type = 'targetgroup')";
                 }
                 break;
             case 'geosegment':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'geosegment' and entity_id = '" . $entity_id . "') or (entity_type = 'geosegmententrie' and after_value ='" . $entity_id . "') )";
                 } else {
                     $query .= " and (entity_type = 'geosegment')";
                 }
                 break;
             case 'bwlist':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'bwlist' and entity_id = '" . $entity_id . "') or (entity_type = 'bwlistentrie' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'bwlist' or entity_type = 'bwlistentrie')";
                 }
                 break;
             case 'bid_profile':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'bid_profile' and entity_id = '" . $entity_id . "') or (entity_type = 'bid_profile_entry' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'bid_profile' or entity_type = 'bid_profile_entry')";
                 }
                 break;
             case 'model':
                 if (!is_null($entity_id)) {
                     $query .= " and ((entity_type = 'modelTable' and entity_id = '" . $entity_id . "') or (entity_type = 'negative_offer_model' and after_value = '" . $entity_id . "') or (entity_type = 'positive_offer_model' and after_value = '" . $entity_id . "')) ";
                 } else {
                     $query .= " and (entity_type = 'modelTable' or entity_type = 'negative_offer_model' or entity_type = 'positive_offer_model')";
                 }
                 break;
             case 'user_id':
                 $user_id = Auth::user()->id;
                 $query .= " and (user_id = '" . $user_id . "')";
                 break;
         }
         if (User::isSuperAdmin()) {
             $audit = Audits::with('getUser')->whereRaw($query)->orderBy('created_at', 'DESC')->get();
         } else {
             $usr_comp = $this->user_company();
             $audit = Audits::with('getUser')->whereIn('user_id', $usr_comp)->whereRaw($query)->whereIn('user_id', $usr_comp)->orderBy('created_at', 'DESC')->get();
         }
         $audit_obj = array();
         if ($audit) {
             $sub = new AuditsController();
             $audit_obj = $sub->SubAudit($audit);
         }
         return view('audit.template.all_audits')->with('audit_obj', $audit_obj);
     }
     return 'check ur login';
 }
 public function jqgrid(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (User::isSuperAdmin()) {
             $validate = \Validator::make($request->all(), ['name' => 'required']);
             if ($validate->passes()) {
                 switch ($request->input('oper')) {
                     case 'add':
                         $audit = new AuditsController();
                         $active = 'Inactive';
                         if ($request->input('active') == 'true') {
                             $active = 'Active';
                         }
                         $company = new Company();
                         $company->name = $request->input('name');
                         $company->save();
                         $audit->store('company', $company->id, null, 'add');
                         return $msg = ['success' => true, 'msg' => "your Company:cl{$company->id} Added successfully"];
                         break;
                     case 'edit':
                         $company_id = $request->input('id');
                         $company = Company::find($company_id);
                         if ($company) {
                             $data = array();
                             $audit = new AuditsController();
                             if ($company->name != $request->input('name')) {
                                 array_push($data, 'Name');
                                 array_push($data, $company->name);
                                 array_push($data, $request->input('name'));
                                 $company->name = $request->input('name');
                             }
                             $audit->store('company', $company_id, $data, 'edit');
                             $company->save();
                             return $msg = ['success' => true, 'msg' => "your Company:cl{$company_id} Saved saved successfully"];
                         }
                         break;
                 }
             }
         }
         return "don't have permission";
     }
     return Redirect::to(url('user/login'));
 }
Example #9
0
 public function creative_bulk(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CREATIVE', $this->permission)) {
             $validate = $this->validation($request);
             if ($validate->passes()) {
                 $usr_company = $this->user_company();
                 $audit = new AuditsController();
                 $audit_key = $audit->generateRandomString();
                 if ($request->input('advertiser_id') == 'all' and !$request->has('creative_list')) {
                     if ($request->input('client_id') == 'all') {
                         if (User::isSuperAdmin()) {
                             $creative_list = Creative::get(['id'])->toArray();
                         } else {
                             $creative_list = Creative::whereHas('getAdvertiser', function ($q) use($usr_company) {
                                 $q->whereHas('GetClientID', function ($p) use($usr_company) {
                                     $p->whereIn('user_id', $usr_company);
                                 });
                             })->get(['id'])->toArray();
                         }
                     } elseif ($request->input('client_id') != 'all') {
                         if (User::isSuperAdmin()) {
                             $creative_list = Creative::whereHas('getAdvertiser', function ($q) use($request) {
                                 $q->where('client_id', $request->input('client_id'));
                             })->get(['id'])->toArray();
                         } else {
                             ////////////////////////
                             $creative_list = Creative::whereHas('getAdvertiser', function ($q) use($usr_company, $request) {
                                 $q->whereHas('GetClientID', function ($p) use($usr_company, $request) {
                                     $p->where('id', $request->input('client_id'))->whereIn('user_id', $usr_company);
                                 });
                             })->get(['id'])->toArray();
                         }
                     }
                 } elseif ($request->input('advertiser_id') != 'all' and !$request->has('creative_list')) {
                     if (User::isSuperAdmin()) {
                         $creative_list = Creative::whereHas('getAdvertiser', function ($q) use($request) {
                             $q->where('id', $request->input('advertiser_id'));
                         })->get(['id'])->toArray();
                     } else {
                         ////////////////////////
                         $creative_list = Creative::whereHas('getAdvertiser', function ($q) use($usr_company, $request) {
                             $q->where('id', $request->input('advertiser_id'))->whereHas('GetClientID', function ($p) use($usr_company, $request) {
                                 $p->whereIn('user_id', $usr_company);
                             });
                         })->get(['id'])->toArray();
                     }
                 } else {
                     $creative_list = explode(',', $request->input('creative_list'));
                 }
                 if (count($creative_list) > 0) {
                     foreach ($creative_list as $index) {
                         $data = array();
                         if (!$request->has('creative_list')) {
                             $creative_id = $index['id'];
                             $creative = Creative::find($creative_id);
                         } else {
                             $creative_id = $index;
                             if (User::isSuperAdmin()) {
                                 $creative = Creative::find($creative_id);
                             } else {
                                 $usr_company = $this->user_company();
                                 $creative = Creative::whereHas('getAdvertiser', function ($q) use($usr_company) {
                                     $q->whereHas('GetClientID', function ($p) use($usr_company) {
                                         $p->whereIn('user_id', $usr_company);
                                     });
                                 })->find($creative_id);
                             }
                         }
                         if ($creative) {
                             if ($request->has('size_width') and $request->has('size_height')) {
                                 $size = $request->input('size_width') . 'x' . $request->input('size_height');
                             }
                             if ($request->input('name')) {
                                 array_push($data, 'Name');
                                 array_push($data, $request->input('name'));
                                 $creative->name = $request->input('name');
                             }
                             if ($request->has('active')) {
                                 $active = 'Inactive';
                                 if ($request->input('active') == 'on') {
                                     $active = 'Active';
                                 }
                                 array_push($data, 'Status');
                                 array_push($data, $active);
                                 $creative->status = $active;
                             }
                             if ($request->input('ad_type')) {
                                 array_push($data, 'Ad Type');
                                 array_push($data, $request->input('ad_type'));
                                 $creative->ad_type = $request->input('ad_type');
                             }
                             if ($request->has('api')) {
                                 array_push($data, 'API');
                                 array_push($data, json_encode($request->input('api')));
                                 $creative->api = json_encode($request->input('api'));
                             }
                             if ($request->input('advertiser_domain_name')) {
                                 array_push($data, 'Domain Name');
                                 array_push($data, $request->input('advertiser_domain_name'));
                                 $creative->advertiser_domain_name = $request->input('advertiser_domain_name');
                             }
                             if ($request->input('description')) {
                                 array_push($data, 'Description');
                                 array_push($data, $request->input('description'));
                                 $creative->description = $request->input('description');
                             }
                             if ($request->input('landing_page_url')) {
                                 array_push($data, 'Landing Page URL');
                                 array_push($data, $request->input('landing_page_url'));
                                 $creative->landing_page_url = $request->input('landing_page_url');
                             }
                             if ($request->input('preview_url')) {
                                 array_push($data, 'Preview URL');
                                 array_push($data, $request->input('preview_url'));
                                 $creative->preview_url = $request->input('preview_url');
                             }
                             if ($request->input('attributes')) {
                                 array_push($data, 'Attributes');
                                 array_push($data, $request->input('attributes'));
                                 $creative->attributes = $request->input('attributes');
                             }
                             if ($request->input('ad_tag')) {
                                 array_push($data, 'AD Tag');
                                 array_push($data, $request->input('ad_tag'));
                                 $creative->ad_tag = $request->input('ad_tag');
                             }
                             if (isset($size)) {
                                 array_push($data, 'Size');
                                 array_push($data, $size);
                                 $creative->size = $size;
                             }
                             $audit->store('creative', $creative_id, $data, 'bulk_edit', $audit_key);
                             $creative->save();
                         }
                     }
                     return Redirect::back()->withErrors(['success' => true, 'msg' => 'Creatives Edited Successfully']);
                 }
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => $validate->messages()->all()])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => 'dont have Edit Permission']);
     }
     return Redirect::to(url('/user/login'));
 }
Example #10
0
 public function jqgrid(Request $request)
 {
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_MODEL', $this->permission)) {
             $validate = \Validator::make($request->all(), ['name' => 'required']);
             if ($validate->passes()) {
                 $model_id = substr($request->input('id'), 3);
                 if (User::isSuperAdmin()) {
                     $modelTable = ModelTable::find($model_id);
                 } else {
                     $usr_company = $this->user_company();
                     $modelTable = ModelTable::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($model_id);
                 }
                 if ($modelTable) {
                     $data = array();
                     $audit = new AuditsController();
                     if ($modelTable->name != $request->input('name')) {
                         array_push($data, 'Name');
                         array_push($data, $modelTable->name);
                         array_push($data, $request->input('name'));
                         $modelTable->name = $request->input('name');
                     }
                     $audit->store('modelTable', $model_id, $data, 'edit');
                     $modelTable->save();
                     return $msg = ['success' => true, 'msg' => "your Model Saved successfully"];
                 }
                 return $msg = ['success' => false, 'msg' => "Please Select a Model First"];
             }
             return $msg = ['success' => false, 'msg' => "Please Check your field"];
         }
         return $msg = ['success' => false, 'msg' => "You don't have permission"];
     }
     return Redirect::to(url('/user/login'));
 }
 public function UploadCreative(Request $request)
 {
     if (Auth::check()) {
         if (in_array('ADD_EDIT_CREATIVE', $this->permission)) {
             if ($request->hasFile('upload')) {
                 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) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($advertiser_obj) {
                     $destpath = public_path();
                     $extension = $request->file('upload')->getClientOriginalExtension();
                     // getting image extension
                     $fileName = str_random(32) . '.' . $extension;
                     $request->file('upload')->move($destpath . '/cdn/test/', $fileName);
                     Config::set('excel.import.startRow', 12);
                     $upload = Excel::load('public/cdn/test/' . $fileName, function ($reader) {
                     })->get();
                     $t = array();
                     foreach ($upload[0] as $key => $value) {
                         array_push($t, $key);
                     }
                     if ($t[1] != 'name' or $t[2] != 'ad_tag' or $t[3] != 'landing_page_url' or $t[4] != 'preview_url' or $t[5] != 'size' or $t[6] != 'attributes' or $t[7] != 'advertiser_domain_name' or $t[8] != 'status' or $t[9] != 'api' or $t[10] != 'ad_type') {
                         File::delete($destpath . '/cdn/test/' . $fileName);
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please be sure that file is correct'])->withInput();
                     }
                     $bad_input = array();
                     $count = 0;
                     foreach ($upload as $test) {
                         $flg = 0;
                         $creative = new Creative();
                         if ($test['name'] == '' or $test['ad_tag'] == '' or $test['landing_page_url'] == '' or $test['preview_url'] == '' or $test['size'] == '' or $test['attributes'] == '' or $test['advertiser_domain_name'] == '' or $test['status'] == '' or $test['api'] == '' or $test['ad_type'] == '') {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (strcasecmp($test['status'], 'active') != 0 and strcasecmp($test['status'], 'inactive') != 0) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         $api = explode(',', $test['api']);
                         if (is_array($api)) {
                             foreach ($api as $index) {
                                 if (strcasecmp($index, 'VPAID_1.0') != 0 and strcasecmp($index, 'VPAID_2.0') != 0 and strcasecmp($index, 'MRAID-1') != 0 and strcasecmp($index, 'ORMMA') != 0 and strcasecmp($index, 'MRAID-2') != 0) {
                                     array_push($bad_input, $test['name']);
                                     $flg = 1;
                                 }
                             }
                             if ($flg == 1) {
                                 $flg = 0;
                                 continue;
                             }
                         } else {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         if (strcasecmp($test['ad_type'], 'IFRAME') != 0 and strcasecmp($test['ad_type'], 'JAVASCRIPT') != 0 and strcasecmp($test['ad_type'], 'XHTML_BANNER_AD') != 0 and strcasecmp($test['ad_type'], 'XHTML_TEXT_AD') != 0) {
                             array_push($bad_input, $test['name']);
                             return dd('ss2');
                             continue;
                         }
                         $size = explode('x', $test['size']);
                         if (!is_array($size) or count($size) != 2 or is_array($size) and count($size) == 2 and !is_numeric($size[0]) or is_array($size) and count($size) == 2 and !is_numeric($size[1])) {
                             array_push($bad_input, $test['name']);
                             continue;
                         }
                         $creative->name = $test['name'];
                         $creative->ad_tag = $test['ad_tag'];
                         $creative->landing_page_url = $test['landing_page_url'];
                         $creative->preview_url = $test['preview_url'];
                         $creative->size = $size[0] . 'x' . $size[1];
                         $creative->attributes = $test['attributes'];
                         $creative->advertiser_domain_name = $test['advertiser_domain_name'];
                         $creative->status = ucwords(strtolower($test['status']));
                         $creative->api = '[' . strtoupper(implode(',', $api)) . ']';
                         $creative->ad_type = strtoupper($test['ad_type']);
                         $creative->advertiser_id = $request->input('advertiser_id');
                         $creative->save();
                         $count++;
                     }
                     $audit = new AuditsController();
                     $audit->store('creative', 0, $count, 'bulk_add');
                     $msg = "Creatives added successfully";
                     if (count($bad_input) > 0) {
                         $msg .= " exept: ";
                         foreach ($bad_input as $index) {
                             $msg .= $index . ',';
                         }
                     }
                     return Redirect::back()->withErrors(['success' => true, 'msg' => $msg]);
                 }
                 return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select Advertiser First'])->withInput();
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select a file'])->withInput();
         }
         return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
     }
     return Redirect::to(url('/user/login'));
 }
 public function jqgrid(Request $request)
 {
     // TODO: must be in inventory
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_BIDPROFILE', $this->permission)) {
             //permission goes here
             $rules = array('domain' => 'required', 'bid_strategy' => 'required');
             if ($request->input('oper') == 'edit' or $request->input('oper') == 'del') {
                 $rules['bid_value'] = 'required';
             } else {
                 if ($request->input('bid_strategy') == 'Absolute' or $request->input('bid_strategy') == 1) {
                     $rules['bid_value'] = 'required';
                 } else {
                     $rules["bid_value1"] = 'required';
                 }
             }
             $validate = \Validator::make($request->all(), $rules);
             if ($validate->passes()) {
                 //                    return dd($request->input('parent_id'));
                 if (User::isSuperAdmin()) {
                     $bid_profile_obj = Bid_Profile::find($request->input('parent_id'));
                 } else {
                     $usr_company = $this->user_company();
                     $bid_profile_obj = Bid_Profile::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($request->input('parent_id'));
                     if (!$bid_profile_obj) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($bid_profile_obj) {
                     if (preg_match($this->pattern, $request->input('domain'))) {
                         //                            return dd($request->all());
                         $audit = new AuditsController();
                         switch ($request->input('oper')) {
                             case 'add':
                                 $chk = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->get();
                                 foreach ($chk as $index) {
                                     if ($index->domain == $request->input('domain')) {
                                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'this name already existed !!!'])->withInput();
                                     }
                                 }
                                 $bid_profile_entry = new Bid_Profile_Entry();
                                 $bid_profile_entry->domain = $request->input('domain');
                                 $bid_profile_entry->bid_strategy = $request->input('bid_strategy');
                                 $bid_profile_entry->bid_profile_id = $request->input('parent_id');
                                 $bid_profile_entry->bid_value = $request->has('bid_value') ? $request->input('bid_value') : $request->input('bid_value1');
                                 $bid_profile_entry->save();
                                 $audit->store('bid_profile_entry', $bid_profile_entry->id, $request->input('parent_id'), 'add');
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Added"];
                                 break;
                             case 'edit':
                                 $bid_profile_entry = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->where('id', $request->input('id'))->first();
                                 if ($bid_profile_entry) {
                                     $data = array();
                                     if ($bid_profile_entry->domain != $request->input('domain')) {
                                         array_push($data, 'Domain');
                                         array_push($data, $bid_profile_entry->domain);
                                         array_push($data, $request->input('domain'));
                                         $bid_profile_entry->domain = $request->input('domain');
                                     }
                                     $bid_strategy = $request->input('bid_strategy') == 1 ? 'Absolute' : 'Percentage';
                                     //                                        return dd($bid_strategy);
                                     if ($bid_profile_entry->bid_strategy != $bid_strategy) {
                                         array_push($data, 'Bid Strategy');
                                         array_push($data, $bid_profile_entry->bid_strategy);
                                         array_push($data, $bid_strategy);
                                         $bid_profile_entry->bid_strategy = $bid_strategy;
                                     }
                                     if ($bid_profile_entry->bid_value != $request->input('bid_value')) {
                                         array_push($data, 'Bid Value');
                                         array_push($data, $bid_profile_entry->bid_value);
                                         array_push($data, $request->input('bid_value'));
                                         $bid_profile_entry->bid_value = $request->input('bid_value');
                                     }
                                     $audit->store('bid_profile_entry', $request->input('id'), $data, 'edit');
                                     $bid_profile_entry->save();
                                     return $msg = ['success' => true, 'msg' => "your Entry has been Edited"];
                                 }
                                 return 'some things went wrong!';
                                 break;
                             case 'del':
                                 $audit = new AuditsController();
                                 $d = array($request->input('id'), $request->input('parent_id'));
                                 $audit->store('bid_profile_entry', $request->input('id'), $d, 'del');
                                 Bid_Profile_Entry::where('id', $request->input('id'))->where('bid_profile_id', $request->input('parent_id'))->delete();
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Deleted"];
                                 break;
                         }
                     }
                     return $msg = ['success' => false, 'msg' => "PLZ enter valid Web site domain"];
                 }
                 return $msg = ['success' => false, 'msg' => "please select correct Bid Profile!"];
             }
             //return print_r($validate->messages());
             return $msg = ['success' => false, 'msg' => "please Check your fields"];
         }
     }
     return Redirect::to(url('/user/login'));
 }