core = $core;
if (isset($_GET['ad_id'])) {
$this->ad_id = $_GET['ad_id'];
}
$this->date_time = $rDateTime = date('Y-m-d H:i:s');
$this->action_by_ip = $_SERVER['REMOTE_ADDR'];
$this->check_add_update();
$this->display_form();
}
function check_add_update() {
$output = '';
if (isset($_POST['msbd_adsmp_save']) && $_POST['msbd_adsmp_save'] == 'save') {
$this->sponsor_type = $this->core->msbd_sanitization($_POST['sponsor_type'], 'text');
$this->content_type = $this->core->msbd_sanitization($_POST['content_type'], 'text');
$this->script = $this->core->msbd_sanitization($_POST['script'], 'html_js');
$this->remark = $this->core->msbd_sanitization($_POST['remark'], 'html');
$this->adv_sizes = $this->core->msbd_sanitization($_POST['adv_sizes'], 'text');
$this->width = $this->core->msbd_sanitization($_POST['width'], 'number');
$this->height = $this->core->msbd_sanitization($_POST['height'], 'number');
$this->status = $this->core->msbd_sanitization($_POST['status'], 'text');
$newdata = array(
'date_time' => $this->date_time,
'sponsor_type' => $this->sponsor_type,
'content_type' => $this->content_type,
'script' => $this->script,
'remark' => $this->remark,
'adv_sizes' => $this->adv_sizes,
'width' => $this->width,
'height' => $this->height,
'status' => $this->status,
'action_by_ip' => $this->action_by_ip
);
//dump($newdata, 'NEW DATA');
$validData = true;
if ($this->adv_sizes=='' && empty($this->width) && empty($this->height) ) {
$output .= '
You must choose a predefined size of advertisement or provide width and height combination.
';
$validData = false;
}
if ($this->sponsor_type == '') {
$output .= 'You must choose a type of advertisement.
';
$validData = false;
}
if ($this->content_type == '') {
$output .= 'You must choose a type of advertisement content.
';
$validData = false;
}
if ($this->script == '') {
$output .= 'You must add the script of advertisement.
';
$validData = false;
}
$var_filter = "sponsor_type='$this->sponsor_type' AND content_type='$this->content_type' AND width='$this->width' AND height='$this->height' AND adv_sizes='$this->adv_sizes'";
if($this->ad_id!="") {
$var_filter .= " AND id!='$this->ad_id'";
}
/*
// After the 0.1 version plugin can create multiple advertisement with same configuration.
// So the unique
$isExist = $this->core->db->check_exist($var_filter, false);
if ($isExist) {
$output .= 'Advertisement from the sponsor with same size, and type is exist!
';
$validData = false;
}
*/
if ($validData) {
$this->core->db->set_table("main_tbl");
$rs = $this->core->db->save($newdata, $this->ad_id);
$output .= 'The advertisement has been saved.
';
$categories = isset($_POST['categories']) ? $_POST['categories'] : array();
if( !empty($categories) ) {
if( !empty($this->ad_id) ) {
$this->core->db->delete_terms_rel($this->ad_id);
} else {
$this->ad_id = $rs;
}
foreach($categories as $i=>$v) {
$terms_rel_data = array("adv_id"=>$this->ad_id, "term_id"=>$i, "term_slug"=>$v);
$this->core->db->set_table("terms_rel_tbl");
$this->core->db->save($terms_rel_data);
}
}
}
//wp_redirect( MSBD_ADSMP_URL."wp-admin/admin.php?page=msbd_adsmp_manage" );
//exit;
}
echo $output;
}
function display_form($record = '') {
if ($this->ad_id && empty($record)) {
$rs = $this->core->db->get_adv_record($this->ad_id, false);
$this->display_form($rs);
return;
}
$isEdit = !empty($this->ad_id) ? 1 : 0;
$field_read_only = !empty($this->ad_id) ? ' readonly=""' : '';
$field_disable = !empty($this->ad_id) ? ' disabled="true"' : '';
$var_sponsor_type = adsmp_echo( $record, 'adv.sponsor_type', false);
$var_content_type = adsmp_echo( $record, 'adv.content_type', false);
$var_adv_sizes = adsmp_echo( $record, 'adv.adv_sizes', false);
?>
';
$html = '';
$html .= ' ';
$html .= $cat['name'].' ';
if(!empty($cat['child'])) {
$html .= '';
foreach($cat['child'] as $sub_cat) {
$html .= $this->create_cat_item($sub_cat, $var_terms_slug);
}
$html .= ' ';
}
$html .= ' ';
//$html .= '';
return $html;
}
function get_sponsor_options($att, $selVal='') {
$html = '-- select -- ';
$record =(array) $this->core->db->get_sponsor_types();
foreach($record as $row) {
if($selVal==$row['title'])
$html .= ''.ucfirst($row['title']).' ';
else
$html .= ''.ucfirst($row['title']).' ';
}
$html .= ' ';
return $html;
}
function get_ad_status_options($att, $selVal='') {
$html = '-- select -- ';
$record = array(
1 => array("value"=>"active", "title"=>"Active"),
0 => array("value"=>"inactive", "title"=>"Inactive"),
);
foreach($record as $row) {
if($selVal==$row['value'])
$html .= ''.ucfirst($row['title']).' ';
else
$html .= ''.ucfirst($row['title']).' ';
}
$html .= ' ';
return $html;
}
function get_ad_content_type_options($att, $selVal='') {
$html = '-- select -- ';
$record = array(
0 => "mix",
1 => "image",
2=>"text"
);
foreach($record as $v) {
if($selVal==$v)
$html .= ''.ucfirst($v).' ';
else
$html .= ''.ucfirst($v).' ';
}
$html .= ' ';
return $html;
}
function get_ad_size_options($att, $selVal='') {
$record =(array) $this->core->db->get_adv_sizes();
$html = '-- Custom Size -- ';
foreach($record as $row) {
$var_title = ucfirst(str_replace("-", " ", $row['name'])) . " (".$row['width']."X".$row['height'].")";
if( $row['name']=="responsive" )
$var_title = "Responsive size";
if($selVal==$row['name'])
$html .= ''.$var_title.' ';
else
$html .= ''.$var_title.' ';
}
$html .= ' ';
return $html;
}
}
/* end of file msbd-ads-admin-add-edit.php */