From 7d52e00a51450bc4a080d4e21b7dda02c0a65191 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 14 Nov 2013 05:42:06 -0500
Subject: [PATCH] Fixed list sorting
---
interface/lib/classes/functions.inc.php | 124 ++++++++++++++++++++++++++++++++++++++--
1 files changed, 116 insertions(+), 8 deletions(-)
diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php
index b0e1f3b..64074d4 100644
--- a/interface/lib/classes/functions.inc.php
+++ b/interface/lib/classes/functions.inc.php
@@ -32,7 +32,8 @@
//* This class is loaded automatically by the ispconfig framework.
class functions {
-
+ var $idn_converter = null;
+ var $idn_converter_name = '';
public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'application/pdf', $filename = '', $cc = '', $bcc = '', $from_name = '') {
global $app,$conf;
@@ -128,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;
}
@@ -211,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");
@@ -291,7 +329,7 @@
foreach($ips as $ip){
$result_array['cdata'][] = array( 'title' => $ip,
- 'description' => $type,
+ 'description' => $type.($server_by_ip[$ip] != ''? ' > '.$server_by_ip[$ip] : ''),
'onclick' => '',
'fill_text' => $ip
);
@@ -302,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;
@@ -310,6 +348,76 @@
return intval($string);
}
}
+
+ /** IDN converter wrapper.
+ * all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
+ */
+ private function _idn_encode_decode($domain, $encode = true) {
+ if($domain == '') return '';
+ if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded
+
+ // get domain and user part if it is an email
+ $user_part = false;
+ if(strpos($domain, '@') !== false) {
+ $user_part = substr($domain, 0, strrpos($domain, '@'));
+ $domain = substr($domain, strrpos($domain, '@') + 1);
+ }
+
+ if($encode == true) {
+ if(function_exists('idn_to_ascii')) {
+ $domain = idn_to_ascii($domain);
+ } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
+ /* use idna class:
+ * @author Matthias Sommerfeld <mso@phlylabs.de>
+ * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
+ * @version 0.8.0 2011-03-11
+ */
+
+ if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
+ include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
+ $this->idn_converter = new idna_convert(array('idn_version' => 2008));
+ $this->idn_converter_name = 'idna_convert.class';
+ }
+ $domain = $this->idn_converter->encode($domain);
+ }
+ } else {
+ if(function_exists('idn_to_utf8')) {
+ $domain = idn_to_utf8($domain);
+ } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
+ /* use idna class:
+ * @author Matthias Sommerfeld <mso@phlylabs.de>
+ * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
+ * @version 0.8.0 2011-03-11
+ */
+
+ if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
+ include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
+ $this->idn_converter = new idna_convert(array('idn_version' => 2008));
+ $this->idn_converter_name = 'idna_convert.class';
+ }
+ $domain = $this->idn_converter->decode($domain);
+ }
+ }
+
+ if($user_part !== false) return $user_part . '@' . $domain;
+ else return $domain;
+ }
+
+ public function idn_encode($domain) {
+ $domains = explode("\n", $domain);
+ for($d = 0; $d < count($domains); $d++) {
+ $domains[$d] = $this->_idn_encode_decode($domains[$d], true);
+ }
+ return implode("\n", $domains);
+ }
+
+ public function idn_decode($domain) {
+ $domains = explode("\n", $domain);
+ for($d = 0; $d < count($domains); $d++) {
+ $domains[$d] = $this->_idn_encode_decode($domains[$d], false);
+ }
+ return implode("\n", $domains);
+ }
}
--
Gitblit v1.9.1