本文整理汇总了PHP中Subnets::modify_subnet方法的典型用法代码示例。如果您正苦于以下问题:PHP Subnets::modify_subnet方法的具体用法?PHP Subnets::modify_subnet怎么用?PHP Subnets::modify_subnet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subnets
的用法示例。
在下文中一共展示了Subnets::modify_subnet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
//booleans can be only 0 and 1!
if ($myField['type'] == "tinyint(1)") {
if ($_POST[$myField['name']] > 1) {
$_POST[$myField['name']] = 0;
}
}
//not null!
if ($myField['Null'] == "NO" && strlen($_POST[$myField['name']]) == 0) {
$Result->show("danger", $myField['name'] . '" can not be empty!', true);
}
# save to update array
$values[$myField['name']] = $_POST[$myField['name']];
}
}
# execute
if (!$Subnets->modify_subnet($_POST['action'], $values)) {
$Result->show("danger", _('Error editing subnet'), true);
} else {
# if add save id !
if ($_POST['action'] == "add") {
$new_subnet_id = $Subnets->lastInsertId;
}
# update also all slave subnets if section changes!
if (isset($values['sectionId']) && $_POST['action'] == "edit" || $_POST['action'] == "delete") {
$Subnets->reset_subnet_slaves_recursive();
$Subnets->fetch_subnet_slaves_recursive($_POST['subnetId']);
$Subnets->remove_subnet_slaves_master($_POST['subnetId']);
if (sizeof($Subnets->slaves) > 0) {
foreach ($Subnets->slaves as $slaveId) {
if ($_POST['action'] == "edit") {
$Admin->object_modify("subnets", "edit", "id", array("id" => $slaveId, "sectionId" => $_POST['sectionIdNew']));
示例2: section_delete
/**
* Delete section, subsections, subnets and ip addresses
*
* @access private
* @param mixed $values
* @return void
*/
private function section_delete($values)
{
# subnets class
$Subnets = new Subnets($this->Database);
# save old values
$old_section = $this->fetch_section("id", $values['id']);
# check for subsections and store all ids
$all_ids = $this->get_all_section_and_subsection_ids($values['id']);
//array of section + all subsections
# truncate and delete all subnets in all sections, than delete sections
foreach ($all_ids as $id) {
$section_subnets = $Subnets->fetch_section_subnets($id);
if (sizeof($section_subnets) > 0) {
foreach ($section_subnets as $ss) {
//delete subnet
$Subnets->modify_subnet("delete", array("id" => $ss->id));
}
}
# delete all sections
try {
$this->Database->deleteRow("sections", "id", $id);
} catch (Exception $e) {
$this->Log->write("Section {$old_section->name} delete", "Failed to delete section {$old_section->name}<hr>" . $e->getMessage() . "<hr>" . $this->array_to_log($this->reformat_empty_array_fields($values, "NULL")), 2);
$this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
return false;
}
}
# write changelog
$this->Log->write_changelog('section', "delete", 'success', $old_section, array());
# log
$this->Log->write("Section {$old_section->name} delete", "Section {$old_section->name} deleted<hr>" . $this->array_to_log($this->reformat_empty_array_fields((array) $old_section)), 0);
return true;
}
示例3: Result
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# validate csrf cookie
$_POST['csrf_cookie'] == $_SESSION['csrf_cookie'] ?: $Result->show("danger", _("Invalid CSRF cookie"), true);
# ID must be numeric
if (!is_numeric($_POST['subnetId'])) {
$Result->show("danger", _("Invalid ID"), true);
}
# verify that user has write permissions for subnet
if ($Subnets->check_permission($User->user, $_POST['subnetId']) < 3) {
$Result->show("danger", _('You do not have permissions to resize subnet') . '!', true);
}
# fetch old subnet details and set new
$subnet_old = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
# verify resizing
$Subnets->verify_subnet_resize($subnet_old['subnet'], $_POST['newMask'], $subnet_old['id'], $subnet_old['vrfId'], $subnet_old['masterSubnetId'], $subnet_old['mask'], $subnet_old['sectionId']);
# we need to recalculate subnet address if needed
if ($subnet_old['mask'] < $_POST['newMask']) {
$subnet_new['subnet'] = $subnet_old['subnet'];
} else {
$new_boundaries = $Subnets->get_network_boundaries($Subnets->transform_address($subnet_old['subnet'], "dotted"), $_POST['newMask']);
$subnet_new['subnet'] = $Subnets->transform_address($new_boundaries['network'], "decimal");
}
# set update values
$values = array("id" => $_POST['subnetId'], "subnet" => $subnet_new['subnet'], "mask" => $_POST['newMask']);
if (!$Subnets->modify_subnet("resize", $values)) {
$Result->show("danger", _("Error resizing subnet") . "!", true);
} else {
$Result->show("success", _("Subnet resized successfully") . "!", true);
}
示例4: delegate_section_permissions
/**
* Delegates section permissions to all belonging subnets
*
* @access public
* @param mixed $sectionId
* @param array $removed_permissions
* @param array $changed_permissions
* @return bool
*/
public function delegate_section_permissions($sectionId, $removed_permissions, $changed_permissions)
{
// init subnets class
$Subnets = new Subnets($this->Database);
// fetch section subnets
$section_subnets = $this->fetch_multiple_objects("subnets", "sectionId", $sectionId);
// loop
if ($section_subnets !== false) {
foreach ($section_subnets as $s) {
// to array
$s_old_perm = json_decode($s->permissions, true);
// removed
if (sizeof($removed_permissions) > 0) {
foreach ($removed_permissions as $k => $p) {
unset($s_old_perm[$k]);
}
}
// added
if (sizeof($changed_permissions) > 0) {
foreach ($changed_permissions as $k => $p) {
$s_old_perm[$k] = $p;
}
}
// set values
$values = array("id" => $s->id, "permissions" => json_encode($s_old_perm));
// update
if ($Subnets->modify_subnet("edit", $values) === false) {
$Result->show("danger", _("Failed to set subnet permissons for subnet") . " {$s->name}!", true);
}
}
// ok
$this->Result->show("success", _("Subnet permissions recursively set") . "!", true);
}
try {
$this->Database->updateObject("subnets", array("permissions" => $permissions, "sectionId" => $sectionId), "sectionId");
} catch (Exception $e) {
$this->Result->show("danger", _("Error: ") . $e->getMessage());
return false;
}
return true;
}
示例5: dirname
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# strip input tags
$_POST = $Admin->strip_input_tags($_POST);
# validate csrf cookie
$User->csrf_cookie("validate", "linkedsubnet", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
# check subnet permissions
if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) {
$Result->show("danger", _('You do not have permissions to add edit/delete this subnet') . "!", true);
}
# ID must be numeric
if (!is_numeric($_POST['subnetId'])) {
$Result->show("danger", _("Invalid ID"), true);
}
if (!is_numeric($_POST['linked_subnet'])) {
$Result->show("danger", _("Invalid ID"), true);
}
# submit
$values = array("id" => $_POST['subnetId'], "linked_subnet" => $_POST['linked_subnet']);
# verify that user has write permissions for subnet
if ($Subnets->modify_subnet("edit", $values) !== false) {
$Result->show("success", _("Subnet linked"), false);
}