version mise à jour par claude , à tester

This commit is contained in:
Arthur Ria
2026-05-20 09:38:07 +02:00
commit b59cbb3546
58 changed files with 24548 additions and 0 deletions
+228
View File
@@ -0,0 +1,228 @@
<?php
session_start();
if(!isset($_SESSION['token']))
{
echo "logout";
exit();
}
// -- TOKEN REFRESH -- //
function token_refresh()
{
$delta = time() - $_SESSION['token_start_time'];
if ($delta > 1000) // SI DELTA OK POUR REFRESH, REFRESH SINON DEMANDER NOUVEAU TOKEN ET RECOPIER DANS INDEX.PHP !!!!!!!!!!!!!!!!!!
{
$ch = curl_init();
if($delta < 1190)
$post_data="grant_type=refresh_token&refresh_token=".$_SESSION['refresh_token'];
else
$post_data="grant_type=password&tenant_code=".$_SESSION['tenant']."&username=".$_SESSION['user']."&password=".$_SESSION['pass'];
curl_setopt($ch, CURLOPT_URL, "https://".$_SESSION['ip']."/EasySTS/OAuth/Token");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded' , 'Authorization: Basic R05BOklFNGU3aXFoZHQ='));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$data = curl_exec($ch);
$tab = json_decode($data, true);
if(!empty($tab))
{
if(isset($tab["refresh_token"]))
{
$refresh_token = $tab["refresh_token"];
$token = $tab["access_token"];
}
else
{
if ( ($tab["error"] == "") or empty($tab["error"]) )
$error = "inconnue";
else
$error = $tab["error"];
header('Location: login.php?fail=true&desc='.urlencode($error));
exit();
}
if(!empty($refresh_token))
{
$_SESSION['refresh_token'] = $refresh_token;
$_SESSION['token'] = $token;
$_SESSION['token_start_time'] = time();
}
}
}
}
// --- DELETE --- //
$ch = curl_init();
if ($_GET["delete"] == "true") {
$action = $_GET['action'];
//sleep(2);
// Préparation query
$type = $_GET['type'];
if ($type == "Containers") {
$component = "ComponentId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.ContainerRemoveCommand";
}
if ($type == "Stocks") {
$component = "StockId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Contracts.Commands.StockRemoveCommand";
}
if ($type == "ProductLocations") {
$component = "ProductLocationId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Expeditions.Contracts.Commands.ProductLocationRemoveCommand";
}
if ($type== "Tasks") {
$component = "TaskId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Contracts.Commands.TaskRemoveCommand";
}
if ($type== "Products") {
$component = "ProductId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.ProductRemoveCommand";
}
if ($type== "Accounts") {
$component = "AccountId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.AccountRemoveCommand";
}
if ($type== "Suppliers") {
$component = "SupplierId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.SupplierRemoveCommand";
}
if ($type== "Kits") {
$component = "KitId";
if($action == 1)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.KitDeleteCommand";
if($action == 5)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.KitDisableCommand";
}
if ($type== "Aliases") {
$component = "AliasId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.MasterData.Contracts.Commands.AliasRemoveCommand";
}
if ($type== "InboundOrders") {
$component = "InboundOrderId";
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Receptions.Contracts.Commands.InboundOrderCancelCommandV2";
}
if ($type== "Receptions") {
$component = "ReceptionId";
if($action == 1)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Receptions.Contracts.Commands.ReceptionCancelCommandV2";
if($action == 2)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Receptions.Contracts.Commands.ReceptionClosingCommandV2";
if($action == 3)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Receptions.Contracts.Commands.ReceptionRemoveCommand";
}
if ($type== "OutboundOrders") {
$component = "OutboundOrderId";
if($action == 1)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Expeditions.Contracts.Commands.OutboundOrderCancelCommand";
if($action == 2)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Expeditions.Contracts.Commands.OutboundOrderForceCloseCommand";
if($action == 3)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Expeditions.Contracts.Commands.OutboundOrderArchiveCommand";
if($action == 4)
$cmd_name = "Mecalux.ITSW.EasyWMS.Modules.Expeditions.Contracts.Commands.OutboundOrderUnsetCurrentOperationCommand";
}
// Récupérer id
$query = '{
"Application": "EasyWMS",
"QueryType": 1,
"Expression" : "Context.'.$type.'.Select(z => z.Id)"
}';
token_refresh();
curl_setopt($ch, CURLOPT_URL, "https://".$_SESSION['ip']."/ApplicationService/api/QueryExecute"
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . $_SESSION["token"],
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$data = curl_exec($ch);
$tab_data = json_decode($data, true);
// echo($tab_data['Table']['Rows'][0]['Values']['Column']);
// Commande Delete en boucle
curl_setopt(
$ch, CURLOPT_URL, "https://".$_SESSION['ip']."/ApplicationService/api/CommandExecute"
);
token_refresh();
foreach ($tab_data["Table"]["Rows"] as $key => $value) {
//echo $value["Values"]["Column"]."<br>";
$cmd_delete =
'[{
"Name": "'.$cmd_name.', Mecalux.ITSW.EasyWMS.Modules.Contracts",
"Properties": {
"'.$component.'": "' .
$value["Values"]["Column"] .
'",
"ForceDeletionOfEmptyHolderContainer": true
}
}]';
//echo "value : ".$value["Values"]["Column"];
curl_setopt($ch, CURLOPT_POSTFIELDS, $cmd_delete);
$data_delete = curl_exec($ch);
$logs[] = $data_delete;
if($logs)
{
foreach ($logs as $key => $value) {
$pos1 = strpos($logs[$key], '"Message":"');
$msg = $logs[$key];
if (!empty($pos1))
{
$msg = substr($logs[$key], $pos1+11);
$pos2 = strpos($msg, '","');
$msg = substr($msg, 0, $pos2)."\n";
echo $msg;
}
}
echo($erreurs);
}
}
}
?>