<?php

require "global.ajax.php";
// https://evopos.dev/ajax/createfolder.php/go=ruta?ent[]=1&ent[]=2&ent[]=3&ent[]=4&ent[]=5&ent[]=6

$valores = array_values($_GET);

$productAllFolder = "../files/products/all";
$userAllFolder = "../files/users/all";
if (!file_exists($productAllFolder)) {
    mkdir($productAllFolder, 0777, true);
}
if (!file_exists($userAllFolder)) {
    mkdir($userAllFolder, 0777, true);
}

foreach ($valores as $valor) {
    if (is_array($valor)) {
        foreach ($valor as $entId) {

            $ent_name = getEnterpriseData($entId)['ent_name'];
            $entName = mb_strtolower($ent_name);
            $entFolderName = str_replace("'", "_", $entName);
            $entFolderName = str_replace("`", "_", $entName);
            $entFolderName = str_replace(" ", "_", $entName);
            $productImageFolder = '../files/products/all/' . $entFolderName;
            $userImageFolder = '../files/users/all/' . $entFolderName;

            if (!file_exists($productImageFolder)) {
                mkdir($productImageFolder, 0777, true);
            }
            if (!file_exists($userImageFolder)) {
                mkdir($userImageFolder, 0777, true);
            }

            $sql = "UPDATE tb_enterprises SET ent_folder_name ='$entFolderName' WHERE ent_id='$entId'";
            echo $result = executeQueryPDO($sql, "Updated", 'ERROR');
        }
    }
}
