require('./conf/config.php');
/********************************************************************************
*
* addService($idService)
* selectService($idService)
* delService($idService)
* addCMDService($idService, $command)
* selectCMDService($idService)
* delCMDService($idService, $command)
*
*
*
********************************************************************************/
function addService($idService) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//Add service
$sql = "INSERT INTO SERVICE VALUE('$idService');";
if (mysql_query($sql, $link)) {
$buffer = 1 ;
} else {
$buffer = "CREATE SERVICE $idService: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
function selectService($idService) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if (empty($idService)) {
$sql = "SELECT * FROM SERVICE";
}else{
$sql = "SELECT * FROM SERVICE WHERE idService='$idService'; ";
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT SERVICE $idService: [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delService($idService) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//del service from SERVICEUSER
$sql = "DELETE FROM SERVICEUSER WHERE idService = '$idService';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE SERVICE $idService FROM TABLE SERVICEUSER: [OK]
";
} else {
$buffer = "DELETE SERVICE $idService FROM TABLE SERVICEUSER: [FAILED] :" . mysql_error() ;
return $buffer;
}
//del service from SERVICESWITCH
$sql = "DELETE FROM SERVICESWITCH WHERE idService='$idService' ;";
if (mysql_query($sql, $link)) {
$buffer = 1 ;
}else{
$buffer = "DELETE SERVICE $idService FROM TABLE SERVICESWITCH : [FAILED] :" . mysql_error() ;
return $buffer ;
}
//del service from CMDSERVICE
$sql = "DELETE FROM CMDSERVICE WHERE idService = '$idService';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE SERVICE $idService FROM TABLE CMDSERVICE: [OK]
";
} else {
$buffer = "DELETE SERVICE $idService FROM TABLE CMDSERVICE: [FAILED] :" . mysql_error() ;
return $buffer;
}
//del service
$sql = "DELETE FROM SERVICE WHERE idService='$idService';";
if (mysql_query($sql, $link)) {
$buffer = "DELETE SERVICE $idService: [OK]
";
} else {
$buffer = "DELETE SERVICE $idService: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
function addCMDService($idService, $command) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//Add command (right) for service
$sql = "INSERT INTO CMDSERVICE VALUE('$command', '$idService');";
if (mysql_query($sql, $link)) {
$buffer =1;
} else {
$buffer = "ADD COMMAND $command FOR SERVICE $idService: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
function selectCMDService($idService, $idPower) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if (empty($idService) && empty($idPower) ) {
$sql = "SELECT * FROM CMDSERVICE";
}else{
if ( !empty($idService) && empty($idPower) ) {
$sql = "SELECT * FROM CMDSERVICE WHERE idService='$idService'; ";
}else{
if ( empty($idService) && !empty($idPower) ) {
$sql = "SELECT * FROM CMDSERVICE WHERE idPower='$idPower'; ";
}else{
$sql = "SELECT * FROM CMDSERVICE WHERE idService='$idService' AND idPower='$idPower'; ";
}
}
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT SERVICE $idService: [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delCMDService($idService, $command) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//del command (right) for service
$sql = "DELETE FROM CMDSERVICE WHERE idService='$idService'
AND idPower='$command';";
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "DELETE COMMAND $command FOR SERVICE $idService: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
?>