Пример #1
0
 /**
  * Конструктор класса
  *
  */
 public function __construct()
 {
     // Название класса
     $className = get_class($this);
     // Подключаем объект CI
     $CI =& get_instance();
     // Подключаем хелпер периодов дат
     $CI->load->helper('periods');
     // Подготавливаем массив для чтения из поста даты
     $fields = array('from' => type_cast($CI->input->post('from'), 'date'), 'to' => type_cast($CI->input->post('to'), 'date'), 'period' => $CI->input->post('period'), 'mode' => $CI->input->post('mode'));
     if (false !== $fields['mode']) {
         // Устанавливаем период
         $period = data_range($fields);
         $this->setUnixRange($period['from'], $period['to']);
         // Сохраняем период
         period_save($className, $fields);
     } else {
         // Загружаем период
         $fields = period_load($className, 'select', 'today');
         // Устанавливаем период
         $period = data_range($fields);
         $this->setUnixRange($period['from'], $period['to']);
     }
     $this->specifiedRange = false;
 }
Пример #2
0
 /**
  * подготавливает данные статистики для периода времени по умолчанию,
  * callback-функция для библиотеки form
  *
  * @param integer $id не используется (обязательный параметр callback-функции)
  * @return array пустой массив (обязательное возвращаемое значение callback-функции)
  */
 public function _load($id)
 {
     $fields = period_load('advdashboard', 'select', 'today');
     $this->_stat(data_range($fields));
     return $fields;
 }
 /**
  * подготавливает данные статистики для периода времени по умолчанию,
  * callback-функция для библиотеки form
  *
  * @return array пустой массив (обязательное возвращаемое значение callback-функции)
  */
 public function _load()
 {
     $fields = period_load('manageadvertisers', 'select', 'today');
     $fields['filt'] = $this->temporary['manageadvertisers_filt'];
     $fields['quicksearch'] = $this->temporary['manageadvertisers_quicksearch'];
     $this->range = data_range($fields);
     return $fields;
 }
 /**
  * Получение таблицы сайтов по указанным критериям
  *
  */
 public function sites_table()
 {
     $this->load->model('channel_program');
     $filter_mode = $this->input->post('filter_mode');
     $this->load->helper('periods_helper');
     $this->table_builder->clear();
     $this->table_builder->init_sort_vars('iframe_channels', 'channel_name', 'asc');
     $this->table_builder->sorted_column(0, 'channel_name', "Channel Name", 'asc');
     $this->table_builder->sorted_column(1, 'id_dimension', 'Format', 'asc');
     $this->table_builder->set_cell_content(0, 2, __('Cost Model'));
     $this->table_builder->sorted_column(3, 'min_cpm_volume', __('Minimal CPM Package (Impressions)'), 'asc');
     $this->table_builder->sorted_column(4, 'min_cpm_cost_text', __('CPM Cost (Text Ads)'), 'asc');
     $this->table_builder->sorted_column(6, 'min_cpm_cost_image', __('CPM Cost (Text & Image)'), 'asc');
     $this->table_builder->sorted_column(8, 'min_flat_rate_volume', __('Minimal Flat Rate Package (Days)'), 'asc');
     $this->table_builder->sorted_column(9, 'min_flat_rate_cost_text', __('Flat Rate Cost (Text Ads)'), 'asc');
     $this->table_builder->sorted_column(11, 'min_flat_rate_cost_image', __('Flat Rate Cost (Text & Image)'), 'asc');
     $this->table_builder->sorted_column(13, 'impressions', 'Traffic Volume', 'asc');
     $this->table_builder->set_cell_content(0, 14, __('Action'));
     $this->table_builder->cell(0, 2)->add_attribute('class', 'simpleTitle');
     $this->table_builder->cell(0, 14)->add_attribute('class', 'simpleTitle');
     $this->table_builder->add_col_attribute(0, 'class', '');
     $this->table_builder->add_col_attribute(1, 'class', 'w80 center');
     $this->table_builder->add_col_attribute(2, 'class', 'w80 center');
     $this->table_builder->add_col_attribute(3, 'class', 'center');
     $this->table_builder->add_col_attribute(4, 'class', 'center');
     $this->table_builder->add_col_attribute(6, 'class', 'center');
     $this->table_builder->add_col_attribute(8, 'class', 'center');
     $this->table_builder->add_col_attribute(9, 'class', 'center');
     $this->table_builder->add_col_attribute(11, 'class', 'center');
     $this->table_builder->add_col_attribute(13, 'class', 'center');
     $this->table_builder->add_col_attribute(14, 'class', 'center');
     $this->table_builder->add_row_attribute(0, 'class', 'th f9px');
     $form_data = array("name" => "iframe_channels_form", "view" => "admin/adplacing/manage_sites_channels/choose_channels/iframe_channels_table.html", 'fields' => array('filter_mode' => array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $filter_mode)));
     switch ($filter_mode) {
         case 'by_category':
             $id_category = $this->input->post('id_category');
             if ($id_category) {
                 $form_data['fields']['id_category'] = array('id_field_type' => 'int', 'form_field_type' => 'hidden', 'default' => $id_category);
                 $channels_array = $this->channel->get_sites_channels(array('fields' => 'id_site_channel, channels.ad_type, channels.name as channel_name,' . ' sites.url as site_url, sites.id_site,' . ' channels.id_channel, channels.id_dimension, dimensions.width,' . ' dimensions.height, SUM(impressions) as impressions', 'category_id_filter' => $id_category, 'show_deleted_channels' => false, 'order_by' => $this->table_builder->sort_field, 'order_direction' => $this->table_builder->sort_direction, 'hide_wo_programs' => true, 'date_filter' => data_range(array('mode' => 'select', 'period' => 'lastmonth')), 'status' => 'active'));
             } else {
                 $channels_array = array();
             }
             break;
         case 'by_price':
             $price = $this->input->post('price');
             if ($price) {
                 $price = type_cast($price, 'float');
             } else {
                 $price = 0;
             }
             $price_program = $this->input->post('price_program');
             $ads_type = $this->input->post('ads_type');
             if ($price && $price_program) {
                 $form_data['fields']['price'] = array('id_field_type' => 'positive_float', 'form_field_type' => 'hidden', 'default' => type_to_str($price, 'float'));
                 $form_data['fields']['price_program'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $price_program);
                 $form_data['fields']['ads_type'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $ads_type);
                 $channels_array = $this->channel->get_sites_channels(array('fields' => 'id_site_channel, channels.ad_type, channels.name as channel_name, ' . 'sites.url as site_url, sites.id_site, channels.id_channel, ' . 'channels.id_dimension, dimensions.width, dimensions.height, ' . 'SUM(impressions) as impressions', 'show_deleted_channels' => false, 'order_by' => $this->table_builder->sort_field, 'order_direction' => $this->table_builder->sort_direction, 'price_filter' => array('price' => $price, 'price_program' => $price_program, 'ads_type' => $ads_type), 'hide_wo_programs' => true, 'date_filter' => data_range(array('mode' => 'select', 'period' => 'lastmonth'))));
             } else {
                 $channels_array = array();
             }
             break;
     }
     //установка атрибутов таблицы
     $this->table_builder->add_attribute('class', 'xTable');
     //or set style here
     if (is_null($channels_array)) {
         $channels_array = array();
     }
     $data_rows_conut = sizeof($channels_array);
     $this->table_builder->insert_empty_cells = false;
     $row_counter = 1;
     $site_id = '';
     for ($i = 0; $i < $data_rows_conut; $i++) {
         if (!$this->channel_program->get_default_program(array('id_site_channel' => $channels_array[$i]['id_site_channel']))) {
             continue;
         }
         if ($site_id != $channels_array[$i]['id_site']) {
             $this->table_builder->set_cell_content($row_counter, 0, array('src' => $this->site_url . 'images/pixel.gif', 'onclick' => 'top.SwitchExpander(' . $channels_array[$i]['id_site'] . ',this)', 'extra' => 'class="minus"'), 'image');
             $this->table_builder->cell($row_counter, 0)->add_content(__('Site') . ':&nbsp<span class="green i">&bdquo;' . $channels_array[$i]['site_url'] . '&ldquo;</span>');
             $this->table_builder->cell($row_counter, 0)->add_attribute('colspan', 15);
             $this->table_builder->add_row_attribute($row_counter, 'class', 'group');
             $site_id = $channels_array[$i]['id_site'];
             $row_counter++;
         }
         $this->table_builder->set_cell_content($row_counter, 0, type_to_str($channels_array[$i]['channel_name'], 'encode'));
         $allowedTypes = explode(',', $channels_array[$i]['ad_type']);
         $this->table_builder->set_cell_content($row_counter, 1, '');
         if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
             $ico_path = $this->site_url . 'images/smartppc6/icons/script_code.png';
             $hint_title = __('Text Ad') . ' (' . $channels_array[$i]['width'] . '&times;' . $channels_array[$i]['height'] . ')';
             $img_prefix = 'txt_';
             $this->table_builder->cell($row_counter, 1)->add_content(array('src' => $ico_path, 'extra' => 'title="' . $hint_title . '" href="' . $this->site_url . 'images/dimensions_preview/' . $img_prefix . $channels_array[$i]['id_dimension'] . '.png" class="tooltip"'), 'image');
         }
         if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes)) {
             $ico_path = $this->site_url . 'images/smartppc6/icons/image.png';
             $hint_title = __('Image Ad') . ' (' . $channels_array[$i]['width'] . '&times;' . $channels_array[$i]['height'] . ')';
             $img_prefix = 'img_';
             $this->table_builder->cell($row_counter, 1)->add_content(array('src' => $ico_path, 'extra' => 'title="' . $hint_title . '" href="' . $this->site_url . 'images/dimensions_preview/' . $img_prefix . $channels_array[$i]['id_dimension'] . '.png" class="tooltip"'), 'image');
         }
         $this->table_builder->cell($row_counter, 1)->add_content($channels_array[$i]['width'] . '&times;' . $channels_array[$i]['height'], '', '<br/> ');
         $program_type = "";
         $min_volume_cpm = "";
         $min_volume_flat_rate = "";
         if (!is_null($channels_array[$i]['min_cpm_volume'])) {
             $program_type .= __('CPM');
             $this->table_builder->set_cell_content($row_counter, 3, type_to_str($channels_array[$i]['min_cpm_volume'], 'integer'));
             if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
                 $this->table_builder->set_cell_content($row_counter, 4, type_to_str($channels_array[$i]['min_cpm_cost_text'], 'money'));
             } else {
                 $this->table_builder->set_cell_content($row_counter, 4, '&#151;');
             }
             if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes) && $channels_array[$i]['min_cpm_cost_image'] > 0) {
                 $this->table_builder->set_cell_content($row_counter, 6, type_to_str($channels_array[$i]['min_cpm_cost_image'], 'money'));
             } else {
                 $this->table_builder->set_cell_content($row_counter, 6, '&#151;');
             }
         } else {
             $program_type .= '&#151;';
             $this->table_builder->set_cell_content($row_counter, 3, '&#151;');
             $this->table_builder->set_cell_content($row_counter, 4, '&#151;');
             $this->table_builder->set_cell_content($row_counter, 6, '&#151;');
         }
         if (!is_null($channels_array[$i]['min_flat_rate_volume'])) {
             $program_type .= ' / ' . __('Flat Rate');
             $this->table_builder->set_cell_content($row_counter, 8, type_to_str($channels_array[$i]['min_flat_rate_volume'], 'integer'));
             if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
                 $this->table_builder->set_cell_content($row_counter, 9, type_to_str($channels_array[$i]['min_flat_rate_cost_text'], 'money'));
             } else {
                 $this->table_builder->set_cell_content($row_counter, 9, '&#151;');
             }
             if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes) && $channels_array[$i]['min_flat_rate_cost_image'] > 0) {
                 $this->table_builder->set_cell_content($row_counter, 11, type_to_str($channels_array[$i]['min_flat_rate_cost_image'], 'money'));
             } else {
                 $this->table_builder->set_cell_content($row_counter, 11, '&#151;');
             }
         } else {
             $program_type .= ' / &#151;';
             $this->table_builder->set_cell_content($row_counter, 8, '&#151;');
             $this->table_builder->set_cell_content($row_counter, 9, '&#151;');
             $this->table_builder->set_cell_content($row_counter, 11, '&#151;');
         }
         $this->table_builder->set_cell_content($row_counter, 2, $program_type);
         $this->table_builder->set_cell_content($row_counter, 13, type_to_str($channels_array[$i]['impressions'], 'impressions'));
         $this->table_builder->set_cell_content($row_counter, 14, array('name' => __('Add'), 'href' => '#', 'extra' => 'value="{@Add@}" title="{@Add@}" class="guibutton floatl ico ico-plusgreen" jframe="no" onclick="return addSiteChannelToGroup(' . $channels_array[$i]['id_site_channel'] . ');"'), 'link');
         $this->table_builder->add_row_attribute($row_counter, 'id', "tr{$channels_array[$i]['id_site']}");
         $this->table_builder->add_row_attribute($row_counter, 'id_site_channel', $channels_array[$i]['id_site_channel']);
         $row_counter++;
     }
     if (0 == $data_rows_conut) {
         $this->table_builder->set_cell_content(1, 0, __('Records not found'));
         $this->table_builder->cell(1, 0)->add_attribute('colspan', 15);
         $this->table_builder->cell(1, 0)->add_attribute('class', 'nodata');
     }
     // Устанавливаем возможность выбора колонок
     $this->table_builder->use_select_columns();
     $invariable_columns = array(0, 1, 2, 14);
     $this->table_builder->set_invariable_columns($invariable_columns);
     $channels_table = $this->table_builder->get_sort_html();
     $this->template = "common/parent/jq_iframe.html";
     $form_content = $this->form->get_form_content('create', $form_data, $this->input, $this);
     $form_content = str_replace('<%CHANNELS_TABLE%>', $channels_table, $form_content);
     $form_content = str_replace('<%COLUMNS%>', $this->table_builder->get_columns_html(), $form_content);
     $this->_set_content($form_content);
     $this->_display();
 }
 /**
  * Callback-функция, сохраняет установленные пользователем значения для фильтра таблицы
  *
  * @return string непустая строка для подавления succes-режима формы
  */
 public function _save($id, $fields)
 {
     $this->date_range = data_range($fields);
     $this->temporary['manadsgroups_filt'] = $fields['filt'];
     period_save('manadsgroups', $fields);
     return 'false';
 }
 /**
  * Отправляет ответ (HTML таблицу) на запрос списка сайтов выбранного канала
  * Канал указывается в GET-параметре id_channel
  */
 public function get_sites($id_channel, $date_from = null, $date_to = null)
 {
     // Add plugins to hook
     $this->add_plugins('channel_sites');
     $message = '';
     if (is_null($date_from) || is_null($date_to)) {
         $fields = period_load('manage_sites_channels', 'select', 'alltime');
         $this->date_range = data_range($fields);
     } else {
         $this->date_range = array('from' => $date_from, 'to' => $date_to);
     }
     $action = $this->input->post('manage_action');
     if ($action) {
         $id_channel = $this->input->post('id_channel');
         switch ($action) {
             case 'pause':
                 $this->pause_channel_sites();
                 break;
             case 'resume':
                 $this->resume_channel_sites();
                 break;
             case 'delete':
                 $message = $this->delete_channel_sites();
                 break;
         }
     }
     $this->pagination_post->clear();
     $this->pagination_post->set_form_name('manage_sites_channels_site_' . $id_channel);
     $total_params = array('channel_id_filter' => $id_channel, 'date_filter' => $this->date_range, 'revenue_field' => $this->revenue_field, 'id_entity' => $this->user_id);
     $total = $this->site->get_count($total_params);
     $this->pagination_post->set_total_records($total['count']);
     $this->pagination_post->read_variables('manage_sites_channels_site', 1, 10, FALSE, 'manage_sites_channels_site_' . $id_channel);
     //настройка параметров разбиения на страницы
     $pagination = $this->pagination_post->create_form();
     $col_index = 0;
     $col_alias = array('chkboxes' => $col_index++, 'id' => $col_index++, 'url' => $col_index++, 'name' => $col_index++, 'status' => $col_index++, 'impressions' => $col_index++, 'alternative_impressions' => $col_index++, 'clicks' => $col_index++, 'ctr' => $col_index++, 'revenue' => $col_index++, 'action' => $col_index++);
     // add addtional columns to column map from plugins
     foreach ($this->_hooks as $hookObj) {
         $col_alias = $hookObj->extendColumnMap($col_alias);
     }
     $this->table_builder->clear();
     $this->table_builder->init_sort_vars('manage_sites_channels_site', 'id', 'desc', FALSE, 'manage_sites_channels_site_' . $id_channel);
     $this->table_builder->sorted_column($col_alias['id'], 'id', 'ID', 'asc');
     $this->table_builder->sorted_column($col_alias['name'], 'name', 'Title', 'asc');
     $this->table_builder->sorted_column($col_alias['url'], 'url', 'Site URL', 'asc');
     $this->table_builder->sorted_column($col_alias['status'], 'status', 'Status', 'asc');
     $this->table_builder->sorted_column($col_alias['impressions'], 'impressions', 'Impressions', 'desc');
     $this->table_builder->sorted_column($col_alias['alternative_impressions'], 'alternative_impressions', 'Alternative Impressions', 'desc');
     $this->table_builder->sorted_column($col_alias['clicks'], 'clicks', 'Clicks', 'desc');
     $this->table_builder->sorted_column($col_alias['ctr'], 'ctr', 'CTR', 'desc');
     $this->table_builder->sorted_column($col_alias['revenue'], 'revenue', 'Revenue', 'desc');
     //$this->table_builder->sorted_column(9,'creation_date','Creation Date','desc');
     //добавление ячеек-заголовка
     $this->table_builder->set_cell_content(0, $col_alias['chkboxes'], array('name' => 'checkAll', 'extra' => 'onclick="return select_all(\'manage_sites_channels_site\', this)"'), 'checkbox');
     $this->table_builder->set_cell_content(0, $col_alias['action'], __('Action'));
     // create additional columns from plugins
     foreach ($this->_hooks as $hookObj) {
         $hookObj->createColumns($col_alias, $this->table_builder);
     }
     $this->table_builder->cell(0, $col_alias['chkboxes'])->add_attribute('class', 'simpleTitle');
     $this->table_builder->cell(0, $col_alias['action'])->add_attribute('class', 'simpleTitle');
     //прописывание стилей для ячеек
     $this->table_builder->add_col_attribute($col_alias['chkboxes'], 'class', '"chkbox"');
     $this->table_builder->add_col_attribute($col_alias['id'], 'class', 'w20');
     //$this->table_builder->add_col_attribute(3, 'class', 'w150');
     //$this->table_builder->add_col_attribute(3, 'class', '"w80 center"');
     $this->table_builder->add_col_attribute($col_alias['status'], 'class', 'w80 center');
     $this->table_builder->add_col_attribute($col_alias['impressions'], 'class', 'w80 right');
     $this->table_builder->add_col_attribute($col_alias['alternative_impressions'], 'class', 'w80 right');
     $this->table_builder->add_col_attribute($col_alias['clicks'], 'class', 'w50 right');
     $this->table_builder->add_col_attribute($col_alias['ctr'], 'class', 'w50 right');
     //$this->table_builder->add_col_attribute(8, 'class', '"w80 right"');
     $this->table_builder->add_col_attribute($col_alias['revenue'], 'class', 'w100 center');
     $this->table_builder->add_col_attribute($col_alias['action'], 'class', 'nowrap center');
     // add styles for additional columns from plugins
     foreach ($this->_hooks as $hookObj) {
         $hookObj->defineColumnStyles($col_alias, $this->table_builder);
     }
     $this->table_builder->add_row_attribute(0, 'class', 'th');
     //установка атрибутов таблицы
     $this->table_builder->add_attribute('class', 'xTable');
     //or set style here
     $params = array('fields' => 'sites.id_site as id, ' . 'sites.url, site_channels.status, sites.name, SUM(impressions) as impressions, ' . 'SUM(alternative_impressions) as alternative_impressions, SUM(clicks) as clicks, ' . '(SUM(clicks)/SUM(impressions)*100) as ctr, UNIX_TIMESTAMP(sites.creation_date) as ' . 'creation_date, SUM(' . $this->revenue_field . ') as revenue, ' . 'e.id_entity AS pub_entity', 'order_by' => $this->table_builder->sort_field, 'order_direction' => $this->table_builder->sort_direction, 'channel_id_filter' => $id_channel, 'date_filter' => $this->date_range, 'id_entity' => $this->user_id, 'offset' => ($this->pagination_post->get_page() - 1) * $this->pagination_post->get_per_page(), 'limit' => $this->pagination_post->get_per_page());
     // Add addtional fields to $params['fields']
     foreach ($this->_hooks as $hookObj) {
         if (method_exists($hookObj, 'extendColumnQueryFields')) {
             $params = $hookObj->extendColumnQueryFields($params, 'stat_sites_channels');
         }
     }
     $sites_array = $this->site->get_list($params);
     //echo $this->db->last_query();
     if (is_null($sites_array)) {
         $sites_array = array();
     }
     //$this->table_builder->add_from_array ($sites_array);
     $data_rows_conut = sizeof($sites_array);
     //модификация контента отдельных столбцов (ссылки, чекбоксы)
     $code_channel = type_to_str($id_channel, 'textcode');
     $page_total = array('revenue' => 0, 'impressions' => 0, 'alternative_impressions' => 0, 'clicks' => 0);
     // register additional per page statistic fields
     foreach ($this->_hooks as $hookObj) {
         $page_total = $hookObj->registerPerPageStatisticFields($page_total);
     }
     $pub_entity = NULL;
     for ($i = 0; $i < $data_rows_conut; $i++) {
         $pub_entity = $sites_array[$i]['pub_entity'];
         $page_total['impressions'] += $sites_array[$i]['impressions'];
         $page_total['alternative_impressions'] += $sites_array[$i]['alternative_impressions'];
         $page_total['clicks'] += $sites_array[$i]['clicks'];
         $page_total['revenue'] += $sites_array[$i]['revenue'];
         // calculate per page statistic for additional columns from plugins
         foreach ($this->_hooks as $hookObj) {
             $page_total = $hookObj->calculatePerPageStatistic($page_total, $sites_array[$i]);
         }
         $code_site = type_to_str($sites_array[$i]['id'], 'textcode');
         if ('deleted' == $sites_array[$i]['status']) {
             $this->table_builder->set_cell_content($i + 1, $col_alias['chkboxes'], '');
             $this->table_builder->set_cell_content($i + 1, $col_alias['action'], '');
             $this->table_builder->add_row_attribute($i + 1, 'class', 'deleted_row');
         } else {
             if ($sites_array[$i]['pub_entity'] == $this->user_id) {
                 $this->table_builder->set_cell_content($i + 1, $col_alias['chkboxes'], array('name' => 'id_site[]', 'value' => $sites_array[$i]['id'], 'extra' => 'id=chk' . $i . ' onclick="checktr(\'chk' . $i . '\',\'tr' . ($i + 1) . '\')"'), 'checkbox');
                 $this->table_builder->set_cell_content($i + 1, $col_alias['action'], array('name' => __('Edit'), 'href' => $this->site_url . $this->index_page . $this->role . '/edit_site/index/' . $sites_array[$i]['id'], 'extra' => 'jframe="no" class="guibutton floatl ico ico-edit" value="{@Edit@}" title="{@Edit@}" onclick="top.location=\'' . $this->site_url . $this->index_page . $this->role . '/edit_site/index/' . $sites_array[$i]['id'] . '\'" target="_top"'), 'link');
                 $this->table_builder->cell($i + 1, $col_alias['action'])->add_content(array('name' => __('Get code'), 'href' => '#get_code', 'extra' => 'jframe="no" class="guibutton floatl ico ico-puzzle2" value="{@Get code@}" title="{@Get code@}" onclick="top.get_channel_code(\'' . $sites_array[$i]['id'] . '\',\'' . $id_channel . '\')"'), 'link', ' ');
                 $this->table_builder->cell($i + 1, $col_alias['action'])->add_content(array('name' => __('Layout'), 'href' => $this->site_url . $this->index_page . $this->role . '/edit_site_channel_layout/index/' . $sites_array[$i]['id'], 'extra' => 'jframe="no" class="guibutton floatl ico ico-site-layout" value="{@Layout@}" title="{@Layout@}" onclick="top.location=\'' . $this->site_url . $this->index_page . $this->role . '/edit_site_channel_layout/index/' . $sites_array[$i]['id'] . '\'" target="_top"'), 'link', '');
             } else {
                 $this->table_builder->set_cell_content($i + 1, $col_alias['chkboxes'], '');
                 $this->table_builder->set_cell_content($i + 1, $col_alias['action'], '');
             }
             $this->table_builder->cell($i + 1, $col_alias['action'])->add_content(array('name' => __('View Ads'), 'href' => '#view_ads', 'extra' => 'jframe="no" class="guibutton floatl ico ico-viewads" value="' . __("View Ads") . '" title="' . __("View Ads") . '"  onclick="top.view_ads(\'' . $code_site . '\',\'' . $code_channel . '\')"'), 'link', ' ');
             $this->table_builder->add_row_attribute($i + 1, 'id', 'tr' . ($i + 1));
             if ('paused' == $sites_array[$i]['status']) {
                 $this->table_builder->add_row_attribute($i + 1, 'class', 'blocked_row');
             }
         }
         $this->table_builder->set_cell_content($i + 1, $col_alias['id'], $sites_array[$i]['id']);
         $this->table_builder->set_cell_content($i + 1, $col_alias['name'], limit_str_and_hint($sites_array[$i]['name'], 30));
         $this->table_builder->set_cell_content($i + 1, $col_alias['url'], array('name' => $sites_array[$i]['url'], 'href' => 'http://' . $sites_array[$i]['url'], 'extra' => 'target="_blank"'), 'link');
         $this->table_builder->set_cell_content($i + 1, $col_alias['status'], __('site_' . $sites_array[$i]['status']));
         $this->table_builder->set_cell_content($i + 1, $col_alias['impressions'], type_to_str($sites_array[$i]['impressions'], 'integer'));
         $this->table_builder->set_cell_content($i + 1, $col_alias['alternative_impressions'], type_to_str($sites_array[$i]['alternative_impressions'], 'integer'));
         $this->table_builder->set_cell_content($i + 1, $col_alias['clicks'], type_to_str($sites_array[$i]['clicks'], 'integer'));
         $this->table_builder->set_cell_content($i + 1, $col_alias['ctr'], type_to_str($sites_array[$i]['ctr'], 'float') . ' %');
         $this->table_builder->set_cell_content($i + 1, $col_alias['revenue'], type_to_str($sites_array[$i]['revenue'], 'money'));
         //$this->table_builder->set_cell_content ( $i + 1, 9, type_to_str($sites_array [$i]['creation_date'], 'date'));
         // render additional columns from plugins
         foreach ($this->_hooks as $hookObj) {
             $hookObj->renderRow($i + 1, $col_alias, $sites_array[$i], $this->table_builder);
         }
     }
     //end модификация контента отдельных столбцов (ссылки, чекбоксы)
     if (0 == $data_rows_conut) {
         $this->table_builder->insert_empty_cells = false;
         $this->table_builder->set_cell_content(1, 0, __('Records not found'));
         $this->table_builder->cell(1, 0)->add_attribute('colspan', count($col_alias));
         $this->table_builder->cell(1, 0)->add_attribute('class', 'nodata');
         $this->table_builder->remove_col_attribute_value(0, 'class', 'chkbox');
         $this->table_builder->cell(0, 0)->add_attribute('class', 'chkbox');
     } else {
         $row = $data_rows_conut + 1;
         $this->table_builder->set_cell_content($row, $col_alias['name'], __("Page total"));
         //$this->table_builder->cell($row, 2)->add_attribute('colspan', 2);
         $this->table_builder->set_cell_content($row, $col_alias['impressions'], type_to_str($page_total['impressions'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['alternative_impressions'], type_to_str($page_total['alternative_impressions'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['clicks'], type_to_str($page_total['clicks'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['revenue'], type_to_str($page_total['revenue'], 'money'));
         $ctr = $page_total['impressions'] ? $page_total['clicks'] / $page_total['impressions'] * 100 : 0;
         $this->table_builder->set_cell_content($row, $col_alias['ctr'], type_to_str($ctr, 'procent'));
         $this->table_builder->clear_row_attributes($row);
         $this->table_builder->add_row_attribute($row, 'class', 'pagetotal');
         // render per page statistic for additional columns from plugins
         foreach ($this->_hooks as $hookObj) {
             $hookObj->renderPageStatisticRow($row, $col_alias, $page_total, $this->table_builder);
         }
         $row++;
         $this->table_builder->set_cell_content($row, $col_alias['name'], __("Total"));
         //$this->table_builder->cell($row, 2)->add_attribute('colspan', 2);
         $this->table_builder->set_cell_content($row, $col_alias['impressions'], type_to_str($total['impressions'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['alternative_impressions'], type_to_str($total['alternative_impressions'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['clicks'], type_to_str($total['clicks'], 'integer'));
         $this->table_builder->set_cell_content($row, $col_alias['revenue'], type_to_str($total['revenue'], 'money'));
         $ctr = $total['impressions'] ? $total['clicks'] / $total['impressions'] * 100 : 0;
         $this->table_builder->set_cell_content($row, $col_alias['ctr'], type_to_str($ctr, 'procent'));
         $this->table_builder->clear_row_attributes($row);
         $this->table_builder->add_row_attribute($row, 'class', 'alltotal');
         // render summary statistic for additional columns from plugins
         foreach ($this->_hooks as $hookObj) {
             $hookObj->renderSummaryRow($row, $col_alias, $total, $this->table_builder);
         }
     }
     // Устанавливаем возможность выбора колонок
     $this->table_builder->use_select_columns();
     $invariable_columns = array($col_alias['chkboxes'], $col_alias['id'], $col_alias['url'], $col_alias['action']);
     $this->table_builder->set_invariable_columns($invariable_columns);
     //$this->table_builder->add_attribute ( 'class', 'xTable' ); //or set style here
     $table = $this->table_builder->get_sort_html();
     $content = $this->parser->parse($this->views_paths['iframe_sites_list'], array('MESSAGE' => json_encode(array('message' => __($message))), 'SITES_TABLE' => $table, 'COLUMNS' => $this->table_builder->get_columns_html(), 'PAGINATION' => $pagination, 'ID_CHANNEL' => $id_channel, 'JFRAME_ACTION' => '<%SITEURL%><%INDEXPAGE%>' . $this->role . '/manage_sites_channels/get_sites/' . $id_channel . '/' . $date_from . '/' . $date_to . '/all'), TRUE);
     if ($pub_entity != $this->user_id) {
         $content = preg_replace("/\\<a name=\"chan_buttons_begin\"\\>\\<\\/a\\>[\\s\\S]*?\\<a name=\"chan_buttons_end\"\\>\\<\\/a\\>/", '', $content);
     }
     //$this->template = "common/parent/iframe.html";
     $this->template = "common/parent/jq_iframe.html";
     $this->_set_content($content);
     $this->_display();
 }
Пример #7
0
 /**
  * возвращает javascript-код для определения текста периода по выбору options
  *
  * @return string javascript-код
  */
 function get_all_periods()
 {
     $all = array('today', 'yesterday', 'lastweek', 'lastbusinessweek', 'thismonth', 'lastmonth', 'alltime');
     $fields['mode'] = 'select';
     $code = '';
     foreach ($all as $per) {
         $fields['period'] = $per;
         $range = data_range($fields);
         $from = type_to_str($range['from'], 'date');
         $to = type_to_str($range['to'], 'date');
         $code .= "case '{$per}': return '{$from}-{$to}';\n";
     }
     $code .= "case 'start': return '" . type_to_str(0, 'date') . "';\n";
     $code .= "case 'end': return '" . type_to_str(mktime(), 'date') . "';\n";
     return $code;
 }
    /**
     * Search sites according to specified criteria
     *
     * @return void
     */
    public function search_sites()
    {
        //load nessesary components
        $this->load->model('pagination_post');
        $filter_mode = $this->input->post('filter_mode');
        $this->load->helper('periods_helper');
        $siteModel = new Sppc_SiteModel();
        //initialize table builder
        $this->table_builder->clear();
        $this->table_builder->init_sort_vars('search_sites_cpc', 'url', 'asc');
        $col_index = 0;
        $col_alias = array('url' => $col_index++, 'impressions' => $col_index++, 'clicks' => $col_index++, 'min_bid' => $col_index++, 'min_bid_image' => $col_index++, 'action' => $col_index++);
        $this->table_builder->sorted_column($col_alias['url'], 'url', "Site", 'asc');
        $this->table_builder->sorted_column($col_alias['impressions'], 'impressions', "Monthly Traffic Volume", 'asc');
        $this->table_builder->sorted_column($col_alias['clicks'], 'clicks', "Clicks", 'asc');
        $this->table_builder->sorted_column($col_alias['min_bid'], 'min_cpc', "Min Bid Text", 'asc');
        $this->table_builder->sorted_column($col_alias['min_bid_image'], 'min_cpc_image', "Min Bid Image", 'asc');
        $this->table_builder->set_cell_content(0, $col_alias['action'], __('Action'));
        $this->table_builder->cell(0, $col_alias['action'])->add_attribute('class', 'simpleTitle');
        // set table attributes
        $this->table_builder->add_attribute('class', 'xTable');
        //or set style here
        $this->table_builder->add_row_attribute(0, 'class', 'th f9px');
        $this->table_builder->add_col_attribute($col_alias['action'], 'class', 'center');
        $this->table_builder->insert_empty_cells = false;
        // initialize page browser
        $this->pagination_post->clear();
        $this->pagination_post->set_form_name('search_sites_cpc');
        //initialize from config
        $form_data = array("name" => "search_sites_cpc_form", "view" => "advertiser/manage_ads/campaigns/creation/select_sites/jframe_search_sites.html", "action" => $this->site_url . $this->index_page . "advertiser/create_campaign_step_select_sites/search_sites", 'fields' => array('filter_mode' => array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $filter_mode)));
        //initialize search filter object
        $dateRange = data_range(array('mode' => 'select', 'period' => 'lastmonth'));
        $statStartDate = new Zend_Date($dateRange['from'], Zend_Date::TIMESTAMP);
        $statEndDate = new Zend_Date($dateRange['to'], Zend_Date::TIMESTAMP);
        $searchFilter = new Sppc_Site_SearchFilter();
        $searchFilter->setConnectToStats(true, $statStartDate, $statEndDate)->setHasCpc(true);
        // according to filter mode configure search filter object
        switch ($filter_mode) {
            case 'all':
                //show all active sites
                break;
            case 'by_category':
                // search sites by category
                $categories = array();
                $id_category = $this->input->post('id_category');
                $include_subcats = $this->input->post('include_subcats');
                if ($id_category) {
                    $categoryModel = new Sppc_CategoryModel();
                    $category = $categoryModel->findObjectById($id_category);
                    if (!is_null($category)) {
                        $categories[] = $category;
                        if ($include_subcats == 'true') {
                            $categories = array_merge($categories, $category->getChildCategories(true));
                        }
                    }
                    $this->table_builder->insert_empty_cells = false;
                    $form_data['fields']['id_category'] = array('id_field_type' => 'int', 'form_field_type' => 'hidden', 'default' => $id_category);
                    $form_data['fields']['include_subcats'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $include_subcats);
                }
                $searchFilter->setCategories($categories);
                break;
            case 'by_name':
                // search sites by id
                $siteIds = array();
                $id_site = $this->input->post('id_site');
                if ($id_site) {
                    $form_data['fields']['id_site'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $id_site);
                    $id_site = explode(',', $id_site);
                    foreach ($id_site as $site) {
                        $siteIds[] = type_cast($site, 'textcode');
                    }
                }
                $searchFilter->setSiteId($siteIds);
                break;
            case 'by_price':
                // search sites by bid
                $bid = $this->input->post('price');
                $cpcBidType = $this->input->post('cpc_bid_type');
                $cpcBidType = in_array($cpcBidType, array('text', 'image')) ? $cpcBidType : false;
                if ($bid && $cpcBidType) {
                    $form_data['fields']['price'] = array('id_field_type' => 'positive_float', 'form_field_type' => 'hidden', 'default' => type_to_str($bid, 'float'));
                    $form_data['field']['cpc_bid_type'] = array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => $cpcBidType);
                    switch ($cpcBidType) {
                        case 'text':
                            $searchFilter->setMaximumTextBid($bid);
                            break;
                        case 'image':
                            $searchFilter->setMaximumImageBid($bid);
                            break;
                    }
                }
                break;
        }
        $sitesCount = $siteModel->getCount($searchFilter);
        $this->pagination_post->set_total_records($sitesCount);
        $this->pagination_post->read_variables('search_sites_cpc', 1, 10);
        $sites = $siteModel->search($searchFilter, $this->table_builder->sort_field . ' ' . $this->table_builder->sort_direction, $this->pagination_post->get_per_page(), $this->pagination_post->get_page());
        $rowsCount = count($sites);
        if ($rowsCount > 0) {
            $rowCounter = 1;
            foreach ($sites as $site) {
                // url
                $this->table_builder->set_cell_content($rowCounter, $col_alias['url'], array('name' => $site->getUrl(), 'href' => 'http://' . $site->getUrl(), 'extra' => 'target="_blank"'), 'link');
                $this->table_builder->add_cell_content($rowCounter, $col_alias['url'], '<br>' . limit_str_and_hint($site->getName(), 30));
                // last month traffic
                $this->table_builder->set_cell_content($rowCounter, $col_alias['impressions'], type_to_str($site->getImpressions(), 'impressions'));
                // Clicks
                $this->table_builder->set_cell_content($rowCounter, $col_alias['clicks'], type_to_str($site->getClicks(), 'clicks'));
                // Min bid for text ads
                $cellContent = '
					<span class="min_bid_text">' . type_to_str($site->getMinCpc(), 'money') . '
						<span class="hide min_bid_value">' . type_to_str($site->getMinCpc(), 'float') . '</span>
					</span>';
                $this->table_builder->set_cell_content($rowCounter, $col_alias['min_bid'], $cellContent);
                // Min bid for image ads
                $cellContent = '
					<span class="min_image_bid_text">' . type_to_str($site->getMinCpcImage(), 'money') . '
						<span class="hide min_image_bid_value">' . type_to_str($site->getMinCpcImage(), 'float') . '
						</span>
					</span>';
                $this->table_builder->set_cell_content($rowCounter, $col_alias['min_bid_image'], $cellContent);
                // Actions
                $this->table_builder->set_cell_content($rowCounter, $col_alias['action'], array('name' => __('Add'), 'href' => '#', 'extra' => 'value="{@Add@}" title="{@Add@}" class="guibutton floatl ico ico-plusgreen" jframe="no" onclick="return addSiteToGroup(\'' . type_to_str($site->getId(), 'textcode') . '\');"'), 'link');
                // add attribute for row
                $this->table_builder->add_row_attribute($rowCounter, 'id_site', type_to_str($site->getId(), 'textcode'));
                $rowCounter++;
            }
        } else {
            $this->table_builder->set_cell_content(1, 0, __('Records not found'));
            $this->table_builder->cell(1, 0)->add_attribute('colspan', count($col_alias));
            $this->table_builder->cell(1, 0)->add_attribute('class', 'nodata');
        }
        // Устанавливаем возможность выбора колонок
        $this->table_builder->use_select_columns();
        $invariable_columns = array($col_alias['url'], $col_alias['action']);
        $this->table_builder->set_invariable_columns($invariable_columns);
        $sites_table = $this->table_builder->get_sort_html();
        $this->template = "common/parent/jq_iframe.html";
        $form_content = $this->form->get_form_content('create', $form_data, $this->input, $this);
        $form_content = str_replace('<%SITES_TABLE%>', $sites_table, $form_content);
        $form_content = str_replace('<%COLUMNS%>', $this->table_builder->get_columns_html(), $form_content);
        $form_content = str_replace('<%PAGINATION%>', $this->pagination_post->create_form(), $form_content);
        $this->_set_content($form_content);
        $this->_display();
    }
Пример #9
0
 /**
  * Callback-функция, сохраняет установленные пользователем значения для фильтра таблицы
  *
  * @return string непустая строка для подавления succes-режима формы
  */
 public function _save($id, $fields)
 {
     $this->date_range = data_range($fields);
     if ($id == 'ads') {
         $this->temporary['manadsads_filt'] = $fields['filt'];
         period_save('manadsads', $fields);
     } elseif ($id == 'channels') {
         $this->temporary['manadschannels_filt'] = $fields['filt'];
         period_save('manadschannels', $fields);
     } else {
         period_save('manadssummary', $fields);
     }
     return 'false';
 }
 /**
  * Получение HTML-таблицы, содержащей каналы, добавленные в группу
  *
  */
 private function _get_added_channels($status_filter)
 {
     $sites_channels_programs = array();
     $this->load->model('new_campaign');
     $this->new_campaign->init_storage($this->id_xml);
     //обновление параметров добавленных ранее сайтов-каналов
     $modified_sites_channels_ids = $this->input->post('modified_sites_channels_info');
     $modified_sites_channels_ids = json_decode($modified_sites_channels_ids);
     if (!is_null($modified_sites_channels_ids)) {
         $this->load->model('channel_program');
         foreach ($modified_sites_channels_ids as $id) {
             $site_channel_info = $this->new_campaign->get_site_channel_info($id);
             if (count($site_channel_info) > 0 && 'old' == $site_channel_info['status']) {
                 $cost = $site_channel_info['cost'];
                 $volume = $site_channel_info['volume'];
                 $program_option = $site_channel_info['id_program'];
                 $ad_type = $site_channel_info['ad_type'];
             } else {
                 //для только что добавленных сайтов-каналов берем инфо о цене и объеме из базы
                 $program_option = $this->input->post('site_channel_' . $id . '_program_option');
                 $ad_type = $this->input->post('site_channel_' . $id . '_ad_type');
                 $allowedAdTypes = explode(',', $ad_type);
                 $textAllowed = in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedAdTypes) ? true : false;
                 $imageAllowed = in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedAdTypes) ? true : false;
                 $program_info = $this->channel_program->get_info($program_option);
                 if (!is_null($program_info)) {
                     $volume = $program_info->volume;
                     if ($textAllowed) {
                         $cost = $program_info->cost_text;
                     }
                     if ($imageAllowed) {
                         $cost = $program_info->cost_image;
                     }
                 } else {
                     continue;
                     // не добавляем cайт-канал с неизвестной ценой
                 }
             }
             $this->new_campaign->add_site_channel(array('id_site_channel' => $id, 'cost' => $cost, 'volume' => $volume, 'id_program' => $program_option, 'ad_type' => $ad_type));
         }
         $this->new_campaign->save_data();
     }
     $action = $this->input->post('action');
     if ($action) {
         $id_site_channel = $this->input->post('id_site_channel');
         switch ($action) {
             case 'delete_site_channel':
                 if ($id_site_channel) {
                     $this->new_campaign->del_site_channel($id_site_channel);
                     $this->new_campaign->save_data();
                 }
                 break;
         }
     }
     $added_sites_channels = $this->new_campaign->get_sites_channels(array('status' => $status_filter));
     $added_sites_channels_ids = array_keys($added_sites_channels);
     $this->table_builder->clear();
     if ('old' == $status_filter) {
         $this->table_builder->init_sort_vars('iframe_added_channels', 'site_name', 'asc');
         $delete_js_function = 'deleteSiteChannelFromGroup';
     } else {
         $this->table_builder->init_sort_vars('iframe_recently_added_channels', 'site_name', 'asc');
         $delete_js_function = 'deleteRecentSiteChannelFromGroup';
     }
     $this->table_builder->sorted_column(0, 'site_name', "Site Name", 'asc');
     $this->table_builder->sorted_column(1, 'channel_name', 'Channel', 'asc');
     $this->table_builder->set_cell_content(0, 2, __('Format'));
     $this->table_builder->set_cell_content(0, 3, __('Ad Type'));
     $this->table_builder->set_cell_content(0, 4, __('Cost Model'));
     $this->table_builder->set_cell_content(0, 5, __('Price'));
     $this->table_builder->sorted_column(7, 'impressions', 'Traffic Volume', 'asc');
     $this->table_builder->set_cell_content(0, 8, __('Action'));
     $this->table_builder->add_row_attribute(0, 'class', 'th');
     $this->table_builder->cell(0, 2)->add_attribute('class', 'simpleTitle');
     $this->table_builder->cell(0, 4)->add_attribute('class', 'simpleTitle');
     $this->table_builder->cell(0, 5)->add_attribute('class', 'simpleTitle');
     $this->table_builder->cell(0, 8)->add_attribute('class', 'simpleTitle');
     //установка атрибутов таблицы
     $this->table_builder->add_attribute('class', '"xTable w100p"');
     //or set style here
     $this->table_builder->add_row_attribute(0, 'class', 'th');
     $this->table_builder->add_col_attribute(2, 'class', '"w100 center"');
     $this->table_builder->add_col_attribute(3, 'class', '"w100 center"');
     $this->table_builder->add_col_attribute(4, 'class', '"w100 center"');
     $this->table_builder->add_col_attribute(5, 'class', '"w300"');
     $this->table_builder->add_col_attribute(7, 'class', '"w100 center"');
     $this->table_builder->add_col_attribute(8, 'class', '"nowrap center"');
     if (count($added_sites_channels_ids) > 0) {
         $this->load->helper('periods_helper');
         $this->load->model('channel');
         $params = array('fields' => 'id_site_channel, channels.ad_type, channels.name as channel_name,' . ' sites.url as site_url, sites.name as site_name, sites.id_site,' . ' channels.id_channel, channels.id_dimension, dimensions.width,' . ' dimensions.height, SUM(impressions) as impressions', 'disable_site_ordering' => true, 'order_by' => $this->table_builder->sort_field, 'order_direction' => $this->table_builder->sort_direction, 'site_channel_id_filter' => $added_sites_channels_ids, 'date_filter' => data_range(array('mode' => 'select', 'period' => 'lastmonth')));
         $sites_channels_array = $this->channel->get_sites_channels($params);
         if (is_null($sites_channels_array)) {
             $sites_channels_array = array();
         } else {
             //формирование данных о программах, доступных в каждом канале
             // для новых сайтов-каналов определяем доступные программы
             $this->load->model('channel_program');
             if ('new' == $status_filter) {
                 $this->load->model('sites_channels');
                 foreach ($sites_channels_array as $site_channel) {
                     $available_programs = $this->channel_program->get_list(array('fields' => 'id_program, title, program_type, cost_text, cost_image, ' . 'volume', 'id_channel' => $site_channel['id_channel'], 'order_by' => 'title', 'order_direction' => 'asc'));
                     if (!is_null($available_programs)) {
                         $slot_info = $this->sites_channels->get_slot_info($site_channel['id_site_channel']);
                         $flat_rate_image_is_allowed = false;
                         if ($slot_info['free'] == 0) {
                             $flat_rate_is_allowed = false;
                         } else {
                             $flat_rate_is_allowed = true;
                             $flat_rate_image_is_allowed = $slot_info['free'] == $slot_info['max'];
                         }
                         foreach ($available_programs as $key => &$available_program) {
                             if ('Flat_Rate' == $available_program['program_type'] && !$flat_rate_is_allowed) {
                                 unset($available_programs[$key]);
                             } else {
                                 $available_program['cost_per_volume_text'] = type_to_str($available_program['cost_text'], 'money') . ' / ' . type_to_str($available_program['volume'], 'integer') . ' ';
                                 $available_program['cost_per_volume_image'] = type_to_str($available_program['cost_image'], 'money') . ' / ' . type_to_str($available_program['volume'], 'integer') . ' ';
                                 if ('CPM' == $available_program['program_type']) {
                                     $available_program['cost_per_volume_text'] .= __('impressions');
                                     $available_program['cost_per_volume_image'] .= __('impressions');
                                 } else {
                                     $available_program['cost_per_volume_text'] .= __('days');
                                     $available_program['cost_per_volume_image'] .= __('days');
                                 }
                             }
                         }
                         $sites_channels_programs[$site_channel['id_site_channel']] = array('programs' => $available_programs, 'restrictions' => array('flat_rate_image_is_allowed' => $flat_rate_image_is_allowed, 'flat_rate_is_allowed' => $flat_rate_is_allowed));
                     }
                 }
             }
         }
     } else {
         $sites_channels_array = array();
     }
     $data_rows_conut = sizeof($sites_channels_array);
     $row_counter = 1;
     $this->table_builder->insert_empty_cells = false;
     for ($i = 0; $i < $data_rows_conut; $i++) {
         $this->table_builder->set_cell_content($row_counter, 0, limit_str_and_hint($sites_channels_array[$i]['site_name'], 30) . ' (<a target="_blank" href="http://' . $sites_channels_array[$i]['site_url'] . '">' . $sites_channels_array[$i]['site_url'] . '</a>)');
         $this->table_builder->set_cell_content($row_counter, 1, type_to_str($sites_channels_array[$i]['channel_name'], 'encode'));
         $allowedTypes = explode(',', $sites_channels_array[$i]['ad_type']);
         $sites_channels_programs[$sites_channels_array[$i]['id_site_channel']]['allowed'] = $allowedTypes;
         $sites_channels_programs[$sites_channels_array[$i]['id_site_channel']]['labels'] = array('text' => __('Text'), 'image' => __('Image'));
         $this->table_builder->set_cell_content($row_counter, 2, '');
         $selected_ad_type = $added_sites_channels[$sites_channels_array[$i]['id_site_channel']]['ad_type'];
         if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
             $ico_path = $this->site_url . 'images/smartppc6/icons/script_code.png';
             $hint_title = __('Text Ad') . ' (' . $sites_channels_array[$i]['width'] . '&times;' . $sites_channels_array[$i]['height'] . ')';
             $img_prefix = 'txt_';
             $this->table_builder->cell($row_counter, 2)->add_content(array('src' => $ico_path, 'extra' => 'title="' . $hint_title . '" href="' . $this->site_url . 'images/dimensions_preview/' . $img_prefix . $sites_channels_array[$i]['id_dimension'] . '.png" class="tooltip"'), 'image');
         }
         if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes)) {
             $ico_path = $this->site_url . 'images/smartppc6/icons/image.png';
             $hint_title = __('Image Ad') . ' (' . $sites_channels_array[$i]['width'] . '&times;' . $sites_channels_array[$i]['height'] . ')';
             $img_prefix = 'img_';
             $this->table_builder->cell($row_counter, 2)->add_content(array('src' => $ico_path, 'extra' => 'title="' . $hint_title . '" href="' . $this->site_url . 'images/dimensions_preview/' . $img_prefix . $sites_channels_array[$i]['id_dimension'] . '.png" class="tooltip"'), 'image');
         }
         $this->table_builder->cell($row_counter, 2)->add_content($sites_channels_array[$i]['width'] . '&times;' . $sites_channels_array[$i]['height'], '', '<br/> ');
         $selected_program_type = $this->channel_program->get_program_type($added_sites_channels[$sites_channels_array[$i]['id_site_channel']]['id_program']);
         $selected_cost_option = $added_sites_channels[$sites_channels_array[$i]['id_site_channel']]['id_program'];
         $program_types_options = array();
         if ('old' == $status_filter) {
             $channel_program_types = array($selected_program_type);
             $program_info = $this->channel_program->get_info($selected_cost_option);
             if (is_null($program_info)) {
                 $program_cost_options = array($selected_cost_option => array('title' => 'ERROR GETTING PROGRAM INFO', 'volume' => 0, 'cost' => 0));
             } else {
                 $cost = $added_sites_channels[$sites_channels_array[$i]['id_site_channel']]['cost'];
                 $volume = $added_sites_channels[$sites_channels_array[$i]['id_site_channel']]['volume'];
                 $program_cost_options = array($selected_cost_option => array('title' => $program_info->title, 'volume' => $volume, 'cost' => $cost));
             }
         } else {
             $channel_program_types = $this->channel_program->get_channel_program_types($sites_channels_array[$i]['id_channel']);
             if (!$sites_channels_programs[$sites_channels_array[$i]['id_site_channel']]['restrictions']['flat_rate_is_allowed']) {
                 foreach ($channel_program_types as $key => $program_type) {
                     if ('Flat_Rate' == $program_type) {
                         unset($channel_program_types[$key]);
                         break;
                     }
                 }
             } else {
                 //Flat Rate на первое место в списке типов программ
                 $flat_rate_index = array_search('Flat_Rate', $channel_program_types);
                 if (FALSE !== $flat_rate_index) {
                     unset($channel_program_types[$flat_rate_index]);
                     array_unshift($channel_program_types, 'Flat_Rate');
                 }
             }
             $program_cost_options = $this->channel_program->get_channel_program_options($sites_channels_array[$i]['id_channel'], $selected_program_type, $selected_ad_type);
         }
         foreach ($program_cost_options as &$cost_option) {
             $cost_option = $cost_option['title'] . ' (' . type_to_str($cost_option['cost'], 'money') . ' / ' . type_to_str($cost_option['volume'], 'integer');
             if ('CPM' == $selected_program_type) {
                 $cost_option .= ' ' . __('impressions') . ')';
             } else {
                 $cost_option .= ' ' . __('days') . ')';
             }
         }
         foreach ($channel_program_types as $channel_program_type) {
             $program_types_options[$channel_program_type] = __($channel_program_type);
         }
         $ad_types_options = array();
         if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
             $ad_types_options['text'] = __('Text');
         }
         if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes)) {
             $keys = array();
             $labels = array();
             if (in_array(Sppc_Channel::AD_TYPE_TEXT, $allowedTypes)) {
                 $keys[] = 'text';
                 $labels[] = __('Text');
             }
             if (in_array(Sppc_Channel::AD_TYPE_IMAGE, $allowedTypes)) {
                 $keys[] = 'image';
                 $labels[] = __('Image');
             }
             $key = implode(',', $keys);
             $label = implode(' & ', $labels);
             $programs = $sites_channels_programs[$sites_channels_array[$i]['id_site_channel']];
             if (in_array('CPM', $program_types_options) || isset($programs['restrictions']) && $programs['restrictions']['flat_rate_image_is_allowed']) {
                 $ad_types_options[$key] = $label;
             }
         }
         $js = 'id_site_channel="' . $sites_channels_array[$i]['id_site_channel'] . '" id="site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_ad_type" class="w200" onchange="onChangeAdType(' . $sites_channels_array[$i]['id_site_channel'] . ',' . $sites_channels_array[$i]['id_channel'] . ');"';
         $this->table_builder->set_cell_content($row_counter, 3, form_dropdown('site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_ad_type', $ad_types_options, $selected_ad_type, $js));
         $js = 'id_site_channel="' . $sites_channels_array[$i]['id_site_channel'] . '" id="site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_program_type" onchange="onChangeProgramType(' . $sites_channels_array[$i]['id_site_channel'] . ',' . $sites_channels_array[$i]['id_channel'] . ');"';
         $this->table_builder->set_cell_content($row_counter, 4, form_dropdown('site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_program_type', $program_types_options, $selected_program_type, $js));
         $js = 'id_site_channel="' . $sites_channels_array[$i]['id_site_channel'] . '" id_channel="' . $sites_channels_array[$i]['id_channel'] . '" class="site_channel_program w100p" id="site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_option" onchange="onChangeProgramOption(' . $sites_channels_array[$i]['id_site_channel'] . ',' . $sites_channels_array[$i]['id_channel'] . ');"';
         $this->table_builder->set_cell_content($row_counter, 5, form_dropdown('site_channel_' . $sites_channels_array[$i]['id_site_channel'] . '_program_option', $program_cost_options, $selected_cost_option, $js));
         $this->table_builder->set_cell_content($row_counter, 7, type_to_str($sites_channels_array[$i]['impressions'], 'impressions'));
         $this->table_builder->set_cell_content($row_counter, 8, '<input type="button" type="button" class="guibutton floatl ico ico-delete" jframe="no" value="' . __('Delete') . '" onclick="return ' . $delete_js_function . '(' . $sites_channels_array[$i]['id_site_channel'] . ')">');
         $this->table_builder->add_row_attribute($row_counter, 'id', "tr{$sites_channels_array[$i]['id_site_channel']}");
         $this->table_builder->add_row_attribute($row_counter, 'id_site_channel', $sites_channels_array[$i]['id_site_channel']);
         if ('new' == $status_filter) {
             $this->table_builder->add_row_attribute($row_counter, 'class', 'new_row');
         }
         $row_counter++;
     }
     if (0 == $data_rows_conut) {
         $this->table_builder->set_cell_content(1, 0, __('Records not found'));
         $this->table_builder->cell(1, 0)->add_attribute('colspan', 9);
         $this->table_builder->cell(1, 0)->add_attribute('class', 'nodata');
         $total_campaign_cost_hint_visibility = 'style="display:none;"';
     } else {
         //Тotal row for new sites/channels
         if ('new' == $status_filter) {
             $this->table_builder->set_cell_content($row_counter, 0, __('Total') . ':');
             $this->table_builder->set_cell_content($row_counter, 1, '&nbsp;');
             $this->table_builder->cell($row_counter, 0)->add_attribute('colspan', 5);
             $this->table_builder->cell($row_counter, 1)->add_attribute('colspan', 4);
             $this->table_builder->cell($row_counter, 1)->add_attribute('id', 'total_cost');
             $this->table_builder->cell($row_counter, 0)->add_attribute('class', 'b');
             $this->table_builder->cell($row_counter, 1)->add_attribute('class', 'b');
             $this->table_builder->cell($row_counter, 0)->add_attribute('style', 'border-top:1px solid #000000;');
             $this->table_builder->cell($row_counter, 1)->add_attribute('style', 'border-top:1px solid #000000;');
         }
         $total_campaign_cost_hint_visibility = '';
     }
     // Устанавливаем возможность выбора колонок
     $this->table_builder->use_select_columns();
     $invariable_columns = array(0, 1, 3, 4, 5, 8);
     $this->table_builder->set_invariable_columns($invariable_columns);
     $table = $this->table_builder->get_sort_html();
     $columns = $this->table_builder->get_columns_html();
     $this->template = "common/parent/jq_iframe.html";
     if ('new' == $status_filter) {
         $iframe_form_template = 'iframe_recently_added_channels_table.html';
     } else {
         $iframe_form_template = 'iframe_added_channels_table.html';
     }
     $this->_set_content($this->parser->parse('advertiser/manage_ads/campaigns/creation/set_pricing/' . $iframe_form_template, array('CHANNELS_TABLE' => $table, 'SITES_CHANNELS_PROGRAMS' => json_encode($sites_channels_programs), 'TOTAL_CAMPAIGN_COST_HINT_VISIBILITY' => $total_campaign_cost_hint_visibility, 'COLUMNS' => $columns), TRUE));
     $this->_display();
 }
 /**
  * Callback-функция, проверяет введенные данные и сохраняет новый запрос отчета
  *
  * @param array $fields массив с полями заполненными пользователем
  * @return string при неудаче - текст ошибки
  */
 public function _create($fields)
 {
     $this->global_variables->set('ReportCreated', 'true', $this->user_id);
     $this->load->model('report_types');
     $this->load->helper('periods');
     $range = data_range($fields);
     if (is_null($fields['extra'])) {
         $fields['extra'] = '';
     }
     $id_report = $this->report_types->add_new_report($this->user_id, $fields['report_type'], $this->input->post('vis_report_type_' . $fields['report_type']), $range['from'], $range['to'], $fields['report_name'], $fields['extra']);
     if (!$id_report) {
         return "Can't create new report request.";
     }
     $this->load->model("report_generator", "", TRUE);
     $this->load->model("sqlite");
     $sqlite_file = $this->report_generator->get_sqlite_file($id_report);
     $sqlite = $this->sqlite->get_database($sqlite_file);
     if (!$sqlite) {
         $this->report_types->action('delete', $this->user_id, $id_report);
         return "Can't create SQLite database object.";
     }
     $this->report_generator->generate_report($id_report, $sqlite);
     return '';
 }