Custom Functions

Custom functions allow you to define operations that run using the module. The custom functions can perform actions or define additional Client Area pages or output. Permissions can be granted for who can use each custom function (just clients, just admins, or both).

The convention for custom function names is the same as any other module function. It must begin with the module filename (filename_) and the custom function name.

Example Custom Function

Consider the following example of a reboot and shutdown function in a VM or VPS system:
<?php
function yourmodule_reboot($params)
{
    # Code to perform reboot action goes here...
    if ($successful) return ["status"=>"success","message"=>"Your Success Message Here"];
    return ["status"=>"error","message"=>"Your Error Message Here"];
}
function yourmodule_shutdown($params) {
    # Code to perform shutdown action goes here...
    if ($successful) return ["status"=>"success","message"=>"Your Success Message Here"];
    return ["status"=>"error","message"=>"Your Error Message Here"];
}

The above example defines a custom function and uses the passed variables. The custom function returns either success or an error message to indicate failure.

The following example allows clients to perform reboots but only allows admins to perform a reboot or shutdown:
<?php
function yourmodule_ClientAreaCustomButtonArray($params)
{
    $buttons = [
        "Reboot Server" => "reboot",
        "Shutdown Server" => "shutdown",
        ];
    return $buttons;
}
function yourmodule_AdminCustomButtonArray($params)
{
    $buttons = [
        "Reboot Server" => "reboot",
        "Shutdown Server" => "shutdown",
        ];
    return $buttons;
}
The key value of the array is what displays to admins and clients on the button or menu options for the commands. The value is the custom function name without the modulename_ prefix.

A description of how to provide a button or way to invoke a custom function is in the Client Area Output section:
<form method="post" action="">
<input type="hidden" name="id" value="{$serviceid}" />
<input type="hidden" name="modop" value="custom" />
<input type="hidden" name="a" value="reboot" />
<input type="submit" value="Reboot VPS Server" />