function getLocationSelectAJAX() { $locationlist = listCells('location'); $locationtree = treeFromList($locationlist); // adds ['trace'] keys into $locationlist items $options = array(); $selected_id = ''; if (!isset($_REQUEST['locationid'])) { $options['error'] = "Sorry, param 'locationid' is empty. Reload page and try again"; } elseif (!preg_match("/locationid_(\\d+)/i", $_REQUEST['locationid'], $m)) { $options['error'] = "Sorry, wrong format locationid:'" . $_REQUEST['locationid'] . "'. Reload page and try again"; } else { $current_location_id = $m[1]; $selected_id = $locationlist[$current_location_id]['parent_id']; echo $selected_id; $options[0] = '-- NONE --'; foreach ($locationlist as $location_id => $locationinfo) { if (!in_array($current_location_id, $locationinfo['trace']) && $current_location_id != $location_id) { $options[$location_id] = $locationinfo['name']; } } } foreach ($options as $location_id => $value) { echo "<option value='{$location_id}'" . ($location_id == $selected_id ? ' selected' : '') . '>' . htmlspecialchars($value) . '</option>'; } }
// parse tree or error message. The latter case is a bug, because // RackCode saving function was supposed to validate its input. if ($rackCode['result'] != 'ACK') { throw new RackTablesError($rackCode['load'], RackTablesError::INTERNAL); } $rackCode = $rackCode['load']; // Only call buildPredicateTable() once and save the result, because it will remain // constant during one execution for constraints processing. $pTable = buildPredicateTable($rackCode); // Constraints parse trees aren't cached in the database, so the least to keep // things running is to maintain application cache for them. $entityCache = array(); // used by getExplicitTagsOnly() $tagRelCache = array(); $taglist = getTagList(); $tagtree = treeFromList($taglist); $auto_tags = array(); if (!isCLIMode() && isset($_SERVER['REMOTE_ADDR'])) { $auto_tags[] = array('tag' => '$client_' . $_SERVER['REMOTE_ADDR']); } // Initial chain for the current user. $user_given_tags = array(); // list of regexps used in findAutoTagWarnings to check RackCode. // add your regexps here to suppress 'Martian autotag' warnings $user_defined_atags = array(); // This also can be modified in local.php. $pageheaders = array(100 => "<link rel='ICON' type='image/x-icon' href='?module=chrome&uri=pix/favicon.ico' />"); addCSS('css/pi.css'); if (!isset($script_mode) or $script_mode !== TRUE) { // A successful call to authenticate() always generates autotags and somethimes // even given/implicit tags. It also sets remote_username and remote_displayname.
function renderRackspaceLocationEditor() { $js = <<<JSTXT \tfunction locationeditor_showselectbox(e) { \t\t\$(this).load('index.php', {module: 'ajax', ac: 'get-location-select', locationid: this.id}); \t\t\$(this).unbind('mousedown', locationeditor_showselectbox); \t} \t\$(document).ready(function () { \t\t\$('select.locationlist-popup').bind('mousedown', locationeditor_showselectbox); \t}); JSTXT; addJS($js, TRUE); function printNewItemTR() { printOpFormIntro('addLocation'); echo '<tr><td>'; printImageHREF('create', 'Add new location', TRUE); echo '</td><td><select name=parent_id tabindex=100>'; renderLocationSelectTree(); echo '</td><td><input type=text size=48 name=name tabindex=101></td><td>'; printImageHREF('create', 'Add new location', TRUE, 102); echo "</td></tr></form>\n"; } startPortlet('Locations'); echo "<table border=0 cellspacing=0 cellpadding=5 align=center class=widetable>\n"; echo "<tr><th> </th><th>Parent</th><th>Name</th><th> </th></tr>\n"; if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewItemTR(); } $locations = listCells('location'); renderLocationRowForEditor(treeFromList($locations)); if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewItemTR(); } echo "</table><br>\n"; finishPortlet(); }
function renderRackspaceLocationEditor() { addJS(<<<END function locationeditor_showselectbox(e) { \t\$(this).load('index.php', {module: 'ajax', ac: 'get-location-select', locationid: this.id}); \t\$(this).unbind('mousedown', locationeditor_showselectbox); } \$(document).ready(function () { \t\$('select.locationlist-popup').bind('mousedown', locationeditor_showselectbox); }); END , TRUE); function printNewItemTR() { printOpFormIntro('addLocation'); echo "<tr><td>"; printImageHREF('create', 'Add new location', TRUE); echo "</td><td><select name=parent_id tabindex=100>"; echo "<option value=0>-- NONE --</option>"; foreach (listCells('location') as $location) { echo "<option value={$location['id']}>{$location['name']}</option>"; } echo "</select></td>"; echo "<td><input type=text size=48 name=name tabindex=101></td><td>"; printImageHREF('create', 'Add new location', TRUE, 102); echo "</td></tr></form>\n"; } startPortlet('Locations'); echo "<table border=0 cellspacing=0 cellpadding=5 align=center class=widetable>\n"; echo "<tr><th> </th><th>Parent</th><th>Name</th><th> </th></tr>\n"; if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewItemTR(); } renderLocationRowForEditor(treeFromList(listCells('location'))); if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewItemTR(); } echo "</table><br>\n"; finishPortlet(); }
function getLocationSelectAJAX() { $locationlist = listCells('location'); $locationtree = treeFromList($locationlist); // adds ['trace'] keys into $locationlist items $options = array(); $selected_id = ''; if (!isset($_REQUEST['locationid'])) { $options['error'] = "Sorry, param 'locationid' is empty. Reload page and try again"; } elseif (!preg_match("/locationid_(\\d+)/i", $_REQUEST['locationid'], $m)) { $options['error'] = "Sorry, wrong format locationid:'" . $_REQUEST['locationid'] . "'. Reload page and try again"; } else { $current_location_id = $m[1]; $selected_id = $locationlist[$current_location_id]['parent_id']; echo $selected_id; echo "<option value=0>-- NONE --</option>"; } foreach ($locationtree as $location) { if ($location['id'] == $current_location_id) { continue; } echo "<option value={$location['id']} "; if ($location['id'] == $selected_id) { echo 'selected '; } echo "style='font-weight: bold'>{$location['name']}</option>"; if ($location['kidc'] > 0) { printLocationChildrenSelectOptions($location, 0, $selected_id, $current_location_id); } } }
function makeIPTree($netlist) { // treeFromList() requires parent_id to be correct for an item to get onto the tree, // so perform necessary pre-processing to calculate parent_id of each item of $netlist. $stack = array(); foreach ($netlist as $net_id => &$net) { while (!empty($stack)) { $top_id = $stack[count($stack) - 1]; if (!IPNetContains($netlist[$top_id], $net)) { // unless $net is a child of stack top array_pop($stack); } else { $net['parent_id'] = $top_id; break; } } if (empty($stack)) { $net['parent_id'] = NULL; } array_push($stack, $net_id); } unset($stack); $tree = treeFromList($netlist); // medium call return $tree; }