naithen_tampa Posted October 7, 2015 Share Posted October 7, 2015 Hi Guys ,, Pleasure to be with you here and join this great community. I have small problem with my WHMCS hooks script and I need help. My hook is not being triggered, but the hook point itself is working. ( as per WHMCS support). they said " So you'd need to take another look at your custom code to see why it is not being triggered. " What I want to do is this " After accepting order, a shell script should be executed This is my PHP script in includes/hooks --------------------------------------- <?php /** * Example Hook Function * * Please refer to the documentation @ [url]http://docs.whmcs.com/Hooks[/url] for more information * The code in this hook is commented out by default. Uncomment to use. * * @package WHMCS * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2013 * @license [url]http://www.whmcs.com/license/[/url] WHMCS Eula * @version $Id$ * @link [url]http://www.whmcs.com/[/url] */ /* if (!defined("WHMCS")) die("This file cannot be accessed directly"); function create_forum_account($vars) { $email = $vars['email']; $domain = $var['domainid']; $output = shell_exec('/home/test.sh $email $domain'); // Run code to create remote forum account here... } add_hook("AcceptOrder",1,"create_forum_account"); */ --------------------------------------- Now the hooks is not triggered and the shell scripts is not executed. for your info: ( I make the owner of the shell script file is the same owner of whmcs source files) Hope find a lead here 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted October 7, 2015 Share Posted October 7, 2015 AcceptOrder hook point doesn't come with "email" and "domainid" fields. It only has "orderid". That said, your $vars['email'] and $vars['domainid'] are always null in your example. The only value you have in this hook point is $vars['orderid']. You need to use it to retreive all other fields you need with 2 SQL queries. This query gives you an array containing all IDs of domains inside your given order: SELECT id FROM tbldomains WHERE orderid = $vars['orderid'] This query gives the email of the client: SELECT t1.email FROM tblclients AS t1 LEFT JOIN tblorders AS t2 ON t1.id = t2.userid WHERE t2.id = $vars['orderid'] 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 7, 2015 Share Posted October 7, 2015 here is the AcceptOrder action hook documentation, it does not pass the variables (values) you use in your code (email, domainid), then you may need to use "orderid" to query these values from Database, also you need to un-comment the function to work by removing the "/*" and "*/". 0 Quote Link to comment Share on other sites More sharing options...
naithen_tampa Posted October 8, 2015 Author Share Posted October 8, 2015 Hi Thank you for your support First I tried your code but it shows error as follows : Fatal error: Call to a member function query() on a non-object Then I checked Whmcs documentation " SQL Helper Functions " and then I follow it as the below however I tried their code but I didnot work as well # function create_forum_account($vars) { $val = $vars['orderid']; $fields = "domain"; $table1 = "tbldomains"; $table2 = "tblclients"; $fields2 = "email"; $where = array("orderid"=>$val); $join = "tblorders ON tblorders.userid=tblclients.id"; $result1 = select_query($table1,$fields,$where); $result2 = select_query($table2,$fields2,$where); $data = mysql_fetch_array($result1); $data2 = mysql_fetch_array($result2); $domain = $data['domain']; $Email = $data2['email']; $output = shell_exec("echo $domain$Email>now.txt"); ---------------------- I did print in file now.txt So I guess It didnt work Any help guys...... 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 9, 2015 Share Posted October 9, 2015 what about replacing you action hook code with the following as a start <? function hook_testshell($vars) { $getDomain = full_query("SELECT id FROM tbldomains WHERE orderid = '".$vars['orderid']."'"); $getDomain = mysql_fetch_assoc($getDomain); $domain = $getDomain['id']; $getEmail = full_query("SELECT tblclients.email FROM tblclients LEFT JOIN tblorders ON (tblclients.id = tblorders.userid) WHERE tblorders.id = '".$vars['orderid']."'"); $getEmail = mysql_fetch_assoc($getEmail); $email = $getEmail['email']; $output = shell_exec('/home/test.sh $email $domain'); } add_hook("AcceptOrder", 1, "hook_testshell"); how about that? 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.