-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathprovisioningmodule.php
More file actions
901 lines (841 loc) · 27.2 KB
/
provisioningmodule.php
File metadata and controls
901 lines (841 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
<?php
/**
* WHMCS SDK Sample Provisioning Module
*
* Provisioning Modules, also referred to as Product or Server Modules, allow
* you to create modules that allow for the provisioning and management of
* products and services in WHMCS.
*
* This sample file demonstrates how a provisioning module for WHMCS should be
* structured and exercises all supported functionality.
*
* Provisioning Modules are stored in the /modules/servers/ directory. The
* module name you choose must be unique, and should be all lowercase,
* containing only letters & numbers, always starting with a letter.
*
* Within the module itself, all functions must be prefixed with the module
* filename, followed by an underscore, and then the function name. For this
* example file, the filename is "provisioningmodule" and therefore all
* functions begin "provisioningmodule_".
*
* If your module or third party API does not support a given function, you
* should not define that function within your module. Only the _ConfigOptions
* function is required.
*
* For more information, please refer to the online documentation.
*
* @see https://developers.whmcs.com/provisioning-modules/
*
* @copyright Copyright (c) WHMCS Limited 2017
* @license https://www.whmcs.com/license/ WHMCS Eula
*/
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
// Require any libraries needed for the module to function.
// require_once __DIR__ . '/path/to/library/loader.php';
//
// Also, perform any initialization required by the service's library.
/**
* Define module related meta data.
*
* Values returned here are used to determine module related abilities and
* settings.
*
* @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
*
* @return array
*/
function provisioningmodule_MetaData()
{
return array(
'DisplayName' => 'Demo Provisioning Module',
'APIVersion' => '1.1', // Use API Version 1.1
'RequiresServer' => true, // Set true if module requires a server to work
'DefaultNonSSLPort' => '1111', // Default Non-SSL Connection Port
'DefaultSSLPort' => '1112', // Default SSL Connection Port
'ServiceSingleSignOnLabel' => 'Login to Panel as User',
'AdminSingleSignOnLabel' => 'Login to Panel as Admin',
);
}
/**
* Define product configuration options.
*
* The values you return here define the configuration options that are
* presented to a user when configuring a product for use with the module. These
* values are then made available in all module function calls with the key name
* configoptionX - with X being the index number of the field from 1 to 24.
*
* You can specify up to 24 parameters, with field types:
* * text
* * password
* * yesno
* * dropdown
* * radio
* * textarea
*
* Examples of each and their possible configuration parameters are provided in
* this sample function.
*
* @see https://developers.whmcs.com/provisioning-modules/config-options/
*
* @return array
*/
function provisioningmodule_ConfigOptions()
{
return array(
// a text field type allows for single line text input
'Text Field' => array(
'Type' => 'text',
'Size' => '25',
'Default' => '1024',
'Description' => 'Enter in megabytes',
),
// a password field type allows for masked text input
'Password Field' => array(
'Type' => 'password',
'Size' => '25',
'Default' => '',
'Description' => 'Enter secret value here',
),
// the yesno field type displays a single checkbox option
'Checkbox Field' => array(
'Type' => 'yesno',
'Description' => 'Tick to enable',
),
// the dropdown field type renders a select menu of options
'Dropdown Field' => array(
'Type' => 'dropdown',
'Options' => array(
'option1' => 'Display Value 1',
'option2' => 'Second Option',
'option3' => 'Another Option',
),
'Description' => 'Choose one',
),
// the radio field type displays a series of radio button options
'Radio Field' => array(
'Type' => 'radio',
'Options' => 'First Option,Second Option,Third Option',
'Description' => 'Choose your option!',
),
// the textarea field type allows for multi-line text input
'Textarea Field' => array(
'Type' => 'textarea',
'Rows' => '3',
'Cols' => '60',
'Description' => 'Freeform multi-line text input field',
),
);
}
/**
* Provision a new instance of a product/service.
*
* Attempt to provision a new instance of a given product/service. This is
* called any time provisioning is requested inside of WHMCS. Depending upon the
* configuration, this can be any of:
* * When a new order is placed
* * When an invoice for a new order is paid
* * Upon manual request by an admin user
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_CreateAccount(array $params)
{
try {
// Call the service's provisioning function, using the values provided
// by WHMCS in `$params`.
//
// A sample `$params` array may be defined as:
//
// ```
// array(
// 'domain' => 'The domain of the service to provision',
// 'username' => 'The username to access the new service',
// 'password' => 'The password to access the new service',
// 'configoption1' => 'The amount of disk space to provision',
// 'configoption2' => 'The new services secret key',
// 'configoption3' => 'Whether or not to enable FTP',
// ...
// )
// ```
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Suspend an instance of a product/service.
*
* Called when a suspension is requested. This is invoked automatically by WHMCS
* when a product becomes overdue on payment or can be called manually by admin
* user.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_SuspendAccount(array $params)
{
try {
// Call the service's suspend function, using the values provided by
// WHMCS in `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Un-suspend instance of a product/service.
*
* Called when an un-suspension is requested. This is invoked
* automatically upon payment of an overdue invoice for a product, or
* can be called manually by admin user.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_UnsuspendAccount(array $params)
{
try {
// Call the service's unsuspend function, using the values provided by
// WHMCS in `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Terminate instance of a product/service.
*
* Called when a termination is requested. This can be invoked automatically for
* overdue products if enabled, or requested manually by an admin user.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_TerminateAccount(array $params)
{
try {
// Call the service's terminate function, using the values provided by
// WHMCS in `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Change the password for an instance of a product/service.
*
* Called when a password change is requested. This can occur either due to a
* client requesting it via the client area or an admin requesting it from the
* admin side.
*
* This option is only available to client end users when the product is in an
* active status.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_ChangePassword(array $params)
{
try {
// Call the service's change password function, using the values
// provided by WHMCS in `$params`.
//
// A sample `$params` array may be defined as:
//
// ```
// array(
// 'username' => 'The service username',
// 'password' => 'The new service password',
// )
// ```
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Upgrade or downgrade an instance of a product/service.
*
* Called to apply any change in product assignment or parameters. It
* is called to provision upgrade or downgrade orders, as well as being
* able to be invoked manually by an admin user.
*
* This same function is called for upgrades and downgrades of both
* products and configurable options.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_ChangePackage(array $params)
{
try {
// Call the service's change password function, using the values
// provided by WHMCS in `$params`.
//
// A sample `$params` array may be defined as:
//
// ```
// array(
// 'username' => 'The service username',
// 'configoption1' => 'The new service disk space',
// 'configoption3' => 'Whether or not to enable FTP',
// )
// ```
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Renew an instance of a product/service.
*
* Attempt to renew an existing instance of a given product/service. This is
* called any time a product/service invoice has been paid.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return string "success" or an error message
*/
function provisioningmodule_Renew(array $params)
{
try {
// Call the service's provisioning function, using the values provided
// by WHMCS in `$params`.
//
// A sample `$params` array may be defined as:
//
// ```
// array(
// 'domain' => 'The domain of the service to provision',
// 'username' => 'The username to access the new service',
// 'password' => 'The password to access the new service',
// 'configoption1' => 'The amount of disk space to provision',
// 'configoption2' => 'The new services secret key',
// 'configoption3' => 'Whether or not to enable FTP',
// ...
// )
// ```
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Daily import of the disk and bandwidth usage for accounts of a server.
*
* The data imported is then used to display the usage stats both within
* the client and admin areas of WHMCS. The data is also used in disk
* and bandwidth overage billing calculations if enabled for a product.
*
* The UsageUpdate function runs via WHMCS Cron, for any active, enabled server.
*
* Important: Runs per server not per product
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/usage-update/
*
*/
function mymodule_UsageUpdate($params) {
$serverid = $params['serverid'];
$serverhostname = $params['serverhostname'];
$serverip = $params['serverip'];
$serverusername = $params['serverusername'];
$serverpassword = $params['serverpassword'];
$serveraccesshash = $params['serveraccesshash'];
$serversecure = $params['serversecure'];
// Run connection to retrieve usage for all domains/accounts on $serverid
// E.g.:
$results = [
[
'domain' => 'example1.com',
'diskusage' => 1100,
'disklimit' => 1000,
'bandwidth' => 2000,
'bwlimit' => 1500,
],
[
'domain' => 'example2.com',
'diskusage' => 800,
'disklimit' => 1000,
'bandwidth' => 2500,
'bwlimit' => 1500,
],
];
// Now loop through results and update DB
foreach ($results AS $domain => $values) {
try {
\WHMCS\Database\Capsule::table('tblhosting')
->where('server', $serverid)
->where('domain', $values['domain'])
->update([
'diskusage' => $values['diskusage'],
'disklimit' => $values['disklimit'],
'bwusage' => $values['bandwidth'],
'bwlimit' => $values['bwlimit'],
'lastupdate' => Capsule::raw('now()'),
]);
} catch (\Exception $e) {
// Handle any error which may occur
}
}
}
/**
* Test connection with the given server parameters.
*
* Allows an admin user to verify that an API connection can be
* successfully made with the given configuration parameters for a
* server.
*
* When defined in a module, a Test Connection button will appear
* alongside the Server Type dropdown when adding or editing an
* existing server.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return array
*/
function provisioningmodule_TestConnection(array $params)
{
try {
// Call the service's connection test function.
$success = true;
$errorMsg = '';
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
$success = false;
$errorMsg = $e->getMessage();
}
return array(
'success' => $success,
'error' => $errorMsg,
);
}
/**
* Additional actions an admin user can invoke.
*
* Define additional actions that an admin user can perform for an
* instance of a product/service.
*
* @see provisioningmodule_buttonOneFunction()
*
* @return array
*/
function provisioningmodule_AdminCustomButtonArray()
{
return array(
"Button 1 Display Value" => "buttonOneFunction",
"Button 2 Display Value" => "buttonTwoFunction",
);
}
/**
* Additional actions a client user can invoke.
*
* Define additional actions a client user can perform for an instance of a
* product/service.
*
* Any actions you define here will be automatically displayed in the available
* list of actions within the client area.
*
* @return array
*/
function provisioningmodule_ClientAreaCustomButtonArray()
{
return array(
"Action 1 Display Value" => "actionOneFunction",
"Action 2 Display Value" => "actionTwoFunction",
);
}
/**
* Custom function for performing an additional action.
*
* You can define an unlimited number of custom functions in this way.
*
* Similar to all other module call functions, they should either return
* 'success' or an error message to be displayed.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
* @see provisioningmodule_AdminCustomButtonArray()
*
* @return string "success" or an error message
*/
function provisioningmodule_buttonOneFunction(array $params)
{
try {
// Call the service's function, using the values provided by WHMCS in
// `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Custom function for performing an additional action.
*
* You can define an unlimited number of custom functions in this way.
*
* Similar to all other module call functions, they should either return
* 'success' or an error message to be displayed.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
* @see provisioningmodule_ClientAreaCustomButtonArray()
*
* @return string "success" or an error message
*/
function provisioningmodule_actionOneFunction(array $params)
{
try {
// Call the service's function, using the values provided by WHMCS in
// `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
return 'success';
}
/**
* Admin services tab additional fields.
*
* Define additional rows and fields to be displayed in the admin area service
* information and management page within the clients profile.
*
* Supports an unlimited number of additional field labels and content of any
* type to output.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
* @see provisioningmodule_AdminServicesTabFieldsSave()
*
* @return array
*/
function provisioningmodule_AdminServicesTabFields(array $params)
{
try {
// Call the service's function, using the values provided by WHMCS in
// `$params`.
$response = array();
// Return an array based on the function's response.
return array(
'Number of Apples' => (int) $response['numApples'],
'Number of Oranges' => (int) $response['numOranges'],
'Last Access Date' => date("Y-m-d H:i:s", $response['lastLoginTimestamp']),
'Something Editable' => '<input type="hidden" name="provisioningmodule_original_uniquefieldname" '
. 'value="' . htmlspecialchars($response['textvalue']) . '" />'
. '<input type="text" name="provisioningmodule_uniquefieldname"'
. 'value="' . htmlspecialchars($response['textvalue']) . '" />',
);
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
// In an error condition, simply return no additional fields to display.
}
return array();
}
/**
* Execute actions upon save of an instance of a product/service.
*
* Use to perform any required actions upon the submission of the admin area
* product management form.
*
* It can also be used in conjunction with the AdminServicesTabFields function
* to handle values submitted in any custom fields which is demonstrated here.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
* @see provisioningmodule_AdminServicesTabFields()
*/
function provisioningmodule_AdminServicesTabFieldsSave(array $params)
{
// Fetch form submission variables.
$originalFieldValue = isset($_REQUEST['provisioningmodule_original_uniquefieldname'])
? $_REQUEST['provisioningmodule_original_uniquefieldname']
: '';
$newFieldValue = isset($_REQUEST['provisioningmodule_uniquefieldname'])
? $_REQUEST['provisioningmodule_uniquefieldname']
: '';
// Look for a change in value to avoid making unnecessary service calls.
if ($originalFieldValue != $newFieldValue) {
try {
// Call the service's function, using the values provided by WHMCS
// in `$params`.
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
// Otherwise, error conditions are not supported in this operation.
}
}
}
/**
* Perform single sign-on for a given instance of a product/service.
*
* Called when single sign-on is requested for an instance of a product/service.
*
* When successful, returns a URL to which the user should be redirected.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return array
*/
function provisioningmodule_ServiceSingleSignOn(array $params)
{
try {
// Call the service's single sign-on token retrieval function, using the
// values provided by WHMCS in `$params`.
$response = array();
return array(
'success' => true,
'redirectTo' => $response['redirectUrl'],
);
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return array(
'success' => false,
'errorMsg' => $e->getMessage(),
);
}
}
/**
* Perform single sign-on for a server.
*
* Called when single sign-on is requested for a server assigned to the module.
*
* This differs from ServiceSingleSignOn in that it relates to a server
* instance within the admin area, as opposed to a single client instance of a
* product/service.
*
* When successful, returns a URL to which the user should be redirected to.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return array
*/
function provisioningmodule_AdminSingleSignOn(array $params)
{
try {
// Call the service's single sign-on admin token retrieval function,
// using the values provided by WHMCS in `$params`.
$response = array();
return array(
'success' => true,
'redirectTo' => $response['redirectUrl'],
);
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return array(
'success' => false,
'errorMsg' => $e->getMessage(),
);
}
}
/**
* Client area output logic handling.
*
* This function is used to define module specific client area output. It should
* return an array consisting of a template file and optional additional
* template variables to make available to that template.
*
* The template file you return can be one of two types:
*
* * tabOverviewModuleOutputTemplate - The output of the template provided here
* will be displayed as part of the default product/service client area
* product overview page.
*
* * tabOverviewReplacementTemplate - Alternatively using this option allows you
* to entirely take control of the product/service overview page within the
* client area.
*
* Whichever option you choose, extra template variables are defined in the same
* way. This demonstrates the use of the full replacement.
*
* Please Note: Using tabOverviewReplacementTemplate means you should display
* the standard information such as pricing and billing details in your custom
* template or they will not be visible to the end user.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/provisioning-modules/module-parameters/
*
* @return array
*/
function provisioningmodule_ClientArea(array $params)
{
// Determine the requested action and set service call parameters based on
// the action.
$requestedAction = isset($_REQUEST['customAction']) ? $_REQUEST['customAction'] : '';
if ($requestedAction == 'manage') {
$serviceAction = 'get_usage';
$templateFile = 'templates/manage.tpl';
} else {
$serviceAction = 'get_stats';
$templateFile = 'templates/overview.tpl';
}
try {
// Call the service's function based on the request action, using the
// values provided by WHMCS in `$params`.
$response = array();
$extraVariable1 = 'abc';
$extraVariable2 = '123';
return array(
'tabOverviewReplacementTemplate' => $templateFile,
'templateVariables' => array(
'extraVariable1' => $extraVariable1,
'extraVariable2' => $extraVariable2,
),
);
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'provisioningmodule',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
// In an error condition, display an error page.
return array(
'tabOverviewReplacementTemplate' => 'error.tpl',
'templateVariables' => array(
'usefulErrorHelper' => $e->getMessage(),
),
);
}
}