Files
Testing/signedout/banners/ajax.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

793 lines
46 KiB
PHP

<?php
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();
get_options();
handle_version();
if (isset($_REQUEST['callback'])) {
header("Content-type: application/json");
$jsonp_enabled = true;
$jsonp_callback = $_REQUEST['callback'];
} else $jsonp_enabled = false;
$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($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'ubm_getbanner':
$html = '';
$sql = "SELECT * FROM ".$icdb->prefix."banners WHERE registered+24*3600*days_purchased < '".time()."' AND status = '".STATUS_ACTIVE."' AND deleted = '0'";
$rows = $icdb->get_rows($sql);
foreach ($rows as $row) {
$sql = "UPDATE ".$icdb->prefix."banners SET status = '".STATUS_EXPIRED."' WHERE id = '".$row["id"]."'";
$icdb->query($sql);
if (!empty($row["email"])) {
$stats = 'Title: '.htmlspecialchars($row["title"], ENT_QUOTES).'
URL: '.$row["url"].'
Rotation period: '.$row["days_purchased"].' '.'days
Shows: '.$row["shows_displayed"].'
Clicks: '.$row["clicks"].'
CTR: '.number_format($row["clicks"]*100/$row["shows_displayed"], 2, ".", "").'%';
$tags = array("{banner_title}", "{statistics}", "{signup_page}");
$vals = array(htmlspecialchars($row["title"], ENT_QUOTES), $stats, $options['signup_page']);
$body = str_replace($tags, $vals, $options['stats_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($row["email"], $options['stats_email_subject'], $body, $mail_headers);
}
}
$banners = array();
$session_id = time().rand(10000,99999);
if (check_options() === true) {
$data = stripslashes(trim($_REQUEST['ubm_banners']));
$pairs = explode(",", $data);
foreach ($pairs as $pair) {
$data = explode(":", $pair);
if (sizeof($data) == 2 && is_numeric($data[0]) && is_numeric($data[1])) {
$type_id = intval($data[1]);
$type_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."types WHERE id = '".$type_id."' AND deleted = '0'");
if (!$type_details) continue;
unset($banner_details);
if (($pos = strpos($_SERVER["HTTP_REFERER"], "ubm_show")) !== false) {
$id_str = substr($_SERVER["HTTP_REFERER"], $pos + strlen("ubm_show="));
if (($pos = strpos($id_str, "&")) !== false) {
$id_str = substr($id_str, 0, $pos);
}
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE type_id = '".$type_id."' AND id_str='".$id_str."' AND deleted = '0' AND id NOT IN (SELECT banner_id FROM ".$icdb->prefix."log WHERE session_id = '".$session_id."' AND type_id = '".$type_id."')");
}
if (empty($banner_details)) $banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE type_id = '".$type_id."' AND registered+24*3600*days_purchased >= '".time()."' AND status = '".STATUS_ACTIVE."' AND deleted = '0' AND id NOT IN (SELECT banner_id FROM ".$icdb->prefix."log WHERE session_id = '".$session_id."' AND type_id = '".$type_id."') ORDER BY RAND()");
if (empty($banner_details)) {
if (intval($type_details['placeholder_type'] == SOURCE1_DEFAULT)) {
if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $options['signup_page']) || strlen($options['signup_page']) == 0) $html = '';
else $html = '<a class="ubm_banner" href="'.$options['signup_page'].'" title="Advertise Here"><span style="width: '.$type_details["width"].'px; height: '.$type_details["height"].'px; line-height: '.$type_details["height"].'px; border: 1px solid #BBB !important;">Advertise Here</span></a>';
} else {
$html = $type_details['placeholder_content'];
}
} else {
$sql = "UPDATE ".$icdb->prefix."banners SET shows_displayed = shows_displayed + 1 WHERE id = '".$banner_details["id"]."'";
$icdb->query($sql);
$sql = "INSERT INTO ".$icdb->prefix."log (banner_id, type_id, session_id, created) VALUES ('".$banner_details["id"]."', '".$type_id."', '".$session_id."', '".time()."')";
$icdb->query($sql);
if (intval($banner_details['source']) == SOURCE2_IMAGE) {
$html = '<a target="_blank" class="ubm_banner" href="'.(!empty($banner_details["url"]) ? $url_base."go.php?id=".$banner_details["id_str"] : '#').'"'.(empty($banner_details["url"]) ? ' onclick="return false;"' : '').' title="'.htmlspecialchars($banner_details["title"], ENT_QUOTES).'"><img class="img img-responsive" src="'.$url_base.'files/'.$banner_details["file"].'" alt="'.htmlspecialchars($banner_details["title"], ENT_QUOTES).'"></a>';
} else {
$html = $banner_details['content'];
}
}
$banners['ubm_'.intval($data[0])] = $html;
}
}
$sql = "DELETE FROM ".$icdb->prefix."log WHERE session_id = '".$session_id."'";
$icdb->query($sql);
}
$html = json_encode($banners);
if ($jsonp_enabled) {
$html_object = new stdClass();
$html_object->html = $html;
echo $jsonp_callback.'('.json_encode($html_object).')';
} else echo $html;
exit;
break;
case 'ubm_getbox':
if (isset($_REQUEST['ubm_url'])) $return_url = trim(stripslashes($_REQUEST['ubm_url']));
else $return_url = '';
$form = '';
if (check_options() === true) {
if (!in_array($options['currency'], $interkassa_currency_list)) $options['enable_interkassa'] = "off";
if (!in_array($options['currency'], $paypal_currency_list)) $options['enable_paypal'] = "off";
if (!in_array($options['currency'], $payza_currency_list)) $options['enable_payza'] = "off";
if (!in_array($options['currency'], $egopay_currency_list)) $options['enable_egopay'] = "off";
if (!in_array($options['currency'], $perfect_currency_list)) $options['enable_perfect'] = "off";
if (!in_array($options['currency'], $skrill_currency_list)) $options['enable_skrill'] = "off";
if (!in_array($options['currency'], $bitpay_currency_list)) $options['enable_bitpay'] = "off";
if (!in_array($options['currency'], $stripe_currency_list)) $options['enable_stripe'] = "off";
if ($options['currency'] != 'USD') $options['enable_authnet'] = "off";
$methods = 0;
if ($options['enable_paypal'] == "on") $methods++;
if ($options['enable_payza'] == "on") $methods++;
if ($options['enable_interkassa'] == "on") $methods++;
if ($options['enable_authnet'] == "on") $methods++;
if ($options['enable_egopay'] == "on") $methods++;
if ($options['enable_perfect'] == "on") $methods++;
if ($options['enable_skrill'] == "on") $methods++;
if ($options['enable_bitpay'] == "on") $methods++;
if ($options['enable_stripe'] == "on") $methods++;
$sql = "SELECT t1.*, t2.total FROM ".$icdb->prefix."types t1 LEFT JOIN (SELECT type_id, COUNT(*) AS total FROM ".$icdb->prefix."banners WHERE registered+24*3600*days_purchased >= '".time()."' AND status = '".STATUS_ACTIVE."' AND deleted = '0' GROUP BY type_id) t2 ON t2.type_id = t1.id WHERE t1.deleted = '0' AND t1.status = '".STATUS_ACTIVE."' AND (t2.total < t1.slots || t2.total IS NULL)";
$rows = $icdb->get_rows($sql);
if ($methods == 0) {
$form = '<div class="ubm_container"><div name="ubm" class="ubm_box"><div class="ubm_confirmation_info" style="text-align: center;"><strong>Ads Manager.</strong> Please check settings!</div></div></div>';
} else if (sizeof($rows) == 0) {
$form = '<div class="ubm_container"><div name="ubm" class="ubm_box"><div class="ubm_confirmation_info" style="text-align: center;">There are no slots available for new banner. Please try again later.</div></div></div>';
} else {
if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $return_url) || strlen($return_url) == 0) $return_url = $_SERVER["HTTP_REFERER"];
$tac = '';
$terms = htmlspecialchars($options['terms'], ENT_QUOTES);
$terms = str_replace("\n", "<br />", $terms);
$terms = str_replace("\r", "", $terms);
if (strlen($terms) > 0) {
$terms_id = "t".random_string(8);
$tac = '
<div id="'.$terms_id.'" style="display: none;">
<div class="ubm_terms">'.$terms.'</div>
</div>
<div style="margin-top: 5px;">By clicking the button below, I agree with the <a href="#" onclick="jQuery(\'#'.$terms_id.'\').slideToggle(300); return false;">Terms & Conditions</a>.</div>';
}
$intro = $options['intro'];
$intro = str_replace("\n", "<br />", $intro);
$intro = str_replace("\r", "", $intro);
$tags = array("{minimum_days}");
$vals = array($options['minimum_days']);
$intro = str_replace($tags, $vals, $intro);
if (strlen($intro) > 0) $intro = '<div style="margin-bottom: 10px;">'.$intro.'</div>';
if ($options['enable_paypal'] == "on") $active_method = 'paypal';
else if ($options['enable_payza'] == "on") $active_method = 'payza';
else if ($options['enable_interkassa'] == "on") $active_method = 'interkassa';
else if ($options['enable_authnet'] == "on") $active_method = 'authnet';
else if ($options['enable_egopay'] == "on") $active_method = 'egopay';
else if ($options['enable_perfect'] == "on") $active_method = 'perfect';
else if ($options['enable_skrill'] == "on") $active_method = 'skrill';
else if ($options['enable_bitpay'] == "on") $active_method = 'bitpay';
else if ($options['enable_stripe'] == "on") $active_method = 'stripe';
$form = '
<div id="contact" class="ubm_container">
<div name="ubm" class="ubm_box" id="ubm">
<div class="ubm_signup_form" id="ubm_signup_form">
'.$intro.'
<form action="'.$url_base.'ajax.php" target="ubm_iframe" enctype="multipart/form-data" onsubmit="ubm_presubmit();" method="post" style="margin: 0px; padding: 0px;">
<div style="overflow: hidden; height: 100%; margin-bottom: 10px;">
<div style="width: 100%; float: left;">
<div style="padding-right: 14px;">
<select class="ubm_input" name="type" id="ubm_type" onchange="ubm_calc();">';
foreach ($rows as $row) {
$form .= '
<option value="'.$row["id"].'">'.htmlspecialchars($row["title"], ENT_QUOTES).' ('.$row["width"].'x'.$row["height"].' | '.number_format($row["price"], 2, ".", "").' '.$options['currency'].' per '.REFERENCE_PERIOD_DAYS.' days)</option>';
}
$form .= '
</select>
</div>
</div>
<em class="ubm_comment">Select available banner type.</em>
</div>
<div style="overflow: hidden; height: 100%; margin-bottom: 10px;">
<div style="width: 50%; float: left;">
<div style="padding-right: 25px;">
<input class="ubm_input" type="text" name="title" placeholder="Banner title (required)" value="Banner title (required)" onfocus="if (this.value == \'Banner title (required)\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'Banner title (required)\';}" title="Please enter banner title." />
</div>
</div>
<div style="width: 50%; float: left;">
<div style="padding-right: 14px;">
<input required="required" class="ubm_input" type="text" name="url" placeholder="Link (optional)" value="Link (optional)" onfocus="if (this.value == \'Link (optional)\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'Link (optional)\';}" title="Please enter banner URL. Your banner will be hyperlinked with this URL." />
</div>
</div>
<em class="ubm_comment">Enter banner title and its URL. The banner will be hyperlinked with this URL.</em>
</div>
<div style="overflow: hidden; height: 100%; margin-bottom: 10px;">
<div style="width: 100%; float: left;">
<div style="padding-right: 14px;">
<input class="ubm_input ubm_file" type="file" name="file" title="Please enter banner URL. Your banner will be hyperlinked with this URL." />
</div>
</div>
<em class="ubm_comment">Upload your banner image. You can use JPEG, GIF and PNG images. Image size must be exactly the same as per banner type.</em>
</div>
<div style="overflow: hidden; height: 100%; margin-bottom: 10px;">
<div style="width: 100%; float: left;">
<div style="padding-right: 14px;">
<input required="required" class="ubm_input" type="text" name="email" placeholder="Enter your e-mail (required)" value="Enter your e-mail (required)" onfocus="if (this.value == \'Enter your e-mail (required)\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'Enter your e-mail (required)\';}" title="Please enter your e-mail." />
</div>
</div>
<em class="ubm_comment">Enter your e-mail. We will send statistics to this e-mail.</em>
</div>
<div style="overflow: hidden; height: 100%;">
<div style="width: 100%; float: left;">
Period:
<input required="required" class="ubm_input ubm_qty" name="period" id="ubm_period" type="text" value="'.$options['minimum_days'].'" title="How many days your banner has to be shown on our website." onkeyup="ubm_calc();" onchange="ubm_calc();" />
days. Total price is
<input class="ubm_input ubm_qty" type="text" id="ubm_total" disabled="disabled" value="'.number_format($rows[0]['price']*$options['minimum_days']/REFERENCE_PERIOD_DAYS, 2, '.', '').'" title="Total price." />
'.$options['currency'].'.
</div>
<em class="ubm_comment">How many days your banner has to be shown on our website.</em>
</div>';
$checked = ' checked="checked"';
if ($methods > 1) {
$form .= '
<div style="overflow: hidden; height: 100%; margin-top: 10px;">';
if ($options['enable_paypal'] == "on") {
$form .= '
<div style="background: transparent url('.$url_base.'img/logo_paypal.png) 25px 1px no-repeat; height: 30px; width: 110px; float: left; margin-right: 30px;">
<input type="radio" value="paypal" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_payza'] == "on") {
$form .= '
<div style="background: transparent url('.$url_base.'img/logo_payza.png) 25px 0px no-repeat; height: 30px; width: 123px; float: left; margin-right: 30px;">
<input type="radio" value="payza" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_skrill'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_skrill.png) 25px -1px no-repeat; height: 30px; width: 97px; float: left; margin-right: 30px;">
<input type="radio" value="skrill" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_interkassa'] == "on") {
$form .= '
<div style="background: transparent url('.$url_base.'img/logo_interkassa.png) 25px 0px no-repeat; height: 30px; width: 120px; float: left; margin-right: 30px;">
<input type="radio" value="interkassa" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_authnet'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_authnet.png) 25px 1px no-repeat; height: 30px; width: 147px; float: left; margin-right: 30px;">
<input type="radio" value="authnet" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_egopay'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_egopay.png) 25px 0px no-repeat; height: 30px; width: 84px; float: left; margin-right: 30px;">
<input type="radio" value="egopay" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_perfect'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_perfect.png) 25px 0px no-repeat; height: 30px; width: 156px; float: left; margin-right: 30px;">
<input type="radio" value="perfect" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_stripe'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_cards.png) 25px 0px no-repeat; height: 30px; width: 170px; float: left; margin-right: 30px;">
<input type="radio" value="stripe" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
if ($options['enable_bitpay'] == "on") {
$form .='
<div style="background: transparent url('.$url_base.'img/logo_bitcoin.png) 25px 0px no-repeat; height: 30px; width: 120px; float: left; margin-right: 30px;">
<input type="radio" value="bitpay" name="method" style="margin: 4px 0px;"'.$checked.'>
</div>';
$checked = '';
}
$form .= '
</div>';
} else {
$form .= '<input type="hidden" name="method" value="'.$active_method.'" />';
}
$form .= $tac.'
<input type="hidden" name="action" value="ubm_submit" />
<input type="hidden" name="id_str" id="ubm_id_str" value="'.random_string(16).'" />
<input type="hidden" name="return" value="'.$return_url.'" />
<input type="hidden" id="ubm_reference_period_days" value="'.REFERENCE_PERIOD_DAYS.'" />
<input type="submit" class="ubm_submit" id="ubm_submit" value="Continue" />
<img id="ubm_loading" class="ubm_loading" src="'.$url_base.'img/loading.gif" alt="">
</form>';
foreach ($rows as $row) {
$form .= '<input type="hidden" id="ubm_type_'.$row['id'].'" value="'.number_format($row["price"], 2, '.', '').'" />';
}
$form .= '
<iframe id="ubm_iframe" name="ubm_iframe" style="border: 0px; height: 0px; width: 0px; margin: 0px; padding: 0px; display: none;" onload="ubm_load();"></iframe>
</div>
<div class="ubm_confirmation_container" id="ubm_confirmation_container"></div>
<div id="ubm_message" class="ubm_message"></div>
</div>
</div>';
}
} else $form = '<div class="ubm_container"><div name="ubm" class="ubm_box"><div class="ubm_confirmation_info" style="text-align: center;"><strong>Ads Manager.</strong> Please check settings!</div></div></div>';
$html = $form;
if ($jsonp_enabled) {
$html_object = new stdClass();
$html_object->html = $html;
echo $jsonp_callback.'('.json_encode($html_object).')';
} else echo $html;
exit;
break;
case 'ubm_submit':
$html = '';
$id_str = trim($_REQUEST['id_str']);
$id_str = preg_replace('/[^a-zA-Z0-9]/', '', $id_str);
if (strlen($id_str) < 16) die();
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id_str = '".$id_str."' AND deleted = '0'");
if ($banner_details && $banner_details['status'] != STATUS_DRAFT) die();
if (!$banner_details) {
$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, registered, blocked, deleted) VALUES ('0', '', '', '', '', '0', '0.00', 'USD', '0', '0', '".$id_str."', '".STATUS_DRAFT."', '', '', '".time()."', '0', '0')");
$id = $icdb->insert_id;
} else $id = $banner_details['id'];
$title = trim(stripslashes($_REQUEST['title']));
$email = trim(stripslashes($_REQUEST['email']));
$url = trim(stripslashes($_REQUEST['url']));
$period = intval($_REQUEST['period']);
$payment_method = trim(stripslashes($_REQUEST['method']));
$return_url = trim(stripslashes($_REQUEST['return']));
$type = intval($_REQUEST['type']);
if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $return_url) || strlen($return_url) == 0) $return_url = $_SERVER["HTTP_REFERER"];
if ($title == 'Banner title (required)') $title = '';
if ($url == 'Link (optional)') $url = '';
$error = '';
if (strlen($title) > 128) $error .= '<li>Banner title is too long.</li>';
else if (strlen($title) < 3) $error .= '<li>Banner title is too short.</li>';
if ($email == '') {
$error .= '<li>Your e-mail address is required.</li>';
} else if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $email)) {
$error .= '<li>You have entered an invalid e-mail address.</li>';
} else if (sizeof($email) > 64) {
$error .= '<li>Your email is too long.</li>';
}
if ($period < $options['minimum_days']) $error .= '<li>Rotation period must be at least '.$options['minimum_days'].' days.</li>';
if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url) && strlen($url) > 0) {
$error .= '<li>Website URL must be valid URL.</li>';
} else if (sizeof($url) > 192) {
$error .= '<li>Your website URL is too long.</li>';
}
$type_details = $icdb->get_row("SELECT t1.*, t2.total FROM ".$icdb->prefix."types t1 LEFT JOIN (SELECT type_id, COUNT(*) AS total FROM ".$icdb->prefix."banners WHERE registered+24*3600*days_purchased >= '".time()."' AND status = '".STATUS_ACTIVE."' AND deleted = '0' GROUP BY type_id) t2 ON t2.type_id = t1.id WHERE t1.id = '".$type."' AND t1.deleted = '0'");
if (!$type_details) $error .= '<li>Invalid banner type.</li>';
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") $error .= '<li>Banner image must be JPEG, GIF or PNG file.</li>';
else {
list($width, $height, $imagetype, $attr) = getimagesize($_FILES["file"]["tmp_name"]);
if ($width != $type_details["width"] || $height != $type_details["height"]) $error .= '<li>Image size must be '.$type_details["width"].'x'.$type_details["height"].'.</li>';
else {
$image = "banner_".md5(microtime().$_FILES["file"]["tmp_name"]).$ext;
if (!move_uploaded_file($_FILES["file"]["tmp_name"], ABSPATH."/files/".$image)) {
$error .= '<li>Can not save uploaded image.</li>';
}
}
}
} else $error .= '<li>Banner image must be uploaded.</li>';
if ($payment_method == 'interkassa') {
if ($options['enable_interkassa'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_interkassa.png) 0px 0px no-repeat; height: 26px; width: 120px; float: left;"></div>';
} else if ($payment_method == 'payza') {
if ($options['enable_payza'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_payza.png) 0px 0px no-repeat; height: 26px; width: 155px; float: left;"></div>';
} else if ($payment_method == 'authnet') {
if ($options['enable_authnet'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method = '
<div style="background: transparent url('.$url_base.'img/logo_authnet.png) 0px 0px no-repeat; height: 30px; width: 147px; float: left;"></div>';
} else if ($payment_method == 'skrill') {
if ($options['enable_skrill'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_skrill.png) 0px 0px no-repeat; height: 30px; width: 97px; float: left;"></div>';
} else if ($payment_method == 'egopay') {
if ($options['enable_egopay'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_egopay.png) 0px 0px no-repeat; height: 30px; width: 84px; float: left;"></div>';
} else if ($payment_method == 'perfect') {
if ($options['enable_perfect'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_perfect.png) 0px 0px no-repeat; height: 30px; width: 156px; float: left;"></div>';
} else if ($payment_method == 'bitpay') {
if ($options['enable_bitpay'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_bitcoin.png) 0px 0px no-repeat; height: 30px; width: 120px; float: left;"></div>';
} else if ($payment_method == 'stripe') {
if ($options['enable_stripe'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_cards.png) 0px 0px no-repeat; height: 30px; width: 170px; float: left;"></div>';
} else {
if ($options['enable_paypal'] != 'on') $error .= '<li>Payment method not supported.</li>';
$method ='
<div style="background: transparent url('.$url_base.'img/logo_paypal.png) 0px 0px no-repeat; height: 26px; width: 110px; float: left;"></div>';
}
if ($error != '') {
$html .= '<div class="ubm_error_message">Attention! Please correct the errors below and try again.';
$html .= '<ul class="ubm_error_messages">'.$error.'</ul>';
$html .= '</div>';
$icdb->query("UPDATE ".$icdb->prefix."banners SET
echo = '".$icdb->escape_string($html)."'
WHERE id = '".$id."'");
} else {
$amount = number_format($period*$type_details["price"]/REFERENCE_PERIOD_DAYS, 2, ".", "");
$html .= '
<div class="ubm_confirmation_info">
<table class="ubm_confirmation_table">
<tr><td style="width: 170px"><strong>Title:</strong></td><td class="ubm_confirmation_data">'.(empty($title) ? '-' : htmlspecialchars($title, ENT_QUOTES)).'</td></tr>
<tr><td><strong>Website:</strong></td><td class="ubm_confirmation_data">'.(empty($url) ? '-' : '<a href="'.$url.'" target="_blank">'.htmlspecialchars($url, ENT_QUOTES).'</a>').'</td></tr>
<tr><td><strong>Banner:</strong></td><td class="ubm_confirmation_data">'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')'.(!empty($type_details['preview_url']) ? '<br /><a href="'.add_url_parameters($type_details["preview_url"], array ("ubm_show" => $id_str)).'" target="_blank">live preview</a>' : '').'</td></tr>
<tr><td><strong>E-Mail:</strong></td><td class="ubm_confirmation_data">'.htmlspecialchars($email, ENT_QUOTES).'</td></tr>
<tr><td><strong>Price:</strong></td><td class="ubm_confirmation_price">'.$amount.' '.$options['currency'].'</td></tr>
<tr><td><strong>Payment method:</strong></td><td class="ubm_confirmation_data">'.$method.'</td></tr>
</table>
<div class="ubm_signup_buttons">';
if ($payment_method == 'bitpay') {
$html .= '
<input type="button" class="ubm_submit" id="ubm_bitpay" value="Confirm and pay" onclick="ubm_bitpay('.$id.', \''.$return_url.'\');">
<input type="button" class="ubm_submit" id="ubm_bitpay_edit" value="Edit info" onclick="ubm_edit();">
<img id="ubm_loading2" class="ubm_loading" src="'.$url_base.'img/loading.gif" alt="">';
} else if ($payment_method == 'stripe') {
$html .= '
<input type="button" class="ubm_submit" id="ubm_stripe" value="Confirm and pay" onclick="ubm_stripe('.$id.', \''.$return_url.'\');">
<input type="button" class="ubm_submit" id="ubm_stripe_edit" value="Edit info" onclick="ubm_edit();">
<img id="ubm_loading2" class="ubm_loading" src="'.$url_base.'img/loading.gif" alt="">';
} else {
$html .= '
<input type="button" class="ubm_submit" id="ubm_signup_pay" value="Confirm and pay" onclick="jQuery(\'#ubm_pay\').click();">
<input type="button" class="ubm_submit" id="ubm_signup_edit" value="Edit info" onclick="ubm_edit();">';
}
$html .= '
</div>';
if ($payment_method == 'interkassa') {
$params = array();
$params['ik_co_id'] = $options['interkassa_checkout_id'];
$params['ik_am'] = number_format($amount, 2, ".", "");
$params['ik_cur'] = $options['currency'];
$params['ik_pm_no'] = $id.'-'.time();
$params['ik_desc'] = htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')';
$params['ik_ia_u'] = $url_base.'ipn.php?method=interkassa';
$params['ik_ia_m'] = 'POST';
$params['ik_suc_u'] = $return_url;
$params['ik_suc_m'] = 'GET';
$params['ik_fal_u'] = $_SERVER["HTTP_REFERER"];
$params['ik_fal_m'] = 'GET';
$params['ik_x_email'] = $email;
$html .= '
<form action="https://sci.interkassa.com/" method="post" target="_top" style="display:none;">';
foreach($params as $key => $value) {
$html .= '
<input type="hidden" name="'.$key.'" id="'.$key.'_'.$button_id.'" value="'.$value.'">';
}
$html .= '
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'payza') {
$html .= '
<form action="'.($options['payza_sandbox'] == 'on' ? 'https://sandbox.payza.com/sandbox/payprocess.aspx' : 'https://secure.payza.com/PayProcess.aspx').'" method="post" target="_top" style="display:none;">
<input type="hidden" name="ap_merchant" value="'.$options['payza_id'].'">
<input type="hidden" name="ap_purchasetype" value="item">
<input type="hidden" name="ap_itemname" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
<input type="hidden" name="ap_amount" value="'.$amount.'">
<input type="hidden" name="ap_currency" value="'.$options['currency'].'">
<input type="hidden" name="apc_1" value="'.$email.'">
<input type="hidden" name="ap_itemcode" value="ID'.$id.'">
<input type="hidden" name="ap_returnurl" value="'.$return_url.'">
<input type="hidden" name="ap_cancelurl" value="'.$_SERVER["HTTP_REFERER"].'">
<input type="hidden" name="ap_alerturl" value="'.$url_base.'ipn.php?method=payza">
<input type="hidden" name="ap_ipnversion" value="2">
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'authnet') {
$fp_timestamp = time();
$fp_sequence = $id.time();
$fingerprint = get_fingerprint($options['authnet_login'], $options['authnet_key'], $amount, $fp_sequence, $fp_timestamp);
$html .= '
<form action="'.(($options['authnet_sandbox'] == "on") ? 'https://test.authorize.net/gateway/transact.dll' : 'https://secure.authorize.net/gateway/transact.dll').'" method="post" target="_top" style="display:none;">';
if ($options['authnet_sandbox'] == "on") {
$html .= '
<input type="hidden" name="x_test_request" value="true">';
} else {
$html .= '
<input type="hidden" name="x_test_request" value="false">';
}
$style = get_auth_style();
$html .= '
<input type="hidden" name="x_version" value="3.1">
<input type="hidden" name="x_show_form" value="payment_form">
<input type="hidden" name="x_relay_response" value="true">
<input type="hidden" name="x_method" value="cc">
<input type="hidden" name="x_fp_hash" value="'.$fingerprint.'">
<input type="hidden" name="x_fp_timestamp" value="'.$fp_timestamp.'">
<input type="hidden" name="x_fp_sequence" value="'.$fp_sequence.'">
<input type="hidden" name="x_receipt_link_url" value="'.$return_url.'">
<input type="hidden" name="x_login" value="'.$options['authnet_login'].'">
<input type="hidden" name="x_email" value="'.$email.'">
<input type="hidden" name="x_relay_url" value="'.$url_base.'ipn.php?method=authnet">
<input type="hidden" name="x_description" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
<input type="hidden" name="x_amount" value="'.$amount.'">
<input type="hidden" name="x_invoice_num" value="ID'.$id.'N'.time().'">
<input type="hidden" name=x_Header_HTML_Payment_Form value="'.htmlspecialchars($style, ENT_QUOTES).'">
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'skrill') {
$html .= '
<form action="https://www.moneybookers.com/app/payment.pl" method="post" target="_top" style="display:none;">
<input type="hidden" name="pay_to_email" value="'.$options['skrill_id'].'">
<input type="hidden" name="return_url" value="'.$return_url.'">
<input type="hidden" name="cancel_url" value="'.$_SERVER["HTTP_REFERER"].'">
<input type="hidden" name="status_url" value="'.$url_base.'ipn.php?method=skrill">
<input type="hidden" name="language" value="EN">
<input type="hidden" name="amount" value="'.$amount.'">
<input type="hidden" name="currency" value="'.$options['currency'].'">
<input type="hidden" name="detail1_description" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
<input type="hidden" name="detail1_text" value="'.$amount.' '.$options['currency'].'">
<input type="hidden" name="merchant_fields" value="banner_id">
<input type="hidden" name="banner_id" value="'.$id.'">
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'egopay') {
$data = array();
$data['amount'] = $amount;
$data['currency'] = $options['currency'];
$data['description'] = htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')';
$data['cf_1'] = $id;
$data['success_url'] = $return_url;
$data['fail_url'] = $_SERVER["HTTP_REFERER"];
$sdata = serialize($data);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $options['egopay_store_pass'], $sdata, MCRYPT_MODE_ECB, $iv);
$hash = base64_encode($crypttext);
$hash = str_replace(array('+','/','='), array('-','_',''), $hash);
$hash = $options['egopay_store_id'].$hash;
$html .= '
<form action="https://www.egopay.com/api/pay" method="post" target="_top" style="display:none;">
<input type="hidden" name="hash" value="'.$hash.'" />
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'perfect') {
$html .= '
<form action="https://perfectmoney.is/api/step1.asp" method="post" target="_top" style="display:none;">
<input type="hidden" name="PAYEE_ACCOUNT" value="'.$options['perfect_account_id'].'">
<input type="hidden" name="PAYEE_NAME" value="'.$options['perfect_payee_name'].'">
<input type="hidden" name="PAYMENT_AMOUNT" value="'.$amount.'">
<input type="hidden" name="PAYMENT_UNITS" value="'.$options['currency'].'">
<input type="hidden" name="SUGGESTED_MEMO" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
<input type="hidden" name="SUGGESTED_MEMO_NOCHANGE" value="1">
<input type="hidden" name="PAYMENT_ID" value="'.$id.'">
<input type="hidden" name="PAYMENT_URL" value="'.$return_url.'">
<input type="hidden" name="PAYMENT_URL_METHOD" value="LINK">
<input type="hidden" name="NOPAYMENT_URL" value="'.$_SERVER["HTTP_REFERER"].'">
<input type="hidden" name="NOPAYMENT_URL_METHOD" value="LINK">
<input type="hidden" name="STATUS_URL" value="'.$url_base.'ipn.php">
<input type="hidden" name="BAGGAGE_FIELDS" value="method">
<input type="hidden" name="method" value="perfect">
<input type="submit" id="ubm_pay" value="Submit">
</form>';
} else if ($payment_method == 'bitpay') {
} else if ($payment_method == 'stripe') {
$html .= '
<div style="display: none;">
<input type="hidden" id="ubm_stripe_publishable" value="'.$options['stripe_publishable'].'">
<input type="hidden" id="ubm_stripe_amount" value="'.intval($amount*100).'">
<input type="hidden" id="ubm_stripe_currency" value="'.$options['currency'].'">
<input type="hidden" id="ubm_stripe_label" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
</div>';
} else {
$html .= '
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" style="display: none;">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="charset" value="utf-8">
<input type="hidden" name="business" value="'.$options['paypal_id'].'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="item_name" value="'.htmlspecialchars($type_details["title"], ENT_QUOTES).' ('.$type_details["width"].'x'.$type_details["height"].')">
<input type="hidden" name="item_number" value="'.$id.'">
<input type="hidden" name="amount" value="'.$amount.'">
<input type="hidden" name="currency_code" value="'.$options['currency'].'">
<input type="hidden" name="custom" value="'.$email.'">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest">
<input type="hidden" name="return" value="'.$return_url.'">
<input type="hidden" name="cancel_return" value="'.$_SERVER["HTTP_REFERER"].'">
<input type="hidden" name="notify_url" value="'.$url_base.'ipn.php?method=paypal">
<input type="submit" id="ubm_pay" value="Submit">
</form>';
}
$html .= '
</div>';
$icdb->query("UPDATE ".$icdb->prefix."banners SET
type_id = '".$type."',
title = '".$icdb->escape_string($title)."',
email = '".$icdb->escape_string($email)."',
url = '".$icdb->escape_string($url)."',
days_purchased = '".number_format(floatval($period), 2, ".", "")."',
amount = '".number_format(floatval($amount), 2, ".", "")."',
currency = '".$options['currency']."',
echo = '".$icdb->escape_string($html)."',
details = '".$icdb->escape_string($return_url)."',
file = '".$icdb->escape_string($image)."'
WHERE id = '".$id."'");
}
exit;
break;
case 'ubm_postsubmit':
$html = '';
$id_str = trim($_REQUEST['ubm_id_str']);
$id_str = preg_replace('/[^a-zA-Z0-9]/', '', $id_str);
if (strlen($id_str) < 16) die();
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id_str = '".$id_str."' AND deleted = '0'");
if ($banner_details && $banner_details['status'] != STATUS_DRAFT) die();
$html = $banner_details['echo'];
if ($jsonp_enabled) {
$html_object = new stdClass();
$html_object->html = $html;
echo $jsonp_callback.'('.json_encode($html_object).')';
} else echo $html;
exit;
break;
case 'ubm_bitpayurl':
$banner_id = intval($_REQUEST['ubm_id']);
$return_url = trim(stripslashes($_REQUEST['ubm_url']));
$banner_details = $icdb->get_row("SELECT * FROM ".$icdb->prefix."banners WHERE id = '".$banner_id."' AND status = '".STATUS_DRAFT."'");
$error = '';
if (!$banner_details) $error .= '<li>Invalid banner details.</li>';
if (empty($error)) {
$bitpay_options['orderID'] = $banner_details['id'].'N'.time();
$bitpay_options['itemDesc'] = $banner_details['title'];
$bitpay_options['itemCode'] = $banner_details['id'];
$bitpay_options['notificationURL'] = $url_base.'ipn.php?method=bitpay';;
$bitpay_options['price'] = number_format($banner_details['amount'], 2, ".", "");
$bitpay_options['currency'] = $banner_details['currency'];
$bitpay_options['physical'] = 'false';
$bitpay_options['transactionSpeed'] = $options['bitpay_speed'];
$bitpay_options['fullNotifications'] = 'false';
$bitpay_options['redirectURL'] = $return_url;
$bitpay_options['posData'] = '{"banner_id" : "'.$banner_details['id'].'", "payer_email" : "'.$banner_details['email'].'"}';
$post = json_encode($bitpay_options);
$curl = curl_init('https://bitpay.com/api/invoice/');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$header = array(
'Content-Type: application/json',
'Content-Length: '.strlen($post),
'Authorization: Basic '.base64_encode($options['bitpay_key']),
);
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); // verify certificate
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // check existence of CN and verify that it matches hostname
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
$json = curl_exec($curl);
curl_close($curl);
if ($json === false) {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>Payment gateway is not available now.</li></ul></div>';
} else {
$post = json_decode($json, true);
if (!$post) {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>Payment gateway is not available now.</li></ul></div>';
} else {
if (isset($post['error'])) {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>'.ucfirst($post['error']['message']).'</li></ul></div>';
} else if ($post['status'] != 'new') {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>Payment gateway is not available now.</li></ul></div>';
} else $html = $post['url'];
}
}
} else {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages">'.$error.'</ul></div>';
}
if ($jsonp_enabled) {
$html_object = new stdClass();
$html_object->html = $html;
echo $jsonp_callback.'('.json_encode($html_object).')';
} else echo $html;
exit;
break;
case 'ubm_stripecharge':
$banner_id = intval($_REQUEST['ubm_id']);
$token = trim(stripslashes($_REQUEST['ubm_token']));
$banner_details = $icdb->get_row("SELECT t1.*, t2.title AS type_title FROM ".$icdb->prefix."banners t1 LEFT JOIN ".$icdb->prefix."types t2 ON t1.type_id = t2.id WHERE t1.id = '".$banner_id."' AND t1.status = '".STATUS_DRAFT."'");
$error = '';
if (!$banner_details) $error .= '<li>Invalid banner details.</li>';
if (empty($error)) {
require_once(dirname(__FILE__).'/lib/Stripe.php');
try {
Stripe::setApiKey($options['stripe_secret']);
$charge = Stripe_Charge::create(array(
"amount" => intval($banner_details['amount']*100),
"currency" => $banner_details['currency'],
"card" => $token,
"description" => $banner_details['email'])
);
$post = json_decode($charge, true);
$response = 'token='.$token;
foreach ($post as $key => $value) {
if (is_array($value)) $response .= "&".$key."=".urlencode(str_replace('&', ' ', serialize($value)));
else $response .= "&".$key."=".urlencode($value);
}
$sql = "INSERT INTO ".$icdb->prefix."transactions (
banner_id, payer_name, payer_email, gross, currency, payment_status, transaction_type, txn_id, details, created) VALUES (
'".$banner_id."',
'".$icdb->escape_string($post['card']['name'])."',
'".$icdb->escape_string($banner_details['email'])."',
'".floatval($banner_details['amount'])."',
'".$banner_details['currency']."',
'Completed',
'Stripe: ".$post['card']['type']."',
'".$token."',
'".$icdb->escape_string($response)."',
'".time()."'
)";
$icdb->query($sql);
$registered = time();
if ($options['enable_approval'] == 'on') $icdb->query("UPDATE ".$icdb->prefix."banners SET status = '".STATUS_PENDING."', registered = '".$registered."', blocked = '".$registered."' WHERE id = '".$banner_id."'");
else $icdb->query("UPDATE ".$icdb->prefix."banners SET status = '".STATUS_ACTIVE."', registered = '".$registered."', blocked = '0' WHERE id = '".$banner_id."'");
$tags = array("{payer_name}", "{payer_email}", "{amount}", "{currency}", "{type_title}", "{banner_title}", "{transaction_date}", "{gateway}");
$vals = array($post['card']['name'], $banner_details['email'], $banner_details['amount'], $banner_details['currency'], $banner_details["type_title"], $banner_details["title"], date("Y-m-d H:i:s")." (server time)", "Stripe");
send_thanksgiving_email($tags, $vals, $banner_details['email']);
$html = '<div class="ubm_confirmation_info" style="text-align: center;">Payment successfully <strong>completed</strong>.</div>';
} catch(Exception $e) {
$body = $e->getJsonBody();
$err = $body['error'];
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>'.$err['message'].'</li></ul></div>';
}
} else {
$html = '<div class="ubm_error_message">Attention! Please correct the errors below and try again.<ul class="ubm_error_messages"><li>'.$error.'</li></ul></div>';
}
if ($jsonp_enabled) {
$html_object = new stdClass();
$html_object->html = $html;
echo $jsonp_callback.'('.json_encode($html_object).')';
} else echo $html;
exit;
break;
default:
break;
}
}
?>