convert eventdetail function to php file

This commit is contained in:
Andrew Bauer 2020-09-18 11:03:20 -05:00
parent 2757b74957
commit 467e75a11c
4 changed files with 99 additions and 102 deletions

View File

@ -8,24 +8,16 @@ if ( empty($_REQUEST['modal']) ) {
$modal = validJsStr($_REQUEST['modal']); $modal = validJsStr($_REQUEST['modal']);
$data = array(); $data = array();
switch ( $modal ) { ZM\Logger::Debug("Including modals/$modal.php");
case 'eventdetail' : # Shouldn't be necessary but at the moment we have last .conf file contents
$eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : ''; ob_start();
$eids = isset($_REQUEST['eids']) ? $_REQUEST['eids'] : ''; @$result = include('modals/'.$modal.'.php');
$data['html'] = getEventDetailHTML($eid, $eids); $data['html'] = ob_get_contents();
break; ob_end_clean();
default : if ( !$result ) {
ZM\Logger::Debug("Including modals/$modal.php");
# Shouldn't be necessary but at the moment we have last .conf file contents
ob_start();
@$result = include('modals/'.$modal.'.php');
$data['html'] = ob_get_contents();
ob_end_clean();
if ( !$result ) {
ajaxError("Unknown modal '".$modal."'"); ajaxError("Unknown modal '".$modal."'");
return; return;
} }
} # end switch $modal
ajaxResponse($data); ajaxResponse($data);
return; return;

View File

@ -0,0 +1,89 @@
<?php
// This is the HTML representing the Event Detail modal on the Events page
$eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : '';
$eids = isset($_REQUEST['eids']) ? $_REQUEST['eids'] : '';
$result = '';
$inputs = '';
$disabled = 'disabled="disabled"';
$null = '';
if ( !canEdit('Events') ) return;
if ( $eid ){ // Single Event Mode
$eid = validInt($eid);
$title = translate('Event').' '.$eid.PHP_EOL;
$inputs .= '<input type="hidden" name="markEids[]" value="' .$eid. '"/>';
$newEvent = dbFetchOne('SELECT E.* FROM Events AS E WHERE E.Id = ?', NULL, array($eid));
} elseif ( $eids ) { // Multi Event Mode
$title = translate('Events');
$sql = 'SELECT E.* FROM Events AS E WHERE ';
$sqlWhere = array();
$sqlValues = array();
foreach ( $eids as $eid ) {
$eid = validInt($eid);
$inputs .= '<input type="hidden" name="markEids[]" value="' .$eid. '"/>';
$sqlWhere[] = 'E.Id = ?';
$sqlValues[] = $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');
}
?>
<div class="modal fade" id="eventDetailModal" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php echo $title ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form name="contentForm" id="eventDetailForm" method="post" action="?view=eventdetail&action=eventdetail">
<?php
// We have to manually insert the csrf key into the form when using a modal generated via ajax call
echo getCSRFinputHTML();
echo $inputs;
?>
<input type="hidden" name="action" value="eventdetail"/>
<input type="hidden" name="view" value="eventdetail"/>
<table class="table-sm">
<tbody>
<tr>
<th scope="row"><?php echo translate('Cause') ?></th>
<td><input type="text" name="newEvent[Cause]" value="<?php echo validHtmlStr($newEvent['Cause']) ?>" size="32"/></td>
</tr>
<tr>
<th scope="row" class="align-middle"><?php echo translate('Notes') ?></th>
<td><textarea name="newEvent[Notes]" rows="6" cols="33"><?php echo validHtmlStr($newEvent['Notes']) ?></textarea></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="submit" name="action" id="eventDetailSaveBtn" class="btn btn-primary" value="save" <?php echo !canEdit('Events') ? $disabled : $null .'>'. translate('Save') ?></button>
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
</div>
</form>
</div>
</div>
</div>

View File

@ -815,90 +815,6 @@ function getStatsTableHTML($eid, $fid, $row='') {
return $result; return $result;
} }
function getEventDetailHTML($eid='', $eids='') {
$result = '';
$inputs = '';
$disabled = 'disabled="disabled"';
$null = '';
if ( !canEdit('Events') ) return;
if ( $eid ){ // Single Event Mode
$eid = validInt($eid);
$title = translate('Event').' '.$eid.PHP_EOL;
$inputs .= '<input type="hidden" name="markEids[]" value="' .$eid. '"/>'.PHP_EOL;
$newEvent = dbFetchOne('SELECT E.* FROM Events AS E WHERE E.Id = ?', NULL, array($eid));
} elseif ( $eids ) { // Multi Event Mode
$title = translate('Events');
$sql = 'SELECT E.* FROM Events AS E WHERE ';
$sqlWhere = array();
$sqlValues = array();
foreach ( $eids as $eid ) {
$eid = validInt($eid);
$inputs .= '<input type="hidden" name="markEids[]" value="' .$eid. '"/>'.PHP_EOL;
$sqlWhere[] = 'E.Id = ?';
$sqlValues[] = $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 .= '<div class="modal fade" id="eventDetailModal" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">'.PHP_EOL;
$result .= '<div class="modal-dialog">'.PHP_EOL;
$result .= '<div class="modal-content">'.PHP_EOL;
$result .= '<div class="modal-header">'.PHP_EOL;
$result .= '<h5 class="modal-title">' .$title. '</h5>'.PHP_EOL;
$result .= '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'.PHP_EOL;
$result .= '<span aria-hidden="true">&times;</span>'.PHP_EOL;
$result .= '</button>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '<div class="modal-body">'.PHP_EOL;
$result .= '<form name="contentForm" id="eventDetailForm" method="post" action="?view=eventdetail&action=eventdetail">'.PHP_EOL;
// We have to manually insert the csrf key into the form when using a modal generated via ajax call
$result .= getCSRFinputHTML();
$result .= '<input type="hidden" name="action" value="eventdetail"/>'.PHP_EOL;
$result .= '<input type="hidden" name="view" value="eventdetail"/>'.PHP_EOL;
$result .= $inputs;
$result .= '<table class="table-sm">'.PHP_EOL;
$result .= '<tbody>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('Cause'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newEvent[Cause]" value="' .validHtmlStr($newEvent['Cause']). '" size="32"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row" class="align-middle">' .translate('Notes'). '</th>'.PHP_EOL;
$result .= '<td><textarea name="newEvent[Notes]" rows="6" cols="33">' .validHtmlStr($newEvent['Notes']). '</textarea></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '</tbody>'.PHP_EOL;
$result .= '</table>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '<div class="modal-footer">'.PHP_EOL;
$result .= '<button type="submit" name="action" id="eventDetailSaveBtn" class="btn btn-primary" value="save" ' .( !canEdit('Events') ? $disabled : $null ). '>' .translate('Save'). '</button>'.PHP_EOL;
$result .= '<button type="button" class="btn btn-secondary" data-dismiss="modal">' .translate('Cancel'). '</button>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '</form>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
return $result;
}
// Use this function to manually insert the csrf key into the form when using a modal generated via ajax call // Use this function to manually insert the csrf key into the form when using a modal generated via ajax call
function getCSRFinputHTML() { function getCSRFinputHTML() {
if ( isset($GLOBALS['csrf']['key']) ) { if ( isset($GLOBALS['csrf']['key']) ) {