Jump to content

My hook is not being triggered


naithen_tampa

Recommended Posts

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

Link to comment
Share on other sites

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']

Link to comment
Share on other sites

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......

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated