From e3d7e5c6d568d135e18c8a8889993c01af2c31bc Mon Sep 17 00:00:00 2001 From: github138 Date: Wed, 10 Aug 2016 16:52:39 +0200 Subject: [PATCH] add showChoice () fix addIPAllocation () show warnings * showChoice(): new function * addIPAllocation (): add showChoice fix warning messages use IPV4_AUTO_RELEASE config var --- wwwroot/inc/functions.php | 29 +++++++++++++++++++++++++++++ wwwroot/inc/ophandlers.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/wwwroot/inc/functions.php b/wwwroot/inc/functions.php index 26691b8a0..6d957a808 100644 --- a/wwwroot/inc/functions.php +++ b/wwwroot/inc/functions.php @@ -5117,6 +5117,35 @@ function showNotice ($message, $option = '') setMessage ('neutral', $message, $option == 'inline'); } +// asks ok/cancel question +// return string 'true' or 'false' +// adds 'answer' to request post data and repeats request +function showChoice ($question) +{ + if (isset ($_POST['answer'])) + return $_POST['answer']; + + $form = "
"; + foreach ($_POST as $name => $value) + $form .= ""; + $form .= ""; + $form .= '
'; + + $msg = $question; + $question = str_replace ('
', '\n', $question); + $question = str_replace ("'", "\'", $question); + $msg .= << + answer = confirm('$question'); + $('input#answer').val(answer); + $('form#choice').submit(); + +ENDMSG; + + setMessage ('warning', $msg, FALSE); +} + // do not call this directly, use showError and its siblings instead // $type could be 'error', 'warning', 'success' or 'neutral' function setMessage ($type, $message, $direct_rendering) diff --git a/wwwroot/inc/ophandlers.php b/wwwroot/inc/ophandlers.php index 2e43b7a32..e6e07cd89 100644 --- a/wwwroot/inc/ophandlers.php +++ b/wwwroot/inc/ophandlers.php @@ -1010,10 +1010,33 @@ function addIPAllocation () return; } - if($address['reserved'] && $address['name'] != '') + $autorelease = getConfigVar ('IPV4_AUTO_RELEASE'); + if ($autorelease > 0) { - showWarning("IP ".ip_format($ip_bin)." reservation \"".$address['name']."\" is removed"); - //TODO ask to take reserved IP or not ! + $reserved = $ipname = FALSE; + if ($autorelease >= 1 && $address['reserved'] == 'yes') + $reserved = TRUE; + if ($autorelease >= 2 && $address['name'] != '') + $ipname = TRUE; + + if ($reserved || $ipname) + { + if (showChoice ('Assign IP '.ip_format ($ip_bin).'?
'. + ($reserved ? 'IP reservation will be removed!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" will be removed!' : '') + ) != 'true') + { + showWarning ('IP '.ip_format ($ip_bin).' NOT assigned
'. + ($reserved ? 'IP is still reserved!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" unchanged' : '')); + + return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin))); + } + + showWarning ('IP '.ip_format ($ip_bin).' assigned
'. + ($reserved ? 'IP is NO longer reserved!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" removed!' : '')); + } } bindIPToObject