hooks.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /* * ********************************************************************
  3. * Existing Domains by WHMCS Services
  4. * Copyright WHMCS Services, All Rights Reserved
  5. *
  6. * Created By WHMCSServices http://www.whmcsservices.com
  7. * Contact: dev@whmcsservices.com
  8. *
  9. * This software is furnished under a license and may be used and copied
  10. * only in accordance with the terms of such license and with the
  11. * inclusion of the above copyright notice. This software or any other
  12. * copies thereof may not be provided or otherwise made available to any
  13. * other person. No title to and ownership of the software is hereby
  14. * transferred.
  15. * ******************************************************************** */
  16. use Illuminate\Database\Capsule\Manager as Capsule;
  17. if (!defined("WHMCS"))
  18. die("This file cannot be accessed directly");
  19. add_hook('ClientAreaPageCart', 145144, function($vars) {
  20. global $CONFIG;
  21. $clang = $CONFIG['Language'];
  22. if (isset($_SESSION['uid'])) {
  23. $litem = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->where('language', '<>', '')->value('language');
  24. if ($litem) {
  25. $clang = $litem;
  26. }
  27. }
  28. if (isset($_SESSION['Language'])) {
  29. $clang = $_SESSION['Language'];
  30. }
  31. if (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php")) {
  32. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php");
  33. } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php")) {
  34. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php");
  35. } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php")) {
  36. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php");
  37. }
  38. if ($vars['productinfo']['pid'] && $_SESSION['uid']) {
  39. $EDMODULE = array();
  40. $results = Capsule::table('tbladdonmodules')->where('module', 'ExistingDomains')->get();
  41. foreach ($results as $data) {
  42. $setting = $data->setting;
  43. $value = $data->value;
  44. $EDMODULE[$setting] = $value;
  45. }
  46. if ($EDMODULE['doption'] != '') {
  47. $edresult = Capsule::table('tbldomains')->where('userid', $_SESSION['uid'])->where('status', 'Active')->get();
  48. }
  49. foreach ($edresult as $eddata) {
  50. $returns['existingdomains'][] = $eddata->domain;
  51. }
  52. $returns['EDLANG'] = $_ADDONLANG;
  53. $returns['WSEXISTING'] = $EDMODULE;
  54. return $returns;
  55. }
  56. });
  57. add_hook("ClientAreaFooterOutput", 1, function($vars) {
  58. global $CONFIG;
  59. if ("flowcart7" == $CONFIG['OrderFormTemplate']) {
  60. return '';
  61. }
  62. if ("lagom" == $CONFIG['OrderFormTemplate']) {
  63. return '';
  64. }
  65. if (!isset($_SESSION['uid'])) {
  66. return '';
  67. }
  68. $wscurrentfile = App::getCurrentFilename();
  69. if ($wscurrentfile != 'cart') {
  70. return '';
  71. }
  72. $clang = $CONFIG['Language'];
  73. $litem = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->where('language', '<>', '')->value('language');
  74. if ($litem) {
  75. $clang = $litem;
  76. }
  77. if (isset($_SESSION['Language'])) {
  78. $clang = $_SESSION['Language'];
  79. }
  80. if (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php")) {
  81. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php");
  82. } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php")) {
  83. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php");
  84. } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php")) {
  85. include(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php");
  86. }
  87. return <<<EOL
  88. <script type="text/javascript">
  89. jQuery('#frmProductDomain').submit(function (e) {
  90. e.preventDefault();
  91. $(".errordomainnamepws").remove();
  92. var btnSearchObj = jQuery(this).find('button[type="submit"]'),
  93. domainSearchResults = jQuery("#DomainSearchResults"),
  94. spotlightTlds = jQuery('#spotlightTlds'),
  95. suggestions = jQuery('#domainSuggestions'),
  96. btnDomainContinue = jQuery('#btnDomainContinue'),
  97. domainoption = jQuery(".domain-selection-options input:checked").val(),
  98. sldInput = jQuery("#" + domainoption + "sld"),
  99. sld = sldInput.val(),
  100. tld = '',
  101. pid = jQuery('#frmProductDomainPid').val(),
  102. tldInput = '';
  103. if (domainoption == 'existing_domain') {
  104. sldInput = jQuery("#existing_domainsld option:selected");
  105. sld = sldInput.text();
  106. var splitDomain = sld.split('.');
  107. sld = splitDomain[0];
  108. splitDomain.splice(0, 1);
  109. tld = '.' + splitDomain.join(".");
  110. jQuery('.domain-lookup-other-loader').show();
  111. jQuery('.domain-lookup-loader').show();
  112. btnDomainContinue.addClass('hidden').attr('disabled', 'disabled');
  113. var otherDomain = jQuery.post(
  114. 'cart.php',
  115. {
  116. token: csrfToken,
  117. a: 'checkDomain',
  118. type: "owndomain",//domainoption,
  119. pid: pid,
  120. wscheck: 1,
  121. domain: sld + tld
  122. },
  123. 'json'
  124. );
  125. otherDomain.done(function(data) {
  126. if (typeof data != 'object' || data.result.length == 0) {
  127. jQuery('.domain-lookup-subdomain-loader').hide();
  128. return;
  129. }
  130. if(typeof data.result.wsres !== 'undefined' && data.result.wsres.length > 0){
  131. $(".errordomainnamepws").remove();
  132. $('#frmProductDomainSelections').prepend('<div class="errordomainnamepws alert alert-danger"><strong>'+data.result.wsdomain+'</strong> {$_ADDONLANG['errordomain']}</div>');
  133. }
  134. jQuery.each(data.result, function(index, result) {
  135. if (result.status === true) {
  136. window.location = 'cart.php?a=confproduct&i=' + result.num;
  137. } else {
  138. jQuery('.domain-lookup-primary-loader').hide();
  139. jQuery('#primaryLookupResult').removeClass('hidden').show().find('.domain-invalid').show();
  140. }
  141. });
  142. }).always(function(){
  143. hasProductDomainLookupEnded(1, btnSearchObj);
  144. });
  145. }else if(domainoption == 'subexisting_domain'){
  146. if($("#subdomainexisting_domaindomains").val() === ''){
  147. $('#subdomainexisting_domaindomains').tooltip('show');
  148. return 0;
  149. }
  150. jQuery('.domain-lookup-other-loader').show();
  151. jQuery('.domain-lookup-loader').show();
  152. btnDomainContinue.addClass('hidden').attr('disabled', 'disabled');
  153. var ddsubdomain = $("#subexisting_domaindomainid").val();
  154. var otherDomain = jQuery.post(
  155. 'cart.php',
  156. {
  157. token: csrfToken,
  158. a: 'checkDomain',
  159. type: "owndomain",//domainoption,
  160. pid: pid,
  161. wscheck: 1,
  162. issubdomain: 1,
  163. domain: ddsubdomain
  164. },
  165. 'json'
  166. );
  167. otherDomain.done(function(data) {
  168. if (typeof data != 'object' || data.result.length == 0) {
  169. jQuery('.domain-lookup-subdomain-loader').hide();
  170. return;
  171. }
  172. if(typeof data.result.wsres !== 'undefined' && data.result.wsres.length > 0){
  173. $(".errordomainnamepws").remove();
  174. $('#frmProductDomainSelections').prepend('<div class="errordomainnamepws alert alert-danger"><strong>'+data.result.wsdomain+'</strong> {$_ADDONLANG['errordomain']}.</div>');
  175. }
  176. jQuery.each(data.result, function(index, result) {
  177. if (result.status === true) {
  178. window.location = 'cart.php?a=confproduct&i=' + result.num;
  179. } else {
  180. jQuery('.domain-lookup-primary-loader').hide();
  181. jQuery('#primaryLookupResult').removeClass('hidden').show().find('.domain-invalid').show();
  182. }
  183. });
  184. }).always(function(){
  185. hasProductDomainLookupEnded(1, btnSearchObj);
  186. });
  187. }
  188. btnDomainContinue.removeClass('hidden');
  189. });
  190. </script>
  191. EOL;
  192. });
  193. $wscurrentfile = App::getCurrentFilename();
  194. function ExistingDomains_checkdomainvalid()
  195. {
  196. $EDMODULE = array();
  197. $results = Capsule::table('tbladdonmodules')->where('module', 'ExistingDomains')->get();
  198. foreach ($results as $data) {
  199. $setting = $data->setting;
  200. $value = $data->value;
  201. $EDMODULE[$setting] = $value;
  202. }
  203. $wcddomain = (string) strip_tags(trim($_REQUEST['domain']));
  204. if ($EDMODULE['doption'] != 'Allow Duplicate') {
  205. $wsdvccheck = false;
  206. $wcduseri = (int) $_SESSION['uid'];
  207. $wcdpid = (int) $_REQUEST['pid'];
  208. if ($EDMODULE['doption'] == 'Same product domain') {
  209. $wcditem = Capsule::table('tblhosting')->where('userid', $wcduseri)->where('packageid', $wcdpid)->where('domain', $wcddomain)->where('domainstatus', 'Active')->count();
  210. if ($wcditem) {
  211. $wsdvccheck = TRUE;
  212. }
  213. }
  214. if ($EDMODULE['doption'] == 'All product domain') {
  215. $wcditem = Capsule::table('tblhosting')->where('userid', $wcduseri)->where('domain', $wcddomain)->where('domainstatus', 'Active')->count();
  216. if ($wcditem) {
  217. $wsdvccheck = TRUE;
  218. }
  219. }
  220. if ($wsdvccheck) {
  221. $result = array(
  222. 'status' => FALSE,
  223. 'result' => '',
  224. 'wsres' => 'notallowed',
  225. 'wsdomain' => $wcddomain,
  226. );
  227. $response = new \WHMCS\Http\JsonResponse(array("result" => $result), 200, array("Content-Type" => "application/json"));
  228. $response->send();
  229. \WHMCS\Terminus::getInstance()->doExit();
  230. }
  231. if (isset($_REQUEST['issubdomain']) && $_REQUEST['issubdomain'] != '') {
  232. $resss = wscheckIncart($wcddomain);
  233. $response = new \WHMCS\Http\JsonResponse(array("result" => array("result" => $resss)), 200, array("Content-Type" => "application/json"));
  234. $response->send();
  235. \WHMCS\Terminus::getInstance()->doExit();
  236. }
  237. }
  238. }
  239. function wscartPreventDuplicateProduct($domain)
  240. {
  241. if ($domain) {
  242. $domains = array();
  243. foreach ($_SESSION["cart"]["products"] as $k => $values) {
  244. $domains[$k] = $values["domain"];
  245. }
  246. if (in_array($domain, $domains)) {
  247. $i = array_search($domain, $domains);
  248. if ($i !== false) {
  249. unset($_SESSION["cart"]["products"][$i]);
  250. $_SESSION["cart"]["products"] = array_values($_SESSION["cart"]["products"]);
  251. }
  252. }
  253. }
  254. }
  255. function wscheckIncart($domain)
  256. {
  257. $orderForm = new \WHMCS\OrderForm();
  258. $productId = (int) $_REQUEST["pid"];
  259. $productInfo = $orderForm->setPid($productId);
  260. $passedVariables = $_SESSION["cart"]["passedvariables"];
  261. unset($_SESSION["cart"]["passedvariables"]);
  262. wscartPreventDuplicateProduct($domain);
  263. $productArray = array("pid" => $productId, "domain" => $domain, "billingcycle" => $passedVariables["billingcycle"] ?: $orderForm->validateBillingCycle(""), "configoptions" => $passedVariables["configoption"], "customfields" => $passedVariables["customfield"], "addons" => $passedVariables["addons"], "server" => "", "noconfig" => true, "skipConfig" => isset($passedVariables["skipconfig"]) && $passedVariables["skipconfig"]);
  264. if (isset($passedVariables["bnum"])) {
  265. $productArray["bnum"] = $passedVariables["bnum"];
  266. }
  267. if (isset($passedVariables["bitem"])) {
  268. $productArray["bitem"] = $passedVariables["bitem"];
  269. }
  270. $_SESSION["cart"]["newproduct"] = true;
  271. $updatedExistingQuantity = false;
  272. if ($productInfo["allowqty"]) {
  273. foreach ($_SESSION["cart"]["products"] as &$cart_prod) {
  274. if ($productId == $cart_prod["pid"]) {
  275. if (empty($cart_prod["qty"])) {
  276. $cart_prod["qty"] = 1;
  277. }
  278. $cart_prod["qty"] ++;
  279. if ($productInfo["stockcontrol"] && $productInfo["qty"] < $cart_prod["qty"]) {
  280. $cart_prod["qty"] = $productInfo["qty"];
  281. }
  282. $updatedExistingQuantity = true;
  283. break;
  284. }
  285. }
  286. }
  287. if (!$updatedExistingQuantity) {
  288. $_SESSION["cart"]["products"][] = $productArray;
  289. }
  290. $newProductIValue = count($_SESSION["cart"]["products"]) - 1;
  291. if (isset($passedVariables["skipconfig"]) && $passedVariables["skipconfig"]) {
  292. unset($_SESSION["cart"]["products"][$newProductIValue]["noconfig"]);
  293. $_SESSION["cart"]["lastconfigured"] = array("type" => "product", "i" => $newProductIValue);
  294. }
  295. $searchResult = array("status" => true, "num" => $newProductIValue);
  296. return $searchResult;
  297. }
  298. if ($wscurrentfile == 'cart' && isset($_SESSION['uid']) && isset($_REQUEST['a']) && $_REQUEST['a'] == "checkDomain" && isset($_REQUEST['wscheck'])) {
  299. ExistingDomains_checkdomainvalid();
  300. }