Skip to content

Commit

Permalink
feat(field): hostname field
Browse files Browse the repository at this point in the history
this field picks the hostname using its IP address

Signed-off-by: btry <[email protected]>
  • Loading branch information
amolecho authored and btry committed Aug 28, 2018
1 parent 56a4b5f commit 72a643a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions inc/fields/hostnamefield.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
class PluginFormcreatorHostnameField extends PluginFormcreatorField
{
public function show($canEdit = true) {
if ($canEdit) {
$hostname = gethostbyaddr(Toolbox::getRemoteIpAddress());
echo '<input type="hidden" class="form-control"
name="formcreator_field_' . $this->fields['id'] . '"
id="formcreator_field_' . $this->fields['id'] . '"
value="' . $hostname . '" />' . PHP_EOL;
} else {
parent::show($canEdit);
}
}

public function isValid($value) {
return true;
}

public static function getName() {
return _n('Hostname', 'Hostname', 1);
}

public static function getPrefs() {
return [
'required' => 0,
'default_values' => 0,
'values' => 0,
'range' => 0,
'show_empty' => 0,
'regex' => 0,
'show_type' => 0,
'dropdown_value' => 0,
'glpi_objects' => 0,
'ldap_values' => 0,
];
}

public static function getJSFields() {
$prefs = self::getPrefs();
return "tab_fields_fields['hostname'] = 'showFields(" . implode(', ', $prefs) . ");';";
}
}
Binary file added pics/ui-hostname-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 72a643a

Please sign in to comment.