diff --git a/lam/lib/types/dhcp.inc b/lam/lib/types/dhcp.inc new file mode 100644 index 00000000..6b72e6b7 --- /dev/null +++ b/lam/lib/types/dhcp.inc @@ -0,0 +1,214 @@ + ("Subnet"), + "dhcprange" => ("IP range"), + "fixed_ips" => ("Fixed IP address / MAC address / description") + ); + } + +} + +/** + * Generates the list view. + * + * @package lists + * @author Thomas Manninger + * + */ +class lamDHCPList extends lamList { + + // A array with all fixed ips, mac adresses and descriptions + var $fixed; + + /** + * Constructor + * + * @param string $type account type + * @return lamList list object + */ + public function __construct($type) { + parent::__construct($type); + $this->labels = array( + 'nav' => _("%s DHCP(s) found"), + 'error_noneFound' => _("No DHCPs found!"), + 'newEntry' => _("New DHCP"), + 'dhcpDefaults' => _("DHCP settings"), + 'deleteEntry' => _("Delete DHCP(s)")); + } + + /** + * Prints the content of a cell in the account list for a given LDAP entry and attribute. + * + * @param array $entry LDAP attributes + * @param string $attribute attribute name + */ + public function listPrintTableCellContent(&$entry, &$attribute) { + // Fixed Ips + if ($attribute=="fixed_ips") { + // find all fixed addresses: + $ldap = $_SESSION['ldap']; + $suffix = $_SESSION['config']->get_Suffix('dhcp'); + + $sr = ldap_search($ldap->server(),"cn=".$entry['cn'][0].",".$suffix,"objectClass=dhcpHost"); + $get = ldap_get_entries($ldap->server(),$sr); + + // Now list all fixed_ips: + echo ""; + $this->fixed_ips = array(); + foreach($get AS $id=>$arr) { + if (is_numeric($id)) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + } + echo "
".array_pop(explode(" ",$get[$id]['dhcpstatements'][0]))."".array_pop(explode(" ",$get[$id]['dhcphwaddress'][0]))."".$get[$id]['cn'][0]."
"; + } + // fixed ip address + elseif ($attribute=="dhcpstatements") { + // Search after the fixed ip entry + if (is_array($entry['dhcpstatements'])) { + foreach($entry['dhcpstatements'] AS $id=>$value) { + + if (!is_array($value) && array_shift( explode(" ", $value) ) == "fixed-address") { + $ip = explode(" ", $value); + echo $ip['1']; + } + } + } + } + elseif ($attribute=="dhcprange") { // DHCP Range + if (is_array($entry['dhcprange'])) { + echo""; + foreach($entry['dhcprange'] AS $id=>$value) { + if (!is_numeric($value)) { + $ex = explode(" ", $value); + echo ""; + } + } + echo"
".$ex[0]."
-
".$ex[1]."
"; + } + } + else + { + parent::listPrintTableCellContent($entry, $attribute); + } + } + + + /** + * Prints the create, delete and PDF buttons. + * + * @param boolean $createOnly true if only the create button should be displayed + */ + function listPrintButtons($createOnly) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + // add/delete/PDF buttons + echo ("type . "\" type=\"submit\" name=\"new\" value=\"" . $this->labels['newEntry'] . "\">\n"); + if (!$createOnly) { + echo ("type . "\" type=\"submit\" name=\"del\" value=\"" . $this->labels['deleteEntry'] . "\">\n"); + } + echo ("type . "\" type=\"submit\" name=\"dhcpDefaults\" value=\"" . $this->labels['dhcpDefaults'] . "\">\n"); + echo "\n"; + $this->listShowOUSelection(); + echo "
\n"; + } + + /** + * Manages all POST actions (e.g. button pressed) for the account lists. + */ + function listDoPost() { + parent::listDoPost(); + if (isset($_POST['dhcpDefaults'])) { + metaRefresh("../account/edit.php?type=dhcp&DN='".$_SESSION['config']->get_suffix('dhcp')."'"); + } + } +} +?> \ No newline at end of file