|
|
@@ -41,19 +41,17 @@ function getActiveConnections()
|
|
|
$client = new Client(new Version4X($socket_url));
|
|
|
$client->initialize();
|
|
|
|
|
|
- // Emitir evento para obtener conexiones
|
|
|
+ $arrInfoConnection = array();
|
|
|
$client->emit('get_connections', []);
|
|
|
-
|
|
|
- // Escuchar respuesta
|
|
|
- $connections = [];
|
|
|
- $client->wait('current_connections', function ($data) use (&$connections) {
|
|
|
- $connections = json_decode($data, true);
|
|
|
- });
|
|
|
+ if ($packet = $client->wait('current_connections')) {
|
|
|
+ $data = json_decode($packet->data, true);
|
|
|
+ $arrInfoConnection = $data;
|
|
|
+ }
|
|
|
|
|
|
$client->close();
|
|
|
- writeLog("Contenido raw del socket: " . json_encode($connections));
|
|
|
- writeLog("Conexiones activas obtenidas: " . count($connections) . " usuarios");
|
|
|
- return $connections;
|
|
|
+ writeLog("Contenido raw del socket: " . json_encode($arrInfoConnection));
|
|
|
+ writeLog("Conexiones activas obtenidas: " . count($arrInfoConnection) . " usuarios");
|
|
|
+ return $arrInfoConnection;
|
|
|
} catch (Exception $e) {
|
|
|
writeLog("ERROR: No se pudo conectar al socket - " . $e->getMessage());
|
|
|
return [];
|
|
|
@@ -65,14 +63,16 @@ function decryptId($encryptedId)
|
|
|
{
|
|
|
$ch = curl_init('http://192.168.2.25:8000/api/decrypt');
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['encrypted' => $encryptedId]));
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['value' => $encryptedId]));
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
$response = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
|
$result = json_decode($response, true);
|
|
|
- $decrypted = $result['decrypted'] ?? null;
|
|
|
+ writeLog("API Response: " . substr($response, 0, 100));
|
|
|
+ $decrypted = $result['response']['decrypted'] ?? null;
|
|
|
writeLog("Desencriptando ID: $encryptedId -> $decrypted");
|
|
|
+
|
|
|
return $decrypted;
|
|
|
}
|
|
|
|
|
|
@@ -80,16 +80,23 @@ function decryptId($encryptedId)
|
|
|
function selectUser($users)
|
|
|
{
|
|
|
writeLog("Seleccionando usuario de: " . implode(',', $users));
|
|
|
- $connections = getActiveConnections();
|
|
|
+ $arrInfoConnection = getActiveConnections();
|
|
|
+
|
|
|
+ $arrUsersConnected = array();
|
|
|
+ foreach ($arrInfoConnection as $userConnection) {
|
|
|
+ $data = explode('.', $userConnection);
|
|
|
+ $userConnected = decryptId($data[0]);
|
|
|
+ if ($userConnected) {
|
|
|
+ $arrUsersConnected[] = $userConnected;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- foreach ($connections as $conn) {
|
|
|
- $connParts = explode('.', $conn);
|
|
|
- $encryptedUserId = $connParts[0];
|
|
|
- $decryptedUserId = decryptId($encryptedUserId);
|
|
|
+ writeLog("Usuarios conectados: " . implode(',', $arrUsersConnected));
|
|
|
|
|
|
- if ($decryptedUserId && in_array($decryptedUserId, $users)) {
|
|
|
- writeLog("Usuario seleccionado: $decryptedUserId (conectado)");
|
|
|
- return $decryptedUserId;
|
|
|
+ foreach ($users as $user) {
|
|
|
+ if (in_array($user, $arrUsersConnected)) {
|
|
|
+ writeLog("Usuario seleccionado: $user (conectado)");
|
|
|
+ return $user;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -126,7 +133,7 @@ function emitNotinotification($module, $title, $content, $actions, $audience)
|
|
|
|
|
|
// Consulta SOVA
|
|
|
$stmt = $pdo->prepare("
|
|
|
- SELECT s.SOVA_IDSV, s.SOVA_INEX, t.TAWO_USAV
|
|
|
+ SELECT s.SOVA_IDSV, s.SOVA_INEX, t.TAWO_USAV, s.SOVA_IDET
|
|
|
FROM S002V01TSOVA s
|
|
|
JOIN S002V01TEJTW e ON s.SOVA_IDET = e.EJTW_IDET
|
|
|
JOIN S002V01TTAWO t ON e.EJTW_IDTA = t.TAWO_IDTA
|
|
|
@@ -147,7 +154,8 @@ foreach ($sovaResults as $row) {
|
|
|
[
|
|
|
['BOTON' => 'Ver todas las solicitudes', 'FUNCION' => 'getValidateApplications', 'PARAMETROS' => json_encode([$iduser, "1"]), true],
|
|
|
['BOTON' => 'Validar', 'FUNCION' => 'asignStateToApplication', 'PARAMETROS' => json_encode([$iduser, "1", $sovaData['idtask'], "Aprobada"]), true],
|
|
|
- ['BOTON' => 'Rechazar', 'FUNCION' => 'asignStateToApplication', 'PARAMETROS' => json_encode([$iduser, "1", $sovaData['idtask'], "Rechazada"]), true]
|
|
|
+ ['BOTON' => 'Rechazar', 'FUNCION' => 'asignStateToApplication', 'PARAMETROS' => json_encode([$iduser, "1", $sovaData['idtask'], "Rechazada"]), true],
|
|
|
+ ['idtask' => $row['SOVA_IDET']]
|
|
|
],
|
|
|
$iduser
|
|
|
);
|
|
|
@@ -162,7 +170,7 @@ foreach ($sovaResults as $row) {
|
|
|
}
|
|
|
|
|
|
// Consulta NOWF
|
|
|
-$stmt = $pdo->prepare("SELECT NOWF_IDNE, NOWF_INEX, NOWF_USNO FROM S002V01TNOEJ WHERE NOWF_ESTA = 'pendiente de envio'");
|
|
|
+$stmt = $pdo->prepare("SELECT NOWF_IDNE, NOWF_INEX, NOWF_USNO, NOWF_IDEJ FROM S002V01TNOEJ WHERE NOWF_ESTA = 'pendiente de envio'");
|
|
|
$stmt->execute();
|
|
|
$nowfResults = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
@@ -174,11 +182,12 @@ foreach ($nowfResults as $row) {
|
|
|
'S002V01M03GEPR',
|
|
|
"La tarea: {$nowfData['nombre_t']} secuencia {$nowfData['secuencia']} ha sido ejecutada",
|
|
|
"La tarea: {$nowfData['nombre_t']} secuencia {$nowfData['secuencia']} del workflow: {$nowfData['nombre_w']}, ha sido ejecutada.",
|
|
|
- [],
|
|
|
+ [['idtask' => $row['NOWF_IDEJ']]],
|
|
|
$usersNoti
|
|
|
);
|
|
|
|
|
|
if ($success) {
|
|
|
+
|
|
|
$updateStmt = $pdo->prepare("UPDATE S002V01TNOEJ SET NOWF_ESTA = 'Enviada' WHERE NOWF_IDNE = ?");
|
|
|
$updateStmt->execute([$row['NOWF_IDNE']]);
|
|
|
writeLog("NOWF actualizada: ID {$row['NOWF_IDNE']} - Estado: Enviada");
|