Exemple #1
0
     $productarray['stocklevel'] = $data['qty'];
 }
 $result2 = select_query("tblpricing", "tblcurrencies.code,tblcurrencies.prefix,tblcurrencies.suffix,tblpricing.msetupfee,tblpricing.qsetupfee,tblpricing.ssetupfee,tblpricing.asetupfee,tblpricing.bsetupfee,tblpricing.tsetupfee,tblpricing.monthly,tblpricing.quarterly,tblpricing.semiannually,tblpricing.annually,tblpricing.biennially,tblpricing.triennially", array("type" => "product", "relid" => $pid), "code", "ASC", "", "tblcurrencies ON tblcurrencies.id=tblpricing.currency");
 while ($data = mysql_fetch_assoc($result2)) {
     $code = $data['code'];
     unset($data['code']);
     $productarray['pricing'][$code] = $data;
 }
 $customfieldsdata = array();
 $customfields = getCustomFields("product", $pid, "", "", "on");
 foreach ($customfields as $field) {
     $customfieldsdata[] = array("id" => $field['id'], "name" => $field['name'], "description" => $field['description'], "required" => $field['required']);
 }
 $productarray['customfields']['customfield'] = $customfieldsdata;
 $configoptiondata = array();
 $configurableoptions = getCartConfigOptions($pid, "", "", "", true);
 foreach ($configurableoptions as $option) {
     $options = array();
     foreach ($option['options'] as $op) {
         $pricing = array();
         $result4 = select_query("tblpricing", "code,msetupfee,qsetupfee,ssetupfee,asetupfee,bsetupfee,tsetupfee,monthly,quarterly,semiannually,annually,biennially,triennially", array("type" => "configoptions", "relid" => $op['id']), "", "", "", "tblcurrencies ON tblcurrencies.id=tblpricing.currency");
         while ($oppricing = mysql_fetch_assoc($result4)) {
             $currcode = $oppricing['code'];
             unset($oppricing['code']);
             $pricing[$currcode] = $oppricing;
         }
         $options['option'][] = array("id" => $op['id'], "name" => $op['name'], "recurring" => $op['recurring'], "pricing" => $pricing);
     }
     $configoptiondata[] = array("id" => $option['id'], "name" => $option['optionname'], "type" => $option['optiontype'], "options" => $options);
 }
 $productarray['configoptions']['configoption'] = $configoptiondata;
function doUpgrade($upgradeid)
{
    $result = select_query("tblupgrades", "", array("id" => $upgradeid));
    $data = mysql_fetch_array($result);
    $orderid = $data['orderid'];
    $type = $data['type'];
    $relid = $data['relid'];
    $originalvalue = $data['originalvalue'];
    $newvalue = $data['newvalue'];
    $upgradeamount = $data['amount'];
    $recurringchange = $data['recurringchange'];
    $result = select_query("tblorders", "promocode", array("id" => $orderid));
    $data = mysql_fetch_array($result);
    $promocode = $data['promocode'];
    if ($type == "package") {
        $newvalue = explode(",", $newvalue);
        $newpackageid = $newvalue[0];
        $newbillingcycle = $newvalue[1];
        $changevalue = "amount";
        if ($newbillingcycle == "free") {
            $newbillingcycle = "Free Account";
        } else {
            if ($newbillingcycle == "onetime") {
                $newbillingcycle = "One Time";
                $changevalue = "firstpaymentamount";
                $recurringchange = $upgradeamount;
            } else {
                if ($newbillingcycle == "monthly") {
                    $newbillingcycle = "Monthly";
                } else {
                    if ($newbillingcycle == "quarterly") {
                        $newbillingcycle = "Quarterly";
                    } else {
                        if ($newbillingcycle == "semiannually") {
                            $newbillingcycle = "Semi-Annually";
                        } else {
                            if ($newbillingcycle == "annually") {
                                $newbillingcycle = "Annually";
                            } else {
                                if ($newbillingcycle == "biennially") {
                                    $newbillingcycle = "Biennially";
                                } else {
                                    if ($newbillingcycle == "triennially") {
                                        $newbillingcycle = "Triennially";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $result = select_query("tblhosting", "billingcycle", array("id" => $relid));
        $data = mysql_fetch_array($result);
        $billingcycle = $data['billingcycle'];
        if ($billingcycle == "Free Account") {
            $newnextdue = getInvoicePayUntilDate(date("Y-m-d"), $newbillingcycle, true);
            update_query("tblhosting", array("nextduedate" => $newnextdue, "nextinvoicedate" => $newnextdue), array("id" => $relid));
        }
        if (!function_exists("migrateCustomFieldsBetweenProducts")) {
            require ROOTDIR . "/includes/customfieldfunctions.php";
        }
        migrateCustomFieldsBetweenProducts($relid, $newpackageid);
        update_query("tblhosting", array("packageid" => $newpackageid, "billingcycle" => $newbillingcycle, "" . $changevalue => "+=" . $recurringchange), array("id" => $relid));
        $result = full_query("SELECT tblinvoiceitems.id,tblinvoiceitems.invoiceid FROM tblinvoices INNER JOIN tblinvoiceitems ON tblinvoiceitems.invoiceid=tblinvoices.id INNER JOIN tblhosting ON tblhosting.id=tblinvoiceitems.relid WHERE tblinvoices.status='Unpaid' AND tblinvoiceitems.type='Hosting' AND tblhosting.id=" . (int) $relid . " ORDER BY tblinvoiceitems.duedate DESC");
        $data = mysql_fetch_array($result);
        $invitemid = $data['id'];
        $inviteminvoiceid = $data['invoiceid'];
        if ($invitemid) {
            update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $inviteminvoiceid));
            update_query("tblinvoiceitems", array("duedate" => "0000-00-00"), array("id" => $invitemid));
            full_query("UPDATE tblhosting SET nextinvoicedate=nextduedate WHERE id=" . (int) $relid);
        }
        if (!function_exists("getCartConfigOptions")) {
            require ROOTDIR . "/includes/configoptionsfunctions.php";
        }
        $configoptions = getCartConfigOptions($newpackageid, "", $newbillingcycle);
        foreach ($configoptions as $configoption) {
            $result = select_query("tblhostingconfigoptions", "COUNT(*)", array("relid" => $relid, "configid" => $configoption['id']));
            $data = mysql_fetch_array($result);
            if (!$data[0]) {
                insert_query("tblhostingconfigoptions", array("relid" => $relid, "configid" => $configoption['id'], "optionid" => $configoption['selectedvalue']));
                continue;
            }
        }
        run_hook("AfterProductUpgrade", array("upgradeid" => $upgradeid));
    } else {
        if ($type == "configoptions") {
            $tempvalue = explode("=>", $originalvalue);
            $configid = $tempvalue[0];
            $result = select_query("tblproductconfigoptions", "", array("id" => $configid));
            $data = mysql_fetch_array($result);
            $optiontype = $data['optiontype'];
            $result = select_query("tblhostingconfigoptions", "COUNT(*)", array("relid" => $relid, "configid" => $configid));
            $data = mysql_fetch_array($result);
            if (!$data[0]) {
                insert_query("tblhostingconfigoptions", array("relid" => $relid, "configid" => $configid));
            }
            if ($optiontype == 1 || $optiontype == 2) {
                update_query("tblhostingconfigoptions", array("optionid" => $newvalue), array("relid" => $relid, "configid" => $configid));
            } else {
                if ($optiontype == 3 || $optiontype == 4) {
                    update_query("tblhostingconfigoptions", array("qty" => $newvalue), array("relid" => $relid, "configid" => $configid));
                }
            }
            update_query("tblhosting", array("amount" => "+=" . $recurringchange), array("id" => $relid));
            run_hook("AfterConfigOptionsUpgrade", array("upgradeid" => $upgradeid));
        }
    }
    if ($promocode) {
        $result = select_query("tblpromotions", "id,type,recurring,value", array("code" => $promocode));
        $data = mysql_fetch_array($result);
        $promoid = $data[0];
        $promotype = $data[1];
        $promorecurring = $data[2];
        $promovalue = $data[3];
        if ($promorecurring) {
            $recurringamount = recalcRecurringProductPrice($relid);
            if ($promotype == "Percentage") {
                $discount = $recurringamount * ($promovalue / 100);
                $recurringamount = $recurringamount - $discount;
            } else {
                $recurringamount = $recurringamount < $promovalue ? "0" : $recurringamount - $promovalue;
            }
            update_query("tblhosting", array("amount" => $recurringamount, "promoid" => $promoid), array("id" => $relid));
        } else {
            update_query("tblhosting", array("promoid" => "0"), array("id" => $relid));
        }
    } else {
        update_query("tblhosting", array("promoid" => "0"), array("id" => $relid));
    }
    if ($type == "package" || $type == "configoptions") {
        $data = get_query_vals("tblhosting", "userid,packageid", array("id" => $relid));
        $userid = $data['userid'];
        $pid = $data['packageid'];
        $result = select_query("tblproducts", "servertype,upgradeemail", array("id" => $pid));
        $data = mysql_fetch_array($result);
        $servertype = $data['servertype'];
        $upgradeemail = $data['upgradeemail'];
        if ($servertype) {
            if (!function_exists("getModuleType")) {
                require dirname(__FILE__) . "/modulefunctions.php";
            }
            $result = ServerChangePackage($relid);
            if ($result != "success") {
                logActivity("Automatic Product/Service Upgrade Failed - Service ID: " . $relid, $userid);
            } else {
                logActivity("Automatic Product/Service Upgrade Successful - Service ID: " . $relid, $userid);
                if ($upgradeemail) {
                    $result = select_query("tblemailtemplates", "name", array("id" => $upgradeemail));
                    $data = mysql_fetch_array($result);
                    $emailtplname = $data[0];
                    sendMessage($emailtplname, $relid);
                }
            }
        } else {
            insert_query("tbltodolist", array("date" => "now()", "title" => "Manual Upgrade Required", "description" => "Manual Upgrade Required for Service ID: " . $relid, "admin" => "", "status" => "Pending", "duedate" => date("Y-m-d")));
        }
    }
    update_query("tblupgrades", array("status" => "Completed"), array("id" => $upgradeid));
}
 $tbl->add($aInt->lang("fields", "nextduedate"), in_array($billingcycle, array("One Time", "Free Account")) ? "N/A" : $frm->hidden("oldnextduedate", $nextduedate) . $frm->date("nextduedate", $nextduedate));
 $tbl->add($aInt->lang("fields", "dedicatedip"), $frm->text("dedicatedip", $dedicatedip, "25"));
 $tbl->add($aInt->lang("fields", "billingcycle"), $aInt->cyclesDropDown($billingcycle));
 $tbl->add($aInt->lang("fields", "username"), $frm->text("username", $username, "20") . (function_exists($module . "_LoginLink") ? " " . ServerLoginLink($id) : ""));
 $tbl->add($aInt->lang("fields", "paymentmethod"), paymentMethodsSelection() . " <a href=\"clientsinvoices.php?userid=" . $userid . "&serviceid=" . $id . "\">" . $aInt->lang("invoices", "viewinvoices") . "</a>");
 $tbl->add($aInt->lang("fields", "password"), $frm->text("password", $password, "20"));
 $tbl->add($aInt->lang("fields", "promocode"), $frm->dropdown("promoid", $promoarr, $promoid, "", "", true) . " (" . $aInt->lang("services", "noaffect") . ")");
 $tbl->add($aInt->lang("fields", "status"), $aInt->productStatusDropDown($domainstatus, false, "domainstatus", "prodstatus") . ($domainstatus == "Suspended" ? " (" . $aInt->lang("services", "suspendreason") . ": " . (!$suspendreason ? $_LANG['suspendreasonoverdue'] : $suspendreason) . ")" : ""));
 $tbl->add($aInt->lang("fields", "subscriptionid"), $frm->text("subscriptionid", $subscriptionid, "25"));
 if ($producttype == "server") {
     $tbl->add($aInt->lang("fields", "assignedips"), $frm->textarea("assignedips", $assignedips, "4", "30"), 1);
     $tbl->add($aInt->lang("fields", "nameserver") . " 1", $frm->text("ns1", $ns1, "35"), 1);
     $tbl->add($aInt->lang("fields", "nameserver") . " 2", $frm->text("ns2", $ns2, "35"), 1);
 }
 $configoptions = array();
 $configoptions = getCartConfigOptions($packageid, "", $billingcycle, $id);
 if ($configoptions) {
     foreach ($configoptions as $configoption) {
         $optionid = $configoption['id'];
         $optionhidden = $configoption['hidden'];
         $optionname = $optionhidden ? $configoption['optionname'] . " <i>(" . $aInt->lang("global", "hidden") . ")</i>" : $configoption['optionname'];
         $optiontype = $configoption['optiontype'];
         $selectedvalue = $configoption['selectedvalue'];
         $selectedqty = $configoption['selectedqty'];
         if ($optiontype == "1") {
             $inputcode = "<select name=\"configoption[" . $optionid . "]" . "\">";
             foreach ($configoption['options'] as $option) {
                 $inputcode .= "<option value=\"" . $option['id'] . "\"";
                 if ($option['hidden']) {
                     $inputcode .= " style='color:#ccc;'";
                 }
function getInvoiceProductPromo($amount, $promoid, $userid = "", $serviceid = "", $orderamt = "")
{
    global $_LANG;
    global $currency;
    if (!$promoid) {
        return array();
    }
    $data = get_query_vals("tblpromotions", "", array("id" => $promoid));
    $promo_id = $data['id'];
    if (!$promo_id) {
        return array();
    }
    $promo_code = $data['code'];
    $promo_type = $data['type'];
    $promo_recurring = $data['recurring'];
    $promo_value = $data['value'];
    $promo_recurfor = $data['recurfor'];
    if ($userid) {
        $currency = getCurrency($userid);
    }
    if ($serviceid) {
        $data = get_query_vals("tblhosting", "packageid,regdate,nextduedate,firstpaymentamount,billingcycle", array("id" => $serviceid));
        $pid = $data['packageid'];
        $regdate = $data['regdate'];
        $nextduedate = $data['nextduedate'];
        $firstpaymentamount = $data['firstpaymentamount'];
        $billingcycle = $data['billingcycle'];
        $billingcycle = str_replace("-", "", strtolower($billingcycle));
        if ($billingcycle == "one time") {
            $billingcycle = "monthly";
        }
    }
    if ($serviceid && $promo_recurfor) {
        $promo_recurringcount = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Hosting", "relid" => $serviceid));
        if ($promo_recurfor - 1 < $promo_recurringcount) {
            $amount = getInvoiceProductDefaultPrice($pid, $billingcycle, $regdate, $nextduedate);
            if (!function_exists("getCartConfigOptions")) {
                require ROOTDIR . "/includes/configoptionsfunctions.php";
            }
            $configoptions = getCartConfigOptions($pid, "", $billingcycle, $serviceid);
            foreach ($configoptions as $configoption) {
                $amount += $configoption['selectedrecurring'];
            }
            update_query("tblhosting", array("amount" => $amount, "promoid" => "0"), array("id" => $serviceid));
        }
    }
    if (!$promo_id) {
        return array();
    }
    if (!$serviceid || ($promo_recurring || !$promo_recurring && $regdate == $nextduedate)) {
        if ($promo_type == "Percentage") {
            $promo_amount = round($amount / (1 - $promo_value / 100), 2) - $amount;
            if (0 < $promo_value && $promo_amount <= 0) {
                $promo_amount = $orderamt ? $orderamt : getInvoiceProductDefaultPrice($pid, $billingcycle, $regdate, $nextduedate);
            }
            $promo_value .= "%";
        } else {
            if ($promo_type == "Fixed Amount") {
                if ($currency['id'] != 1) {
                    $promo_value = convertCurrency($promo_value, 1, $currency['id']);
                }
                $default_price = "";
                $default_price = getInvoiceProductDefaultPrice($pid, $billingcycle, $regdate, $nextduedate, $serviceid, $userid);
                if ($default_price < $promo_value) {
                    $promo_value = $default_price;
                }
                $default_price = "";
                $promo_amount = $promo_value;
                $promo_value = formatCurrency($promo_value);
            } else {
                if ($promo_type == "Price Override") {
                    if ($currency['id'] != 1) {
                        $promo_value = convertCurrency($promo_value, 1, $currency['id']);
                    }
                    $promo_amount = $orderamt ? $orderamt : getInvoiceProductDefaultPrice($pid, $billingcycle, $regdate, $nextduedate);
                    $promo_amount -= $promo_value;
                    $promo_value = formatCurrency($promo_value) . " " . $_LANG['orderpromopriceoverride'];
                } else {
                    if ($promo_type == "Free Setup") {
                        $promo_amount = $orderamt ? $orderamt : getInvoiceProductDefaultPrice($pid, $billingcycle, $regdate, $nextduedate);
                        $promo_amount -= $firstpaymentamount;
                        $promo_value = $_LANG['orderpromofreesetup'];
                    }
                }
            }
        }
        getUsersLang($userid);
        $promo_recurring = $promo_recurring ? $_LANG['recurring'] : $_LANG['orderpaymenttermonetime'];
        $promo_description = $_LANG['orderpromotioncode'] . (": " . $promo_code . " - " . $promo_value . " " . $promo_recurring . " ") . $_LANG['orderdiscount'];
        getUsersLang(0);
        return array("description" => $promo_description, "amount" => $promo_amount * (0 - 1));
    }
    return array();
}
Exemple #5
0
        $promo_value .= "%";
    } else {
        $promo_value = formatCurrency($promo_value);
    }
    $promo_recurring = $promo_recurring ? "Recurring" : "One Time";
    echo "<option value=\"" . $promo_code . "\">" . $promo_code . " - " . $promo_value . " " . $promo_recurring . "</option>";
    exit;
}
if ($action == "getconfigoptions") {
    check_token("WHMCS.admin.default");
    releaseSession();
    if (!trim($pid)) {
        exit;
    }
    $options = "";
    $configoptions = getCartConfigOptions($pid, "", $cycle);
    if (count($configoptions)) {
        $options .= "<p><b>" . $aInt->lang("setup", "configoptions") . "</b></p>\n<table class=\"form\" width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">";
        foreach ($configoptions as $configoption) {
            $options .= "<tr><td width=\"130\" class=\"fieldlabel\">" . $configoption['optionname'] . "</td><td class=\"fieldarea\">";
            if ($configoption['optiontype'] == "1") {
                $options .= "<select onchange=\"updatesummary()\" name=\"configoption[" . $orderid . "][" . $configoption['id'] . "]\">";
                foreach ($configoption['options'] as $optiondata) {
                    $options .= "<option value=\"" . $optiondata['id'] . "\"";
                    if ($optiondata['id'] == $configoption['selectedvalue']) {
                        $options .= " selected";
                    }
                    $options .= ">" . $optiondata['name'] . "</option>";
                }
                $options .= "</select>";
            } else {
Exemple #6
0
        $apiresults = array("result" => "error", "message" => "Invalid Payment Method. Valid options include " . implode(",", $gatewaysarray));
        return null;
    }
}
$apiresults['result'] = "success";
if ($type == "product") {
    $upgrades = SumUpPackageUpgradeOrder($serviceid, $newproductid, $newproductbillingcycle, $promocode, $paymentmethod, $checkout);
    $apiresults = array_merge($apiresults, $upgrades[0]);
} else {
    if ($type == "configoptions") {
        $subtotal = 0;
        $result = select_query("tblhosting", "packageid,billingcycle", array("id" => $serviceid));
        $data = mysql_fetch_array($result);
        $pid = $data[0];
        $billingcycle = $data[1];
        $configoption = getCartConfigOptions($pid, "", $billingcycle, $serviceid);
        $configoptions = $_REQUEST['configoptions'];
        if (!is_array($configoptions)) {
            $configoptions = array();
        }
        foreach ($configoption as $option) {
            $id = $option['id'];
            $optiontype = $option['optiontype'];
            $selectedvalue = $option['selectedvalue'];
            $selectedqty = $option['selectedqty'];
            if (!isset($configoptions[$id])) {
                if ($optiontype == "3" || $optiontype == "4") {
                    $selectedvalue = $selectedqty;
                }
                $configoptions[$id] = $selectedvalue;
                continue;
Exemple #7
0
function calcCartTotals($checkout = "", $ignorenoconfig = "")
{
    global $CONFIG;
    global $_LANG;
    global $remote_ip;
    global $currency;
    global $promo_data;
    $cart_total = $cart_discount = $cart_tax = 0;
    run_hook("PreCalculateCartTotals", $_SESSION['cart']);
    if (!$ignorenoconfig) {
        if (array_key_exists("products", $_SESSION['cart'])) {
            foreach ($_SESSION['cart']['products'] as $key => $productdata) {
                if ($productdata['noconfig']) {
                    unset($_SESSION['cart']['products'][$key]);
                    continue;
                }
            }
        }
        $bundlewarnings = bundlesValidateCheckout();
        if (array_key_exists("products", $_SESSION['cart'])) {
            $_SESSION['cart']['products'] = array_values($_SESSION['cart']['products']);
        }
    }
    if ($checkout) {
        if (!$_SESSION['cart']) {
            return false;
        }
        run_hook("PreShoppingCartCheckout", $_SESSION['cart']);
        $order_number = generateUniqueID();
        $paymentmethod = $_SESSION['cart']['paymentmethod'];
        $availablegateways = getAvailableOrderPaymentGateways();
        if (!array_key_exists($paymentmethod, $availablegateways)) {
            foreach ($availablegateways as $k => $v) {
                $paymentmethod = $k;
                break;
            }
        }
        $userid = $_SESSION['uid'];
        $ordernotes = "";
        if ($_SESSION['cart']['notes'] && $_SESSION['cart']['notes'] != $_LANG['ordernotesdescription']) {
            $ordernotes = $_SESSION['cart']['notes'];
        }
        $cartitems = count($_SESSION['cart']['products']) + count($_SESSION['cart']['addons']) + count($_SESSION['cart']['domains']) + count($_SESSION['cart']['renewals']);
        if (!$cartitems) {
            return false;
        }
        $orderid = insert_query("tblorders", array("ordernum" => $order_number, "userid" => $userid, "contactid" => $_SESSION['cart']['contact'], "date" => "now()", "status" => "Pending", "paymentmethod" => $paymentmethod, "ipaddress" => $remote_ip, "notes" => $ordernotes));
        logActivity("New Order Placed - Order ID: " . $orderid . " - User ID: " . $userid);
        $domaineppcodes = array();
    }
    $promotioncode = array_key_exists("promo", $_SESSION['cart']) ? $_SESSION['cart']['promo'] : "";
    if ($promotioncode) {
        $result = select_query("tblpromotions", "", array("code" => $promotioncode));
        $promo_data = mysql_fetch_array($result);
    }
    if (!isset($_SESSION['uid'])) {
        if (!$_SESSION['cart']['user']['country']) {
            $_SESSION['cart']['user']['country'] = $CONFIG['DefaultCountry'];
        }
        $state = $_SESSION['cart']['user']['state'];
        $country = $_SESSION['cart']['user']['country'];
    } else {
        $clientsdetails = getClientsDetails($_SESSION['uid']);
        $state = $clientsdetails['state'];
        $country = $clientsdetails['country'];
    }
    if ($CONFIG['TaxEnabled']) {
        $taxdata = getTaxRate(1, $state, $country);
        $taxname = $taxdata['name'];
        $taxrate = $taxdata['rate'];
        $rawtaxrate = $taxrate;
        $inctaxrate = $taxrate / 100 + 1;
        $taxrate /= 100;
        $taxdata = getTaxRate(2, $state, $country);
        $taxname2 = $taxdata['name'];
        $taxrate2 = $taxdata['rate'];
        $rawtaxrate2 = $taxrate2;
        $inctaxrate2 = $taxrate2 / 100 + 1;
        $taxrate2 /= 100;
    }
    if ($CONFIG['TaxInclusiveDeduct'] && (!$taxrate && !$taxrate2 || $clientsdetails['taxexempt'])) {
        $result = select_query("tbltax", "", "");
        $data = mysql_fetch_array($result);
        $excltaxrate = 1 + $data['taxrate'] / 100;
    } else {
        $CONFIG['TaxInclusiveDeduct'] = 0;
    }
    $cartdata = $productsarray = $tempdomains = $orderproductids = $orderdomainids = $orderaddonids = $orderrenewalids = $freedomains = array();
    $recurring_cycles_total = array("monthly" => 0, "quarterly" => 0, "semiannually" => 0, "annually" => 0, "biennially" => 0, "triennially" => 0);
    if (array_key_exists("products", $_SESSION['cart']) && is_array($_SESSION['cart']['products'])) {
        foreach ($_SESSION['cart']['products'] as $key => $productdata) {
            $result = select_query("tblproducts", "tblproducts.id,tblproducts.gid,tblproductgroups.name AS groupname,tblproducts.name,tblproducts.paytype,tblproducts.allowqty,tblproducts.proratabilling,tblproducts.proratadate,tblproducts.proratachargenextmonth,tblproducts.tax,tblproducts.servertype,tblproducts.servergroup,tblproducts.stockcontrol,tblproducts.freedomain,tblproducts.freedomainpaymentterms,tblproducts.freedomaintlds", array("tblproducts.id" => $productdata['pid']), "", "", "", "tblproductgroups ON tblproductgroups.id=tblproducts.gid");
            $data = mysql_fetch_array($result);
            $pid = $data['id'];
            $gid = $data['gid'];
            $groupname = $data['groupname'];
            $productname = $data['name'];
            $paytype = $data['paytype'];
            $allowqty = $data['allowqty'];
            $proratabilling = $data['proratabilling'];
            $proratadate = $data['proratadate'];
            $proratachargenextmonth = $data['proratachargenextmonth'];
            $tax = $data['tax'];
            $servertype = $data['servertype'];
            $servergroup = $data['servergroup'];
            $stockcontrol = $data['stockcontrol'];
            $freedomain = $data['freedomain'];
            if ($freedomain) {
                $freedomainpaymentterms = $data['freedomainpaymentterms'];
                $freedomaintlds = $data['freedomaintlds'];
                $freedomainpaymentterms = explode(",", $freedomainpaymentterms);
                $freedomaintlds = explode(",", $freedomaintlds);
            } else {
                $freedomainpaymentterms = $freedomaintlds = array();
            }
            $productinfo = getProductInfo($pid);
            $productdata['productinfo'] = $productinfo;
            if (!function_exists("getCustomFields")) {
                require ROOTDIR . "/includes/customfieldfunctions.php";
            }
            $customfields = getCustomFields("product", $pid, "", true, "", $productdata['customfields']);
            $productdata['customfields'] = $customfields;
            $pricing = getPricingInfo($pid);
            $qty = $productdata['qty'];
            if (!$allowqty || !$qty) {
                $qty = 1;
            }
            $productdata['allowqty'] = $allowqty;
            $productdata['qty'] = $qty;
            if ($pricing['type'] == "recurring") {
                $billingcycle = strtolower($productdata['billingcycle']);
                if (!in_array($billingcycle, array("monthly", "quarterly", "semiannually", "annually", "biennially", "triennially"))) {
                    $billingcycle = "";
                }
                if ($pricing['rawpricing'][$billingcycle] < 0) {
                    $billingcycle = "";
                }
                if (!$billingcycle) {
                    if (0 <= $pricing['rawpricing']['monthly']) {
                        $billingcycle = "monthly";
                    } else {
                        if (0 <= $pricing['rawpricing']['quarterly']) {
                            $billingcycle = "quarterly";
                        } else {
                            if (0 <= $pricing['rawpricing']['semiannually']) {
                                $billingcycle = "semiannually";
                            } else {
                                if (0 <= $pricing['rawpricing']['annually']) {
                                    $billingcycle = "annually";
                                } else {
                                    if (0 <= $pricing['rawpricing']['biennially']) {
                                        $billingcycle = "biennially";
                                    } else {
                                        if (0 <= $pricing['rawpricing']['triennially']) {
                                            $billingcycle = "triennially";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($pricing['type'] == "onetime") {
                    $billingcycle = "onetime";
                } else {
                    $billingcycle = "free";
                }
            }
            $productdata['billingcycle'] = $billingcycle;
            if ($billingcycle == "free") {
                $product_setup = $product_onetime = $product_recurring = "0";
                $databasecycle = "Free Account";
            } else {
                if ($billingcycle == "onetime") {
                    $product_setup = $pricing['rawpricing']['msetupfee'];
                    $product_onetime = $pricing['rawpricing']['monthly'];
                    $product_recurring = 0;
                    $databasecycle = "One Time";
                } else {
                    $product_setup = $pricing['rawpricing'][substr($billingcycle, 0, 1) . "setupfee"];
                    $product_onetime = $product_recurring = $pricing['rawpricing'][$billingcycle];
                    $databasecycle = ucfirst($billingcycle);
                    if ($databasecycle == "Semiannually") {
                        $databasecycle = "Semi-Annually";
                    }
                }
            }
            $before_priceoverride_value = "";
            if ($bundleoverride = bundlesGetProductPriceOverride("product", $key)) {
                $before_priceoverride_value = $product_setup + $product_onetime;
                $product_setup = 0;
                $product_onetime = $product_recurring = $bundleoverride;
            }
            $hookret = run_hook("OrderProductPricingOverride", array("key" => $key, "pid" => $pid, "proddata" => $productdata));
            foreach ($hookret as $hookret2) {
                if (is_array($hookret2)) {
                    if ($hookret2['setup']) {
                        $product_setup = $hookret2['setup'];
                    }
                    if ($hookret2['recurring']) {
                        $product_onetime = $product_recurring = $hookret2['recurring'];
                        continue;
                    }
                    continue;
                }
            }
            $productdata['pricing']['baseprice'] = formatCurrency($product_onetime);
            $configurableoptions = array();
            $configurableoptions = getCartConfigOptions($pid, $productdata['configoptions'], $billingcycle);
            $configoptions = "";
            if ($configurableoptions) {
                foreach ($configurableoptions as $confkey => $value) {
                    $configoptions[] = array("name" => $value['optionname'], "type" => $value['optiontype'], "option" => $value['selectedoption'], "optionname" => $value['selectedname'], "setup" => 0 < $value['selectedsetup'] ? formatCurrency($value['selectedsetup']) : "", "recurring" => formatCurrency($value['selectedrecurring']), "qty" => $value['selectedqty']);
                    $configoptionsdb[$value['id']] = array("value" => $value['selectedvalue'], "qty" => $value['selectedqty']);
                    $product_setup += $value['selectedsetup'];
                    $product_onetime += $value['selectedrecurring'];
                    if (strlen($before_priceoverride_value)) {
                        $before_priceoverride_value += $value['selectedrecurring'];
                    }
                    if ($billingcycle != "onetime") {
                        $product_recurring += $value['selectedrecurring'];
                        continue;
                    }
                }
            }
            $productdata['configoptions'] = $configoptions;
            if (in_array($billingcycle, $freedomainpaymentterms)) {
                $domain = $productdata['domain'];
                $domainparts = explode(".", $domain, 2);
                $tld = "." . $domainparts[1];
                if (in_array($tld, $freedomaintlds)) {
                    $freedomains[$domain] = $freedomain;
                }
            }
            if ($proratabilling) {
                $proratavalues = getProrataValues($billingcycle, $product_onetime, $proratadate, $proratachargenextmonth, date("d"), date("m"), date("Y"), $_SESSION['uid']);
                $product_onetime = $proratavalues['amount'];
                $productdata['proratadate'] = fromMySQLDate($proratavalues['date']);
            }
            if ($CONFIG['TaxInclusiveDeduct']) {
                $product_setup = format_as_currency($product_setup / $excltaxrate);
                $product_onetime = format_as_currency($product_onetime / $excltaxrate);
                $product_recurring = format_as_currency($product_recurring / $excltaxrate);
            }
            $product_total_today_db = $product_setup + $product_onetime;
            $product_recurring_db = $product_recurring;
            $productdata['pricing']['setup'] = $product_setup * $qty;
            $productdata['pricing']['recurring'][$billingcycle] = $product_recurring * $qty;
            $productdata['pricing']['totaltoday'] = $product_total_today_db * $qty;
            if ($product_onetime == 0 && $product_recurring == 0) {
                $pricing_text = $_LANG['orderfree'];
            } else {
                $pricing_text = "";
                if (strlen($before_priceoverride_value)) {
                    $pricing_text .= "<strike>" . formatCurrency($before_priceoverride_value) . "</strike> ";
                }
                $pricing_text .= formatCurrency($product_onetime);
                if (0 < $product_setup) {
                    $pricing_text .= " + " . formatCurrency($product_setup) . " " . $_LANG['ordersetupfee'];
                }
                if ($allowqty && 1 < $qty) {
                    $pricing_text .= $_LANG['invoiceqtyeach'] . "<br />" . $_LANG['invoicestotal'] . ": " . formatCurrency($productdata['pricing']['totaltoday']);
                }
            }
            $productdata['pricingtext'] = $pricing_text;
            if ($promotioncode) {
                $onetimediscount = $recurringdiscount = $promoid = 0;
                if ($promocalc = CalcPromoDiscount($pid, $databasecycle, $product_total_today_db, $product_recurring_db, $product_setup)) {
                    $onetimediscount = $promocalc['onetimediscount'];
                    $recurringdiscount = $promocalc['recurringdiscount'];
                    $product_total_today_db -= $onetimediscount;
                    $product_recurring_db -= $recurringdiscount;
                    $cart_discount += $onetimediscount * $qty;
                    $promoid = $promo_data['id'];
                }
            }
            if (isset($productdata['priceoverride'])) {
                $product_total_today_db = $product_recurring_db = $product_onetime = $productdata['priceoverride'];
                $product_setup = 0;
            }
            $cart_total += $product_total_today_db * $qty;
            $product_total_qty_recurring = $product_recurring_db * $qty;
            if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt']) {
                $cart_tax += $product_total_today_db * $qty;
                if ($CONFIG['TaxType'] == "Exclusive") {
                    if ($CONFIG['TaxL2Compound']) {
                        $product_total_qty_recurring += $product_total_qty_recurring * $taxrate;
                        $product_total_qty_recurring += $product_total_qty_recurring * $taxrate2;
                    } else {
                        $product_total_qty_recurring += $product_total_qty_recurring * $taxrate + $product_total_qty_recurring * $taxrate2;
                    }
                }
            }
            $recurring_cycles_total[$billingcycle] += $product_total_qty_recurring;
            $domain = $productdata['domain'];
            $serverhostname = $productdata['server']['hostname'];
            $serverns1prefix = $productdata['server']['ns1prefix'];
            $serverns2prefix = $productdata['server']['ns2prefix'];
            $serverrootpw = encrypt($productdata['server']['rootpw']);
            if ($serverns1prefix && $domain) {
                $serverns1prefix = $serverns1prefix . "." . $domain;
            }
            if ($serverns2prefix && $domain) {
                $serverns2prefix = $serverns2prefix . "." . $domain;
            }
            if ($serverhostname) {
                $domain = $domain ? $serverhostname . "." . $domain : $serverhostname;
            }
            $productdata['domain'] = $domain;
            if ($checkout) {
                $multiqtyids = array();
                $qtycount = 1;
                while ($qtycount <= $qty) {
                    $serverid = $servertype ? getServerID($servertype, $servergroup) : "0";
                    $hostingquerydates = $databasecycle == "Free Account" ? "0000-00-00" : date("Y-m-d");
                    $serviceid = insert_query("tblhosting", array("userid" => $userid, "orderid" => $orderid, "packageid" => $pid, "server" => $serverid, "regdate" => "now()", "domain" => $domain, "paymentmethod" => $paymentmethod, "firstpaymentamount" => $product_total_today_db, "amount" => $product_recurring_db, "billingcycle" => $databasecycle, "nextduedate" => $hostingquerydates, "nextinvoicedate" => $hostingquerydates, "domainstatus" => "Pending", "ns1" => $serverns1prefix, "ns2" => $serverns2prefix, "password" => $serverrootpw, "promoid" => $promoid));
                    $multiqtyids[$qtycount] = $serviceid;
                    $orderproductids[] = $serviceid;
                    if ($stockcontrol) {
                        full_query("UPDATE tblproducts SET qty=qty-1 WHERE id='" . mysql_real_escape_string($pid) . "'");
                    }
                    if ($configoptionsdb) {
                        foreach ($configoptionsdb as $key => $value) {
                            insert_query("tblhostingconfigoptions", array("relid" => $serviceid, "configid" => $key, "optionid" => $value['value'], "qty" => $value['qty']));
                        }
                    }
                    foreach ($productdata['customfields'] as $key => $value) {
                        insert_query("tblcustomfieldsvalues", array("fieldid" => $value['id'], "relid" => $serviceid, "value" => $value['rawvalue']));
                    }
                    $productdetails = getInvoiceProductDetails($serviceid, $pid, date("Y-m-d"), $hostingquerydates, $databasecycle, $domain);
                    $invoice_description = $productdetails['description'];
                    $invoice_tax = $productdetails['tax'];
                    if (!$_SESSION['cart']['geninvoicedisabled']) {
                        $prodinvoicearray = array();
                        $prodinvoicearray['userid'] = $userid;
                        $prodinvoicearray['type'] = "Hosting";
                        $prodinvoicearray['relid'] = $serviceid;
                        $prodinvoicearray['taxed'] = $invoice_tax;
                        $prodinvoicearray['duedate'] = $hostingquerydates;
                        $prodinvoicearray['paymentmethod'] = $paymentmethod;
                        if (0 < $product_setup) {
                            $prodinvoicearray['description'] = $productname . " " . $_LANG['ordersetupfee'];
                            $prodinvoicearray['amount'] = $product_setup;
                            insert_query("tblinvoiceitems", $prodinvoicearray);
                            $prodinvoicearray['type'] = "";
                            $prodinvoicearray['relid'] = 0;
                        }
                        if (0 < $product_onetime) {
                            $prodinvoicearray['description'] = $invoice_description;
                            $prodinvoicearray['amount'] = $product_onetime;
                            insert_query("tblinvoiceitems", $prodinvoicearray);
                        }
                        $promovals = getInvoiceProductPromo($product_total_today_db, $promoid, $userid, $serviceid, $product_setup + $product_onetime);
                        if ($promovals['description']) {
                            $prodinvoicearray['type'] = "PromoHosting";
                            $prodinvoicearray['description'] = $promovals['description'];
                            $prodinvoicearray['amount'] = $promovals['amount'];
                            insert_query("tblinvoiceitems", $prodinvoicearray);
                        }
                    }
                    $adminemailitems .= $_LANG['orderproduct'] . (": " . $groupname . " - " . $productname . "<br>\r\n");
                    if ($domain) {
                        $adminemailitems .= $_LANG['orderdomain'] . (": " . $domain . "<br>\r\n");
                    }
                    foreach ($configurableoptions as $confkey => $value) {
                        $adminemailitems .= $value['optionname'] . ": " . $value['selectedname'] . "<br />\r\n";
                    }
                    foreach ($customfields as $customfield) {
                        if (!$customfield['adminonly']) {
                            $adminemailitems .= "" . $customfield['name'] . ": " . $customfield['value'] . "<br />\r\n";
                            continue;
                        }
                    }
                    $adminemailitems .= $_LANG['firstpaymentamount'] . ": " . formatCurrency($product_total_today_db) . "<br>\r\n";
                    if ($product_recurring_db) {
                        $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($product_recurring_db) . "<br>\r\n";
                    }
                    $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($databasecycle))] . "<br>\r\n";
                    if ($allowqty && 1 < $qty) {
                        $adminemailitems .= $_LANG['quantity'] . (": " . $qty . "<br>\r\n") . $_LANG['invoicestotal'] . ": " . $productdata['pricing']['totaltoday'] . "<br>\r\n";
                    }
                    $adminemailitems .= "<br>\r\n";
                    ++$qtycount;
                }
            }
            $addonsarray = array();
            $addons = $productdata['addons'];
            if ($addons) {
                foreach ($addons as $addonid) {
                    $result = select_query("tbladdons", "name,description,billingcycle,tax", array("id" => $addonid));
                    $data = mysql_fetch_array($result);
                    $addon_name = $data['name'];
                    $addon_description = $data['description'];
                    $addon_billingcycle = $data['billingcycle'];
                    $addon_tax = $data['tax'];
                    if (!$CONFIG['TaxEnabled']) {
                        $addon_tax = "";
                    }
                    $result = select_query("tblpricing", "msetupfee,monthly", array("type" => "addon", "currency" => $currency['id'], "relid" => $addonid));
                    $data = mysql_fetch_array($result);
                    $addon_setupfee = $data['msetupfee'];
                    $addon_recurring = $data['monthly'];
                    $hookret = run_hook("OrderAddonPricingOverride", array("key" => $key, "pid" => $pid, "addonid" => $addonid, "proddata" => $productdata));
                    foreach ($hookret as $hookret2) {
                        if (is_array($hookret2)) {
                            if ($hookret2['setup']) {
                                $addon_setupfee = $hookret2['setup'];
                            }
                            if ($hookret2['recurring']) {
                                $addon_recurring = $hookret2['recurring'];
                                continue;
                            }
                            continue;
                        }
                    }
                    $addon_total_today_db = $addon_setupfee + $addon_recurring;
                    $addon_recurring_db = $addon_recurring;
                    $addon_total_today = $addon_total_today_db * $qty;
                    if ($CONFIG['TaxInclusiveDeduct']) {
                        $addon_total_today_db = round($addon_total_today_db / $excltaxrate, 2);
                        $addon_recurring_db = round($addon_recurring_db / $excltaxrate, 2);
                    }
                    if ($promotioncode) {
                        $onetimediscount = $recurringdiscount = $promoid = 0;
                        if ($promocalc = CalcPromoDiscount("A" . $addonid, $addon_billingcycle, $addon_total_today_db, $addon_recurring_db, $addon_setupfee)) {
                            $onetimediscount = $promocalc['onetimediscount'];
                            $recurringdiscount = $promocalc['recurringdiscount'];
                            $addon_total_today_db -= $onetimediscount;
                            $addon_recurring_db -= $recurringdiscount;
                            $cart_discount += $onetimediscount * $qty;
                        }
                    }
                    if ($checkout) {
                        $qtycount = 1;
                        while ($qtycount <= $qty) {
                            $serviceid = $multiqtyids[$qtycount];
                            $addonsetupfee = $addon_total_today_db - $addon_recurring_db;
                            $aid = insert_query("tblhostingaddons", array("hostingid" => $serviceid, "addonid" => $addonid, "orderid" => $orderid, "regdate" => "now()", "name" => "", "setupfee" => $addonsetupfee, "recurring" => $addon_recurring_db, "billingcycle" => $addon_billingcycle, "status" => "Pending", "nextduedate" => "now()", "nextinvoicedate" => "now()", "paymentmethod" => $paymentmethod, "tax" => $addon_tax));
                            $orderaddonids[] = $aid;
                            $adminemailitems .= $_LANG['clientareaaddon'] . (": " . $addon_name . "<br>\r\n") . $_LANG['ordersetupfee'] . ": " . formatCurrency($addonsetupfee) . "<br>\r\n";
                            if ($addon_recurring_db) {
                                $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($addon_recurring_db) . "<br>\r\n";
                            }
                            $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($addon_billingcycle))] . "<br>\r\n<br>\r\n";
                            ++$qtycount;
                        }
                    }
                    $addon_total_today_db *= $qty;
                    $cart_total += $addon_total_today_db;
                    $addon_recurring_db *= $qty;
                    if ($addon_tax && !$clientsdetails['taxexempt']) {
                        $cart_tax += $addon_total_today_db;
                        if ($CONFIG['TaxType'] == "Exclusive") {
                            if ($CONFIG['TaxL2Compound']) {
                                $addon_recurring_db += $addon_recurring_db * $taxrate;
                                $addon_recurring_db += $addon_recurring_db * $taxrate2;
                            } else {
                                $addon_recurring_db += $addon_recurring_db * $taxrate + $addon_recurring_db * $taxrate2;
                            }
                        }
                    }
                    $addon_billingcycle = str_replace(array("-", " "), "", strtolower($addon_billingcycle));
                    $recurring_cycles_total[$addon_billingcycle] += $addon_recurring_db;
                    if ($addon_setupfee == "0" && $addon_recurring == "0") {
                        $pricing_text = $_LANG['orderfree'];
                    } else {
                        $pricing_text = formatCurrency($addon_recurring);
                        if ($addon_setupfee != "0.00") {
                            $pricing_text .= " + " . formatCurrency($addon_setupfee) . " " . $_LANG['ordersetupfee'];
                        }
                        if ($allowqty && 1 < $qty) {
                            $pricing_text .= $_LANG['invoiceqtyeach'] . "<br />" . $_LANG['invoicestotal'] . ": " . formatCurrency($addon_total_today);
                        }
                    }
                    $addonsarray[] = array("name" => $addon_name, "pricingtext" => $pricing_text, "setup" => formatCurrency($addon_setupfee), "recurring" => formatCurrency($addon_recurring), "totaltoday" => formatCurrency($addon_total_today));
                    $productdata['pricing']['setup'] += $addon_setupfee * $qty;
                    $productdata['pricing']['addons'] += $addon_recurring * $qty;
                    $productdata['pricing']['recurring'][$addon_billingcycle] += $addon_recurring * $qty;
                    $productdata['pricing']['totaltoday'] += $addon_total_today;
                }
            }
            $productdata['addons'] = $addonsarray;
            $totaltaxrates = 1;
            if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt']) {
                $product_tax = $productdata['pricing']['totaltoday'];
                if ($CONFIG['TaxType'] == "Inclusive") {
                    $totaltaxrates = 1 + ($taxrate + $taxrate2);
                    $total_without_tax = $productdata['pricing']['totaltoday'] = $product_tax / $totaltaxrates;
                    $total_tax_1 = $total_without_tax * $taxrate;
                    $total_tax_2 = $total_without_tax * $taxrate2;
                } else {
                    $total_tax_1 = $product_tax * $taxrate;
                    if ($CONFIG['TaxL2Compound']) {
                        $total_tax_2 = ($product_tax + $total_tax_1) * $taxrate2;
                    } else {
                        $total_tax_2 = $product_tax * $taxrate2;
                    }
                }
                $total_tax_1 = round($total_tax_1, 2);
                $total_tax_2 = round($total_tax_2, 2);
                $productdata['pricing']['totaltoday'] += $total_tax_1 + $total_tax_2;
                if (0 < $total_tax_1) {
                    $productdata['pricing']['tax1'] = formatCurrency($total_tax_1);
                }
                if (0 < $total_tax_2) {
                    $productdata['pricing']['tax2'] = formatCurrency($total_tax_2);
                }
            }
            $productdata['pricing']['setup'] = formatCurrency($productdata['pricing']['setup']);
            foreach ($productdata['pricing']['recurring'] as $cycle => $recurring) {
                unset($productdata['pricing']['recurring'][$cycle]);
                if (0 < $recurring) {
                    $recurringwithtax = $recurring;
                    if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt'] && $CONFIG['TaxType'] == "Exclusive") {
                        $rectax = $recurringwithtax * $taxrate;
                        if ($CONFIG['TaxL2Compound']) {
                            $rectax += ($recurringwithtax + $rectax) * $taxrate2;
                        } else {
                            $rectax += $recurringwithtax * $taxrate2;
                        }
                        $recurringwithtax += $rectax;
                    }
                    $productdata['pricing']['recurring'][$_LANG["orderpaymentterm" . $cycle]] = formatCurrency($recurringwithtax);
                    $productdata['pricing']['recurringexcltax'][$_LANG["orderpaymentterm" . $cycle]] = formatCurrency($recurring / $totaltaxrates);
                    continue;
                }
            }
            if (0 < $productdata['pricing']['addons']) {
                $productdata['pricing']['addons'] = formatCurrency($productdata['pricing']['addons']);
            }
            $productdata['pricing']['totaltoday'] = formatCurrency($productdata['pricing']['totaltoday']);
            $productsarray[$key] = $productdata;
        }
    }
    $cartdata['products'] = $productsarray;
    $addonsarray = array();
    if (array_key_exists("addons", $_SESSION['cart']) && is_array($_SESSION['cart']['addons'])) {
        foreach ($_SESSION['cart']['addons'] as $key => $addon) {
            $addonid = $addon['id'];
            $serviceid = $addon['productid'];
            $result = select_query("tbladdons", "name,description,billingcycle,tax", array("id" => $addonid));
            $data = mysql_fetch_array($result);
            $addon_name = $data['name'];
            $addon_description = $data['description'];
            $addon_billingcycle = $data['billingcycle'];
            $addon_tax = $data['tax'];
            if (!$CONFIG['TaxEnabled']) {
                $addon_tax = "";
            }
            $result = select_query("tblpricing", "msetupfee,monthly", array("type" => "addon", "currency" => $currency['id'], "relid" => $addonid));
            $data = mysql_fetch_array($result);
            $addon_setupfee = $data['msetupfee'];
            $addon_recurring = $data['monthly'];
            $hookret = run_hook("OrderAddonPricingOverride", array("key" => $key, "addonid" => $addonid, "serviceid" => $serviceid));
            foreach ($hookret as $hookret2) {
                if (strlen($hookret2)) {
                    if ($hookret2['setup']) {
                        $addon_setupfee = $hookret2['setup'];
                    }
                    if ($hookret2['recurring']) {
                        $addon_recurring = $hookret2['recurring'];
                        continue;
                    }
                    continue;
                }
            }
            $addon_total_today_db = $addon_setupfee + $addon_recurring;
            $addon_recurring_db = $addon_recurring;
            if ($CONFIG['TaxInclusiveDeduct']) {
                $addon_total_today_db = round($addon_total_today_db / $excltaxrate, 2);
                $addon_recurring_db = round($addon_recurring_db / $excltaxrate, 2);
            }
            if ($promotioncode) {
                $onetimediscount = $recurringdiscount = $promoid = 0;
                if ($promocalc = CalcPromoDiscount("A" . $addonid, $addon_billingcycle, $addon_total_today_db, $addon_recurring_db, $addon_setupfee)) {
                    $onetimediscount = $promocalc['onetimediscount'];
                    $recurringdiscount = $promocalc['recurringdiscount'];
                    $addon_total_today_db -= $onetimediscount;
                    $addon_recurring_db -= $recurringdiscount;
                    $cart_discount += $onetimediscount;
                }
            }
            if ($checkout) {
                $addonsetupfee = $addon_total_today_db - $addon_recurring_db;
                $aid = insert_query("tblhostingaddons", array("hostingid" => $serviceid, "addonid" => $addonid, "orderid" => $orderid, "regdate" => "now()", "name" => "", "setupfee" => $addonsetupfee, "recurring" => $addon_recurring_db, "billingcycle" => $addon_billingcycle, "status" => "Pending", "nextduedate" => "now()", "nextinvoicedate" => "now()", "paymentmethod" => $paymentmethod, "tax" => $addon_tax));
                $orderaddonids[] = $aid;
                $adminemailitems .= $_LANG['clientareaaddon'] . (": " . $addon_name . "<br>\r\n") . $_LANG['ordersetupfee'] . ": " . formatCurrency($addonsetupfee) . "<br>\r\n";
                if ($addon_recurring_db) {
                    $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($addon_recurring_db) . "<br>\r\n";
                }
                $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($addon_billingcycle))] . "<br>\r\n<br>\r\n";
            }
            $cart_total += $addon_total_today_db;
            if ($addon_tax && !$clientsdetails['taxexempt']) {
                $cart_tax += $addon_total_today_db;
                if ($CONFIG['TaxType'] == "Exclusive") {
                    if ($CONFIG['TaxL2Compound']) {
                        $addon_recurring_db += $addon_recurring_db * $taxrate;
                        $addon_recurring_db += $addon_recurring_db * $taxrate2;
                    } else {
                        $addon_recurring_db = $addon_recurring_db + $addon_recurring_db * $taxrate + $addon_recurring_db * $taxrate2;
                    }
                }
            }
            $addon_billingcycle = str_replace(array("-", " "), "", strtolower($addon_billingcycle));
            $recurring_cycles_total[$addon_billingcycle] += $addon_recurring_db;
            if ($addon_setupfee == "0" && $addon_recurring == "0") {
                $pricing_text = $_LANG['orderfree'];
            } else {
                $pricing_text = formatCurrency($addon_recurring);
                if ($addon_setupfee != "0.00") {
                    $pricing_text .= " + " . formatCurrency($addon_setupfee) . " " . $_LANG['ordersetupfee'];
                }
            }
            $result = select_query("tblhosting", "tblproducts.name,tblhosting.domain", array("tblhosting.id" => $serviceid), "", "", "", "tblproducts ON tblproducts.id=tblhosting.packageid");
            $data = mysql_fetch_array($result);
            $productname = $data['name'];
            $domainname = $data['domain'];
            $addonsarray[] = array("name" => $addon_name, "productname" => $productname, "domainname" => $domainname, "pricingtext" => $pricing_text);
        }
        $cartdata['addons'] = $addonsarray;
    }
    include ROOTDIR . "/includes/additionaldomainfields.php";
    $totaldomainprice = 0;
    if (array_key_exists("domains", $_SESSION['cart']) && is_array($_SESSION['cart']['domains'])) {
        $result = select_query("tblpricing", "", array("type" => "domainaddons", "currency" => $currency['id'], "relid" => 0));
        $data = mysql_fetch_array($result);
        $domaindnsmanagementprice = $data['msetupfee'];
        $domainemailforwardingprice = $data['qsetupfee'];
        $domainidprotectionprice = $data['ssetupfee'];
        foreach ($_SESSION['cart']['domains'] as $key => $domain) {
            $domaintype = $domain['type'];
            $domainname = $domain['domain'];
            $regperiod = $domain['regperiod'];
            $domainparts = explode(".", $domainname, 2);
            $sld = $domainparts[0];
            $tld = $domainparts[1];
            $temppricelist = getTLDPriceList("." . $tld);
            if (!isset($temppricelist[$regperiod][$domaintype])) {
                $tldyears = array_keys($temppricelist);
                $regperiod = $tldyears[0];
            }
            if (!isset($temppricelist[$regperiod][$domaintype])) {
                exit("Invalid TLD/Registration Period Supplied for Domain Registration");
            }
            if (array_key_exists($domainname, $freedomains)) {
                $tldyears = array_keys($temppricelist);
                $regperiod = $tldyears[0];
                $domainprice = "0.00";
                $renewprice = $freedomains[$domainname] == "once" ? $temppricelist[$regperiod]['renew'] : ($renewprice = "0.00");
            } else {
                $domainprice = $temppricelist[$regperiod][$domaintype];
                $renewprice = $temppricelist[$regperiod]['renew'];
            }
            $before_priceoverride_value = "";
            if ($bundleoverride = bundlesGetProductPriceOverride("domain", $key)) {
                $before_priceoverride_value = $domainprice;
                $domainprice = $renewprice = $bundleoverride;
            }
            $hookret = run_hook("OrderDomainPricingOverride", array("type" => $domaintype, "domain" => $domainname, "regperiod" => $regperiod, "dnsmanagement" => $domain['dnsmanagement'], "emailforwarding" => $domain['emailforwarding'], "idprotection" => $domain['idprotection'], "eppcode" => html_entity_decode($domain['eppcode'])));
            foreach ($hookret as $hookret2) {
                if (strlen($hookret2)) {
                    $before_priceoverride_value = $domainprice;
                    $domainprice = $hookret2;
                    continue;
                }
            }
            if ($domain['dnsmanagement']) {
                $dnsmanagement = true;
                $domainprice += $domaindnsmanagementprice * $regperiod;
                $renewprice += $domaindnsmanagementprice * $regperiod;
                if (strlen($before_priceoverride_value)) {
                    $before_priceoverride_value += $domaindnsmanagementprice * $regperiod;
                }
            } else {
                $dnsmanagement = false;
            }
            if ($domain['emailforwarding']) {
                $emailforwarding = true;
                $domainprice += $domainemailforwardingprice * $regperiod;
                $renewprice += $domainemailforwardingprice * $regperiod;
                if (strlen($before_priceoverride_value)) {
                    $before_priceoverride_value += $domainemailforwardingprice * $regperiod;
                }
            } else {
                $emailforwarding = false;
            }
            if ($domain['idprotection']) {
                $idprotection = true;
                $domainprice += $domainidprotectionprice * $regperiod;
                $renewprice += $domainidprotectionprice * $regperiod;
                if (strlen($before_priceoverride_value)) {
                    $before_priceoverride_value += $domainidprotectionprice * $regperiod;
                }
            } else {
                $idprotection = false;
            }
            if ($CONFIG['TaxInclusiveDeduct']) {
                $domainprice = round($domainprice / $excltaxrate, 2);
                $renewprice = round($renewprice / $excltaxrate, 2);
            }
            $domain_price_db = $domainprice;
            $domain_renew_price_db = $renewprice;
            if ($promotioncode) {
                $onetimediscount = $recurringdiscount = $promoid = 0;
                if ($promocalc = CalcPromoDiscount("D." . $tld, $regperiod . "Years", $domain_price_db, $domain_renew_price_db)) {
                    $onetimediscount = $promocalc['onetimediscount'];
                    $recurringdiscount = $promocalc['recurringdiscount'];
                    $domain_price_db -= $onetimediscount;
                    $domain_renew_price_db -= $recurringdiscount;
                    $cart_discount += $onetimediscount;
                    $promoid = $promo_data['id'];
                }
            }
            if ($regperiod == "1") {
                $domain_billing_cycle = "annually";
            } else {
                if ($regperiod == "2") {
                    $domain_billing_cycle = "biennially";
                } else {
                    if ($regperiod == "3") {
                        $domain_billing_cycle = "triennially";
                    }
                }
            }
            $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db;
            if ($CONFIG['TaxEnabled'] && $CONFIG['TaxDomains'] && $CONFIG['TaxType'] == "Exclusive" && !$clientsdetails['taxexempt']) {
                if ($CONFIG['TaxL2Compound']) {
                    $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db * $taxrate + ($domain_renew_price_db + $domain_renew_price_db * $taxrate) * $taxrate2;
                } else {
                    $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db * $taxrate + $domain_renew_price_db * $taxrate2;
                }
            }
            if ($checkout) {
                $donotrenew = $CONFIG['DomainAutoRenewDefault'] ? "" : "on";
                $domainid = insert_query("tbldomains", array("userid" => $userid, "orderid" => $orderid, "type" => $domaintype, "registrationdate" => "now()", "domain" => $domainname, "firstpaymentamount" => $domain_price_db, "recurringamount" => $domain_renew_price_db, "registrationperiod" => $regperiod, "status" => "Pending", "paymentmethod" => $paymentmethod, "expirydate" => "00000000", "nextduedate" => "now()", "nextinvoicedate" => "now()", "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection, "donotrenew" => $donotrenew, "promoid" => $promoid));
                $orderdomainids[] = $domainid;
                $adminemailitems .= $_LANG['orderdomainregistration'] . ": " . ucfirst($domaintype) . "<br>\r\n" . $_LANG['orderdomain'] . (": " . $domainname . "<br>\r\n") . $_LANG['firstpaymentamount'] . ": " . formatCurrency($domain_price_db) . "<br>\r\n" . $_LANG['recurringamount'] . ": " . formatCurrency($domain_renew_price_db) . "<br>\r\n" . $_LANG['orderregperiod'] . (": " . $regperiod . " ") . $_LANG['orderyears'] . "<br>\r\n";
                if ($dnsmanagement) {
                    $adminemailitems .= " + " . $_LANG['domaindnsmanagement'] . "<br>\r\n";
                }
                if ($emailforwarding) {
                    $adminemailitems .= " + " . $_LANG['domainemailforwarding'] . "<br>\r\n";
                }
                if ($idprotection) {
                    $adminemailitems .= " + " . $_LANG['domainidprotection'] . "<br>\r\n";
                }
                $adminemailitems .= "<br>\r\n";
                if ($domaintype == "register") {
                    unset($tempdomainfields);
                    $tempdomainfields = $additionaldomainfields["." . $tld];
                    if ($tempdomainfields) {
                        foreach ($tempdomainfields as $fieldkey => $value) {
                            $storedvalue = $domain['fields'][$fieldkey];
                            insert_query("tbldomainsadditionalfields", array("domainid" => $domainid, "name" => $value['Name'], "value" => $storedvalue));
                        }
                    }
                }
                if ($domaintype == "transfer" && $domain['eppcode']) {
                    $domaineppcodes[$domainname] = html_entity_decode($domain['eppcode']);
                }
            }
            $pricing_text = "";
            if (strlen($before_priceoverride_value)) {
                $pricing_text .= "<strike>" . formatCurrency($before_priceoverride_value) . "</strike> ";
            }
            $pricing_text .= formatCurrency($domainprice);
            $tempdomains[$key] = array("type" => $domaintype, "domain" => $domainname, "regperiod" => $regperiod, "price" => $pricing_text, "renewprice" => formatCurrency($renewprice), "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection, "eppvalue" => $domain['eppcode']);
            $totaldomainprice += $domain_price_db;
        }
    }
    $cartdata['domains'] = $tempdomains;
    $cart_total += $totaldomainprice;
    if ($CONFIG['TaxDomains']) {
        $cart_tax += $totaldomainprice;
    }
    $orderrenewals = "";
    if (array_key_exists("renewals", $_SESSION['cart']) && is_array($_SESSION['cart']['renewals'])) {
        $result = select_query("tblpricing", "", array("type" => "domainaddons", "currency" => $currency['id'], "relid" => 0));
        $data = mysql_fetch_array($result);
        $domaindnsmanagementprice = $data['msetupfee'];
        $domainemailforwardingprice = $data['qsetupfee'];
        $domainidprotectionprice = $data['ssetupfee'];
        foreach ($_SESSION['cart']['renewals'] as $domainid => $regperiod) {
            $result = select_query("tbldomains", "", array("id" => $domainid));
            $data = mysql_fetch_array($result);
            $domainname = $data['domain'];
            $expirydate = $data['expirydate'];
            if ($expirydate == "0000-00-00") {
                $expirydate = $data['nextduedate'];
            }
            $dnsmanagement = $data['dnsmanagement'];
            $emailforwarding = $data['emailforwarding'];
            $idprotection = $data['idprotection'];
            $domainparts = explode(".", $domainname, 2);
            $sld = $domainparts[0];
            $tld = "." . $domainparts[1];
            $temppricelist = getTLDPriceList($tld, "", true);
            if (!isset($temppricelist[$regperiod]['renew'])) {
                exit("Invalid TLD/Registration Period Supplied for Domain Renewal");
            }
            $renewprice = $temppricelist[$regperiod]['renew'];
            if ($dnsmanagement) {
                $renewprice += $domaindnsmanagementprice * $regperiod;
            }
            if ($emailforwarding) {
                $renewprice += $domainemailforwardingprice * $regperiod;
            }
            if ($idprotection) {
                $renewprice += $domainidprotectionprice * $regperiod;
            }
            if ($CONFIG['TaxInclusiveDeduct']) {
                $renewprice = round($renewprice / $excltaxrate, 2);
            }
            $domain_renew_price_db = $renewprice;
            if ($promotioncode) {
                $onetimediscount = $recurringdiscount = $promoid = 0;
                if ($promocalc = CalcPromoDiscount("D" . $tld, $regperiod . "Years", $domain_renew_price_db, $domain_renew_price_db)) {
                    $onetimediscount = $promocalc['onetimediscount'];
                    $domain_renew_price_db -= $onetimediscount;
                    $cart_discount += $onetimediscount;
                }
            }
            $cart_total += $domain_renew_price_db;
            if ($CONFIG['TaxDomains']) {
                $cart_tax += $domain_renew_price_db;
            }
            if ($checkout) {
                $domain_renew_price_db = format_as_currency($domain_renew_price_db);
                $orderrenewalids[] = $domainid;
                $orderrenewals .= "" . $domainid . "=" . $regperiod . ",";
                $adminemailitems .= $_LANG['domainrenewal'] . (": " . $domainname . " - " . $regperiod . " ") . $_LANG['orderyears'] . "<br>\r\n";
                $domaindesc = $_LANG['domainrenewal'] . (" - " . $domainname . " - " . $regperiod . " ") . $_LANG['orderyears'] . " (" . fromMySQLDate($expirydate) . " - " . fromMySQLDate(getInvoicePayUntilDate($expirydate, $regperiod)) . ")";
                if ($dnsmanagement) {
                    $adminemailitems .= " + " . $_LANG['domaindnsmanagement'] . "<br>\r\n";
                    $domaindesc .= "\r\n + " . $_LANG['domaindnsmanagement'];
                }
                if ($emailforwarding) {
                    $adminemailitems .= " + " . $_LANG['domainemailforwarding'] . "<br>\r\n";
                    $domaindesc .= "\r\n + " . $_LANG['domainemailforwarding'];
                }
                if ($idprotection) {
                    $adminemailitems .= " + " . $_LANG['domainidprotection'] . "<br>\r\n";
                    $domaindesc .= "\r\n + " . $_LANG['domainidprotection'];
                }
                $adminemailitems .= "<br>\r\n";
                $tax = $CONFIG['TaxDomains'] ? "1" : "0";
                update_query("tbldomains", array("registrationperiod" => $regperiod, "recurringamount" => $domain_renew_price_db), array("id" => $domainid));
                insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Domain", "relid" => $domainid, "description" => $domaindesc, "amount" => $domain_renew_price_db, "taxed" => $tax, "duedate" => "now()", "paymentmethod" => $paymentmethod));
                $result = select_query("tblinvoiceitems", "tblinvoiceitems.id,tblinvoiceitems.invoiceid", array("type" => "Domain", "relid" => $domainid, "status" => "Unpaid", "tblinvoices.userid" => $_SESSION['uid']), "", "", "", "tblinvoices ON tblinvoices.id=tblinvoiceitems.invoiceid");
                while ($data = mysql_fetch_array($result)) {
                    $itemid = $data['id'];
                    $invoiceid = $data['invoiceid'];
                    $result2 = select_query("tblinvoiceitems", "COUNT(*)", array("invoiceid" => $invoiceid));
                    $data = mysql_fetch_array($result2);
                    $itemcount = $data[0];
                    if ($itemcount == 1) {
                        update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $invoiceid));
                        logActivity("Cancelled Previous Domain Renewal Invoice - Invoice ID: " . $invoiceid . " - Domain: " . $domainname);
                    }
                    delete_query("tblinvoiceitems", array("id" => $itemid));
                    updateInvoiceTotal($invoiceid);
                    logActivity("Removed Previous Domain Renewal Line Item - Invoice ID: " . $invoiceid . " - Domain: " . $domainname);
                }
            }
            $cartdata['renewals'][$domainid] = array("domain" => $domainname, "regperiod" => $regperiod, "price" => formatCurrency($renewprice), "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection);
        }
    }
    $cart_adjustments = 0;
    $adjustments = run_hook("CartTotalAdjustment", $_SESSION['cart']);
    foreach ($adjustments as $k => $adjvals) {
        if ($checkout) {
            insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "", "relid" => "", "description" => $adjvals['description'], "amount" => $adjvals['amount'], "taxed" => $adjvals['taxed'], "duedate" => "now()", "paymentmethod" => $paymentmethod));
        }
        $adjustments[$k]['amount'] = formatCurrency($adjvals['amount']);
        $cart_adjustments += $adjvals['amount'];
        if ($adjvals['taxed']) {
            $cart_tax += $adjvals['amount'];
            continue;
        }
    }
    if ($CONFIG['TaxEnabled'] && !$clientsdetails['taxexempt']) {
        if ($CONFIG['TaxType'] == "Inclusive") {
            $totaltaxrates = 1 + ($taxrate + $taxrate2);
            $total_without_tax = $cart_tax / $totaltaxrates;
            $total_tax_1 = $total_without_tax * $taxrate;
            $total_tax_2 = $total_without_tax * $taxrate2;
        } else {
            $total_tax_1 = $cart_tax * $taxrate;
            if ($CONFIG['TaxL2Compound']) {
                $total_tax_2 = ($cart_tax + $total_tax_1) * $taxrate2;
            } else {
                $total_tax_2 = $cart_tax * $taxrate2;
            }
        }
        $total_tax_1 = round($total_tax_1, 2);
        $total_tax_2 = round($total_tax_2, 2);
        if ($CONFIG['TaxType'] == "Inclusive") {
            $cart_total -= $total_tax_1 + $total_tax_2;
        }
    } else {
        $total_tax_1 = $total_tax_2 = 0;
    }
    $cart_subtotal = $cart_total + $cart_discount;
    $cart_total += $total_tax_1 + $total_tax_2 + $cart_adjustments;
    $cart_subtotal = format_as_currency($cart_subtotal);
    $cart_discount = format_as_currency($cart_discount);
    $cart_adjustments = format_as_currency($cart_adjustments);
    $total_tax_1 = format_as_currency($total_tax_1);
    $total_tax_2 = format_as_currency($total_tax_2);
    $cart_total = format_as_currency($cart_total);
    if ($checkout) {
        $adminemailitems .= $_LANG['ordertotalduetoday'] . ": " . formatCurrency($cart_total);
        if ($promotioncode && $promo_data['promoapplied']) {
            update_query("tblpromotions", array("uses" => "+1"), array("code" => $promotioncode));
            $promo_recurring = $promo_data['recurring'] ? "Recurring" : "One Time";
            update_query("tblorders", array("promocode" => $promo_data['code'], "promotype" => $promo_recurring . " " . $promo_data['type'], "promovalue" => $promo_data['value']), array("id" => $orderid));
        }
        if ($_SESSION['cart']['ns1'] && $_SESSION['cart']['ns1']) {
            $ordernameservers = $_SESSION['cart']['ns1'] . "," . $_SESSION['cart']['ns2'];
            if ($_SESSION['cart']['ns3']) {
                $ordernameservers .= "," . $_SESSION['cart']['ns3'];
            }
            if ($_SESSION['cart']['ns4']) {
                $ordernameservers .= "," . $_SESSION['cart']['ns4'];
            }
            if ($_SESSION['cart']['ns5']) {
                $ordernameservers .= "," . $_SESSION['cart']['ns5'];
            }
        }
        $domaineppcodes = count($domaineppcodes) ? serialize($domaineppcodes) : "";
        $orderdata = array();
        if (is_array($_SESSION['cart']['bundle'])) {
            foreach ($_SESSION['cart']['bundle'] as $bvals) {
                $orderdata['bundleids'][] = $bvals['bid'];
            }
        }
        update_query("tblorders", array("amount" => $cart_total, "nameservers" => $ordernameservers, "transfersecret" => $domaineppcodes, "renewals" => substr($orderrenewals, 0, 0 - 1), "orderdata" => serialize($orderdata)), array("id" => $orderid));
        $invoiceid = 0;
        if (!$_SESSION['cart']['geninvoicedisabled']) {
            if (!$userid) {
                exit("An Error Occurred");
            }
            $invoiceid = createInvoices($userid, true, "", array("products" => $orderproductids, "addons" => $orderaddonids, "domains" => $orderdomainids));
            if ($CONFIG['OrderDaysGrace']) {
                $new_time = mktime(0, 0, 0, date("m"), date("d") + $CONFIG['OrderDaysGrace'], date("Y"));
                $duedate = date("Y-m-d", $new_time);
                update_query("tblinvoices", array("duedate" => $duedate), array("id" => $invoiceid));
            }
            if (!$CONFIG['NoInvoiceEmailOnOrder']) {
                sendMessage("Invoice Created", $invoiceid);
            }
        }
        if ($invoiceid) {
            update_query("tblorders", array("invoiceid" => $invoiceid), array("id" => $orderid));
            $result = select_query("tblinvoices", "status", array("id" => $invoiceid));
            $data = mysql_fetch_array($result);
            $status = $data['status'];
            if ($status == "Paid") {
                $invoiceid = "";
            }
        }
        if (!$_SESSION['adminid']) {
            if (isset($_COOKIE['WHMCSAffiliateID'])) {
                $result = select_query("tblaffiliates", "clientid", array("id" => (int) $_COOKIE['WHMCSAffiliateID']));
                $data = mysql_fetch_array($result);
                $clientid = $data['clientid'];
                if ($clientid && $_SESSION['uid'] != $clientid) {
                    foreach ($orderproductids as $orderproductid) {
                        insert_query("tblaffiliatesaccounts", array("affiliateid" => (int) $_COOKIE['WHMCSAffiliateID'], "relid" => $orderproductid));
                    }
                }
            }
            if (isset($_COOKIE['WHMCSLinkID'])) {
                update_query("tbllinks", array("conversions" => "+1"), array("id" => $_COOKIE['WHMCSLinkID']));
            }
        }
        $result = select_query("tblclients", "firstname, lastname, companyname, email, address1, address2, city, state, postcode, country, phonenumber, ip, host", array("id" => $userid));
        $data = mysql_fetch_array($result);
        list($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $ip, $host) = $data;
        $customfields = getCustomFields("client", "", $userid, "", true);
        $clientcustomfields = "";
        foreach ($customfields as $customfield) {
            $clientcustomfields .= "" . $customfield['name'] . ": " . $customfield['value'] . "<br />\r\n";
        }
        $result = select_query("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "name"));
        $data = mysql_fetch_array($result);
        $nicegatewayname = $data['value'];
        sendAdminMessage("New Order Notification", array("order_id" => $orderid, "order_number" => $order_number, "order_date" => fromMySQLDate(date("Y-m-d H:i:s"), true), "invoice_id" => $invoiceid, "order_payment_method" => $nicegatewayname, "order_total" => formatCurrency($cart_total), "client_id" => $userid, "client_first_name" => $firstname, "client_last_name" => $lastname, "client_email" => $email, "client_company_name" => $companyname, "client_address1" => $address1, "client_address2" => $address2, "client_city" => $city, "client_state" => $state, "client_postcode" => $postcode, "client_country" => $country, "client_phonenumber" => $phonenumber, "client_customfields" => $clientcustomfields, "order_items" => $adminemailitems, "order_notes" => nl2br($ordernotes), "client_ip" => $ip, "client_hostname" => $host), "account");
        if (!$_SESSION['cart']['orderconfdisabled']) {
            sendMessage("Order Confirmation", $userid, array("order_id" => $orderid, "order_number" => $order_number, "order_details" => $adminemailitems));
        }
        $_SESSION['cart'] = array();
        $_SESSION['orderdetails'] = array("OrderID" => $orderid, "OrderNumber" => $order_number, "ServiceIDs" => $orderproductids, "DomainIDs" => $orderdomainids, "AddonIDs" => $orderaddonids, "RenewalIDs" => $orderrenewalids, "PaymentMethod" => $paymentmethod, "InvoiceID" => $invoiceid, "TotalDue" => $cart_total, "Products" => $orderproductids, "Domains" => $orderdomainids, "Addons" => $orderaddonids, "Renewals" => $orderrenewalids);
        run_hook("AfterShoppingCartCheckout", $_SESSION['orderdetails']);
    }
    $total_recurringmonthly = $recurring_cycles_total['monthly'] <= 0 ? "" : formatCurrency($recurring_cycles_total['monthly']);
    $total_recurringquarterly = $recurring_cycles_total['quarterly'] <= 0 ? "" : formatCurrency($recurring_cycles_total['quarterly']);
    $total_recurringsemiannually = $recurring_cycles_total['semiannually'] <= 0 ? "" : formatCurrency($recurring_cycles_total['semiannually']);
    $total_recurringannually = $recurring_cycles_total['annually'] <= 0 ? "" : formatCurrency($recurring_cycles_total['annually']);
    $total_recurringbiennially = $recurring_cycles_total['biennially'] <= 0 ? "" : formatCurrency($recurring_cycles_total['biennially']);
    $total_recurringtriennially = $recurring_cycles_total['triennially'] <= 0 ? "" : formatCurrency($recurring_cycles_total['triennially']);
    $cartdata['bundlewarnings'] = $bundlewarnings;
    $cartdata['rawdiscount'] = $cart_discount;
    $cartdata['subtotal'] = formatCurrency($cart_subtotal);
    $cartdata['discount'] = formatCurrency($cart_discount);
    $cartdata['promotype'] = $promo_data['type'];
    $cartdata['promovalue'] = $promo_data['type'] == "Fixed Amount" || $promo_data['type'] == "Price Override" ? formatCurrency($promo_data['value']) : round($promo_data['value'], 2);
    $cartdata['promorecurring'] = $promo_data['recurring'] ? $_LANG['recurring'] : $_LANG['orderpaymenttermonetime'];
    $cartdata['taxrate'] = $rawtaxrate;
    $cartdata['taxrate2'] = $rawtaxrate2;
    $cartdata['taxname'] = $taxname;
    $cartdata['taxname2'] = $taxname2;
    $cartdata['taxtotal'] = formatCurrency($total_tax_1);
    $cartdata['taxtotal2'] = formatCurrency($total_tax_2);
    $cartdata['adjustments'] = $adjustments;
    $cartdata['adjustmentstotal'] = formatCurrency($cart_adjustments);
    $cartdata['rawtotal'] = $cart_total;
    $cartdata['total'] = formatCurrency($cart_total);
    $cartdata['totalrecurringmonthly'] = $total_recurringmonthly;
    $cartdata['totalrecurringquarterly'] = $total_recurringquarterly;
    $cartdata['totalrecurringsemiannually'] = $total_recurringsemiannually;
    $cartdata['totalrecurringannually'] = $total_recurringannually;
    $cartdata['totalrecurringbiennially'] = $total_recurringbiennially;
    $cartdata['totalrecurringtriennially'] = $total_recurringtriennially;
    return $cartdata;
}
Exemple #8
0
    $userid = $data['userid'];
    $currencyid = $data['currency'];
    $currency = getCurrency($userid, $currencyid);
    $result = select_query("tblproducts", "tblproducts.name,tblproducts.tax,tblproductgroups.name AS groupname", array("tblproducts.id" => $pid), "", "", "", "tblproductgroups ON tblproductgroups.id=tblproducts.gid");
    $data = mysql_fetch_array($result);
    $groupname = $data['groupname'];
    $prodname = $data['name'];
    $tax = $data['tax'];
    $desc = $groupname . " - " . $prodname;
    $pricing = getPricingInfo($pid);
    $billingcycle = $pricing['minprice']['cycle'];
    if ($billingcycle == "onetime") {
        $billingcycle = "monthly";
    }
    $amount = $pricing['rawpricing'][$billingcycle];
    $configoptions = getCartConfigOptions($pid, $configoption, $billingcycle);
    foreach ($configoptions as $option) {
        $desc .= "\r\n" . $option['optionname'] . ": " . $option['selectedname'];
        $amount += $option['selectedsetup'] + $option['selectedrecurring'];
    }
    insert_query("tblquoteitems", array("quoteid" => $id, "description" => $desc, "quantity" => "1", "unitprice" => $amount, "discount" => "0", "taxable" => $tax));
    saveQuote($id, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", true);
    redir("action=manage&id=" . $id);
    exit;
}
if ($action == "save") {
    check_token("WHMCS.admin.default");
    $lineitems = array();
    if ($desc) {
        foreach ($desc as $lid => $description) {
            $lineitems[] = array("id" => $lid, "desc" => $description, "qty" => $qty[$lid], "up" => $up[$lid], "discount" => $discount[$lid], "taxable" => $taxable[$lid]);
Exemple #9
0
 $id = $data['id'];
 $itemdata = $data['itemdata'];
 $itemdata = unserialize($itemdata);
 $vals = "";
 if ($i) {
     $i = (int) $i;
 }
 if (strlen($i)) {
     $vals = $itemdata[$i];
 }
 if (!$vals) {
     $vals = array();
 }
 $configoption = is_array($vals['configoption']) ? $vals['configoption'] : array();
 $addon = is_array($vals['addons']) ? $vals['addons'] : array();
 $configoptions = getCartConfigOptions($pid, $configoptions, "", "", true);
 if (count($configoptions)) {
     echo "<b>" . $aInt->lang("setup", "configoptions") . "</b><br />\n<div style=\"background-color:#efefef;padding:5px;margin:2px;\">\n<table>";
     foreach ($configoptions as $vals) {
         $opid = $vals['id'];
         $optionname = $vals['optionname'];
         $optiontype = $vals['optiontype'];
         $options = $vals['options'];
         echo "<tr><td width=\"100\">" . $optionname . "</td><td><input type=\"checkbox\" name=\"coprestrict[]\" value=\"" . $opid . "\"";
         if (array_key_exists($opid, $configoption)) {
             echo " checked";
         }
         echo " />" . $aInt->lang("bundles", "restrict") . "</td><td>";
         if ($optiontype == 1 || $optiontype == 2) {
             echo "<select name=\"coopval[" . $opid . "]\">";
             foreach ($options as $svals) {
Exemple #10
0
         }
     }
     $upgradedata = createUpgradeOrder($id, "", $promocode, $service_paymentmethod);
     $orderid = $upgradedata['orderid'];
     unset($_SESSION['uid']);
     echo "<s";
     echo "cript language=\"javascript\">\nwindow.opener.location.href = \"orders.php?action=view&id=";
     echo $orderid;
     echo "\";\nwindow.close();\n</script>\n";
     exit;
 } else {
     if (!$action) {
         if (!$type) {
             $type = "product";
         }
         $configoptions = getCartConfigOptions($service_pid, "", $service_billingcycle, $id);
         echo "\n<p>";
         echo "<s";
         echo "trong>";
         echo $aInt->lang("services", "related");
         echo ":</strong> ";
         echo $service_groupname . " - " . $service_prodname;
         if ($service_domain) {
             echo " (" . $service_domain . ")";
         }
         echo "</p>\n\n";
         echo "<s";
         echo "cript language=\"javascript\">\n\$(document).ready(function(){\n\n    calctotals();\n\n    \$(\"#newpid\").change(function () {\n        var newpid = \$(\"#newpid option:selected\").val();\n        \$.post(\"clientsupgrade.php\", { action: \"getcycles\", id: ";
         echo $id;
         echo ", pid: newpid },\n        function(data){\n            \$(\"#billingcyclehtml\").html(data);\n            calctotals();\n        });\n    });\n\n});\n\nfunction calctotals() {\n    \$.post(\"clientsupgrade.php\", \"action=calcsummary&\"+\$(\"#upgradefrm\").serialize(),\n    function(data){\n        if (data) \$(\"#upgradesummary\").html(data);\n        else \$(\"#upgradesummary\").html(\"";
         echo $aInt->lang("services", "nochanges");
Exemple #11
0
function recalcRecurringProductPrice($serviceid, $userid = "", $pid = "", $billingcycle = "", $configoptionsrecurring = "empty", $promoid = 0, $includesetup = false)
{
    if (!$userid || !$pid || !$billingcycle) {
        $result = select_query("tblhosting", "userid,packageid,billingcycle", array("id" => $serviceid));
        $data = mysql_fetch_array($result);
        if (!$userid) {
            $userid = $data['userid'];
        }
        if (!$pid) {
            $pid = $data['packageid'];
        }
        if (!$billingcycle) {
            $billingcycle = $data['billingcycle'];
        }
    }
    global $currency;
    $currency = getCurrency($userid);
    $result = select_query("tblpricing", "", array("type" => "product", "currency" => $currency['id'], "relid" => $pid));
    $data = mysql_fetch_array($result);
    if ($billingcycle == "Monthly") {
        $amount = $data['monthly'];
    } else {
        if ($billingcycle == "Quarterly") {
            $amount = $data['quarterly'];
        } else {
            if ($billingcycle == "Semi-Annually") {
                $amount = $data['semiannually'];
            } else {
                if ($billingcycle == "Annually") {
                    $amount = $data['annually'];
                } else {
                    if ($billingcycle == "Biennially") {
                        $amount = $data['biennially'];
                    } else {
                        if ($billingcycle == "Triennially") {
                            $amount = $data['triennially'];
                        } else {
                            $amount = 0;
                        }
                    }
                }
            }
        }
    }
    if ($includesetup === true) {
        $setupvar = substr(strtolower($billingcycle), 0, 1);
        $amount += $data[$setupvar . "setupfee"];
    }
    if ($configoptionsrecurring == "empty") {
        if (!function_exists("getCartConfigOptions")) {
            require ROOTDIR . "/includes/configoptionsfunctions.php";
        }
        $configoptions = getCartConfigOptions($pid, "", $billingcycle, $serviceid);
        foreach ($configoptions as $configoption) {
            $amount += $configoption['selectedrecurring'];
            if ($includesetup === true) {
                $amount += $configoption['selectedsetup'];
                continue;
            }
        }
    } else {
        $amount += $configoptionsrecurring;
    }
    if ($promoid) {
        $amount -= recalcPromoAmount($pid, $userid, $serviceid, $billingcycle, $amount, $promoid);
    }
    return $amount;
}
Exemple #12
0
             exit;
         }
         redir("a=confdomains");
         exit;
     }
 }
 $billingcycle = $_SESSION['cart']['products'][$i]['billingcycle'];
 $server = $_SESSION['cart']['products'][$i]['server'];
 $customfields = $_SESSION['cart']['products'][$i]['customfields'];
 $configoptions = $_SESSION['cart']['products'][$i]['configoptions'];
 $addons = $_SESSION['cart']['products'][$i]['addons'];
 $domain = $_SESSION['cart']['products'][$i]['domain'];
 $noconfig = $_SESSION['cart']['products'][$i]['noconfig'];
 $billingcycle = $orderfrm->validateBillingCycle($billingcycle);
 $pricing = getPricingInfo($pid);
 $configurableoptions = getCartConfigOptions($pid, $configoptions, $billingcycle, "", true);
 $customfields = getCustomFields("product", $pid, "", "", "on", $customfields);
 $addonsarray = getAddons($pid, $addons);
 $recurringcycles = 0;
 if ($pricing['type'] == "recurring") {
     if (0 <= $pricing['rawpricing']['monthly']) {
         ++$recurringcycles;
     }
     if (0 <= $pricing['rawpricing']['quarterly']) {
         ++$recurringcycles;
     }
     if (0 <= $pricing['rawpricing']['semiannually']) {
         ++$recurringcycles;
     }
     if (0 <= $pricing['rawpricing']['annually']) {
         ++$recurringcycles;
Exemple #13
0
 public function calcConfigOptionsUpgradeDue()
 {
     global $whmcs;
     $pid = $this->getProductInfo("pid");
     $domain = $this->getProductInfo("domain");
     $nextduedate = $this->getProductInfo("nextduedate");
     $billingcycle = $this->getProductInfo("billingcycle");
     $productname = $this->getProductInfo("productname");
     $applytax = $this->getProductInfo("tax");
     if ($domain) {
         $productname .= " - " . $domain;
     }
     $year = substr($nextduedate, 0, 4);
     $month = substr($nextduedate, 5, 2);
     $day = substr($nextduedate, 8, 2);
     $cyclemonths = getBillingCycleMonths($billingcycle);
     $prevduedate = date("Y-m-d", mktime(0, 0, 0, $month - $cyclemonths, $day, $year));
     $totaldays = round((strtotime($nextduedate) - strtotime($prevduedate)) / 86400);
     $todaysdate = date("Y-m-d");
     $todaysdate = strtotime($todaysdate);
     $nextduedatetime = strtotime($nextduedate);
     $days = round(($nextduedatetime - $todaysdate) / 86400);
     if ($days < 0) {
         $days = $totaldays;
     }
     $percentage = $days / $totaldays;
     $newconfigoptions = getCartConfigOptions($pid, $this->newconfigoptions, $billingcycle);
     $oldconfigoptions = getCartConfigOptions($pid, "", $billingcycle, $id);
     foreach ($newconfigoptions as $key => $configoption) {
         $configid = $configoption['id'];
         $configname = $configoption['optionname'];
         $optiontype = $configoption['optiontype'];
         $new_selectedvalue = $configoption['selectedvalue'];
         $new_selectedqty = $configoption['selectedqty'];
         $new_selectedname = $configoption['selectedname'];
         $new_selectedsetup = $configoption['selectedsetup'];
         $new_selectedrecurring = $configoption['selectedrecurring'];
         $old_selectedvalue = $oldconfigoptions[$key]['selectedvalue'];
         $old_selectedqty = $oldconfigoptions[$key]['selectedqty'];
         $old_selectedname = $oldconfigoptions[$key]['selectedname'];
         $old_selectedsetup = $oldconfigoptions[$key]['selectedsetup'];
         $old_selectedrecurring = $oldconfigoptions[$key]['selectedrecurring'];
         if (($optiontype == 1 || $optiontype == 2) && $new_selectedvalue != $old_selectedvalue || ($optiontype == 3 || $optiontype == 4) && $new_selectedqty != $old_selectedqty) {
             $difference = $new_selectedrecurring - $old_selectedrecurring;
             $amountdue = $difference * $percentage;
             $amountdue = format_as_currency($amountdue);
             if (!$CONFIG['CreditOnDowngrade'] && $amountdue < 0) {
                 $amountdue = format_as_currency(0);
             }
             if ($optiontype == 1 || $optiontype == 2) {
                 $db_orig_value = $old_selectedvalue;
                 $db_new_value = $new_selectedvalue;
                 $originalvalue = $old_selectedname;
                 $newvalue = $new_selectedname;
             } else {
                 if ($optiontype == 3) {
                     $db_orig_value = $old_selectedqty;
                     $db_new_value = $new_selectedqty;
                     if ($old_selectedqty) {
                         $originalvalue = $whmcs->get_lang("yes");
                         $newvalue = $whmcs->get_lang("no");
                     } else {
                         $originalvalue = $whmcs->get_lang("no");
                         $newvalue = $whmcs->get_lang("yes");
                     }
                 } else {
                     if ($optiontype == 4) {
                         $new_selectedqty = (int) $new_selectedqty;
                         if ($new_selectedqty < 0) {
                             $new_selectedqty = 11;
                         }
                         $db_orig_value = $old_selectedqty;
                         $db_new_value = $new_selectedqty;
                         $originalvalue = $old_selectedqty;
                         $newvalue = $new_selectedqty . " " . $configoption['options'][0]['nameonly'];
                     }
                 }
             }
             $itemdiscount = 0;
             if ($promoqualifies && 0 < $amountdue && (!count($upgradeconfigoptions) || in_array($configid, $upgradeconfigoptions))) {
                 $itemdiscount = $discounttype == "Percentage" ? round($amountdue * $promovalue, 2) : ($amountdue < $promovalue ? $amountdue : $promovalue);
             }
             $discount += $itemdiscount;
             $description = $productname . "\r\n" . $configname . ": " . (0 < $amountdue ? "Upgrade" : "Downgrade") . " from " . $originalvalue . " to " . $newvalue . " (" . getTodaysDate() . " - " . fromMySQLDate($nextduedate) . ")" . "\r\n" . "Regular Recurring Amount Increase: " . formatCurrency($difference) . "";
             $this->addLineItem($description, $amountdue);
             $upgradearray[] = array("configname" => $configname, "originalvalue" => $originalvalue, "newvalue" => $newvalue, "price" => formatCurrency($amountdue));
             continue;
         }
     }
     return $upgradearray;
 }
Exemple #14
0
 public function getConfigurableOptions()
 {
     return getCartConfigOptions($this->getData("pid"), "", $this->getData("billingcycle"), $this->getData("id"));
 }