administrator/ 0000755 7742766 0035230 00000000000 11564472367 017464 5 ustar nf.mortgageoriginatorseminars www administrator/backups/ 0000755 7742766 0035230 00000000000 11564474763 021116 5 ustar nf.mortgageoriginatorseminars www administrator/backups/index.html 0000644 7742766 0035230 00000000000 11564474663 023100 0 ustar nf.mortgageoriginatorseminars www amember/ 0000755 7742766 0035230 00000000000 11717042277 016205 5 ustar nf.mortgageoriginatorseminars www amember/aff.php 0000644 7742766 0035230 00000022126 11613276244 017453 0 ustar nf.mortgageoriginatorseminars www get_user($member_id);
$u['is_affiliate'] = 1;
$db->update_user($member_id, $u);
if($config['aff']['mail_signup_user']) check_aff_signup_email_sent($member_id);
return true;
}
function display_links($member_id){
global $config, $t, $db;
///
$links = array();
foreach ((array)$config['aff']['links'] as $k => $l){
$l['url'] = aff_make_url($l['url'], 'l'.$k, $member_id);
$l['code'] = "$l[title]";
$links[ ] = $l;
}
$t->assign('links', $links);
///
$banners = array();
foreach ((array)$config['aff']['banners'] as $k=>$l){
$l['url'] = aff_make_url($l['url'], 'b'.$k, $member_id);
$alt = htmlspecialchars($l[alt]);
$wc = ($w=$l['width']) ? "width=$w" : "";
$hc = ($h=$l['height']) ? "height=$h" : "";
$l['code'] = "";
$banners[] = $l;
}
$t->assign('banners', $banners);
///
$t->display('aff_links.html');
}
function get_ym_options(){
$res = array();
$y = date('Y');
$m = date('m');
for ($i=0;$i<36;$i++){
$res[ $y."_".$m ] = date('F 01-t, Y', strtotime("{$y}-{$m}-01"));
$m--;
if ($m <= 0) { $m = 12; $y--; }
}
return $res;
}
function get_default_ym(){
$y = date('Y');
$m = date('m');
$m -= 0;
if ($m <= 0){
$y--;
$m = 12 - $m;
}
return "{$y}_{$m}";
}
function display_stats($member_id, $vars){
global $db, $t;
$t->assign('year_month_options', get_ym_options());
$t->assign('default_month', get_default_ym());
if ($vars['year_month'] == '')
$vars['year_month'] = get_default_ym();
list($y, $m) = split('_', $vars['year_month']);
$y = sprintf('%04d', $y);
$m = sprintf('%02d', $m);
$dat1 = "{$y}-{$m}-01";
$dat2 = date('Y-m-t', strtotime($dat1));
$dattm1 = date('Ymd000000', strtotime($dat1));
$dattm2 = date('Ymd235959', strtotime($dat2));
$totaldays = date('t', strtotime($dat1));
$days = array();
$total = array();
for ($i=1;$i<=$totaldays;$i++)
$days[$i] = array('dat' => sprintf("$y-$m-%02d", $i));
// get clicks for the month
$q = $db->query("SELECT DAYOFMONTH(ac.time), COUNT(log_id), COUNT(DISTINCT(remote_addr))
FROM {$db->config[prefix]}aff_clicks ac
WHERE aff_id=$member_id AND ac.time BETWEEN $dattm1 AND $dattm2
GROUP BY DAYOFMONTH(ac.time)
");
while (list($d, $r, $u) = mysql_fetch_row($q)){
$days[$d]['raw'] = $r;
$days[$d]['uniq'] = $u;
}
// get total clicks for the month
$q = $db->query("SELECT COUNT(log_id), COUNT(DISTINCT(remote_addr))
FROM {$db->config[prefix]}aff_clicks ac
WHERE aff_id=$member_id AND ac.time BETWEEN $dattm1 AND $dattm2
");
while (list($r, $u) = mysql_fetch_row($q)){
$total['raw'] = $r;
$total['uniq'] = $u;
}
// get comissions for the month
$q = $db->query("SELECT DAYOFMONTH(ac.date), COUNT(commission_id),
SUM(IF(record_type='debit', amount, 0)),
SUM(IF(record_type='credit', amount, 0)),
SUM(IF(record_type='debit', 1, 0))
FROM {$db->config[prefix]}aff_commission ac
WHERE aff_id=$member_id AND ac.date BETWEEN '$dat1' AND '$dat2'
GROUP BY DAYOFMONTH(ac.date)
");
while (list($d, $cnt, $deb, $cre, $deb_count) = mysql_fetch_row($q)){
$days[$d]['trans'] = $cnt;
$days[$d]['debit'] = $deb != 0 ? -$deb." ($deb_count)" : '';
$days[$d]['credit'] = $cre;
if ($deb || $cre)
$days[$d]['total'] = $cre - $deb;
$total['trans'] += $cnt;
$total['debit'] += $deb;
$total['credit'] += $cre;
$total['total'] += $days[$d]['total'];
}
$total['debit'] = $total['debit'] != 0 ? -$total['debit'] : '';
$t->assign('days', $days);
$t->assign('total', $total);
/// top 20 referrers
$q = $db->query("SELECT referrer, COUNT(log_id) as clog_id, COUNT(DISTINCT(remote_addr)) as cremote_addr
FROM {$db->config[prefix]}aff_clicks ac
WHERE aff_id=$member_id AND referrer > '' AND ac.time BETWEEN $dattm1 AND $dattm2
GROUP BY referrer
ORDER BY clog_id DESC, cremote_addr DESC
LIMIT 0,20
");
$refs = array();
while (list($ref, $raw, $uniq) = mysql_fetch_row($q)){
$refs[] = array(
'raw' => $raw,
'uniq' => $uniq,
'ref' => $ref
);
}
$t->assign('refs', $refs);
$t->display("aff_stats.html");
}
function display_payout_info($member_id, $u, $err=array()){
global $t, $config, $db;
$t->assign('u', $u);
$t->assign('error', $err);
$t->assign('aff_payout_types', $m=aff_get_payout_methods(1));
$t->display("aff_payout_info.html");
}
function update_payout_info($member_id, $u){
global $db;
foreach ($u as $k => $v)
$u[$k] = str_replace('"', "'", strip_tags($v));
$err = array();
$user = $db->get_user($member_id);
$user['aff_payout_type'] = $u['aff_payout_type'];
if ($u['aff_payout_type'] == 'paypal'){
if ($u['aff_paypal_email'] == ''){
$err[] = _AFF_ERROR_1;
return $err;
}
$user['data']['aff_paypal_email'] = $u['aff_paypal_email'];
} elseif ($u['aff_payout_type'] == 'check'){
if ($u['aff_check_payable_to'] == ''){
$err[] = _AFF_ERROR_2;
return $err;
}
$user['data']['aff_check_payable_to'] = $u['aff_check_payable_to'];
$user['street'] = $u['street'];
$user['city'] = $u['city'];
$user['state'] = $u['state'];
$user['zip'] = $u['zip'];
$user['country'] = $u['country'];
} elseif ($u['aff_payout_type'] == 'stormpay'){
if ($u['aff_stormpay_email'] == ''){
$err[] = _AFF_ERROR_3;
return $err;
}
$user['data']['aff_stormpay_email'] = $u['aff_stormpay_email'];
} elseif ($u['aff_payout_type'] == 'ikobo'){
if ($u['aff_ikobo_email'] == ''){
$err[] = _AFF_ERROR_4;
return $err;
}
$user['data']['aff_ikobo_email'] = $u['aff_ikobo_email'];
} elseif ($u['aff_payout_type'] == 'moneybookers'){
if ($u['aff_moneybookers_email'] == ''){
$err[] = _AFF_ERROR_5;
return $err;
}
$user['data']['aff_moneybookers_email'] = $u['aff_moneybookers_email'];
} elseif ($u['aff_payout_type'] == 'egold'){
if ($u['aff_egold_id'] == ''){
$err[] = _AFF_ERROR_6;
return $err;
}
$user['data']['aff_egold_id'] = $u['aff_egold_id'];
} elseif ($u['aff_payout_type'] == 'safepay'){
if ($u['aff_safepay_email'] == ''){
$err[] = _AFF_ERROR_9;
return $err;
}
$user['data']['aff_safepay_email'] = $u['aff_safepay_email'];
} elseif ($u['aff_payout_type'] == ''){
//
} else {
$err[] = _AFF_ERROR_7;
return; // unknown payout type
}
$db->update_user($member_id, $user);
return $err;
}
switch ($vars['action']){
case 'enable_aff':
enable_aff($member_id);
display_links($member_id);
break;
case 'links':
display_links($member_id);
break;
case 'stats':
display_stats($member_id, $vars);
break;
case 'payout_info':
if ($vars['save'] && !$vars['type_change']){
$u = $vars;
$u['data'] = $vars;
$err = update_payout_info($member_id, $vars);
if (!$err) {
$u = $db->get_user($member_id);
}
} else
$u = $db->get_user($member_id);
if ($vars['type_change'])
$u['aff_payout_type'] = $vars['aff_payout_type'];
display_payout_info($member_id, $u, $err);
break;
default: fatal_error(sprintf(_AFF_ERROR_8,$vars[action]), 0);
}
?>
amember/aff.inc.php 0000644 7742766 0035230 00000047563 11573171450 020235 0 ustar nf.mortgageoriginatorseminars www 'PayPal payment',
'check' => 'Offline check',
'egold' => 'E-Gold',
'stormpay' => 'StormPay',
'ikobo' => 'iKobo',
'moneybookers' => 'MoneyBookers',
'safepay' => 'SafePaySolutions'
);
function aff_get_payout_methods($only_enabled=0){
global $config;
$res = $GLOBALS['payout_methods'];
if ($only_enabled){
foreach ($res as $k=>$v)
if (!in_array($k, (array)$config['aff']['payout_methods']))
unset($res[$k]);
}
return $res;
}
function aff_config(){
global $config;
config_set_notebook_comment('Affiliates', 'affiliate program configuration');
add_config_field('aff.payout_methods', 'Accepted Payout methods',
'multi_select', "affiliate can choose a method for payout comissions.
If nothing will be selected, comissions will not be included to automated
payout report.
",
"Affiliates",
'', '', '',
array(
'store_type' => 1,
'options' => aff_get_payout_methods()
));
add_config_field('aff.aff_commission', 'Affiliate commission for first payment',
'integer', "affiliate comissions for first payment, ex.: 1.5 or 2.5%",
"Affiliates",
'', '', '');
add_config_field('aff.aff_commission_rec', 'Affiliate commission for the following payments',
'integer', "affiliate comissions for the following payments, ex.: 1.5 or 2.5%",
"Affiliates",
'', '', '');
add_config_field('aff.aff_commission2', '2 Tier - Affiliate commission for the first payment',
'integer', 'affiliate comissions for referrer of the affiliate, can be set to
percentage of commission received by immediate affiliate only, ex.: 1.5 or 15%
in first case 2 tier affiliate will get USD 1.5 for each sale,
in second case 2 tier affiliate will receive 15% of all related
affiliate commissions',
"Affiliates",
'', '', '');
add_config_field('aff.aff_commission_rec2', '2 Tier - Affiliate commission for the following payments',
'integer', 'affiliate comissions for referrer of the affiliate, can be set to
percentage of commission received by immediate affiliate only, ex.: 1.5 or 15%
in first case 2 tier affiliate will get USD 1.5 for each sale,
in second case 2 tier affiliate will receive 15% of all related
affiliate commissions',
"Affiliates",
'', '', '');
add_config_field('aff.cookie_lifetime', 'Affiliate cookie lifetime',
'integer', "how long (in days) store cookies about referrer.
So if customer will return to the site later, comission will be
paid to referring affiliate.
",
"Affiliates",
'', '', '',
array('default'=>365));
add_config_field('aff.only_first', 'Pay only first commission',
'checkbox', "affiliate will get commision only for first purchase.
In case of recurring payments, only one (first) commission will
be generated.
",
"Affiliates",
'', '', '',
array(
'store_type' => 1
));
add_config_field('aff.do_not_pay_for_free_subscriptions', 'Do not give commision for free subscriptions',
'select', "sale commission will not be credited to affiliate account
if user subscribed to free subscription. Of course, it only affects
'fixed' affiliate commissions.
",
"Affiliates",
'', '', '',
array(
'store_type' => 1,
'options' => array('' => 'Give Commission even for free subscriptions',
1 => 'Do not give commissions for free subscriptions')
));
add_config_field('aff.signup_type', 'Affiliates Signup Type',
'select', "affiliate will get commision only for first purchase.
In case of recurring payments, only one (first) commission will
be generated.
",
"Affiliates",
'', '', '',
array(
'store_type' => 1,
'options' => array('' => 'Default - user have to click link to become affiliate',
1 => 'All new members automatically become affiliates',
2 => 'Only admin can enable user as an affiliate')
));
add_config_field('aff.mail_sale_admin', 'E-Mail commission to admin',
'checkbox', "when new sale commission credited to affiliate account
send an e-mail message to admin
",
"Affiliates",
'', 'email_checkbox_get', '',
array(
'store_type' => 1,
));
add_config_field('aff.mail_sale_user', 'E-Mail commission to customer',
'checkbox', "when new sale commission credited to affiliate account
send an e-mail message to affiliate
",
"Affiliates",
'', 'email_checkbox_get', '',
array(
'store_type' => 1,
));
add_config_field('aff.mail_signup_user', 'Send Signup E-Mail to Affiliate',
'checkbox', "send email when affiliate will signup
",
"Affiliates",
'', 'email_checkbox_get', '',
array(
'store_type' => 1,
));
}
function aff_set_cookie($aff_id){
global $config;
$aff_id = intval($aff_id);
if (!$aff_id) return;
$d = $_SERVER['HTTP_HOST'];
$k = 'amember_aff_id';
$v = $aff_id;
$tm = time() + $config['aff']['cookie_lifetime'] * 3600 * 24;
if (preg_match('/([^\.]+)\.(org|com|net|biz|info)$/', $d, $regs))
setcookie($k,$v,$tm,"/",".{$regs[1]}.{$regs[2]}");
else
setcookie($k,$v,$tm,"/");
}
function aff_decrypt($s){ // easy encryption to hide texts in URL
$from = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$to = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
return strtr($s, $from, $to);
}
function aff_encrypt($s){ // easy encryption to hide texts in URL
return aff_decrypt($s);
}
function aff_make_url($url, $link_id, $aff_id){
global $config;
return "$config[root_url]/go.php?r=$aff_id&i=$link_id";
// return "$config[root_url]/go.php?r=$aff_id&l=".urlencode(aff_encrypt($url));
}
function aff_get_commission($product_id, $is_first, $aff_id=0, $paid='', $tier=1){
global $config, $db;
$pr = $db->get_product($product_id);
$fa = ($tier == 1) ? '' : $tier;
$cf = ($pr['aff_commission'.$fa] != '') ?
$pr['aff_commission'.$fa] : $config['aff']['aff_commission'.$fa];
$cr = ($pr['aff_commission_rec'.$fa] != '') ?
$pr['aff_commission_rec'.$fa] : $config['aff']['aff_commission_rec'.$fa];
$cexp = $is_first ? $cf : $cr;
if (preg_match('/^([\d\.]+)\s*\%$/', $cexp, $regs)){ // %
return round($regs[1] * 0.01 * $paid, 2);
} else { // absolute
return $cexp;
}
return 0;
}
function add_affiliate_commission($payment_id, $receipt_id='', $amount=''){
global $db, $config;
if ($GLOBALS['amember_ignore_aff_commission'] > 0)
return;
$oldp = $db->get_payment($payment_id);
/// affiliate thing
if (!$oldp['member_id']) return;
$u = $db->get_user($oldp['member_id']);
$aff_id = $u['aff_id'];
if ($aff_id){
if ($u['member_id'] == $aff_id) return; // don't credit affiliate himself
$pl = $db->get_user_payments($oldp['member_id'], 1);
$is_first = 1;
if (count($pl))
foreach ($pl as $v){
$orig_id = $v['data'][0]['ORIG_ID'];
if ($v['payment_id'] == $payment_id)
continue;
if ($orig_id && ($oldp['payment_id'] == $orig_id))
continue;
if ($orig_id && ($oldp['data'][0]['ORIG_ID'] == $orig_id))
continue;
$is_first = 0;
break;
}
if ($config['aff']['only_first'] && !$is_first){
return;
}
if ($amount == '')
$amount = $oldp['amount'];
if ($amount<=0.0 && $config['aff']['do_not_pay_for_free_subscriptions'])
return;
$commission = aff_get_commission($oldp['product_id'],
$is_first, $aff_id, $amount, 1);
if ($commission){
$db->aff_add_commission($aff_id, $commission,
$payment_id, $receipt_id,
$oldp['product_id'], $is_first, false, 1);
// calculate 2-tier commission
$aff = $db->get_user($aff_id);
$aff_id2 = $aff['aff_id']; // find second-tier affiliate
if(!$aff_id2) return;
$commission2 = aff_get_commission($oldp['product_id'],
$is_first, $aff_id, $commission, 2);
if(!$commission2) return;
$db->aff_add_commission($aff_id2, $commission2,
$payment_id, $receipt_id,
$oldp['product_id'], $is_first, false, 2);
}
}
}
function aff_get_payout($dat2, $payout_method){
global $db, $config;
$payout_method = $db->escape($payout_method);
if ($payout_method == 'ALL')
$payout_where = " 1 ";
else
$payout_where = " m.aff_payout_type = '$payout_method' ";
$prefix = $db->config['prefix'];
$q = $db->query($s = "SELECT
m.*,
SUM(c.amount) as credit_amount
FROM {$prefix}members m
LEFT JOIN {$prefix}aff_commission c
ON (m.member_id = c.aff_id AND c.record_type='credit' AND ifnull(c.payout_id,'')='' AND c.date <= '$dat2')
WHERE $payout_where
GROUP BY m.member_id
HAVING credit_amount > 0
");
$rows = array();
while ($r = mysql_fetch_assoc($q)){
if ($r['data'])
$r['data'] = $db->decode_data($r['data']);
$rows[$r['member_id']] = $r;
}
###
$q = $db->query($s = "SELECT
m.*,
SUM(c1.amount) as debit_amount,
SUM(IF(record_type='debit', 1, 0)) as debit_count
FROM {$prefix}members m
LEFT JOIN {$prefix}aff_commission c1
ON (m.member_id = c1.aff_id AND c1.record_type='debit' AND ifnull(c1.payout_id, '') = '' AND c1.date <= '$dat2')
WHERE $payout_where
GROUP BY m.member_id
HAVING debit_amount > 0
");
while ($r = mysql_fetch_assoc($q)){
$i = $r['member_id'];
if ($rows[$i]['member_id'])
$rows[$i]['debit_amount'] = $r['debit_amount'] != 0 ? -$r['debit_amount']." (".$r['debit_count'].")" : '';
else {
$r['credit_amount'] = 0.0;
$rows[$i] = $r;
}
}
foreach ($rows as $k=>$r){
$r['account_id'] = "";
switch ($r['aff_payout_type']) {
case 'stormpay':
if ($payout_method == 'ALL')
$r['account_id'] .= 'StormPay: ';
$r['account_id'] .= $r['data']['aff_stormpay_email'];
break;
case 'ikobo':
if ($payout_method == 'ALL')
$r['account_id'] .= 'iKobo: ';
$r['account_id'] .= $r['data']['aff_ikobo_email'];
break;
case 'moneybookers':
if ($payout_method == 'ALL')
$r['account_id'] .= 'MoneyBookers: ';
$r['account_id'] .= $r['data']['aff_moneybookers_email'];
break;
case 'egold':
if ($payout_method == 'ALL')
$r['account_id'] .= 'E-Gold: ';
$r['account_id'] .= $r['data']['aff_egold_id'];
break;
case 'paypal':
if ($payout_method == 'ALL')
$r['account_id'] .= 'PayPal: ';
$r['account_id'] .= $r['data']['aff_paypal_email'];
break;
case 'safepay':
if ($payout_method == 'ALL')
$r['account_id'] .= 'SafePaySolutions: ';
$r['account_id'] .= $r['data']['aff_safepay_email'];
break;
default:
$r['account_id'] = ' ';
break;
}
$rows[$k] = $r;
$rows[$k]['to_pay'] = $s = sprintf('%.2f', $r['credit_amount'] + $r['debit_amount']);
if (!$s)
$rows[$k]['to_pay'] = '';
}
return $rows;
}
function aff_pay_commissions($dat2, $rows, $payout_id){
global $db;
$payout_id = $db->escape($payout_id);
foreach ($rows as $k=>$r){
$db->query("UPDATE {$db->config[prefix]}aff_commission
SET payout_id='$payout_id'
WHERE aff_id='$r[member_id]' AND date <= '$dat2' AND payout_id IS NULL
");
}
}
function aff_pay_commission_paypal($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=paypal-commission-$tm.txt");
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "{$r[data][aff_paypal_email]}\t$r[to_pay]\tUSD\t$r[member_id]\tAffiliate commission for $dat1 - $dat2\r\n";
}
}
function aff_pay_commission_check($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=check-commission-$tm.csv");
print "First Name;Last Name;Street Address;City;State;ZIP;Country;Check Amount\n";
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "$r[name_f];$r[name_l];$r[street];$r[city];$r[state];$r[zip];$r[country];$r[to_pay]\n";
}
}
function aff_pay_commission_stormpay($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=stormpay-commission-$tm.csv");
print "StormPay Account ID; Amount\n";
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "{$r[data][aff_stormpay_email]};$r[to_pay]\n";
}
}
function aff_pay_commission_ikobo($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=ikobo-commission-$tm.csv");
print "iKobo Account ID; Amount\n";
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "{$r[data][aff_ikobo_email]};$r[to_pay]\n";
}
}
function aff_pay_commission_moneybookers($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=moneybookers-commission-$tm.csv");
print "MoneyBookers Account ID; Amount\n";
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "{$r[data][aff_moneybookers_email]};$r[to_pay]\n";
}
}
function aff_pay_commission_egold($dat1, $dat2, $payout_method, $rows){
global $db;
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=egold-commission-$tm.csv");
print "E-Gold Account ID; Amount\n";
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "{$r[data][aff_egold_id]};$r[to_pay]\n";
}
}
function aff_pay_commission_safepay($dat1, $dat2, $payout_method, $rows){
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-type: application/csv");
$tm = time();
header("Content-Disposition: attachment; filename=safepay-commission-$tm.txt");
foreach ($rows as $r){
$r['to_pay'] = sprintf('%.2f', $r['to_pay']);
print "\"{$r[data][aff_safepay_email]}\";\"$r[to_pay]\";\"Affiliate commission for $dat1 - $dat2\"\r\n";
}
}
function aff_get_member_links($u){
global $config;
if (!$u['is_affiliate'] && ($config['aff']['signup_type'] == '')){
return array($config['root_url']."/aff.php?action=enable_aff"
=> _AFF_ADVERTISE_SITE);
} elseif ($u['is_affiliate']) {
return array($config['root_url']."/aff_member.php"
=> _AFF_MEMBER_AREA);
}
}
function aff_make_affiliate($member_id){
global $db, $_AFF_MAKE_AFFILIATE,$config;
if ($_AFF_MAKE_AFFILIATE) return;
if ($member_id <= 0) return;
$u = $db->get_user($member_id);
$u['is_affiliate'] = 1;
$_AFF_MAKE_AFFILIATE = 1;
$db->update_user($member_id, $u);
if($config['aff']['mail_signup_user']) check_aff_signup_email_sent($member_id);
unset($_AFF_MAKE_AFFILIATE);
}
global $config;
if ($config['use_affiliates']){
/**/
add_product_field('aff_commission', 'Affiliate commission for first payment',
'text', 'affiliate comissions for first payment, ex.: 1.5 or 2.5%');
add_product_field('aff_commission_rec', 'Affiliate commission for the following payments',
'text', 'affiliate comissions for following payments, ex.: 0 or 5%');
add_product_field('aff_commission2', '2 Tier - Affiliate commission for first payment',
'text', 'affiliate comissions for referrer of the affiliate');
add_product_field('aff_commission_rec2', '2 Tier - Affiliate commission for the following payments',
'text', 'affiliate comissions for referrer of the affiliate');
add_member_field(
'aff_signup_email_sent', 'Affiliate Signup Email Sent',
'hidden', '',
'',
array('hidden_anywhere' => 1));
/**/
if (in_array('paypal', (array)$config['aff']['payout_methods'])){
add_member_field('aff_paypal_email', _AFF_MEMBER_F1_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('stormpay', (array)$config['aff']['payout_methods'])){
add_member_field('aff_stormpay_email', _AFF_MEMBER_F2_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('ikobo', (array)$config['aff']['payout_methods'])){
add_member_field('aff_ikobo_email', _AFF_MEMBER_F3_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('moneybookers', (array)$config['aff']['payout_methods'])){
add_member_field('aff_moneybookers_email', _AFF_MEMBER_F4_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('egold', (array)$config['aff']['payout_methods'])){
add_member_field('aff_egold_id', _AFF_MEMBER_F5_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('check', (array)$config['aff']['payout_methods'])){
add_member_field('aff_check_payable_to', _AFF_MEMBER_F6_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
if (in_array('safepay', (array)$config['aff']['payout_methods'])){
add_member_field('aff_safepay_email', _AFF_MEMBER_F7_1, 'text', '', '',
array('hidden_anywhere' => 1));
}
setup_plugin_hook('finish_waiting_payment', 'add_affiliate_commission');
setup_plugin_hook('get_member_links', 'aff_get_member_links');
if ($config['aff']['signup_type'] == 1){
setup_plugin_hook('update_users', 'aff_make_affiliate');
}
}
function check_aff_signup_email_sent($member_id){
global $db,$config;
$user = $db->get_user($member_id);
if(!$user['data']['aff_signup_email_sent']){
mail_signup_affiliate($member_id);
$user['data']['aff_signup_email_sent']++;
$db->update_user($member_id, $user);
}
}
?> amember/aff_member.php 0000644 7742766 0035230 00000012763 11573171450 021006 0 ustar nf.mortgageoriginatorseminars www get_user($member_id);
if ($u['is_affiliate'] == '0') {
//fatal_error ('Error. Affiliate members area only.');
$url = $config['root_url'] . "/member.php";
html_redirect($url, 0, _MEMBER_PLEASE_WAIT, _MEMBER_REDIRECTING);
exit();
}
if ($member_id <= 0) die(_AFF_INTERNAL_ERROR);
$vars = get_input_vars();
if (($_SESSION['_amember_user']['email_verified'] < 0) && ($config['verify_email'])){
$u = $_SESSION['_amember_user'];
$v = md5($u['member_id'].$u['login'].$u['email']);
fatal_error(sprintf(_MEMBER_ERROR_1,"
","
","
","",
""), 1,1);
}
/// redirect to make F5 key (Refresh) working
if (strlen($_POST['amember_pass']) && ($_SERVER["REQUEST_METHOD"] == 'POST')){
$url = $PHP_SELF;
srand(time());
if (!preg_match('/\?/', $url))
$url .= "?r=". rand(10000,99999);
html_redirect($url, 0, _MEMBER_PLEASE_WAIT, _MEMBER_REDIRECTING);
exit();
}
////////////////////////////////////////////////////////////////////////
function display_stats($member_id, $vars){
global $db, $t,$config;
$y = date('Y');
$m = date('n');
$months = array();
$total = array();
for ($i=0;$i<12;$i++) {
//$months[$y."-".$m] = array( 'dat' => date( 'F 0-t, Y', strtotime("{$y}-{$m}-01") ) );
$months[$y."_".$m] = array( 'dat' => date( 'F, Y', strtotime("{$y}-{$m}-01") ) );
$m--;
if ($m <= 0) { $m = 12; $y--; }
}
$m = sprintf('%02d', $m);
$dat1 = "{$y}-{$m}-01";
$dat2 = date('Y-m-t');
$dattm1 = date('Ym01000000', strtotime($dat1));
$dattm2 = date('Ymt235959', strtotime($dat2));
// get clicks for the month
$q = $db->query("SELECT CONCAT(YEAR(ac.time),'_',MONTH(ac.time)) AS point, COUNT(log_id), COUNT(DISTINCT(remote_addr))
FROM {$db->config[prefix]}aff_clicks ac
WHERE aff_id=$member_id AND ac.time BETWEEN $dattm1 AND $dattm2
GROUP BY point
");
while (list($d, $r, $u) = mysql_fetch_row($q)){
$months[$d]['raw'] = $r;
$months[$d]['uniq'] = $u;
}
// get total clicks for the month
$q = $db->query("SELECT COUNT(log_id), COUNT(DISTINCT(remote_addr))
FROM {$db->config[prefix]}aff_clicks ac
WHERE aff_id=$member_id AND ac.time BETWEEN $dattm1 AND $dattm2
");
while (list($r, $u) = mysql_fetch_row($q)){
$total['raw'] = $r;
$total['uniq'] = $u;
}
// get comissions for the month
$q = $db->query("SELECT CONCAT(YEAR(ac.date),'_',MONTH(ac.date)) AS point, COUNT(commission_id),
SUM(IF(record_type='debit', amount, 0)),
SUM(IF(record_type='credit', amount, 0))
FROM {$db->config[prefix]}aff_commission ac
WHERE aff_id=$member_id AND ac.date BETWEEN '$dat1' AND '$dat2'
GROUP BY point
");
while (list($d, $cnt, $deb, $cre) = mysql_fetch_row($q)){
$months[$d]['trans'] = $cnt;
$months[$d]['debit'] = $deb != 0 ? -$deb : '';
$months[$d]['credit'] = $cre;
if ($deb || $cre)
//$months[$d]['total'] = $cre + $deb;
$months[$d]['total'] = $cre - $deb;
$total['trans'] += $cnt;
$total['debit'] += $deb;
$total['credit'] += $cre;
$total['total'] += $months[$d]['total'];
}
$total['debit'] = $total['debit'] != 0 ? -$total['debit'] : '';
$t->assign('months', $months);
$t->assign('total', $total);
$q = $db->query("select payout_id, sum(if(record_type='credit', amount, -amount)) as pamount from {$db->config[prefix]}aff_commission where aff_id=$member_id and payout_id != '' and payout_id is not null group by payout_id order by payout_id desc");
while($r = mysql_fetch_assoc($q)){
$d = strtotime($r[payout_id]);
$r[payout_id] = strftime($config[date_format], $d);
$payouts[] = $r;
}
$t->assign("payouts", $payouts);
return $t->fetch("aff_month_stats.html");
}
///////////////////////// MAIN /////////////////////////////////////////
$_amember_id = $_SESSION['_amember_id'];
$vars = get_input_vars();
$aff_stats = display_stats($member_id, $vars);
//$member_links = plugin_get_member_links($_SESSION['_amember_user']);
$member_links = array($config['root_url']."/aff.php?action=links"
=> _AFF_GET_BANS_LINKS,
$config['root_url']."/aff.php?action=stats"
=> _AFF_REVIEW_STAT,
$config['root_url']."/aff.php?action=payout_info"
=> _AFF_UPDATE_PAYOUT
);
$t->assign('member_links', $member_links);
$t->assign('aff_stats', $aff_stats);
$t->display('aff_member.html');
?>
amember/aff_signup.php 0000644 7742766 0035230 00000024211 11573171450 021033 0 ustar nf.mortgageoriginatorseminars www "]/', $vars['name_f'])){
$error[] = _SIGNUP_PLEASE_ENTER_FNAME;
}
if (!strlen($vars['name_l'])){
$error[] = _SIGNUP_PLEASE_ENTER_LNAME;
}
if (preg_match('/[<>"]/', $vars['name_l'])){
$error[] = _SIGNUP_PLEASE_ENTER_LNAME;
}
if (preg_match('/[^0-9a-zA-Z_ ]+/', $vars['login'])){
$error[] = _SIGNUP_INVALID_USERNAME;
} elseif (strlen($vars['login']) < $config['login_min_length']){
$error[] = sprintf(_SIGNUP_INVALID_USERNAME_2,$config['login_min_length']);
} elseif (!$member_id=$db->check_uniq_login($vars['login'], $vars['email'],
$vars['pass0'], 1)){
$error[] = sprintf(_SIGNUP_INVALID_USERNAME_3,$vars[login]);
}
if (!check_email($vars['email'])){
$error[] = _SIGNUP_PLEASE_ENTER_EMAIL;
} elseif (($config['unique_email'] && $member_id <= 0) &&
$db->users_find_by_string($vars['email'], 'email', 1)){
$error[] = _SIGNUP_INVALID_EMAIL_1.'
'.sprintf(_SIGNUP_INVALID_EMAIL_2,'','','
');
}
if (!strlen($vars['pass0'])){
$error[] = _SIGNUP_PLEASE_ENTER_PSWD;
} elseif (strlen($vars['pass0']) < $config['pass_min_length']){
$ll = $config[pass_min_length];
$error[] = sprintf(_SIGNUP_INVALID_PASS_1,$ll);
}
if ($vars['pass0'] != $vars['pass1']){
$error[] = _SIGNUP_INVALID_PASS_2;
}
if (!strlen($vars['aff_payout_type']) && count(aff_get_payout_methods(1)) > 1){
$error[] = _AFF_SIGNUP_PLEASE_PAYOUT_TYPE;
}
$error = array_merge($error, plugin_validate_signup_form($vars, 'affiliate_signup'));
return !count($error);
}
###############################################################################
# SHOW_FORM
#
# get vars from database and plugins
# display $GLOBAL[error] if it set
# substitute previous entered parameters using Smarty
#
function show_form(){
global $t;
global $error;
global $db, $config, $vars;
$t->assign('error', $error);
plugin_fill_in_signup_form($_REQUEST);
$t->assign('additional_fields_html', get_additional_fields_html($vars, 'affiliate_signup'));
$t->assign('aff_payout_types', aff_get_payout_methods(1));
$is_affiliate = '2';
$newsletter_threads = $db->get_signup_threads_c($is_affiliate);
$t->assign('newsletter_threads', $newsletter_threads);
$t->display('aff_signup.html');
}
function auto_login_and_move_subscriptions ($member_id){
global $db, $config;
settype($member_id, 'integer');
if ($member_id <= 0)
return;
$u = $db->get_user($member_id);
if (!$u)
return;
if ($config['auto_login_after_signup']){
$_SESSION['_amember_login'] = $u['login'];
$_SESSION['_amember_pass'] = $u['pass'];
}
if($config['aff']['mail_signup_user']) check_aff_signup_email_sent($member_id);
$g = $db->get_guest_by_email($u['email']);
if (count($g) > 0 && $g['guest_id'] > 0){
$guest_id = $g['guest_id'];
$threads = $db->get_guest_threads($guest_id);
$threads = array_keys($threads);
if (count($threads) > 0){
$db->add_member_threads($member_id, $threads);
$db->delete_guest_threads($guest_id);
}
$db->delete_guest($guest_id);
}
}
###############################################################################
##
## M A I N
##
###############################################################################
$t = & new_smarty();
$error = '';
$vars = & get_input_vars();
plugin_display_signup_form();
$error = array();
unset($member_id);
if ($vars['continue_signup']){
$u = $db->get_user($vars['member_id']);
if (!$u['member_id'])
fatal_error(_SIGNUP_INCORRECT_LINK, 1);
$md5 = md5($u['login'].$u['pass'].$vars['member_id']);
if ($md5 != $vars['md5'])
fatal_error(_SIGNUP_INCORRECT_LINK, 1);
$u['email_verified'] = 1;
$db->update_user($u['member_id'], $u);
auto_login_and_move_subscriptions($u['member_id']);
header("Location: ".$config['root_url']."/thanks.php");
exit();
}
// verificate CAPTCHA
if (($vars['do_affiliate'] || $vars['do_agreement'])
&& $config['use_captcha_signup'] && !$_SESSION['amember_captcha_verified']){
if (($vars['captcha'] != '') &&
(strtolower($vars['captcha']) == $_SESSION['amember_captcha'])){
$_SESSION['amember_captcha_verified'] = true;
} else {
$error[] = _SIGNUP_CAPTCHA_ERROR;
}
}
if ($vars['do_agreement']){
if (!$vars['i_agree']){
$error[] = _SIGNUP_USER_AGREEMENT;
display_agreement($vars['data']);
exit();
}
$vars = unserialize($vars['data']);
$vars['i_agree']++;
foreach ($vars as $k=>$v)
$t->_smarty_vars['request'][$k] = $v;
}
if (!$config['login_dont_lowercase'])
$vars['login'] = strtolower($vars['login']);
if ($config['generate_login'])
$vars['login'] = generate_login($vars);
if ($config['generate_pass'])
$vars['pass'] = $vars['pass0'] = $vars['pass1'] = generate_password($vars);
/////
if ( $vars['do_affiliate'] && check_form() ){
/*
//check for agreement
$display_agreement = 0;
foreach ((array)$vars['product_id'] as $pid){
$product = $db->get_product($pid);
if ($product['need_agreement'])
$display_agreement++;
}
if ($display_agreement && !$vars['i_agree']){
display_agreement(serialize($vars)); // defined in the product.inc.php
exit();
}
*/
$login = $vars['login'];
do { // to easy exit using break()
$member_id = $db->check_uniq_login($vars['login'], $vars['email'], $vars['pass0'], 1);
$member_id_exists = 0;
if ($config['verify_email'])
$vars['email_verified'] = -1;
if ($GLOBALS['_LANG_SELECTED'] != get_default_lang()){
$vars['selected_lang'] = $GLOBALS['_LANG_SELECTED'];
}
if (!$vars['aff_payout_type']){ // if payout type not selected
$payout_methods = aff_get_payout_methods(1);
if (count($payout_methods) == 1) { // if there is only one payout type
$payout_methods = array_keys($payout_methods);
$vars['aff_payout_type'] = $payout_methods[0];
}
}
if ($member_id < 0) {
$member_id = $db->add_pending_user($vars);
$is_affiliate = '2'; //only affiliate
if ($db->get_signup_threads_c($is_affiliate) && $vars['to_subscribe'])
$db->subscribe_member ($member_id, $is_affiliate);
$member = $db->get_user($member_id);
$member['is_affiliate'] = $is_affiliate;
/* No unsubscribe new members!
if (!$vars['to_subscribe']) $member['unsubscribed']='1';
*/
$db->update_user($member_id, $member);
}
elseif (!$member_id)
die(_SIGNUP_LOGIN_EXISTS);
else {
$member_id_exists++; //we found existing user with the same params
// then will clean CC parameters if any
$member = $db->get_user($member_id);
$is_affiliate = '1'; //member & affiliate
if ($db->get_signup_threads_c('2') && $vars['to_subscribe'])
$db->subscribe_member ($member_id, '2'); // subscribe ONLY as affiliate !!!
$member['is_affiliate'] = $is_affiliate;
if (!$vars['to_subscribe']) $member['unsubscribed']='1';
$member['data']['cc-hidden']='';
$member['data']['cc-expire']='';
$member['data']['cc']='';
$member['data']['cc_street']='';
$member['data']['cc_city']='';
$member['data']['cc_state']='';
$member['data']['cc_zip']='';
$member['data']['cc_country']='';
foreach ($vars as $k=>$v) $member[$k] = $v;
$db->update_user($member_id, $member);
}
$additional_values = array();
foreach ($payment_additional_fields as $f){
$fname = $f['name'];
if (isset($vars[$fname]))
$additional_values[$fname] = $vars[$fname];
}
if ($error) {
$db->delete_user($member_id);
break;
}
if ($config['verify_email']){
global $db;
$u = $db->get_user($member_id);
$md5 = md5($u['login'].$u['pass'].$member_id);
mail_verification_email($u, $config['root_url']."/aff_signup.php?continue_signup=1&member_id=$member_id&member_id_exists=$member_id_exists&md5=$md5");
$t->assign('user', $u);
$t->display("email_verify.html");
exit();
}
unset($_SESSION['amember_captcha_verified']);
auto_login_and_move_subscriptions ($member_id);
//header("Location: ".$config['root_url']."/aff_member.php");
$url = $config['root_url'] . "/aff_member.php";
html_redirect($url, 0, _AFF_MEMBER_THANK_YOU, _AFF_MEMBER_REDIRECTING);
exit();
} while (0);
}
show_form();
?>
amember/ajax.php 0000644 7742766 0035230 00000006663 11573171451 017651 0 ustar nf.mortgageoriginatorseminars www encode($resp);
return true;
}
function ajaxError($msg){
ajaxResponse(array('msg' => $msg));
}
function ajaxGetStates($vars){
return ajaxResponse(db_getStatesForCountry($vars['country']));
}
function ajaxCheckUniqLogin($vars){
global $db, $config;
$login = htmlentities($vars['login']);
$res = array('msg' => '', 'errorCode' => 0);
do {
// check for valid login first
if ($vars['login'] == '') {
$res['msg'] = sprintf(_SIGNUP_INVALID_USERNAME_2, $config['login_min_length'], $config['login_max_length']);
$res['errorCode'] = 2;
break;
}
if (strlen($vars['login']) < $config['login_min_length'] || strlen($vars['login']) > $config['login_max_length']){
$res['msg'] = sprintf(_SIGNUP_INVALID_USERNAME_2, $config['login_min_length'], $config['login_max_length']);
$res['errorCode'] = 3;
break;
}
if (!preg_match(getLoginRegex(), $vars['login'])){
$res['msg'] = $config['login_disallow_spaces'] ? _SIGNUP_INVALID_USERNAME : _SIGNUP_INVALID_USERNAME_W_SPACES;
$res['errorCode'] = 4;
break;
}
// check if it is available
$r = $db->check_uniq_login($vars['login'], $vars['email'], $vars['pass'], 1);
if (!$r){
$res['msg'] =
sprintf(_UNIQ_LOGIN_EXSTS_TEXT, htmlentities($login)) . ".
" .
_UNIQ_LOGIN_EXSTS_TEXT_1 . "
" .
sprintf(_UNIQ_LOGIN_EXSTS_TEXT_2, "", "");
$res['errorCode'] = 1;
break;
} else {
$res['msg'] = sprintf(_UNIQ_LOGIN_FREE_TEXT, htmlentities($login));
$res['errorCode'] = 0;
break;
}
} while (false);
return ajaxResponse($res);
}
function ajaxCheckCoupon($vars){
global $db, $config;
$coupon = htmlentities($vars['coupon']);
$res = array('msg' => '', 'errorCode' => 0);
$ret = $db->coupon_get($vars['coupon']);
if (!is_array($ret) || !$ret['coupon_id']){
$res['msg'] = $ret;
$res['errorCode'] = 1;
}
return ajaxResponse($res);
}
header("Content-type: text/plain; charset=UTF-8");
$vars = get_input_vars();
$vars['do'] = preg_replace('/[^a-zA-Z0-9_.,-]/', '', $vars['do']);
switch ($vars['do']){
case 'get_states':
ajaxGetStates($vars);
break;
case 'check_uniq_login':
ajaxCheckUniqLogin($vars);
break;
case 'check_coupon':
ajaxCheckCoupon($vars);
break;
default:
ajaxError('Unknown Request: ' . $vars['do']);
}
amember/amember.sql 0000644 7742766 0035230 00000070375 11613276243 020347 0 ustar nf.mortgageoriginatorseminars www ###############################################################
# #
# aMember MySQL DATABASE DUMP #
# #
# This file is to use with amember/setup.php only #
# It cannot be loaded to MySQL as is. #
# #
###############################################################
# Table structure for table 'access_log'
CREATE TABLE @DB_MYSQL_PREFIX@access_log(
log_id int(11) NOT NULL auto_increment,
member_id int(11) NOT NULL,
time timestamp(14) NOT NULL,
url varchar(255) default NULL,
remote_addr varchar(15) default NULL,
referrer varchar(255) default NULL,
PRIMARY KEY (log_id),
INDEX (member_id, time, remote_addr),
INDEX (time)
)
;
#
# Table structure for table 'aff_clicks'
#
CREATE TABLE @DB_MYSQL_PREFIX@aff_clicks(
log_id int(11) NOT NULL auto_increment,
aff_id int(11) NOT NULL,
time timestamp(14) NOT NULL,
url varchar(255) default NULL,
remote_addr varchar(15) default NULL,
referrer varchar(255) default NULL,
PRIMARY KEY (log_id),
INDEX (aff_id, time, remote_addr),
INDEX (time)
)
;
#
# Table structure for table 'cron_run'
#
CREATE TABLE @DB_MYSQL_PREFIX@cron_run (
id int(11) NOT NULL default '0',
time datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id)
);
#
# Table structure for table 'error_log'
#
CREATE TABLE @DB_MYSQL_PREFIX@error_log (
log_id int(11) NOT NULL auto_increment,
member_id int(11) default '0',
time timestamp(14) NOT NULL,
url varchar(255) default NULL,
remote_addr varchar(15) default NULL,
referrer varchar(255) default NULL,
error text,
PRIMARY KEY (log_id)
) ;
#
# Table structure for table 'members'
#
CREATE TABLE @DB_MYSQL_PREFIX@members (
member_id int(11) NOT NULL auto_increment,
login varchar(32) NOT NULL,
pass varchar(32) default NULL,
email varchar(64) default NULL,
name_f varchar(32) NOT NULL default '',
name_l varchar(32) NOT NULL default '',
street varchar(255) default NULL,
city varchar(255) default NULL,
state varchar(255) default NULL,
zip varchar(255) default NULL,
country varchar(255) default NULL,
is_male smallint(6) default NULL,
added datetime NOT NULL default '0000-00-00 00:00:00',
remote_addr varchar(15) default NULL,
data text NOT NULL,
PRIMARY KEY (member_id),
UNIQUE KEY login (login)
) ;
#
# Table structure for table 'payments'
#
CREATE TABLE @DB_MYSQL_PREFIX@payments (
payment_id int(11) NOT NULL auto_increment,
member_id int(11) NOT NULL ,
product_id int(11) NOT NULL ,
begin_date date NOT NULL ,
expire_date date NOT NULL ,
paysys_id varchar(32) NOT NULL default '',
receipt_id varchar(32) NOT NULL default '',
amount decimal(12,2) NOT NULL default '0.00',
completed smallint(6) default '0',
remote_addr varchar(15) NOT NULL default '',
data text,
time timestamp(14) NOT NULL,
PRIMARY KEY (payment_id),
KEY member_id (member_id)
) ;
#
# Table structure for table 'products'
#
CREATE TABLE @DB_MYSQL_PREFIX@products (
product_id int(11) NOT NULL auto_increment,
title varchar(255) NOT NULL default '',
description text,
price decimal(12,2) default NULL,
data text,
PRIMARY KEY (product_id)
) ;
#### *** 1.9.1 ***
CREATE TABLE @DB_MYSQL_PREFIX@coupon (
coupon_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,
batch_id int(10) unsigned NOT NULL,
code varchar(32) NOT NULL,
comment varchar(64),
discount varchar(32) NOT NULL,
begin_date date,
expire_date date,
locked tinyint(3) unsigned NOT NULL,
product_id varchar(255),
use_count int(11),
member_use_count int(11),
used_count int(11),
used_for text,
data text,
UNIQUE KEY code (code)
);
CREATE TABLE @DB_MYSQL_PREFIX@config (
config_id int(11) NOT NULL auto_increment PRIMARY KEY,
name varchar(64) NOT NULL,
type smallint(6) default '0',
value varchar(255) ,
blob_value blob,
UNIQUE KEY name (name)
);
CREATE TABLE @DB_MYSQL_PREFIX@aff_commission (
commission_id int(11) NOT NULL auto_increment PRIMARY KEY,
aff_id int NOT NULL,
date DATE NOT NULL,
amount DECIMAL(12,2),
record_type char(16) NOT NULL,
payment_id int NOT NULL,
receipt_id char(32) NOT NULL,
product_id int not null,
is_first int not null,
payout_id char(32),
tier smallint default 1,
INDEX aff_id (aff_id, date),
UNIQUE KEY payment (payment_id, receipt_id, record_type, tier)
);
CREATE TABLE @DB_MYSQL_PREFIX@folders (
folder_id int(11) NOT NULL auto_increment,
path varchar(255) NOT NULL default '',
url varchar(255) NOT NULL default '',
method varchar(64) default NULL,
product_ids varchar(64) NOT NULL default '',
files_content blob,
PRIMARY KEY (folder_id),
UNIQUE KEY path (path),
UNIQUE KEY url (url)
);
CREATE TABLE @DB_MYSQL_PREFIX@admin_log (
log_id int(11) NOT NULL auto_increment,
dattm datetime,
admin_id int(11),
ip varchar(32),
tablename varchar(32) NOT NULL,
record_id int(11) NOT NULL,
message text,
admin_login varchar(32) default NULL,
PRIMARY KEY (log_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@admins (
admin_id int(11) NOT NULL auto_increment,
login varchar(32) NOT NULL default '',
pass varchar(40) NOT NULL default '',
last_login datetime default NULL,
last_ip varchar(32) default NULL,
last_session varchar(32) default NULL,
email varchar(255) default NULL,
super_user smallint(6) NOT NULL default '0',
perms text,
PRIMARY KEY (admin_id),
UNIQUE KEY login (login)
);
#### fill-in config values
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('root_url', 0, '@ROOT_URL@', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('root_surl', 0, '@ROOT_SURL@', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('admin_email', 0, '@ADMIN_EMAIL@', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('generate_login', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('login_min_length', 0, '4', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('login_max_length', 0, '32', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('generate_pass', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('pass_min_length', 0, '4', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('pass_max_length', 0, '32', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('clear_access_log', 0, '1', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('clear_access_log_days', 0, '7', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('max_ip_count', 0, '5', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('max_ip_period', 0, '1440', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('select_multiple_products', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('multi_title', 0, 'Membership', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('use_coupons', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('date_format', 0, '%m/%d/%Y', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('time_format', 0, '%m/%d/%Y %H:%M:%S', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('send_signup_mail', 0, '1', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('mail_expire', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('mail_expire_days', 0, '1', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('use_address_info', 0, '0', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('unique_email', 0, '1', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('curl', 0, '@CURL_PATH@', '');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('profile_fields', 1, '', 'a:4:{i:0;s:5:"pass0";i:1;s:6:"name_f";i:2;s:6:"name_l";i:3;s:5:"email";}');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('license', 2, '', '@LICENSE@');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('plugins.payment', 1, '', '@PAYMENT_PLUGINS@');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('plugins.protect', 1, '', '@PROTECT_PLUGINS@');
REPLACE INTO @DB_MYSQL_PREFIX@config
(name,type,value,blob_value) VALUES ('lang.list', 1, '', 'a:1:{i:0;s:10:"en:English";}');
REPLACE INTO @DB_MYSQL_PREFIX@admins
(login, pass, email, super_user)
VALUES
('@ADMIN_LOGIN@', '@ADMIN_PASS@', '@ADMIN_EMAIL@', 1);
MODIFY @DB_MYSQL_PREFIX@members FIELD status smallint NOT NULL DEFAULT 0;
MODIFY @DB_MYSQL_PREFIX@members FIELD aff_id int;
MODIFY @DB_MYSQL_PREFIX@members FIELD is_affiliate tinyint(4);
MODIFY @DB_MYSQL_PREFIX@members FIELD aff_payout_type varchar(32);
MODIFY @DB_MYSQL_PREFIX@members FIELD unsubscribed tinyint(4) DEFAULT 0;
MODIFY @DB_MYSQL_PREFIX@members FIELD email_verified tinyint(4) DEFAULT 0;
### add affiliate id field if it don't exists
MODIFY @DB_MYSQL_PREFIX@payments FIELD aff_id int NOT NULL;
### add payer_id field if it don't exists
MODIFY @DB_MYSQL_PREFIX@payments FIELD payer_id VARCHAR(255) NOT NULL;
### add indexes
MODIFY @DB_MYSQL_PREFIX@payments INDEX payer_id (payer_id);
MODIFY @DB_MYSQL_PREFIX@admin_log INDEX al (tablename, record_id);
MODIFY @DB_MYSQL_PREFIX@aff_commission INDEX ac (date);
### 1.9.3RC..
##
MODIFY @DB_MYSQL_PREFIX@coupon FIELD use_count int NOT NULL DEFAULT 0;
MODIFY @DB_MYSQL_PREFIX@coupon FIELD member_use_count int NOT NULL DEFAULT 0;
MODIFY @DB_MYSQL_PREFIX@coupon FIELD used_count int NOT NULL DEFAULT 0;
MODIFY @DB_MYSQL_PREFIX@payments FIELD coupon_id int NOT NULL;
MODIFY @DB_MYSQL_PREFIX@payments INDEX coupon_id (coupon_id);
MODIFY @DB_MYSQL_PREFIX@payments FIELD tm_added datetime NOT NULL;
MODIFY @DB_MYSQL_PREFIX@payments INDEX tm_added (tm_added, product_id);
MODIFY @DB_MYSQL_PREFIX@payments FIELD tm_completed datetime NULL;
MODIFY @DB_MYSQL_PREFIX@payments INDEX tm_completed (tm_completed, product_id);
CREATE TABLE @DB_MYSQL_PREFIX@failed_login (
failed_login_id int(11) NOT NULL auto_increment,
ip char(15) NOT NULL,
login_type int(11) NOT NULL,
failed_logins int(11) NOT NULL,
last_failed int(11) NOT NULL,
PRIMARY KEY (failed_login_id),
UNIQUE KEY ip (ip, login_type)
);
## 300 ##
MODIFY @DB_MYSQL_PREFIX@members FIELD security_code VARCHAR(40);
MODIFY @DB_MYSQL_PREFIX@members FIELD securitycode_expire DATETIME;
REPLACE INTO @DB_MYSQL_PREFIX@config (name,type,value) VALUES ('auto_login_after_signup', 0, '1');
CREATE TABLE @DB_MYSQL_PREFIX@newsletter_thread (
thread_id int(10) unsigned NOT NULL auto_increment,
title varchar(60) NOT NULL default '',
description text,
is_active smallint NOT NULL default 1,
blob_available_to blob default NULL,
blob_auto_subscribe blob default NULL,
PRIMARY KEY (thread_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@newsletter_archive (
archive_id int(10) unsigned NOT NULL auto_increment,
threads varchar(255) NOT NULL default '',
subject varchar(255) NOT NULL default '',
message text,
add_date datetime,
PRIMARY KEY (archive_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@newsletter_guest (
guest_id int(10) unsigned NOT NULL auto_increment,
guest_name varchar(60) NOT NULL default '',
guest_email varchar(60) NOT NULL default '',
PRIMARY KEY (guest_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@newsletter_guest_subscriptions (
guest_subscription_id int(10) unsigned NOT NULL auto_increment,
guest_id int(10) unsigned NOT NULL,
thread_id int(10) unsigned NOT NULL,
PRIMARY KEY (guest_subscription_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@newsletter_member_subscriptions (
member_subscription_id int(10) unsigned NOT NULL auto_increment,
member_id int(10) unsigned NOT NULL,
thread_id int(10) unsigned NOT NULL,
PRIMARY KEY (member_subscription_id)
);
CREATE TABLE @DB_MYSQL_PREFIX@email_templates (
email_template_id int(11) NOT NULL auto_increment,
name varchar(32) NOT NULL default '',
lang varchar(16) NOT NULL default '',
format enum('text','html','multipart') NOT NULL default 'text',
subject varchar(255) NOT NULL default '',
txt mediumtext NOT NULL,
plain_txt mediumtext,
attachments mediumtext,
product_id int(11) default NULL,
`day` int(11) default NULL,
PRIMARY KEY (email_template_id)
);
## insert e-mail templates
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (1, 'verify_email', 'en', 'text', '{$config.site_title} - Account Verification', 'Hello {$user.name_f} {$user.name_l},\r\n\r\nYou (or someone else) has just registered an account on {$config.site_title}.\r\nClicking on the link below will activate the account:\r\n{$url}\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (2, 'send_pending_email', 'en', 'text', 'Pending Payment', 'Dear {$name_f} {$name_l},\r\n\r\nThank you for signup. Your payment status is PENDING.\r\nPlease complete payment as described.\r\n\r\n Your User ID: {$login} \r\n Your Password: {$pass}\r\n\r\nYour may log-on to your member pages at:\r\n{$config.root_url}/member.php\r\nand check your subscription status.\r\n\r\nBest Regards,\r\nSite Team\r\n', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (3, 'mail_not_completed', 'en', 'text', '{$config.site_title} - Signup is not finished', 'Dear {$name_f} {$name_l},\r\n\r\nThank you for signup! Unfortunately, you have not finished\r\npayment yet. If you have any troubles with payment,\r\ndon''t hesitate to contact us using the following \r\nemail address: {$config.admin_email}.\r\n\r\nDespite the fact that your payment is not completed,\r\na customer record has been created for you. \r\nYou may login to members area using the following \r\nURL :\r\n {$config.root_url}/member.php\r\nYou member details are:\r\n Your User ID: {$login} \r\n Your Password: {$pass}\r\n\r\nAfter logging-in, you may use "Add/Renew Subscription" controls\r\nto complete your payment.\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, 1);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (4, 'send_signup_mail', 'en', 'text', '{$config.site_title} - Membership Information', 'Dear {$name_f} {$name_l},\r\n\r\nThank you for subscribing on {$config.site_title}!\r\n\r\n Your User ID: {$login} \r\n Your Password: {$pass}\r\n\r\nLog-on to your member pages at:\r\n{$config.root_url}/member.php\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (5, 'send_payment_mail', 'en', 'text', '{$config.site_title} - Payment Receipt', 'Thank you for your order. You may find order details below:\r\n\r\nYour Invoice Number {$payment.payment_id} from {$payment.tm_completed|date_format:$config.date_format}\r\n\r\n{"Product/Subscription Title"|string_format:"%-50s"} Price\r\n-----------------------------------------------------------\r\n{foreach from=$products item=p}\r\n{$p.title|string_format:"%-50s"} {$config.currency|default:"$"}{$p.price}\r\n{/foreach}\r\n-----------------------------------------------------------\r\n{"Subtotal"|string_format:"%-50s"} {$config.currency|default:"$"}{$subtotal|string_format:"%.2f"}\r\n{if $payment.data.COUPON_DISCOUNT ne "" }\r\n{"Discount"|string_format:"%-50s"} {$config.currency|default:"$"}{$payment.data.COUPON_DISCOUNT|string_format:"%.2f"}\r\n{/if}\r\n{if $payment.data.TAX_AMOUNT ne ""}\r\n{"Tax Amount"|string_format:"%-50s"} {$config.currency|default:"$"}{$payment.data.TAX_AMOUNT|string_format:"%.2f"}\r\n{/if}\r\n-----------------------------------------------------------\r\n{"Total"|string_format:"%-50s"} {$config.currency|default:"$"}{$total|string_format:"%.2f"}\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (6, 'send_payment_admin', 'en', 'text', '{$config.site_title} *** New Payment', 'New payment completed:\r\n Product: {$product.title}\r\n Amount: {$config.currency|default:"$"}{$payment.amount}\r\n Period: {$payment.begin_date|date_format:$config.date_format} - {$payment.expire_date|date_format:$config.date_format}\r\n\r\n User details:\r\n Username: {$user.login}\r\n Email: {$user.email}\r\n Name: {$user.name_f} {$user.name_l}\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (7, 'mail_expire', 'en', 'text', '{$config.site_title} - Your Subscription Expires', 'Dear {$name_f} {$name_l},\r\n\r\nYour subscription on {$config.site_title} expires {$payment.expire_date|date_format:"%m/%d/%Y"}.\r\n\r\nPlease log-on to membership information page at:\r\n{$config.root_url}/member.php\r\nand renew your subscription.\r\n\r\nYour login details:\r\n Your User ID: {$login} \r\n Your Password: {$pass}\r\n\r\nThank you for your attention!\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, 1);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (8, 'mail_cancel_admin', 'en', 'text', '{$config.site_title} - User subscription cancelled', 'User {$user.login}, "{$user.name_f} {$user.name_l}" <{$user.email}>\r\nhas cancelled recurring subscription #{$payment.payment_id} to product\r\n{$product.title}.\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (9, 'mail_cancel_member', 'en', 'text', '{$config.site_title} - Subscription cancelled', 'Dear {$user.name_f} {$user.name_l},\r\n\r\nYour subscription to "{$product.title}" cancelled. Feel free to subscribe \r\nagain, you can do it here:\r\n {$config.root_url}/member.php\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (10, 'cc_rebill_failed', 'en', 'text', '{$config.site_title} Subscription Renewal Failed', 'Hello {$user.name_f} {$user.name_l},\r\n\r\nYour subscription was not renewed automatically by membership system\r\ndue to payment failure: "{$error}".\r\n\r\n{* If subscription has been pro-rated. *}\r\n{if $new_expire ne "" }\r\nBilling attempt will be automatically repeated {$new_expire|date_format:$config.date_format},\r\nplease add funds to your card or update your credit card information.\r\n{/if}\r\n\r\nYou may update your credit card info here: \r\n{$config.root_url}/member.php\r\n\r\nThank you for attention!\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (11, 'cc_rebill_success', 'en', 'text', '{$config.site_title} Subscription Renewed', 'Hello {$user.name_f} {$user.name_l},\r\n\r\nYour subscription has been renewed automatically by our membership system.\r\nYour credit card was charged on ${$payment.amount}.\r\n\r\nNext renewal date: {$payment.expire_date|date_format:$config.date_format}\r\n\r\nYou may login to membership info page at :\r\n{$config.root_url}/member.php\r\n\r\nThank you!\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (12, 'card_expires', 'en', 'text', 'Credit Card Expiration', 'Hello {$user.name_f} {$user.name_l},\r\n\r\nYour credit card that we have on file for recurring billing will expire\r\non {$expires}. Next recurring billing for "{$product.title}"\r\nis sheduled for {$payment.expire_date|date_format:$config.date_format}.\r\n\r\nTo avoid any interruption of your subscription, please visit page\r\n{$config.root_url}/member.php\r\nand update your credit card information. \r\n\r\nThank you!\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (13, 'aff.mail_sale_admin', 'en', 'text', '** Affiliate Commission', 'Dear admin,\r\n\r\nNew sale has been made with using of affiliate link.\r\nYou may find sale details below:\r\n\r\n----\r\nAffilate: {$affiliate.member_id} / {$affiliate.login} / {$affiliate.email} \r\n {$affiliate.name_f} {$affiliate.name_l} / {$affiliate.remote_addr}\r\nNew Member: {$user.member_id} / {$user.login} / {$user.email} \r\n {$user.name_f} {$user.name_l} / {$user.remote_addr}\r\nPayment REF: {$payment.payment_id}\r\nTotal: {$payment.amount}\r\nProduct ordered: {$product.title}\r\nCommission paid: {$commission}\r\n----\r\n\r\n', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (14, 'aff.mail_sale_user', 'en', 'text', '** Affiliate Sale', 'Dear {$affiliate.name_f} {$affiliate.name_l},\r\n\r\nNew sale has been made by your affiliate link and \r\ncommission credited to your balance. You may find \r\nsale details below:\r\n\r\n----\r\nPayment REF: {$payment.payment_id}\r\nTotal: {$payment.amount}\r\nProduct ordered: {$product.title}\r\nYour commission: {$commission}\r\n----\r\n\r\n', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (15, 'max_ip_actions', 'en', 'text', '*** Account Sharing Violation Detected', 'There is an automated message from aMember Pro script. \r\nAn account violation has been detected for the following\r\ncustomer:\r\n User details:\r\n Username: {$user.login}\r\n Email: {$user.email}\r\n Name: {$user.name_f} {$user.name_l}\r\n{if $config.max_ip_actions ne "2"}\r\nCustomer account has been automatically locked.\r\n{/if}\r\n \r\nIt has reached configured limit of {$config.max_ip_count} IP within\r\n{$config.max_ip_period} minutes. Please login into aMember CP and review\r\nhis access log. \r\n\r\nIf it looks like a script mistake, you may disable sharing violation checking \r\nfor this user in the "User Profile", or disable it globally at aMember CP -> \r\nSetup -> Advanced by setting "Max Number of IP" to something like "99999".\r\n \r\n--\r\nYour aMember Pro script \r\n{$config.root_url}/admin/', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (16, 'manually_approve', 'en', 'text', '{$config.site_title} Your signup is pending', 'Dear {$name_f} {$name_l},\r\n\r\nThank you for subscribing!\r\n\r\nWe review all payments manually, so your payment \r\nstatus is pending. You will receive email when your\r\naccount will be approved. Thank you for your patience.\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (17, 'verify_guest', 'en', 'text', '{$config.site_title} - Newsletter Subscription', 'Dear {$name},\r\n\r\nYou signed up for a guest subscription on {$config.site_title}.\r\n\r\nTo confirm subscription please follow a link:\r\n {$link}\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (18, 'send_pass', 'en', 'text', '{$config.site_title} - Lost Password', 'Dear {$name_f} {$name_l},\r\n\r\nYou have requested your member log-in information.\r\n\r\n Your User ID: {$login}\r\n\r\n Your Password: {$pass}\r\n\r\nLog-in to member pages at:\r\n {$config.root_url}/member.php\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (19, 'send_security_code', 'en', 'text', 'Your Lost Password', 'Dear {$name_f} {$name_l},\r\n\r\nYou have requested your member log-in information.\r\n\r\n Your User ID: {$login}\r\n\r\nFollow a link below to change your password:\r\n {$config.root_url}/sendpass.php?s={$code}\r\n \r\nThis link will be active {$hours} hour(s).\r\n\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
MODIFY @DB_MYSQL_PREFIX@newsletter_guest FIELD security_code VARCHAR(40);
MODIFY @DB_MYSQL_PREFIX@newsletter_guest FIELD securitycode_expire DATETIME;
MODIFY @DB_MYSQL_PREFIX@newsletter_guest_subscriptions FIELD security_code VARCHAR(40);
MODIFY @DB_MYSQL_PREFIX@newsletter_guest_subscriptions FIELD securitycode_expire DATETIME;
## 301 ##
MODIFY @DB_MYSQL_PREFIX@payments FIELD tax_amount decimal(12,2) NOT NULL default '0.00';
MODIFY @DB_MYSQL_PREFIX@newsletter_archive FIELD is_html smallint NOT NULL default 0;
MODIFY @DB_MYSQL_PREFIX@folders FIELD product_ids text NOT NULL;
## 308 ##
MODIFY @DB_MYSQL_PREFIX@admins FIELD pass varchar(128) NOT NULL default '';
CREATE TABLE @DB_MYSQL_PREFIX@countries (
country_id INT NOT NULL auto_increment PRIMARY KEY,
country char(2) NOT NULL,
title varchar(64),
tag int default NULL,
UNIQUE (country)
);
CREATE TABLE @DB_MYSQL_PREFIX@states (
state_id int NOT NULL auto_increment PRIMARY KEY,
state char(12) NOT NULL,
country char(2) NOT NULL,
title varchar(64),
UNIQUE(state),
INDEX (country)
);
MODIFY @DB_MYSQL_PREFIX@coupon FIELD is_recurring smallint not null default 0;
MODIFY @DB_MYSQL_PREFIX@aff_commission FIELD tier smallint default 1;
MODIFY @DB_MYSQL_PREFIX@aff_commission UNIQUE INDEX payment (payment_id, receipt_id, record_type, tier);
MODIFY @DB_MYSQL_PREFIX@newsletter_member_subscriptions FIELD status smallint NOT NULL default 1;
## 311 ##
MODIFY @DB_MYSQL_PREFIX@countries FIELD status ENUM( 'added', 'changed' ) default NULL;
MODIFY @DB_MYSQL_PREFIX@states FIELD status ENUM( 'added', 'changed' ) default NULL;
MODIFY @DB_MYSQL_PREFIX@states FIELD tag int default 0;
# Table structure for table 'products_links' for incremental content plugin
CREATE TABLE @DB_MYSQL_PREFIX@products_links(
link_id int(11) NOT NULL auto_increment,
link_product_id int(11) NOT NULL,
link_start_delay varchar(10) NOT NULL,
link_duration varchar(10) NOT NULL,
link_url varchar(255) default NULL,
link_title varchar(255) default NULL,
link_path varchar(255) default NULL,
link_protected smallint(6) default '0',
time timestamp(14) NOT NULL,
PRIMARY KEY (link_id),
INDEX (link_product_id),
INDEX (time)
);
MODIFY @DB_MYSQL_PREFIX@products_links FIELD link_group_id int default 0;
# Table structure for table 'products_links_groups'
CREATE TABLE @DB_MYSQL_PREFIX@products_links_groups (
id int(11) NOT NULL auto_increment,
title varchar(255) NOT NULL ,
description varchar(255) default NULL ,
priority int(11) default '0',
PRIMARY KEY (id)
);
## 313 ##
CREATE TABLE @DB_MYSQL_PREFIX@rebill_log (
rebill_log_id int not null auto_increment PRIMARY KEY,
added_tm datetime not null,
payment_date date not null,
payment_id int not null,
rebill_payment_id int not null,
amount decimal(12,2) not null,
status smallint default null,
status_tm datetime,
status_msg varchar(255),
index (payment_id)
);
## 314 ##
MODIFY @DB_MYSQL_PREFIX@coupon FIELD member_id int not null default 0;
## 319 ##
MODIFY @DB_MYSQL_PREFIX@products_links FIELD link_comment text NOT NULL;
MODIFY @DB_MYSQL_PREFIX@products_links FIELD link_files_path text NOT NULL;
## 320 ##
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (20, 'verify_email_profile', 'en', 'text', '{$config.site_title} - Email Verification', 'Hello {$user.name_f} {$user.name_l},\r\n\r\nYou (or someone else) has just changed email address in your account on {$config.site_title}.\r\nClicking on the link below will approve this change:\r\n\r\n{$url}\r\n\r\nPlease note that email address will be changed in your profile only if you will click on above link.\r\nIf you didn\'t request email address change just disregard this message.\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
INSERT INTO @DB_MYSQL_PREFIX@email_templates VALUES (21, 'aff.mail_signup_user', 'en', 'text', '{$config.site_title} - Affiliate Information', 'Dear {$name_f} {$name_l},\r\n\r\nThank you for signup to affiliate programm on {$config.site_title}!\r\n\r\n Your User ID: {$login} \r\n Your Password: {$pass}\r\n\r\nLog-on to your affiliate area at:\r\n{$config.root_url}/aff_member.php\r\nYour affiliate link:\r\n{$config.root_url}/go.php?r={$user.member_id}\r\n--\r\nBest Regards,\r\n{$config.site_title}\r\n{$config.root_url}', '', '', NULL, NULL);
## ALL ##
### keep this last line, don't forget to increase db_version in common.inc.php
REPLACE INTO @DB_MYSQL_PREFIX@config (name,type,value) VALUES ('db_version', 0, '320');
### amember/cancel.php 0000644 7742766 0035230 00000002054 11573171451 020141 0 ustar nf.mortgageoriginatorseminars www display("cancel.html");
?>
amember/captcha.php 0000644 7742766 0035230 00000005076 11573171451 020326 0 ustar nf.mortgageoriginatorseminars www getKeyString();
amember/common.inc.php 0000644 7742766 0035230 00000177406 11613276246 020775 0 ustar nf.mortgageoriginatorseminars www $v) {
if (preg_match('/^(GLOBALS|_SERVER|_GET|_POST|_COOKIE|_FILES|_ENV|_REQUEST|_SESSION)$/i', $k)) exit();
unset(${$k});
}
$config['version'] = '3.2.4PRO';
$config['require_db_version'] = '320';
$config['tables'] = array(
'access_log',
'admin_log',
'admins',
'aff_clicks',
'aff_commission',
'config',
'coupon',
'cron_run',
'error_log',
'email_templates',
'folders',
'failed_login',
'members',
'newsletter_archive',
'newsletter_guest',
'newsletter_guest_subscriptions',
'newsletter_member_subscriptions',
'newsletter_thread',
'payments',
'products',
);
$config['tables_skip_backup'] = array(
'access_log',
'error_log'
);
/**
* Create new Smarty object
* @return double Smarty to newly created Smarty object
*
*/
function smarty_modifier_amember_date_format($string, $format=null)
{
if ($string == MAX_SQL_DATE)
return _COMMON_LIFETIME;
if ($string == RECURRING_SQL_DATE)
return _COMMON_RECURRING;
if ($format == null)
$format = $GLOBALS['config']['date_format'];
if ($string != '') {
return strftime($format, smarty_make_timestamp($string));
}
}
function smarty_prefilter_literal_script($source, &$smarty){
$result=&$source;
$result=preg_replace('~~iU', '', $result);
return $result;
}
function smarty_prefilter_literal_style($source, &$smarty){
$result=&$source;
$result=preg_replace('~~iU', '', $result);
return $result;
}
function smarty_prefilter_put_config_cb($args){
global $config;
return $config[$args[1]];
}
function smarty_outputfilter_put_config($source, &$smarty){
$result=&$source;
$result=preg_replace_callback('/#\$config\.(.+?)#/', 'smarty_prefilter_put_config_cb',
$result);
return $result;
}
function smarty_prefilter_put_lang_cb($args){
$vars = split('\|', $args[1]);
$const = array_shift($vars);
if ($vars){
return vsprintf(constant($const), $vars);
} else {
return constant($args[1]);
}
}
function smarty_outputfilter_put_lang($source, &$smarty){
$result=&$source;
$result=preg_replace_callback('/#(_[A-Z].+?)#/', 'smarty_prefilter_put_lang_cb',
$result);
return $result;
}
function smarty_outputfilter_literal_cleanup($source, &$smarty){
$result=&$source;
$result=preg_replace('~~iU', '', $result);
return $result;
}
function smarty_function_country_options($params, &$smarty){
global $db;
$ret = "";
foreach (db_getCountryList($add_empty=true) as $c => $t){
$sel = ($c == $params['selected']) ? 'selected="selected"' : '';
$ret .= "\n";
}
return $ret;
}
function smarty_function_state_options($params, &$smarty){
global $db;
$ret='';
$state=db_getStateByCode($country, $state_code);
$states=db_getStatesForCountry($country, 1);
foreach ($states as $c=>$t) {
$sel = ($c == $params['selected']) ? 'selected="selected"' : '';
$ret .= "\n";
}
return $ret;
}
function smarty_function_lookup_country($params, &$smarty){
$d = & amDb();
return $d->selectCell("SELECT title FROM ?_countries WHERE country=?", $params['key']);
}
function smarty_function_lookup_state($params, &$smarty){
$d = & amDb();
return $d->selectCell("SELECT title FROM ?_states WHERE country=? and state=?", $params['country'], $params['key']);
}
/**
* @return relative URL path to Root URL with slash included if needed
* It is calculated based on location of file relative to root_dir
* If called not from a file within aMember root, root_surl will be
* returned
*/
function smarty_function_root_url($params, &$smarty){
$rd = ROOT_DIR;
$fn = normalizePath(dirname(array_shift(get_included_files()))); // filename of the script
if (($c = strpos($fn, $rd)) === FALSE)
return amConfig('root_surl');
$fn = substr($fn, $c + strlen($rd)+1);
if ($fn == '') return '';
$fnn = '';
foreach (explode('/', $fn) as $f)
$fnn .= '../';
return $fnn;
}
function new_smarty(){
global $config;
static $has_templates_c;
$tc = ROOT_DIR . '/templates_c/';
if (!isset($has_templates_c)){
$has_templates_c = is_dir($tc) && is_writable($tc) && file_exists("$tc/.htaccess");
}
require_once($config['root_dir'].'/smarty/Smarty.class.php');
if (!$has_templates_c){
require_once($config['root_dir'].'/smarty/SmartyNoWrite.class.php');
$t = new _SmartyNoWrite();
$t->force_compile = 1;
$t->compile_check = 1;
} else {
$t = new _Smarty;
$t->compile_check = 1;
}
$t->register_prefilter('smarty_prefilter_literal_script');
$t->register_prefilter('smarty_prefilter_literal_style');
require_once $t->_get_plugin_filepath('shared','make_timestamp');
$t->register_modifier('amember_date_format', 'smarty_modifier_amember_date_format');
$t->register_outputfilter('smarty_outputfilter_put_config');
$t->register_outputfilter('smarty_outputfilter_put_lang');
$t->register_outputfilter('smarty_outputfilter_literal_cleanup');
$t->register_outputfilter('amember_filter_output');
$t->register_function('country_options', 'smarty_function_country_options');
$t->register_function('state_options', 'smarty_function_state_options');
$t->register_function('lookup_country', 'smarty_function_lookup_country');
$t->register_function('lookup_state', 'smarty_function_lookup_state');
$t->register_function('root_url', 'smarty_function_root_url');
$t->template_dir = ROOT_DIR . "/templates";
$t->compile_dir = ROOT_DIR . "/templates_c";
$t->register_resource("memory", array("memory_get_template",
"memory_get_timestamp",
"memory_get_secure",
"memory_get_trusted"));
$t->assign('config', $config);
return $t;
}
/**
* Check email using regexes
* @param string email
* @return bool true if email valid, false if not
*/
function check_email($email) {
#characters allowed on name: 0-9a-Z-._ on host: 0-9a-Z-. on between: @
if (!preg_match('/^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/', $email))
return false;
#must start or end with alpha or num
if ( preg_match('/^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/', $email))
return false;
#name must end with alpha or num
if (!preg_match('/([0-9a-zA-Z_]{1})\@./',$email) )
return false;
#host must start with alpha or num
if (!preg_match('/.\@([0-9a-zA-Z_]{1})/',$email) )
return false;
#pair .- or -. or -- or .. not allowed
if ( preg_match('/.\.\-.|.\-\..|.\.\..|.\-\-./',$email) )
return false;
#pair ._ or -_ or _. or _- not allowed
// if ( preg_match('/.\._.|.-_.|._\..|._-./',$email) )
// return false;
#host must end with '.' plus 2-6 alpha for TopLevelDomain
if (!preg_match('/\.([a-zA-Z]{2,6})$/',$email) )
return false;
return true;
}
/**
* Retrieve input vars, trim spaces and return as array
* @return array array of input vars (_POST / _GET)
*
*/
function get_input_vars(){
$vars = $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET;
am_filter_input_var($vars, '');
return $vars;
}
function am_filter_input_var(&$s, $key){
if (is_array($s)){
array_walk($s, 'am_filter_input_var') ;
} else {
$s = trim($s);
if (get_magic_quotes_gpc())
$s = stripslashes($s);
}
}
/**
* Display fatal error to user.
* Should send mail and save log (not implemented yet)
* Exit current script
* return bool should never return
*/
function fatal_error($error, $log_error=1, $is_html=0){
global $config, $db;
global $in_fatal_error; //!
$in_fatal_error++;
if ($in_fatal_error > 2){
die("
fatal_error called twice");
}
$display_error = $error;
if (defined('AM_DEBUG')){
$display_error .=
"
" .
print_r(debug_backtrace(), true) .
"";
}
$t = & new_smarty();
$t->assign('is_html', $is_html);
$t->assign('error', $display_error);
$t->assign('admin_email', $config['admin_email']);
$t->display("fatal_error.html");
// log error
if ($log_error && is_object($db))
$db->log_error($error);
exit();
}
/**
* Load URL
* if post specified, will be POST, if not, will be GET request
* return string with result of fetch
*/
function get_url($url, $post='', $add_referer=0, $no_proxy=0){
global $db, $config;
if (extension_loaded("curl")){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if ($post) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($add_referer)
curl_setopt($ch, CURLOPT_REFERER, "$config[root_surl]/signup.php");
/*
if(!$no_proxy)
if (strpos($db->config['host'], ".secureserver.net") > 0){
//use GoDaddy proxy
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
*/
$buffer = curl_exec($ch);
if(curl_errno($ch))$db->log_error("CURL ERROR: (".curl_errno($ch).") - ".curl_error($ch));
curl_close($ch);
return $buffer;
} else {
$curl = $config['curl'];
if (!strlen($curl)) {
$db->log_error("cURL path is not set - cc transaction cannot be completed");
return;
}
$params = "";
if ($add_referer){
$params .= " -e ". escapeshellarg($config['root_surl']."/signup.php");
}
if (substr(php_uname(), 0, 7) == "Windows") {
if ($post)
$ret = `$curl $params -d "$post" "$url"`;
else
$ret = `$curl $params "$url"`;
} else {
$url = escapeshellarg($url);
$post = escapeshellarg($post);
if ($post)
$ret = `$curl $params -d $post $url`;
else
$ret = `$curl $params $url`;
}
return $ret;
}
}
///////////////// smarty resource //////////////////////////////////
function memory_get_template($tpl_name, &$tpl_source, &$smarty){
global $_AMEMBER_TEMPLATE;
if (isset($_AMEMBER_TEMPLATE[$tpl_name])){
$tpl_source = $GLOBALS['_AMEMBER_TEMPLATE'][$tpl_name];
return true;
} else {
return false;
}
}
function memory_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
{
global $_AMEMBER_TEMPLATE;
if (isset($_AMEMBER_TEMPLATE[$tpl_name])){
$tpl_timestamp = time();
return true;
} else {
return false;
}
}
function memory_get_secure($tpl_name, &$smarty){ return true; }
function memory_get_trusted($tpl_name, &$smarty){ }
function set_date_from_smarty($prefix, &$vars){
return $vars[$prefix] = sprintf('%04d-%02d-%02d',
$vars[$prefix. 'Year'],
$vars[$prefix. 'Month'],
$vars[$prefix. 'Day']
);
}
function mail_signup_user($member_id){
global $db, $config;
$u = $db->get_user($member_id);
$pl = $db->get_user_payments($u['member_id'], 1);
$u['name'] = $u['name_f'] . ' ' . $u['name_l'];
////////////
$t = new_smarty();
$t->assign('login', $u['login']);
$t->assign('pass', $u['pass']);
$t->assign('name_f', $u['name_f']);
$t->assign('name_l', $u['name_l']);
$t->assign('user', $u);
$t->assign('payment', $pl[0]);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "send_signup_mail";
$et->product_id = $pl[0]['product_id'] ? $pl[0]['product_id'] : null;
mail_template_user($t, $et, $u);
}
function mail_signup_affiliate($member_id){
global $db, $config;
$u = $db->get_user($member_id);
$u['name'] = $u['name_f'] . ' ' . $u['name_l'];
////////////
$t = new_smarty();
$t->assign('login', $u['login']);
$t->assign('pass', $u['pass']);
$t->assign('name_f', $u['name_f']);
$t->assign('name_l', $u['name_l']);
$t->assign('user', $u);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "aff.mail_signup_user";
mail_template_user($t, $et, $u);
}
function mail_pending_user($member_id, $payment_id){
global $db, $config;
$t = & new_smarty();
$p = $db->get_payment($payment_id);
$u = $db->get_user($member_id);
///////////////////////////////////
$t->assign('login', $u['login']);
$t->assign('pass', $u['pass']);
$t->assign('name_f', $u['name_f']);
$t->assign('name_l', $u['name_l']);
///////////////////////////////////
$t->assign('user', $u);
$t->assign('payment', $p);
///////////////////////////////////
if (!($prices = $p['data'][0]['BASKET_PRICES'])){
$prices = array($p['product_id'] => $p['amount']);
}
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$v['price'] = $price;
$pr[$product_id] = $v;
}
$t->assign('total', $total = array_sum($prices));
$t->assign('products', $pr);
///
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "send_pending_email";
mail_template_user($t, $et, $u);
}
function mail_pending_admin($member_id, $payment_id){
global $db, $config;
$t = & new_smarty();
$p = $db->get_payment($payment_id);
$u = $db->get_user($member_id);
///////////////////////////////////
$t->assign('login', $u['login']);
$t->assign('pass', $u['pass']);
$t->assign('name_f', $u['name_f']);
$t->assign('name_l', $u['name_l']);
///////////////////////////////////
$t->assign('user', $u);
$t->assign('payment', $p);
///////////////////////////////////
if (!($prices = $p['data'][0]['BASKET_PRICES'])){
$prices = array($p['product_id'] => $p['amount']);
}
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$v['price'] = $price;
$pr[$product_id] = $v;
}
$t->assign('total', $total = array_sum($prices));
$t->assign('products', $pr);
///
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "send_pending_admin";
mail_template_admin($t, $et);
}
function mail_aff_sale_user($payment_id, $aff_id, $commission, $receipt_id, $product_id){
global $db, $config;
$p = $db->get_payment($payment_id);
$u = $db->get_user($p['member_id']);
$aff = $db->get_user($aff_id);
$pr = $db->get_product($p['product_id']);
///////////////////////////////////
$t = new_smarty();
$t->assign('user', $u);
$t->assign('payment', $p);
$t->assign('affiliate', $aff);
$t->assign('product', $pr);
$t->assign('commission', $commission);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "aff.mail_sale_user";
mail_template_user($t, $et, $aff);
}
function mail_aff_sale_admin($payment_id, $aff_id, $commission, $receipt_id, $product_id){
global $db, $config;
$p = $db->get_payment($payment_id);
$u = $db->get_user($p['member_id']);
$aff = $db->get_user($aff_id);
$pr = $db->get_product($p['product_id']);
///////////////////////////////////
$t = new_smarty();
$t->assign('user', $u);
$t->assign('payment', $p);
$t->assign('affiliate', $aff);
$t->assign('product', $pr);
$t->assign('commission', $commission);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "aff.mail_sale_admin";
mail_template_admin($t, $et);
}
function mail_approval_wait_user($member_id){
global $db, $config;
$t = & new_smarty();
$u = $db->get_user($member_id);
///////////////////////////////////
$t->assign('login', $u['login']);
$t->assign('pass', $u['pass']);
$t->assign('name_f', $u['name_f']);
$t->assign('name_l', $u['name_l']);
///////////////////////////////////
$t->assign('user', $u);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "manually_approve";
mail_template_user($t, $et, $u);
}
function mail_approval_wait_admin($member_id){
global $t, $db, $config;
$u = $db->get_user($member_id);
mail_admin("
New signup completed and is awaiting your approval.
Please login to aMember CP at
$config[root_url]/admin/
Then click the following link:
$config[root_url]/admin/users.php?member_id=$member_id&action=edit
Short details:
Username: $u[login]
E-Mail: $u[email]
Name: $u[name_f] $u[name_l]
--
Your aMember Pro script
$config[root_url]/admin
", "*** Your approval required");
}
function mail_payment_admin($payment_id, $member_id){
global $db, $config;
$t = &new_smarty();
$p = $db->get_payment($payment_id);
$u = $db->get_user($p['member_id']);
$pr = $db->get_product($p['product_id']);
///////////////////////////////////
$t->assign('user', $u);
$t->assign('payment', $p);
$t->assign('product', $pr);
///////////////////////////////////
$et = & new aMemberEmailTemplate();
$et->name = "send_payment_admin";
mail_template_admin($t, $et);
}
function mail_payment_user($payment_id, $member_id){
global $db, $config, $_AMEMBER_TEMPLATE;
$t = new_smarty();
$p = $db->get_payment($payment_id);
if ($p['data'][0]['ORIG_ID'] > 0) return; // don't sent for child payments
if (!($prices = $p['data'][0]['BASKET_PRICES'])){
$prices = array($p['product_id'] => $p['amount']);
}
$u = $db->get_user($p['member_id']);
$subtotal = 0;
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$subtotal += $v['price'];
//$v['price'] = $price;
$pr[$product_id] = $v;
}
if (!$t) $t = &new_smarty();
$total = array_sum($prices);
if ($total == 0) return; // don't email zero receipt
if ($p['receipt_id'] == 'manual'){ // ONLY for single product !!!
$coupon_discount = $p['data']['COUPON_DISCOUNT'];
//$tax_amount = $p['data']['TAX_AMOUNT'];
$tax_amount = $p['tax_amount'];
if ($subtotal - $coupon_discount + $tax_amount != $total){
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$subtotal = $total - $tax_amount + $coupon_discount;
$v['price'] = $subtotal;
$pr[$product_id] = $v;
}
}
}
$t->assign('total', $total);
$t->assign('subtotal', $subtotal);
$t->assign('user', $u);
$t->assign('payment', $p);
$t->assign('products', $pr);
$t->assign('config', $config);
$attachments = array();
if ($config['send_pdf_invoice']){
require_once("$config[root_dir]/includes/fpdf/fpdf.php");
$attachments[] = get_pdf_invoice($payment_id, $p[member_id]);
}
$et = & new aMemberEmailTemplate();
$et->name = "send_payment_mail";
$et->lang = $u['data']['selected_lang'] ? $u['data']['selected_lang'] : get_default_lang();
// load and find templated
if (!$et->find_applicable()){
trigger_error("Cannot find applicable e-mail template for [{$et->name},{$et->lang},{$et->product_id},{$et->day}]", E_USER_WARNING);
return false;
}
$_AMEMBER_TEMPLATE['text'] = $et->get_smarty_template();
$parsed_mail = $t->fetch('memory:text');
unset($_AMEMBER_TEMPLATE['text']);
mail_customer($u['email'], $parsed_mail,
null, null, $attachments, false,
$u['name_f'] . ' ' . $u['name_l']);
}
function get_pdf_invoice($payment_id, $member_id){
global $t, $db, $config;
$p = $db->get_payment($payment_id);
if ($p['member_id'] != $member_id)
return array();
//if ($p['data'][0]['ORIG_ID'] > 0) return array(); // don't sent for child payments
if ($p['data'][0]['ORIG_ID'] > 0)
$p1 = $db->get_payment($p['data'][0]['ORIG_ID']);
if($p['tax_amount']=='0.00' && $p1['tax_amount']>0){
$p['tax_amount'] = $p1['tax_amount'];
$db->update_payment($p['payment_id'], $p);
}
if (!($prices = $p['data'][0]['BASKET_PRICES'])){
$prices = array($p['product_id'] => $p['amount']);
}
$u = $db->get_user($p['member_id']);
$products = array();
$total = 0;
$subtotal = 0;
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$products[$product_id] = $v;
$total += $price;
$subtotal += $v['price'];
}
if (!$t) $t = &new_smarty();
//if ($p['receipt_id'] == 'manual'){ // ONLY for single product !!!
if ($p['receipt_id'] != 'manual'||1){ // ONLY for single product !!!
$coupon_discount = $p['data']['COUPON_DISCOUNT'];
//$tax_amount = $p['data']['TAX_AMOUNT'];
$tax_amount = $p['tax_amount'];
if ($subtotal - $coupon_discount + $tax_amount != $total){
foreach ($prices as $product_id => $price){
$v = $db->get_product($product_id);
$subtotal = $total - $tax_amount + $coupon_discount;
$v['price'] = $subtotal;
$products[$product_id] = $v;
}
}
}
$t->assign('total', $total);
$t->assign('subtotal', $subtotal);
$t->assign('payment', $p);
$t->assign('products', $products);
$content = $t->fetch('mail_receipt.pdf.txt');
$pdf_content = parse_pdf_content ($content, $p['member_id']);
$attach = array();
$attach['string'] = $pdf_content; // use stringEncoded in attachment
$attach['name'] = 'Invoice.pdf';
$attach['type'] = 'application/pdf';
return $attach;
}
function mm_to_pt ($value){ // convert millimeters to points
$value = $value / 25.4; //inch
$value = $value * 72; //pt
return $value;
}
function get_font_styles ($string){ // apply an allowed text formatting tags
$attr = '';
if (preg_match('/(.*)<\/b>/i', $string, $regs)){
$attr .= "B";
$string = $regs[1];
}
if (preg_match('/(.*)<\/i>/i', $string, $regs)){
$attr .= "I";
$string = $regs[1];
}
if (preg_match('/(.*)<\/u>/i', $string, $regs)){
$attr .= "U";
$string = $regs[1];
}
return $attr;
}
function parse_pdf_content ($content, $member_id){ // parse text content from Smarty to pdf content
global $db, $config, $t;
$pdf_content = '';
$margins = array(mm_to_pt(20), mm_to_pt(20), mm_to_pt(20), mm_to_pt(20)); //left, top, right, bottom (in points) 56pt ~= 20mm
$font_size = 14; //points
$pdf = new FPDF('P', 'pt', 'A4'); // portrait, A4
$pdf->SetCompression (false);
$pdf->SetMargins ($margins[0], $margins[1], $margins[2]); //only left, top, right margins. bottom margin equals to 20mm by default.
$pdf->SetTitle ('Your Invoice');
$pdf->SetSubject ('*** Your Payment');
$pdf->SetAuthor ('aMember');
$pdf->AddPage();
$pdf->SetFont('Arial', '', $font_size);
$current_x = $pdf->GetX();
$current_y = $pdf->GetY();
$width = mm_to_pt (210);
$height = mm_to_pt (270);
$width = $width - $margins[0] - $margins[2]; // target width
$height = $height - $margins[1] - $margins[3];// target height
$image = $config['root_dir'] . "/logo.jpg"; // logo path to include in pdf at top-right corner
if (is_file($image)){
$size = getimagesize($image);
$x = $width - $size[0] + $margins[0];
$y = $current_y;
$pdf->Image ($image, $x, $y, $size[0], $size[1]); // use original size
$current_y += $size[1];
}
$current_y += $font_size; //pt
$contacts = explode("\n", $config['invoice_contacts']); // output contact information right-aligned
$max_length = 0;
foreach ($contacts as $row){
$row = trim($row);
$length = $pdf->GetStringWidth ($row);
if ($length > $max_length)
$max_length = $length;
}
$x = $width - $max_length + $margins[0];
$y = $current_y;
foreach ($contacts as $row){
$row = trim($row);
$attr = get_font_styles ($row);
$pdf->SetFont('Arial', $attr, $font_size);
$pdf->Text ($x, $y, strip_tags($row));
$y += $font_size;
}
$current_y = $y;
$pdf->SetFont('Arial', '', $font_size); //return font settings
// customer contacts
$u = $db->get_user($member_id);
if (!$t) $t = &new_smarty();
$t->assign('u', $u);
$cust_contacts = $t->fetch('mail_receipt_contact.pdf.txt');
$cust_contacts = explode("\n", $cust_contacts); // output contact information left-aligned
$num_rows = count($contacts);
$x = $margins[0];
$y = $current_y - $font_size * $num_rows; // $num_rows rows up from contact information and output customer data
foreach ($cust_contacts as $row){
$row = trim($row);
$attr = get_font_styles ($row);
$pdf->SetFont('Arial', $attr, $font_size);
$pdf->Text ($x, $y, strip_tags($row));
$y += $font_size;
}
$current_y = $y;
/*
$y = $current_y - $font_size * 4; // 4 rows up from contact information and output customer data
$string = $u['name_f'] . ' ' . $u['name_l'];
$pdf->Text ($x, $y, $string);
$y += $font_size;
$string = $u['street'];
$pdf->Text ($x, $y, $string);
$y += $font_size;
$string = $u['zip'] . ' ' . $u['city'];
$pdf->Text ($x, $y, $string);
$y += $font_size;
$state = db_getStateByCode($u['country'], $u['state']);
$country = db_getCountryByCode($u['country']);
$string = $state . ' ' . $country;
$pdf->Text ($x, $y, $string);
$y += $font_size;
*/
$current_y = $y + $font_size * 2; //2 rows down
$pdf->SetFont('Arial', '', $font_size); //return font settings
// remove new lines
$content = str_replace ("\n", "", $content);
$content = str_replace ("\r", "", $content);
$content = str_replace ("£", chr(163), $content);
// split text by