function resellerclubwebservices_ClientArea($params)
{
    if (isset($_POST['cplogin']) && strlen(trim($_POST['cplogin'])) > 0) {
        $cplogin_action = strtolower(trim($_POST['cplogin']));
        switch ($cplogin_action) {
            case 'webhost':
                _redirect_to_webhosting_control_panel($params);
                break;
            case 'mailhost':
                _redirect_to_mailhosting_control_panel($params);
                break;
            case 'dns':
                _redirect_to_dns_control_panel($params);
                break;
            case 'webmail':
                _redirect_to_webmail_control_panel($params);
                break;
            case 'websitebuilder':
                _redirect_to_websitebuilder_control_panel($params);
                break;
        }
    }
    global $smarty;
    global $orderbox;
    try {
        $is_processing = false;
        $plan_pieces = _get_plan_details($params['configoption1']);
        $api_path_orderid_from_domain = '/webservices/orderid.json';
        $api_path_order_details = '/webservices/details.json';
        $api_path_dns_details = '/webservices/dns-record.json';
        $order_id_result = $orderbox->api('GET', $api_path_orderid_from_domain, array('domain-name' => $params['domain']), $response, 'resellerclubwebservices', 'clientarea');
        if (is_array($order_id_result) && array_key_exists('status', $order_id_result) && strtolower($order_id_result['status']) == 'error') {
            $is_processing = true;
        } else {
            $order_id = $order_id_result;
            $order_details = $orderbox->api('GET', $api_path_order_details, array('order-id' => $order_id), $response, 'resellerclubwebservices', 'clientarea');
            $order_dns_details = $orderbox->api('GET', $api_path_dns_details, array('order-id' => $order_id), $response, 'resellerclubwebservices', 'clientarea');
        }
        $smarty->assign('is_processing', $is_processing);
        if ($is_processing) {
            $smarty->assign('wpp_status', 'Processing...');
        } else {
            $smarty->assign('wpp_status', $order_details['currentstatus']);
            if ('website builder' == $plan_pieces['type']) {
                $smarty->assign('is_websitebuilder', true);
                $smarty->assign('wpp_websitebuilder_panel', _display_websitebuilder_panel_form());
                $smarty->assign('wpp_ip_address', $order_details['ipaddress']);
                $smarty->assign('wpp_mailpop', $order_details['mailpop'] == '-1' ? 'Unlimited' : $order_details['mailpop']);
                $smarty->assign('wpp_diskspace', $order_details['webspace'] == '-1' ? 'Unlimited' : $order_details['webspace']);
                $smarty->assign('wpp_bandwidth', $order_details['bandwidth'] == '-1' ? 'Unlimited' : $order_details['bandwidth']);
            }
            $smarty->assign('wpp_mailhosting_panel', _display_mailhosting_panel_form());
            $smarty->assign('wpp_dns_panel', _display_dns_panel_form());
            $smarty->assign('wpp_webmail_panel', _display_webmail_panel_form());
            $smarty->assign('wpp_allocated_mailspace', $order_details['mailspace'] == '-1' ? 'Unlimited' : $order_details['mailspace'] . " GB");
            $smarty->assign('wpp_email_accounts', $order_details['no_of_mail_boxes'] == '-1' ? 'Unlimited' : $order_details['no_of_mail_boxes']);
            $smarty->assign('nameservers', $order_details['ns_detail']);
            $smarty->assign('dns_details', $order_dns_details);
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }
}
 function _get_control_panel_link($params)
 {
     global $orderbox;
     $error = '';
     $client_details = $orderbox->api('GET', '/customers/details.json', array('username' => $params['clientsdetails']['email']), $response, 'resellerclubsdhostingin', 'clientarea');
     if (is_array($client_details) && strtolower($client_details['status']) == 'error') {
         $error = "Customer ({$params['clientsdetails']['email']}) not found at Resellerclub";
     } else {
         $customer_id = $client_details['customerid'];
         $customer_temp_password = $orderbox->api('GET', '/customers/temp-password.json', array('customer-id' => $customer_id), $response, 'resellerclubsdhostingin', 'clientarea');
         $resellerclub_customer_password = $customer_temp_password;
     }
     if ($error == '') {
         // get orderid from resellerclub
         $plan_pieces = _get_plan_details($params['configoption1']);
         if ('windows' == $plan_pieces['type']) {
             $api_path_orderid_from_domain = '/singledomainhosting/windows/in/orderid.json';
         } else {
             $api_path_orderid_from_domain = '/singledomainhosting/linux/in/orderid.json';
         }
         $order_id_result = $orderbox->api('GET', $api_path_orderid_from_domain, array('domain-name' => $params['domain']), $response, 'resellerclubsdhostingin', 'clientarea');
         if (is_array($order_id_result) && array_key_exists('status', $order_id_result) && strtolower($order_id_result['status']) == 'error') {
             $error = "Hosting order ({$params['domain']}) not found at Resellerclub";
         } else {
             $order_id = $order_id_result;
         }
     }
     if ($error == '') {
         // get reseller branded url
         $reseller_details = $orderbox->api('GET', '/resellers/details.json', array(), $response, 'resellerclubsdhostingin', 'clientarea');
         if (is_array($reseller_details) && strtolower($reseller_details['status']) == 'error') {
             $error = "Reseller not found at Resellerclub";
         } else {
             $reseller_branding_url = $reseller_details['brandingurl'];
         }
     }
     if ($error == '') {
         // generate authentication token
         $ip = $_SERVER['REMOTE_ADDR'];
         $authentication_token_result = $orderbox->api('GET', '/customers/generate-token.json', array('username' => $params['clientsdetails']['email'], 'passwd' => $resellerclub_customer_password, 'ip' => $ip), $response, 'resellerclubsdhostingin', 'clientarea');
         if (is_array($authentication_token_result) && array_key_exists('status', $authentication_token_result) && strtolower($authentication_token_result['status']) == 'error') {
             $authentication_token = '';
         } else {
             $authentication_token = $authentication_token_result;
         }
         return $control_panel_url = "http://" . $reseller_branding_url . "/servlet/ManageServiceServletForAPI?auth-token={$authentication_token}&orderid={$order_id}";
     } else {
         throw new Exception($error);
     }
 }
function resellerclubsdhosting_ChangePackage($params)
{
    global $orderbox;
    try {
        $api_path = '/webservices/orderid.json';
        $order_id_result = $orderbox->api('GET', $api_path, array('domain-name' => $params['domain']), $response);
        if (is_array($order_id_result) && array_key_exists('status', $order_id_result) && strtolower($order_id_result['status']) == 'error') {
            return $order_id_result['message'];
        } else {
            $order_id = $order_id_result;
            $plan_pieces = _get_plan_details($params['configoption1']);
            $billing_cycle = _get_order_billing_cycle($params['clientsdetails']['userid'], $params['serviceid'], $params['domain'], $params['pid']);
            $billing_cycle = strtolower($billing_cycle);
            $months = _get_order_duration_months($billing_cycle);
            $order_details = array('order-id' => $order_id, 'new-plan-id' => $plan_pieces['id'], 'months' => $months, 'invoice-option' => 'NoInvoice');
            $api_path = '/webservices/modify.json';
            $order_api_result = $orderbox->api('POST', $api_path, $order_details);
            if (is_array($order_api_result) && strtolower($order_api_result['status']) == 'error') {
                return $order_api_result['message'];
            }
            return 'success';
        }
    } catch (Exception $e) {
        return "Order Upgrade/Downgrade error - " . $e->getMessage();
    }
}