-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
132 lines (104 loc) · 3.44 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?
function httpGet($url, $port = '80') {
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_URL, $url);
@curl_setopt ($ch, CURLOPT_PORT , $port);
//curl_setopt($ch, CURLOPT_POST,1);
//curl_setopt($ch, CURLOPT_POSTFIELDS,$postVars);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
@curl_setopt( $ch, CURLOPT_AUTOREFERER, 1 );
@curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
//@curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$rawResponse = @curl_exec($ch);
if(curl_errno($ch)) {
exit("Curl error for url {$url} and port {$port}: " . curl_error($ch));
@curl_close($ch);
return(false);
}
@curl_close($ch);
return($rawResponse);
}
//$options = array("name" => "level", "multiple" => "multiple", "onchange" => "list.searchFilter()", "operator" => "in");
//$jsOptions = array("containerCssClass" => "span12", "placeholder" => "Select a State", "allowClear" => "true");
function select2($data, $url, $options, $jsOptions) {
if (!empty($url)) {
$data = json_decode(httpGet($url), true);
}
if (empty($options)) {
die("Select options is required");
}
$o = (object)$options;
$formatValue = function ($value) {
if ("true" == $value) {
return $value;
} else {
return '"'.$value.'"';
}
};
$f = function () use($jsOptions, $formatValue) {
$js = array();
foreach ($jsOptions as $key => $value) {
$js[] = ' '.$key.': '.$formatValue($value);
}
return join(",", $js);
};
$attr = "";
foreach ($options as $key => $value) {
$attr .= ' '.$key.'="'.$value.'"';
}
$select = '<select '.$attr.'>';
foreach ($data as $key => $value) {
$select .= '<option value="'.$key.'">'.$value.'</option>';
}
$select .= '</select>';
$select .= '
<script>
$(document).ready(function() {
$("select[name='.$o->name.']").select2({ '.$f().' });
});
</script>';
return $select;
}
//$options = array("name" => "category_id", "multiple" => "multiple", "onchange" => "list.searchFilter()", "class" => "span12", "data-placeholder" => "Избери категория");
//$jsOptions = array("allow_single_deselect" => true);
function select_chosen($data, $url, $options, $jsOptions) {
if (!empty($url)) {
$data = json_decode(httpGet($url), true);
}
if (empty($options)) {
die("Select options is required");
}
$o = (object)$options;
$formatValue = function ($value) {
if ("true" == $value) {
return $value;
} else {
return '"'.$value.'"';
}
};
$f = function () use($jsOptions, $formatValue) {
$js = array();
foreach ($jsOptions as $key => $value) {
$js[] = ' '.$key.': '.$formatValue($value);
}
return join(",", $js);
};
$attr = "";
foreach ($options as $key => $value) {
$attr .= ' '.$key.'="'.$value.'"';
}
$select = '<select '.$attr.'>';
foreach ($data as $key => $value) {
$select .= '<option value="'.$key.'">'.$value.'</option>';
}
$select .= '</select>';
$select .= '
<script>
jQuery(document).ready(function() {
jQuery("select[name='.$o->name.']").chosen({ '.$f().' });
});
</script>';
return $select;
}