ZeroGravity Posted December 10, 2010 Share Posted December 10, 2010 I am new to WHMCS and PHP (but not to programming). I am trying to add a hook to create a custom inovice number. Just starting with the system I'm not wanting my invoice numbers to be 1,2,3... I picked up the code from another thread. When I put the php file in the includes/hooks directory I get blank pages when saving settings. If I delete the file everything works fine. I have added the following to configration.php but nothing appears on the screen at all. error_reporting(E_ALL); $display_errors = true; $mysql_errors = true; eg. I put the PHP file in the hook folder. Go to the Setup->General Settings page Invoices tab. Change one of the settings and click "Save Changes." I get a blank screen. Click the browser back button and the General Setting->General Tab is displayed. Go to the Invoices Tab and the changes have been saved. If I remove the file from the hooks directory the changes save and the screen refreshes with the confirmation message displayed at the top. I have commented the add_hook line and even commented every line of code inside the function but the error stills happens. Error aside I am not sure if I am going about this the correct way so any advice and assisstance is appreciated. Here is the code in custom_invoice_number.php <?php add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number"); function custom_invoice_number($invoiceid) { // generate invoice number and save $customnumber = date("Ym") . $invoiceid; // = 201004312 mysql_query ("UPDATE tblinvoices SET invoicenum='$customnumber' WHERE id='$invoiceid' LIMIT 1"); // check $d = array(); $q = mysql_query("SELECT id, invoicenum FROM tblinvoices WHERE id='$invoiceid' LIMIT 1"); while ($row = mysql_fetch_array($q)) { if ($row['invoicenum'] == '') { $d['message'] = 'no invoicenumber stored'; } else { $d['id'] = $row['id']; $d['invoicenum'] = $row['invoicenum']; } } // make response // standard response construction #echo "a=fuffig;b=faffig;c=lalala"; echo 'id=' . $d['id'] . ';invoicenum=' . $d['invoicenum']; } ?> Many Thanks 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted December 11, 2010 Share Posted December 11, 2010 (edited) Make sure that the files in the hooks folder only contain code for your hook functions. Any other files in this directory (like an error log) will screw things up. But also your syntax is wrong for your hook function. All variables come into the function within an array even if the hook function has only a single var. You need something like: <?php add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number"); function custom_invoice_number($vars) { $invoiceid = $vars['invoiceid']; at the beginning of your code. Edited December 11, 2010 by tomdchi 0 Quote Link to comment Share on other sites More sharing options...
ZeroGravity Posted December 11, 2010 Author Share Posted December 11, 2010 Thanks for the heads up on the variables @tomdchi. I made the change you suggested but it didn't change what was happening. I created the hook using example.php as the base. In desperation I recreated the hook using the other sample in the hook directory (vatnumbervalidation.php) as the base. The blank screen problem is no longer happening. I haven't got the time to work out why I was getting blank screens particularly as it isn't happening anymore. But... the hook isn't working, invoicenum is not being updated. I copied the SQL and used it in phpMyAdmin and it worked there. Is there something else that I haven't done? add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number"); function custom_invoice_number($vars) { $invoiceid = $vars['invoiceid']; // generate invoice number and save $customnumber = date("Ym") . $invoiceid; // = 201004312 mysql_query ("UPDATE tblinvoices SET invoicenum='$customnumber' WHERE id='$invoiceid'"); // check $d = array(); $q = mysql_query("SELECT id, invoicenum FROM tblinvoices WHERE id='$invoiceid' LIMIT 1"); while ($row = mysql_fetch_array($q)) { if ($row['invoicenum'] == '') { $d['message'] = 'no invoicenumber stored'; } else { $d['id'] = $row['id']; $d['invoicenum'] = $row['invoicenum']; } } // make response // standard response construction #echo "a=fuffig;b=faffig;c=lalala"; echo 'id=' . $d['id'] . ';invoicenum=' . $d['invoicenum']; } When exactly in the process does this action occur? 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.