function addDevice($mac, $hostname, $ip, $type) {
$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 switch
$sql = "INSERT INTO DEVICE VALUE('$mac', '$hostname', '$ip', '$type');";
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "CREATE DEVICE $idSwicth: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
function selectDevice($filter) {
//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($filter)) {
$sql = "SELECT * FROM DEVICE";
}else{
$sql = "SELECT * FROM DEVICE WHERE $filter ;" ;
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT DEVICE : [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delDevice($hostname) {
$buffer = "";
//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();
}
//Before del user of Table USER, del user in all others Table
//del switch from CMDSWITCH
$sql="DELETE FROM CMDSWITCH WHERE idSwitch='$hostname';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE SWITCH $hostname FROM CMDSWITCH: [OK]
";
} else {
$buffer = "DELETE SWITCH $hostname FROM CMDSWITCH: [FAILED] :" . mysql_error() ;
return $buffer;
}
//del switch from SERVICESWITCH
$sql = "DELETE FROM SERVICESWITCH WHERE idSwitch='$hostname'";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE SWITCH $hostname FROM SERVICESWITCH: [OK]
";
} else {
$buffer = "DELETE SWITCH $hostname FROM SERVICESWITCH: [FAILED] :" . mysql_error() ;
return $buffer;
}
//del switch
$sql = "DELETE FROM SWITCH WHERE idswitch='$hostname';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE SWITCH $hostname: [OK]
";
} else {
$buffer = "DELETE SWITCH $hostname: [FAILED] :" . mysql_error() ;
return $buffer;
}
//dev Device
$sql = "DELETE FROM DEVICE WHERE hostname='$hostname';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE DEVICE $hostname: [OK]
";
} else {
$buffer = "DELETE DEVICE $hostname: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function updateDevice($hostname, $mac, $ip, $type) {
//connect DB^M
$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();
}
//update Device
$sql = "UPDATE DEVICE SET
mac='$mac',
ip='$ip',
type='$type',
hostname='$hostname'
WHERE hostname='$hostname' ;" ;
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "UPDATE DEVICE $hostname: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
?>