/** * Reorders custom fields * * @access public * @param mixed $table * @param mixed $next * @param mixed $current * @return boolean */ public function reorder_custom_fields($table, $next, $current) { # get current field details $Tools = new Tools($this->Database); $old = (array) $Tools->fetch_full_field_definition($table, $current); # set update request if ($old['Null'] == "NO") { $query = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `' . $current . '` ' . $old['Type'] . ' NOT NULL COMMENT "' . $old['Comment'] . '" AFTER `' . $next . '`;'; } else { $query = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `' . $current . '` ' . $old['Type'] . ' DEFAULT NULL COMMENT "' . $old['Comment'] . '" AFTER `' . $next . '`;'; } # execute try { $res = $this->Database->runQuery($query); } catch (Exception $e) { $this->Result->show("danger", _("Error: ") . $e->getMessage(), false); return false; } # ok return true; }
# verify that user is logged in $User->check_user_session(); # create csrf token $csrf = $User->csrf_cookie("create", "custom_field"); # strip tags - XSS $_POST = $User->strip_input_tags($_POST); # validate action $Admin->validate_action($_POST['action'], true); /* reset field name for add! */ if ($_POST['action'] == "add") { $_POST['fieldName'] = ""; } else { $_POST['oldname'] = $_POST['fieldName']; } # fetch old field definition $fieldval = (array) $Tools->fetch_full_field_definition($_POST['table'], $_POST['fieldName']); ?> <div class="pHeader"><?php print ucwords(_("{$_POST['action']}")); ?> <?php print _('custom field'); ?> </div> <div class="pContent"> <form id="editCustomFields">
$reqfields = array("section", "subnet"); # manually adjust the standard fields foreach ($expfields as $std_field) { # extra table and field if (isset($extfields[$std_field])) { $cfield = $extfields[$std_field]["field"]; $ctable = $extfields[$std_field]["table"]; $pname = $extfields[$std_field]["pname"] . " "; } else { # default table and field $cfield = $std_field; $ctable = $mtable; $pname = ""; } # read field attributes $field = $Tools->fetch_full_field_definition($ctable, $cfield); $field = (array) $field; # mark required fields with * $msgr = in_array($std_field, $reqfields) ? "*" : ""; #prebuild template table rows to avoid useless foreach loops $tpl_field_names .= "<th>" . $pname . $field['Field'] . $msgr . "</th>"; $tpl_field_types .= "<td><small>" . wordwrap($field['Type'], 18, "<br>\n", true) . "</small></td>"; } # append the custom fields, if any $custom_fields = $Tools->fetch_custom_fields($mtable); if (sizeof($custom_fields) > 0) { foreach ($custom_fields as $myField) { # add field to required fields if needed if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
# verify that user is logged in $User->check_user_session(); $tpl_field_names = ""; $tpl_field_types = ""; # predefine field list $expfields = array("name", "rd", "description"); # required fields without which we will not continue $reqfields = array("rd", "name"); # manually adjust the standard fields foreach ($expfields as $std_field) { if (in_array($std_field, $reqfields)) { $msgr = "*"; } else { $msgr = ""; } $field = $Tools->fetch_full_field_definition("vrf", $std_field); $field = (array) $field; $res[$field['Field']]['name'] = $field['Field']; $res[$field['Field']]['type'] = $field['Type']; $res[$field['Field']]['Comment'] = $field['Comment']; $res[$field['Field']]['Null'] = $field['Null']; $res[$field['Field']]['Default'] = $field['Default']; #prebuild template table rows to avoid useless foreach loops $tpl_field_names .= "<th>" . $field['Field'] . $msgr . "</th>"; $tpl_field_types .= "<td><small>" . wordwrap($field['Type'], 18, "<br>\n", true) . "</small></td>"; } # append the custom fields, if any $custom_fields = $Tools->fetch_custom_fields("vrf"); if (sizeof($custom_fields) > 0) { $res[] = $custom_fields; foreach ($custom_fields as $myField) {