forked from puarudz/WHMCS-7.8.0-decoded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientarea.php
executable file
·2735 lines (2733 loc) · 254 KB
/
clientarea.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* @ PHP 5.6
* @ Decoder version : 1.0.0.1
* @ Release on : 24.03.2018
* @ Website : http://EasyToYou.eu
*/
define("CLIENTAREA", true);
require __DIR__ . "/init.php";
require ROOTDIR . "/includes/clientfunctions.php";
require ROOTDIR . "/includes/gatewayfunctions.php";
require ROOTDIR . "/includes/ccfunctions.php";
require ROOTDIR . "/includes/domainfunctions.php";
require ROOTDIR . "/includes/registrarfunctions.php";
require ROOTDIR . "/includes/customfieldfunctions.php";
require ROOTDIR . "/includes/invoicefunctions.php";
require ROOTDIR . "/includes/configoptionsfunctions.php";
$action = $whmcs->get_req_var("action");
$sub = $whmcs->get_req_var("sub");
$id = (int) $whmcs->get_req_var("id");
$modop = $whmcs->get_req_var("modop");
$submit = $whmcs->get_req_var("submit");
$save = $whmcs->get_req_var("save");
$q = $whmcs->get_req_var("q");
$paymentmethod = WHMCS\Gateways::makeSafeName($whmcs->get_req_var("paymentmethod"));
$params = array();
$addRenewalToCart = $whmcs->get_req_var("addRenewalToCart");
if ($addRenewalToCart) {
check_token();
$renewID = $whmcs->get_req_var("renewID");
$renewalPeriod = $whmcs->get_req_var("period");
$_SESSION["cart"]["renewals"][$renewID] = $renewalPeriod;
WHMCS\Terminus::getInstance()->doExit();
} else {
if ($action == "resendVerificationEmail") {
check_token();
$clientDetails = WHMCS\User\Client::find(WHMCS\Session::get("uid"));
if (!is_null($clientDetails)) {
$clientDetails->sendEmailAddressVerification();
}
WHMCS\Terminus::getInstance()->doExit();
} else {
if ($action == "parseMarkdown") {
check_token();
$markup = new WHMCS\View\Markup\Markup();
echo json_encode(array("body" => $markup->transform($whmcs->get_req_var("content"), "markdown")));
WHMCS\Terminus::getInstance()->doExit();
} else {
if ($action == "manage-service") {
check_token();
$serviceId = App::getFromRequest("service-id");
$server = new WHMCS\Module\Server();
if (substr($serviceId, 0, 1) == "a") {
$server->loadByAddonId((int) substr($serviceId, 1));
$errorPrependText = "An error occurred when managing Service Addon ID: " . (int) substr($serviceId, 1) . ": ";
} else {
$serviceId = (int) $serviceId;
$server->loadByServiceID($serviceId);
$errorPrependText = "An error occurred when managing Service ID: " . $serviceId . ": ";
}
$serviceServerParams = $server->buildParams();
$allowedModuleFunctions = array();
$clientAreaAllowedFunctions = $server->call("ClientAreaAllowedFunctions");
if (is_array($clientAreaAllowedFunctions) && !array_key_exists("error", $clientAreaAllowedFunctions)) {
foreach ($clientAreaAllowedFunctions as $functionName) {
if (is_string($functionName)) {
$allowedModuleFunctions[] = $functionName;
}
}
}
$clientAreaCustomButtons = $server->call("ClientAreaCustomButtonArray");
if (is_array($clientAreaCustomButtons) && !array_key_exists("error", $clientAreaAllowedFunctions)) {
foreach ($clientAreaCustomButtons as $buttonLabel => $functionName) {
if (is_string($functionName)) {
$allowedModuleFunctions[] = $functionName;
}
}
}
if (WHMCS\Session::get("uid") == $serviceServerParams["userid"]) {
if (in_array("manage_order", $allowedModuleFunctions) && $server->functionExists("manage_order")) {
$apiResponse = $server->call("manage_order");
$apiResponse = isset($apiResponse["jsonResponse"]) ? $apiResponse["jsonResponse"] : array();
if (is_array($apiResponse) && !empty($apiResponse["success"])) {
$response = array("redirect" => $apiResponse["redirect"]);
} else {
$errorMsg = isset($apiResponse["error"]) ? $apiResponse["error"] : "An unknown error occurred";
$response = array("error" => $errorMsg);
}
} else {
$response = array("error" => "Function Not Allowed");
}
} else {
$response = array("error" => "Access Denied");
}
echo json_encode($response);
WHMCS\Terminus::getInstance()->doExit();
} else {
if ($action == "dismiss-email-banner") {
check_token();
WHMCS\Session::setAndRelease("DismissEmailVerificationBannerForSession", true);
echo json_encode(array("success" => true));
WHMCS\Terminus::getInstance()->doExit();
}
}
}
}
}
$activeLanguage = WHMCS\Session::get("Language");
if ($action == "changesq" || $whmcs->get_req_var("2fasetup")) {
$action = "security";
}
$ca = new WHMCS\ClientArea();
$ca->setPageTitle($whmcs->get_lang("clientareatitle"));
$ca->addToBreadCrumb("index.php", $whmcs->get_lang("globalsystemname"))->addToBreadCrumb("clientarea.php", $whmcs->get_lang("clientareatitle"));
$ca->initPage();
$legacyClient = new WHMCS\Client($ca->getClient());
$clientInformation = $legacyClient->getClientModel();
$clientInformationAvailable = is_null($clientInformation) ? false : true;
$verifyEmailAddressEnabled = WHMCS\Config\Setting::getValue("EnableEmailVerification");
$emailVerificationPending = false;
$emailVerificationRecentlyCleared = false;
$verificationIdNotValid = false;
$today = WHMCS\Carbon::today();
if ($verifyEmailAddressEnabled) {
$verificationId = $whmcs->get_req_var("verificationId");
if (!empty($verificationId)) {
$transientData = WHMCS\TransientData::getInstance();
$transientDataName = $transientData->retrieveByData($verificationId);
$initialVerificationId = WHMCS\Session::get("initialVerificationId");
$smartyvalues["verificationId"] = $verificationId;
$smartyvalues["transientDataName"] = $transientDataName;
if (!$clientInformationAvailable) {
WHMCS\Session::set("initialVerificationId", $verificationId);
} else {
if ($initialVerificationId != $verificationId && !$clientInformation->emailVerified) {
WHMCS\Session::delete("uid");
WHMCS\Session::set("initialVerificationId", $verificationId);
} else {
if ($transientDataName) {
$clientInformation->emailVerified = true;
$clientInformation->save();
run_hook("ClientEmailVerificationComplete", array("userId" => $ca->getUserID()));
$emailVerificationRecentlyCleared = true;
$transientData->delete($transientDataName);
WHMCS\Session::delete("initialVerificationId");
} else {
if (!$clientInformation->emailVerified) {
$verificationIdNotValid = true;
}
}
}
}
}
if ($clientInformationAvailable) {
$isEmailAddressVerified = $clientInformation->isEmailAddressVerified();
if (!$isEmailAddressVerified && !WHMCS\Session::get("DismissEmailVerificationBannerForSession")) {
$emailVerificationPending = true;
}
}
}
$smartyvalues["emailVerificationPending"] = $emailVerificationPending;
$ca->requireLogin();
if ($emailVerificationRecentlyCleared) {
$smartyvalues["emailVerificationIdValid"] = true;
} else {
if ($verificationIdNotValid) {
$smartyvalues["emailVerificationIdValid"] = false;
}
}
if ($action == "hosting") {
$ca->addToBreadCrumb("clientarea.php?action=hosting", $whmcs->get_lang("clientareanavhosting"));
}
if (in_array($action, array("products", "services", "cancel"))) {
$ca->addToBreadCrumb("clientarea.php?action=products", $whmcs->get_lang("clientareaproducts"));
}
if (in_array($action, array("domains", "domaindetails", "domaincontacts", "domaindns", "domainemailforwarding", "domaingetepp", "domainregisterns", "domainaddons"))) {
$ca->addToBreadCrumb("clientarea.php?action=domains", $whmcs->get_lang("clientareanavdomains"));
}
if ($action == "invoices") {
$ca->addToBreadCrumb("clientarea.php?action=invoices", $whmcs->get_lang("invoices"));
}
if ($action == "emails") {
$ca->addToBreadCrumb("clientarea.php?action=emails", $whmcs->get_lang("clientareaemails"));
}
if ($action == "addfunds") {
$ca->addToBreadCrumb("clientarea.php?action=addfunds", $whmcs->get_lang("addfunds"));
}
if ($action == "masspay") {
$ca->addToBreadCrumb("clientarea.php?action=masspay" . ($whmcs->get_req_var("all") ? "&all=true" : "") . "#", $whmcs->get_lang("masspaytitle"));
}
if ($action == "quotes") {
$ca->addToBreadCrumb("clientarea.php?action=quotes", $whmcs->get_lang("quotestitle"));
}
$currency = $legacyClient->getCurrency();
if (substr($action, 0, 6) == "domain" && $action != "domains") {
$domainID = $whmcs->get_req_var("id");
if (!$domainID) {
$domainID = $whmcs->get_req_var("domainid");
}
$domains = new WHMCS\Domains();
$domainData = $domains->getDomainsDatabyID($domainID);
if (!$domainData) {
redir("action=domains", "clientarea.php");
}
$domainModel = WHMCS\Domain\Domain::find($domainData["id"]);
$ca->setDisplayTitle(Lang::trans("managing") . " " . $domainData["domain"]);
$domainName = new WHMCS\Domains\Domain($domainData["domain"]);
$managementOptions = $domains->getManagementOptions();
if ($domainModel->registrarModuleName) {
$registrar = new WHMCS\Module\Registrar();
$registrar->setDomainID($domainModel->id);
if ($registrar->load($domainModel->registrarModuleName)) {
$params = $registrar->getSettings();
}
}
$ca->assign("managementoptions", $managementOptions);
}
$ca->assign("action", $action);
$ca->assign("clientareaaction", $action);
if ($action == "") {
$templateVars = $ca->getTemplateVariables();
$ca->setDisplayTitle(Lang::trans("welcomeback") . ", " . $templateVars["loggedinuser"]["firstname"]);
$ca->setTemplate("clientareahome");
$clientId = $ca->getClient()->id;
$panels = array();
if (checkContactPermission("invoices", true)) {
$invoiceTypeItemInvoiceIds = WHMCS\Database\Capsule::table("tblinvoiceitems")->where("userid", $userid)->where("type", "Invoice")->pluck("invoiceid");
$invoices = WHMCS\Database\Capsule::table("tblinvoices")->where("tblinvoices.userid", $clientId)->where("status", "Unpaid")->where("duedate", WHMCS\Carbon::now()->toDateString())->whereNotIn("tblinvoices.id", $invoiceTypeItemInvoiceIds)->leftJoin("tblaccounts", "tblaccounts.invoiceid", "=", "tblinvoices.id")->first(array(WHMCS\Database\Capsule::raw("IFNULL(count(tblinvoices.id), 0) as invoice_count"), WHMCS\Database\Capsule::raw("IFNULL(SUM(total), 0) as total"), WHMCS\Database\Capsule::raw("IFNULL(SUM(amountin), 0) as amount_in"), WHMCS\Database\Capsule::raw("IFNULL(SUM(amountout), 0) as amount_out")));
if (0 < $invoices->invoice_count) {
$msg = Lang::trans("clientHomePanels.overdueInvoicesMsg", array(":numberOfInvoices" => $invoices->invoice_count, ":balanceDue" => formatCurrency($invoices->total - $invoices->amount_in + $invoices->amount_out)));
$panels[] = array("name" => "Overdue Invoices", "label" => Lang::trans("clientHomePanels.overdueInvoices"), "icon" => "fa-calculator", "extras" => array("color" => "red", "btn-icon" => "fas fa-arrow-right", "btn-link" => "clientarea.php?action=masspay&all=true", "btn-text" => Lang::trans("invoicespaynow")), "bodyHtml" => "<p>" . $msg . "</p>", "order" => "10");
} else {
$invoices = WHMCS\Database\Capsule::table("tblinvoices")->where("tblinvoices.userid", $clientId)->where("status", "Unpaid")->whereNotIn("tblinvoices.id", $invoiceTypeItemInvoiceIds)->leftJoin("tblaccounts", "tblaccounts.invoiceid", "=", "tblinvoices.id")->first(array(WHMCS\Database\Capsule::raw("IFNULL(count(tblinvoices.id), 0) as invoice_count"), WHMCS\Database\Capsule::raw("IFNULL(SUM(total), 0) as total"), WHMCS\Database\Capsule::raw("IFNULL(SUM(amountin), 0) as amount_in"), WHMCS\Database\Capsule::raw("IFNULL(SUM(amountout), 0) as amount_out")));
if (0 < $invoices->invoice_count) {
$msg = Lang::trans("clientHomePanels.overdueInvoicesMsg", array(":numberOfInvoices" => $invoices->invoice_count, ":balanceDue" => formatCurrency($invoices->total - $invoices->amount_in + $invoices->amount_out)));
$panels[] = array("name" => "Unpaid Invoices", "label" => Lang::trans("clientHomePanels.unpaidInvoices"), "icon" => "fa-calculator", "extras" => array("color" => "red", "btn-icon" => "fas fa-arrow-right", "btn-link" => "clientarea.php?action=invoices", "btn-text" => Lang::trans("viewAll")), "bodyHtml" => "<p>" . $msg . "</p>", "order" => "10");
}
}
}
if (checkContactPermission("domains", true)) {
$domainsDueWithin45Days = $ca->getClient()->domains()->nextDueBefore(WHMCS\Carbon::now()->addDays(45))->count();
if (0 < $domainsDueWithin45Days) {
$msg = Lang::trans("clientHomePanels.domainsExpiringSoonMsg", array(":days" => 45, ":numberOfDomains" => $domainsDueWithin45Days));
$extras = array();
if (WHMCS\Config\Setting::getValue("EnableDomainRenewalOrders")) {
$extras = array("btn-icon" => "fas fa-sync", "btn-link" => routePath("cart-domain-renewals"), "btn-text" => Lang::trans("domainsrenewnow"));
}
$extras["color"] = "midnight-blue";
$panels[] = array("name" => "Domains Expiring Soon", "label" => Lang::trans("clientHomePanels.domainsExpiringSoon"), "icon" => "fa-globe", "extras" => $extras, "bodyHtml" => "<p>" . $msg . "</p>", "order" => "50");
}
}
if (checkContactPermission("products", true)) {
$servicesList = array();
$services = $ca->getClient()->services()->whereIn("domainstatus", array("Active", "Suspended"))->orderBy("domainstatus", "asc")->orderBy("id", "desc")->limit(101)->get();
foreach ($services as $service) {
$groupName = $service->product->productGroup->name;
$productName = $service->product->name;
$domain = "<span class=\"text-domain\">" . $service->domain . "</span>";
$labelClass = "label pull-right label-success";
if ($service->domainStatus == "Suspended") {
$labelClass = "label pull-right label-warning";
}
$status = Lang::trans("clientarea" . $ca->getRawStatus($service->domainStatus));
$label = "<span class=\"" . $labelClass . "\">" . $status . "</span>";
$servicesList[] = array("uri" => "clientarea.php?action=productdetails&id=" . $service->id, "label" => $groupName . " - " . $productName . $label . "<br />" . $domain);
}
$servicesPanel = array("name" => "Active Products/Services", "label" => Lang::trans("clientHomePanels.activeProductsServices"), "icon" => "fa-cube", "extras" => array("color" => "gold", "btn-icon" => "fas fa-plus", "btn-link" => "clientarea.php?action=services", "btn-text" => Lang::trans("viewAll")), "children" => $servicesList, "order" => "100");
$bodyHtml = "";
if (count($servicesList) == 0) {
$bodyHtml .= "<p>" . Lang::trans("clientHomePanels.activeProductsServicesNone") . "</p>";
} else {
if (100 < count($servicesList)) {
unset($servicesPanel["children"][100]);
$bodyHtml .= "<p>" . Lang::trans("clientHomePanels.showingRecent100") . ".</p>";
}
}
if ($bodyHtml) {
$servicesPanel["bodyHtml"] = $bodyHtml;
}
$panels[] = $servicesPanel;
}
if (checkContactPermission("orders", true) && (WHMCS\Config\Setting::getValue("AllowRegister") || WHMCS\Config\Setting::getValue("AllowTransfer"))) {
$bodyContent = "<form method=\"post\" action=\"domainchecker.php\">\n <div class=\"input-group margin-10\">\n <input type=\"text\" name=\"domain\" class=\"form-control\" />\n <div class=\"input-group-btn\">";
if (WHMCS\Config\Setting::getValue("AllowRegister")) {
$bodyContent .= "\n <input type=\"submit\" value=\"" . Lang::trans("domainsregister") . "\" class=\"btn btn-success\" />";
}
if (WHMCS\Config\Setting::getValue("AllowTransfer")) {
$bodyContent .= "\n <input type=\"submit\" name=\"transfer\" value=\"" . Lang::trans("domainstransfer") . "\" class=\"btn\" />";
}
$bodyContent .= "\n </div>\n </div>\n </form>";
$panels[] = array("name" => "Register a New Domain", "label" => Lang::trans("navregisterdomain"), "icon" => "fa-globe", "extras" => array("color" => "emerald"), "bodyHtml" => $bodyContent, "order" => "200");
}
if (WHMCS\Config\Setting::getValue("AffiliateEnabled") && checkContactPermission("affiliates", true) && !is_null($affiliate = $ca->getClient()->affiliate)) {
$currencyLimit = convertCurrency(WHMCS\Config\Setting::getValue("AffiliatePayout"), 1, $currency["id"]);
$amountUntilWithdrawal = $currencyLimit - $affiliate->balance;
if (0 < $amountUntilWithdrawal) {
$msgTemplate = "clientHomePanels.affiliateSummary";
} else {
$msgTemplate = "clientHomePanels.affiliateSummaryWithdrawalReady";
}
$msg = Lang::trans($msgTemplate, array(":commissionBalance" => formatCurrency($affiliate->balance), ":amountUntilWithdrawalLevel" => formatCurrency($amountUntilWithdrawal)));
$panels[] = array("name" => "Affiliate Program", "label" => Lang::trans("clientHomePanels.affiliateProgram"), "icon" => "fa-users", "extras" => array("color" => "teal", "btn-icon" => "fas fa-arrow-right", "btn-link" => "affiliates.php", "btn-text" => Lang::trans("moreDetails")), "bodyHtml" => "<p>" . $msg . "</p>", "order" => "300");
}
if (!function_exists("AddNote")) {
require ROOTDIR . DIRECTORY_SEPARATOR . "includes" . DIRECTORY_SEPARATOR . "ticketfunctions.php";
}
$tickets = array();
$statusfilter = array();
$result = select_query("tblticketstatuses", "title", array("showactive" => "1"));
while ($data = mysql_fetch_array($result)) {
$statusfilter[] = $data[0];
}
$result = select_query("tbltickets", "", array("userid" => (int) $legacyClient->getID(), "status" => array("sqltype" => "IN", "values" => $statusfilter), "merged_ticket_id" => 0), "lastreply", "DESC");
while ($data = mysql_fetch_array($result)) {
$id = $data["id"];
$tid = $data["tid"];
$c = $data["c"];
$deptid = $data["did"];
$date = $data["date"];
$date = fromMySQLDate($date, 1, 1);
$subject = $data["title"];
$status = $data["status"];
$urgency = $data["urgency"];
$lastreply = $data["lastreply"];
$lastreply = fromMySQLDate($lastreply, 1, 1);
$clientunread = $data["clientunread"];
$htmlFormattedStatus = getStatusColour($status);
$dept = getDepartmentName($deptid);
$urgency = Lang::trans("supportticketsticketurgency" . strtolower($urgency));
$statusClass = WHMCS\View\Helper::generateCssFriendlyClassName($status);
$tickets[] = array("id" => $id, "tid" => $tid, "c" => $c, "date" => $date, "department" => $dept, "subject" => $subject, "status" => $htmlFormattedStatus, "statusClass" => $statusClass, "urgency" => $urgency, "lastreply" => $lastreply, "unread" => $clientunread);
}
$ca->assign("tickets", $tickets);
if (checkContactPermission("tickets", true)) {
$ticketsList = array();
$rawStatusColors = WHMCS\Database\Capsule::table("tblticketstatuses")->get();
$ticketRows = WHMCS\Database\Capsule::table("tbltickets")->where("userid", "=", $legacyClient->getID())->where("merged_ticket_id", "=", "0")->orderBy("lastreply", "DESC")->limit(10)->get();
foreach ($ticketRows as $data) {
$id = $data->id;
$tid = $data->tid;
$c = $data->c;
$subject = $data->title;
$status = $data->status;
$lastreply = $data->lastreply;
$clientunread = $data->clientunread;
$lastreply = fromMySQLDate($lastreply, 1, 1);
$statusColors = array();
foreach ($rawStatusColors as $color) {
$statusColors[$color->title] = $color->color;
}
$langStatus = preg_replace("/[^a-z]/i", "", strtolower($status));
if (Lang::trans("supportticketsstatus" . $langStatus) != "supportticketsstatus" . $langStatus) {
$statusText = Lang::trans("supportticketsstatus" . $langStatus);
} else {
$statusText = $status;
}
$ticketsList[] = array("uri" => "viewticket.php?tid=" . $tid . "&c=" . $c, "label" => ($clientunread ? "<strong>" : "") . "#" . $tid . " - " . $subject . ($clientunread ? "</strong> " : " ") . "<label class=\"label\" style=\"background-color: " . $statusColors[$status] . "\">" . $statusText . "</label><br />" . "<small>" . Lang::trans("supportticketsticketlastupdated") . ": " . $lastreply . "</small>");
}
$ticketsPanel = array("name" => "Recent Support Tickets", "label" => Lang::trans("clientHomePanels.recentSupportTickets"), "icon" => "fa-comments", "extras" => array("color" => "blue", "btn-icon" => "fas fa-plus", "btn-link" => "submitticket.php", "btn-text" => Lang::trans("opennewticket")), "children" => $ticketsList, "order" => "150");
if (count($ticketsList) == 0) {
$ticketsPanel["bodyHtml"] = "<p>" . Lang::trans("clientHomePanels.recentSupportTicketsNone") . "</p>";
}
$panels[] = $ticketsPanel;
}
$invoice = new WHMCS\Invoice();
$invoices = $invoice->getInvoices("Unpaid", $legacyClient->getID(), "id", "DESC");
$ca->assign("invoices", $invoices);
$ca->assign("totalbalance", $invoice->getTotalBalanceFormatted());
$ca->assign("masspay", WHMCS\Config\Setting::getValue("EnableMassPay"));
$ca->assign("defaultpaymentmethod", getGatewayName($clientsdetails["defaultgateway"]));
$ca->assign("addfundsenabled", WHMCS\Config\Setting::getValue("AddFundsEnabled"));
$files = $legacyClient->getFiles($legacyClient->getID());
$ca->assign("files", $files);
if (0 < count($files)) {
$filesList = array();
foreach ($files as $file) {
$filesList[] = array("label" => $file["title"] . "<br /><small>" . $file["date"] . "</small>", "uri" => "dl.php?type=f&id=" . $file["id"]);
}
$panels[] = array("name" => "Your Files", "label" => Lang::trans("clientareafiles"), "icon" => "fa-download", "extras" => array("color" => "purple"), "children" => $filesList, "order" => "250");
}
$announcementsList = array();
$announcements = WHMCS\Announcement\Announcement::wherePublished(true)->orderBy("date", "DESC")->take(3)->get();
foreach ($announcements as $announcement) {
$announcementTitle = $announcement->title;
$announcementContent = $announcement->announcement;
if ($activeLanguage) {
try {
$announcementLocal = WHMCS\Announcement\Announcement::whereParentid($announcement->id)->whereLanguage($activeLanguage)->firstOrFail();
$announcementTitle = $announcementLocal->title;
$announcementContent = $announcementLocal->announcement;
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
}
}
$uri = getModRewriteFriendlyString($announcementTitle);
$announcementsList[] = array("id" => $announcement->id, "date" => fromMySQLDate($announcement->date, 0, 1), "title" => $announcementTitle, "urlfriendlytitle" => $uri, "text" => $announcementContent, "label" => $announcementTitle . "<br /><span class=\"text-last-updated\">" . fromMySQLDate($announcement->publishDate, 0, 1) . "</span>", "uri" => routePath("announcement-view", $announcement->id, $uri));
}
$smartyvalues["announcements"] = $announcementsList;
$panels[] = array("name" => "Recent News", "label" => Lang::trans("clientHomePanels.recentNews"), "icon" => "far fa-newspaper", "extras" => array("color" => "asbestos", "btn-icon" => "fas fa-arrow-right", "btn-link" => routePath("announcement-index"), "btn-text" => Lang::trans("viewAll")), "children" => $announcementsList, "order" => "500");
$smartyvalues["registerdomainenabled"] = (bool) WHMCS\Config\Setting::getValue("AllowRegister");
$smartyvalues["transferdomainenabled"] = (bool) WHMCS\Config\Setting::getValue("AllowTransfer");
$smartyvalues["owndomainenabled"] = (bool) WHMCS\Config\Setting::getValue("AllowOwnDomain");
$captcha = new WHMCS\Utility\Captcha();
$smartyvalues["captcha"] = $captcha;
$smartyvalues["captchaForm"] = WHMCS\Utility\Captcha::FORM_REGISTRATION;
$smartyvalues["recaptchahtml"] = clientAreaReCaptchaHTML();
$smartyvalues["contacts"] = $legacyClient->getContacts();
$addons_html = run_hook("ClientAreaHomepage", array());
$ca->assign("addons_html", $addons_html);
$factory = new WHMCS\View\Menu\MenuFactory();
$item = $factory->getLoader()->load(array("name" => "ClientAreaHomePagePanels", "children" => $panels));
run_hook("ClientAreaHomepagePanels", array($item), true);
$smartyvalues["panels"] = WHMCS\View\Menu\Item::sort($item);
$ca->addOutputHookFunction("ClientAreaPageHome");
} else {
if ($action == "details") {
checkContactPermission("profile");
$ca->setDisplayTitle(Lang::trans("clientareanavdetails"));
$ca->setTemplate("clientareadetails");
$ca->addToBreadCrumb("clientarea.php?action=details", Lang::trans("clientareanavdetails"));
$uneditablefields = explode(",", WHMCS\Config\Setting::getValue("ClientsProfileUneditableFields"));
$smartyvalues["uneditablefields"] = $uneditablefields;
$e = "";
$exdetails = array();
$ca->assign("successful", false);
if ($save) {
check_token();
$e = checkDetailsareValid($legacyClient->getID(), false);
if ($e) {
$ca->assign("errormessage", $e);
} else {
$legacyClient->updateClient();
redir("action=details&success=1");
}
}
if ($whmcs->get_req_var("success")) {
$ca->assign("successful", true);
}
if (!$e) {
$exdetails = $legacyClient->getDetails();
}
$countries = new WHMCS\Utility\Country();
$ca->assign("clientfirstname", $whmcs->get_req_var_if($e, "firstname", $exdetails));
$ca->assign("clientlastname", $whmcs->get_req_var_if($e, "lastname", $exdetails));
$ca->assign("clientcompanyname", $whmcs->get_req_var_if($e, "companyname", $exdetails));
$ca->assign("clientemail", $whmcs->get_req_var_if($e, "email", $exdetails));
$ca->assign("clientaddress1", $whmcs->get_req_var_if($e, "address1", $exdetails));
$ca->assign("clientaddress2", $whmcs->get_req_var_if($e, "address2", $exdetails));
$ca->assign("clientcity", $whmcs->get_req_var_if($e, "city", $exdetails));
$ca->assign("clientstate", $whmcs->get_req_var_if($e, "state", $exdetails));
$ca->assign("clientpostcode", $whmcs->get_req_var_if($e, "postcode", $exdetails));
$ca->assign("clientcountry", $countries->getName($whmcs->get_req_var_if($e, "country", $exdetails)));
$ca->assign("clientcountriesdropdown", getCountriesDropDown($whmcs->get_req_var_if($e, "country", $exdetails), "", "", false, in_array("country", $uneditablefields)));
$phoneNumber = $e ? App::formatPostedPhoneNumber() : $exdetails["telephoneNumber"];
$ca->assign("clientphonenumber", $phoneNumber);
$ca->assign("clientTaxId", $whmcs->get_req_var_if($e, "tax_id", $exdetails));
$ca->assign("customfields", getCustomFields("client", "", $legacyClient->getID(), "", "", $whmcs->get_req_var("customfield")));
$ca->assign("contacts", $legacyClient->getContacts());
$ca->assign("billingcid", $whmcs->get_req_var_if($e, "billingcid", $exdetails));
$ca->assign("paymentmethods", showPaymentGatewaysList(array(), $legacyClient->getID()));
$ca->assign("taxIdLabel", WHMCS\Billing\Tax\Vat::getLabel());
$ca->assign("showTaxIdField", WHMCS\Billing\Tax\Vat::isUsingNativeField());
$ca->assign("showMarketingEmailOptIn", WHMCS\Config\Setting::getValue("AllowClientsEmailOptOut"));
$ca->assign("marketingEmailOptInMessage", Lang::trans("emailMarketing.optInMessage") != "emailMarketing.optInMessage" ? Lang::trans("emailMarketing.optInMessage") : WHMCS\Config\Setting::getValue("EmailMarketingOptInMessage"));
$ca->assign("marketingEmailOptIn", App::isInRequest("marketingoptin") ? (bool) App::getFromRequest("marketingoptin") : $legacyClient->getClientModel()->isOptedInToMarketingEmails());
$ca->assign("defaultpaymentmethod", $whmcs->get_req_var_if($e, "paymentmethod", $exdetails, "defaultgateway"));
$ca->addOutputHookFunction("ClientAreaPageProfile");
} else {
if ($action == "contacts") {
checkContactPermission("contacts");
$ca->setDisplayTitle(Lang::trans("clientareanavcontacts"));
$ca->setTemplate("clientareacontacts");
$ca->addToBreadCrumb("clientarea.php?action=details", $whmcs->get_lang("clientareanavdetails"));
$ca->addToBreadCrumb("clientarea.php?action=contacts", $whmcs->get_lang("clientareanavcontacts"));
$contact_data = array();
$contactid = $whmcs->get_req_var("contactid");
if ($contactid) {
if ($contactid == "new") {
redir("action=addcontact");
}
$id = (int) $contactid;
}
if ($id) {
$contact_data = $legacyClient->getContact($id);
if (!$contact_data) {
redir("action=contacts", "clientarea.php");
}
$id = $contact_data["id"];
}
if ($whmcs->get_req_var("delete")) {
check_token();
$legacyClient->deleteContact($id);
redir("action=contacts");
}
$e = "";
$smartyvalues["successful"] = false;
if ($submit) {
check_token();
$errormessage = $e = checkContactDetails($id, $whmcs->get_req_var("password") ? true : false);
$subaccount = $whmcs->get_req_var("subaccount");
if (!$subaccount) {
$password = $permissions = "";
}
$smartyvalues["errormessage"] = $errormessage;
if (!$errormessage) {
$oldcontactdata = get_query_vals("tblcontacts", "", array("userid" => $legacyClient->getID(), "id" => $id));
$array = db_build_update_array(array("firstname", "lastname", "companyname", "email", "address1", "address2", "city", "state", "postcode", "country", "phonenumber", "subaccount", "permissions", "generalemails", "productemails", "domainemails", "invoiceemails", "supportemails", "tax_id"), "implode");
if ($array["phonenumber"]) {
$array["phonenumber"] = $phonenumber = App::formatPostedPhoneNumber();
}
$array["subaccount"] = $subaccount ? "1" : "0";
$password = $whmcs->get_req_var("password");
if ($password) {
$hasher = new WHMCS\Security\Hash\Password();
$array["password"] = $hasher->hash(WHMCS\Input\Sanitize::decode($password));
}
update_query("tblcontacts", $array, array("userid" => $legacyClient->getID(), "id" => $id));
if (!$subaccount) {
WHMCS\Authentication\Remote\AccountLink::where("contact_id", "=", $id)->where("client_id", "=", $legacyClient->getID())->delete();
}
run_hook("ContactEdit", array_merge(array("userid" => $legacyClient->getID(), "contactid" => $id, "olddata" => $oldcontactdata), $array));
logActivity("Client Contact Modified - User ID: " . $legacyClient->getID() . " - Contact ID: " . $id);
$smartyvalues["successful"] = true;
}
}
if ($whmcs->get_req_var("success")) {
$smartyvalues["successful"] = true;
}
$contactsarray = $legacyClient->getContacts();
if (!$id && count($contactsarray)) {
$id = $contactsarray[0]["id"];
}
if (!$id) {
redir("action=addcontact");
}
$smartyvalues["contacts"] = $contactsarray;
$smartyvalues["contactid"] = $id;
$remoteAuth = DI::make("remoteAuth");
if ($id) {
$contact = WHMCS\User\Client\Contact::find($id);
$remoteAccountLinks = array();
if ($contact) {
$smartyvalues["hasLinkedProvidersEnabled"] = (bool) count($remoteAuth->getProviders());
$linkUrl = routePath("auth-manage-client-links");
if (strpos($linkUrl, "?") !== false) {
$linkUrl .= "&cid=" . $id;
} else {
$linkUrl .= "?cid=" . $id;
}
$smartyvalues["linkedAccountsUrl"] = $linkUrl;
foreach ($contact->remoteAccountLinks()->get() as $remoteAccountLink) {
$provider = $remoteAuth->getProviderByName($remoteAccountLink->provider);
$remoteAccountLinks[$remoteAccountLink->id] = $provider->parseMetadata($remoteAccountLink->metadata);
}
$smartyvalues["remoteAccountLinks"] = $remoteAccountLinks;
}
}
if (!$errormessage && $submit && $id || $id && !count($contact_data)) {
$contact_data = $legacyClient->getContact($id);
if (!$contact_data) {
redir("action=contacts", "clientarea.php");
}
}
$smartyvalues["contactfirstname"] = $whmcs->get_req_var_if($e, "firstname", $contact_data);
$smartyvalues["contactlastname"] = $whmcs->get_req_var_if($e, "lastname", $contact_data);
$smartyvalues["contactcompanyname"] = $whmcs->get_req_var_if($e, "companyname", $contact_data);
$smartyvalues["contactemail"] = $whmcs->get_req_var_if($e, "email", $contact_data);
$smartyvalues["contactaddress1"] = $whmcs->get_req_var_if($e, "address1", $contact_data);
$smartyvalues["contactaddress2"] = $whmcs->get_req_var_if($e, "address2", $contact_data);
$smartyvalues["contactcity"] = $whmcs->get_req_var_if($e, "city", $contact_data);
$smartyvalues["contactstate"] = $whmcs->get_req_var_if($e, "state", $contact_data);
$smartyvalues["contactpostcode"] = $whmcs->get_req_var_if($e, "postcode", $contact_data);
$smartyvalues["contactphonenumber"] = $whmcs->get_req_var_if($e, "phonenumber", $contact_data);
$smartyvalues["contactTaxId"] = $whmcs->get_req_var_if($e, "tax_id", $contact_data);
$smartyvalues["countriesdropdown"] = getCountriesDropDown($whmcs->get_req_var_if($e, "country", $contact_data), "", "", false);
$smartyvalues["subaccount"] = $whmcs->get_req_var_if($e, "subaccount", $contact_data);
$permissions = $whmcs->get_req_var_if($e, "permissions", $contact_data);
if ($permissions == "") {
$permissions = array();
}
$smartyvalues["allPermissions"] = WHMCS\User\Client\Contact::$allPermissions;
$smartyvalues["permissions"] = $permissions;
$smartyvalues["generalemails"] = $whmcs->get_req_var_if($e, "generalemails", $contact_data);
$smartyvalues["productemails"] = $whmcs->get_req_var_if($e, "productemails", $contact_data);
$smartyvalues["domainemails"] = $whmcs->get_req_var_if($e, "domainemails", $contact_data);
$smartyvalues["invoiceemails"] = $whmcs->get_req_var_if($e, "invoiceemails", $contact_data);
$smartyvalues["supportemails"] = $whmcs->get_req_var_if($e, "supportemails", $contact_data);
$smartyvalues["taxIdLabel"] = WHMCS\Billing\Tax\Vat::getLabel();
$ca->addOutputHookFunction("ClientAreaPageContacts");
} else {
if ($action == "addcontact") {
checkContactPermission("contacts");
$ca->setDisplayTitle(Lang::trans("clientareanavaddcontact"));
$ca->setTemplate("clientareaaddcontact");
$ca->addToBreadCrumb("clientarea.php?action=details", $whmcs->get_lang("clientareanavdetails"));
$ca->addToBreadCrumb("clientarea.php?action=addcontact", $whmcs->get_lang("clientareanavaddcontact"));
$firstname = $whmcs->get_req_var("firstname");
$lastname = $whmcs->get_req_var("lastname");
$companyname = $whmcs->get_req_var("companyname");
$email = $whmcs->get_req_var("email");
$address1 = $whmcs->get_req_var("address1");
$address2 = $whmcs->get_req_var("address2");
$city = $whmcs->get_req_var("city");
$state = $whmcs->get_req_var("state");
$postcode = $whmcs->get_req_var("postcode");
$country = $whmcs->get_req_var("country");
$phonenumber = $whmcs->get_req_var("phonenumber");
$subaccount = $whmcs->get_req_var("subaccount");
$permissions = $whmcs->get_req_var("permissions");
$generalemails = $whmcs->get_req_var("generalemails");
$productemails = $whmcs->get_req_var("productemails");
$domainemails = $whmcs->get_req_var("domainemails");
$invoiceemails = $whmcs->get_req_var("invoiceemails");
$supportemails = $whmcs->get_req_var("supportemails");
$taxId = App::getFromRequest("tax_id");
if ($submit) {
check_token();
$errormessage = checkContactDetails("", true);
if (!$subaccount) {
$password = $permissions = "";
}
$smartyvalues["errormessage"] = $errormessage;
if (!$errormessage) {
$contactid = addContact($legacyClient->getID(), $firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $password, $permissions, $generalemails, $productemails, $domainemails, $invoiceemails, $supportemails, "", $taxId);
redir("action=contacts&id=" . $contactid . "&success=1");
}
}
$contactsarray = $legacyClient->getContacts();
$smartyvalues["contacts"] = $contactsarray;
if (!$permissions) {
$permissions = array();
}
$smartyvalues["contactfirstname"] = $firstname;
$smartyvalues["contactlastname"] = $lastname;
$smartyvalues["contactcompanyname"] = $companyname;
$smartyvalues["contactemail"] = $email;
$smartyvalues["contactaddress1"] = $address1;
$smartyvalues["contactaddress2"] = $address2;
$smartyvalues["contactcity"] = $city;
$smartyvalues["contactstate"] = $state;
$smartyvalues["contactpostcode"] = $postcode;
$smartyvalues["contactphonenumber"] = $phonenumber;
$smartyvalues["contactTaxId"] = $taxId;
$smartyvalues["countriesdropdown"] = getCountriesDropDown($country, "", "", false);
$smartyvalues["subaccount"] = $subaccount;
$smartyvalues["allPermissions"] = WHMCS\User\Client\Contact::$allPermissions;
$smartyvalues["permissions"] = $permissions;
$smartyvalues["generalemails"] = $generalemails;
$smartyvalues["productemails"] = $productemails;
$smartyvalues["domainemails"] = $domainemails;
$smartyvalues["invoiceemails"] = $invoiceemails;
$smartyvalues["supportemails"] = $supportemails;
$smartyvalues["taxIdLabel"] = WHMCS\Billing\Tax\Vat::getLabel();
$smartyvalues["showTaxIdField"] = WHMCS\Billing\Tax\Vat::isUsingNativeField(true);
$ca->addOutputHookFunction("ClientAreaPageAddContact");
} else {
if ($action == "creditcard") {
App::redirectToRoutePath("account-paymentmethods");
} else {
if ($action == "changepw") {
$ca->setDisplayTitle(Lang::trans("clientareanavchangepw"));
$ca->setTemplate("clientareachangepw");
$ca->addToBreadCrumb("clientarea.php?action=details", $whmcs->get_lang("clientareanavdetails"));
$ca->addToBreadCrumb("clientarea.php?action=changepw", $whmcs->get_lang("clientareanavchangepw"));
$validate = new WHMCS\Validate();
if ($submit) {
check_token();
$existingpw = WHMCS\Input\Sanitize::decode($existingpw);
$newpw = WHMCS\Input\Sanitize::decode($newpw);
$confirmpw = WHMCS\Input\Sanitize::decode($confirmpw);
$userId = $legacyClient->getID();
$contactId = (int) WHMCS\Session::get("cid");
if ($contactId) {
$result = select_query("tblcontacts", "password", array("id" => $contactId, "userid" => $userId));
} else {
$result = select_query("tblclients", "password", array("id" => $userId));
}
$data = mysql_fetch_array($result);
$storedPasswordHash = $data["password"];
if ($validate->validate("password_verify", "existingpwd", "existingpasswordincorrect", array($existingpw, $storedPasswordHash)) && $validate->validate("required", "newpw", "ordererrorpassword") && $validate->validate("pwstrength", "newpw", "pwstrengthfail") && $validate->validate("required", "confirmpw", "clientareaerrorpasswordconfirm")) {
$validate->validate("match_value", "newpw", "clientareaerrorpasswordnotmatch", "confirmpw");
}
if (!$validate->hasErrors()) {
$hasher = new WHMCS\Security\Hash\Password();
$passwordToSave = $hasher->hash($newpw);
if ($contactId) {
update_query("tblcontacts", array("password" => $passwordToSave), array("id" => $contactId, "userid" => $userId));
run_hook("ContactChangePassword", array("userid" => $userId, "contactid" => $contactId, "password" => $newpw));
} else {
update_query("tblclients", array("password" => $passwordToSave), array("id" => $userId));
run_hook("ClientChangePassword", array("userid" => $userId, "password" => $newpw));
}
WHMCS\Session::set("upw", WHMCS\Authentication\Client::generateClientLoginHash($userId, $contactId, $passwordToSave));
logActivity("Modified Password - User ID: " . $legacyClient->getID() . (isset($_SESSION["cid"]) ? " - Contact ID: " . $_SESSION["cid"] : ""));
redir("action=changepw&success=1");
}
}
$smartyvalues["successful"] = $whmcs->get_req_var("success") ? true : false;
$smartyvalues["errormessage"] = $validate->getHTMLErrorOutput();
$ca->addOutputHookFunction("ClientAreaPageChangePassword");
} else {
if ($action == "security") {
$ca->setDisplayTitle(Lang::trans("clientareanavsecurity"));
$ca->setTemplate("clientareasecurity");
$ca->addToBreadCrumb("clientarea.php?action=details", $whmcs->get_lang("clientareanavdetails"));
$ca->addToBreadCrumb("clientarea.php?action=security", $whmcs->get_lang("clientareanavsecurity"));
if (!WHMCS\Session::get("cid")) {
if ($whmcs->get_req_var("toggle_sso")) {
check_token();
$client = $ca->getClient();
$client->allowSso = (bool) $whmcs->get_req_var("allow_sso");
$client->save();
exit;
}
$smartyvalues["successful"] = $whmcs->get_req_var("successful") ? true : false;
$twofa = new WHMCS\TwoFactorAuthentication();
$twofa->setClientID($ca->getUserID());
if ($twofa->isActiveClients()) {
$twoFactorAuthEnabled = $twofa->isEnabled();
$ca->assign("twoFactorAuthAvailable", true);
$ca->assign("twoFactorAuthEnabled", $twoFactorAuthEnabled);
$ca->assign("twofaavailable", true);
$ca->assign("twofastatus", $twoFactorAuthEnabled);
}
if (App::getFromRequest("activate2fa")) {
add_hook("ClientAreaFooterOutput", 1, function () {
return "<script>\n jQuery(document).ready(function() {\n jQuery(\".twofa-config-link.enable\").attr(\"href\", \"" . routePathWithQuery("account-security-two-factor-enable", array(), array("enforce" => true)) . "\").click();\n });\n</script>";
});
}
$securityquestions = getSecurityQuestions("");
$smartyvalues["securityquestions"] = $securityquestions;
$smartyvalues["securityquestionsenabled"] = count($securityquestions) ? true : false;
$clientsdetails = getClientsDetails($legacyClient->getID());
if ($clientsdetails["securityqid"] == 0) {
$smartyvalues["nocurrent"] = true;
} else {
foreach ($securityquestions as $values) {
if ($values["id"] == $clientsdetails["securityqid"]) {
$smartyvalues["currentquestion"] = $values["question"];
}
}
}
if ($whmcs->get_req_var("submit")) {
check_token();
if ($clientsdetails["securityqid"] && $clientsdetails["securityqans"] != $currentsecurityqans) {
$errormessage .= "<li>" . Lang::trans("securitycurrentincorrect");
}
if (!$securityqans) {
$errormessage .= "<li>" . Lang::trans("securityanswerrequired");
}
if ($securityqans != $securityqans2) {
$errormessage .= "<li>" . Lang::trans("securitybothnotmatch");
}
if (!$errormessage) {
update_query("tblclients", array("securityqid" => $securityqid, "securityqans" => encrypt($securityqans)), array("id" => $legacyClient->getID()));
logActivity("Modified Security Question - User ID: " . $legacyClient->getID());
redir("action=changesq&successful=true");
}
}
$smartyvalues["errormessage"] = $errormessage;
$smartyvalues["showSsoSetting"] = 1 <= WHMCS\ApplicationLink\ApplicationLink::whereIsEnabled(1)->count();
$smartyvalues["isSsoEnabled"] = $ca->getClient()->allowSso;
} else {
$smartyvalues["twofaavailable"] = false;
$smartyvalues["twofaactivation"] = true;
$smartyvalues["securityquestionsenabled"] = false;
$smartyvalues["showSsoSetting"] = false;
}
$remoteAuthData = (new WHMCS\Authentication\Remote\Management\Client\ViewHelper())->getTemplateData(WHMCS\Authentication\Remote\Providers\AbstractRemoteAuthProvider::HTML_TARGET_CONNECT);
foreach ($remoteAuthData as $key => $value) {
$smartyvalues[$key] = $value;
}
$ca->addOutputHookFunction("ClientAreaPageSecurity");
} else {
if (in_array($action, array("hosting", "products", "services"))) {
checkContactPermission("products");
$ca->setDisplayTitle(Lang::trans("clientareaproducts"));
$ca->setTemplate("clientareaproducts");
$table = "tblhosting";
$fields = "COUNT(*)";
$where = "userid='" . db_escape_string($legacyClient->getID()) . "'";
if ($q) {
$q = preg_replace("/[^a-z0-9-.]/", "", strtolower($q));
$where .= " AND domain LIKE '%" . db_escape_string($q) . "%'";
$smartyvalues["q"] = $q;
}
if ($module = $whmcs->get_req_var("module")) {
$where .= " AND tblproducts.servertype='" . db_escape_string($module) . "'";
}
$innerjoin = "tblproducts ON tblproducts.id=tblhosting.packageid INNER JOIN tblproductgroups ON tblproductgroups.id=tblproducts.gid";
$result = select_query($table, $fields, $where, "", "", "", $innerjoin);
$data = mysql_fetch_array($result);
$numitems = $data[0];
list($orderby, $sort, $limit) = clientAreaTableInit("prod", "product", "ASC", $numitems);
$smartyvalues["orderby"] = $orderby;
$smartyvalues["sort"] = strtolower($sort);
if ($orderby == "price") {
$orderby = "amount";
} else {
if ($orderby == "billingcycle") {
$orderby = "billingcycle";
} else {
if ($orderby == "nextduedate") {
$orderby = "nextduedate";
} else {
if ($orderby == "status") {
$orderby = "domainstatus";
} else {
$orderby = "domain` " . $sort . ",`tblproducts`.`name";
}
}
}
}
$clientSslStatuses = WHMCS\Domain\Ssl\Status::where("user_id", $legacyClient->getID())->get();
$productCache = array();
$accounts = array();
$fields = "tblhosting.*,tblproductgroups.id AS group_id,tblproducts.name as product_name,tblproducts.tax," . "tblproductgroups.name as group_name,tblproducts.servertype,tblproducts.type";
$result = select_query($table, $fields, $where, $orderby, $sort, $limit, $innerjoin);
while ($data = mysql_fetch_array($result)) {
$id = $data["id"];
$productId = $data["packageid"];
$regdate = $data["regdate"];
$domain = $data["domain"];
$firstpaymentamount = $data["firstpaymentamount"];
$recurringamount = $data["amount"];
$nextduedate = $data["nextduedate"];
$billingcycle = $data["billingcycle"];
$status = $data["domainstatus"];
$tax = $data["tax"];
$server = $data["server"];
$username = $data["username"];
$module = $data["servertype"];
if (!isset($productCache["downloads"][$productId])) {
$productCache["downloads"][$productId] = WHMCS\Product\Product::find($productId)->getDownloadIds();
}
if (!isset($productCache["upgrades"][$productId])) {
$productCache["upgrades"][$productId] = WHMCS\Product\Product::find($productId)->getUpgradeProductIds();
}
if (!isset($productCache["groupNames"][$data["group_id"]])) {
$productCache["groupNames"][$data["group_id"]] = WHMCS\Product\Group::getGroupName($data["group_id"], $data["group_name"]);
}
if (!isset($productCache["productNames"][$data["packageid"]])) {
$productCache["productNames"][$data["packageid"]] = WHMCS\Product\Product::getProductName($data["packageid"], $data["product_name"]);
}
if (0 < $server && !isset($productCache["servers"][$server])) {
$productCache["servers"][$server] = get_query_vals("tblservers", "", array("id" => $server));
}
$downloads = $productCache["downloads"][$productId];
$upgradepackages = $productCache["upgrades"][$productId];
$productgroup = $productCache["groupNames"][$data["group_id"]];
$productname = $productCache["productNames"][$data["packageid"]];
$serverarray = 0 < $server ? $productCache["servers"][$server] : array();
$normalisedRegDate = $regdate;
$regdate = fromMySQLDate($regdate, 0, 1, "-");
$normalisedNextDueDate = $nextduedate;
$nextduedate = fromMySQLDate($nextduedate, 0, 1, "-");
$langbillingcycle = $ca->getRawStatus($billingcycle);
$rawstatus = $ca->getRawStatus($status);
$legacyClassTplVar = $status;
if (!in_array($legacyClassTplVar, array("Active", "Completed", "Pending", "Suspended"))) {
$legacyClassTplVar = "Terminated";
}
$amount = $billingcycle == "One Time" ? $firstpaymentamount : $recurringamount;
$isDomain = str_replace(".", "", $domain) != $domain;
if ($data["type"] == "other") {
$isDomain = false;
}
$isActive = in_array($status, array("Active", "Completed"));
$sslStatus = NULL;
if ($isDomain && $isActive) {
$sslStatus = $clientSslStatuses->where("domain_name", $domain)->first();
if (is_null($sslStatus)) {
$sslStatus = WHMCS\Domain\Ssl\Status::factory($legacyClient->getID(), $domain);
}
}
$accounts[] = array("id" => $id, "regdate" => $regdate, "normalisedRegDate" => $normalisedRegDate, "group" => $productgroup, "product" => $productname, "module" => $module, "server" => $serverarray, "domain" => $domain, "firstpaymentamount" => formatCurrency($firstpaymentamount), "recurringamount" => formatCurrency($recurringamount), "amountnum" => $amount, "amount" => formatCurrency($amount), "nextduedate" => $nextduedate, "normalisedNextDueDate" => $normalisedNextDueDate, "billingcycle" => Lang::trans("orderpaymentterm" . $langbillingcycle), "username" => $username, "status" => $status, "statusClass" => WHMCS\View\Helper::generateCssFriendlyClassName($status), "statustext" => Lang::trans("clientarea" . $rawstatus), "rawstatus" => $rawstatus, "class" => strtolower($legacyClassTplVar), "addons" => get_query_val("tblhostingaddons", "id", array("hostingid" => $id), "id", "DESC") ? true : false, "packagesupgrade" => 0 < count($upgradepackages), "downloads" => 0 < count($downloads), "showcancelbutton" => (bool) WHMCS\Config\Setting::getValue("ShowCancellationButton"), "sslStatus" => $sslStatus, "isActive" => $isActive);
}
$ca->assign("services", $accounts);
$smartyvalues = array_merge($smartyvalues, clientAreaTablePageNav($numitems));
$ca->addOutputHookFunction("ClientAreaPageProductsServices");
} else {
if ($action == "productdetails") {
checkContactPermission("products");
$ca->setDisplayTitle(Lang::trans("manageproduct"));
$ca->setTemplate("clientareaproductdetails");
$service = new WHMCS\Service($id, $legacyClient->getID());
if ($service->isNotValid()) {
redir("action=products", "clientarea.php");
}
$serviceModel = WHMCS\Service\Service::find($service->getID());
$ca->addToBreadCrumb("clientarea.php?action=products", $whmcs->get_lang("clientareaproducts"));
$ca->addToBreadCrumb("clientarea.php?action=productdetails#", $whmcs->get_lang("clientareaproductdetails"));
$customfields = $service->getCustomFields();
$domainIds = WHMCS\Domain\Domain::where("userid", $legacyClient->getID())->where("domain", $service->getData("domain"))->where("status", "Active")->pluck("id")->all();
if (count($domainIds) < 1) {
$domainIds = WHMCS\Domain\Domain::where("userid", $legacyClient->getID())->where("domain", $service->getData("domain"))->where("status", "!=", "Fraud")->pluck("id")->all();
}
if (count($domainIds) < 1) {
$domainIds = WHMCS\Domain\Domain::where("userid", $legacyClient->getID())->where("domain", $service->getData("domain"))->where("status", "Fraud")->pluck("id")->all();
}
if (count($domainIds) < 1) {
$domainId = "";
} else {
$domainId = array_shift($domainIds);
}
$ca->assign("id", $service->getData("id"));
$ca->assign("domainId", $domainId);
$ca->assign("serviceid", $service->getData("id"));
$ca->assign("pid", $service->getData("packageid"));
$ca->assign("producttype", $service->getData("type"));
$ca->assign("type", $service->getData("type"));
$ca->assign("regdate", fromMySQLDate($service->getData("regdate"), 0, 1, "-"));
$ca->assign("modulename", $service->getModule());
$ca->assign("module", $service->getModule());
$ca->assign("serverdata", $service->getServerInfo());
$ca->assign("domain", $service->getData("domain"));
$ca->assign("domainValid", str_replace(".", "", $service->getData("domain")) != $service->getData("domain"));
$ca->assign("groupname", $service->getData("groupname"));
$ca->assign("product", $service->getData("productname"));
$ca->assign("paymentmethod", $service->getPaymentMethod());
$ca->assign("firstpaymentamount", formatCurrency($service->getData("firstpaymentamount")));
$ca->assign("recurringamount", formatCurrency($service->getData("amount")));
$ca->assign("billingcycle", $service->getBillingCycleDisplay());
$ca->assign("nextduedate", fromMySQLDate($service->getData("nextduedate"), 0, 1, "-"));
$ca->assign("systemStatus", $service->getData("status"));
$ca->assign("status", $service->getStatusDisplay());
$ca->assign("rawstatus", strtolower($service->getData("status")));
$ca->assign("dedicatedip", $service->getData("dedicatedip"));
$ca->assign("assignedips", $service->getData("assignedips"));
$ca->assign("ns1", $service->getData("ns1"));
$ca->assign("ns2", $service->getData("ns2"));
$ca->assign("packagesupgrade", $service->getAllowProductUpgrades());
$ca->assign("configoptionsupgrade", $service->getAllowConfigOptionsUpgrade());
$ca->assign("customfields", $customfields);
$ca->assign("productcustomfields", $customfields);
$ca->assign("suspendreason", $service->getSuspensionReason());
$ca->assign("subscriptionid", $service->getData("subscriptionid"));
$isDomain = str_replace(".", "", $service->getData("domain")) != $service->getData("domain");
if ($service->getData("type") == "other") {
$isDomain = false;
}
$sslStatus = NULL;
if ($isDomain) {
$sslStatus = WHMCS\Domain\Ssl\Status::factory($legacyClient->getID(), $service->getData("domain"))->syncAndSave();
}
$ca->assign("sslStatus", $sslStatus);
$diskstats = $service->getDiskUsageStats();
foreach ($diskstats as $k => $v) {
$ca->assign($k, $v);
}
$availableAddonIds = array();
$availableAddonProducts = array();
if ($service->getData("status") == "Active") {
$predefinedAddonProducts = $service->getPredefinedAddonsOnce();
$availableAddonIds = $service->hasProductGotAddons();
foreach ($availableAddonIds as $addonId) {
$availableAddonProducts[$addonId] = $predefinedAddonProducts[$addonId];
}
}
$ca->assign("showcancelbutton", $service->getAllowCancellation());
$ca->assign("configurableoptions", $service->getConfigurableOptions());
$ca->assign("addons", $service->getAddons());
$ca->assign("addonsavailable", $availableAddonIds);
$ca->assign("availableAddonProducts", $availableAddonProducts);
$ca->assign("downloads", $service->getAssociatedDownloads());
$ca->assign("pendingcancellation", $service->hasCancellationRequest());
$ca->assign("username", $service->getData("username"));
$ca->assign("password", $service->getData("password"));
$hookResponses = run_hook("ClientAreaProductDetailsOutput", array("service" => $serviceModel));
$ca->assign("hookOutput", $hookResponses);
$hookResponses = run_hook("ClientAreaProductDetailsPreModuleTemplate", $ca->getTemplateVariables());
foreach ($hookResponses as $hookTemplateVariables) {
foreach ($hookTemplateVariables as $k => $v) {
$ca->assign($k, $v);
}
}
$tplOverviewTabOutput = "";
$moduleClientAreaOutput = "";
$clientAreaCustomButtons = array();
$ca->assign("modulecustombuttonresult", "");
if (App::isInRequest("addonId") && 0 < (int) App::getFromRequest("addonId") && App::getFromRequest("modop") == "custom") {
$service = new WHMCS\Addon();
$service->setAddonId(App::getFromRequest("addonId"));
}
if ($service->getModule()) {
$moduleInterface = new WHMCS\Module\Server();
if ($service instanceof WHMCS\Addon) {
$moduleInterface->loadByAddonId($service->getID());
} else {
$moduleInterface->loadByServiceID($service->getID());
}
if ($whmcs->get_req_var("dosinglesignon") && checkContactPermission("productsso", true)) {
if ($service->getData("status") == "Active") {
try {
$redirectUrl = $moduleInterface->getSingleSignOnUrlForService();
header("Location: " . $redirectUrl);
exit;
} catch (WHMCS\Exception\Module\SingleSignOnError $e) {
$ca->assign("modulecustombuttonresult", $whmcs->get_lang("ssounabletologin"));
} catch (Exception $e) {