$title = $_POST['title']; $desc = $_POST['description']; $location = $_POST['location']; $owner = $_POST['owner']; $assigned = $_POST['assigned']; $status = $_POST['status']; $tags = $_POST['tags']; $ip_2 = new IP_Database($id); $ip_2->set_title($title); $ip_2->set_description($desc); $ip_2->set_location_id($location); $ip_2->set_owner_id($owner); $ip_2->set_assigned_to_id($assigned); if (isset($_POST['status'])) { if ($status != 'undefined') { $ip_2->set_status($status); } } if (isset($_POST['stub'])) { $stub = $_POST['stub']; $ip_2->set_stub($stub); } $ip_2->set_tags($tags); if (!$ip_2->update()) { return false; } } if (isset($_GET['stub'])) { $stub_id = explode("@", $_GET['stub']); $ip_db = new IP_Database($stub_id[1]); $ip_db->set_stub($stub_id[0]);
function display_all_ip($arr, $ip_manager) { global $string; //if nothing is given show no ip if (empty($arr)) { $string .= Form::warning("NO IP!"); //return false; } //create the modal box style sheets $string .= "<style>"; foreach ($arr as $id => $name) { $string .= "#modalBox #dialog" . $id; $string .= "{\n\t\t\twidth:auto;\n\t\t\tmax-width: 80%;\n\t\t\tmin-width:40%;\n \t\t\theight:auto;\n\t\t\tpadding:10px;\n\t\t\tpadding-top:10px;\n\t\t}\n\t\t"; $string .= "#modalBox #dialog_host" . $id; $string .= "{\n\t\t\twidth:auto;\n\t\t\tmax-width: 80%;\n\t\t\tmin-width:40%;\n \t\t\theight:auto;\n\t\t\tpadding:10px;\n\t\t\tpadding-top:10px;\n\t\t}\n\t\t"; $string .= "#modalBox #dialog_calc" . $id; $string .= "{\n\t\t\twidth:auto;\n\t\t\tmax-width: 80%;\n\t\t\tmin-width:40%;\n \t\t\theight:auto;\n\t\t\tpadding:10px;\n\t\t\tpadding-top:10px;\n\t\t}"; } $string .= "</style>"; //start the tree view if (IP_Database::get_master($id) == $id) { $string .= "<ul id='browser' class='filetree'>"; } else { $string .= "<ul>"; } //create individual modal views and tree roots for each networks foreach ($arr as $id => $name) { //get ip info $ip_2 = new IP_Database($id); if ($ip_2->get_netblock_id() == NULL) { return false; } //make a form $string .= "<li id='ip_row" . $id . "'><a name='" . $id . "'></a>"; $string .= "<div id='netblock" . $id . "'><form method='post' id='form_ip" . $id . "'>"; //do some ip calculation $ip_manager->set_IP($ip_2->get_address_int() . "/" . $ip_2->get_subnet_size(), $ip_2->get_family()); //set the status color $color = "black"; $tag_str = ""; $status = $ip_2->get_status(); if (IP_Database::is_parent($id)) { if ($status != "PARENT") { $ip_2->set_status("PARENT"); $ip_2->update(); } } switch ($status) { case "FREE": $color = "green"; break; case "RESERVED": $color = "blue"; break; case "ASSIGNED": $color = "red"; break; case "PARENT": $color = "grey; font-style:italic;"; break; } //make a modal window for ip calculator $string .= "<div id='modalBox'>\n\t\t\t<div id='dialog_calc" . $id . "' class='window'>\n\t\t\t<div style='clear:both;'></div>"; $string .= "<a href='#'class='close' /><img src='icons/close.png'></a>"; $string .= $ip_manager->print_all(); $string .= "</div>\n\t\t\t<div id='mask'></div>\n\t\t\t</div>"; //check if it's stub to give the network proper icons $string .= "<span id='stub_img" . $id . "'>"; if ($ip_2->is_stub() == 1) { $string .= "<img id='stub' src='icons/stub2.png' />"; } $string .= "</span>"; //write the initial ip info and give it the status color $string .= "<a name='modal' href='#dialog" . $id . "' style='cursor:default;' class='ipdesc' rel='" . $ip_manager->get_IP() . "@" . $id . "'><span id='status" . $id . "'><font style='color:" . $color . "'>" . $ip_manager->get_IP() . "</font></span></a>"; //display the calculator icon $string .= "<a name='modal' href='#dialog_calc" . $id . "' style='cursor:default;' class='ipcalc' rel='" . $ip_manager->get_IP() . "@" . $id . "'><img src='icons/calculator.png' /></a>"; //have a hidden input $string .= "<input type='hidden' name='id' value='" . $id . "' />"; //if it's a stub give it a host icon else give it a gear icon if ($ip_2->is_stub() == 1) { $string .= "<a name='modal' href='#dialog_host" . $id . "'><span id='st_ho_img" . $id . "'><img src='icons/host.png' /></span></a>"; } else { if (!IP_Database::is_parent($id)) { if (is_numeric($ip_2->get_parent_id())) { $p_netblock = new IP_Database($ip_2->get_parent_id()); if (!$p_netblock->is_stub()) { $string .= "<a name='modal' href='#dialog_host" . $id . "'><span id='st_ho_img" . $id . "'><img src='icons/gears.png' /></span></a>"; } } else { $string .= "<a name='modal' href='#dialog_host" . $id . "'><span id='st_ho_img" . $id . "'><img src='icons/gears.png' /></span></a>"; } } } //give it proper icons if it has the location, or assigned to assigned $ip_title = ""; $ip_loc = ""; $ip_assign = ""; if ($ip_2->get_title() != "") { $ip_title = " - " . $ip_2->get_title(); } if ($ip_2->get_location_name() != "") { $ip_loc = " - <img src='icons/location.png' />" . $ip_2->get_location_name(); } if ($ip_2->get_assigned_to_name() != "") { $ip_assign = " - <img src='icons/People.png' /> " . $ip_2->get_assigned_to_name(); } //show the title, location and assigned to and the make an update icon $string .= "<span id='ip_name" . $id . "'>" . $ip_title . $ip_loc . $ip_assign . "</span><p id='update" . $id . "' style='display:inline'></p>"; //$string.= "<input type='image' src='images/ip_switch_split.png' value='change_to_stub' alt='Submit' style='background-color:transparent; border:none;' />"; // $string .= "<div id='modalBox'>\n\t\t\t<div id='dialog" . $id . "' class='window'>\n\t\t\t<div style='clear:both;'></div>"; $string .= "<a href='#'class='close' /><img src='icons/close.png'></a>"; $string .= "<font class='header2'>" . $ip_2->get_address_ip() . "</font><br/><hr /><font class='header'>Name</font> "; $string .= "<input type='text' id='title" . $id . "' name='title' style='width:100%; margin-bottom:10px;' maxchar='100' value='" . $ip_2->get_title() . "' />"; $string .= "<font class='header'>Comment</font><textArea id='description" . $id . "' name='description' style='width:100%; margin-bottom:10px;' rows='5' >" . $ip_2->get_description() . "</textArea>"; $string .= "Location: <select name='location' id='location" . $id . "'>"; if ($ip_2->get_location_id() === NULL) { $string .= "<option selected value='NULL'>No Location</option>"; } else { $string .= "<option value='NULL'>No Location</option>"; } foreach (Location::get_locations() as $lid => $lname) { if ($lid == $ip_2->get_location_id()) { $string .= "<option selected value='" . $lid . "'>" . $lname . "</option>"; } else { $string .= "<option value='" . $lid . "'>" . $lname . "</option>"; } } $string .= "</select> "; $string .= "Owner: <select name='owner' id='owner" . $id . "'>"; if ($ip_2->get_owner_id() === NULL) { $string .= "<option selected value='NULL'>No Owner</option>"; } else { $string .= "<option value='NULL'>No Owner</option>"; } foreach (Contact::get_groups() as $g_id => $g_name) { if ($g_id == $ip_2->get_owner_id()) { $string .= "<option selected value='" . $g_id . "'>" . $g_name . "</option>"; } else { $string .= "<option value='" . $g_id . "'>" . $g_name . "</option>"; } } $string .= "</select> "; $string .= "Assigned To: <select name='assigned' id='assigned" . $id . "'>"; if ($ip_2->get_owner_id() === NULL) { $string .= "<option selected value='NULL'>No Assigned To</option>"; } else { $string .= "<option value='NULL'>No Assigned To</option>"; } foreach (Contact::get_groups() as $g_id => $g_name) { if ($g_id == $ip_2->get_assigned_to_id()) { $string .= "<option selected value='" . $g_id . "'>" . $g_name . "</option>"; } else { $string .= "<option value='" . $g_id . "'>" . $g_name . "</option>"; } } $string .= "</select> "; $string .= "<div style='width:100%'>"; if (!IP_Database::is_parent($id)) { $string .= "Status: <select name='status' id='status" . $id . "'>"; $all_status = array("FREE", "RESERVED", "ASSIGNED"); foreach ($all_status as $s_id => $s_name) { if ($ip_2->get_status() == $s_name) { $string .= "<option selected value='" . $s_name . "'>" . $s_name . "</option>"; } else { $string .= "<option value='" . $s_name . "'>" . $s_name . "</option>"; } } $string .= "</select> "; } if (is_numeric($ip_2->get_parent_id())) { $p_netblock = new IP_Database($ip_2->get_parent_id()); if (!$p_netblock->is_stub()) { if (!IP_Database::is_parent($id)) { $string .= "Stub: <select name='stub' id='stub" . $id . "'>"; if ($ip_2->is_stub() == 0) { $string .= "<option value='0' selected >not stub</option>\n\t\t\t\t\t\t<option value='1' >stub</option>"; } else { $string .= "<option value='0' >not stub</option>\n\t\t\t\t\t\t<option value='1' selected >stub</option>"; } $string .= "</select>"; } } } else { if (!IP_Database::is_parent($id)) { $string .= "Stub: <select name='stub' id='stub" . $id . "'>"; if ($ip_2->is_stub() == 0) { $string .= "<option value='0' selected >not stub</option>\n\t\t\t\t\t<option value='1' >stub</option>"; } else { $string .= "<option value='0' >not stub</option>\n\t\t\t\t\t<option value='1' selected >stub</option>"; } $string .= "</select>"; } } $string .= "</div>"; $string .= "<br /><font class='header'>Tags</font><input type='text' id='tags" . $id . "' class='tags_input' name='tags' style='width:100%; margin-bottom:10px;' value='"; foreach ($ip_2->get_tags() as $t_id => $t_name) { $tag_str .= $t_name . ", "; } $tag_str = rtrim($tag_str, " "); $tag_str = str_replace("<", "", $tag_str); $tag_str = str_replace(">", "", $tag_str); $tag_str = str_replace("\"", "", $tag_str); $tag_str = str_replace("\\'", "", $tag_str); $string .= rtrim($tag_str, ","); $string .= "' />"; $string .= " <input type='button' class='close' id='ip_update' name='ip_update' value='UPDATE' onclick='return update_info(" . $id . ")' />"; $temp_netblock = new IP_Database($ip_2->get_parent_id()); if (!$temp_netblock->is_stub()) { $all_child_netblock_num = count(get_all_children($ip_2->get_netblock_id(), $ip_2->get_family())); $string .= " <input type='submit' id='ip_force_delete' name='ip_force_delete' onclick='return confirmForceDelete(" . $all_child_netblock_num . ")' value='FORCE DELETE' style='float:right; background:red; color:white;'/>"; } $string .= "<input type='hidden' name='id' value='" . $id . "' />\n\t\t<input type='submit' id='ip_delete' name='ip_delete' onclick='return confirmSubmit()' value='DELETE NETWORK' />"; $string .= "</div>\n\t\t\t <div id='mask'></div>\n\t\t\t\t</div>"; if (!IP_Database::is_parent($id)) { $string .= "<div id='modalBox'>\n\t\t\t<div id='dialog_host" . $id . "' class='window'>\n\t\t\t<div style='clear:both;'></div>"; $string .= "<a href='#'class='close' /><img src='icons/close.png' /></a>"; $string .= "<div id='loader" . $id . "' style='display:inline'>"; $string .= "<font class='header'>" . $ip_2->get_address_ip() . "</font><br/>"; //DYNAMIC CHANGE HERE $string .= "<div id='host_split" . $id . "'>"; if ($ip_2->is_stub() == 0) { if ($ip_manager->get_family() == 4) { if ($ip_2->get_subnet_size() != 32) { $string .= "<select name='split'>"; for ($i = $ip_manager->get_length(); $i < 32; $i++) { $string .= "<option value='" . ($i + 1) . "'>" . ($i + 1) . "</option>"; } $string .= "</select>"; $string .= " <input type='submit' name='ip_split_submit' value='SPLIT NETWORK' />"; } else { $string .= "<span style='color:red; font-size:14px'>CANNOT SPLIT ANY FURTHER</span>"; } $parent_id = IP_Database::get_parent($id); if (is_numeric($parent_id)) { $temp_ip = new IP_Database($parent_id); if ($temp_ip->is_stub() != true) { $string .= "<br/>"; $string .= "<select name='merge'>"; for ($i = $ip_manager->get_length() - 1; $i >= $temp_ip->get_subnet_size(); $i--) { $string .= "<option value='" . $i . "'>" . $i . "</option>"; } $string .= "</select>"; $string .= " <input type='submit' name='ip_merge_submit' value='MERGE NETWORK' />"; } } } else { if ($ip_manager->get_family() == 6) { if ($ip_2->get_subnet_size() != 128) { $string .= "<select name='split'>"; for ($i = $ip_manager->get_length(); $i < 128; $i++) { $string .= "<option value='" . ($i + 1) . "'>" . ($i + 1) . "</option>"; } $string .= "</select>"; $string .= " <input type='submit' name='ip_split_submit' value='SPLIT NETWORK' />"; } else { $string .= "<span style='color:red; font-size:14px'>CANNOT SPLIT ANY FURTHER</span>"; } $parent_id = IP_Database::get_parent($id); if (is_numeric($parent_id)) { $temp_ip = new IP_Database($parent_id); if ($temp_ip->is_stub() != true) { $string .= "<br/>"; $string .= "<select name='merge'>"; for ($i = $ip_manager->get_length() - 1; $i >= $temp_ip->get_subnet_size(); $i--) { $string .= "<option value='" . $i . "'>" . $i . "</option>"; } $string .= "</select>"; $string .= " <input type='submit' name='ip_merge_submit' value='MERGE NETWORK' />"; } } } } } else { if ($ip_manager->get_family() == 4) { if ($ip_2->get_subnet_size() != 32) { $string .= "<input type='text' id='ip_hostip" . $id . "' name='ip_hostip' style='width:200px;'/> / \n\t\t\t\t\t\t<input type='text' maxlength='3' id='ip_hostsubnet" . $id . "' name='ip_hostsubnet' style='width:50px;' value='32'/>\n\t\t\t\t\t\t<input type='submit' name='ip_host' value='ADD HOST' />"; //<input type='button' class='close' id='ip_host_a' name='ip_host_a' value='ADD HOST ASYNC' onclick='return add_host(".$id.")' /> } else { $string .= "<span style='color:red; font-size:14px'>CANNOT CREATE ANYMORE HOST</span>"; } } else { if ($ip_manager->get_family() == 6) { if ($ip_2->get_subnet_size() != 128) { $string .= "<input type='text' name='ip_hostip' style='width:200px;'/> / \n\t\t\t\t\t\t<input type='text' name='ip_hostsubnet' maxlength='3' style='width:50px;' value='128'/>\n\t\t\t\t\t\t<input type='submit' name='ip_host' value='ADD HOST' />"; } else { $string .= "<span style='color:red; font-size:14px'>CANNOT CREATE ANYMORE HOST</span>"; } } } } $string .= "</div>"; $string .= "<hr/>Inherit: <input type='checkbox' name='inh_loc' checked /> Location | <input type='checkbox' name='inh_owner' checked /> Owner | "; $string .= "<input type='checkbox' name='inh_assigned' /> Assigned to | <input type='checkbox' name='inh_status' /> Status | <input type='checkbox' name='inh_tags' /> Tags "; $string .= "</div>"; $string .= "</div>\n\t\t\t<div id='mask'></div>\n\t\t\t</div>"; $string .= "</div>"; $string .= "</form>"; } else { if ($ip_2->is_stub() == 1) { $string .= "<div id='modalBox'>\n\t\t\t\t<div id='dialog_host" . $id . "' class='window'>\n\t\t\t\t<div style='clear:both;'></div>"; $string .= "<a href='#' class='close' /><img src='icons/close.png' /></a>"; $string .= "<font class='header'>" . $ip_2->get_address_ip() . "</font><br/>"; if ($ip_manager->get_family() == 4) { if ($ip_2->get_subnet_size() != 32) { $string .= "<input type='text' id='ip_hostip' name='ip_hostip' style='width:200px;'/> / \n\t\t\t\t\t\t<input type='text' id='ip_hostsubnet' name='ip_hostsubnet' style='width:50px;' value='32'/>\n\t\t\t\t\t\t<input type='submit' name='ip_host' value='ADD HOST' />"; } else { $string .= "<span style='color:red; font-size:14px'>CANNOT CREATE ANYMORE HOST</span>"; } } else { if ($ip_manager->get_family() == 6) { if ($ip_2->get_subnet_size() != 128) { $string .= "<input type='text' name='ip_hostip' style='width:200px;'/> / \n\t\t\t\t\t\t<input type='text' name='ip_hostsubnet' style='width:50px;' value='128'/>\n\t\t\t\t\t\t<input type='submit' name='ip_host' value='ADD HOST' />"; } else { $string .= "<span style='color:red; font-size:14px'>CANNOT CREATE ANYMORE HOST</span>"; } } } $string .= "<hr/>Inherit: <input type='checkbox' name='inh_loc' checked /> Location | <input type='checkbox' name='inh_owner' checked /> Owner | "; $string .= "<input type='checkbox' name='inh_assigned' /> Assigned to | <input type='checkbox' name='inh_status' /> Status | <input type='checkbox' name='inh_tags' /> Tags "; $string .= "<div id='mask'></div>\n\t\t\t\t</div></div>"; } $string .= "</div>"; $string .= "</form>"; display_all_ip(IP_Database::get_all_ip($id), $ip_manager); } $string .= "\n</li></a>"; } $string .= "</ul>"; return $string; }