Difference between revisions of "Internal Functions"

From WHMCS Documentation

(Formatting Currency)
(Replaced content with "This page has moved to https://developers.whmcs.com/advanced/")
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
The following code samples are intended to provide developers with some core functions that are available to make use of in custom hooks, modules and addons for WHMCS to provide consistency with the rest of the system.
+
This page has moved to https://developers.whmcs.com/advanced/
 
 
==Date Functions==
 
 
 
There are 3 date related functions you can use from WHMCS in custom modules to work with dates, for getting the current date, for converting a date/time field from the display into the chosen display format, and for convert an input date/time into the database format:
 
 
 
<source lang="php">
 
$todaysdate = getTodaysDate();
 
$date = fromMySQLDate($date,$time);
 
$date = toMySQLDate($date);
 
</source>
 
 
 
In the fromMySQLDate function, $time can be a true/false value to determine if you want the time to be displayed with the date also.
 
 
 
==Formatting Currency==
 
 
 
These 2 functions can be used to format amounts for display in a clients currency.  The first function retrieves the currency details for a given Client ID, and the second formats it for display.  You must call the first function first unless you are only wanting to display a value in the default system currency.
 
 
 
<source lang="php">
 
$currency = getCurrency($userid);
 
$amount = formatCurrency($amount,$currency);
 
</source>
 
 
 
==Email Templates==
 
 
 
Email Templates can be sent to clients as follows.  Here the 3 parameters the function accepts are the email template name, and the ID to send it for (a Client ID for a general email template, a Service ID for a product related email, an Invoice ID for an invoice related email, etc...) and finally an optional extra variables parameter that allows you to define custom merge fields that should be available to the email template.
 
 
 
<source lang="php">
 
$messagename = 'Demo Email Template';
 
$relid = '1';
 
$extravars = array( 'custom_var1' => 'abc', 'another_var' => 'def' );
 
sendMessage($messagename,$relid,$extravars);
 
</source>
 
 
 
==MySQL Database Queries==
 
 
 
A DB connection is open and available to use from all WHMCS files.  So you can simply use that with the regular mysql_query syntax, or you can make use of the [[SQL Helper Functions]] provided in WHMCS.
 
 
 
==CURL Connections==
 
 
 
For any remote API connections, we recommend using CURL. And to simplify that, there is a built in call function you can use as follows.
 
 
 
<source lang="php">
 
$url = 'http://www.whmcs.com/';
 
$postfields = array( 'a' => 'b', 'c' => 'd', etc... );
 
#$options = array( 'CURLOPT_TIMEOUT' => '300', 'HEADER' => 'xxxxx' ); # Optional
 
$response = curlCall($url,$postfields,$options);
 
</source>
 
 
 
==Local API==
 
 
 
The Local API makes available over 100 WHMCS functions to custom coding, for things like creating invoices, applying payments, creating tickets, managing products/domains, and more...  For more details, please refer to the [[API:Internal_API]] section
 
 
 
==Log Module Call==
 
 
 
For provisioning and registrar modules, we recommend making use of the logModuleCall function to record all API requests and responses, to aid in debugging problems with the module.  More details on this can be found in the Provisioning Module docs @ http://docs.whmcs.com/Provisioning_Module_Developer_Docs#Module_Logging
 
 
 
==Log Activity==
 
 
 
If you want to add an entry to the activity log, then you can do so using the LogActivity function as follows which will automatically record the message you specify along with the currently logged in admin or client, and IP address.
 
 
 
<source lang="php">
 
logActivity('Message goes here');
 
</source>
 

Latest revision as of 15:50, 13 March 2017

This page has moved to https://developers.whmcs.com/advanced/