Git Product home page Git Product logo

fbrettnich / whmcs-supportpin-module Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 11.0 638 KB

SupportPin WHMCS Addon | Let your customers generate a support/phone pin to identify your customers faster, for example on the phone

License: GNU General Public License v3.0

PHP 81.82% Smarty 16.54% CSS 1.65%
admin-dashboard-widget phone-pins support support-pins whmcs whmcs-addon whmcs-module whmcs-supportpin

whmcs-supportpin-module's People

Contributors

bastianleicht avatar conandoyl avatar fbrettnich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

whmcs-supportpin-module's Issues

You can use a Template Manager for this

function supportpin_output($vars) {

If you don't want to provide the template code directly inside the Main file, you can use this Template Manager to handle that code outside the main file.

class TemplateManager {

protected $basePath;
protected $currentTemplate;
protected $currentTPLFile;


public function __construct(string $basepath, $currentTemplate = "admin/home.tpl"){
    $this->setBasePath($basepath . '/Templates/');
    $this->setCurrentTemplate($this->getBasePath() . $currentTemplate);
    $this->setCurrentTPLFile($currentTemplate);

}


public function getTemplate($page, $isAdmin = false){
    return ($isAdmin ? $this->getBasePath() ."admin/" . $page .".tpl"  : "Templates/client/" . $page . ".tpl");
}



/**
 * Get the value of currentTemplate
 */ 
public function getCurrentTemplate()
{
    return $this->currentTemplate;
}

/**
 * Set the value of currentTemplate
 *
 * @return  self
 */ 
public function setCurrentTemplate($currentTemplate)
{
    $this->currentTemplate = $currentTemplate;

    return $this;
}

/**
 * Get the value of basePath
 */ 
public function getBasePath()
{
    return $this->basePath;
}

/**
 * Set the value of basePath
 *
 * @return  self
 */ 
public function setBasePath($basePath)
{
    $this->basePath = $basePath;

    return $this;
}

/**
 * Get the value of currentTPLFile
 */ 
public function getCurrentTPLFile()
{
return $this->currentTPLFile;
}

/**
 * Set the value of currentTPLFile
 *
 * @return  self
 */ 
public function setCurrentTPLFile($currentTPLFile)
{
$this->currentTPLFile = $currentTPLFile;

return $this;
}
}

Then the call could be like this:

function module_output($vars) {
$smarty = new Smarty();
    $_lang = $vars['_lang'];
    $TPLManager = new TemplateManager(dirname(__FILE__), "admin/home.tpl");
    $page = isset($_GET['page']) ? $_GET['page'] : 'home';
    
    $smarty->assign('modulelink', $vars['modulelink'] );
    $smarty->caching = false; // Debugging
    $smarty->compile_dir = $GLOBALS['templates_compiledir'];

    $CustomFunction = "template_" . $page;

    $smarty->assign('tplVars', (new TemplateService)->$CustomFunction($vars));


    //Load Template
	$smarty->display($TPLManager->getTemplate($page, true));
	
}

function module_clientarea($vars){
(...)
 $TPLManager = new TemplateManager(dirname(__FILE__), "admin/home.tpl");
 return array(
        'pagetitle'     => 'Page Title',
        'templatefile'  => $TPLManager->getTemplate($page),
        'requirelogin'  => true, # accepts true/false
        'forcessl'      => true, # accepts true/false
        'vars'          => array(
            'modulelink'    => $modulelink,
            'moduleversion' => $version,
            'currentPage'   => $page,
            'tplVars'       => (new TemplateService)->$CustomFunction($vars),
            'addonlang'     => $_lang,
        ),
    );

}

And the TemplateService handles the additional variables if needed. In this case we define the function related to the template

class TemplateService {

      public function template_home($vars) { // home is the name of the template file that will be displayed
        return []; // Return a Value or a Array with additional variables that need to be available inside the template.
       }
}

Add it on different location

Does anyone knows how we can add it on a different page? Ex: to be displayed only on support sidebar instead of clientarea homepage?

Or maybe add it in a drop down right next to the notification icon?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.