if( $a == 'confproduct' )
{
$templatefile = 'configureproduct';
if( is_null($productInfoKey) || !isset($_SESSION['cart']['products'][$productInfoKey]) || !is_array($_SESSION['cart']['products'][$productInfoKey]) )
{
if( $ajax )
{
exit( $_LANG['invoiceserror'] );
}
redir();
}
$newproduct = $_SESSION['cart']['newproduct'];
unset($_SESSION['cart']['newproduct']);
$pid = $_SESSION['cart']['products'][$productInfoKey]['pid'];
$productinfo = $orderfrm->setPid($pid);
if( !$productinfo )
{
redir();
}
$_SESSION['cart']['cartsummarypid'] = $productinfo['pid'];
$pid = $productinfo['pid'];
if( $configure )
{
global $errormessage;
$errormessage = '';
$result = select_query('tblproducts', 'type', array( 'id' => $pid ));
$data = mysql_fetch_array($result);
$producttype = $data['type'];
if( $producttype == 'server' )
{
$hostname = $whmcs->get_req_var('hostname');
$ns1prefix = $whmcs->get_req_var('ns1prefix');
$ns2prefix = $whmcs->get_req_var('ns2prefix');
$rootpw = $whmcs->get_req_var('rootpw');
if( !$hostname )
{
$errormessage .= "<li>" . $_LANG['ordererrorservernohostname'];
}
else
{
$result = select_query('tblhosting', "COUNT(id)", array( 'domain' => $hostname . "." . $_SESSION['cart']['products'][$productInfoKey]['domain'], 'domainstatus' => array( 'sqltype' => 'NEQ', 'value' => 'Cancelled' ), 'domainstatus' => array( 'sqltype' => 'NEQ', 'value' => 'Terminated' ), 'domainstatus' => array( 'sqltype' => 'NEQ', 'value' => 'Fraud' ) ));
$data = mysql_fetch_array($result);
$existingcount = $data[0];
if( $existingcount )
{
$errormessage .= "<li>" . $_LANG['ordererrorserverhostnameinuse'];
}
}
if( !$ns1prefix || !$ns2prefix )
{
$errormessage .= "<li>" . $_LANG['ordererrorservernonameservers'];
}
if( !$rootpw )
{
$errormessage .= "<li>" . $_LANG['ordererrorservernorootpw'];
}
$serverarray = array( 'hostname' => $hostname, 'ns1prefix' => $ns1prefix, 'ns2prefix' => $ns2prefix, 'rootpw' => $rootpw );
}
$configoption = $whmcs->get_req_var('configoption');
if( $configoption )
{
$configOpsReturn = validateAndSanitizeQuantityConfigOptions($configoption);
$configoptionsarray = $configOpsReturn['validOptions'];
$errormessage .= $configOpsReturn['errorMessage'];
}
$addonsarray = is_array($addons) ? array_keys($addons) : '';
$errormessage .= bundlesValidateProductConfig($productInfoKey, $billingcycle, $configoptionsarray, $addonsarray);
$_SESSION['cart']['products'][$productInfoKey]['billingcycle'] = $billingcycle;
$_SESSION['cart']['products'][$productInfoKey]['server'] = $serverarray;
$_SESSION['cart']['products'][$productInfoKey]['configoptions'] = $configoptionsarray;
$_SESSION['cart']['products'][$productInfoKey]['customfields'] = $customfield;
$_SESSION['cart']['products'][$productInfoKey]['addons'] = $addonsarray;
if( $calctotal )
{
$productinfo = $orderfrm->setPid($_SESSION['cart']['products'][$productInfoKey]['pid']);
$ordersummarytemp = '/templates/orderforms/' . $orderfrm->getTemplate() . "/ordersummary.tpl";
if( file_exists(ROOTDIR . $ordersummarytemp) )
{
$carttotals = calcCartTotals(false, true);
$templatevars = array( 'producttotals' => $carttotals['products'][$productInfoKey], 'carttotals' => $carttotals );
echo processSingleTemplate($ordersummarytemp, $templatevars);
}
exit();
}
if( !$ajax && !$nocyclerefresh && $previousbillingcycle != $billingcycle )
{
redir("a=confproduct&i=" . $productInfoKey);
}
$validate = new WHMCS_Validate();
$validate->validateCustomFields('product', $pid, true);
run_validate_hook($validate, 'ShoppingCartValidateProductUpdate', $_REQUEST);
if( $validate->hasErrors() )
{
$errormessage .= $validate->getHTMLErrorOutput();
}
if( $errormessage )
{
if( $ajax )
{
exit( $errormessage );
}
$smartyvalues['errormessage'] = $errormessage;
}
else
{
unset($_SESSION['cart']['products'][$productInfoKey]['noconfig']);
$_SESSION['cart']['lastconfigured'] = array( 'type' => 'product', 'i' => $productInfoKey );
if( $ajax )
{
exit();
}
redir("a=confdomains");
}
}
$billingcycle = $_SESSION['cart']['products'][$productInfoKey]['billingcycle'];
$server = $_SESSION['cart']['products'][$productInfoKey]['server'];
$customfields = $_SESSION['cart']['products'][$productInfoKey]['customfields'];
$configoptions = $_SESSION['cart']['products'][$productInfoKey]['configoptions'];
$addons = $_SESSION['cart']['products'][$productInfoKey]['addons'];
$domain = $_SESSION['cart']['products'][$productInfoKey]['domain'];
$noconfig = $_SESSION['cart']['products'][$productInfoKey]['noconfig'];
$billingcycle = $orderfrm->validateBillingCycle($billingcycle);
$pricing = getPricingInfo($pid);
$configurableoptions = getCartConfigOptions($pid, $configoptions, $billingcycle, '', true);
$customfields = getCustomFields('product', $pid, '', '', 'on', $customfields);
$addonsarray = getAddons($pid, $addons);
$recurringcycles = 0;
if( $pricing['type'] == 'recurring' )
{
if( 0 <= $pricing['rawpricing']['monthly'] )
{
$recurringcycles++;
}
if( 0 <= $pricing['rawpricing']['quarterly'] )
{
$recurringcycles++;
}
if( 0 <= $pricing['rawpricing']['semiannually'] )
{
$recurringcycles++;
}
if( 0 <= $pricing['rawpricing']['annually'] )
{
$recurringcycles++;
}
if( 0 <= $pricing['rawpricing']['biennially'] )
{
$recurringcycles++;
}
}
if( $newproduct && $productinfo['type'] != 'server' && ($pricing['type'] != 'recurring' || $recurringcycles <= 1) && !count($configurableoptions) && !count($customfields) && !count($addonsarray) )
{
unset($_SESSION['cart']['products'][$productInfoKey]['noconfig']);
$_SESSION['cart']['lastconfigured'] = array( 'type' => 'product', 'i' => $productInfoKey );
if( $ajax )
{
exit();
}
redir("a=confdomains");
}
$serverarray = array( 'hostname' => isset($server['hostname']) ? $server['hostname'] : '', 'ns1prefix' => isset($server['ns1prefix']) ? $server['ns1prefix'] : '', 'ns2prefix' => isset($server['ns2prefix']) ? $server['ns2prefix'] : '', 'rootpw' => isset($server['rootpw']) ? $server['rootpw'] : '' );
$smartyvalues['editconfig'] = true;
$smartyvalues['firstconfig'] = $noconfig ? true : false;
$smartyvalues['i'] = $productInfoKey;
$smartyvalues['productinfo'] = $productinfo;
$smartyvalues['pricing'] = $pricing;
$smartyvalues['billingcycle'] = $billingcycle;
$smartyvalues['server'] = $serverarray;
$smartyvalues['configurableoptions'] = $configurableoptions;
$smartyvalues['addons'] = $addonsarray;
$smartyvalues['customfields'] = $customfields;
$smartyvalues['domain'] = $domain;
}