public function content() { global $dbh, $postvar, $getvar, $instance; if (main::isint(str_replace("P2H-", "", $getvar['view']))) { //Display the invoice if (substr_count($getvar['view'], "P2H-")) { $p2hid = str_replace("P2H-", "", $getvar['view']); $userid = $dbh->select("users", array("id", "=", $p2hid)); $userid = $userid['id']; $userdata = coupons::admin_userdata($userid); } else { $invoiceid = $getvar['view']; $invoice_data_top = $dbh->select("invoices", array("id", "=", $invoiceid)); $pid = $invoice_data_top['pid']; $userid = $invoice_data_top['uid']; $uidtopack = main::uidtopack($userid, $pid); if (!$pid) { $dbh->update("invoices", array("pid" => $uidtopack['pid']), array("id", "=", $invoice_data_top['id'])); } $userdata = coupons::admin_userdata($userid); } if ($_POST['submitaddcoupon']) { if (!$postvar['addcoupon']) { main::errors("Please enter a coupon code."); } else { $coupcode = $postvar['addcoupon']; $user = main::uname($userid); $pack_data = main::uidtopack($userid, $pid); $packid = $pack_data['packages']['id']; $multi_coupons = $dbh->config("multicoupons"); if ($p2hid) { $monthly = $pack_data['additional']['monthly']; $monthly = coupons::get_discount("p2hmonthly", $monthly, $userid); $total_posted = coupons::totalposts($userid); $amt_owed = max(0, $monthly - $total_posted); } else { $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid)); if ($invoice_info['pid'] != $pack_data['pid']) { $pack_data = upgrade::pidtobak($invoice_info['pid'], $invoice_info["uid"]); } $total_paid = coupons::totalpaid($invoiceid); $amt_owed = max(0, $invoice_info['amount'] - $total_paid); } if ($amt_owed == 0) { main::errors("The user's balance is already paid in full, so you can't add another coupon."); } else { $coupon_info = coupons::coupon_data($coupcode); $coupid = $coupon_info['id']; $use_coupon = coupons::use_coupon($coupid, $packid, $invoiceid, $userid); if (!$use_coupon) { if (!$multi_coupons) { main::errors("Coupon code entered was invalid or user is already using a coupon. You can give them a credit instead."); } else { main::errors("Coupon code entered was invalid or the user is already using this coupon."); } } else { main::redirect("?page=invoices&view=" . $getvar['view']); } } } } if ($_POST['submitcredit']) { $postvar['credit'] = str_replace(array(" ", ","), array("", "."), $postvar['credit']); if (!is_numeric($postvar['credit'])) { main::errors("Please enter the amount to be credited or debited."); } else { if ($postvar['creditreason']) { $creditreason = $postvar['creditreason']; $creditreason = ' <a title="' . $creditreason . '" class="tooltip"><img src="<URL>themes/icons/information.png"></a>'; $creditreason = str_replace(",", "", $creditreason); //Can't have commas, no way no how! ;) lol We need to be able to explode(",", $invoice_info['txn']); } if ($p2hid) { $credit_fee = $postvar['credit']; } else { $credit_fee = main::addzeros($postvar['credit']); } if ($credit_fee != 0) { if (substr_count($credit_fee, "-")) { $creditfee_lable = "CHARGE"; } else { $creditfee_lable = "CREDIT"; } $packinfo = main::uidtopack($userid, $pid); if (!$packinfo['user_data']['pid'] && !$p2hid) { $packinfo = upgrade::pidtobak($pid, $userid); } $monthly = $packinfo['additional']['monthly']; if ($p2hid) { $amt_owed = max(0, $monthly - coupons::totalposts($userid)); } else { $amt_owed = max(0, $monthly - coupons::totalpaid($invoiceid)); } if ($amt_owed == 0 && $creditfee_lable == "CREDIT") { main::errors("The user's balance is already paid in full, so you can't add a credit."); } else { if ($p2hid) { $p2h_info = $dbh->select("coupons_p2h", array("uid", "=", $userid)); if ($p2h_info['datepaid']) { $comma = ","; } $datepaid = $p2h_info['datepaid'] . $comma . time(); $txn = $p2h_info['txn'] . $comma . $creditfee_lable . $creditreason; $amt_paid = $p2h_info['amt_paid'] . $comma . $credit_fee; $gateway = $p2h_info['gateway'] . $comma . "INTERNAL"; $update_coupons_p2h = array("datepaid" => $datepaid, "txn" => $txn, "amt_paid" => $amt_paid, "gateway" => $gateway); $dbh->update("coupons_p2h", $update_coupons_p2h, array("uid", "=", $userid), "1"); } else { $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid)); if ($invoice_info['pid'] != $packinfo['pid']) { $pack_info = upgrade::pidtobak($invoice_info['pid'], $invoice_info["uid"]); } if ($invoice_info['datepaid']) { $comma = ","; } $datepaid = $invoice_info['datepaid'] . $comma . time(); $txn = $invoice_info['txn'] . $comma . $creditfee_lable . $creditreason; $amt_paid = $invoice_info['amt_paid'] . $comma . $credit_fee; $gateway = $invoice_info['gateway'] . $comma . "INTERNAL"; $update_invoices = array("datepaid" => $datepaid, "txn" => $txn, "amt_paid" => $amt_paid, "gateway" => $gateway); $dbh->update("invoices", $update_invoices, array("id", "=", $invoiceid), "1"); } main::redirect("?page=invoices&view=" . $getvar['view']); } } } } if ($_POST['submitpayarrange']) { $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid)); $duedate = $invoice_info['due']; $days_modify = $postvar['days']; $days_modify = $days_modify * 24 * 60 * 60; if ($postvar['addsub'] == "add") { $new_due_date = $duedate + $days_modify; } else { $new_due_date = $duedate - $days_modify; } $dbh->update("invoices", array("due" => $new_due_date), array("id", "=", $invoiceid), "1"); main::redirect("?page=invoices&view=" . $getvar['view']); } if ($p2hid) { $p2h_info = $dbh->select("users", array("id", "=", $p2hid)); } else { $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid)); } if (empty($invoice_info) && empty($p2h_info)) { main::redirect("?page=invoices"); exit; } if ($getvar['deleteinv']) { if ($postvar['yes']) { if ($p2hid) { $dbh->delete("coupons_p2h", array("uid", "=", $userid), "1"); main::redirect("?page=invoices&view=" . $getvar['view']); } else { $dbh->delete("invoices", array("id", "=", $invoiceid), "1"); main::redirect("?page=invoices"); } } elseif ($postvar['no']) { main::redirect("?page=invoices&view=" . $getvar['view']); } else { $warning_array['HIDDEN'] = "<input type = 'hidden' name = 'confirm' value = 'confirm'>"; echo style::replaceVar("tpl/warning.tpl", $warning_array); $warning_page = '1'; } } if ($userdata['removed'] == 1) { $upackage = $dbh->select("users_bak", array("id", "=", $userid)); } else { $upackage = $dbh->select("users", array("id", "=", $userid)); } if (!$p2hid) { $package = $dbh->select("packages", array("id", "=", $invoice_info['pid'])); } else { $package = $dbh->select("packages", array("id", "=", $upackage['pid'])); } $monthly = type::additional($package['id']); $subtotal = $monthly['monthly']; if (is_numeric($getvar['remove'])) { $remove_id = $getvar['remove']; if ($p2hid) { coupons::remove_p2h_coupon($remove_id, $userid); } else { coupons::remove_coupon($remove_id, $package['id'], $invoice_info['id'], $userid); } main::redirect("?page=invoices&view=" . $getvar['view']); exit; } if ($p2hid) { $due = date("m/t/Y"); $created = date("m/1/Y"); $p2h = $instance->packtypes["p2h"]; $monthly_with_disc = coupons::get_discount("p2hmonthly", $subtotal, $userid); $total_posts = $p2h->userposts($package['id'], $p2hid); $total_paid = coupons::totalposts($userid); if (empty($total_paid)) { $total_paid = 0; } if (empty($total_posts)) { $total_posts = 0; } $acct_balance = max(0, $monthly_with_disc - $total_paid); $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::s($invoice_info['amount'], " Post") . " (Package price: " . main::s($subtotal, " Post") . ")" : main::s($invoice_info['amount'], " Post"); $view_invoice_array['COUPONTOTAL'] = main::s($subtotal - $monthly_with_disc, " Post"); $invoice_transactions_array['TOTALAMOUNT'] = main::s($acct_balance, " Post"); $invoice_transactions_array['TOTALPAID'] = main::s($total_paid, " Post"); $admin_ops_array['TOTALAMT'] = main::s($acct_balance, " Post"); $admin_ops_array['DELRESET'] = "Reset"; $admin_ops_modify_array['CREDIT'] = $acct_balance; $admin_ops_modify_array['CURRSYMBOL'] = ""; $admin_ops_modify_array['POSTS'] = " Posts"; } else { $created = $invoice_info['created']; $thirty_days = 30 * 24 * 60 * 60; $orig_due = $created + $thirty_days; if ($getvar['resetpayarange']) { $dbh->update("invoices", array("due" => $orig_due), array("id", "=", $invoiceid), "1"); main::redirect("?page=invoices&view=" . $invoiceid); } if (main::convertdate("n/d/Y", $invoice_info['due']) != main::convertdate("n/d/Y", $created + $thirty_days)) { $due_text = " (Originally " . main::convertdate("n/d/Y", $orig_due) . ") - <a href = '?page=invoices&view=" . $invoiceid . "&resetpayarange=1'>Reset</a>"; } $due = main::convertdate("n/d/Y", $invoice_info['due']); $created = main::convertdate("n/d/Y", $created); $total_paid_real = coupons::totalpaid($invoiceid); if ($total_paid_real < 0) { $total_paid = "0.00"; } else { $total_paid = $total_paid_real; } $acct_balance = $invoice_info['amount'] - $total_paid_real; $acct_balance = main::addzeros($acct_balance); if ($acct_balance < 0) { $acct_balance = "0.00"; } if ($acct_balance == 0 && $invoice_info['is_paid'] == '0') { $dbh->update("invoices", array("is_paid" => "1"), array("id", "=", $invoice_info['id']), "1"); unset($where); $where[] = array("id", "=", $invoice_info['uid'], "AND"); $where[] = array("status", "=", "4"); $dbh->update("users", array("status" => "1"), $where, "1"); unset($where); $where[] = array("id", "=", $invoice_info['uid'], "AND"); $where[] = array("status", "=", "4"); $dbh->update("users", array("status" => "1"), $where, "1"); main::redirect("?page=invoices&view=" . $invoiceid); } if ($acct_balance > 0 && $invoice_info['is_paid'] == '1') { $dbh->update("invoices", array("is_paid" => "0"), array("id", "=", $invoice_info['id']), "1"); main::redirect("?page=invoices&view=" . $invoiceid); } $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::money($invoice_info['amount']) . " (Package price: " . main::money($subtotal) . ")" : main::money($invoice_info['amount']); $view_invoice_array['COUPONTOTAL'] = main::money($subtotal - coupons::get_discount("paid", $subtotal, $userid)); $invoice_transactions_array['TOTALAMOUNT'] = main::money($acct_balance); $invoice_transactions_array['TOTALPAID'] = main::money($total_paid); $admin_ops_array['TOTALAMT'] = main::money($acct_balance); $admin_ops_array['DELRESET'] = "Delete"; $admin_ops_modify_array['CREDIT'] = $acct_balance; $admin_ops_modify_array['CURRSYMBOL'] = main::money($acct_balance, "", 1) . " "; $admin_ops_modify_array['POSTS'] = ""; } $view_invoice_array['ID'] = $getvar['view']; $view_invoice_array['DUE'] = $due . $due_text; $view_invoice_array['PACKDUE'] = $due; $view_invoice_array['CREATED'] = $created; $view_invoice_array['UNAME'] = $userdata['user']; $view_invoice_array['FNAME'] = $userdata['firstname']; $view_invoice_array['LNAME'] = $userdata['lastname']; $view_invoice_array['ADDRESS'] = $userdata['address']; $view_invoice_array['CITY'] = $userdata['city']; $view_invoice_array['STATE'] = $userdata['state']; $view_invoice_array['ZIP'] = $userdata['zip']; $view_invoice_array['COUNTRY'] = strtoupper($userdata['country']); $view_invoice_array['DOMAIN'] = $upackage['domain']; $view_invoice_array['PACKAGE'] = $package['name']; $view_invoice_array['STATUS'] = $acct_balance == 0 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>"; if ($invoice_info['changed_plan'] && $invoice_info['hadcoupons']) { $coupon_list = explode(",", $invoice_info['hadcoupons']); $coupon_values = explode(",", $invoice_info['couponvals']); if ($coupon_list) { for ($i = 0; $i < count($coupon_list); $i++) { $coupons_list_array['COUPONAMOUNT'] = main::money($coupon_values[$i]); $coupons_list_array['COUPCODE'] = $coupon_list[$i]; $coupons_list_array['REMOVE'] = ""; $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array); $coup_total = $coup_total + $coupon_values[$i]; } $view_invoice_array['COUPONTOTAL'] = main::money(min($subtotal, $coup_total)); } } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_query = $dbh->select("coupons_used", $where, array("id", "ASC"), 0, 1); while ($coupons_used_fetch = $dbh->fetch_array($coupons_query)) { $valid_coupon = coupons::check_expire($coupons_used_fetch['coupcode'], $userid); if ($valid_coupon) { if ($p2hid) { $coupamt = main::s($coupons_used_fetch['p2hmonthlydisc'], " Post"); } else { $coupamt = main::money($coupons_used_fetch['paiddisc']); } $coupons_list_array['COUPONAMOUNT'] = $coupamt; $coupons_list_array['COUPCODE'] = $coupons_used_fetch['coupcode']; $coupons_list_array['REMOVE'] = $userdata['removed'] == 1 ? "" : '(<a href = "?page=invoices&view=' . $getvar['view'] . '&remove=' . $coupons_used_fetch['id'] . '">Remove</a>)'; $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array); } } } if (!$view_invoice_array['COUPONSLIST']) { $view_invoice_array['COUPONSLIST'] = "<tr><td></td><td align = 'center'>None</td></tr>"; } if ($p2hid) { $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid)); $package_info = main::uidtopack($userid); if (empty($p2h_payments)) { $p2h_pay_array = array("uid" => $userid, "amt_paid" => $total_posts, "txn" => $package_info['uadditional']['fuser'], "datepaid" => time(), "gateway" => $package_info['additional']['forum']); $dbh->insert("coupons_p2h", $p2h_pay_array); $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid)); } $amt_paid = $p2h_payments['amt_paid']; $txn = $p2h_payments['txn']; $datepaid = $p2h_payments['datepaid']; $gateway = $p2h_payments['gateway']; } else { $amt_paid = $invoice_info['amt_paid']; $txn = $invoice_info['txn']; $datepaid = $invoice_info['datepaid']; $gateway = $invoice_info['gateway']; } $amt_paid = explode(",", $amt_paid); $txn = explode(",", $txn); $datepaid = explode(",", $datepaid); $gateway = explode(",", $gateway); $remnum = 1; for ($i = 0; $i < count($amt_paid); $i++) { unset($remtxn); if ($gateway[$i] == "INTERNAL" && !$userdata['removed']) { $remtxn = ' <a href = "?page=invoices&view=' . $getvar['view'] . '&remtxn=' . $remnum . '">[Delete]</a>'; } if ($txn[$i] == $package_info['uadditional']['fuser']) { if ($amt_paid[$i] != $total_posts) { $reload = 1; } $amt_paid[$i] = $total_posts; $datepaid[$i] = time(); } $paid_this = $paid_this + $amt_paid[$i]; if ($p2hid) { $transaction_list_array['PAIDAMOUNT'] = main::s(str_replace("-", "−", $amt_paid[$i]), " Post") . $remtxn; } else { $transaction_list_array['PAIDAMOUNT'] = main::money($amt_paid[$i]) . $remtxn; } $transaction_list_array['TXN'] = $txn[$i]; $transaction_list_array['PAIDDATE'] = main::convertdate("n/d/Y", $datepaid[$i]); $transaction_list_array['GATEWAY'] = $gateway[$i]; $invoice_transactions_array['TXNS'] .= style::replaceVar("tpl/invoices/transaction-list.tpl", $transaction_list_array); if ($getvar['remtxn'] != $i + 1) { $paidamts = $paidamts . "," . $amt_paid[$i]; $paidtxn = $paidtxn . "," . $txn[$i]; $paiddate = $paiddate . "," . $datepaid[$i]; $paidgateway = $paidgateway . "," . $gateway[$i]; } $remnum++; } if ($p2hid) { $paidamts = substr($paidamts, 1, strlen($paidamts)); $paidtxn = substr($paidtxn, 1, strlen($paidtxn)); $paiddate = substr($paiddate, 1, strlen($paiddate)); $paidgateway = substr($paidgateway, 1, strlen($paidgateway)); $p2h_pay_array = array("amt_paid" => $paidamts, "txn" => $paidtxn, "datepaid" => $paiddate, "gateway" => $paidgateway); unset($where); $where[] = array("uid", "=", $userid); $dbh->update("coupons_p2h", $p2h_pay_array, $where); if ($getvar['remtxn'] || $reload) { main::redirect("?page=invoices&view=" . $getvar['view']); } } else { if ($getvar['remtxn']) { $paidamts = substr($paidamts, 1, strlen($paidamts)); $paidtxn = substr($paidtxn, 1, strlen($paidtxn)); $paiddate = substr($paiddate, 1, strlen($paiddate)); $paidgateway = substr($paidgateway, 1, strlen($paidgateway)); $update_invoices = array("amt_paid" => $paidamts, "txn" => $paidtxn, "datepaid" => $paiddate, "gateway" => $paidgateway); $dbh->update("invoices", $update_invoices, array("id", "=", $invoiceid), "1"); main::redirect("?page=invoices&view=" . $invoiceid); } } if ($invoice_info['amt_paid'] || $p2hid) { $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array); } $addsub[] = array("Add", "add"); $addsub[] = array("Subtract", "subtract"); $days[] = array("1 Day", "1"); for ($num = 2; $num < 31; $num++) { $days[] = array($num . " Days", $num); } $payment_arrangments_array['ADDSUB'] = main::dropDown("addsub", $addsub, "add", 0); $payment_arrangments_array['DAYS'] = main::dropDown("days", $days, 1, 0); if ($userdata['removed'] == 1) { $admin_ops_array['MODIFYFUNCS'] = ' <tr> <td align="center" colspan = "2"><font color = "#FF0055"><strong>The owner of this invoice has been dismembered. Er... I mean the member who owned this invoice has been removed.</strong></font></td> </tr>'; } else { if (!$p2hid) { $admin_ops_modify_array['PAYARRANGE'] = style::replaceVar("tpl/admin/invoices/payment-arrangments.tpl", $payment_arrangments_array); } else { $admin_ops_modify_array['PAYARRANGE'] = ""; } $admin_ops_array['MODIFYFUNCS'] = style::replaceVar("tpl/admin/invoices/admin-ops-modify.tpl", $admin_ops_modify_array); if ($invoice_info['changed_plan']) { $admin_ops_array['MODIFYFUNCS'] .= ' <tr> <td align="center" colspan = "2"><font color = "#FF0055"><strong>The owner of this invoice has upgraded their account and this is an invoice from an old account.</strong></font></td> </tr>'; } } $view_invoice_array['TRANSACTIONS'] .= style::replaceVar("tpl/admin/invoices/admin-ops.tpl", $admin_ops_array); if (!$warning_page) { echo style::replaceVar("tpl/invoices/view-invoice.tpl", $view_invoice_array); } } else { //Display the invoice list //Status search $showstatus = "all"; if ($postvar['submitstatus']) { $showstatus = $postvar['status']; } //End ststus search //Type search $showtype = "all"; if ($postvar['submittype']) { $showtype = $postvar['invtype']; } //End type search $users[] = array("All", "all"); $users[] = array("Orphans", "orphans"); $users_query = $dbh->select("users", 0, array("user", "ASC")); while ($users_data = $dbh->fetch_array($users_query)) { $users[] = array($users_data['user'], $users_data['id']); } //User search $users_default = "all"; if ($postvar['submitusers']) { $users_default = $postvar['users']; if ($users_default != "all" && $users_default != "orphans") { $show_user = array("uid", "=", $users_default); $show_p2h_user_where = array("id", "=", $users_default, "AND"); $username = main::uname($users_default); $for_user = "******" . $username; } } //End user search $num_invoices = 0; $num_paid = 0; $num_unpaid = 0; $total_unpaid = 0; if ($showtype == "all" || $showtype == "p2h") { $p2h_query = $dbh->select("packages", array("type", "=", "p2h"), 0, 0, 1); while ($p2h_data = $dbh->fetch_array($p2h_query)) { $show_p2h_user_where[] = array("pid", "=", $p2h_data['id']); $user_query = $dbh->select("users", $show_p2h_user_where, 0, 0, 1); while ($user_data = $dbh->fetch_array($user_query)) { unset($user_show); unset($orphaned); $user_show = main::uname($user_data["id"]); if (!$user_show) { $user_show = '<font color = "FF0055">ORPHANED</font>'; $orphaned = 1; } if ($orphaned && $users_default == "orphans" || $users_default != "orphans") { $pack_info = main::uidtopack($user_data['id']); $p2h = $instance->packtypes["p2h"]; $monthly = $pack_info['additional']['monthly']; $monthly_with_disc = coupons::get_discount("p2hmonthly", $monthly, $user_data['id']); $userposts = coupons::totalposts($user_data['id']); $invoice_list_item_array['ID'] = "P2H-" . $user_data['id']; $invoice_list_item_array['USERFIELD'] = '<td width="100" align="center">' . $user_show . '</td>'; $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", mktime(date("H"), date("i"), date("s"), date("n"), date("t"), date("Y"))); $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", mktime(date("H"), date("i"), date("s"), date("n"), 1, date("Y"))); $invoice_list_item_array['AMOUNT'] = main::s($monthly, " Post"); $invoice_list_item_array['AMTPAID'] = main::s($userposts, " Post"); if ($showstatus == "unpaid" || $showstatus == "all") { if ($monthly_with_disc - $userposts > 0) { $pulled = 1; $invoice_list_item_array["PAID"] = "<font color = '#FF7800'>Unpaid</font>"; $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array); } } if ($showstatus == "paid" || $showstatus == "all" && !$pulled) { if ($monthly_with_disc - $userposts <= 0) { $invoice_list_item_array["PAID"] = "<font color = '#779500'>Paid</font>"; $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array); } } if ($monthly_with_disc - $userposts > 0) { $total_unpaid = $total_unpaid + 1; } $pulled = 0; $num_invoices = $num_invoices + 1; } } } } if ($showtype == "all" || $showtype == "paid") { $invoices_query = $dbh->select("invoices", $show_user, array("id", "DESC"), 0, 1); while ($invoices_data = $dbh->fetch_array($invoices_query)) { unset($user_show); unset($orphaned); unset($invoice_locked); $user_show = main::uname($invoices_data["uid"]); if (!$user_show) { $user_show = '<font color = "FF0055">ORPHANED</font>'; $orphaned = 1; } if ($orphaned && $users_default == "orphans" || $users_default != "orphans") { $pack_info = main::uidtopack($invoices_data["uid"], $invoices_data['pid']); if (!$invoices_data['pid']) { $dbh->update("invoices", array("pid" => $pack_info['user_data']['pid']), array("id", "=", $invoices_data['id'])); $invoices_data['pid'] = $pack_info['user_data']['pid']; } if ($invoices_data['pid'] != $pack_info['user_data']['pid']) { $pack_info = upgrade::pidtobak($invoices_data['pid'], $invoices_data["uid"]); } $invoice_list_item_array['ID'] = $invoices_data['id']; $invoice_list_item_array['USERFIELD'] = '<td width="100" align="center">' . $user_show . '</td>'; $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", $invoices_data['due']); $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", $invoices_data['created']); $total_paid_real = coupons::totalpaid($invoices_data['id']); $invoice_list_item_array['AMOUNT'] = main::money($invoices_data['amount']); $invoice_list_item_array['AMTPAID'] = main::money($total_paid_real); if ($showstatus == "unpaid" || $showstatus == "all") { if ($invoices_data["is_paid"] == 0) { $pulled = 1; $invoice_list_item_array["PAID"] = "<font color = '#FF7800'>Unpaid</font>" . $invoice_locked; $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array); } } if ($showstatus == "paid" || $showstatus == "all" && !$pulled) { if ($invoices_data["is_paid"] == 1) { $invoice_list_item_array["PAID"] = "<font color = '#779500'>Paid</font>" . $invoice_locked; $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array); } } if ($invoices_data["is_paid"] == 0) { $total_unpaid = $total_unpaid + 1; } $pulled = 0; $num_invoices = $num_invoices + 1; } } } if (!$admin_page_array['LIST']) { $admin_page_array['LIST'] = "<tr>\n<td colspan = '7' align = 'center'>There are not currently any invoices to show.</td>\n</tr>"; } $statusopts[] = array("All", "all"); $statusopts[] = array("Unpaid", "unpaid"); $statusopts[] = array("Paid", "paid"); $typeopts[] = array("All", "all"); $typeopts[] = array("P2H", "p2h"); $typeopts[] = array("Paid", "paid"); $admin_page_array['USERS'] = main::dropDown("users", $users, $users_default, 0); $admin_page_array['TYPEOPTS'] = main::dropDown("invtype", $typeopts, $showtype, 0); $admin_page_array['STATUSOPTS'] = main::dropDown("status", $statusopts, $showstatus, 0); $admin_page_array['FORUSER'] = $for_user; $admin_page_array['NUM'] = $num_invoices; $admin_page_array['NUMPAID'] = $num_invoices - $total_unpaid; $admin_page_array['NUMUNPAID'] = $total_unpaid; echo style::replaceVar("tpl/admin/invoices/admin-page.tpl", $admin_page_array); } }
$update ? $user->confirmCourses($courseIds) : $user->addCourses($courseIds, 'student', $activate); } if ($credit) { $user->user['balance'] += $credit; $user->persist(); } } if ($_POST['payment_status'] == 'Pending') { $reason = $_POST['pending_reason']; //for notification } $fields = array("amount" => $_POST['mc_gross'], "timestamp" => time(), "method" => "paypal", "status" => $paymentStatus, "txn_id" => $_POST['txn_id'], "users_LOGIN" => $_POST['custom'], "charset" => $_POST['charset'], "comments" => $responseText, "lessons" => $lessonIds, "courses" => $courseIds); if (!isset($processedPayments[$_POST['txn_id']])) { $payment = payments::create($fields); if ($couponIds) { $coupon = new coupons($couponIds); is_array($lessonIds) or $lessonIds = array(); is_array($courseIds) or $courseIds = array(); $coupon->useCoupon($user, $payment, array('lessons' => $lessonIds, 'courses' => $courseIds)); } } else { $result = eF_getTableData("payments", "id", "txn_id='" . $_POST['txn_id'] . "'"); $payment = new payments($result[0]['id']); $payment->payments = array_merge($payment->payments, $fields); $payment->persist(); } } else { if (strcmp($res, "INVALID") == 0) { $responseText = ''; foreach ($_POST as $key => $value) { $responseText .= $key . " = " . $value . "\n";
public function couponcheck() { global $dbh, $postvar, $getvar, $instance; if (empty($getvar['coupon'])) { echo 1; return; } else { $package_type = type::packagetype($getvar['package']); if ($package_type == "free") { echo 0; return; } $coupon_text = coupons::validate_coupon($getvar['coupon'], $getvar['location'], $getvar['username'], $getvar['package']); if ($coupon_text) { echo $coupon_text; return; } else { echo 0; return; } } }
private function getMonthly($id, $user = "") { $type_additional = type::additional($id); if (!$user) { $user = $_SESSION['cuser']; } if (!is_numeric($user)) { $user = main::userid($user); } $type_additional['monthly'] = coupons::get_discount("p2hmonthly", $type_additional['monthly'], $user); return $type_additional['monthly']; }
public function do_upgrade($upgradeid, $mode, $no_errors_out = 0) { global $dbh, $postvar, $getvar, $instance; //$mode // //Init - When the upgrade info is added, we call this function. //Update - When cron or an admin does something with this function, we check to see if various tasks are ready to be performed. //Flag meaning: // //IMMEDIATE UPGRADE FLAGS // //0 - Upgrade is immediate. //5 - If admin approves the upgrade, then the upgrade will be immediate. // //6 - If admin approves the upgrade, then the new account will be created on the new server and the // admin will know that they are moving to a new server so they can manually close the old account // when they're ready. // //7 - The new account on the new server will be immediately created and the admin will be notified that // the user is switching servers. // //NEXT MONTH UPGRADE FLAGS // //1 - Cron will upgrade them next month. //2 - If admin approves this, then it will be set to 1 for cron to upgrade them next month. //3 - The admin will be notified that the user wishes to be upgraded and if they approve it, // then an account on the new server will be created so they can migrate to the new server. // the admin can opt to switch the account over before next month if they both agree and the // switch will be made in the admin area manually. // //4 - Cron will create a new account on the new server next month and inform the admin that the // user is changing to the new server. // $upgrade_data = $dbh->select("upgrade", array("id", "=", $upgradeid)); $userid = $upgrade_data['uid']; $newpack = $upgrade_data['newpack']; $flags = $upgrade_data['flags']; $created = $upgrade_data['created']; $coupcode = $upgrade_data['coupcode']; $user_data = main::uidtopack($userid); $current_pack_type = $user_data['packages']['type']; $current_pack_name = $user_data['packages']['name']; $current_pack_id = $user_data['packages']['id']; $user_info = $dbh->select("users", array("id", "=", $userid)); $user_email = $user_info['email']; $username = $user_info['user']; $new_plan_data = $dbh->select("packages", array("id", "=", $newpack)); $newpack_name = $new_plan_data['name']; $new_plan_additional = type::additional($newpack); $new_server_data = $dbh->select("servers", array("id", "=", $new_plan_data['server'])); $new_server_name = $new_server_data['name']; $old_server_data = $dbh->select("servers", array("id", "=", $user_data['packages']['server'])); $old_server_name = $old_server_data['name']; switch ($flags) { case "0": $upgrade = 1; break; case "1": $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } break; case "2": if ($mode = "Init") { $admin_approval = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags" => "1"), array("id", "=", $upgradeid), "1"); } } break; case "3": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags", "=", "4"), array("id", "=", $upgradeid), "1"); } } break; case "4": //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; $admin_inform = 1; } break; case "5": if ($mode = "Init") { $admin_approval = 1; $immediate = 1; } else { $upgrade = 1; } break; case "6": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; $immediate = 1; } else { $upgrade = 1; $new_server = 1; } break; case "7": $upgrade = 1; $new_server = 1; $admin_inform = 1; break; } $adminmsg_array['USER'] = $username; $adminmsg_array['NEWPLAN'] = $newpack_name; $adminmsg_array['OLDPLAN'] = $current_pack_name; $adminmsg_array['NEWSERVER'] = $new_server_name; $adminmsg_array['OLDSERVER'] = $old_server_name; if ($immediate) { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "immediately"; } else { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "next billing cycle"; } $url = $dbh->config("url"); if (ADMINDIR) { $admin_dir = ADMINDIR; } else { $admin_dir = "admin"; } $adminmsg_array['APPROVE_LINK'] = $url . $admin_dir . "/?page=users&sub=upgrade"; if ($upgrade) { if ($new_plan_data['type'] == "paid") { $new_invoice_text = " A new invoice has been generated."; if ($current_pack_type == "paid" && $user_data['additional']['monthly'] >= $new_plan_additional['monthly']) { unset($new_invoice_text); } } $serverfile = server::createServer($newpack); if ($new_server) { $new_serv_pass_for_email = time(); $domsub = "sub"; //Checks to see if the domain contains 3 or more segments and fails if there are more than 3 and if the last one two aren't TLD portions, it fails, //so we can see if this is a subdomain this way. if (check::domain($user_data['user_data']['domain'])) { $domsub = "dom"; } $done = $serverfile->signup(type::packageserver($newpack), $new_plan_data['reseller'], $username, $user_email, $new_serv_pass_for_email, $user_data['user_data']['domain'], type::packageBackend($newpack), $domsub); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-newserv-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-newserv-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account on the new server." . $new_invoice_text); } else { return false; } } else { if ($serverfile->canupgrade) { $done = $serverfile->do_upgrade($new_plan_data['server'], type::packageBackend($newpack), $username); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account." . $new_invoice_text); } else { return false; } } else { $emaildata = email::emailTemplate("manual-upgrade-request"); main::errors("Your upgrade request has been added and the administrator has been emailed."); } } if ($uemaildata) { $welcomeemail_array['USER'] = $username; $welcomeemail_array['EMAIL'] = $user_email; $welcomeemail_array['PACKAGE'] = $newpack_name; $welcomeemail_array['SERVERIP'] = $new_server_data['ip']; $welcomeemail_array['LNAME'] = $user_info['lastname']; $welcomeemail_array['FNAME'] = $user_info['firstname']; $welcomeemail_array['CPPORT'] = $new_server_data['port']; $welcomeemail_array['PASS'] = $new_serv_pass_for_email; $welcomeemail_array['RESELLERPORT'] = $new_server_data['resellerport']; $welcomeemail_array['NAMESERVERS'] = nl2br($new_server_data['nameservers']); $welcomeemail_array['DOMAIN'] = $user_data['user_data']['domain']; email::send($user_email, $uemaildata['subject'], $uemaildata['content'], $welcomeemail_array); } } else { main::errors("Your upgrade request has been added."); } //Now we need to send the admin a dozen emails. lol FIRE! Nah, we'll only ever send them one email at a time. ;) if ($admin_approval) { if ($new_server) { $emaildata = email::emailTemplate("upgrade-newserv-adminval"); } else { $emaildata = email::emailTemplate("upgrade-adminval"); } } if ($admin_inform) { $emaildata = email::emailTemplate("notify-upgrade-new-server"); } if (!$emaildata && $change_tht) { $emaildata = email::emailTemplate("notify-upgrade"); } if ($emaildata) { email::staff($emaildata['subject'], $emaildata['content'], $adminmsg_array); } if ($change_tht) { main::thtlog("Client Upgraded", "Upgraded from " . $current_pack_name . " to " . $newpack_name, $userid, ""); if ($current_pack_type == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", ""); $dbh->update("invoices", array("pid" => $current_pack_id), $where); } if ($new_plan_data['type'] != "p2h") { $dbh->delete("coupons_p2h", array("uid", "=", $userid)); } $user_pack_data = $user_data['user_data']; $users_update = array("pid" => $newpack, "domain" => $user_pack_data['domain'], "additional" => $user_pack_data['additional']); $dbh->update("users", $users_update, array("id", "=", $userid), "1"); $dbh->update("users_bak", $users_update, array("id", "=", $userid), "1"); if ($current_pack_type == "paid") { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $had_coupons .= $coupons_used_data['coupcode'] . ","; $couponvals .= $coupons_used_data['paiddisc'] . ","; } $had_coupons = substr($had_coupons, 0, strlen($had_coupons) - 1); $couponvals = substr($couponvals, 0, strlen($couponvals) - 1); if (!$had_coupons) { $had_coupons = "0"; $couponvals = "0"; } $invoices_update = array("changed_plan" => "1", "hadcoupons" => $had_coupons, "couponvals" => $couponvals); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("hadcoupons", "=", ""); $dbh->update("invoices", $invoices_update, $where); } $multi_coupons = $dbh->config("multicoupons"); if ($coupcode || $new_plan_data['type'] == "free") { if (!$multi_coupons || $new_plan_data['type'] == "free") { $coupons_used_update = array("disabled" => "2", "datedisabled" => time()); $dbh->update("coupons_used", $coupons_used_update, array("user", "=", $userid)); } } if ($new_plan_data['type'] != "free") { if ($new_plan_data['type'] == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($user_data['additional']['monthly'] < $new_plan_additional['monthly'] && $current_pack_type == "paid" && $last_invoice) { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); $coupcode = $current_coupon['coupcode']; coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); $invoice_update_array = array("amount" => $new_plan_additional['monthly'], "due" => $last_invoice['due'] + 7 * 24 * 60 * 60, "pid" => $newpack, "hadcoupons" => "", "couponvals" => "", "changed_plan" => "0", "is_paid" => "0"); $where[] = array("id", "=", $last_invoice['id']); $dbh->update("invoices", $invoice_update_array, $where); } else { $amount = $new_plan_additional['monthly']; if (!$coupcode) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupcode = $dbh->select("coupons_used", $where); $coupcode = $coupcode['coupcode']; } $coupon_data = coupons::coupon_data($coupcode); $coupon_data['paiddisc'] = coupons::percent_to_value("paid", "paidtype", "paiddisc", $amount); if ($multi_coupons) { $amount = coupons::get_discount("paid", $amount, $userid) - $coupon_data['paiddisc']; } else { $amount = max(0, $amount - $coupon_data['paiddisc']); } $due = time() + 2592000; $notes = "Your hosting package invoice for this billing cycle. Package: " . $newpack_name; invoice::create($userid, $amount, $due, $notes); $last_invoice = $dbh->select("invoices", array("uid", "=", $userid), array("id", "DESC"), "1"); $dbh->update("invoices", array("pid" => $newpack), array("id", "=", $last_invoice['id']), "1"); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($coupcode) { $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } if ($multi_coupons && $use_coupons) { for ($i = 0; $i < count($use_coupons); $i++) { $coupcode = $use_coupons[$i]; $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } } } //We now remove the upgrade stub. $dbh->delete("upgrade", array("uid", "=", $userid)); } unset($where); $where[] = array("amount", "=", "0", "OR"); $where[] = array("amount", "=", "0.00"); $dbh->update("invoices", array("is_paid" => "1"), $where); if (!$no_errors_out) { echo "<ERRORS>"; } }
public function coupon($coupon, $user, $package) { if (empty($coupon)) { return true; } if (type::packagetype($package) == "free") { return false; } $coupon_text = coupons::validate_coupon($coupon, "orders", $user, $package); if ($coupon_text) { return $coupon_text; } return false; }
public function content() { global $dbh, $postvar, $getvar, $instance; $upackinfo = main::uidtopack(); $currentpack = $upackinfo['user_data']['pid']; $packsid = $postvar['packs']; if (!$packsid) { $packsid = $getvar['package']; } unset($where); if (is_numeric($packsid)) { $where[] = array("id", "=", $packsid, "AND"); } else { $where[] = array("is_hidden", "=", "0", "AND"); } $where[] = array("is_disabled", "=", "0", "AND"); $where[] = array("id", "!=", $currentpack); $packages_order[] = array("type", "ASC"); $packages_order[] = array("name", "ASC"); $packages_query = $dbh->select("packages", $where, $packages_order, 0, 1); $upgrade_array['PACK'] = ""; while ($packages_data = $dbh->fetch_array($packages_query)) { $additional = type::additional($packages_data['id']); $monthly = $additional['monthly']; $signup = $additional['signup']; unset($info); if ($packages_data['type'] == "p2h") { $info = "[Signup Posts: " . $signup . ", Monthly Posts: " . $monthly . "] "; $contribution = "<strong>Signup Posts:</strong> " . $signup . "<br><strong>Monthly Posts:</strong> " . $monthly; } elseif ($packages_data['type'] == "paid") { $info = "[" . main::money($monthly) . "] "; $contribution = main::money($monthly); } else { $contribution = "Free"; } $packages[] = array("[" . $packages_data['type'] . "] " . $info . $packages_data['name'], $packages_data['id']); if ($packsid && $packsid == $packages_data['id']) { $prorate = upgrade::prorate($packages_data['id'], $postvar['coupon']); $package_array['DISABLED'] = ""; if ($prorate == "inelegible") { main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>"); $package_array['DISABLED'] = "disabled"; } if ($prorate == "owe") { main::errors("You have outstanding charges on your account and can only upgrade your paid package. Your charges are outstanding! Keep up the good work. lol<br><br>"); $package_array['DISABLED'] = "disabled"; } if ($prorate == "oweposts") { main::errors("You still owe your required monthly posts and can only upgrade to a paid plan until you finish your posting quota. Our forum is a lot of fun, so come join us! =)<br><br>"); $package_array['DISABLED'] = "disabled"; } if ($prorate == "next" || $prorate == "check next") { main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle. If you do not wish to wait, please contact us.<br><br>"); $next_month = 1; } if (is_numeric($prorate) && $prorate > 0) { $contribution .= " (You pay only <font color = '#FF0055'>" . main::money($prorate) . "</font> more today to upgrade.)"; } if ($prorate == "check" || $prorate == "check next" || $prorate == "check now") { $fuser = $postvar['fuser']; $fpass = $postvar['fpass']; $forum_credentials_array['FUSER'] = $fuser; $forum_credentials_array['FPASS'] = $fpass; $package_array['FORUMINFO'] = style::replaceVar("tpl/upgrade/forum-credentials.tpl", $forum_credentials_array); } else { if ($packages_data['type'] == "p2h") { $fuser = $upackinfo['uadditional']['fuser']; $fpass = $upackinfo['uadditional']['fpass']; $no_fcheck = 1; } $package_array['FORUMINFO'] = ""; } $coupon_entry_array['COUPCODE'] = ""; $coupon_entry_array['COUPTEXT'] = ""; $coupon_entry_array['COUPCODEVALID'] = ""; if ($packages_data['type'] == "p2h" && $prorate != "owe") { //Paid users can enter them when they pay the invoice and free users don't need coupons. $coupcode = $postvar['coupon']; $validcoupon = $postvar['validcoupon']; if ($postvar['addcoupon']) { $uname = main::uname($_SESSION['cuser']); if ($coupcode) { $response = coupons::validate_coupon($coupcode, "orders", $uname, $packsid); if ($response) { $coup_data = coupons::coupon_data($coupcode); $discount = $coup_data['p2hinitdisc']; $multi_coupons = $dbh->config("multicoupons"); if ($multi_coupons) { $discount = $discount + upgrade::get_init_discount(); } $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount; if ($total_posts < $signup) { $error = 1; main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>"); $package_array['DISABLED'] = "disabled"; $coupon_entry_array['COUPCODEVALID'] = ""; } else { $prorate = upgrade::prorate($packages_data['id'], $coupcode); if ($prorate == "next" || $prorate == "check next" || $prorate == "inelegible") { //We know they're eligible or they wouldn't be at this stage. It just doesn't check existing coupons. main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle. If you do not wish to wait, please contact us.<br><br>"); $next_month = 1; } else { unset($_SESSION['errors']); } $package_array['DISABLED'] = ""; $coupon_entry_array['COUPCODEVALID'] = $coupcode; } $coupon_entry_array['COUPTEXT'] = $response; $coupon_entry_array['COUPCODE'] = $coupcode; } else { $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>"; $coupon_entry_array['COUPCODEVALID'] = "invalid"; } } else { $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>"; $coupon_entry_array['COUPCODEVALID'] = "invalid"; } } else { $coupon_entry_array['COUPTEXT'] = ""; $coupon_entry_array['COUPCODE'] = $coupcode; $coupon_entry_array['COUPCODEVALID'] = $validcoupon; } $package_array['COUPONS'] = style::replaceVar("tpl/upgrade/coupon-entry.tpl", $coupon_entry_array); } else { $package_array['COUPONS'] = ""; } $package_array['CONTRIBUTION'] = $contribution; $package_array['PACKID'] = $packages_data['id']; $package_array['PACKNAME'] = $packages_data['name']; $package_array['PACKDESC'] = $packages_data['description']; $package_array['ADMIN'] = $packages_data['admin'] == "1" ? "Yes" : "No"; $package_array['RESELLER'] = $packages_data['reseller'] == "1" ? "Yes" : "No"; $package_array['SERVER'] = $packages_data['server'] != $upackinfo['packages']['server'] ? "Yes" : "No"; $package_array['TYPE'] = $packages_data['type'] == "p2h" ? strtoupper($packages_data['type']) : ucfirst($packages_data['type']); if ($postvar['submitchange']) { //Someone cheated and modified the code to re-enable the button. This stops all that. if ($package_array['DISABLED'] == "disabled") { main::redirect("?page=upgrade"); return; } if ((!$fuser || !$fpass) && $packages_data['type'] == "p2h" && !$no_fcheck) { $error = 1; main::errors("Please enter your forum username and password to continue.<br><br>"); } if ($fuser && $fpass && $packages_data['type'] == "p2h" && !$no_fcheck) { $p2h = $instance->packtypes["p2h"]; $response = $p2h->checkSignup($fuser, $fpass, $postvar['packs'], $postvar['validcoupon']); switch ($response) { case "3": $error = 1; main::errors("The username, " . $fuser . ", does not exist.<br><br>"); break; case "4": $error = 1; main::errors("Invalid password.<br><br>"); break; default: //We add this now so the post checks can use it and it also tacks it to the user's account for future reference. $new_additional = "fuser="******",fpass=0"; $dbh->update("users", array("additional" => $new_additional), array("id", "=", $upackinfo['user_data']['id']), "1"); break; } } if (!$error) { if ($validcoupon && $validcoupon != "invalid") { $coup_data = coupons::coupon_data($validcoupon); $discount = $coup_data['p2hinitdisc']; $db_coupcode = $validcoupon; } $multi_coupons = $dbh->config("multicoupons"); if ($multi_coupons) { $discount = $discount + upgrade::get_init_discount(); } if ($packages_data['type'] == "p2h") { $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount; if ($total_posts < $signup) { $error = 1; main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>"); } } if (!$error) { //The user is elegible to upgrade and all checks have passed. if ($packages_data['admin']) { $admin = 1; } if ($packages_data['server'] != $upackinfo['packages']['server']) { $different_server = 1; } //Flag meaning: // //IMMEDIATE UPGRADE FLAGS // //0 - Upgrade is immediate. //5 - If admin approves the upgrade, then the upgrade will be immediate. // //6 - If admin approves the upgrade, then the new account will be created on the new server and the // admin will know that they are moving to a new server so they can manually close the old account // when they're ready. // //7 - The new account on the new server will be immediately created and the admin will be notified that // the user is switching servers. // //NEXT MONTH UPGRADE FLAGS // //1 - Cron will upgrade them next month. //2 - If admin approves this, then it will be set to 1 for cron to upgrade them next month. //3 - The admin will be notified that the user wishes to be upgraded and if they approve it, // then an account on the new server will be created so they can migrate to the new server. // the admin can opt to switch the account over before next month if they both agree and the // switch will be made in the admin area manually. // //4 - Cron will create a new account on the new server next month and inform the admin that the // user is changing to the new server. // if ($next_month) { $flags = "1"; if ($admin) { $flags = "2"; if ($different_server) { $flags = "3"; } } else { if ($different_server) { $flags = "4"; } } } else { $flags = "0"; if ($admin) { $flags = "5"; if ($different_server) { $flags = "6"; } } else { if ($different_server) { $flags = "7"; } } } $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser'])); //When the upgrade is finished, the entry is removed. if ($pending_upgrade['id']) { $upgrade_update = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode); $dbh->update("upgrade", $upgrade_update, array("id", "=", $pending_upgrade['id']), "1"); } else { $upgrade_insert = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode); $dbh->insert("upgrade", $upgrade_insert); } $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser'])); $response = upgrade::do_upgrade($pending_upgrade['id'], "Init"); if ($response === false) { echo "Your upgrade could not be completed as dialed. Please check with your admin and try your upgrade again later. The following tones are for the deaf community in hopes that they'll be able to hear again. BEEEEEEEEEEEEEEEEEEEEEEEEP!!!!!!!!"; } else { echo $response; } return; } } } } } if ($packsid) { $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/package.tpl", $package_array); } else { $select_package_array['PACKS'] = main::dropDown("packs", $packages, '', 0); $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/select-package.tpl", $select_package_array); } echo style::replaceVar("tpl/upgrade/upgrade.tpl", $upgrade_array); $page_shown = 1; //The page doesn't show if they refresh it after the upgrade since the loop checks if they're upgrading to the same package they are on and fails if they are. if (!$page_shown) { main::redirect("?page=upgrade"); } }
} if (sizeof($nonFreeLessons) > 0) { $currentUser->addLessons($nonFreeLessons, array_fill(0, sizeof($nonFreeLessons), 'student'), true); } if (sizeof($nonFreeCourses) > 0) { $currentUser->addCourses($nonFreeCourses, array_fill(0, sizeof($nonFreeCourses), 'student'), true); } $currentUser->user['balance'] = $currentUser->user['balance'] - $totalPrice; $currentUser->persist(); $fields = array("amount" => $totalPrice, "timestamp" => time(), "method" => "balance", "status" => "completed", "users_LOGIN" => $currentUser->user['login'], "lessons" => $nonFreeLessons, "courses" => $nonFreeCourses); $payment = payments::create($fields); if ($coupon) { $coupon->useCoupon($currentUser, $payment, array('lessons' => $nonFreeLessons, 'courses' => $nonFreeCourses)); } } else { if ($form->exportValue('coupon') && ($coupon = new coupons($form->exportValue('coupon'), true))) { if (!$coupon->checkEligibility($currentUser)) { throw new Exception(_INVALIDCOUPON); } if (!$GLOBALS['configuration']['paypalbusiness']) { //If we have paypal, the reduction is already done $totalPrice = $totalPrice * (1 - $coupon->{$coupon->entity}['discount'] / 100); } } //in case of 100% discount if ($totalPrice == 0) { //Assign new lessons as inactive if (sizeof($nonFreeLessons) > 0) { $currentUser->addLessons($nonFreeLessons, array_fill(0, sizeof($nonFreeLessons), 'student'), true); } if (sizeof($nonFreeCourses) > 0) {
public function cron() { global $dbh, $postvar, $getvar, $instance; $packages_query = $dbh->select("packages", array("type" => "paid"), 0, 0, 1); $packages_num_rows = $dbh->num_rows($packages_query); //Do we have paid packages? if ($packages_num_rows) { while ($packages_data = $dbh->fetch_array($packages_query)) { $i++; //Do we have multiple packages and aren't on the last one? if ($packages_data < $i) { //Did we already pull one package? If so, we don't set the flag for the parenthesis. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "OR"); //We are on the first listing of the paid packages, so we set the flag for the opening parenthesis and mark it that we pulled one already. } else { $where[] = array("pid", "=", $packages_data['id'], "OR", 1); $pulled_one = 1; } } else { //Are we on the last listing of paid listings? If so, we close the parenthesis by setting that flag. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "", 1); //We only had one listing, so we don't use parenthesis and we don't use "OR." } else { $where[] = array("pid", "=", $packages_data['id']); } } //So we can later grab the package's information without needing to repull this data. $packages_info[$packages_data['id']] = $packages_data; } $time = time(); //Look at every last invoice. $invoices_query = $dbh->select("invoices"); while ($invoices_data = $dbh->fetch_array($invoices_query)) { $uid = $invoices_data['uid']; $client = $dbh->client($uid); //Skip this invoice if it belongs to a user marked as a free user. if ($client['freeuser']) { continue; } //If the invoice is older than 30 days and we haven't issued a new invoice yet... (This makes sure the user is still on the package //before issuing a new invoice for it.) if ($time > $invoices_data['created'] + 2592000 && !in_array($uid, $invoiced_to) && $invoices_data['pid'] == $client['pid']) { $pack_additional = type::additional($client['pid']); $amount = coupons::get_discount("paid", $pack_additional['monthly'], $client['user']); invoice::create($uid, $amount, $time, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$client['pid']]['name']); $invoiced_to[] = $uid; //Track what clients have been sent a new invoice. } $lastmonth = $time - 2592000; $suspenddays = $dbh->config('suspensiondays'); $terminationdays = $suspenddays + $dbh->config('terminationdays'); $suspendseconds = $suspenddays * 24 * 60 * 60; $terminateseconds = $dbh->config('terminationdays') * 24 * 60 * 60; //If we have an unpaid bill that's greater than $0 and it's past it's due date... if ($invoices_data['due'] < $time and $invoices_data['is_paid'] == 0 && $invoices_data['amount'] > 0) { //If we have a bill that's overdue by $terminationdays + $suspenddays, then we terminate the account... if ($time - $suspendseconds - $terminateseconds > $invoices_data['due']) { server::terminate($uid, "Your account was overdue for more than " . $terminationdays . " days."); $checked_term = 1; //If we have a bill that's overdue by $suspenddays and the client is active, then we suspend them... //Just an FYI, if I start(ed) charging for this script, check The Pirate Bay for this script as I always upload my payware stuff there since I know not everyone can afford to pay me. } elseif ($time - $suspendseconds > $invoices_data['due'] && $client['status'] == '1') { server::suspend($uid, "Your account is overdue. Please log in and pay your invoice to bring your account out of suspension."); } } } //If the user does not have an invoice yet and never had one, this will create one for them. The portion above //handles creating NEW invoices. (It checks for outdated ones and such.) $users_query = $dbh->select("users", $where, 0, 0, 1); while ($users_data = $dbh->fetch_array($users_query)) { //Skip this user if its marked as a free user. if ($users_data['freeuser']) { continue; } $invoice_data = $dbh->select("invoices", array("pid", "=", $users_data['pid'])); if (!$invoice_data['id']) { $monthly = type::additional($users_data['pid']); $amount = $monthly['monthly']; $amount = coupons::get_discount("paid", $amount, $users_data['id']); invoice::create($users_data['id'], $amount, $time + 30 * 24 * 60 * 60, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$users_data['pid']]['name']); // Create Invoice +30 Days } } } }
function validate_ipn() { global $dbh, $postvar, $getvar, $instance; $invoice_id = $getvar['invoiceID']; $url_parsed = parse_url($this->paypal_url); $post_string = ''; foreach ($postvar as $field => $value) { $this->ipn_data["{$field}"] = $value; $post_string .= $field . '=' . urlencode($value) . '&'; } $post_string .= "cmd=_notify-validate"; $fp = fsockopen("ssl://" . $url_parsed[host], "443", $err_num, $err_str, 30); if (!$fp) { // could not open the connection. If logging is on, the error message // will be in the logged. $this->last_error = "fsockopen error no. {$err_num}: {$err_str}"; $this->log_ipn_results(false); return false; } else { // Post the data back to paypal fputs($fp, "POST /cgi-bin/webscr HTTP/1.0\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-Length: " . strlen($post_string) . "\r\n\r\n"); fputs($fp, $post_string . "\r\n\r\n"); // loop through the response from the server and append to variable while (!feof($fp)) { $this->ipn_response .= fgets($fp, 1024); } fclose($fp); // close connection } $invoice_info = $dbh->select("invoices", array("id", "=", $invoice_id)); $due_date = $invoice_info['due']; $amt_paid = $invoice_info['amt_paid']; $txn = $invoice_info['txn']; $datepaid = $invoice_info['datepaid']; $gateway = $invoice_info['gateway']; if ($amt_paid) { $amt_paid = $amt_paid . "," . $this->ipn_data["mc_gross"]; } else { $amt_paid = $this->ipn_data["mc_gross"]; } if ($this->ipn_data["parent_txn_id"]) { $new_txn = $this->ipn_data["parent_txn_id"]; } else { $new_txn = $this->ipn_data["txn_id"]; } if ($txn) { $txn = $txn . "," . $new_txn; } else { $txn = $new_txn; } if ($datepaid) { $datepaid = $datepaid . "," . time(); } else { $datepaid = time(); } if ($gateway) { $gateway = $gateway . ",PayPal"; } else { $gateway = "PayPal"; } if ($this->ipn_data["mc_gross"] < 0) { //As the transaction was revered or refunded, we need to set the is_paid flag to 0 and make sure they don't get terminated if this was an //invoice older than 30 days. if (is_numeric($invoice_id)) { $total_paid = coupons::totalpaid($invoice_id) + $this->ipn_data["mc_gross"]; if ($invoice_info['amount'] > $total_paid) { $suspenddays = intval($dbh->config('suspensiondays')); $suspendseconds = $suspenddays * 24 * 60 * 60; $time = time(); if ($time - $suspendseconds > intval($due_date)) { $due_date = $time - $suspendseconds; } $amt_due = array("is_paid" => "0", "due" => $due_date); } $gateway = $gateway . " (Reversal)"; $invoices_update = array("amt_paid" => $amt_paid, "txn" => $txn, "datepaid" => $datepaid, "gateway" => $gateway); if ($amt_due) { $invoices_update = array_merge($invoices_update, $amt_due); } $dbh->update("invoices", $invoices_update, array("id", "=", $invoice_id)); } $this->log_ipn_results(true); } if (eregi("VERIFIED", $this->ipn_response)) { // Valid IPN transaction. $this->log_ipn_results(true); $invoices_update = array("amt_paid" => $amt_paid, "txn" => $txn, "datepaid" => $datepaid, "gateway" => $gateway); $dbh->update("invoices", $invoices_update, array("id", "=", $invoice_id)); $total_paid = coupons::totalpaid($invoice_id); if ($invoice_info['amount'] > $total_paid) { return false; } else { return true; } } else { // Invalid IPN transaction. Check the log for details. $this->last_error = 'IPN Validation Failed.'; $this->log_ipn_results(false); return false; } }
public function content() { global $dbh, $postvar, $getvar, $instance; if (is_numeric($getvar['view'])) { //Show the invoice unset($where); $where[] = array("uid", "=", $_SESSION['cuser'], "AND"); $where[] = array("id", "=", $getvar['view']); $invoice_info_top = $dbh->select("invoices", $where); $pack_data_top = main::uidtopack(); if (!$invoice_info_top['pid']) { $dbh->update("invoices", array("pid" => $pack_data_top['user_data']['pid']), array("id", "=", $invoice_info_top['id'])); $invoice_info_top['pid'] = $pack_data_top['user_data']['pid']; } if ($_POST['submitaddcoupon']) { if (!$postvar['addcoupon']) { main::errors("Please enter a coupon code or click the checkout button."); } else { $coupcode = $postvar['addcoupon']; $user = main::uname($_SESSION['cuser']); $pack_data = main::uidtopack(); if ($invoice_info_top['pid'] != $pack_data['user_data']['pid']) { $pack_data = upgrade::pidtobak($invoice_info_top['pid']); } $packid = $pack_data['packages']['id']; $multi_coupons = $dbh->config("multicoupons"); $coupon_info = coupons::coupon_data($coupcode); $coupid = $coupon_info['id']; $use_coupon = coupons::use_coupon($coupid, $packid, $getvar['view']); if (!$use_coupon) { if (!$multi_coupons) { main::errors("Coupon code entered was invalid or you're already using a coupon."); } else { main::errors("Coupon code entered was invalid."); } } else { main::redirect("?page=invoices&view=" . $getvar['view']); } } } unset($where); $where[] = array("uid", "=", $_SESSION['cuser'], "AND"); $where[] = array("id", "=", $getvar['view']); $invoice_info = $dbh->select("invoices", $where); if (empty($invoice_info)) { main::redirect("?page=invoices"); exit; } $package = $dbh->select("packages", array("id", "=", $invoice_info['pid'])); $monthly = type::additional($package['id']); $subtotal = $monthly['monthly']; if (is_numeric($getvar['remove'])) { $remove_id = $getvar['remove']; $remove = coupons::remove_coupon($remove_id, $package['id'], $invoice_info['id'], $_SESSION['cuser']); main::redirect("?page=invoices&view=" . $invoice_info['id']); exit; } $total_paid_real = coupons::totalpaid($getvar['view']); if ($total_paid_real < 0) { $total_paid = "0.00"; } else { $total_paid = $total_paid_real; } $acct_balance = coupons::get_discount("paid", $subtotal) - $total_paid_real; if ($acct_balance < 0) { $acct_balance = "0.00"; } $acct_balance = main::addzeros($acct_balance); if ($acct_balance == 0 && $invoice_info['is_paid'] == '0') { $dbh->update("invoices", array("is_paid" => "1"), array("id", "=", $invoice_info['id']), "1"); main::redirect("?page=invoices&view=" . $invoice_info['id']); } if ($acct_balance > 0 && $invoice_info['is_paid'] == '1') { $dbh->update("invoices", array("is_paid" => "0"), array("id", "=", $invoice_info['id']), "1"); main::redirect("?page=invoices&view=" . $invoice_info['id']); } if ($_POST['checkout']) { $postvar['paythis'] = str_replace(array(" ", ","), array("", "."), $postvar['paythis']); if (!is_numeric($postvar['paythis'])) { main::errors("Please enter the amount you wish to pay today."); } else { if ($postvar['paythis'] > $acct_balance || $acct_balance <= 0) { main::errors("You can't pay more than you owe. =)"); } else { $dbh->update("invoices", array("pay_now" => $postvar['paythis']), array("id", "=", $getvar['view'])); main::redirect("?page=invoices&iid=" . $getvar['view']); exit; } } } $created = $invoice_info['created']; $thirty_days = 30 * 24 * 60 * 60; $orig_due = $created + $thirty_days; if (main::convertdate("n/d/Y", $invoice_info['due']) != main::convertdate("n/d/Y", $created + $thirty_days)) { $due_text = " (Originally " . main::convertdate("n/d/Y", $orig_due) . ")"; } $due = main::convertdate("n/d/Y", $invoice_info['due']); $client = $dbh->client($_SESSION['cuser']); $invoice_transactions_array['TOTALAMOUNT'] = main::money($acct_balance); $invoice_transactions_array['TOTALPAID'] = main::money($total_paid); $pay_invoice_array['TOTALAMT'] = main::money($acct_balance); $pay_invoice_array['PAYBALANCE'] = $acct_balance; $pay_invoice_array['CURRSYMBOL'] = main::money($acct_balance, "", 1); $pay_invoice_array['PACKID'] = $invoice_info['pid']; $pay_invoice_array['USER'] = $client['user']; $view_invoice_array['ID'] = $invoice_info['id']; $view_invoice_array['DUE'] = $due . $due_text; $view_invoice_array['PACKDUE'] = $due; $view_invoice_array['CREATED'] = main::convertdate("n/d/Y", $created); $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::money($invoice_info['amount']) . " (Package price: " . main::money($subtotal) . ")" : main::money($invoice_info['amount']); $view_invoice_array['BALANCE'] = main::money($acct_balance); $view_invoice_array['COUPONTOTAL'] = main::money($subtotal - coupons::get_discount("paid", $subtotal)); $view_invoice_array['UNAME'] = $client['user']; $view_invoice_array['FNAME'] = $client['firstname']; $view_invoice_array['LNAME'] = $client['lastname']; $view_invoice_array['ADDRESS'] = $client['address']; $view_invoice_array['CITY'] = $client['city']; $view_invoice_array['STATE'] = $client['state']; $view_invoice_array['ZIP'] = $client['zip']; $view_invoice_array['COUNTRY'] = strtoupper($client['country']); $view_invoice_array['DOMAIN'] = $client['domain']; $view_invoice_array['PACKAGE'] = $package['name']; $view_invoice_array['STATUS'] = $invoice_info["is_paid"] == 1 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>"; if ($invoice_info['changed_plan'] && $invoice_info['hadcoupons']) { $coupon_list = explode(",", $invoice_info['hadcoupons']); $coupon_values = explode(",", $invoice_info['couponvals']); if ($coupon_list) { for ($i = 0; $i < count($coupon_list); $i++) { $coupons_list_array['COUPONAMOUNT'] = main::money($coupon_values[$i]); $coupons_list_array['COUPCODE'] = $coupon_list[$i]; $coupons_list_array['REMOVE'] = ""; $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array); $coup_total = $coup_total + $coupon_values[$i]; } $view_invoice_array['COUPONTOTAL'] = main::money(min($subtotal, $coup_total)); } } else { unset($where); $where[] = array("user", "=", $client['id'], "AND"); $where[] = array("disabled", "=", "0"); $coupons_query = $dbh->select("coupons_used", $where, array("id", "ASC"), 0, 1); while ($coupons_used_fetch = $dbh->fetch_array($coupons_query)) { $valid_coupon = coupons::check_expire($coupons_used_fetch['coupcode'], $client['id']); if ($valid_coupon) { $coupons_list_array['COUPONAMOUNT'] = main::money($coupons_used_fetch['paiddisc']); $coupons_list_array['COUPCODE'] = $coupons_used_fetch['coupcode']; $coupons_list_array['REMOVE'] = $invoice_info['is_paid'] == 1 ? "" : '(<a href = "?page=invoices&view=' . $invoice_info['id'] . '&remove=' . $coupons_used_fetch['id'] . '">Remove</a>)'; $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array); } } if (!$view_invoice_array['COUPONSLIST']) { $view_invoice_array['COUPONSLIST'] = "<tr><td></td><td align = 'center'>None</td></tr>"; } } $amt_paid = $invoice_info['amt_paid']; $txn = $invoice_info['txn']; $datepaid = $invoice_info['datepaid']; $gateway = $invoice_info['gateway']; $amt_paid = explode(",", $amt_paid); $txn = explode(",", $txn); $datepaid = explode(",", $datepaid); $gateway = explode(",", $gateway); $view_invoice_array['TRANSACTIONS'] = ""; for ($i = 0; $i < count($amt_paid); $i++) { $paid_this = $paid_this + $amt_paid[$i]; $transaction_list_array['PAIDAMOUNT'] = main::money($amt_paid[$i]); $transaction_list_array['TXN'] = $txn[$i]; $transaction_list_array['PAIDDATE'] = main::convertdate("n/d/Y", $datepaid[$i]); $transaction_list_array['GATEWAY'] = $gateway[$i]; $invoice_transactions_array['TXNS'] .= style::replaceVar("tpl/invoices/transaction-list.tpl", $transaction_list_array); } if ($invoice_info["is_paid"]) { if (!$invoice_info['amt_paid']) { $invoice_transactions_array['TXNS'] = "<tr><td colspan = '4' align = 'center'><b>--- None ---</b></td></tr>"; } $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array); } else { if ($invoice_info['amt_paid']) { $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array); } $view_invoice_array['TRANSACTIONS'] .= style::replaceVar("tpl/client/invoices/pay-invoice.tpl", $pay_invoice_array); } echo style::replaceVar("tpl/invoices/view-invoice.tpl", $view_invoice_array); } else { //Show the list of invoices $pack_info = main::uidtopack(); $invoices_query = $dbh->select("invoices", array("uid", "=", $_SESSION['cuser']), array("id", "DESC"), 0, 1); $client_page_array['LIST'] = ""; while ($invoices_data = $dbh->fetch_array($invoices_query)) { if (!$invoices_data['pid']) { $dbh->update("invoices", array("pid" => $pack_info['user_data']['pid']), array("id", "=", $invoices_data['id'])); $invoices_data['pid'] = $pack_info['user_data']['pid']; } if ($invoices_data['pid'] != $pack_info['user_data']['pid']) { $pack_info = upgrade::pidtobak($invoices_data['pid']); } $monthly = $pack_info['additional']['monthly']; $invoice_list_item_array['ID'] = $invoices_data['id']; $invoice_list_item_array['USERFIELD'] = ""; $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", $invoices_data['due']); $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", $invoices_data['created']); $invoice_list_item_array["PAID"] = $invoices_data["is_paid"] == 1 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>"; $invoice_list_item_array['AMOUNT'] = main::money($invoices_data['amount']); $invoice_list_item_array['AMTPAID'] = main::money(coupons::totalpaid($invoices_data['id'])); $client_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array); } $client_page_array['NUM'] = $dbh->num_rows($invoices_query); if ($client_page_array['NUM'] == 0) { $client_page_array['LIST'] = "<tr>\n<td colspan = '6' align = 'center'>You currently do not have any invoices.</td>\n</tr>"; } echo style::replaceVar("tpl/client/invoices/client-page.tpl", $client_page_array); } }
public function signup($data) { global $dbh, $postvar, $getvar, $instance; $domain = $data['domain']; $username = $data['username']; $password = $data['password']; $user_email = $data['user_email']; $firstname = $data['firstname']; $lastname = $data['lastname']; $address = $data['address']; $city = $data['city']; $state = $data['state']; $zip = $data['zip']; $country = $data['country']; $phone = $data['phone']; $tzones = $data['tzones']; $coupon = $data['coupon']; $package = $data['package']; $domsub = $data['domsub']; $additional = $data['additional']; $subdomain = empty($data['subdomain']) ? 0 : $data['subdomain']; //Let's make sure we're actually receiving an integer as a string. if (!is_numeric($package) || strpos($package, ".") !== false) { return "The package specified is invalid."; } //Check to see if we have a valid domain type. if ($domsub != "dom" && $domsub != "sub") { return "The domain/subdomain type is unspecified in the URL."; } if ($domsub == "dom") { $cdom = $domain; } else { $csub2 = $domain; $csub = $subdomain; } unset($where); $where[] = array("id", "=", $package, "AND"); $where[] = array("is_disabled", "=", "0"); $packages_data = $dbh->select("packages", $where); if (!$packages_data['id']) { return "This package is disabled or doesn't exist."; } $package_server = $packages_data['server']; if ($domsub == "dom") { $use_dom = $cdom; } if ($domsub == "sub") { unset($where); $where[] = array("server", "=", $package_server, "AND"); $where[] = array("domain", "=", $csub2); $subdomains_data = $dbh->select("subdomains", $where, 0, "1"); if (!$subdomains_data['id']) { return "The chosen domain for your subdomain is not in the allowed list of domains."; } $use_dom = $csub . "." . $csub2; } if ($coupon && $packages_data['type'] != 'free') { $coupon_response = coupons::validate_coupon($coupon, "orders", $username, $package); if (!$coupon_response) { return "Please enter a valid coupon."; } else { $coupon_info = coupons::coupon_data($coupon); } } $packtype_instance = $instance->packtypes[$packages_data['type']]; if (method_exists($packtype_instance, "signup")) { $packtype_signup = $packtype_instance->signup(); //If this gives any response, it means it failed to validate the signup. if ($packtype_signup) { return $packtype_signup; } } $server_package_name = type::packageBackend($package); $serverfile = self::createServer($package); $packages_data = $dbh->select("packages", array("id", "=", $package)); $extra['firstname'] = $firstname; $extra['lastname'] = $lastname; $extra['address'] = $address; $extra['city'] = $city; $extra['state'] = $state; $extra['zip'] = $zip; $extra['country'] = strtoupper($country); $extra['phone'] = $phone; $server_response = $serverfile->signup(type::packageserver($package), $packages_data['reseller'], $username, $user_email, $password, $use_dom, $server_package_name, $extra, $use_dom); if ($server_response !== true) { return $server_response; } else { $time = time(); $ip = $_SERVER['REMOTE_ADDR']; $salt = crypto::salt(); $password_hash = crypto::passhash($password, $salt); if ($packages_data['admin'] == "1") { $status = "3"; } else { if ($packages_data['type'] == "paid") { $status = "4"; } else { $status = "1"; } } $users_insert = array("user" => $username, "email" => $user_email, "password" => $password_hash, "salt" => $salt, "signup" => $time, "ip" => $ip, "firstname" => $firstname, "lastname" => $lastname, "address" => $address, "city" => $city, "state" => $state, "zip" => $zip, "country" => $country, "phone" => $phone, "status" => $status, "tzadjust" => $tzones, "domain" => $use_dom, "pid" => $package, "additional" => $additional); $dbh->insert("users", $users_insert); $users_data = $dbh->select("users", array("user", "=", $username), 0, "1"); $users_bak_insert = array("uid" => $users_data['id'], "user" => $username, "email" => $user_email, "password" => $password_hash, "salt" => $salt, "signup" => $time, "ip" => $ip, "firstname" => $firstname, "lastname" => $lastname, "address" => $address, "city" => $city, "state" => $state, "zip" => $zip, "country" => $country, "phone" => $phone, "status" => $status, "tzadjust" => $tzones, "domain" => $use_dom, "pid" => $package, "additional" => $additional); $dbh->insert("users_bak", $users_bak_insert); main::thtlog("Client Registered", 'Registered.', $users_data['id']); if (!$users_data['id']) { $return = "Your account could not be created. Please contact your system administrator."; } else { if (!empty($coupon_info)) { main::thtlog("Coupon Used", "Coupon used (" . $coupon_info['coupcode'] . ")", $users_data['id']); $package_info = type::additional($package); $packmonthly = $package_info['monthly']; if ($packages_data['type'] == "paid") { $coupon_info['p2hmonthlydisc'] = "0"; $coupon_info['paiddisc'] = coupons::percent_to_value("paid", $coupon_info['paidtype'], $coupon_info['paiddisc'], $packmonthly); } else { $coupon_info['paiddisc'] = "0"; $coupon_info['p2hmonthlydisc'] = coupons::percent_to_value("p2h", $coupon_info['p2hmonthlytype'], $coupon_info['p2hmonthlydisc'], $packmonthly); } $insert_array = array("user" => $users_data['id'], "coupcode" => $coupon_info['coupcode'], "timeapplied" => time(), "packages" => $package, "goodfor" => $coupon_info['goodfor'], "monthsgoodfor" => $coupon_info['monthsgoodfor'], "paiddisc" => $coupon_info['paiddisc'], "p2hmonthlydisc" => $coupon_info['p2hmonthlydisc']); $dbh->insert("coupons_used", $insert_array); } $servers_data = $dbh->select("servers", array("id", "=", $package_server), 0, "1"); $server_host = $servers_data['host']; $server_ip = $servers_data['ip']; $server_nameservers = $servers_data['nameservers']; $server_port = $servers_data['port']; $server_resellerport = $servers_data['resellerport']; $url = $dbh->config("url"); $new_acc_email_array['CPPORT'] = $server_port; $new_acc_email_array['RESELLERPORT'] = $server_resellerport; $new_acc_email_array['SERVERIP'] = $server_ip; $new_acc_email_array['NAMESERVERS'] = nl2br($server_nameservers); $new_acc_email_array['USER'] = $username; $new_acc_email_array['PASS'] = $password; $new_acc_email_array['EMAIL'] = $user_email; $new_acc_email_array['FNAME'] = $firstname; $new_acc_email_array['LNAME'] = $lastname; $new_acc_email_array['DOMAIN'] = $use_dom; $new_acc_email_array['CONFIRM'] = $url . "client/confirm.php?u=" . $username . "&c=" . $time; $new_acc_email_array['PACKAGE'] = $packages_data['name']; if ($packages_data['admin'] == 0) { if ($packages_data['reseller'] == "1") { $new_acc_email = email::emailTemplate("new-reseller-account"); } else { $new_acc_email = email::emailTemplate("new-account"); } $return = "<strong>Your account has been created!</strong><br />You may now <a href = '../client'>login</a> to see your client area or proceed to your <a href = 'http://" . $server_host . ":" . $server_port . "'>control panel</a>. An email has been dispatched to the address on file."; if (type::packagetype($package) == "paid") { //Set the user up for when they finish their payment. $_SESSION['clogged'] = 1; $_SESSION['cuser'] = $users_data['id']; } $donecorrectly = true; } else { if ($serverfile->suspend($username, type::packageserver($package), 1) == false) { $return = "We could not suspend your account! Please contact the admin to suspend it until they validate it. lol"; } else { $dbh->update("users", array("status" => "3"), array("id", "=", $users_data['id'])); if ($packages_data['reseller'] == "1") { $new_acc_email = email::emailTemplate("new-reseller-account-adminval"); } else { $new_acc_email = email::emailTemplate("new-account-adminval"); } $admin_val_email = email::emailTemplate("admin-validation-requested"); $valarray['LINK'] = $dbh->config("url") . ADMINDIR . "/?page=users&sub=search&do=" . $users_data['id']; email::staff($admin_val_email['subject'], $admin_val_email['content'], $valarray); $return = "<strong>Your account is awaiting admin validation!</strong><br />An email has been dispatched to the address on file. You will recieve another email when the admin has looked over your account."; $donecorrectly = true; } } email::send($new_acc_email_array['EMAIL'], $new_acc_email['subject'], $new_acc_email['content'], $new_acc_email_array); } if ($donecorrectly && type::packagetype($package) == "paid") { $amountinfo = type::additional($package); $amount = $amountinfo['monthly']; $due = time() + 2592000; $notes = "Your hosting package invoice for this billing cycle. Package: " . $packages_data['name']; if (!empty($coupon_info)) { $amount = max(0, $amount - $coupon_info['paiddisc']); } invoice::create($users_data['id'], $amount, $due, $notes); $serverfile->suspend($username, type::packageserver($package), 0, 1); $dbh->update("users", array("status" => $status), array("id", "=", $users_data['id'])); if ($packages_data['admin'] != "1") { $return = '<div class="errors"><b>You are being redirected to payment! It will load in a couple of seconds.</b></div>'; return true; } } return $return; } }