TeleMagic Posted August 25, 2013 Share Posted August 25, 2013 Hi Guys I am writing a custom addon hook to execute when a product Addon is Activated. I have a hook that pulls $vars as a variable aray for the function. Now in the documentation here http://docs.whmcs.com/Hooks:Addons it shows just 4 variables passed is that just the specific variables? Would it also pass things like serverusername, serverpassword etc the same as the module I created for the main product? Also is there any way of passing debug information from a hook? Can I place a Die in the script? Regards 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 25, 2013 Share Posted August 25, 2013 AddonActivation hook point gives you the following vars: id - the ID of the addon service (tblhostingaddons.id)userid - the client ID (tblclients.id) serviceid - the ID of the product/service it is tied to (tblhosting.id) addonid - the ID of the predefined addon it is assigned to (tbladdons.id) With these variables you can literally retrieve everything you want. Simply play around with some JOIN to get the things done. You should JOIN userid/serviceid with tblhosting where you can get both server username and password. 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 25, 2013 Author Share Posted August 25, 2013 Ah I hadn't thought of doing that! Thanks for the pointer! 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 26, 2013 Author Share Posted August 26, 2013 Ok gone to do this and found one issue. To achieve this I would need to pull the value of tblservers.password however this is an encrypted field, is there a function in WHMCS to decrypt this back to use in a DB Connect? Regards 0 Quote Link to comment Share on other sites More sharing options...
jclarke Posted August 26, 2013 Share Posted August 26, 2013 Yes, there is a function available called decrypt which you can use to decrypt the tblservers.password field. $password = decrypt($server_password); 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 26, 2013 Share Posted August 26, 2013 Also you can use Internal API functions inside you hook. $command = "decryptpassword"; $adminuser = "admin"; $values["password2"] = "xxxxxx"; $results = localAPI($command,$values,$adminuser); With this one you can retreive the client password. $command = "getclientpassword"; $adminuser = "admin"; $values["userid"] = "1"; $results = localAPI($command,$values,$adminuser); 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 26, 2013 Author Share Posted August 26, 2013 Thats great. Now how do I debug this hook. I have written the code which I think will do what I want but it does not seem to be doing anything? How do I veryify and debug if the hook is actualling being called? And then if it is debug the actual hook code? Regards 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 26, 2013 Share Posted August 26, 2013 You can print_r(); before die(); or even a fwrite(); in a txt or a lazy mailto(); 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 26, 2013 Author Share Posted August 26, 2013 Um. I have tried a die, but it does not seem to give me a blank screen in same way a die does on a module! So I wonder if that means the hook isn't loading! Is there anything I have to do to make the hook load? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 26, 2013 Share Posted August 26, 2013 In this case try with the brute way. Remove everything inside your function and just leave a mailto or an header to google.com. If you can't get the email or if you aren't redirected to Google probably you are referring in a wrong way to your function or you are using a wrong hook point. Please post the line you use to call your function. 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 26, 2013 Author Share Posted August 26, 2013 I'm out at the moment, but will paste is shortly. I copied it from The hook docs so should be right! Probably made schoolboy error. Is mailto an internal function? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 26, 2013 Share Posted August 26, 2013 Something like this function YourFunction($vars) { $to = "yourmail@example.com"; $subject = "Hello, i'm the hook!"; $message = "I'm fine"; $from = "whatever@example.com"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); } add_hook("AddonActivation",1,"YourFunction"); 0 Quote Link to comment Share on other sites More sharing options...
TeleMagic Posted August 27, 2013 Author Share Posted August 27, 2013 Thanks for the Help Kian I said it would be a schoolboy error, I wasnt expecting it to be something quite as stupid as it was though. There was nothing wrong with the code or my hook, it actually worked first time, which is pretty good as I am not really a programmer and until last week when I started doing my VOIP modules for WHMCS had only ever done basic hacks to php scripts. The only issue is that I was working on the wrong version of WHMCS. I have 2 dev licenses for 2 dev sites to keep code seperated between 2 groups of developers I freelance work to. I was working on the module code on one and trying to get it to execute by purchasing a product add-on on the other! DOH!!! 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.