Actualizar la asignación de permisos
Some checks are pending
Deploy Pruebas / deploy (push) Waiting to run
Some checks are pending
Deploy Pruebas / deploy (push) Waiting to run
This commit is contained in:
@@ -1,36 +1,69 @@
|
||||
<?php
|
||||
$ruta = "../";
|
||||
require_once "../include/bd_pdo.php";
|
||||
global $db;
|
||||
if(isset($_POST['lectura']))
|
||||
$ver = $_POST['lectura'];
|
||||
if(isset($_POST['editar']))
|
||||
$editar = $_POST['editar'];
|
||||
foreach($editar as $edit){
|
||||
$edit_separado = explode("_", $edit);
|
||||
$completo[]=$edit_separado;
|
||||
$ruta = "../";
|
||||
require_once "../include/bd_pdo.php";
|
||||
global $db, $pdo;
|
||||
|
||||
try {
|
||||
// Begin transaction
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Initialize arrays
|
||||
$ver = $_POST['lectura'] ?? [];
|
||||
$editar = $_POST['editar'] ?? [];
|
||||
|
||||
// Only proceed if $ver and $editar are not empty
|
||||
if (empty($ver) && empty($editar)) {
|
||||
throw new Exception("Both arrays are empty.");
|
||||
}
|
||||
|
||||
$completo = [];
|
||||
|
||||
// Process $editar array
|
||||
foreach ($editar as $edit) {
|
||||
$edit_separado = explode("_", $edit);
|
||||
$completo[] = $edit_separado;
|
||||
}
|
||||
|
||||
// Call the function to delete all permissions
|
||||
$db->query("SELECT fd_permiso()");
|
||||
foreach($ver as $lectura){
|
||||
$igual=false;
|
||||
|
||||
// Process $ver array and merge with $completo
|
||||
foreach ($ver as $lectura) {
|
||||
$igual = false;
|
||||
$ver_separado = explode("_", $lectura);
|
||||
foreach($completo as $comp){
|
||||
if($ver_separado[0] == $comp[0] && $ver_separado[1] == $comp[1]){
|
||||
$igual=true;
|
||||
foreach ($completo as $comp) {
|
||||
if ($ver_separado[0] == $comp[0] && $ver_separado[1] == $comp[1]) {
|
||||
$igual = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$igual)
|
||||
$completo[]=$ver_separado;
|
||||
if (!$igual) {
|
||||
$completo[] = $ver_separado;
|
||||
}
|
||||
}
|
||||
foreach($completo as $actual){
|
||||
|
||||
// Insert the combined data into the 'permiso' table
|
||||
foreach ($completo as $actual) {
|
||||
$db->insert('permiso', [
|
||||
'pagina_id' => $actual['0'],
|
||||
'rol_id' => $actual['1'],
|
||||
'permiso_tipo' => $actual['2'],
|
||||
'pagina_id' => $actual[0],
|
||||
'rol_id' => $actual[1],
|
||||
'permiso_tipo' => $actual[2],
|
||||
]);
|
||||
}
|
||||
|
||||
// Commit the transaction
|
||||
$db->commit();
|
||||
|
||||
// Redirect to permisos.php
|
||||
header("Location: ../permisos.php");
|
||||
exit();
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Rollback the transaction on error
|
||||
$pdo->rollback();
|
||||
|
||||
// Handle the error (for example, log it or show an error message)
|
||||
echo "An error occurred: " . $e->getMessage();
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user