kangzj Posted May 31, 2010 Share Posted May 31, 2010 I wrote a module to integrate with my application, but it seems that the module didnot return successful value. The module I wrote is listed below. Many thanks if anyone can help to point out which part is wrong. <?php /*function stppp_ConfigOptions() { # Should return an array of the module options for each product - maximum of 24 $configarray = array( "Username" => array( "Type" => "text", "Size" => "25", ), "Password" => array( "Type" => "text", "Size" => "25", ), ); return $configarray; }*/ function stppp_CreateAccount($params) { # ** The variables listed below are passed into all module functions ** $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database $pid = $params["pid"]; # Product/Service ID $producttype = $params["producttype"]; # Product Type: hostingaccount, reselleraccount, server or other $domain = $params["domain"]; $username = $params["username"]; $password = $params["password"]; $clientsdetails = $params["clientsdetails"]; # Array of clients details - firstname, lastname, email, country, etc... $customfields = $params["customfields"]; # Array of custom field values for the product $configoptions = $params["configoptions"]; # Array of configurable option values for the product # Product module option settings from ConfigOptions array above $configoption1 = $params["configoption1"]; $configoption2 = $params["configoption2"]; $configoption3 = $params["configoption3"]; $configoption4 = $params["configoption4"]; # Additional variables if the product/service is linked to a server $server = $params["server"]; # True if linked to a server $serverid = $params["serverid"]; $serverip = $params["serverip"]; $serverusername = $params["serverusername"]; $serverpassword = $params["serverpassword"]; $serveraccesshash = $params["serveraccesshash"]; $serversecure = $params["serversecure"]; # If set, SSL Mode is enabled in the server config # Code to perform action goes here... $successful=TRUE; $link = mysql_connect('localhost', 'user', '***'); mysql_select_db('database'); //用户 $sql = "INSERT INTO `database`.`radcheck` ( `id` , `UserName` , `Attribute` , `op` , `Value` ) VALUES ( NULL , '$username', 'User-Password', ':=', '$password')"; mysql_query($sql); //用户组 $sql="INSERT INTO `database`.`usergroup` ( `id` , `UserName` , `GroupName` , `priority` ) VALUES ( NULL , '$username', 'users', '1' )"; mysql_query($sql); mysql_close($link); if ($successful) { $result = "success"; } else { $result = "failed..."; } return $result; } function stppp_TerminateAccount($params) { $username = $params["username"]; $password = $params["password"]; # Code to perform action goes here... $successful=TRUE; $link = mysql_connect('localhost', 'vpn', 'eaAzTnAvdSaFRnsj'); mysql_select_db('database'); $sql = "DELETE FROM `database`.`radcheck` WHERE `radcheck`.`UserName` ='$username' LIMIT 1"; mysql_query($sql); $sql = "DELETE FROM `database`.`usergroup` WHERE `usergroup`.`UserName` ='$username' LIMIT 1"; mysql_query($sql); mysql_close($link); if ($successful) { $result = "success"; } else { $result = "failed..."; } return $result; } function stppp_SuspendAccount($params) { # Code to perform action goes here... $successful=TRUE; stppp_TerminateAccount($params); if ($successful) { $result = "success"; } else { $result = "failed..."; } return $result; } function stppp_UnsuspendAccount($params) { # Code to perform action goes here... $successful=TRUE; stppp_CreateAccount($params); if ($successful) { $result = "success"; } else { $result = "failed..."; } return $result; } //This function returns the right value. function stppp_ChangePassword($params) { $username = $params["username"]; $password = $params["password"]; # Code to perform action goes here... $successful=TRUE; $link = mysql_connect('localhost', 'user', '***'); mysql_select_db('database'); $sql = "UPDATE `database`.`radcheck` SET `Value` = '$password' WHERE `radcheck`.`UserName` ='$username' LIMIT 1"; mysql_query($sql); mysql_close($link); if ($successful) { $result = "success"; } else { $result = "failed..."; } return $result; } ?> 0 Quote Link to comment Share on other sites More sharing options...
rdavis Posted May 31, 2010 Share Posted May 31, 2010 We know someone who could help should he have time, his email is sales@logicsurge.com. He got our code fixed up quick. 0 Quote Link to comment Share on other sites More sharing options...
kangzj Posted June 1, 2010 Author Share Posted June 1, 2010 We know someone who could help should he have time, his email is sales@logicsurge.com. He got our code fixed up quick. Thanks. I'll try to contact him. 0 Quote Link to comment Share on other sites More sharing options...
logicsurge Posted June 1, 2010 Share Posted June 1, 2010 Hey, i'm the one Robert mentioned above. If the database you are connecting to is the same as WHMCS, you don't need to open or close the connection. If it is different, you must re-open the connection to the WHMCS database when you are done. Try that and tell me what happens. 0 Quote Link to comment Share on other sites More sharing options...
kangzj Posted June 1, 2010 Author Share Posted June 1, 2010 Hey, i'm the one Robert mentioned above. If the database you are connecting to is the same as WHMCS, you don't need to open or close the connection. If it is different, you must re-open the connection to the WHMCS database when you are done. Try that and tell me what happens. Thanks. The database i use was not the same as whmcs. In fact, it was the database of my app that i want to integrate with. Any other suggestions? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
kangzj Posted June 1, 2010 Author Share Posted June 1, 2010 How to re-open the connection to the WHMCS database please? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
Hutts Posted June 1, 2010 Share Posted June 1, 2010 I just installed WHMCS and created a module and had a little bit of problems with the module at first. One thing I learned and noticed in your code, except for ConfigOptions, return must be TRUE if it was successful and return should be an error message if it was not. 0 Quote Link to comment Share on other sites More sharing options...
kangzj Posted June 2, 2010 Author Share Posted June 2, 2010 I just installed WHMCS and created a module and had a little bit of problems with the module at first. One thing I learned and noticed in your code, except for ConfigOptions, return must be TRUE if it was successful and return should be an error message if it was not. The example from whmcs returns "success" but not TRUE. Which would be the right one? 0 Quote Link to comment Share on other sites More sharing options...
logicsurge Posted June 2, 2010 Share Posted June 2, 2010 No, that is not correct. A server module should return the string "success" if it worked, and a string with the error message if it failed. 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.