| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- /* * ********************************************************************
- * Existing Domains by WHMCS Services
- * Copyright WHMCS Services, All Rights Reserved
- *
- * Created By WHMCSServices http://www.whmcsservices.com
- * Contact: dev@whmcsservices.com
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- * ******************************************************************** */
- use Illuminate\Database\Capsule\Manager as Capsule;
- if (!defined("WHMCS"))
- die("This file cannot be accessed directly");
- add_hook('ClientAreaPageCart', 145144, function($vars) {
- global $CONFIG;
- $clang = $CONFIG['Language'];
- if (isset($_SESSION['uid'])) {
- $litem = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->where('language', '<>', '')->value('language');
- if ($litem) {
- $clang = $litem;
- }
- }
- if (isset($_SESSION['Language'])) {
- $clang = $_SESSION['Language'];
- }
- if (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php");
- } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php");
- } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php");
- }
- if ($vars['productinfo']['pid'] && $_SESSION['uid']) {
- $EDMODULE = array();
- $results = Capsule::table('tbladdonmodules')->where('module', 'ExistingDomains')->get();
- foreach ($results as $data) {
- $setting = $data->setting;
- $value = $data->value;
- $EDMODULE[$setting] = $value;
- }
- if ($EDMODULE['doption'] != '') {
- $edresult = Capsule::table('tbldomains')->where('userid', $_SESSION['uid'])->where('status', 'Active')->get();
- }
- foreach ($edresult as $eddata) {
- $returns['existingdomains'][] = $eddata->domain;
- }
- $returns['EDLANG'] = $_ADDONLANG;
- $returns['WSEXISTING'] = $EDMODULE;
- return $returns;
- }
- });
- add_hook("ClientAreaFooterOutput", 1, function($vars) {
- global $CONFIG;
- if ("flowcart7" == $CONFIG['OrderFormTemplate']) {
- return '';
- }
- if ("lagom" == $CONFIG['OrderFormTemplate']) {
- return '';
- }
- if (!isset($_SESSION['uid'])) {
- return '';
- }
- $wscurrentfile = App::getCurrentFilename();
- if ($wscurrentfile != 'cart') {
- return '';
- }
- $clang = $CONFIG['Language'];
- $litem = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->where('language', '<>', '')->value('language');
- if ($litem) {
- $clang = $litem;
- }
- if (isset($_SESSION['Language'])) {
- $clang = $_SESSION['Language'];
- }
- if (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $clang . ".php");
- } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/" . $CONFIG['Language'] . ".php");
- } elseif (file_exists(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php")) {
- include(ROOTDIR . "/modules/addons/ExistingDomains/lang/english.php");
- }
- return <<<EOL
- <script type="text/javascript">
- jQuery('#frmProductDomain').submit(function (e) {
- e.preventDefault();
- $(".errordomainnamepws").remove();
- var btnSearchObj = jQuery(this).find('button[type="submit"]'),
- domainSearchResults = jQuery("#DomainSearchResults"),
- spotlightTlds = jQuery('#spotlightTlds'),
- suggestions = jQuery('#domainSuggestions'),
- btnDomainContinue = jQuery('#btnDomainContinue'),
- domainoption = jQuery(".domain-selection-options input:checked").val(),
- sldInput = jQuery("#" + domainoption + "sld"),
- sld = sldInput.val(),
- tld = '',
- pid = jQuery('#frmProductDomainPid').val(),
- tldInput = '';
- if (domainoption == 'existing_domain') {
- sldInput = jQuery("#existing_domainsld option:selected");
- sld = sldInput.text();
- var splitDomain = sld.split('.');
- sld = splitDomain[0];
- splitDomain.splice(0, 1);
- tld = '.' + splitDomain.join(".");
- jQuery('.domain-lookup-other-loader').show();
- jQuery('.domain-lookup-loader').show();
- btnDomainContinue.addClass('hidden').attr('disabled', 'disabled');
- var otherDomain = jQuery.post(
- 'cart.php',
- {
- token: csrfToken,
- a: 'checkDomain',
- type: "owndomain",//domainoption,
- pid: pid,
- wscheck: 1,
- domain: sld + tld
- },
- 'json'
- );
- otherDomain.done(function(data) {
- if (typeof data != 'object' || data.result.length == 0) {
- jQuery('.domain-lookup-subdomain-loader').hide();
- return;
- }
- if(typeof data.result.wsres !== 'undefined' && data.result.wsres.length > 0){
- $(".errordomainnamepws").remove();
- $('#frmProductDomainSelections').prepend('<div class="errordomainnamepws alert alert-danger"><strong>'+data.result.wsdomain+'</strong> {$_ADDONLANG['errordomain']}</div>');
- }
- jQuery.each(data.result, function(index, result) {
- if (result.status === true) {
- window.location = 'cart.php?a=confproduct&i=' + result.num;
- } else {
- jQuery('.domain-lookup-primary-loader').hide();
- jQuery('#primaryLookupResult').removeClass('hidden').show().find('.domain-invalid').show();
- }
- });
- }).always(function(){
- hasProductDomainLookupEnded(1, btnSearchObj);
- });
- }else if(domainoption == 'subexisting_domain'){
- if($("#subdomainexisting_domaindomains").val() === ''){
- $('#subdomainexisting_domaindomains').tooltip('show');
- return 0;
- }
- jQuery('.domain-lookup-other-loader').show();
- jQuery('.domain-lookup-loader').show();
- btnDomainContinue.addClass('hidden').attr('disabled', 'disabled');
- var ddsubdomain = $("#subexisting_domaindomainid").val();
- var otherDomain = jQuery.post(
- 'cart.php',
- {
- token: csrfToken,
- a: 'checkDomain',
- type: "owndomain",//domainoption,
- pid: pid,
- wscheck: 1,
- issubdomain: 1,
- domain: ddsubdomain
- },
- 'json'
- );
- otherDomain.done(function(data) {
- if (typeof data != 'object' || data.result.length == 0) {
- jQuery('.domain-lookup-subdomain-loader').hide();
- return;
- }
- if(typeof data.result.wsres !== 'undefined' && data.result.wsres.length > 0){
- $(".errordomainnamepws").remove();
- $('#frmProductDomainSelections').prepend('<div class="errordomainnamepws alert alert-danger"><strong>'+data.result.wsdomain+'</strong> {$_ADDONLANG['errordomain']}.</div>');
- }
- jQuery.each(data.result, function(index, result) {
- if (result.status === true) {
- window.location = 'cart.php?a=confproduct&i=' + result.num;
- } else {
- jQuery('.domain-lookup-primary-loader').hide();
- jQuery('#primaryLookupResult').removeClass('hidden').show().find('.domain-invalid').show();
- }
- });
- }).always(function(){
- hasProductDomainLookupEnded(1, btnSearchObj);
- });
- }
- btnDomainContinue.removeClass('hidden');
- });
- </script>
- EOL;
- });
- $wscurrentfile = App::getCurrentFilename();
- function ExistingDomains_checkdomainvalid()
- {
- $EDMODULE = array();
- $results = Capsule::table('tbladdonmodules')->where('module', 'ExistingDomains')->get();
- foreach ($results as $data) {
- $setting = $data->setting;
- $value = $data->value;
- $EDMODULE[$setting] = $value;
- }
- $wcddomain = (string) strip_tags(trim($_REQUEST['domain']));
- if ($EDMODULE['doption'] != 'Allow Duplicate') {
- $wsdvccheck = false;
- $wcduseri = (int) $_SESSION['uid'];
- $wcdpid = (int) $_REQUEST['pid'];
- if ($EDMODULE['doption'] == 'Same product domain') {
- $wcditem = Capsule::table('tblhosting')->where('userid', $wcduseri)->where('packageid', $wcdpid)->where('domain', $wcddomain)->where('domainstatus', 'Active')->count();
- if ($wcditem) {
- $wsdvccheck = TRUE;
- }
- }
- if ($EDMODULE['doption'] == 'All product domain') {
- $wcditem = Capsule::table('tblhosting')->where('userid', $wcduseri)->where('domain', $wcddomain)->where('domainstatus', 'Active')->count();
- if ($wcditem) {
- $wsdvccheck = TRUE;
- }
- }
- if ($wsdvccheck) {
- $result = array(
- 'status' => FALSE,
- 'result' => '',
- 'wsres' => 'notallowed',
- 'wsdomain' => $wcddomain,
- );
- $response = new \WHMCS\Http\JsonResponse(array("result" => $result), 200, array("Content-Type" => "application/json"));
- $response->send();
- \WHMCS\Terminus::getInstance()->doExit();
- }
- if (isset($_REQUEST['issubdomain']) && $_REQUEST['issubdomain'] != '') {
- $resss = wscheckIncart($wcddomain);
- $response = new \WHMCS\Http\JsonResponse(array("result" => array("result" => $resss)), 200, array("Content-Type" => "application/json"));
- $response->send();
- \WHMCS\Terminus::getInstance()->doExit();
- }
- }
- }
- function wscartPreventDuplicateProduct($domain)
- {
- if ($domain) {
- $domains = array();
- foreach ($_SESSION["cart"]["products"] as $k => $values) {
- $domains[$k] = $values["domain"];
- }
- if (in_array($domain, $domains)) {
- $i = array_search($domain, $domains);
- if ($i !== false) {
- unset($_SESSION["cart"]["products"][$i]);
- $_SESSION["cart"]["products"] = array_values($_SESSION["cart"]["products"]);
- }
- }
- }
- }
- function wscheckIncart($domain)
- {
- $orderForm = new \WHMCS\OrderForm();
- $productId = (int) $_REQUEST["pid"];
- $productInfo = $orderForm->setPid($productId);
- $passedVariables = $_SESSION["cart"]["passedvariables"];
- unset($_SESSION["cart"]["passedvariables"]);
- wscartPreventDuplicateProduct($domain);
- $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"]);
- if (isset($passedVariables["bnum"])) {
- $productArray["bnum"] = $passedVariables["bnum"];
- }
- if (isset($passedVariables["bitem"])) {
- $productArray["bitem"] = $passedVariables["bitem"];
- }
- $_SESSION["cart"]["newproduct"] = true;
- $updatedExistingQuantity = false;
- if ($productInfo["allowqty"]) {
- foreach ($_SESSION["cart"]["products"] as &$cart_prod) {
- if ($productId == $cart_prod["pid"]) {
- if (empty($cart_prod["qty"])) {
- $cart_prod["qty"] = 1;
- }
- $cart_prod["qty"] ++;
- if ($productInfo["stockcontrol"] && $productInfo["qty"] < $cart_prod["qty"]) {
- $cart_prod["qty"] = $productInfo["qty"];
- }
- $updatedExistingQuantity = true;
- break;
- }
- }
- }
- if (!$updatedExistingQuantity) {
- $_SESSION["cart"]["products"][] = $productArray;
- }
- $newProductIValue = count($_SESSION["cart"]["products"]) - 1;
- if (isset($passedVariables["skipconfig"]) && $passedVariables["skipconfig"]) {
- unset($_SESSION["cart"]["products"][$newProductIValue]["noconfig"]);
- $_SESSION["cart"]["lastconfigured"] = array("type" => "product", "i" => $newProductIValue);
- }
- $searchResult = array("status" => true, "num" => $newProductIValue);
- return $searchResult;
- }
- if ($wscurrentfile == 'cart' && isset($_SESSION['uid']) && isset($_REQUEST['a']) && $_REQUEST['a'] == "checkDomain" && isset($_REQUEST['wscheck'])) {
- ExistingDomains_checkdomainvalid();
- }
|