From 4a149588ffa974654a5d865f4282f2b207fe79a2 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Tue, 28 Aug 2018 15:54:29 +0200 Subject: [PATCH] Fix composer.json --- ajax.php | 27 +++++++++++++++++++++++++++ call.php | 22 ---------------------- composer.json | 2 +- editor.php | 8 ++++---- 4 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 call.php diff --git a/ajax.php b/ajax.php index 1fc710b05..0c0d8eb86 100644 --- a/ajax.php +++ b/ajax.php @@ -55,4 +55,31 @@ switch (get('op')) { echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'" )}'; break; + + case 'active_users': + $posizione = get('id_module'); + if (isset($id_record)) { + $posizione .= ', '.get('id_record'); + } + + $user = Auth::user(); + $interval = setting('Timeout notifica di presenza (minuti)') * 60 * 2; + + $dbo->query('UPDATE zz_semaphores SET updated = NOW() WHERE id_utente = :user_id AND posizione = :position', [ + ':user_id' => $user['id'], + ':position' => $posizione, + ]); + + // Rimozione record scaduti + $dbo->query('DELETE FROM zz_semaphores WHERE DATE_ADD(updated, INTERVAL :interval SECOND) <= NOW()', [ + ':interval' => $interval, + ]); + + $datas = $dbo->fetchArray('SELECT DISTINCT username FROM zz_semaphores INNER JOIN zz_users ON zz_semaphores.id_utente=zz_users.id WHERE zz_semaphores.id_utente != :user_id AND posizione = :position', [ + ':user_id' => $user['id'], + ':position' => $posizione, + ]); + + echo json_encode($datas); + break; } diff --git a/call.php b/call.php deleted file mode 100644 index ea93f917f..000000000 --- a/call.php +++ /dev/null @@ -1,22 +0,0 @@ -query('UPDATE zz_semaphores SET updated = NOW() WHERE id_utente = '.prepare(Auth::user()['id']).' AND posizione = '.prepare($posizione)); -$dbo->query('DELETE FROM zz_semaphores WHERE DATE_ADD(updated, INTERVAL '.(setting('Timeout notifica di presenza (minuti)') * 2).' SECOND) <= NOW()'); - -$datas = $dbo->fetchArray('SELECT DISTINCT username FROM zz_semaphores INNER JOIN zz_users ON zz_semaphores.id_utente=zz_users.id WHERE zz_semaphores.id_utente != '.prepare(Auth::user()['id']).' AND posizione = '.prepare($posizione)); - -$result = []; -foreach ($datas as $data) { - $result[] = [ - 'username' => $data['username'], - ]; -} - -echo json_encode($result); diff --git a/composer.json b/composer.json index 2e3a81fbc..b0e34407c 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "Modules\\Fatture\\Custom\\": "modules/fatture/custom/src", "Modules\\Anagrafiche\\": "modules/anagrafiche/src", "Modules\\Anagrafiche\\Custom\\": "modules/anagrafiche/custom/src", - "Plugins\\Fatturazione\\": "plugins/fatturazione/src" + "Plugins\\Fatturazione\\": "plugins/fatturazione/src", "Plugins\\Fatturazione\\Custom\\": "plugins/fatturazione/custom/src" }, "files": [ diff --git a/editor.php b/editor.php index 50d16b6d1..00cfeb0a6 100755 --- a/editor.php +++ b/editor.php @@ -17,7 +17,7 @@ include_once $docroot.'/actions.php'; echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top", "place": "editor" )}'; $advanced_sessions = setting('Attiva notifica di presenza utenti sul record'); -if ($advanced_sessions) { +if (!empty($advanced_sessions)) { $dbo->query('DELETE FROM zz_semaphores WHERE id_utente='.prepare(Auth::user()['id']).' AND posizione='.prepare($id_module.', '.$id_record)); $dbo->query('INSERT INTO zz_semaphores (id_utente, posizione, updated) VALUES ('.prepare(Auth::user()['id']).', '.prepare($id_module.', '.$id_record).', NOW())'); @@ -350,11 +350,11 @@ if ($read_only || !empty($block_edit)) { function getActiveUsers(){ - $.getJSON('/call.php', { + $.getJSON('/ajax.php?op=active_users', { id_module: , id_record: }, @@ -372,7 +372,7 @@ if ($advanced_sessions) { getActiveUsers(); - setInterval(getActiveUsers, ); + setInterval(getActiveUsers, );