function fusionne($afus) { global $l; $i = 0; $maxStamp = 0; $minStamp = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); //demain foreach ($afus as $a) { $d = $a["lastcome"]; $a["stamp"] = mktime($d[11] . $d[12], $d[14] . $d[15], $d[17] . $d[18], $d[5] . $d[6], $d[8] . $d[9], $d[0] . $d[1] . $d[2] . $d[3]); //echo "stamp:".$a["stamp"]."== mktime($d[11]$d[12],$d[14]$d[15],$d[17]$d[18],$d[5]$d[6],$d[8]$d[9],$d[0]$d[1]$d[2]$d[3]);<br>"; if ($maxStamp < $a["stamp"]) { $maxStamp = $a["stamp"]; $maxInd = $i; } if ($minStamp > $a["stamp"]) { $minStamp = $a["stamp"]; $minInd = $i; } $i++; } if ($afus[$minInd]["deviceid"] != "") { $okLock = true; foreach ($afus as $a) { if (!($okLock = $okLock && lock($a["id"]))) { break; } else { $locked[] = $a["id"]; } } if ($okLock) { //TRACE_DELETED if (mysqli_num_rows(mysql2_query_secure("SELECT * FROM config WHERE IVALUE>0 AND NAME='TRACE_DELETED'", $_SESSION['OCS']["readServer"]))) { foreach ($afus as $a) { if ($afus[$maxInd]["deviceid"] == $a["deviceid"]) { continue; } $sql = "insert into deleted_equiv(DELETED,EQUIVALENT) values('%s','%s')"; $arg = array($a["deviceid"], $afus[$maxInd]["deviceid"]); mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg); } } //KEEP OLD QUALITY,FIDELITY AND CHECKSUM $sql = "SELECT CHECKSUM,QUALITY,FIDELITY FROM hardware WHERE ID='%s'"; $persistent_req = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $afus[$minInd]["id"]); $reqDelAccount = "DELETE FROM accountinfo WHERE hardware_id='%s'"; mysql2_query_secure($reqDelAccount, $_SESSION['OCS']["writeServer"], $afus[$maxInd]["id"]); msg_success($l->g(190) . " " . $afus[$maxInd]["deviceid"] . " " . $l->g(191)); $keep = array("accountinfo", "devices", "groups_cache"); foreach ($keep as $tableToBeKept) { $reqRecupAccount = "UPDATE %s SET hardware_id='%s' WHERE hardware_id='%s'"; $argRecupAccount = array($tableToBeKept, $afus[$maxInd]["id"], $afus[$minInd]["id"]); mysql2_query_secure($reqRecupAccount, $_SESSION['OCS']["writeServer"], $argRecupAccount); } msg_success($l->g(190) . " " . $afus[$minInd]["deviceid"] . " " . $l->g(206) . " " . $afus[$maxInd]["deviceid"]); $i = 0; foreach ($afus as $a) { if ($i != $maxInd) { deleteDid($a["id"], false, false, false); $lesDel .= $a["deviceid"] . "/"; } $i++; } //RESTORE PERSISTENT VALUES $persistent_values = mysqli_fetch_row($persistent_req); $sql = "UPDATE hardware SET QUALITY=%s,FIDELITY=%s,CHECKSUM=CHECKSUM|%s WHERE id='%s'"; $arg = array($persistent_values[1], $persistent_values[2], $persistent_values[0], $afus[$maxInd]["id"]); mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg); } else { errlock(); } foreach ($locked as $a) { unlock($a); } } $lesDel .= " => " . $afus[$maxInd]["deviceid"]; AddLog("FUSION", $lesDel); }
/** * Deleting function * @param id Hardware identifier to be deleted * @param checkLock Tells wether or not the locking system must be used (default true) * @param traceDel Tells wether or not the deleted entities must be inserted in deleted_equiv for tracking purpose (default true) */ function deleteDid($id, $checkLock = true, $traceDel = true, $silent = false) { global $l; //If lock is not user OR it is used and available if (!$checkLock || lock($id)) { $resId = mysql_query("SELECT deviceid,name FROM hardware WHERE id='{$id}'", $_SESSION["readServer"]) or die(mysql_error()); $valId = mysql_fetch_array($resId); $idHard = $id; $did = $valId["deviceid"]; if ($did) { //Deleting a network device if (strpos($did, "NETWORK_DEVICE-") === false) { $resNetm = @mysql_query("SELECT macaddr FROM networks WHERE hardware_id={$idHard}", $_SESSION["writeServer"]) or die(mysql_error()); while ($valNetm = mysql_fetch_array($resNetm)) { @mysql_query("DELETE FROM netmap WHERE mac='" . $valNetm["macaddr"] . "';", $_SESSION["writeServer"]) or die(mysql_error()); } } //deleting a regular computer if ($did != "_SYSTEMGROUP_" and $did != '_DOWNLOADGROUP_') { $tables = array("accesslog", "accountinfo", "bios", "controllers", "drives", "inputs", "memories", "modems", "monitors", "networks", "ports", "printers", "registry", "slots", "softwares", "sounds", "storages", "videos", "devices", "download_history", "download_servers", "groups_cache"); } elseif ($did == "_SYSTEMGROUP_" or $did == '_DOWNLOADGROUP_') { //Deleting a group $tables = array("devices"); $del_groups_server_cache = "DELETE FROM download_servers WHERE group_id='" . $idHard . "'"; mysql_query($del_groups_server_cache, $_SESSION["writeServer"]) or die(mysql_error()); mysql_query("DELETE FROM groups WHERE hardware_id={$idHard}", $_SESSION["writeServer"]) or die(mysql_error()); $resDelete = mysql_query("DELETE FROM groups_cache WHERE group_id={$idHard}", $_SESSION["writeServer"]) or die(mysql_error()); $affectedComputers = mysql_affected_rows($_SESSION["writeServer"]); } if (!$silent) { echo "deleting record " . $valId["name"] . "\n"; } foreach ($tables as $table) { mysql_query("DELETE FROM {$table} WHERE hardware_id={$idHard};", $_SESSION["writeServer"]) or die(mysql_error()); } mysql_query("delete from download_enable where SERVER_ID=" . $idHard, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"])); mysql_query("DELETE FROM hardware WHERE id={$idHard};", $_SESSION["writeServer"]) or die(mysql_error()); //Deleted computers tracking if ($traceDel && mysql_num_rows(mysql_query("SELECT IVALUE FROM config WHERE IVALUE>0 AND NAME='TRACE_DELETED'", $_SESSION["writeServer"]))) { mysql_query("insert into deleted_equiv(DELETED,EQUIVALENT) values('{$did}',NULL)", $_SESSION["writeServer"]) or die(mysql_error()); } } //Using lock ? Unlock if ($checkLock) { unlock($id); } } else { errlock(); } }