/**
  *     handle form add/update agency
  *     @param  integer $id 
  */
 function postUpdate($id = 0)
 {
     // check validate
     $validate = Validator::make(Input::all(), $this->model->getUpdateRules(), $this->model->getUpdateLangs());
     if ($validate->passes()) {
         $campaignName = Input::get('campaign');
         $adFormatID = Input::get('ad_format_id');
         $adFormatName = AdFormatBaseModel::find($adFormatID)->name;
         $updateData = array('campaign_id' => Input::get('campaign_id'), 'ad_format_id' => $adFormatID, 'ad_type' => Input::get('ad_type'), 'width' => Input::get('width'), 'height' => Input::get('height'), 'source_url' => Input::get('source_url'), 'destination_url' => Input::get('destination_url'), 'flash_wmode' => Input::get('flash_wmode'), 'video_duration' => Input::get('video_duration'), 'video_linear' => Input::get('video_linear'), 'video_type_vast' => Input::get('video_type_vast'), 'video_wrapper_tag' => Input::get('video_wrapper_tag'), 'video_bitrate' => Input::get('video_bitrate'), 'video_impression_track' => Input::get('video_impression_track'), 'updated_by' => $this->user->id);
         if (!empty($campaignName) || !empty($adFormatName)) {
             $updateData['name'] = $campaignName . ' ' . $adFormatName;
         }
         if ($id == 0) {
             // INSERT
             $updateData['created_by'] = $this->user->id;
             if ($item = $this->model->create($updateData)) {
                 $this->data['id'] = $item->id;
                 return TRUE;
             }
         } else {
             // UPDATE
             // GET CURRENT ITEM
             $item = $this->model->with('flight')->find($id);
             if ($item) {
                 if ($this->model->where("id", $id)->update($updateData)) {
                     return TRUE;
                 }
             }
         }
     } else {
         $this->data['errors'] = $validate->messages();
     }
     return FALSE;
 }
 public static function getView($id)
 {
     $view = "";
     $ad_format = AdFormatBaseModel::where("id", "=", $id)->first();
     if ($ad_format) {
         $view = $ad_format->code_view;
     }
     return 'partials.code' . $view;
 }
Beispiel #3
0
        <div class="col-sm-9">
            <input type="text" class="form-control" id="name" value="{{{ $item->name or Input::get('name') }}}" name="name" placeholder="Nhập tiêu đề">
            @if( isset($validate) && $validate->has('name')  )
            <span class="text-warning">{{ $validate->first('name') }}</span>
            @endif
        </div>
    </div>

    <div class="form-group">
        <label for="inputPassword3" class="col-sm-3">Ad format: </label>
        <div class="col-sm-9">
            <select name="ad_format_id" class="ad_format_id form-control">
                <option value="" selected="selected"> -- Select Ad Format -- </option>

                <?php 
foreach (AdFormatBaseModel::all() as $ad_format_id) {
    if ($item->ad_format_id == $ad_format_id->id) {
        echo '<option value="' . $ad_format_id->id . '" selected="selected">' . $ad_format_id->name . '</option>';
    } else {
        echo '<option value="' . $ad_format_id->id . '">' . $ad_format_id->name . '</option>';
    }
}
?>
            </select>
            @if( isset($validate) && $validate->has('ad_format_id')  )
            <span class="text-warning">{{ $validate->first('ad_format_id') }}</span>
            @endif
        </div>
    </div>

    <div class="form-group" id="type2">
 public function showPublisher()
 {
     $start_date = Input::get('start_date') ? date("Y-m-d", strtotime(Input::get('start_date'))) : date('Y-m-d');
     $end_date = Input::get('end_date') ? date("Y-m-d", strtotime(Input::get('end_date'))) : date('Y-m-d');
     $website = Input::get('website');
     $adformat = Input::get('adformat');
     $this->data['lists_website'] = PublisherSiteBaseModel::where("status", '=', 1)->get();
     $this->data['lists_adfortmat'] = AdFormatBaseModel::get();
     $tracking = DB::connection('mongodb')->collection('trackings_summary')->where("created_d", '>=', $start_date)->where("created_d", '<=', $end_date);
     if ($website != "") {
         $tracking = $tracking->where('w', '=', (int) $website);
     }
     if ($adformat != "") {
         $tracking = $tracking->where('af', '=', (int) $adformat);
     }
     $tracking = $tracking->get();
     $list_site = array();
     $list_zone = array();
     $data_ok = array();
     if (!empty($tracking)) {
         foreach ($tracking as $tract) {
             if (isset($tract['ads_request'])) {
                 if (!isset($list_site[$tract['w']])) {
                     $site = PublisherSiteBaseModel::find($tract['w']);
                     if ($site) {
                         $list_site[$tract['w']] = $site;
                     } else {
                         continue;
                     }
                 }
                 if (!isset($list_zone[$tract['az']])) {
                     $adzone = PublisherAdZoneBaseModel::find($tract['az']);
                     if ($adzone) {
                         $list_zone[$tract['az']] = $adzone;
                     } else {
                         continue;
                     }
                 }
                 if (isset($tract['f'])) {
                     $data_ok[$tract['w']][$tract['az']]['ads'][] = $tract['ads_request'];
                 } else {
                     $data_ok[$tract['w']][$tract['az']]['noads'][] = $tract['ads_request'];
                 }
             }
         }
     }
     $this->data['list_zone'] = $list_zone;
     $this->data['list_site'] = $list_site;
     $this->data['data_ok'] = $data_ok;
     $this->data['start_date'] = date("m/d/Y", strtotime($start_date));
     $this->data['end_date'] = date("m/d/Y", strtotime($end_date));
     $this->data['website'] = $website;
     $this->data['adformat'] = $adformat;
     $this->layout->content = View::make('publisher', $this->data);
 }
 /**
  *     handle form add/update agency
  *     @param  integer $id 
  */
 function postUpdate($id = 0)
 {
     // check validate
     $validate = Validator::make(Input::all(), $this->model->getUpdateRules(), $this->model->getUpdateLangs());
     if ($validate->passes()) {
         $campaignName = Input::get('campaign');
         $adFormatID = Input::get('ad_format_id');
         $adFormat = AdFormatBaseModel::find($adFormatID);
         if ('HTML' == $adFormat->name && 'video' == Input::get('ad_type')) {
             $campaign_id = Input::get('campaign_id');
             $name = Input::get('name');
             if (!isset($_FILES['vast_file']) || empty($_FILES['vast_file']['name'])) {
                 if (!empty($campaign_id) && !empty($name)) {
                     $file_name = str_replace(' ', '_', strtolower($name)) . '.xml';
                     $url = "http://static.yomedia.vn/xml/{$campaign_id}/{$file_name}";
                     $file_headers = @get_headers($url);
                     if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                         Session::flash('flash-message', "Vast file is required");
                         return FALSE;
                     }
                 }
             } else {
                 $file = $_FILES['vast_file'];
                 if (isset($file['name']) && $file['name'] != "") {
                     $ftp = new MyFTP();
                     $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name']));
                     if ('.xml' != $type) {
                         Session::flash('flash-message', "Extension of vast file error");
                         return FALSE;
                     }
                     $file_name = str_replace(' ', '_', strtolower(Input::get('name'))) . '.xml';
                     $dirUpload = "xml/{$campaign_id}/";
                     if (!$ftp->uploadFtp($dirUpload, $file['tmp_name'], $file_name)) {
                         Session::flash('flash-message', "Upload file error");
                         return FALSE;
                     }
                 }
             }
         }
         $updateData = array('campaign_id' => Input::get('campaign_id'), 'name' => Input::get('name'), 'ad_format_id' => $adFormatID, 'ad_type' => Input::get('ad_type'), 'width' => Input::get('width'), 'height' => Input::get('height'), 'width_2' => Input::get('width_2'), 'height_2' => Input::get('height_2'), 'width_after' => Input::get('width_after'), 'height_after' => Input::get('height_after'), 'source_url' => Input::get('source_url'), 'source_url2' => Input::get('source_url2'), 'destination_url' => Input::get('destination_url'), 'flash_wmode' => Input::get('flash_wmode', 'none'), 'video_duration' => Input::get('video_duration'), 'video_linear' => Input::get('video_linear'), 'video_type_vast' => Input::get('video_type_vast'), 'video_wrapper_tag' => Input::get('video_wrapper_tag'), 'third_impression_track' => Input::get('third_impression_track'), 'third_click_track' => Input::get('third_click_track'), 'video_bitrate' => Input::get('video_bitrate'), 'third_party_tracking' => Input::get('tracking') == "" ? "" : json_encode(Input::get('tracking')), 'main_source' => Input::get('main_source'), 'updated_by' => $this->user->id, 'platform' => json_encode(Input::get('platform')), 'ad_view_type' => Input::get('ad_view_type'), 'source_url_backup' => Input::get('source_url_backup'), 'html_source' => Input::get('html_source'), 'skipads' => Input::get('skipads'), 'display_type' => Input::get('display_type'), 'bar_height' => Input::get('bar_height'), 'vast_include' => Input::get('vast_include', 0), 'audience_id' => Input::get('audience_id', 0), 'position' => Input::get('position'));
         if (!$updateData['ad_view_type']) {
             if ($adFormat->ad_view) {
                 $updateData['ad_view'] = $adFormat->ad_view;
             } else {
                 $updateData['ad_view'] = '';
             }
         } else {
             $updateData['ad_view'] = Input::get('ad_view');
         }
         // Upload FILE FTP
         if (isset($_FILES['file_source_url'])) {
             $file = $_FILES['file_source_url'];
             if (isset($file['name']) && $file['name'] != "") {
                 $ftp = new MyFTP();
                 $file_name = time() . $file['name'];
                 if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) {
                     Session::flash('flash-message', "Extension file error");
                     return FALSE;
                 }
                 $updateData['source_url'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name;
             }
         }
         // Upload FILE FTP
         if (isset($_FILES['file_source_url_2'])) {
             $file = $_FILES['file_source_url_2'];
             if (isset($file['name']) && $file['name'] != "") {
                 $ftp = new MyFTP();
                 $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name']));
                 $file_name = time() . $file['name'];
                 $ftp->uploadFtp("", $file['tmp_name'], $file_name);
                 if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) {
                     Session::flash('flash-message', "Extension file error");
                     return FALSE;
                 }
                 $updateData['source_url2'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name;
             }
         }
         // Upload FILE BACKUP
         if (isset($_FILES['file_source_backup_url'])) {
             $file = $_FILES['file_source_backup_url'];
             if (isset($file['name']) && $file['name'] != "") {
                 $ftp = new MyFTP();
                 $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name']));
                 $file_name = time() . $file['name'];
                 if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) {
                     Session::flash('flash-message', "Extension file error");
                     return FALSE;
                 }
                 $updateData['source_url_backup'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name;
             }
         }
         $mime = '';
         if ($updateData['ad_type'] == 'html') {
             $mime = 'text/html';
         } else {
             if (!empty($updateData['source_url'])) {
                 $ch = curl_init($updateData['source_url']);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_exec($ch);
                 $mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
             }
         }
         $updateData['mime'] = $mime;
         // if (!empty($campaignName) || !empty($adFormatName)) {
         //     $updateData['name'] = $campaignName . ' ' . $adFormatName;
         // }
         if ($id == 0) {
             // INSERT
             $updateData['created_by'] = $this->user->id;
             if ($item = $this->model->create($updateData)) {
                 $this->data['id'] = $item->id;
                 (new Delivery())->renewCache('ad', $item->id);
                 Session::flash('flash-message', 'Create Ad Success!');
                 return TRUE;
             }
         } else {
             // UPDATE
             // GET CURRENT ITEM
             $item = $this->model->find($id);
             if ($item) {
                 if ($this->model->where("id", $id)->update($updateData)) {
                     //update audience id
                     $this->audience->updateCampaign($id, Input::get('campaign_id'));
                     $flights = FlightBaseModel::where('ad_id', $item->id)->get();
                     if ($flights) {
                         foreach ($flights as $flight) {
                             (new Delivery())->removeCache('flight', $flight->id);
                             $flight->ad_format_id = $updateData['ad_format_id'];
                             if ($flight->save()) {
                                 (new Delivery())->renewCache('flight', $flight->id);
                             }
                         }
                     }
                     (new Delivery())->renewCache('ad', $id);
                     Session::flash('flash-message', 'Update Ad Success!');
                     return TRUE;
                 }
             }
         }
     } else {
         $this->data['errors'] = $validate->messages();
     }
     return FALSE;
 }
 function getAlternate()
 {
     return AdFormatBaseModel::all();
 }
 public function showUpdateZone($pid = 0, $wid = 0, $zid = 0)
 {
     $publisher = $this->model->find($pid);
     if (!$publisher) {
         return Redirect::to($this->moduleURL . 'show-list');
     }
     $website = PublisherSiteBaseModel::find($wid);
     if (!$website) {
         return Redirect::to($this->moduleURL . 'show-list');
     }
     $this->data['id'] = $zid;
     $this->data['listAlternateAd'] = NULL;
     // WHEN UPDATE SHOW CURRENT INFOMATION
     if ($zid != 0) {
         $item = PublisherAdZoneBaseModel::find($zid);
         if ($item) {
             $this->data['item'] = $item;
             $listAlternateAdData['lists'] = $item->alternateAd;
             $this->data['listAlternateAd'] = View::make('alternateAdList', $listAlternateAdData)->render();
         } else {
             return Redirect::to($this->moduleURL . 'show-list');
         }
     }
     $this->data['listadformat'] = AdFormatBaseModel::all();
     if (Request::isMethod('post')) {
         if ($this->postUpdateZone($wid, $zid)) {
             return Redirect::to($this->moduleURL . $pid . '/view-site/' . $wid);
         }
     }
     $this->loadLeftMenu('menu.publisherUpdate', array('pid' => $pid));
     $this->layout->content = View::make('showUpdateZone', $this->data);
 }