<?php
/* * ********************************************************************
*  ProxmoxVPS Product developed. (27.03.19)
* *
*
*  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
*  CONTACT                        ->       contact@modulesgarden.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.
*
*
* ******************************************************************** */


namespace ModulesGarden\ProxmoxAddon\App\Services\Vps;


use ModulesGarden\ProxmoxAddon\Core\UI\Traits\WhmcsParams;
use function ModulesGarden\ProxmoxAddon\Core\Helper\isAdmin;

class UrlService
{
    use WhmcsParams;

    public function getUrl($controller = null, $action = null, array $params = [])
    {
        $url = 'clientarea.php?action=productdetails&id=' . $this->getWhmcsParamByKey('serviceid');
        if ($controller)
        {
            $params['modop']   = 'custom';
            $params['a']       = 'management';
            $params['mg-page'] = $controller;
            if ($action)
            {
                $params['mg-action'] = $action;
            }
            if ($params)
            {
                $url .= '&' . http_build_query($params);
            }
        }
        if (isAdmin())
        {
            return '../dologin.php?username=' . urlencode($this->getWhmcsParamByKey('clientsdetails')['email']) . '&goto=' . urlencode($url);
        }
        return $url;
    }

}