1 <?php 2 3 if (!defined('BASEPATH')) exit('Нет доступа к скрипту'); 4 session_start(); 5 class Banners 6 7 { 8 private $core; 9 public $on = TRUE; 10 private $shows = 2; 11 public $banners = array(); 12 public $array_shows = array(); 13 public $positions = array(); 14 15 16 17 18 function __construct() 19 { 20 21 $this->core = $CI = & get_instance(); 22 //unset($_SESSION['BANNERS']); die(); 23 $this->Check(); 24 $this->GetAllBanners(); 25 26 27 } 28 29 protected function Check() 30 { 31 if (empty($_SESSION['BANNERS']) && $this->on == TRUE) 32 { 33 34 $_SESSION['BANNERS'] = $this->Get(); 35 36 } 37 } 38 39 public function GetAllBanners(){ 40 41 foreach ($_SESSION['POSITIONS'] as $position) { 42 43 $this->GetCurrentBanner($position); 44 } 45 } 46 47 48 public function Get() 49 { 50 $query = $this->core->db->query('SELECT * FROM banners WHERE status = 1 AND showes>0 AND timeout >= CURDATE() ORDER BY position DESC')->result(); 51 return $this->SortList($query); 52 } 53 54 private function SortList($array) 55 { 56 foreach($array as $value) 57 { 58 59 $this->banners[$value->position]['id'][] = $value->id; 60 $this->banners[$value->position]['image'][] = $value->image; 61 $this->banners[$value->position]['code'][] = $value->code; 62 $this->banners[$value->position]['link'][] = $value->link; 63 $this->banners[$value->position]['showes'][] = $value->showes; 64 $this->array_shows[$value->id] = $this->shows; 65 $this->positions[$value->position] = $value->position; 66 67 68 } 69 $_SESSION['POSITIONS'] = $this->positions; 70 $_SESSION['SHOWS'] = $this->array_shows; 71 72 return $this->banners; 73 } 74 75 private function GetCurrentBanner($id_position, $i = 0){ 76 echo $_SESSION['SHOWS'][$first_banner]; //HERE GET 1 ALWAYS 77 $first_banner = $_SESSION['BANNERS'][$id_position]['id'][$i]; 78 79 if ($_SESSION['SHOWS'][$first_banner] !== 0){ 80 81 $int = $_SESSION['SHOWS'][$first_banner] - 1; 82 $_SESSION['SHOWS'][$first_banner] = $int; 83 //HERE GET 0 84 $_SESSION['BANNERS'][$id_position]['showes'][$i] = ($_SESSION['BANNERS'][$id_position]['showes'][$i]) - 1; 85 86 87 $this->banners[$id_position] = array( 88 89 'id' => $_SESSION['BANNERS'][$id_position]['id'][$i], 90 'image' => $_SESSION['BANNERS'][$id_position]['image'][$i], 91 'code' => $_SESSION['BANNERS'][$id_position]['code'][$i], 92 'link' => $_SESSION['BANNERS'][$id_position]['link'][$i]); 93 94 95 } else { 96 97 if($_SESSION['BANNERS'][$id_position]['showes'][$i] !== 0) { 98 99 array_push($_SESSION['SHOWS'], $_SESSION['SHOWS'][$first_banner] = $this->shows); 100 101 } 102 array_shift($_SESSION['SHOWS']); 103 $this->GetCurrentBanner($id_position, $i++); 104 105 } 106 107 } 108 109 } 110 ?>
GetCurrentBanner
!==0
$_SESSION['SHOWS']
0 (//comment)
$first_banner
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)