Files

1497 lines
66 KiB
PHP
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
<?php
session_start();
if (isset($_GET['debug'])) error_reporting(-1);
else error_reporting(0);
include_once(dirname(__FILE__).'/inc/config.php');
include_once(dirname(__FILE__).'/inc/settings.php');
include_once(dirname(__FILE__).'/inc/icdb.php');
include_once(dirname(__FILE__).'/inc/functions.php');
$icdb = new ICDB(DB_HOST, DB_HOST_PORT, DB_NAME, DB_USER, DB_PASSWORD, TABLE_PREFIX);
install();
$is_logged = false;
$session_id = '';
if (isset($_COOKIE['ubm-auth'])) {
$session_id = preg_replace('/[^a-zA-Z0-9]/', '', $_COOKIE['ubm-auth']);
$session_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."sessions WHERE session_id = '".$session_id."' AND registered + valid_period > '".time()."'");
if ($session_details) {
$icdb->query("UPDATE ".$icdb->prefix."sessions SET registered = '".time()."', ip = '".$_SERVER['REMOTE_ADDR']."' WHERE session_id = '".$session_id."'");
$is_logged = true;
}
}
get_options();
handle_version();
$currency_list = array_unique(array_merge($paypal_currency_list, $payza_currency_list, $interkassa_currency_list, $egopay_currency_list, $perfect_currency_list, $skrill_currency_list, $bitpay_currency_list));
sort($currency_list);
$currency_list = array_unique(array_merge(array("USD"), $currency_list));
$url_base = ((empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] == 'off') ? 'http://' : 'https://').$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$filename = basename(__FILE__);
if (($pos = strpos($url_base, $filename)) !== false) $url_base = substr($url_base, 0, $pos);
if (isset($_SESSION['error'])) {
$error_message = $_SESSION['error'];
unset($_SESSION['error']);
} else $error_message = '';
if (isset($_SESSION['ok'])) {
$ok_message = $_SESSION['ok'];
unset($_SESSION['ok']);
} else $ok_message = '';
$pages = array (
'settings' => array('title' => 'Settings', 'menu' => true),
'types' => array('title' => 'Banner Types', 'menu' => true),
'banners' => array('title' => 'Banners', 'menu' => true),
'embed' => array('title' => 'Embedding', 'menu' => true),
'edit' => array('title' => 'Edit Banner', 'menu' => false),
'edittype' => array('title' => 'Edit Banner Type', 'menu' => false)
);
$deafult_page = 'types';
if ($is_logged) {
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'logout':
if (!empty($session_id)) {
$icdb->query("UPDATE ".$icdb->prefix."sessions SET valid_period = '0' WHERE session_id = '".$session_id."'");
}
header('Location: admin.php');
exit;
break;
case 'update-options':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=settings');
exit;
}
if (empty($_POST["login"])) {
$_SESSION['error'] = '<strong>Invalid login value.</strong> Empty admin login value is not allowed.';
header('Location: admin.php?page=settings');
exit;
}
if (isset($_POST['action']) && $_POST['action'] == 'update-options') {
populate_options();
if (isset($_POST["enable_approval"])) $options['enable_approval'] = "on";
else $options['enable_approval'] = "off";
if (isset($_POST["enable_paypal"])) $options['enable_paypal'] = "on";
else $options['enable_paypal'] = "off";
if (isset($_POST["enable_payza"])) $options['enable_payza'] = "on";
else $options['enable_payza'] = "off";
if (isset($_POST["payza_sandbox"])) $options['payza_sandbox'] = "on";
else $options['payza_sandbox'] = "off";
if (isset($_POST["enable_skrill"])) $options['enable_skrill'] = "on";
else $options['enable_skrill'] = "off";
if (isset($_POST["enable_interkassa"])) $options['enable_interkassa'] = "on";
else $options['enable_interkassa'] = "off";
if (isset($_POST["enable_authnet"])) $options['enable_authnet'] = "on";
else $options['enable_authnet'] = "off";
if (isset($_POST["authnet_sandbox"])) $options['authnet_sandbox'] = "on";
else $options['authnet_sandbox'] = "off";
if (isset($_POST["enable_egopay"])) $options['enable_egopay'] = "on";
else $options['enable_egopay'] = "off";
if (isset($_POST["enable_perfect"])) $options['enable_perfect'] = "on";
else $options['enable_perfect'] = "off";
if (isset($_POST["enable_bitpay"])) $options['enable_bitpay'] = "on";
else $options['enable_bitpay'] = "off";
if (isset($_POST["enable_stripe"])) $options['enable_stripe'] = "on";
else $options['enable_stripe'] = "off";
$errors = check_options();
if (isset($_POST['password'])) $password = trim(stripslashes($_POST['password']));
else $password = '';
if (isset($_POST['confirm_password'])) $confirm_password = trim(stripslashes($_POST['confirm_password']));
else $confirm_password = '';
if (!empty($password)) {
if ($password == $confirm_password) {
$options['password'] = md5($password);
} else {
if ($errors === true) $errors = array('Password and its confirmation are not equal');
else $errors[] = 'Password and its confirmation are not equal';
}
}
update_options();
if (is_array($errors)) {
$_SESSION['error'] = 'The following error(s) exists:<ul><li>'.implode('</li><li>', $errors).'</li></ul>';
} else {
$_SESSION['ok'] = 'Settings successfully saved!';
}
}
header('Location: admin.php?page=settings');
exit;
break;
case 'update-type':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=types');
exit;
}
if (isset($_POST['action']) && $_POST['action'] == 'update-type') {
unset($id);
if (isset($_POST["id"]) && !empty($_POST["id"])) {
$id = intval($_POST["id"]);
$type_details = $icdb->get_row("SELECT t1.*, t2.total_banners, t2.total_amount FROM ".$icdb->prefix."types t1 LEFT JOIN (SELECT type_id, SUM(amount) AS total_amount, COUNT(*) AS total_banners FROM ".$icdb->prefix."banners WHERE status != '".STATUS_DRAFT."' AND deleted = '0' GROUP BY type_id) t2 ON t2.type_id = t1.id WHERE t1.id = '".$id."' AND t1.deleted = '0'");
if (!$type_details) unset($id);
}
$title = trim(stripslashes($_POST['title']));
$type = intval(trim($_POST["type"]));
$slots = intval(trim($_POST["slots"]));
if ($type != 0) {
foreach($types as $type_tmp) {
if ($type_tmp["id"] == $type) {
$width = $type_tmp["width"];
$height = $type_tmp["height"];
break;
}
}
} else {
$width = intval(trim($_POST["width"]));
$height = intval(trim($_POST["height"]));
}
$error = array();
if (empty($title)) $errors[] = 'Title is too short';
else if (strlen($title) > 128) $errors[] = 'Title is too long';
if ($slots <= 0) $errors[] = 'Number of slots must be higher then zero';
if ($width < 20) $errors[] = 'Width must be 20 or higher';
if ($height < 20) $errors[] = 'Height must be 20 or higher';
if (!empty($id) && $type_details["total_banners"] > 0 && ($width != $type_details["width"] || $height != $type_details["height"])) $errors[] = 'Banner size must be the same, because you have banners of this type';
if (!empty($errors)) {
$_SESSION['error'] = 'The following error(s) exists:<ul><li>'.implode('</li><li>', $errors).'</li></ul>';
$_SESSION['title'] = $title;
$_SESSION['width'] = $width;
$_SESSION['height'] = $height;
$_SESSION['slots'] = $slots;
header('Location: admin.php?page=edittype'.(empty($id) ? '' : '&id='.$id));
exit;
} else {
if (!empty($id)) {
$icdb->query("UPDATE ".$icdb->prefix."types SET
title = '".$icdb->escape_string($title)."',
width = '".$width."',
height = '".$height."',
slots = '".$slots."'
WHERE id = '".$id."'");
$_SESSION['ok'] = 'Banner Type details successfully updated!';
} else {
$icdb->query("INSERT INTO ".$icdb->prefix."types
(title, width, height, slots, status, details, registered, deleted) VALUES (
'".$icdb->escape_string($title)."',
'".$width."',
'".$height."',
'".$slots."',
'".STATUS_ACTIVE."', '',
'".time()."', '0')");
$_SESSION['ok'] = 'New Banner Type successfully added!';
}
}
}
header('Location: admin.php?page=types');
exit;
break;
case 'delete-type':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=types');
exit;
}
$id = intval($_GET["id"]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$id."' AND deleted = '0'");
if (intval($type_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=types');
exit;
}
$sql = "UPDATE ".$icdb->prefix."types SET deleted = '1' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Record successfully deleted!';
} else {
$_SESSION['error'] = 'Record can not be deleted!';
}
header('Location: admin.php?page=types');
exit;
break;
case 'delete-all-types':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=types');
exit;
}
$sql = "UPDATE ".$icdb->prefix."types SET deleted = '1' WHERE deleted != '1'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Records successfully deleted!';
} else {
$_SESSION['error'] = 'Records can not be deleted!';
}
header('Location: admin.php?page=types');
exit;
break;
case 'block-type':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=types');
exit;
}
$id = intval($_GET["id"]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$id."' AND deleted = '0'");
if (intval($type_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=types');
exit;
}
$sql = "UPDATE ".$icdb->prefix."types SET status = '".STATUS_PENDING."' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Banner Type successfully blocked!';
} else {
$_SESSION['error'] = 'Banner Type can not be blocked!';
}
header('Location: admin.php?page=types');
exit;
break;
case 'unblock-type':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=types');
exit;
}
$id = intval($_GET["id"]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$id."' AND deleted = '0'");
if (intval($type_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=types');
exit;
}
$sql = "UPDATE ".$icdb->prefix."types SET status = '".STATUS_ACTIVE."' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Banner Type successfully unblocked!';
} else {
$_SESSION['error'] = 'Banner Type can not be unblocked!';
}
header('Location: admin.php?page=types');
exit;
break;
case 'update-banner':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=banners');
exit;
}
if (isset($_POST['action']) && $_POST['action'] == 'update-banner') {
if (isset($_POST["cid"])) $cid = intval(trim(stripslashes($_POST["cid"])));
else $cid = 0;
unset($id);
if (isset($_POST["id"]) && !empty($_POST["id"])) {
$id = intval($_POST["id"]);
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$id."' AND deleted = '0'");
if (!$banner_details) unset($id);
}
$type_id = intval($_POST['type_id']);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$type_id."' AND deleted = '0'");
if (!$type_details) {
if (isset($id)) {
$type_id = $banner_details['type_id'];
} else {
$_SESSION['error'] = 'Banner Type not found!';
header('Location: admin.php?page=edit'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
}
$title = trim(stripslashes($_POST['title']));
$email = trim(stripslashes($_POST['email']));
$url = trim(stripslashes($_POST['url']));
$days_purchased = trim(stripslashes($_POST['days_purchased']));
$source = intval($_POST['source']);
$content = trim(stripslashes($_POST['content']));
$errors = array();
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $email) && strlen($email) > 0) $errors[] = 'E-mail must be valid e-mail address';
if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url) && strlen($url) > 0) $errors[] = 'URL must be valid URL';
if (!is_numeric($days_purchased) || intval($days_purchased) <= 0) $errors[] = 'Invalid rotation period';
if (isset($_POST['filename'])) $file = trim($_POST['filename']);
else if (!empty($id)) $file = $banner_details["file"];
else $file = '';
if ($source == SOURCE2_IMAGE) {
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
$ext = "";
if (($pos = strrpos($_FILES["file"]["name"], ".")) !== false) {
$ext = strtolower(substr($_FILES["file"]["name"], $pos));
}
if ($ext != ".jpg" && $ext != ".jpeg" && $ext != ".gif" && $ext != ".png") $errors[] = 'Banner image must be JPEG, GIF or PNG file';
else {
list($width, $height, $imagetype, $attr) = getimagesize($_FILES["file"]["tmp_name"]);
if ($width != $type_details["width"] || $height != $type_details["height"]) $errors[] = 'Banner image size must be '.$type_details["width"].'x'.$type_details["height"];
else {
$file = "banner_".random_string(16).$ext;
if (!move_uploaded_file($_FILES["file"]["tmp_name"], ABSPATH."/files/".$file)) {
$errors[] = 'Can not save uploaded banner image';
$file = "";
} else {
if (!empty($banner_details["file"]) && empty($errors)) {
if (file_exists(ABSPATH."/files/".$banner_details["file"]) && is_file(ABSPATH."/files/".$banner_details["file"]))
unlink(ABSPATH."/files/".$banner_details["file"]);
}
}
}
}
} else if (!file_exists(ABSPATH."/files/".$file) || !is_file(ABSPATH."/files/".$file)) $errors[] = 'Banner image must be uploaded';
} else if ($source == SOURCE2_CONTENT) {
} else $errors[] = 'Invalid banner source';
if (!empty($errors)) {
$_SESSION['error'] = 'The following error(s) exists:<ul><li>'.implode('</li><li>', $errors).'</li></ul>';
$_SESSION['title'] = $title;
$_SESSION['email'] = $email;
$_SESSION['url'] = $url;
$_SESSION['days_purchased'] = $days_purchased;
$_SESSION['type_id'] = $type_id;
$_SESSION['file'] = $file;
$_SESSION['source'] = $source;
$_SESSION['content'] = $content;
header('Location: admin.php?page=edit'.(empty($id) ? '' : '&id='.$id).($cid == 0 ? '' : '&cid='.$cid));
exit;
} else {
if (!empty($id)) {
$status = $banner_details['status'];
if ($status == STATUS_EXPIRED) {
if ($banner_details['registered']+24*3600*intval($days_purchased) >= time()) $status = STATUS_ACTIVE;
}
$icdb->query("UPDATE ".$icdb->prefix."banners SET
type_id = '".$type_id."',
title = '".$icdb->escape_string($title)."',
email = '".$icdb->escape_string($email)."',
url = '".$icdb->escape_string($url)."',
days_purchased = '".intval($days_purchased)."',
status = '".$status."',
source = '".$source."',
content = '".$icdb->escape_string($content)."',
file = '".$icdb->escape_string($file)."'
WHERE id = '".$id."'");
$_SESSION['ok'] = 'Banner details successfully updated!';
} else {
$icdb->query("INSERT INTO ".$icdb->prefix."banners (
type_id,
title,
email,
url,
file,
days_purchased,
amount,
currency,
shows_displayed,
clicks,
id_str,
status,
details,
echo,
source,
content,
registered,
blocked,
deleted
) VALUES (
'".$type_id."',
'".$icdb->escape_string($title)."',
'".$icdb->escape_string($email)."',
'".$icdb->escape_string($url)."',
'".$icdb->escape_string($file)."',
'".$icdb->escape_string($days_purchased)."',
'0.00', 'USD', '0', '0', '".random_string(16)."',
'".STATUS_ACTIVE."', '', '',
'".$source."',
'".$icdb->escape_string($content)."',
'".time()."', '0', '0')");
$_SESSION['ok'] = 'New banner successfully added!';
}
}
}
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$type_id));
exit;
break;
case 'delete-banner':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=banners');
exit;
}
if (isset($_GET["cid"])) $cid = intval($_GET["cid"]);
else $cid = 0;
$id = intval($_GET["id"]);
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$id."' AND deleted = '0'");
if (intval($banner_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
$sql = "UPDATE ".$icdb->prefix."banners SET deleted = '1' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Record successfully deleted!';
if ($banner_details["blocked"] == $banner_details["registered"] && !empty($banner_details["email"]) && $options['enable_approval'] == 'on') {
$tags = array("{banner_title}");
$vals = array($banner_details["title"]);
$body = str_replace($tags, $vals, $options['rejected_email_body']);
$mail_headers = "Content-Type: text/plain; charset=utf-8\r\n";
$mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n";
$mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n";
mail($banner_details["email"], $banner_details["title"], $body, $mail_headers);
$_SESSION['ok'] = 'Record successfully deleted and advertiser notified about rejection!';
}
} else {
$_SESSION['error'] = 'Record can not be deleted!';
}
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
break;
case 'delete-all-banners':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=banners');
exit;
}
if (isset($_GET["cid"])) $cid = intval($_GET["cid"]);
else $cid = 0;
$sql = "UPDATE ".$icdb->prefix."banners SET deleted = '1' WHERE deleted != '1'".($cid == 0 ? '' : " AND type_id = '".$cid."'");
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Records successfully deleted!';
} else {
$_SESSION['error'] = 'Records can not be deleted!';
}
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
break;
case 'block-banner':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=banners');
exit;
}
if (isset($_GET["cid"])) $cid = intval($_GET["cid"]);
else $cid = 0;
$id = intval($_GET["id"]);
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$id."' AND deleted = '0'");
if (intval($banner_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
if ($banner_details['status'] != STATUS_ACTIVE) {
$_SESSION['error'] = 'Banner can not be blocked!';
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
$sql = "UPDATE ".$icdb->prefix."banners SET status = '".STATUS_PENDING."', blocked = '".time()."' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Banner successfully blocked!';
} else {
$_SESSION['error'] = 'Banner can not be blocked!';
}
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
break;
case 'unblock-banner':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=banners');
exit;
}
if (isset($_GET["cid"])) $cid = intval($_GET["cid"]);
else $cid = 0;
$id = intval($_GET["id"]);
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$id."' AND deleted = '0'");
if (intval($banner_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
if ($banner_details['status'] != STATUS_PENDING) {
$_SESSION['error'] = 'Banner is already unblocked!';
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
}
if (intval($banner_details["blocked"]) >= $banner_details["registered"]) {
$registered = time() - $banner_details["blocked"] + $banner_details["registered"];
} else $registered = $banner_details["registered"];
$sql = "UPDATE ".$icdb->prefix."banners SET status = '".STATUS_ACTIVE."', registered = '".$registered."' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Banner successfully unblocked!';
if ($banner_details["blocked"] == $banner_details["registered"] && !empty($banner_details["email"]) && $options['enable_approval'] == 'on') {
$tags = array("{banner_title}");
$vals = array($banner_details["title"]);
$body = str_replace($tags, $vals, $options['approved_email_body']);
$mail_headers = "Content-Type: text/plain; charset=utf-8\r\n";
$mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n";
$mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n";
mail($banner_details["email"], $banner_details["title"], $body, $mail_headers);
$_SESSION['ok'] = 'Banner successfully unblocked and advertiser notified about approval!';
}
} else {
$_SESSION['error'] = 'Banner can not be unblocked!';
}
header('Location: admin.php?page=banners'.($cid == 0 ? '' : '&cid='.$cid));
exit;
break;
case 'delete-transaction':
if (DEMO_MODE) {
$_SESSION['error'] = '<strong>Demo mode.</strong> This operation is disabled.';
header('Location: admin.php?page=transactions');
exit;
}
$id = intval($_GET["id"]);
$transaction_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."transactions WHERE id = '".$id."' AND deleted = '0'");
if (intval($transaction_details["id"]) == 0) {
$_SESSION['error'] = 'Record not found!';
header('Location: admin.php?page=transactions');
exit;
}
$sql = "UPDATE ".$icdb->prefix."transactions SET deleted = '1' WHERE id = '".$id."'";
if ($icdb->query($sql) !== false) {
$_SESSION['ok'] = 'Record successfully deleted!';
} else {
$_SESSION['error'] = 'Record can not be deleted!';
}
header('Location: admin.php?page=transactions');
exit;
break;
default:
break;
}
header('Location: admin.php');
exit;
}
if (isset($_GET['page'])) {
$page = preg_replace('/[^a-zA-Z0-9]/', '', $_GET['page']);
if (!array_key_exists($_GET['page'], $pages)) $page = $deafult_page;
} else $page = $deafult_page;
} else {
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'login':
if (isset($_POST['password'])) $password = trim(stripslashes($_POST['password']));
else $password = '';
if (isset($_POST['login'])) $login = trim(stripslashes($_POST['login']));
else $login = '';
if ($login == $options['login'] && md5($password) == $options['password']) {
$session_id = random_string(16);
$icdb->query("INSERT INTO ".$icdb->prefix."sessions (ip, session_id, registered, valid_period) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".$session_id."', '".time()."', '900')");
setcookie('ubm-auth', $session_id, time()+3600*24*180);
$_SESSION['ok'] = 'Welcome to admin panel!'.(DEMO_MODE ? ' Admin Panel operates in <strong>demo mode</strong> for security reasons.' : '');
} else $_SESSION['error'] = 'Invalid login or password!';
header('Location: admin.php');
exit;
break;
default:
break;
}
header('Location: admin.php');
exit;
}
$page = 'login';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo (array_key_exists($page, $pages) ? $pages[$page]['title'] : 'Login').' - '; ?>Ads Manager</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="js/jquery-1.10.1.min.js"></script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-modal.js"></script>
<body>
<!-- Header - begin -->
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Ads Manager</a>
<?php
if ($is_logged) echo '
<a class="navbar-text pull-right" href="admin.php?action=logout">Logout</a>';
else echo '
<a class="navbar-text pull-right" href="admin.php?page=login">Login</a>';
if ($is_logged) {
?>
<ul class="nav">
<?php
foreach ($pages as $key => $value) {
if ($value['menu']) echo '
<li'.($key == $page ? ' class="active"' : '').'><a href="admin.php?page='.$key.'">'.$value['title'].'</a></li>';
}
?>
</ul>
<?php
}
?>
</div>
</div>
</div>
<!-- Header - end -->
<div class="container" style="margin-top: 40px; margin-bottom: 40px;">
<?php
if ($page == 'settings') {
if (empty($error_message)) {
$errors = check_options();
if (is_array($errors)) $message = '<div class="alert alert-error">The following error(s) exists:<ul><li>'.implode('</li><li>', $errors).'</li></ul></div>';
else if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else if (DEMO_MODE) $message = '<div class="alert alert-warning"><strong>Demo mode.</strong> Real e-mails and payment details are hidden.</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
if (DEMO_MODE) {
$hidden_options = array (
"owner_email" => "<hidden>",
"from_email" => "<hidden>",
"paypal_id" => "<hidden>",
"payza_id" => "<hidden>",
"interkassa_checkout_id" => "<hidden>",
"interkassa_secret_key" => "<hidden>",
"authnet_login" => "<hidden>",
"authnet_key" => "<hidden>",
"authnet_md5hash" => "<hidden>",
"skrill_id" => "<hidden>",
"skrill_secret_word" => "<hidden>",
"egopay_store_id" => "<hidden>",
"egopay_store_pass" => "<hidden>",
"perfect_account_id" => "<hidden>",
"perfect_payee_name" => "<hidden>",
"perfect_passphrase" => "<hidden>",
"bitpay_key" => "<hidden>",
"stripe_secret" => "<hidden>",
"stripe_publishable" => "<hidden>"
);
$options = array_merge($options, $hidden_options);
}
?>
<form enctype="multipart/form-data" method="post" action="admin.php?action=update-options">
<h3>General Settings</h3>
<div class="row">
<div class="span3"><strong>E-mail for notifications:</strong></div>
<div class="span9">
<input type="text" class="span9" id="owner_email" name="owner_email" value="<?php echo htmlspecialchars($options['owner_email'], ENT_QUOTES); ?>">
<br /><small>All eventual script alerts are sent to this e-mail address.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Sender name:</strong></div>
<div class="span9">
<input type="text" class="span9" id="from_name" name="from_name" value="<?php echo htmlspecialchars($options['from_name'], ENT_QUOTES); ?>">
<br /><small>All statistics messages to advertisers are sent using this name as "FROM:" header value.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Sender e-mail:</strong></div>
<div class="span9">
<input type="text" class="span9" id="from_email" name="from_email" value="<?php echo htmlspecialchars($options['from_email'], ENT_QUOTES); ?>">
<br /><small>All statistics messages to advertisers are sent using this e-mail as "FROM:" header value. It is recommended to set an existing e-mail address.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Statistics e-mail subject:</strong></div>
<div class="span9">
<input type="text" class="span9" id="stats_email_subject" name="stats_email_subject" value="<?php echo htmlspecialchars($options['stats_email_subject'], ENT_QUOTES); ?>">
<br /><small>All set advertisers receive statistics via email when the campaign is ended. This is the subject field of the message.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Statistics e-mail body:</strong></div>
<div class="span9">
<textarea class="span9" rows="5" id="stats_email_body" name="stats_email_body"><?php echo htmlspecialchars($options['stats_email_body'], ENT_QUOTES); ?></textarea>
<br /><small>Statistics e-mail body. You can use the following keywords: {banner_title}, {statistics}, {signup_page}.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Sign up page:</strong></div>
<div class="span9">
<input type="text" class="span9" id="signup_page" name="signup_page" value="<?php echo htmlspecialchars($options['signup_page'], ENT_QUOTES); ?>">
<br /><small>URL of the page where where paid advertisers can buy ads space.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Minimum days:</strong></div>
<div class="span9">
<input type="text" class="input-mini" id="minimum_days" name="minimum_days" value="<?php echo htmlspecialchars($options['minimum_days'], ENT_QUOTES); ?>">
<br /><small>Enter the minimum number of days this type of ad should stay active for.</small>
</div>
</div>
<hr>
<h3>Admin Settings</h3>
<div class="row">
<div class="span3"><strong>Login:</strong></div>
<div class="span9">
<input type="text" class="input-large" name="login" value="<?php echo htmlspecialchars($options['login'], ENT_QUOTES); ?>">
<br /><small>Please set admin access login.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Password:</strong></div>
<div class="span9">
<input type="password" class="input-large" name="password" autocomplete="off" value="">
<br /><small>Please set admin access password. Leave this field blank if you don't want to change current password.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Confirm password:</strong></div>
<div class="span9">
<input type="password" class="input-large" name="confirm_password" autocomplete="off" value="">
<br /><small>Please confirm admin access password.</small>
</div>
</div>
<div class="row">
<div class="span12">
<input type="hidden" name="action" value="update-options" />
<input type="submit" class="btn btn-primary pull-right" name="submit" value="Update Settings">
</div>
</div>
<hr>
</form>
<script type="text/javascript">
function supportedmethods() {
var paypal_currencies = new Array(<?php echo '"'.implode('", "', $paypal_currency_list).'"'; ?>);
var payza_currencies = new Array(<?php echo '"'.implode('", "', $payza_currency_list).'"'; ?>);
var egopay_currencies = new Array(<?php echo '"'.implode('", "', $egopay_currency_list).'"'; ?>);
var perfect_currencies = new Array(<?php echo '"'.implode('", "', $perfect_currency_list).'"'; ?>);
var skrill_currencies = new Array(<?php echo '"'.implode('", "', $skrill_currency_list).'"'; ?>);
var bitpay_currencies = new Array(<?php echo '"'.implode('", "', $bitpay_currency_list).'"'; ?>);
var stripe_currencies = new Array(<?php echo '"'.implode('", "', $stripe_currency_list).'"'; ?>);
var interkassa_currencies = new Array(<?php echo '"'.implode('", "', $interkassa_currency_list).'"'; ?>);
var currency = jQuery("#currency").val();
var supported = "";
if (currency == "USD") supported = supported + '<span class="label label-success">Authorize.Net</span> ';
if (jQuery.inArray(currency, bitpay_currencies) >= 0) supported = supported + '<span class="label label-success">BitPay</span> ';
if (jQuery.inArray(currency, egopay_currencies) >= 0) supported = supported + '<span class="label label-success">EgoPay</span> ';
if (jQuery.inArray(currency, interkassa_currencies) >= 0) supported = supported + '<span class="label label-success">InterKassa</span> ';
if (jQuery.inArray(currency, perfect_currencies) >= 0) supported = supported + '<span class="label label-success">Perfect Money</span> ';
if (jQuery.inArray(currency, paypal_currencies) >= 0) supported = supported + '<span class="label label-success">PayPal</span> ';
if (jQuery.inArray(currency, payza_currencies) >= 0) supported = supported + '<span class="label label-success">Payza</span> ';
if (jQuery.inArray(currency, skrill_currencies) >= 0) supported = supported + '<span class="label label-success">Skrill</span> ';
if (jQuery.inArray(currency, stripe_currencies) >= 0) supported = supported + '<span class="label label-success">Stripe</span> ';
jQuery("#supported").html("Supported: " + supported.substring(0, supported.length));
}
supportedmethods();
</script>
<?php
} else if ($page == 'types') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
if (isset($_GET["s"])) $search_query = trim(stripslashes($_GET["s"]));
else $search_query = "";
$tmp = $icdb->get_row("SELECT COUNT(*) AS total FROM ".$icdb->prefix."types WHERE deleted = '0'".((strlen($search_query) > 0) ? " AND title LIKE '%".addslashes($search_query)."%'" : ""));
$total = $tmp["total"];
$totalpages = ceil($total/RECORDS_PER_PAGE);
if ($totalpages == 0) $totalpages = 1;
if (isset($_GET["p"])) $page = intval($_GET["p"]);
else $page = 1;
if ($page < 1 || $page > $totalpages) $page = 1;
$switcher = page_switcher("admin.php?page=types".((strlen($search_query) > 0) ? "&s=".rawurlencode($search_query) : ""), $page, $totalpages);
$sql = "SELECT t1.*, t2.total_banners, t2.total_amount FROM ".$icdb->prefix."types t1 LEFT JOIN (SELECT type_id, SUM(amount) AS total_amount, COUNT(*) AS total_banners FROM ".$icdb->prefix."banners WHERE status != '".STATUS_DRAFT."' && deleted = '0' GROUP BY type_id) t2 ON t2.type_id = t1.id WHERE t1.deleted = '0'".((strlen($search_query) > 0) ? " AND t1.title LIKE '%".addslashes($search_query)."%'" : "")." ORDER BY registered DESC LIMIT ".(($page-1)*RECORDS_PER_PAGE).", ".RECORDS_PER_PAGE;
$rows = $icdb->get_rows($sql);
?>
<h3>Banner Types</h3>
<form action="admin.php" method="get" style="margin-bottom: 10px;">
<input type="hidden" name="page" value="types" />
<input type="text" name="s" value="<?php echo htmlspecialchars($search_query, ENT_QUOTES); ?>">
<input type="submit" class="btn" value="Search" />
<?php echo (strlen($search_query) > 0 ? '<input type="button" class="btn" value="Reset search results" onclick="window.location.href=\'admin.php?page=types\';" />' : ''); ?>
</form>
<div class="row">
<div class="span12">
<div class="btn-group pull-right">
<a class="btn btn-primary" href="admin.php?page=edittype">Add New Banner Type</a>
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="admin.php?page=edittype">Add New Banner Type</a></li>
<?php echo (!$rows ? '<li class="disabled"><a>Delete All Banner Types</a></li>' : '<li><a href="admin.php?action=delete-all-types" onclick="return submitOperation();">Delete All Banner Types</a></li>'); ?>
</ul>
</div>
</div>
</div>
<table class="table table-striped">
<tr>
<th>Title</th>
<th>Shortcode</th>
<th style="width: 100px; text-align: right;">Size</th>
<th style="width: 100px; text-align: right;"></th>
<th style="width: 60px; text-align: right;">Slots</th>
<th style="width: 80px;"></th>
</tr>
<?php
if (sizeof($rows) > 0) {
foreach ($rows as $row) {
print ('
<tr'.($row['status'] == STATUS_PENDING ? ' class="error"' : '').'>
<td>'.htmlspecialchars($row['title'], ENT_QUOTES).(!empty($row['preview_url']) ? '<br /><small>Preview: <a href="'.$row['preview_url'].'" target="_blank">'.htmlspecialchars(cut_string($row['preview_url'], 30), ENT_QUOTES).'</a></small>' : '').'</td>
<td><code>'.htmlspecialchars('<a class="ubm-banner" data-id="'.$row['id'].'"></a>', ENT_QUOTES).'</code></td>
<td style="text-align: right;">'.$row['width'].' x '.$row['height'].'</td>
<td style="text-align: right;"></td>
<td style="text-align: right;">'.$row['slots'].'</td>
<td style="text-align: center;">
<a href="admin.php?page=edittype&id='.$row['id'].'" title="Edit type details"><img src="img/edit.png" alt="Edit type details" border="0"></a>
<a href="admin.php?page=banners&cid='.$row['id'].'" title="Banners"><img src="img/banners.png" alt="Banners" border="0"></a>
'.($row["status"] == STATUS_ACTIVE ? '<a href="admin.php?action=block-type&id='.$row['id'].'" title="Block type"><img src="img/block.png" alt="Block type" border="0"></a>' : '').'
'.($row["status"] == STATUS_PENDING ? '<a href="admin.php?action=unblock-type&id='.$row['id'].'" title="Unblock type"><img src="img/unblock.png" alt="Unblock type" border="0"></a>' : '').'
<a href="admin.php?action=delete-type&id='.$row['id'].'" title="Delete record" onclick="return submitOperation();"><img src="img/delete.png" alt="Delete record" border="0"></a>
</td>
</tr>');
}
} else {
print ('
<tr><td colspan="6" style="padding: 20px; text-align: center;">'.((strlen($search_query) > 0) ? 'No results found for "<strong>'.htmlspecialchars($search_query, ENT_QUOTES).'</strong>"' : 'List is empty.').'</td></tr>');
}
?>
</table>
<div class="row">
<div class="span6">
<div class="pull-left">
<?php echo $switcher; ?>
&nbsp;
</div>
</div>
<div class="span6">
<div class="btn-group pull-right">
<a class="btn btn-primary" href="admin.php?page=edittype">Add New Banner Type</a>
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="admin.php?page=edittype">Add New Banner Type</a></li>
<?php echo (!$rows ? '<li class="disabled"><a>Delete All Banner Types</a></li>' : '<li><a href="admin.php?action=delete-all-types" onclick="return submitOperation();">Delete All Banner Types</a></li>'); ?>
</ul>
</div>
</div>
</div>
<hr>
<script type="text/javascript">
function submitOperation() {
var answer = confirm("Do you really want to continue?");
if (answer) return true;
else return false;
}
</script>
<?php
} else if ($page == 'edittype') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
unset($id);
if (isset($_GET["id"]) && !empty($_GET["id"])) {
$id = intval($_GET["id"]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$id."' AND deleted = '0'");
if (!$type_details) unset($id);
}
$values = array();
foreach (array('title', 'slots', 'width', 'height') as $value) {
if (isset($_SESSION[$value])) {
$values[$value] = $_SESSION[$value];
unset($_SESSION[$value]);
} else if (!empty($id)) $values[$value] = $type_details[$value];
else $values[$value] = '';
}
?>
<form enctype="multipart/form-data" method="post" action="admin.php?action=update-type">
<h3><?php echo (empty($id) ? 'Add new type' : 'Edit type details'); ?></h3>
<div class="row">
<div class="span3"><strong>Title:</strong></div>
<div class="span9">
<input type="text" class="span9" id="title" name="title" value="<?php echo htmlspecialchars($values['title'], ENT_QUOTES); ?>">
<br /><small>Please enter banner type title.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Banner size:</strong></div>
<div class="span9">
<select class="span2" name="type" id="type" onchange="changesize();">');
<?php
$selected = false;
foreach($types as $type) {
if ($values["width"] > 0 && $values["height"] > 0 && $values["width"] == $type["width"] && $values["height"] == $type["height"]) {
$selected = true;
print ('
<option value="'.$type["id"].'" selected="selected">'.$type["width"]." x ".$type["height"].'</option>');
} else if ($type["id"] > 0) {
print ('
<option value="'.$type["id"].'">'.$type["width"]." x ".$type["height"].'</option>');
} else if ($values["width"] > 0 && $values["height"] > 0 && !$selected) {
print ('
<option value="0" selected="selected">Custom</option>');
} else {
print ('
<option value="0">Custom</option>');
}
}
?>
</select>
<input type="text" class="input-mini" id="width" name="width" value="<?php echo (!empty($values['width']) ? htmlspecialchars($values['width'], ENT_QUOTES) : $types[0]["width"]); ?>" style="text-align: right;"> x
<input type="text" class="input-mini" id="height" name="height" value="<?php echo (!empty($values['height']) ? htmlspecialchars($values['height'], ENT_QUOTES) : $types[0]["height"]); ?>" style="text-align: right;">
<br /><small>Select banner size. You can choose standard banner sizes or specify your custom size.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Slots:</strong></div>
<div class="span9">
<input type="text" class="input-small" id="slots" name="slots" value="<?php echo (!empty($values['slots']) ? intval($values['slots']) : '1'); ?>" style="text-align: right;">
<br /><small>Enter number of available slots for this banner type.</small>
</div>
</div>
<div class="row">
<div class="span12">
<input type="hidden" name="action" value="update-type" />
<?php echo (empty($id) ? '' : '<input type="hidden" name="id" value="'.$id.'" />'); ?>
<input type="submit" class="btn btn-primary pull-right" name="submit" value="Update Details">
</div>
</div>
<hr>
</form>
<script type="text/javascript">
function changesize() {
var type = jQuery("#type").val();
<?php
foreach($types as $type) {
if ($type["id"] == 0) {
print ('
if (type == "0") {
jQuery("#width").removeAttr("disabled");
jQuery("#height").removeAttr("disabled");
}');
} else {
print ('
if (type == "'.$type["id"].'") {
jQuery("#width").attr("disabled", "disabled");
jQuery("#height").attr("disabled", "disabled");
jQuery("#width").val("'.$type["width"].'");
jQuery("#height").val("'.$type["height"].'");
}');
}
}
?>
}
function changeplaceholder() {
if (jQuery("#placeholder_type").val() == "0") {
jQuery(".placeholder-content").hide();
} else {
jQuery(".placeholder-content").show();
}
}
changeplaceholder();
changesize();
</script>
<?php
} else if ($page == 'banners') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else if (DEMO_MODE) $message = '<div class="alert alert-warning"><strong>Demo mode.</strong> Real e-mails are hidden.</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
if (isset($_GET["s"])) $search_query = trim(stripslashes($_GET["s"]));
else $search_query = "";
if (isset($_GET["cid"])) {
$type_id = intval($_GET["cid"]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE deleted = '0' AND id = '".$type_id."'");
if (!$type_details) $type_id = 0;
}
else $type_id = 0;
$tmp = $icdb->get_row("SELECT COUNT(*) AS total FROM ".$icdb->prefix."types WHERE deleted = '0'");
$total_types = $tmp["total"];
$tmp = $icdb->get_row("SELECT COUNT(*) AS total FROM ".$icdb->prefix."banners WHERE deleted = '0' AND status != '".STATUS_DRAFT."'".($type_id > 0 ? " AND type_id = '".$type_id."'" : "").((strlen($search_query) > 0) ? " AND (title LIKE '%".addslashes($search_query)."%' OR email LIKE '%".addslashes($search_query)."%')" : ""));
$total = $tmp["total"];
$totalpages = ceil($total/RECORDS_PER_PAGE);
if ($totalpages == 0) $totalpages = 1;
if (isset($_GET["p"])) $page = intval($_GET["p"]);
else $page = 1;
if ($page < 1 || $page > $totalpages) $page = 1;
$switcher = page_switcher("admin.php?page=banners".($type_id > 0 ? "&cid=".$type_id : "").((strlen($search_query) > 0) ? "&s=".rawurlencode($search_query) : ""), $page, $totalpages);
$sql = "SELECT t1.*, t2.title AS type_title, t2.deleted AS type_deleted, t2.width, t2.height, t2.preview_url FROM ".$icdb->prefix."banners t1 LEFT JOIN ".$icdb->prefix."types t2 ON t1.type_id = t2.id WHERE t1.deleted = '0' AND t1.status != '".STATUS_DRAFT."'".($type_id > 0 ? " AND t1.type_id = '".$type_id."'" : "").((strlen($search_query) > 0) ? " AND (t1.title LIKE '%".addslashes($search_query)."%' OR t1.email LIKE '%".addslashes($search_query)."%')" : "")." ORDER BY t1.registered DESC LIMIT ".(($page-1)*RECORDS_PER_PAGE).", ".RECORDS_PER_PAGE;
$rows = $icdb->get_rows($sql);
?>
<h3>Banners<?php echo ($type_id > 0 ? ' <span class="label label-info">'.htmlspecialchars($type_details['title'], ENT_QUOTES).'</span>' : ''); ?></h3>
<form action="admin.php" method="get" style="margin-bottom: 10px;">
<input type="hidden" name="page" value="banners" />
<input type="text" name="s" value="<?php echo htmlspecialchars($search_query, ENT_QUOTES); ?>">
<?php echo ($type_id > 0 ? '<input type="hidden" name="cid" value="'.$type_id.'" />' : ''); ?>
<input type="submit" class="btn" value="Search" />
<?php echo (strlen($search_query) > 0 ? '<input type="button" class="btn" value="Reset search results" onclick="window.location.href=\'admin.php?page=banners'.($type_id > 0 ? "&cid=".$type_id : "").'\';" />' : ''); ?>
</form>
<div class="row">
<div class="span12">
<div class="btn-group pull-right">
<?php echo ($total_types == 0 ? '<a class="btn btn-primary disabled" href="#" onclick="return false;">Add New Banner</a>' : '<a class="btn btn-primary" href="admin.php?page=edit'.($type_id > 0 ? '&cid='.$type_id : '').'">Add New Banner</a>'); ?>
<button class="btn btn-primary dropdown-toggle<?php echo ($total_types == 0 ? ' disabled' : ''); ?>" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<?php echo ($total_types == 0 ? '<li class="disabled"><a>Add New Banner</a></li>' : '<li><a href="admin.php?page=edit'.($type_id > 0 ? '&cid='.$type_id : '').'">Add New Banner</a></li>'); ?>
<?php echo (!$rows ? '<li class="disabled"><a>Delete All Banners</a></li>' : '<li><a href="admin.php?action=delete-all-banners'.($type_id > 0 ? '&cid='.$type_id : '').'" onclick="return submitOperation();">Delete All Banners</a></li>'); ?>
</ul>
</div>
</div>
</div>
<table class="table table-striped">
<tr>
<th>Banner Type</th>
<th>Title</th>
<th>E-mail</th>
<th style="width: 60px; text-align: right;">Shows</th>
<th style="width: 60px; text-align: right;">Clicks</th>
<th style="width: 80px;"></th>
</tr>
<?php
if (sizeof($rows) > 0) {
foreach ($rows as $row) {
$email = $row['email'];
if (DEMO_MODE) {
if (($pos = strpos($email, "@")) !== false) {
$name = substr($email, 0, strpos($email, "@"));
$email = substr($name, 0, 1).'*****'.substr($email, $pos);
}
}
if ($row["status"] < STATUS_PENDING && $row["status"] > STATUS_DRAFT) {
if (time() <= $row["registered"] + 24*3600*$row["days_purchased"]) $expired = 'Expires in '.period_to_string($row["registered"] + 24*3600*$row["days_purchased"] - time());
else $expired = 'Expired';
} else $expired = "";
print ('
<tr'.($row['status'] == STATUS_PENDING ? ' class="error"' : '').'>
<td>'.htmlspecialchars($row['type_title'], ENT_QUOTES).' ('.$row['width'].'x'.$row['height'].')'.($row['type_deleted'] ? ' <span class="label label-important">DEL</span>' : '').'</td>
<td>
'.(!empty($row['url']) ? '<a href="'.$row['url'].'" target="_blank">' : '').(empty($row['title']) ? '-' : htmlspecialchars($row['title'], ENT_QUOTES)).(!empty($row['url']) ? '</a>' : '').'
<br /><small>'.$expired.(!empty($row['preview_url']) ? (!empty($expired) ? ', ' : '').'<a href="'.add_url_parameters($row["preview_url"], array("ubm_show" => $row["id_str"])).'" target="_blank">live preview</a>' : '').'</small>
</td>
<td>'.htmlspecialchars($email, ENT_QUOTES).'</td>
<td style="text-align: right;">'.intval($row["shows_displayed"]).'</td>
<td style="text-align: right;">'.intval($row["clicks"]).'</td>
<td style="text-align: center;">
<a href="admin.php?page=edit&id='.$row['id'].($type_id > 0 ? '&cid='.$type_id : '').'" title="Edit banner details"><img src="img/edit.png" alt="Edit banner details" border="0"></a>
'.($row["status"] == STATUS_ACTIVE ? '<a href="admin.php?action=block-banner&id='.$row['id'].($type_id > 0 ? '&cid='.$type_id : '').'" title="Block banner"><img src="img/block.png" alt="Block banner" border="0"></a>' : '').'
'.($row["status"] == STATUS_PENDING ? '<a href="admin.php?action=unblock-banner&id='.$row['id'].($type_id > 0 ? '&cid='.$type_id : '').'" title="Unblock banner"><img src="img/unblock.png" alt="Unblock banner" border="0"></a>' : '').'
<a href="admin.php?action=delete-banner&id='.$row['id'].($type_id > 0 ? '&cid='.$type_id : '').'" title="Delete record" onclick="return submitOperation();"><img src="img/delete.png" alt="Delete record" border="0"></a>
</td>
</tr>');
}
} else {
print ('
<tr><td colspan="6" style="padding: 20px; text-align: center;">'.((strlen($search_query) > 0) ? 'No results found for "<strong>'.htmlspecialchars($search_query, ENT_QUOTES).'</strong>"' : 'List is empty.').'</td></tr>');
}
?>
</table>
<div class="row">
<div class="span6">
<div class="pull-left">
<?php echo $switcher; ?>
&nbsp;
</div>
</div>
<div class="span6">
<div class="btn-group pull-right">
<?php echo ($total_types == 0 ? '<a class="btn btn-primary disabled" href="#" onclick="return false;">Add New Banner</a>' : '<a class="btn btn-primary" href="admin.php?page=edit'.($type_id > 0 ? '&cid='.$type_id : '').'">Add New Banner</a>'); ?>
<button class="btn btn-primary dropdown-toggle<?php echo ($total_types == 0 ? ' disabled' : ''); ?>" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<?php echo ($total_types == 0 ? '<li class="disabled"><a>Add New Banner</a></li>' : '<li><a href="admin.php?page=edit'.($type_id > 0 ? '&cid='.$type_id : '').'">Add New Banner</a></li>'); ?>
<?php echo (!$rows ? '<li class="disabled"><a>Delete All Banners</a></li>' : '<li><a href="admin.php?action=delete-all-banners'.($type_id > 0 ? '&cid='.$type_id : '').'" onclick="return submitOperation();">Delete All Banners</a></li>'); ?>
</ul>
</div>
</div>
</div>
<hr>
<script type="text/javascript">
function submitOperation() {
var answer = confirm("Do you really want to continue?");
if (answer) return true;
else return false;
}
</script>
<?php
} else if ($page == 'edit') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else if (DEMO_MODE) $message = '<div class="alert alert-warning"><strong>Demo mode.</strong> Real e-mail is hidden.</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
$types = $icdb->get_rows("SELECT * FROM ".$icdb->prefix."types WHERE deleted = '0'");
if (isset($_GET["cid"])) $type_id = intval($_GET["cid"]);
else $type_id = 0;
unset($id);
if (isset($_GET["id"]) && !empty($_GET["id"])) {
$id = intval($_GET["id"]);
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$id."' AND deleted = '0'");
if (!$banner_details) unset($id);
}
$values = array();
foreach (array('title', 'email', 'url', 'days_purchased', 'type_id', 'file', 'source', 'content') as $value) {
if (isset($_SESSION[$value])) {
$values[$value] = $_SESSION[$value];
unset($_SESSION[$value]);
} else if (!empty($id)) $values[$value] = $banner_details[$value];
else $values[$value] = '';
}
if ($values['type_id'] == '') $values['type_id'] = $type_id;
if (DEMO_MODE) {
if (($pos = strpos($values['email'], "@")) !== false) {
$nickname = substr($values['email'], 0, strpos($values['email'], "@"));
$values['email'] = substr($nickname, 0, 1).'*****'.substr($values['email'], $pos);
}
}
?>
<form enctype="multipart/form-data" method="post" action="admin.php?action=update-banner">
<h3><?php echo (empty($id) ? 'Add new banner' : 'Edit banner details'); ?></h3>
<div class="row">
<div class="span3"><strong>Banner type:</strong></div>
<div class="span9">
<select id="type_id" name="type_id" class="span5">
<?php
if (sizeof($types) > 0) {
foreach ($types as $type) {
echo '
<option value="'.$type['id'].'"'.($type['id'] == $values['type_id'] ? ' selected="selected"' : '').'>'.htmlspecialchars($type['title'], ENT_QUOTES).' ('.$type["width"].'x'.$type["height"].')</option>';
}
} else {
echo '
<option value="0">No types found</option>';
}
?>
</select>
<br /><?php echo (sizeof($types) > 0 ? '<small>Select banner type.</small>' : '<span class="label label-important">Please create at least one banner type.</span>'); ?>
</div>
</div>
<div class="row">
<div class="span3"><strong>Title:</strong></div>
<div class="span9">
<input type="text" class="span9" id="title" name="title" value="<?php echo htmlspecialchars($values['title'], ENT_QUOTES); ?>">
<br /><small>Please enter banner title.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Banner source:</strong></div>
<div class="span9">
<select id="source" name="source" class="span5" onchange="changesource();">
<?php
if (sizeof($banner_sources) > 0) {
foreach ($banner_sources as $key => $value) {
echo '
<option value="'.$key.'"'.($key == $values['source'] ? ' selected="selected"' : '').'>'.htmlspecialchars($value, ENT_QUOTES).'</option>';
}
}
?>
</select>
<br /><small>Please select the source of the banner.</small>
</div>
</div>
<div class="row source-image">
<div class="span3"><strong>URL:</strong></div>
<div class="span9">
<input type="text" class="span9" id="url" name="url" value="<?php echo htmlspecialchars($values['url'], ENT_QUOTES); ?>">
<br /><small>Please enter banner URL. The banner will be hyperlinked with this URL.</small>
</div>
</div>
<div class="row source-image">
<div class="span3"><strong>Banner image:</strong></div>
<div class="span9">
<?php echo (!empty($values["file"]) && file_exists(ABSPATH.'/files/'.$values["file"]) ? '<img src="'.$url_base.'files/'.rawurlencode($values["file"]).'"><input type="hidden" name="filename" value="'.rawurlencode($values["file"]).'"><br />' : ''); ?>
<input type="file" name="file" id="file" class="span9">
<br /><small>Please select banner image. You can use JPEG, GIF and PNG images. The size of image must be exactly the same as specified in banner type.</small>
</div>
</div>
<div class="row source-content">
<div class="span3"><strong>HTML Content:</strong></div>
<div class="span9">
<textarea class="span9" id="content" name="content" style="height: 100px;"><?php echo htmlspecialchars($values['content'], ENT_QUOTES); ?></textarea>
<br /><small>Please enter HTML content. The HTML content is used as is. It is your responsibility to match to website design. <strong>To make the banner responsive add class="img img-responsive" to the img tag.</strong></small>
</div>
</div>
<div class="row">
<div class="span3"><strong>Rotation period:</strong></div>
<div class="span9">
<input type="text" class="input-small" id="days_purchased" name="days_purchased" value="<?php echo ($values['days_purchased'] == 0 ? intval($options['minimum_days']) : intval($values['days_purchased'])); ?>" style="text-align: right;"> days
<br /><small>Please enter period of rotation. How many days banner will be in rotation.</small>
</div>
</div>
<div class="row">
<div class="span3"><strong>E-Mail:</strong></div>
<div class="span9">
<input type="text" class="span9" id="email" name="email" value="<?php echo htmlspecialchars($values['email'], ENT_QUOTES); ?>">
<br /><small>Enter user's e-mail. It is used to send statistics to user.</small>
</div>
</div>
<div class="row">
<div class="span12">
<input type="hidden" name="action" value="update-banner" />
<?php echo (empty($id) ? '' : '<input type="hidden" name="id" value="'.$id.'" />'); ?>
<?php echo ($type_id == 0 ? '' : '<input type="hidden" name="cid" value="'.$type_id.'" />'); ?>
<input type="submit" class="btn btn-primary pull-right" name="submit" value="Update Details">
</div>
</div>
<hr>
</form>
<script type="text/javascript">
function changesource() {
if (jQuery("#source").val() == "0") {
jQuery(".source-image").show();
jQuery(".source-content").hide();
} else {
jQuery(".source-image").hide();
jQuery(".source-content").show();
}
}
changesource();
</script>
<?php
} else if ($page == 'transactions') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else if (DEMO_MODE) $message = '<div class="alert alert-warning"><strong>Demo mode.</strong> Real e-mails and transaction details are hidden.</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
if (isset($_GET["s"])) $search_query = trim(stripslashes($_GET["s"]));
else $search_query = "";
if (isset($_GET["did"])) $banner_id = intval(trim(stripslashes($_GET["did"])));
else $banner_id = 0;
$tmp = $icdb->get_row("SELECT COUNT(*) AS total FROM ".$icdb->prefix."transactions WHERE deleted = '0'".($banner_id > 0 ? " AND banner_id = '".$banner_id."'" : "").((strlen($search_query) > 0) ? " AND (payer_name LIKE '%".addslashes($search_query)."%' OR payer_email LIKE '%".addslashes($search_query)."%')" : ""));
$total = $tmp["total"];
$totalpages = ceil($total/RECORDS_PER_PAGE);
if ($totalpages == 0) $totalpages = 1;
if (isset($_GET["p"])) $page = intval($_GET["p"]);
else $page = 1;
if ($page < 1 || $page > $totalpages) $page = 1;
$switcher = page_switcher("admin.php?page=transactions".($banner_id > 0 ? "&did = '".$banner_id."'" : "").((strlen($search_query) > 0) ? "&s=".rawurlencode($search_query) : ""), $page, $totalpages);
$rows = $icdb->get_rows("SELECT t1.*, t2.title AS banner_title, t2.url AS banner_url FROM ".$icdb->prefix."transactions t1 LEFT JOIN ".$icdb->prefix."banners t2 ON t1.banner_id = t2.id WHERE t1.deleted = '0'".($banner_id > 0 ? " AND t1.banner_id = '".$banner_id."'" : "").((strlen($search_query) > 0) ? " AND (t1.payer_name LIKE '%".addslashes($search_query)."%' OR t1.payer_email LIKE '%".addslashes($search_query)."%')" : "")." ORDER BY t1.created DESC LIMIT ".(($page-1)*RECORDS_PER_PAGE).", ".RECORDS_PER_PAGE);
?>
<h3>Transactions</h3>
<form action="admin.php" method="get" style="margin-bottom: 10px;">
<input type="hidden" name="page" value="transactions" />
<input type="text" name="s" value="<?php echo htmlspecialchars($search_query, ENT_QUOTES); ?>">
<?php echo ($banner_id > 0 ? '<input type="hidden" name="did" value="'.$banner_id.'" />' : ''); ?>
<input type="submit" class="btn" value="Search" />
<?php echo (strlen($search_query) > 0 ? '<input type="button" class="btn" value="Reset search results" onclick="window.location.href=\'admin.php?page=transactions'.($banner_id > 0 ? "&did = '".$banner_id."'" : "").'\';" />' : ''); ?>
</form>
<table class="table table-striped">
<tr>
<th>Banner</th>
<th>Payer</th>
<th style="width: 100px; text-align: right;">Amount</th>
<th style="width: 160px;">Status</th>
<th style="width: 120px;">Created</th>
<th style="width: 20px;"></th>
</tr>
<?php
$modals = '';
if (sizeof($rows) > 0) {
foreach ($rows as $row) {
$email = $row['payer_email'];
$name = $row['payer_name'];
if (DEMO_MODE) {
if (($pos = strpos($email, "@")) !== false) {
$nickname = substr($email, 0, strpos($email, "@"));
$email = substr($nickname, 0, 1).'*****'.substr($email, $pos);
}
if (($pos = strpos($name, "@")) !== false) {
$nickname = substr($name, 0, strpos($name, "@"));
$name = substr($nickname, 0, 1).'*****'.substr($name, $pos);
}
}
$modals .= '
<div style="display: none;" class="modal" id="details_'.$row['id'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Transaction Details</h3>
</div>
<div class="modal-body">
<table class="table table-striped">';
$details = explode("&", $row["details"]);
foreach ($details as $param) {
$param = trim($param);
if (!empty($param)) {
$data = explode("=", $param, 2);
$modals .= '
<tr>
<td style="width: 170px; font-weight: bold;">'.htmlspecialchars($data[0], ENT_QUOTES).'</td>
<td>'.(DEMO_MODE ? '*****' : htmlspecialchars(urldecode($data[1]), ENT_QUOTES)).'</td>
</tr>';
}
}
$modals .= '
</table>
</div>
</div>';
echo '
<tr>
<td>'.(!empty($row['banner_url']) ? '<a href="'.$row['banner_url'].'" target="_blank">' : '').(empty($row['banner_title']) ? '-' : htmlspecialchars($row['banner_title'], ENT_QUOTES)).(!empty($row['banner_url']) ? '</a>' : '').'</td>
<td>'.htmlspecialchars($name, ENT_QUOTES).'<br /><em>'.htmlspecialchars($email, ENT_QUOTES).'</em></td>
<td style="text-align: right;">'.number_format($row['gross'], 2, ".", "").' '.$row['currency'].'</td>
<td><a href="#details_'.$row['id'].'" data-toggle="modal">'.$row["payment_status"].'</a><br /><em>'.$row["transaction_type"].'</em></td>
<td>'.date("Y-m-d H:i", $row['created']).'</td>
<td style="text-align: center;">
<a href="admin.php?action=delete-transaction&id='.$row['id'].'" title="Delete record" onclick="return submitOperation();"><img src="img/delete.png" alt="Delete record" border="0"></a>
</td>
</tr>';
}
} else {
print ('
<tr><td colspan="6" style="padding: 20px; text-align: center;">'.((strlen($search_query) > 0) ? 'No results found for "<strong>'.htmlspecialchars($search_query, ENT_QUOTES).'</strong>"' : 'List is empty.').'</td></tr>');
}
?>
</table>
<div class="row">
<div class="span6">
<div class="pull-left">
<?php echo $switcher; ?>
&nbsp;
</div>
</div>
</div>
<?php echo $modals; ?>
<hr>
<script type="text/javascript">
function submitOperation() {
var answer = confirm("Do you really want to continue?");
if (answer) return true;
else return false;
}
</script>
<?php
} else if ($page == 'embed') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
echo $message;
$url_base = '//'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$filename = basename(__FILE__);
if (($pos = strpos($url_base, $filename)) !== false) $url_base = substr($url_base, 0, $pos);
?>
<h3>Embed Ads Manager into your website</h3>
<ol class="embed-list">
<li>
Make sure that your website loads jQuery. If it doesn't, just add this line into <code>head</code> section:
<br /><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;</code>
</li>
<li>
Add these lines into <code>head</code> section (before <code>&lt;/head&gt;</code> tag):
<br /><code>&lt;link href="<?php echo $url_base; ?>css/ubm.css" rel="stylesheet"&gt;</code>
<br /><code>&lt;script src="<?php echo $url_base; ?>js/ubm-jsonp.js"&gt;&lt;/script&gt;</code>
</li>
<li>
Add banner shortcode (from <code>Banner Types</code> page) in the place where you want to see appropriate banner. Example:
<br /><code>&lt;a class="ubm-banner" data-id="X"&gt;&lt;/a&gt;</code>
</li>
That's it! Enjoy!
</li>
</ol>
<hr>
<?php
} else if ($page == 'login') {
if (empty($error_message)) {
if (!empty($ok_message)) $message = '<div class="alert alert-success">'.$ok_message.'</div>';
else $message = '';
} else $message = '<div class="alert alert-error">'.$error_message.'</div>';
//$message = '<div class="alert alert-warning" style="text-align: center; margin-top: 50px;"><strong>Admin Panel is under maintenance. Will be online soon.</strong></div>';
echo $message;
?>
<div class="loginbox">
<h4 style="text-align: center;">Admin Panel</h4>
<div style="margin-top: 10px; margin-left: 20px;">
<form class="form-inline" method="post" action="admin.php?action=login">
<input type="text" class="input-medium" name="login" placeholder="Login" title="Login">
<input type="password" class="input-medium" name="password" placeholder="Password" title="Password">
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
</div>
</div>
<?php
}
?>
</div>
<!-- Footer - begin -->
<div class="navbar navbar-fixed-bottom navbar-inverse">
<div class="navbar-inner">
<div class="container">
<p class="navbar-text pull-left">Ads Manager, BateWorld Build 1.0</p>
<p class="navbar-text pull-right">Copyright &copy; 2015-<?php echo date('Y'); ?> <a href="http://www.madeinpluto.com/" target="_blank">MadeInPluto</a></p>
</div>
</div>
</div>
<!-- Footer - end -->
</body>
</html>