Skip to content

Commit

Permalink
refine showChoice()
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Root committed Aug 13, 2016
1 parent e3d7e5c commit dfd54ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions wwwroot/inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5118,12 +5118,13 @@ function showNotice ($message, $option = '')
}

// asks ok/cancel question
// return string 'true' or 'false'
// return TRUE/FALSE/NULL
// NULL = waiting for choice
// adds 'answer' to request post data and repeats request
function showChoice ($question)
{
if (isset ($_POST['answer']))
return $_POST['answer'];
return ($_POST['answer'] === 'true' ? TRUE : FALSE);

$form = "<form id=choice method=post action='?{$_SERVER['QUERY_STRING']}'>";
foreach ($_POST as $name => $value)
Expand All @@ -5144,6 +5145,8 @@ function showChoice ($question)
ENDMSG;

setMessage ('warning', $msg, FALSE);

return NULL;
}

// do not call this directly, use showError and its siblings instead
Expand Down
24 changes: 16 additions & 8 deletions wwwroot/inc/ophandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,23 +1021,31 @@ function addIPAllocation ()

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')
$choice = showChoice ('Assign IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'"?<br>'.
($reserved ? 'IP reservation will be removed!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" and comment will be removed!' : '')
);

if ($choice === NULL) // waiting for choice
return;

if($choice !== TRUE)
{
showWarning ('IP '.ip_format ($ip_bin).' NOT assigned<br>'.
showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" NOT assigned<br>'.
($reserved ? 'IP is still reserved!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" unchanged' : ''));
($ipname ? 'IP name "'.$address['name'].'" and comment unchanged' : ''));

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

showWarning ('IP '.ip_format ($ip_bin).' assigned<br>'.
showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" assigned<br>'.
($reserved ? 'IP is NO longer reserved!<br>' : '').
($ipname ? 'IP name "'.$address['name'].'" removed!' : ''));
($ipname ? 'IP name "'.$address['name'].'" and comment removed!' : ''));
}
}
else
if ($address['reserved'] == 'yes' && $address['name'] != '')
showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" is already reserved!');

bindIPToObject
(
Expand Down

0 comments on commit dfd54ce

Please sign in to comment.