Jump to content

A WHMCS Module Creation Question


kangzj

Recommended Posts

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;
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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