convert servermodal function to php file

This commit is contained in:
Andrew Bauer 2020-09-18 10:34:33 -05:00
parent a058d077bb
commit 2757b74957
4 changed files with 107 additions and 104 deletions

View File

@ -9,10 +9,6 @@ $modal = validJsStr($_REQUEST['modal']);
$data = array();
switch ( $modal ) {
case 'server' :
if ( !isset($_REQUEST['id']) ) ajaxError('Storage Id Not Provided');
$data['html'] = getServerModalHTML($_REQUEST['id']);
break;
case 'eventdetail' :
$eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : '';
$eids = isset($_REQUEST['eids']) ? $_REQUEST['eids'] : '';

105
web/ajax/modals/server.php Normal file
View File

@ -0,0 +1,105 @@
<?php
// This is the HTML representing the Server modal from Options -> Server
if ( !isset($_REQUEST['id']) ) {
ajaxError('Server Id Not Provided');
return;
}
$result = '';
$checked = ' checked="checked"';
$null = '';
$sid = $_REQUEST['id'];
if ( !canEdit('System') ) return;
$Server = new ZM\Server($sid);
if ( $sid and ! $Server->Id() ) return;
?>
<div class="modal fade" id="ServerModal" 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 translate('Server') .' - '. $Server->Name() ?></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 id="serverModalForm" name="contentForm" method="post" action="?view=server&action=save" class="validateFormOnSubmit">
<?php
// We have to manually insert the csrf key into the form when using a modal generated via ajax call
echo getCSRFinputHTML();
?>
<input type="hidden" name="view" value="server"/>
<input type="hidden" name="object" value="server"/>
<input type="hidden" name="id" value="<?php echo validHtmlStr($_REQUEST['id']) ?>"/>
<table class="table-sm">
<tbody>
<tr>
<th scope="row"><?php echo translate('Name') ?></th>
<td><input type="text" name="newServer[Name]" value="<?php echo $Server->Name() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Protocol') ?></th>
<td><input type="text" name="newServer[Protocol]" value="<?php echo $Server->Protocol() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Hostname') ?></th>
<td><input type="text" name="newServer[Hostname]" value="<?php echo $Server->Hostname() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Port') ?></th>
<td><input type="number" name="newServer[Port]" value="<?php echo $Server->Port() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('PathToIndex') ?></th>
<td><input type="text" name="newServer[PathToIndex]" value="<?php echo $Server->PathToIndex() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('PathToZMS') ?></th>
<td><input type="text" name="newServer[PathToZMS]" value="<?php echo $Server->PathToZMS() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('PathToApi') ?></th>
<td><input type="text" name="newServer[PathToApi]" value="<?php echo $Server->PathToApi() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunStats') ?></th>
<td>
<input type="radio" name="newServer[zmstats]" value="1" <?php echo $Server->zmstats() ? $checked : $null ?>/> Yes
<input type="radio" name="newServer[zmstats]" value="0" <?php echo $Server->zmstats() ? $null : $checked ?>/> No
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunAudit') ?></th>
<td>
<input type="radio" name="newServer[zmaudit]" value="1"<?php echo $Server->zmaudit() ? $checked : $null ?>/> Yes
<input type="radio" name="newServer[zmaudit]" value="0"<?php echo $Server->zmaudit() ? $null : $checked ?>/> No
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunTrigger') ?></th>
<td>
<input type="radio" name="newServer[zmtrigger]" value="1" <?php echo $Server->zmtrigger() ? $checked : $null ?>/> Yes
<input type="radio" name="newServer[zmtrigger]" value="0" <?php echo $Server->zmtrigger() ? $null : $checked ?>/> No
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunEventNotification') ?></th>
<td>
<input type="radio" name="newServer[zmeventnotification]" value="1" <?php echo $Server->zmeventnotification() ? $checked : $null ?>/> Yes
<input type="radio" name="newServer[zmeventnotification]" value="0" <?php echo $Server->zmeventnotification() ? $null : $checked ?>/> No
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button name="action" id="serverSubmitBtn" type="submit" class="btn btn-primary" value="Save"><?php echo translate('Save') ?></button>
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
</div>
</div>
</div>
</div>

View File

@ -24,7 +24,7 @@ if ( ! canEdit('System') ) {
return;
}
if ( $action == 'Save' ) {
if ( $action == 'save' ) {
if ( !empty($_REQUEST['id']) ) {
$dbServer = dbFetchOne(
'SELECT * FROM Servers WHERE Id=?',
@ -46,7 +46,7 @@ if ( $action == 'Save' ) {
}
$refreshParent = true;
}
$view = 'none';
$redirect = '?view=options&tab=servers';
} else {
ZM\Error("Unknown action $action in saving Server");
}

View File

@ -910,104 +910,6 @@ function getCSRFinputHTML() {
return $result;
}
function getServerModalHTML($sid) {
$result = '';
$checked = ' checked="checked"';
$null = '';
if ( !canEdit('System') ) return;
$Server = new ZM\Server($sid);
if ( $sid and ! $Server->Id() ) return;
$result .= '<div class="modal fade" id="ServerModal" 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">' .translate('Server').' - '.$Server->Name(). '</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" method="post" action="?view=server&action=save" class="validateFormOnSubmit">'.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="view" value="server"/>'.PHP_EOL;
$result .= '<input type="hidden" name="object" value="server"/>'.PHP_EOL;
$result .= '<input type="hidden" name="id" value="' .validHtmlStr($_REQUEST['id']). '"/>'.PHP_EOL;
$result .= '<table class="table-sm">'.PHP_EOL;
$result .= '<tbody>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('Name'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[Name]" value="' .$Server->Name(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('Protocol'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[Protocol]" value="' .$Server->Protocol(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('Hostname'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[Hostname]" value="' .$Server->Hostname(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('Port'). '</th>'.PHP_EOL;
$result .= '<td><input type="number" name="newServer[Port]" value="' .$Server->Port(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('PathToIndex'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[PathToIndex]" value="' .$Server->PathToIndex(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('PathToZMS'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[PathToZMS]" value="' .$Server->PathToZMS(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('PathToApi'). '</th>'.PHP_EOL;
$result .= '<td><input type="text" name="newServer[PathToApi]" value="' .$Server->PathToApi(). '"/></td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('RunStats'). '</th>'.PHP_EOL;
$result .= '<td>'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmstats]" value="1"' .($Server->zmstats() ? $checked : $null). '/> Yes'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmstats]" value="0"' .($Server->zmstats() ? $null : $checked). '/> No'.PHP_EOL;
$result .= '</td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('RunAudit'). '</th>'.PHP_EOL;
$result .= '<td>'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmaudit]" value="1"' .($Server->zmaudit() ? $checked : $null). '/> Yes'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmaudit]" value="0"' .($Server->zmaudit() ? $null : $checked). '/> No'.PHP_EOL;
$result .= '</td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('RunTrigger'). '</th>'.PHP_EOL;
$result .= '<td>'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmtrigger]" value="1"' .($Server->zmtrigger() ? $checked : $null). '/> Yes'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmtrigger]" value="0"' .($Server->zmtrigger() ? $null : $checked). '/> No'.PHP_EOL;
$result .= '</td>'.PHP_EOL;
$result .= '</tr>'.PHP_EOL;
$result .= '<tr>'.PHP_EOL;
$result .= '<th scope="row">' .translate('RunEventNotification'). '</th>'.PHP_EOL;
$result .= '<td>'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmeventnotification]" value="1"' .($Server->zmeventnotification() ? $checked : $null). '/> Yes'.PHP_EOL;
$result .= '<input type="radio" name="newServer[zmeventnotification]" value="0"' .($Server->zmeventnotification() ? $null : $checked). '/> No'.PHP_EOL;
$result .= '</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 name="action" id="serverSubmitBtn" type="submit" class="btn btn-primary" value="Save">' .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 .= '</div>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
$result .= '</div>'.PHP_EOL;
return $result;
}
function xhtmlFooter() {
global $css;
global $cspNonce;