Skip to content

Commit 77dbe51

Browse files
committed
- Implemented FS#2219.
1 parent 2213401 commit 77dbe51

File tree

11 files changed

+365
-7
lines changed

11 files changed

+365
-7
lines changed

interface/lib/lang/de.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ $wb['globalsearch_resultslimit_results_txt'] = "Treffern";
7575
$wb['globalsearch_noresults_text_txt'] = "Keine Treffer.";
7676
$wb['globalsearch_noresults_limit_txt'] = "0 Treffer";
7777
$wb['globalsearch_searchfield_watermark_txt'] = "Suche";
78+
$wb['globalsearch_suggestions_text_txt'] = "Vorschläge";
7879
?>

interface/lib/lang/en.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ $wb['globalsearch_resultslimit_results_txt'] = "results";
7676
$wb['globalsearch_noresults_text_txt'] = "No results.";
7777
$wb['globalsearch_noresults_limit_txt'] = "0 results";
7878
$wb['globalsearch_searchfield_watermark_txt'] = "Search";
79+
$wb['globalsearch_suggestions_text_txt'] = "Suggestions";
7980
?>

interface/web/admin/form/server_ip.tform.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
5656
Hinweis:
5757
Das ID-Feld ist nicht bei den Table Values einzufügen.
58+
59+
Search:
60+
- searchable = 1 or searchable = 2 include the field in the search
61+
- searchable = 1: this field will be the title of the search result
62+
- searchable = 2: this field will be included in the description of the search result
5863
5964
6065
*/
@@ -110,7 +115,8 @@
110115
'datatype' => 'VARCHAR',
111116
'formtype' => 'SELECT',
112117
'default' => '',
113-
'value' => array('IPv4' => 'IPv4', 'IPv6' => 'IPv6')
118+
'value' => array('IPv4' => 'IPv4', 'IPv6' => 'IPv6'),
119+
'searchable' => 2
114120
),
115121
'ip_address' => array (
116122
'datatype' => 'VARCHAR',
@@ -126,7 +132,8 @@
126132
'width' => '15',
127133
'maxlength' => '15',
128134
'rows' => '',
129-
'cols' => ''
135+
'cols' => '',
136+
'searchable' => 1
130137
),
131138
'virtualhost' => array (
132139
'datatype' => 'VARCHAR',
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2012, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
require_once('../../lib/config.inc.php');
32+
require_once('../../lib/app.inc.php');
33+
34+
//* Check permissions for module
35+
$app->auth->check_module_permissions('dns');
36+
37+
$app->uses('tform');
38+
39+
$type = $_GET["type"];
40+
41+
//if($_SESSION["s"]["user"]["typ"] == 'admin') {
42+
43+
44+
if($type == 'get_ipv4'){
45+
$q = $app->db->quote(trim($_GET["q"]));
46+
$authsql = " AND ".$app->tform->getAuthSQL('r');
47+
$modules = explode(',', $_SESSION['s']['user']['modules']);
48+
49+
$result = array();
50+
51+
// ipv4
52+
$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
53+
54+
$json = $app->functions->json_encode($result);
55+
}
56+
57+
if($type == 'get_ipv6'){
58+
$q = $app->db->quote(trim($_GET["q"]));
59+
$authsql = " AND ".$app->tform->getAuthSQL('r');
60+
$modules = explode(',', $_SESSION['s']['user']['modules']);
61+
62+
$result = array();
63+
64+
// ipv4
65+
$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
66+
67+
$json = $app->functions->json_encode($result);
68+
}
69+
70+
//}
71+
72+
function _search($module, $section, $additional_sql = ''){
73+
global $app, $q, $authsql, $modules;
74+
75+
$result_array = array('cheader' => array(), 'cdata' => array());
76+
if(in_array($module, $modules) || ($module == 'admin' && $section == 'server_ip')){
77+
$search_fields = array();
78+
$desc_fields = array();
79+
if(is_file('../'.$module.'/form/'.$section.'.tform.php')){
80+
include_once('../'.$module.'/form/'.$section.'.tform.php');
81+
82+
$category_title = $form["title"];
83+
$form_file = $form["action"];
84+
$db_table = $form["db_table"];
85+
$db_table_idx = $form["db_table_idx"];
86+
$order_by = $db_table_idx;
87+
88+
if(is_array($form["tabs"]) && !empty($form["tabs"])){
89+
foreach($form["tabs"] as $tab){
90+
if(is_array($tab['fields']) && !empty($tab['fields'])){
91+
foreach($tab['fields'] as $key => $val){
92+
if(isset($val['searchable']) && $val['searchable'] > 0){
93+
$search_fields[] = $key." LIKE '%".$q."%'";
94+
if($val['searchable'] == 1){
95+
$order_by = $key;
96+
$title_key = $key;
97+
}
98+
if($val['searchable'] == 2){
99+
$desc_fields[] = $key;
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
}
107+
unset($form);
108+
109+
$where_clause = '';
110+
if(!empty($search_fields)){
111+
$where_clause = implode(' OR ', $search_fields);
112+
} else {
113+
// valid SQL query which returns an empty result set
114+
$where_clause = '1 = 0';
115+
}
116+
if($where_clause != '') $where_clause = '('.$where_clause.')';
117+
if($additional_sql != '') $where_clause .= ' '.$additional_sql.' ';
118+
$order_clause = '';
119+
if($order_by != '') $order_clause = ' ORDER BY '.$order_by;
120+
121+
$sql = "SELECT * FROM ".$db_table." WHERE ".$where_clause.$authsql.$order_clause." LIMIT 0,10";
122+
$results = $app->db->queryAllRecords($sql);
123+
124+
if(is_array($results) && !empty($results)){
125+
$lng_file = '../'.$module.'/lib/lang/'.$_SESSION['s']['language'].'_'.$section.'.lng';
126+
if(is_file($lng_file)) include($lng_file);
127+
$result_array['cheader'] = array('title' => $category_title,
128+
'total' => count($results),
129+
'limit' => count($results)
130+
);
131+
foreach($results as $result){
132+
$description = '';
133+
if(!empty($desc_fields)){
134+
$desc_items = array();
135+
foreach($desc_fields as $desc_field){
136+
if($result[$desc_field] != '') $desc_items[] = $wb[$desc_field.'_txt'].': '.$result[$desc_field];
137+
}
138+
if(!empty($desc_items)) $description = implode(' - ', $desc_items);
139+
}
140+
141+
$result_array['cdata'][] = array( 'title' => $wb[$title_key.'_txt'].': '.$result[$title_key],
142+
'description' => $description,
143+
'onclick' => '',
144+
'fill_text' => $result[$title_key]
145+
);
146+
}
147+
}
148+
}
149+
return $result_array;
150+
}
151+
152+
header('Content-type: application/json');
153+
echo $json;
154+
?>

interface/web/dns/lib/lang/de_dns_wizard.lng

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ $wb['error_domain_regex'] = 'Domain beinhaltet ungültige Zeichen.';
2626
$wb['error_ns1_regex'] = 'NS1 beinhaltet ungültige Zeichen.';
2727
$wb['error_ns2_regex'] = 'NS2 beinhaltet ungültige Zeichen.';
2828
$wb['error_email_regex'] = 'E-Mail-Adresse beinhaltet keine gültige Adresse.';
29+
$wb['globalsearch_resultslimit_of_txt'] = "von";
30+
$wb['globalsearch_resultslimit_results_txt'] = "Treffern";
31+
$wb['globalsearch_noresults_text_txt'] = "Keine Treffer.";
32+
$wb['globalsearch_noresults_limit_txt'] = "0 Treffer";
33+
$wb['globalsearch_searchfield_watermark_txt'] = "Suche";
34+
$wb['globalsearch_suggestions_text_txt'] = "Vorschläge";
2935
?>

interface/web/dns/lib/lang/en_dns_wizard.lng

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ $wb['error_domain_regex'] = 'Domain contains invalid characters.';
2727
$wb['error_ns1_regex'] = 'NS1 contains invalid characters.';
2828
$wb['error_ns2_regex'] = 'NS2 contains invalid characters.';
2929
$wb['error_email_regex'] = 'Email does not contain a valid email address.';
30+
$wb['globalsearch_resultslimit_of_txt'] = "of";
31+
$wb['globalsearch_resultslimit_results_txt'] = "results";
32+
$wb['globalsearch_noresults_text_txt'] = "No results.";
33+
$wb['globalsearch_noresults_limit_txt'] = "0 results";
34+
$wb['globalsearch_searchfield_watermark_txt'] = "Search";
35+
$wb['globalsearch_suggestions_text_txt'] = "Suggestions";
3036
?>

interface/web/dns/templates/dns_a_edit.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@ <h2><tmpl_var name="list_head_txt"></h2>
3737
</div>
3838

3939
</div>
40+
<script language="JavaScript" type="text/javascript">
41+
jQuery('#data').ispconfigSearch({
42+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
43+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
44+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
45+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
46+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
47+
minChars: 0,
48+
cssPrefix: 'df-',
49+
fillSearchField: true,
50+
fillSearchFieldWith: 'fill_text',
51+
searchFieldWatermark: '',
52+
resultBoxPosition: 'e'
53+
});
54+
</script>

interface/web/dns/templates/dns_aaaa_edit.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@ <h2><tmpl_var name="list_head_txt"></h2>
3737
</div>
3838

3939
</div>
40+
<script language="JavaScript" type="text/javascript">
41+
jQuery('#data').ispconfigSearch({
42+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv6',
43+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
44+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
45+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
46+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
47+
minChars: 0,
48+
cssPrefix: 'df-',
49+
fillSearchField: true,
50+
fillSearchFieldWith: 'fill_text',
51+
searchFieldWatermark: '',
52+
resultBoxPosition: 'e'
53+
});
54+
</script>

interface/web/dns/templates/dns_wizard.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,18 @@ <h2><tmpl_var name="list_head_txt"></h2>
7878
</div>
7979

8080
</div>
81+
<script language="JavaScript" type="text/javascript">
82+
jQuery('#ip').ispconfigSearch({
83+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
84+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
85+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
86+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
87+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
88+
minChars: 0,
89+
cssPrefix: 'df-',
90+
fillSearchField: true,
91+
fillSearchFieldWith: 'fill_text',
92+
searchFieldWatermark: '',
93+
resultBoxPosition: 'e'
94+
});
95+
</script>

interface/web/js/jquery.ispconfigsearch.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
timeout: 500,
3434
minChars: 2,
3535
resultBox: '-resultbox',
36+
resultBoxPosition: 's', // n = north, e = east, s = south, w = west
3637
cssPrefix: 'gs-',
3738
fillSearchField: false,
3839
fillSearchFieldWith: 'title',
40+
ResultsTextPrefix: '',
3941
resultsLimit: '$ of % results',
4042
noResultsText: 'No results.',
4143
noResultsLimit: '0 results',
@@ -50,7 +52,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5052
settings.resultBox = $(this).attr('id')+settings.resultBox;
5153

5254
$(this).attr('autocomplete', 'off');
53-
$(this).val(settings.searchFieldWatermark);
55+
if($(this).val() == '') $(this).val(settings.searchFieldWatermark);
5456
$(this).wrap('<div class="'+settings.cssPrefix+'container" />');
5557
$(this).after('<ul id="'+settings.resultBox+'" class="'+settings.cssPrefix+'resultbox" style="display:none;"></ul>');
5658
var searchField = $(this);
@@ -63,7 +65,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6365
// query value
6466
var q = searchField.val();
6567

66-
if (settings.minChars > q.length || q == ''){
68+
if (settings.minChars > q.length || (q == '' && settings.minChars > 0)){
6769
resultBox.fadeOut();
6870
resetTimer(timeout);
6971
} else {
@@ -94,7 +96,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9496
}
9597

9698
if (!resultsFound){
97-
output += '<li class="'+settings.cssPrefix+'cheader"><p class="'+settings.cssPrefix+'cheader-title">'+settings.noResultsText+'</p><p class="'+settings.cssPrefix+'cheader-limit">'+settings.noResultsLimit+'</p></li>';
99+
output += '<li class="'+settings.cssPrefix+'cheader"><p class="'+settings.cssPrefix+'cheader-title">'+(settings.ResultsTextPrefix == '' ? '' : settings.ResultsTextPrefix+': ')+settings.noResultsText+'</p><p class="'+settings.cssPrefix+'cheader-limit">'+settings.noResultsLimit+'</p></li>';
98100
} else {
99101

100102
$.each(data, function(i, category){
@@ -103,7 +105,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103105
var limit = category['cheader']['limit'];
104106
var cnt = 0;
105107

106-
output += '<li class="'+settings.cssPrefix+'cheader"><p class="'+settings.cssPrefix+'cheader-title">'+category['cheader']['title']+'</p><p class="'+settings.cssPrefix+'cheader-limit">'+settings.resultsLimit.replace("%", category['cheader']['total']).replace("$", (category['cheader']['limit'] < category['cdata'].length ? category['cheader']['limit'] : category['cdata'].length))+'</p></li>';
108+
output += '<li class="'+settings.cssPrefix+'cheader"><p class="'+settings.cssPrefix+'cheader-title">'+(settings.ResultsTextPrefix == '' ? '' : settings.ResultsTextPrefix+': ')+category['cheader']['title']+'</p><p class="'+settings.cssPrefix+'cheader-limit">'+settings.resultsLimit.replace("%", category['cheader']['total']).replace("$", (category['cheader']['limit'] < category['cdata'].length ? category['cheader']['limit'] : category['cdata'].length))+'</p></li>';
107109

108110
var fillSearchFieldCode = (settings.fillSearchField) ? 'document.getElementById(\''+searchField.attr('id')+'\').value = \'%\';' : '';
109111
//var fillSearchFieldCode = 'document.getElementById(\''+searchField.attr('id')+'\').value = \'%\';';
@@ -128,7 +130,19 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128130
});
129131
}
130132

131-
resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top+searchField.outerHeight(), 'right' : '0'}).fadeIn();
133+
//resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top+searchField.outerHeight(), 'right' : '0'}).fadeIn();
134+
if(settings.resultBoxPosition == 'n'){
135+
resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top-resultBox.outerHeight(), 'left' : searchField.position().left+searchField.outerWidth()-resultBox.outerWidth()}).fadeIn();
136+
}
137+
if(settings.resultBoxPosition == 'e'){
138+
resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top, 'left' : searchField.position().left+searchField.outerWidth()}).fadeIn();
139+
}
140+
if(settings.resultBoxPosition == 's'){
141+
resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top+searchField.outerHeight(), 'left' : searchField.position().left+searchField.outerWidth()-resultBox.outerWidth()}).fadeIn();
142+
}
143+
if(settings.resultBoxPosition == 'w'){
144+
resultBox.html(output).css({'position' : 'absolute', 'top' : searchField.position().top, 'left' : searchField.position().left-resultBox.outerWidth()}).fadeIn();
145+
}
132146

133147
searchField.removeClass(settings.cssPrefix+'loading');
134148
}
@@ -150,6 +164,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150164
resultBox.fadeIn();
151165
} else if(searchField.val() == settings.searchFieldWatermark){
152166
searchField.val('');
167+
if(settings.minChars == 0) searchField.trigger('keyup');
153168
} else if (searchField.val() != ''){
154169
searchField.trigger('keyup');
155170
}

0 commit comments

Comments
 (0)