WisTex Posted December 9, 2018 Share Posted December 9, 2018 I have some already existing code that I would like to integrate with WHMCS. It is fairly simple old school code (query database, write HTML). Not the modern way of doing things, but the code works well, and I don't have the time nor budget to rewrite the entire script. I was hoping to enhance the code by tapping into the WHMCS login system and prepopulating fields with information stored in the WHMCS database. I was looking at the sample code for creating an Addon Module, and it was not clear where you would paste such code. For example, if I wanted to execute the following code, where would you put it? <?php $message = "Hello World!"; echo $message; ?> Or are modules structured in such a way where old-school code won't work? If that is the case, should I just create pages then? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted December 9, 2018 Share Posted December 9, 2018 It's all described here. I know, it seems complicated but it's not. 0 Quote Link to comment Share on other sites More sharing options...
WisTex Posted December 9, 2018 Author Share Posted December 9, 2018 (edited) I read that whole section. The only examples I see use hooks and functions. The existing code is old-school. No functions. Just database query, output HTML. It appears it would go in addonmodule.php but that code seems to want functions. Do I just replace the function with HTML? Do I put the HTML in the function? Edited December 9, 2018 by WisTex 0 Quote Link to comment Share on other sites More sharing options...
WisTex Posted December 10, 2018 Author Share Posted December 10, 2018 It appears modules would not be a suitable solution for my issue, for the following reasons: The example code outputs the WHMCS header and footer even though I don't need it. The template and the PHP code are separated in WHMCS and in my existing script, HTML and PHP are merged. As such, it is actually impossible to just cut and paste the code from the other script into the module and have it work. Since the whole purpose of integrating the other script is to not have to rewrite it, modules would not be an ideal way to do it. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted December 12, 2018 WHMCS Staff Share Posted December 12, 2018 Hi @WisTex, For addon pages available within the Admin Area, you would need to add this to ~/lib/Admin/Controller.php - https://github.com/WHMCS/sample-addon-module/blob/master/modules/addons/addonmodule/lib/Admin/Controller.php In the WHMCS Admin Area, the url would look like ~/admin/addonmodules.php?module=addonmodulename&action=page - the action variable calls the function in Controller.php. For example, if you added the following function to Controller.php: public function mynewpage($vars) { $message = "Hello World!"; echo $message; return; } This would allow you to view "Hello World" from ~/admin/addonmodules.php?module=addonmodulename&action=mynewpage Naturally, addonmodulename would be the name of your module. I hope this helps! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.