Skip to content

Commit

Permalink
add showChoice ()
Browse files Browse the repository at this point in the history
fix addIPAllocation () show warnings

* showChoice(): new function
* addIPAllocation (): add showChoice
	fix warning messages
	use IPV4_AUTO_RELEASE config var
  • Loading branch information
github138 committed Aug 11, 2016
1 parent e2b4528 commit d109dff
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
29 changes: 29 additions & 0 deletions wwwroot/inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<form id=choice method=post action='?{$_SERVER['QUERY_STRING']}'>";
foreach($_POST as $name => $value)
$form .= "<input type=hidden name='$name' value='$value'>";
$form .= "<input type=hidden id=answer name=answer value='false'>";
$form .= '</form>';

$msg = $question;
$question = str_replace ('<br>', '\n', $question);
$question = str_replace ("'", "\'", $question);
$msg .= <<<ENDMSG
$form
<script type="text/javascript">
answer = confirm('$question');
$('input#answer').val(answer);
$('form#choice').submit();
</script>
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)
Expand Down
29 changes: 26 additions & 3 deletions wwwroot/inc/ophandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).'?<br>'.
($reserved ? 'IP reservation will be removed!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" will be removed!' : '')
) != 'true')
{
showWarning('IP '.ip_format($ip_bin).' NOT assigned<br>'.
($reserved ? 'IP is still reserved!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" unchanged' : ''));

return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin)));
}

showWarning('IP '.ip_format($ip_bin).' assigned<br>'.
($reserved ? 'IP is NO longer reserved!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" removed!' : ''));
}
}

bindIPToObject
Expand Down

0 comments on commit d109dff

Please sign in to comment.