Файл: InstantSocial/uploud/components/reklama/model.php
Строк: 123
<?php
if(!defined('VALID_CMS')) { die('ACCESS DENIED'); }
class cms_model_reklama{
function __construct(){
$this->inDB = cmsDatabase::getInstance();
}
public function getConfig(){
$sql = "SELECT * FROM cms_reklama_config";
$result = $this->inDB->query($sql);
$conf = $this->inDB->fetch_assoc($result);
return $conf;
}
public function widthClass($width){
if($width == 80){$witdh_class = 'rec_width_a_80';}
if($width == 90){$witdh_class = 'rec_width_a_90';}
if($width == 100){$witdh_class = 'rec_width_a_100';}
if($width == 110){$witdh_class = 'rec_width_a_110';}
if($width == 120){$witdh_class = 'rec_width_a_120';}
return $witdh_class;
}
public function maxText($size){
if($size == 80){$size = 15;}
if($size == 90){$size = 17;}
if($size == 100){$size = 19;}
if($size == 110){$size = 21;}
if($size == 120){$size = 23;}
return $size;
}
public function lastId(){
$sql = "SELECT * FROM cms_reklama ORDER by id DESC";
$result = $this->inDB->query($sql);
$item = $this->inDB->fetch_assoc($result);
return $item['id'];
}
public function getItem($id, $user_id){
$sql = "SELECT * FROM cms_reklama WHERE id = $id AND user_id = $user_id LIMIT 1";
$result = $this->inDB->query($sql);
if ($this->inDB->num_rows($result)){
$item = $this->inDB->fetch_assoc($result);
}
return $item;
}
public function getBalans($user_id){
$sql = "SELECT * FROM cms_reklama_balans WHERE user_id = $user_id LIMIT 1";
$result = $this->inDB->query($sql);
if ($this->inDB->num_rows($result)){
$item = $this->inDB->fetch_assoc($result);
}
return $item;
}
public function getBanner($id){
$sql = "SELECT * FROM cms_reklama WHERE id = $id LIMIT 1";
$result = $this->inDB->query($sql);
if ($this->inDB->num_rows($result)){
$banner = $this->inDB->fetch_assoc($result);
$banner = cmsCore::callEvent('GET_BANNER', $banner);
return $banner;
} else {
return false;
}
}
public function clickBanner($id){
$date = date('Y-m-d');
$update_sql = "UPDATE cms_reklama SET clics = clics + 1 WHERE id=$id";
$this->inDB->query($update_sql);
$update_click = "UPDATE cms_reklama_hits SET clics = clics + 1 WHERE reklama_id=$id AND hitdate = '$date'";
$this->inDB->query($update_click);
cmsCore::callEvent('CLICK_BANNER', $id);
return true;
}
public function segHits($id){
$date = date('Y-m-d');
$sql = "SELECT * FROM cms_reklama_hits WHERE reklama_id = $id AND hitdate = '$date'";
$result = $this->inDB->query($sql);
if (!$this->inDB->num_rows($result)){ return 0;}
$hits = $this->inDB->fetch_assoc($result);
return $hits['hity'];
}
public function segClick($id){
$date = date('Y-m-d');
$sql = "SELECT * FROM cms_reklama_hits WHERE reklama_id = $id AND hitdate = '$date'";
$result = $this->inDB->query($sql);
if (!$this->inDB->num_rows($result)){ return 0;}
$hits = $this->inDB->fetch_assoc($result);
return $hits['clics'];
}
public function vcheraHits($id){
$date = date("Y-m-d", time()-3600*24);
$sql = "SELECT * FROM cms_reklama_hits WHERE reklama_id = $id AND hitdate = '$date'";
$result = $this->inDB->query($sql);
if (!$this->inDB->num_rows($result)){ return 0;}
$hits = $this->inDB->fetch_assoc($result);
return $hits['hity'];
}
public function vcheraClick($id){
$date = date("Y-m-d", time()-3600*24);
$sql = "SELECT * FROM cms_reklama_hits WHERE reklama_id = $id AND hitdate = '$date'";
$result = $this->inDB->query($sql);
if (!$this->inDB->num_rows($result)){ return 0;}
$hits = $this->inDB->fetch_assoc($result);
return $hits['clics'];
}
public function addReklamaPay($reklama_pay){
$sql = "INSERT INTO cms_reklama_pay (user_id, secret_key, summ, purse, type_wm, pokazi)
VALUES ('{$reklama_pay['user_id']}', '{$reklama_pay['secret_key']}', '{$reklama_pay['summ']}', '{$reklama_pay['purse']}', '{$reklama_pay['type_wm']}', '{$reklama_pay['pokazi']}')";
$this->inDB->query($sql);
$reklama_pay_id = $this->inDB->get_last_id('cms_reklama_pay');
return $reklama_pay_id;
}
public function getReklamaPay($id){
$sql = "SELECT * FROM cms_reklama_pay WHERE id = '{$id}'";
$result = $this->inDB->query($sql);
$reklama_pay = $this->inDB->fetch_assoc($result);
return $reklama_pay;
}
public function deleteExpiredReklamaPay($session_id) {
$secret_key = md5($session_id);
$this->inDB->query("DELETE FROM cms_reklama_pay WHERE secret_key='$secret_key' LIMIT 1");
return true;
}
public function isURL($value) {
if($value && !preg_match("^(http://|https://)?(www\.)?([a-zA-Z0-9])([a-zA-Z0-9_.-]+)\.([a-zA-Z]{2,4})$",$value,$arrw)) return 0;
if (!strstr( $value,"://" )) $value = "http://".$value;
$value = strtolower($value);
return $value;
}
}
?>