From 391e05cbee6ff84bce60b665be60b4e5f049ee7f Mon Sep 17 00:00:00 2001
From: Falko Timme <ft@falkotimme.com>
Date: Tue, 22 Oct 2013 12:48:51 -0400
Subject: [PATCH] - Display hostname next to IP (where available) in the jQuery IP suggestion box.

---
 interface/lib/classes/functions.inc.php |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php
index 0801c1c..64074d4 100644
--- a/interface/lib/classes/functions.inc.php
+++ b/interface/lib/classes/functions.inc.php
@@ -129,11 +129,36 @@
 		return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep);
 	}
 	
+	//* convert currency formatted number back to floating number
+	public function currency_unformat($number) {
+		global $app;
+        
+		$number_format_dec_point = $app->lng('number_format_dec_point');
+		$number_format_thousands_sep = $app->lng('number_format_thousands_sep');
+		if($number_format_thousands_sep == 'number_format_thousands_sep') $number_format_thousands_sep = '';
+		
+		if($number_format_thousands_sep != '') $number = str_replace($number_format_thousands_sep, '', $number);
+		if($number_format_dec_point != '.' && $number_format_dec_point != '') $number = str_replace($number_format_dec_point, '.', $number);
+		
+		return (double)$number;
+	}
+	
 	public function get_ispconfig_url() {
+		global $app;
+		
 		$url = (stristr($_SERVER['SERVER_PROTOCOL'],'HTTPS') || stristr($_SERVER['HTTPS'],'on'))?'https':'http';
-		$url .= '://'.$_SERVER['SERVER_NAME'];
-		if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
-			$url .= ':'.$_SERVER['SERVER_PORT'];
+		if($_SERVER['SERVER_NAME'] != '_') {
+			$url .= '://'.$_SERVER['SERVER_NAME'];
+			if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
+				$url .= ':'.$_SERVER['SERVER_PORT'];
+			}
+		} else {
+			$app->uses("getconf");
+			$server_config = $app->getconf->get_server_config(1,'server');
+			$url .= '://'.$server_config['hostname'];
+			if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
+				$url .= ':'.$_SERVER['SERVER_PORT'];
+			}
 		}
 		return $url;
 	}
@@ -212,12 +237,24 @@
 			// IPv6
 			$regex = "/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i";
 		}
+		
+		$server_by_id = array();
+		$server_by_ip = array();
+		$servers = $app->db->queryAllRecords("SELECT * FROM server");
+		if(is_array($servers) && !empty($servers)){
+			foreach($servers as $server){
+				$server_by_id[$server['server_id']] = $server['server_name'];
+			}
+		}
 	
 		$ips = array();
-		$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM server_ip WHERE ip_type = '".$type."'");
+		$results = $app->db->queryAllRecords("SELECT ip_address AS ip, server_id FROM server_ip WHERE ip_type = '".$type."'");
 		if(!empty($results) && is_array($results)){
 			foreach($results as $result){
-				if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
+				if(preg_match($regex, $result['ip'])){
+					$ips[] = $result['ip'];
+					$server_by_ip[$result['ip']] = $server_by_id[$result['server_id']];
+				}
 			}
 		}
 		$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip");
@@ -292,7 +329,7 @@
 	
 			foreach($ips as $ip){
 				$result_array['cdata'][] = array(	'title' => $ip,
-													'description' => $type,
+													'description' => $type.($server_by_ip[$ip] != ''? ' &gt; '.$server_by_ip[$ip] : ''),
 													'onclick' => '',
 													'fill_text' => $ip
 												);
@@ -303,7 +340,7 @@
 	}
 
     public function intval($string, $force_numeric = false) {
-        if(intval($string) == 2147483647) {
+        if(intval($string) == 2147483647 || ($string > 0 && intval($string) < 0)) {
             if($force_numeric == true) return floatval($string);
             elseif(preg_match('/^([-]?)[0]*([1-9][0-9]*)([^0-9].*)*$/', $string, $match)) return $match[1].$match[2];
             else return 0;

--
Gitblit v1.9.1