/** * Вывод баненров ajax */ public function ajxLoadAction() { global $sys; $ret = array('error' => ''); $brs = cot_import('brs', 'P', 'ARR'); if (!$brs) { $ret['error'] = 'Nothing to load'; echo json_encode($ret); exit; } $nullDate = date('Y-m-d H:i:s', 0); // 1970-01-01 00:00:00 // Пока выбыраем баненры по одному, // @todo оптимизировать $baseCondition = array(array('published', 1), array('publish_up', date('Y-m-d H:i:s', cot::$sys['now']), '<='), array('SQL', "publish_down >='" . date('Y-m-d H:i:s', cot::$sys['now']) . "' OR publish_down ='{$nullDate}'"), array('SQL', "imptotal = 0 OR impressions < imptotal")); $cnt = 0; foreach ($brs as $pid => $data) { $pid = (int) $pid; if (empty($data['category'])) { $ret['items'][$pid] = ''; continue; } else { $cat = cot_import($data['category'], 'D', 'TXT'); } if ($pid == 0) { continue; } if (empty($cat)) { $ret['items'][$pid] = ''; continue; } $condition = $baseCondition; $condition[] = array('category', $cat); $client = false; if (!empty($data['client'])) { $client = cot_import($data['client'], 'D', 'INT'); } if ($client) { $condition[] = array('client', $client); } $order = 'order'; if (!empty($data['order'])) { $order = cot_import($data['order'], 'D', 'TXT'); } $ord = "lastimp ASC"; if ($order == 'rand') { $ord = 'RAND()'; } // $banner = brs_model_Banner::find($condition, 1, 0, $ord); $banner = brs_model_Banner::fetchOne($condition, $ord); if (empty($banner)) { $ret['items'][$pid] = ''; continue; } $banner->impress(); $url = cot_url('brs', 'a=click&id=' . $banner->id); switch ($banner->type) { case brs_model_Banner::TYPE_IMAGE: if (!empty($banner->file)) { $image = cot_rc('banner_image', array('file' => $banner->file, 'alt' => $banner->alt, 'width' => $banner->width, 'height' => $banner->height)); if (!empty($banner->clickurl)) { $image = cot_rc_link($url, $image, array('target' => '_blank')); } $ret['items'][$pid] = cot_rc('banner', array('banner' => $image)); } break; case brs_model_Banner::TYPE_FLASH: if (!empty($banner->file)) { $image = cot_rc('banner_flash', array('file' => $banner->file, 'width' => $banner->width, 'height' => $banner->height)); if (!empty($banner->clickurl)) { $image = cot_rc_link($url, $image, array('target' => '_blank')); } $ret['items'][$pid] = cot_rc('banner', array('banner' => $image)); } break; case brs_model_Banner::TYPE_CUSTOM: $ret['items'][$pid] = cot_rc('banner', array('banner' => $banner->customcode)); break; } $cnt++; } echo json_encode($ret); exit; }
protected function afterDelete() { // Обновить структуру $count = brs_model_Banner::count(array(array('category', $this->_data['category']))); static::$_db->update(cot::$db->structure, array('structure_count' => $count), "structure_area='brs' AND structure_code=?", $this->_data['category']); cot::$cache && cot::$cache->db->remove('structure', 'system'); }
/** * Update banner category code * * @param string $oldcat Old Cat code * @param string $newcat New Cat code * @return bool * @global CotDB $db */ function cot_brs_updatecat($oldcat, $newcat) { return (bool) cot::$db->update(brs_model_Banner::tableName(), array("category" => $newcat), "category='" . cot::$db->prep($oldcat) . "'"); }
/** * основная статистика кликов и показов */ public function indexAction() { global $admintitle, $adminpath, $structure; $admintitle = cot::$L['brs_tracks']; $adminpath[] = array(cot_url('admin', array('m' => 'brs', 'n' => 'track')), cot::$L['brs_tracks']); $sortFields = array('b.title' => cot::$L['Title'], 'b.category' => cot::$L['Category'], 'b.client' => cot::$L['brs_client'], 't.type' => cot::$L['Type'], 't.track_count' => cot::$L['Count'], 't.date' => cot::$L['Date']); $sort = cot_import('s', 'G', 'TXT'); // order field name $way = cot_import('w', 'G', 'ALP', 4); // order way (asc, desc) $f = cot_import('f', 'G', 'ARR'); // filters $f['date_from'] = cot_import_date('f_df', true, false, 'G'); $f['date_to'] = cot_import_date('f_dt', true, false, 'G'); $maxrowsperpage = cot::$cfg['maxrowsperpage']; if ($maxrowsperpage < 1) { $maxrowsperpage = 1; } list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage); //page number for banners list $sort = empty($sort) ? 't.date' : $sort; $way = empty($way) || !in_array($way, array('asc', 'desc')) ? 'desc' : $way; $urlParams = array('m' => 'brs', 'n' => 'track'); if ($sort != 't.date') { $urlParams['s'] = $sort; } if ($way != 'desc') { $urlParams['w'] = $way; } $where = array(); $params = array(); if (!empty($f)) { foreach ($f as $key => $val) { $val = trim(cot_import($val, 'D', 'TXT')); if (empty($val) && $val !== '0') { continue; } if (in_array($key, array('b.title'))) { $kkey = str_replace('.', '_', $key); $params[$kkey] = "%{$val}%"; $where['filter'][] = "{$key} LIKE :{$kkey}"; $urlParams["f[{$key}]"] = $val; } elseif ($key == 'date_from') { if ($f[$key] == 0) { continue; } $where['filter'][] = "t.date >= '" . date('Y-m-d H:i:s', $f[$key]) . "'"; $urlParams["f_df[year]"] = cot_date('Y', $f[$key]); $urlParams["f_df[month]"] = cot_date('m', $f[$key]); $urlParams["f_df[day]"] = cot_date('d', $f[$key]); } elseif ($key == 'date_to') { if ($f[$key] == 0) { continue; } $where['filter'][] = "t.date <= '" . date('Y-m-d H:i:s', $f[$key]) . "'"; $urlParams["f_dt[year]"] = cot_date('Y', $f[$key]); $urlParams["f_dt[month]"] = cot_date('m', $f[$key]); $urlParams["f_dt[day]"] = cot_date('d', $f[$key]); } else { $kkey = str_replace('.', '_', $key); $params[$kkey] = $val; $where['filter'][] = "{$key} = :{$kkey}"; $urlParams["f[{$key}]"] = $val; } } empty($where['filter']) || ($where['filter'] = implode(' AND ', $where['filter'])); } else { $f = array(); } $orderby = "{$sort} {$way}"; $where = array_filter($where); $where = $where ? 'WHERE ' . implode(' AND ', $where) : ''; $sql = "SELECT `t`.`date`, `t`.`type` , `t`.`track_count`, `t`.`banner`, b.title, b.category, cl.title as client_title,\n cl.id as client_id\n FROM " . cot::$db->banner_tracks . " AS t\n LEFT JOIN " . cot::$db->banners . " AS b ON b.id=t.banner\n LEFT JOIN " . cot::$db->banner_clients . " AS cl ON cl.id=b.client\n {$where} ORDER BY {$orderby} LIMIT {$d}, {$maxrowsperpage}"; $sqlCount = "SELECT COUNT(*)\n FROM " . cot::$db->banner_tracks . " AS t\n LEFT JOIN " . cot::$db->banners . " AS b ON b.id=t.banner\n LEFT JOIN " . cot::$db->banner_clients . " AS cl ON cl.id=b.client\n {$where}"; $totallines = cot::$db->query($sqlCount, $params)->fetchColumn(); $sqllist = cot::$db->query($sql, $params); // Без Ajax, а то дата пропадает (UI datetime) $pagenav = cot_pagenav('admin', $urlParams, $d, $totallines, $maxrowsperpage); $track_types = array(1 => cot::$L['brs_impressions'], 2 => cot::$L['brs_clicks']); $items = $sqllist->fetchAll(); if ($items) { foreach ($items as $key => $itemRow) { $items[$key]['categoryTitle'] = ''; if (!empty($itemRow['category']) && !empty($structure['brs'][$itemRow['category']])) { $items[$key]['categoryTitle'] = $structure['brs'][$itemRow['category']]['title']; } $items[$key]['track_typeTitle'] = $track_types[$itemRow['type']]; } } $clients = brs_model_Client::keyValPairs(); if (!$clients) { $clients = array(); } $filterForm = array('hidden' => cot_inputbox('hidden', 'n', 'track'), 'title' => array('element' => cot_inputbox('text', 'f[b.title]', $f['b.title']), 'label' => brs_model_Banner::fieldLabel('title')), 'category' => array('element' => brs_selectbox_structure('brs', $f['b.category'], 'f[b.category]', '', false, false, true), 'label' => brs_model_Banner::fieldLabel('category')), 'client' => array('element' => cot_selectbox($f['b.client'], 'f[b.client]', array_keys($clients), array_values($clients)), 'label' => brs_model_Banner::fieldLabel('client')), 'type' => array('element' => cot_selectbox($f['t.type'], 'f[t.type]', array_keys($track_types), array_values($track_types)), 'label' => cot::$L['Type']), 'date_from' => array('element' => cot_selectbox_date($f['date_from'], 'short', 'f_df'), 'label' => cot::$L['brs_from']), 'date_to' => array('element' => cot_selectbox_date($f['date_to'], 'short', 'f_dt'), 'label' => cot::$L['brs_to']), 'sort' => array('element' => cot_selectbox($sort, 's', array_keys($sortFields), array_values($sortFields), false), 'label' => cot::$L['adm_sort']), 'way' => array('element' => cot_selectbox($way, 'w', array('asc', 'desc'), array(cot::$L['Ascending'], cot::$L['Descending']), false))); if (isset(cot::$cfg['plugin']['urleditor']) && cot::$cfg['plugin']['urleditor']['preset'] != 'handy') { $filterForm['hidden'] .= cot_inputbox('hidden', 'm', 'brs'); } $template = array('brs', 'admin', 'track'); $view = new View(); $view->page_title = $admintitle; $view->fistNumber = $d + 1; $view->items = $items; $view->clients = $clients; $view->track_types = $track_types; $view->totalitems = $totallines; $view->filterForm = $filterForm; $view->pagenav = $pagenav; // $view->addNewUrl = $addNewUrl; $view->urlParams = $urlParams; $view->filter = $f; /* === Hook === */ foreach (cot_getextplugins('brs.admin.track.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
/** * Generates a banner widget. * * @param string $tpl * @param array|string $cat Category, semicolon separated * @param string $order 'order' OR 'rand' * @param int $cnt Banner count * @param int|bool $client * @param int|bool $subcats * @return string * */ public static function banner($cat = '', $cnt = 1, $tpl = 'brs.banner', $order = 'order', $client = false, $subcats = false) { global $cache_ext; $cats = array(); $client = (int) $client; $cnt = (int) $cnt; if (!empty($cat)) { if (is_array($cat)) { $cats = $cat; } elseif ($cat != '') { $categs = explode(';', $cat); if (is_array($categs)) { foreach ($categs as $tmp) { $tmp = trim($tmp); if (empty($tmp)) { continue; } if ($subcats) { // Specific cat // var_dump(cot_structure_children('banners', $tmp)); $cats = array_merge($cats, cot_structure_children('brs', $tmp, true, true, false, false)); } else { $cats[] = $tmp; } } } $cats = array_unique($cats); } } $nullDate = date('Y-m-d H:i:s', 0); // 1970-01-01 00:00:00 $condition = array(array('published', 1), array('publish_up', date('Y-m-d H:i:s', cot::$sys['now']), '<='), array('SQL', "publish_down >='" . date('Y-m-d H:i:s', cot::$sys['now']) . "' OR publish_down ='{$nullDate}'"), array('SQL', "imptotal = 0 OR impressions < imptotal")); if (count($cats) > 0) { $condition[] = array('category', $cats); } if ($client) { $condition[] = array('client', $client); } $ord = "lastimp ASC"; if ($order == 'rand') { $ord = 'RAND()'; } $items = brs_model_Banner::find($condition, $cnt, 0, $ord); if (!$items) { return ''; } // Display the items $t = new XTemplate(cot_tplfile($tpl, 'plug')); foreach ($items as $itemRow) { // Если включено кеширование и это незарег не засчитываем показ. Баннер будет запрошен аяксом if (!(!empty($cache_ext) && cot::$usr['id'] == 0 && cot::$cfg['cache_' . $cache_ext])) { $itemRow->impress(); } self::$count++; // Порядковый номер баннера на странице $itemRow->number = self::$count; } $view = new View(); $view->items = $items; $view->order = $order; $view->client = $client; return $view->render($tpl); }
public function deleteAction() { $id = cot_import('id', 'G', 'INT'); $d = cot_import('d', 'G', 'INT'); $backUrlParams = array('m' => 'brs'); if (!empty($d)) { $backUrlParams['d'] = $d; } // Фильтры из списка $f = cot_import('f', 'G', 'ARR'); if (!empty($f)) { foreach ($f as $key => $val) { if ($key == 'id') { continue; } $backUrlParams["f[{$key}]"] = $val; } } $sort = cot_import('s', 'G', 'ALP'); // order field name $way = cot_import('w', 'G', 'ALP', 4); // order way (asc, desc) if ($sort != 'title') { $backUrlParams['s'] = $sort; } if ($way != 'asc') { $backUrlParams['w'] = $way; } if (!$id) { cot_error(cot::$L['brs_err_not_found']); cot_redirect(cot_url('admin', $backUrlParams)); } $item = brs_model_Banner::getById($id); if (!$item) { cot_error(cot::$L['brs_err_not_found']); cot_redirect(cot_url('admin', $backUrlParams)); } $title = $item->title; $item->delete(); cot_message(sprintf(cot::$L['brs_deleted'], $title)); cot_redirect(cot_url('admin', $backUrlParams, '', true)); }