Jump to content

Arrays don't seem to be returning anything


1337ts

Recommended Posts

I'm relatively new to php coding, so bear with me.

 

I'm trying to code a module that will simply execute a function from a class that i've included into the module file. When I try to execute the function, it returns an error. This error is resulting from it not being given the correct variables by WHMCS I believe. Here is the code I have

 

function teamspeak_SuspendAccount($params) {

# Code to perform action goes here...
$ts=new tsac();
$ts->connect("$serverip",51234,"$serverusername","$serverpassword");
$ts->stopserver($customfields[port]);
   if ($successful) {
	$result = "success";
} else {
	$result = "failed";
}
return $result;

 

If I change $result = "failed" to $result = $ts->error it will return the error normally. The error suggests that the port number provided in the function argument is invalid, or nonexistent.

If I change the output of another function called by WHMCS, teamspeak_LoginLink($params) to "echo print_r($customfields)" where WHMCS would normally show a cPanel link, or something similar, it has only a 1(the number 1, and no other text) It's not being turnicated by the page itself; I checked the source and could not find the word "array" anywhere, something that's typically in the print_f of an array.

Now, for the real kicker: If I change $result = "failed" to $result = print_r($customfields) WHMCS says "Module Command Success

Service Suspended Successfully" but the actual script was not executed properly as if it had been, the TS server would be offline.

 

I'm lead to believe that the issue lies in using the correct variables and arrays, but I can't find anything to explain (in more detail than the readme pdf that came with the devkit) exactly how you would go about using any of these. For example, the description in the template says

"$customfields = $params["customfields"]; # Array of custom field values for the product"

That doesn't tell me how to get the items out of the array. How am I to know what keys to use to select the data contained in the array? Are the keys numerical? the name of the field? something from the database?

 

 

On another note, I need some sort of way to have WHMCS automatically assign the value of this field (the port of the client's server.) I need it to be able to pull from a list of available ports that I provide it, autofill the field with the port, then remove it from the list. Upon deletion of the account, it would need to reintroduce the port number into the list.

 

I've tried to set this up by making a mysql database table for a serverlist. The table contains 3 columns, port hostingid and host. Host is to be implemented later in the event that I get more than one server. The mysql query, before creating a server, is supposed to look in a table and find a port number by searching for a hostingid of zero, with a limit of 1. A hostingid of zero would mean that it's unassigned. It's then supposed to write to my table the hostingid of the client, then write to the WHMCS tblcustomfieldsvalues to update the port number. Unfortunately, with no way to pass the port number to anything, having such a setup is useless. Additionally, I'd like to avoid it as it would keep record keeping far more complicated.

Any advice on that would be much appreciated.

 

Is there any way to test my code and debug it within WHMCS? It seems like the modifications I'm making are very hard to troubleshoot as there's no page I can go to to repeatedly test the function and see the resulting error messages.

Edited by 1337ts
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