-
Notifications
You must be signed in to change notification settings - Fork 79
/
upgrade.php
executable file
·351 lines (349 loc) · 17 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
/*
* @ PHP 5.6
* @ Decoder version : 1.0.0.1
* @ Release on : 24.03.2018
* @ Website : http://EasyToYou.eu
*/
define("CLIENTAREA", true);
require "init.php";
require "includes/configoptionsfunctions.php";
require "includes/gatewayfunctions.php";
require "includes/invoicefunctions.php";
require "includes/clientfunctions.php";
require "includes/upgradefunctions.php";
require "includes/orderfunctions.php";
$pagetitle = $_LANG["upgradedowngradepackage"];
$pageicon = "images/clientarea_big.gif";
$breadcrumbnav = "<a href=\"index.php\">" . $_LANG["globalsystemname"] . "</a> > <a href=\"clientarea.php\">" . $_LANG["clientareatitle"] . "</a> > <a href=\"upgrade.php\">" . $_LANG["upgradedowngradepackage"] . "</a>";
$displayTitle = Lang::trans("upgradedowngradepackage");
$tagline = "";
initialiseClientArea($pagetitle, $displayTitle, $tagline, $pageicon, $breadcrumbnav);
if (!isset($_SESSION["uid"])) {
$goto = "clientarea";
include "login.php";
outputClientArea($templatefile);
exit;
}
checkContactPermission("orders");
$currency = getCurrency($_SESSION["uid"]);
$templatefile = "upgrade";
$step = $whmcs->get_req_var("step");
if ($step == "4") {
foreach ($_SESSION["upgradeorder"] as $k => $v) {
${$k} = $v;
}
}
$result = select_query("tblhosting", "tblhosting.id,tblhosting.domain,tblhosting.nextduedate,tblhosting.billingcycle,tblhosting.packageid," . "tblproducts.name as product_name, tblproductgroups.id AS group_id,tblproductgroups.name as group_name", array("userid" => $_SESSION["uid"], "tblhosting.id" => $id, "tblhosting.domainstatus" => "Active"), "", "", "", "tblproducts ON tblproducts.id=tblhosting.packageid INNER JOIN tblproductgroups ON tblproductgroups.id=tblproducts.gid");
$data = mysql_fetch_array($result);
$id = $data["id"];
if (!$id) {
redir("", "clientarea.php");
}
$domain = $data["domain"];
$productname = WHMCS\Product\Product::getProductName($data["packageid"], $data["product_name"]);
$groupname = WHMCS\Product\Group::getGroupName($data["group_id"], $data["group_name"]);
$packageid = $data["packageid"];
$nextduedate = $data["nextduedate"];
$billingcycle = $data["billingcycle"];
$smarty->assign("id", $id);
$smarty->assign("type", $type);
$smarty->assign("groupname", $groupname);
$smarty->assign("productname", $productname);
$smarty->assign("domain", $domain);
$smartyvalues["overdueinvoice"] = false;
$smartyvalues["existingupgradeinvoice"] = false;
$smartyvalues["upgradenotavailable"] = false;
$smartyvalues["overdueinvoice"] = false;
$smartyvalues["existingupgradeinvoice"] = false;
$result = select_query("tblinvoiceitems", "invoiceid", array("type" => "Hosting", "relid" => $id, "status" => "Unpaid", "tblinvoices.userid" => $_SESSION["uid"]), "", "", "", "tblinvoices ON tblinvoices.id=tblinvoiceitems.invoiceid");
$data = mysql_fetch_array($result);
if ($data[0]) {
Menu::addContext("service", WHMCS\Service\Service::find($id));
Menu::primarySidebar("serviceUpgrade");
Menu::secondarySidebar("serviceUpgrade");
$smartyvalues["overdueinvoice"] = true;
outputClientArea($templatefile);
exit;
}
$errormessage = "";
if ($step == "2" && $type == "configoptions") {
$configOpsReturn = validateAndSanitizeQuantityConfigOptions($whmcs->get_req_var("configoption"));
if ($configOpsReturn["errorMessage"]) {
$errormessage = $configOpsReturn["errorMessage"];
$step = "";
}
}
$checkUpgradeAlreadyInProgress = upgradeAlreadyInProgress($id);
Menu::addContext("service", WHMCS\Service\Service::find($id));
Menu::primarySidebar("serviceUpgrade");
Menu::secondarySidebar("serviceUpgrade");
if (!$step) {
if (upgradeAlreadyInProgress($id)) {
$smartyvalues["existingupgradeinvoice"] = true;
outputClientArea($templatefile);
exit;
}
$service = new WHMCS\Service($id, WHMCS\Session::get("uid"));
if ($type == "package" && !$service->getAllowProductUpgrades() || $type == "configoptions" && !$service->getAllowConfigOptionsUpgrade()) {
$redirect = "cart.php";
$vars = "";
if (0 < count($service->hasProductGotAddons())) {
$vars = "gid=addons";
}
redirSystemURL($vars, $redirect);
}
if ($type == "package") {
$upgradepackages = WHMCS\Product\Product::find($packageid)->getUpgradeProductIds();
$result = select_query("tblproducts", "id, stockcontrol, qty", "id IN (" . db_build_in_array($upgradepackages) . ")", "order` ASC, `name", "ASC");
while ($data = mysql_fetch_array($result)) {
$upgradepackageid = $data["id"];
$stockControlEnabled = $data["stockcontrol"];
$stockQty = $data["qty"];
if (!$stockControlEnabled || 0 < $stockQty) {
$upgradepackagesarray[$upgradepackageid] = getProductInfo($upgradepackageid);
$upgradepackagesarray[$upgradepackageid]["pricing"] = getPricingInfo($upgradepackageid, "", true);
}
}
$smarty->assign("upgradepackages", $upgradepackagesarray);
} else {
if ($type == "configoptions") {
$result = select_query("tblhosting", "billingcycle", array("userid" => $_SESSION["uid"], "id" => $id));
$data = mysql_fetch_array($result);
$billingcycle = $data["billingcycle"];
$newproductbillingcycle = strtolower($billingcycle);
$newproductbillingcycle = str_replace("-", "", $newproductbillingcycle);
$newproductbillingcycle = str_replace("lly", "l", $newproductbillingcycle);
if ($newproductbillingcycle == "onetime") {
$newproductbillingcycle = "monthly";
}
$configoptions = array();
$configoptions = getCartConfigOptions($packageid, "", $billingcycle, $id);
foreach ($configoptions as $configkey => $configoption) {
$selectedoption = $configoption["selectedoption"];
$selectedName = $configoption["selectedname"];
$selectedprice = $configoption["selectedrecurring"];
$options = $configoption["options"];
foreach ($options as $optionkey => $option) {
$optionname = $option["name"];
$optionNameOnly = $option["nameonly"];
$optionprice = $option["recurring"];
$optionprice = $optionprice - $selectedprice;
$configoptions[$configkey]["options"][$optionkey]["price"] = formatCurrency($optionprice);
if ($optionname == $selectedoption || $optionNameOnly == $selectedName && 0 < $configoption["selectedsetup"]) {
$configoptions[$configkey]["options"][$optionkey]["selected"] = true;
}
}
}
$smarty->assign("configoptions", $configoptions);
$smarty->assign("errormessage", $errormessage);
}
}
} else {
if ($step == "2") {
$templatefile = "upgradesummary";
Menu::primarySidebar("serviceUpgrade");
Menu::secondarySidebar("serviceUpgrade");
$upgrades = array();
$applytax = false;
$serviceid = $_REQUEST["id"];
$configoption = $whmcs->get_req_var("configoption");
$promocode = $whmcs->get_req_var("promocode");
$smartyvalues["promoerror"] = "";
$smartyvalues["promorecurring"] = "";
$smartyvalues["promodesc"] = "";
$smartyvalues["promocode"] = "";
if ($promocode && empty($_REQUEST["removepromo"])) {
$promodata = validateUpgradePromo($promocode);
if (!is_array($promodata)) {
$promocode = "";
$smartyvalues["promoerror"] = $promodata;
} else {
$smartyvalues["promocode"] = $promocode;
if ($promodata["type"] == "configoptions" && count($promodata["configoptions"])) {
$promodata["desc"] .= " " . $_LANG["upgradeonselectedoptions"];
}
$smartyvalues["promodesc"] = $promodata["desc"];
$smartyvalues["promorecurring"] = $promodata["recurringdesc"];
}
} else {
$promodata = get_query_vals("tblpromotions", "code,type,value", array("lifetimepromo" => 1, "recurring" => 1, "id" => get_query_val("tblhosting", "promoid", array("id" => $serviceid))));
if (is_array($promodata)) {
$smartyvalues["promocode"] = $promocode = $promodata["code"];
$smartyvalues["promodesc"] = $promodata["type"] == "Percentage" ? $promodata["value"] . "%" : formatCurrency($promodata["value"]);
$smartyvalues["promorecurring"] = $smartyvalues["promodesc"];
$smartyvalues["promodesc"] .= " " . $_LANG["orderdiscount"];
}
}
if (isset($_REQUEST["removepromo"])) {
$promocode = "";
unset($smartyvalues["promoerror"]);
unset($smartyvalues["promocode"]);
unset($smartyvalues["promodesc"]);
unset($smartyvalues["promorecurring"]);
$GLOBALS["discount"] = 0;
$GLOBALS["qualifies"] = false;
}
if ($type == "package") {
$newproductid = $_REQUEST["pid"];
$newproductbillingcycle = $_REQUEST["billingcycle"];
$upgrades = SumUpPackageUpgradeOrder($serviceid, $newproductid, $newproductbillingcycle, $promocode);
} else {
if ($type == "configoptions") {
$configoptions = $_REQUEST["configoption"];
$upgrades = SumUpConfigOptionsOrder($serviceid, $configoptions, $promocode);
}
}
$subtotal = $GLOBALS["subtotal"];
$qualifies = $GLOBALS["qualifies"];
$discount = $GLOBALS["discount"];
if ($promocode && !$qualifies) {
$smartyvalues["promoerror"] = $_LANG["promoappliedbutnodiscount"];
}
$smarty->assign("configoptions", $configoption);
$smarty->assign("upgrades", $upgrades);
$gatewayslist = showPaymentGatewaysList(array(), $_SESSION["uid"]);
$paymentmethod = key($gatewayslist);
$smarty->assign("gateways", $gatewayslist);
$smarty->assign("allowgatewayselection", (bool) WHMCS\Config\Setting::getValue("AllowCustomerChangeInvoiceGateway"));
$smarty->assign("selectedgateway", $paymentmethod);
if ($CONFIG["TaxEnabled"]) {
$clientsdetails = getClientsDetails($_SESSION["uid"]);
$state = $clientsdetails["state"];
$country = $clientsdetails["country"];
$taxexempt = $clientsdetails["taxexempt"];
if (!$taxexempt) {
$smarty->assign("taxenabled", true);
$taxdata = getTaxRate(1, $state, $country);
$taxrate = $taxdata["rate"];
$taxname = $taxdata["name"];
$taxdata2 = getTaxRate(2, $state, $country);
$taxrate2 = $taxdata2["rate"];
$taxname2 = $taxdata2["name"];
}
}
$smartyvalues["subtotal"] = formatCurrency($subtotal);
$smartyvalues["discount"] = formatCurrency($discount);
$subtotal = $subtotal - $GLOBALS["discount"];
$tax = $tax2 = 0;
if ($applytax) {
if ($taxrate) {
if ($CONFIG["TaxType"] == "Inclusive") {
$inctaxrate = 1 + $taxrate / 100;
$tempsubtotal = $subtotal;
$subtotal = $subtotal / $inctaxrate;
$tax = $tempsubtotal - $subtotal;
} else {
$tax = $subtotal * $taxrate / 100;
}
}
if ($taxrate2) {
$tempsubtotal = $subtotal;
if ($CONFIG["TaxL2Compound"]) {
$tempsubtotal += $tax;
}
if ($CONFIG["TaxType"] == "Inclusive") {
$inctaxrate = 1 + $taxrate / 100;
$subtotal = $tempsubtotal / $inctaxrate;
$tax2 = $tempsubtotal - $subtotal;
} else {
$tax2 = $tempsubtotal * $taxrate2 / 100;
}
}
$tax = round($tax, 2);
$tax2 = round($tax2, 2);
}
$tax = format_as_currency($tax);
$tax2 = format_as_currency($tax2);
$smarty->assign("taxenabled", $CONFIG["TaxEnabled"]);
$smarty->assign("taxname", $taxname);
$smarty->assign("taxrate", $taxrate);
$smarty->assign("tax", formatCurrency($tax));
$smarty->assign("taxname2", $taxname2);
$smarty->assign("taxrate2", $taxrate2);
$smarty->assign("tax2", formatCurrency($tax2));
$total = $subtotal + $tax + $tax2;
$total = formatCurrency($total);
$smarty->assign("total", $total);
} else {
if ($step == "3") {
check_token();
$orderdescription = "";
$serviceid = $_POST["id"];
$paymentmethod = $_POST["paymentmethod"];
if ($type == "package") {
$newproductid = $_POST["pid"];
$newproductbillingcycle = $_POST["billingcycle"];
$upgrades = SumUpPackageUpgradeOrder($serviceid, $newproductid, $newproductbillingcycle, $promocode, $paymentmethod, true);
} else {
if ($type == "configoptions") {
$configoptions = $_POST["configoption"];
$upgrades = SumUpConfigOptionsOrder($serviceid, $configoptions, $promocode, $paymentmethod, true);
}
}
$ordernotes = "";
if ($notes && $notes != $_LANG["ordernotesdescription"]) {
$ordernotes = $notes;
}
$_SESSION["upgradeorder"] = createUpgradeOrder($serviceid, $ordernotes, $promocode, $paymentmethod);
redir("step=4");
} else {
if ($step == "4") {
$orderfrm = new WHMCS\OrderForm();
$invoiceid = (int) $invoiceid;
if ($invoiceid) {
$result = select_query("tblinvoices", "id,total,paymentmethod", array("userid" => $_SESSION["uid"], "id" => $invoiceid));
$data = mysql_fetch_array($result);
$invoiceid = $data["id"];
$total = $data["total"];
$paymentmethod = $data["paymentmethod"];
if ($invoiceid && 0 < $total) {
$paymentmethod = WHMCS\Gateways::makeSafeName($paymentmethod);
if (!$paymentmethod) {
exit("Unexpected payment method value. Exiting.");
}
$result = select_query("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "type"));
$data = mysql_fetch_array($result);
$gatewaytype = $data["value"];
if (($gatewaytype == "CC" || $gatewaytype == "OfflineCC") && ($CONFIG["AutoRedirectoInvoice"] == "on" || $CONFIG["AutoRedirectoInvoice"] == "gateway")) {
if (!isValidforPath($paymentmethod)) {
exit("Invalid Payment Gateway Name");
}
$gatewaypath = ROOTDIR . "/modules/gateways/" . $paymentmethod . ".php";
if (file_exists($gatewaypath)) {
require_once $gatewaypath;
}
if (!function_exists($paymentmethod . "_link")) {
$whmcs->redirect("creditcard.php", "invoiceid=" . (int) $invoiceid);
}
}
if ($CONFIG["AutoRedirectoInvoice"] == "on") {
$whmcs->redirect("viewinvoice.php", "id=" . (int) $invoiceid);
}
if ($CONFIG["AutoRedirectoInvoice"] == "gateway") {
$clientsdetails = getClientsDetails($_SESSION["uid"]);
$params = getGatewayVariables($paymentmethod, $invoiceid, $total);
$paymentbutton = call_user_func($paymentmethod . "_link", $params);
$templatefile = "forwardpage";
$smarty->assign("message", $_LANG["forwardingtogateway"]);
$smarty->assign("code", $paymentbutton);
$smarty->assign("invoiceid", $invoiceid);
outputClientArea($templatefile);
exit;
}
} else {
$smarty->assign("ispaid", true);
}
}
$templatefile = "complete";
$smarty->assign("orderid", (int) $orderid);
$smarty->assign("ordernumber", $order_number);
$smarty->assign("invoiceid", $invoiceid);
$smarty->assign("carttpl", WHMCS\View\Template\OrderForm::factory($templatefile . ".tpl")->getName());
$orderform = "true";
}
}
}
}
outputClientArea($templatefile, false, array("ClientAreaPageUpgrade"));
?>