From fb85d6f79c847b8edf7908644e11f80ac2effe0e Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Mon, 14 Sep 2020 13:47:09 -0500 Subject: [PATCH] rough in eventdetail modal --- web/ajax/modal.php | 5 ++ web/skins/classic/includes/functions.php | 89 ++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/web/ajax/modal.php b/web/ajax/modal.php index 8f5cb8ac9..91d1aec08 100644 --- a/web/ajax/modal.php +++ b/web/ajax/modal.php @@ -35,6 +35,11 @@ switch ( $modal ) { if ( !isset($_REQUEST['id']) ) ajaxError('Storage Id Not Provided'); $data['html'] = getStorageModalHTML($_REQUEST['id']); break; + case 'eventdetail' : + isset($_REQUEST['eid'] ? $eid = $_REQUEST['eid'] : ''; + isset($_REQUEST['eids'] ? $eids = $_REQUEST['eids'] : ''; + $data['html'] = getEventDetailHTML($eid, $eids); + break; default : // Maybe don't need both ZM\Warning('Unknown modal '.$modal); diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 8facb1f80..d13e5545b 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -1016,6 +1016,95 @@ function getStorageModalHTML($sid) { return $result; } +function getEventDetailHTML($eid='', $eids='') { + $result = ''; + $inputs = ''; + $disabled = 'disabled="disabled"'; + $null = ''; + + if ( !canEdit('Events') ) return; + + // We have to manually insert the csrf key into the form when using a modal generated via ajax call + if ( isset($GLOBALS['csrf']['key']) ) { + $csrf_input = ''.PHP_EOL; + } else { + $csrf_input = ''; + } + + if ( isset($eid) ){ // Single Event Mode + $title = translate('Event').' '.$eid.PHP_EOL; + $inputs .= ''.PHP_EOL; + $eid = validInt($eid); + $newEvent = dbFetchOne('SELECT E.* FROM Events AS E WHERE E.Id = ?', NULL, array($eid)); + + } elseif ( isset($eids) ) { // Multi Event Mode + + $title = translate('Events'); + $sql = 'SELECT E.* FROM Events AS E WHERE '; + $sqlWhere = array(); + $sqlValues = array(); + foreach ( $eids as $eid ) { + $inputs .= ''.PHP_EOL; + $sqlWhere[] = 'E.Id = ?'; + $sqlValues[] = validInt($eid); + } + unset($eid); + $sql .= join(' OR ', $sqlWhere); + foreach( dbFetchAll( $sql, NULL, $sqlValues ) as $row ) { + if ( !isset($newEvent) ) { + $newEvent = $row; + } else { + if ( $newEvent['Cause'] && $newEvent['Cause'] != $row['Cause'] ) + $newEvent['Cause'] = ''; + if ( $newEvent['Notes'] && $newEvent['Notes'] != $row['Notes'] ) + $newEvent['Notes'] = ''; + } + } + + } else { // Event Mode not specified - should we really proceed if neither eid nor eids is set? + $title = translate('Events'); + } + + $result .= ''.PHP_EOL; + + return $result; +} + function xhtmlFooter() { global $css; global $cspNonce;