PluginProbe
SQL Chart Builder / 2.3.0
SQL Chart Builder v2.3.0
3.0.2 3.0.1 trunk 1.0.2 1.0.3 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.7.1 2.3.7.2 2.3.8 3.0.0
sql-chart-builder / admin_metabox.php

admin_metabox.php in SQL Chart Builder 2.3.0, at admin_metabox.php

280 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 die;
4 }
5
6 global $post;
7 wp_nonce_field('meta_box_nonce_action', 'meta_box_nonce_field');
8
9
10 ?>
11 <div style="width:calc(100% - 110px);float:left">
12
13 <h3>Required parameters</h3>
14
15 <h4 class="gsql_h4">Step 1: Choose a chart type</h4>
16
17 <p>
18 <select name="guaven_sqlcharts_graphtype" id="guaven_sqlcharts_graphtype">
19 <option value="pie_l" <?php $smfootnote='';
20 $guaven_sqlcharts_graphtype = get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true);
21 echo ($guaven_sqlcharts_graphtype == 'pie_l' ? 'selected' : '');?>>Pie Chart</option>
22 <option value="line_l" <?php echo ($guaven_sqlcharts_graphtype == 'line_l' ? 'selected' : '');?>>Line Chart</option>
23 <option value="donut_l" <?php echo ($guaven_sqlcharts_graphtype == 'donut_l' ? 'selected' : '');?>>Donut Chart</option>
24 <option value="bar_l" <?php echo ($guaven_sqlcharts_graphtype == 'bar_l' ? 'selected' : '');?>>Vertical Bar Chart</option>
25 <option value="horizontalbar_l" <?php echo ($guaven_sqlcharts_graphtype == 'horizontalbar_l' ? 'selected' : '');?>>Horizontal Bar Chart</option>
26 <option value="area_l" <?php echo ($guaven_sqlcharts_graphtype == 'area_l' ? 'selected' : '');?>>Area Chart</option>
27 <option value="polar_l" <?php echo ($guaven_sqlcharts_graphtype == 'polar_l' ? 'selected' : '');?>>Polar Area</option>
28
29 <?php
30 if ($guaven_sqlcharts_graphtype!='' and strpos($guaven_sqlcharts_graphtype,'_l')===false) {
31 ?>
32 <option value="pie" <?php echo ($guaven_sqlcharts_graphtype == 'pie' ? 'selected' : '');?>>Google Chart - Pie *</option>
33 <option value="3dpie" <?php echo ($guaven_sqlcharts_graphtype == '3dpie' ? 'selected' : '');?>>Google Chart - 3D Pie *</option>
34 <option value="column" <?php echo ($guaven_sqlcharts_graphtype == 'column' ? 'selected' : '');?>>Google Chart - Column *</option>
35 <option value="bar" <?php echo ($guaven_sqlcharts_graphtype == 'bar' ? 'selected' : '');?>>Google Chart - Bar *</option>
36 <option value="area" <?php echo ($guaven_sqlcharts_graphtype == 'area' ? 'selected' : '');?>>Google Chart - Area *</option>
37 <?php
38 $smfootnote='<br><small>
39 * Google Chart options are deprecated and will be removed since 3.0 version.
40 Currently those options support single queries only. Use non-Google Chart options above.
41 </small>';
42 } ?>
43 </select>
44 <?php
45 echo $smfootnote;
46 ?>
47 <br>
48 </p>
49
50 <p><label><input type="checkbox" name="guaven_sqlcharts_tablepart" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_tablepart', true)!=''?'checked':''; ?>>
51 Show table-view data below the graph</lable></p>
52 </div>
53 <div style="width:110px;float:left"><img src="<?php echo plugin_dir_url( __FILE__ ) . 'asset/img/pie.png';?>" class="charttype" style="opacity:0.5;margin-top:20px;float:right;width:100px"></div>
54 <div style="clear:both;display:block"></div>
55 <hr>
56
57
58
59
60 <h4 class="gsql_h4">Step 2: Enter Your SQL Query </h4>
61 <p>
62 <textarea name="guaven_sqlcharts_code" id="guaven_sqlcharts_code" style="width:100%" rows="6"><?php
63 echo (get_post_meta($post->ID, 'guaven_sqlcharts_code', true) != '' ? get_post_meta($post->ID, 'guaven_sqlcharts_code', true) : '');
64 ?>
65 </textarea>
66 <br><small>Separate sql queries with ";" if you would like to use multiple queries to build comparison graphs. <a href="https://www.dropbox.com/s/l9xggkeliqdswo9/mysqlchart_example.png?dl=0" target="_blank">See example</a>
67 <br>
68 <b>Some supported dynamic tags can be used in your query: {current_user_id},{current_user_login},{current_user_email},{current_user_display_name}.</b>
69 </small>
70 </p>
71
72 <hr>
73
74
75
76
77
78 <h4 class="gsql_h4">Step 3: Set Arguments and Values for a Chart - See <a href="https://www.dropbox.com/s/5tt0se24x6hfas0/mysqlchart_example-1.png?dl=0" target="_blank">Example 1</a>
79 and <a href="https://www.dropbox.com/s/s8ygh1zngo2ajzi/mysqlchart_example-4.png?dl=0" target="_blank">Example 2</a></h4>
80 <p>
81 Label for X axis: <br><input type="text" name="guaven_sqlcharts_xarg_l" id="guaven_sqlcharts_xarg_l" value="<?php
82 echo get_post_meta($post->ID, 'guaven_sqlcharts_xarg_l', true);
83 ?>">
84 <br>
85 <small>This is just label text for query argument, you can type any desired name here.</small>
86 </p>
87 <p>
88 SQL field name of X axis:
89 <br>
90 <input type="text" name="guaven_sqlcharts_xarg_s" id="guaven_sqlcharts_xarg_s" value="<?php
91 echo get_post_meta($post->ID, 'guaven_sqlcharts_xarg_s', true);
92 ?>"><br>
93 <small>Write corresponding SQL field name here. f.e. display_name, post_date</small>
94 </p>
95
96 <p>
97 Label for Y axis: <br><input type="text" name="guaven_sqlcharts_yarg_l" id="guaven_sqlcharts_yarg_l" value="<?php
98 echo get_post_meta($post->ID, 'guaven_sqlcharts_yarg_l', true);
99 ?>">
100 <br><small>This is just label text for query's main value, you can type any desired name here.<br>
101 Use ";" separated label names if you have more than one query inside SQL CODE field.</small>
102 </p>
103 <p>
104 SQL field name of Y axis:
105 <br>
106 <input type="text" name="guaven_sqlcharts_yarg_s" id="guaven_sqlcharts_yarg_s" value="<?php
107 echo get_post_meta($post->ID, 'guaven_sqlcharts_yarg_s', true);
108 ?>"><br>
109 <small>Write corresponding SQL field name here. f.e. post_count) - Use one single output name even if you have multiple queries in SQL CODE field.</small>
110
111 </p>
112
113 <hr>
114 <h3>Optional parameters</h3>
115
116
117 <h4 class="gsql_h4">Dynamic filters - See <a href="https://www.dropbox.com/s/6xa6gk7uc75b8me/mysqlchart_example-2.png?dl=0" target="_blank">Example Settings</a>
118 and <a href="https://www.dropbox.com/s/fq1gnqcqdbj65ch/mysqlchart_example-3.png?dl=0" target="_blank">Example Demo</a>
119 </h4>
120 <p>By using this section you can create dynamic variables inside SQL code. It also creates corresponding dynamic input form above each chart. <a class="btn button dynamicfieldbutton">Show/Hide</a></p>
121 <script>
122 jQuery(".dynamicfieldbutton").click(function(){jQuery(".dynamicfielddiv").toggle()});
123 plugindirurl='<?php echo plugin_dir_url( __FILE__ ) . 'asset/img/'; ?>';
124 jQuery("#guaven_sqlcharts_graphtype").change(function(){
125 jQuery(".charttype").attr("src",plugindirurl+jQuery(this).val().replace("_l","").replace("column","bar")+'.png');
126 });
127 jQuery("#guaven_sqlcharts_graphtype").trigger('change');
128
129 </script>
130 <div class="dynamicfielddiv" style="display:none; padding: 10px; background: whitesmoke;">
131 <p style="font-weight:bold">Enter dynamic filter variables using the format described below:</p>
132 <textarea name="guaven_sqlcharts_variables" id="guaven_sqlcharts_variables" style="width:100%" rows="2"><?php
133 echo (get_post_meta($post->ID, 'guaven_sqlcharts_variables', true) != '' ? get_post_meta($post->ID, 'guaven_sqlcharts_variables', true) : '');
134 ?>
135 </textarea>
136 <br><p>Use this format: <i>variable_name~default_value~variable_label~variable_type | variable_name~default_value~variable_label~variable_type</i> etc.<br>
137 <ul style="padding-left:20px"><li>variable_name - any single name you want.</li><li>
138 default_value - default value when no any variable chosen by a user</li><li>
139 variable_label - Label which would be visible at a form above the chart</li><li>
140 variable_type - number, text or date</li><li>
141 ~ is a separator between variable elements.</li><li>
142 | is a separator between variables</li></ul>
143
144 For example if to put <b>limit_tag~10~Count~number | post_date_tag~2010-07-05 17:25:18~Date Published~date</b> here,
145 then you can use this SQL code <b>select * from wp_posts where post_date<{post_date_tag} limit {limit_tag}</b> in SQL CODE field.
146 {post_date_tag} and {limit_tag} would be replaced with dynamic variables.
147 So, the plugin will automatically recognize it and put corresponding selectboxes above the chart. <br></p>
148 <p><label><input type="checkbox" name="guaven_sqlcharts_formpartrole" value="1"
149 <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_formpartrole', true)!=''?'checked':''; ?>>
150 Hide dynamic filters form from not-loggedin users at frontend. </label></p>
151
152 <p><label>Submit button text (default is "OK") <input type="text" name="guaven_sqlcharts_formpartbutton" value="<?php
153 echo esc_attr(get_post_meta($post->ID, 'guaven_sqlcharts_formpartbutton', true) ); ?>" placeholder="Submit button text"></label></p>
154
155 </div>
156
157 <hr>
158
159
160 <h4 class="gsql_h4">Width and height (with px. don't type px itself, just numbers)</h4>
161 <p>
162
163 <input type="number" name="guaven_sqlcharts_chartwidth" id="guaven_sqlcharts_chartwidth" value="<?php
164 echo get_post_meta($post->ID, 'guaven_sqlcharts_chartwidth', true);
165 ?>">
166
167 <input type="number" name="guaven_sqlcharts_chartheight" id="guaven_sqlcharts_chartheight" value="<?php
168 echo get_post_meta($post->ID, 'guaven_sqlcharts_chartheight', true);
169 ?>">
170 </p>
171
172 <p>
173 Color scheme (comma separated #RGB colors. f.e. <i>#FF0000</i> or <i>#00FF00,#BBCC00</i> ).
174 <br>
175 <input type="text" name="guaven_sqlcharts_colors" id="guaven_sqlcharts_colors" value="<?php
176 echo get_post_meta($post->ID, 'guaven_sqlcharts_colors', true);
177 ?>" style="width:500px">
178 <br><small>Leave empty if you want random colors</small>
179 </p>
180
181 <h4 class="gsql_h4">X and Y Axis Ticks (for Line and Bar charts)</h4>
182 <p>
183 <label for="guaven_sqlcharts_begin_with_0_x">
184 <input type="checkbox" name="guaven_sqlcharts_begin_with_0_x" id="guaven_sqlcharts_begin_with_0_x" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_begin_with_0_x', true)!=''?'checked':''; ?>>
185 Force start X axes at 0
186 </label>
187
188 <label for="guaven_sqlcharts_begin_with_0_y">
189 <input type="checkbox" name="guaven_sqlcharts_begin_with_0_y" id="guaven_sqlcharts_begin_with_0_y" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_begin_with_0_y', true)!=''?'checked':''; ?>>
190 Force start X axes at 0
191 </label>
192 </p>
193
194 <p>
195 <label for="guaven_sqlcharts_round_y_values">
196 <input type="checkbox" name="guaven_sqlcharts_round_y_values" id="guaven_sqlcharts_round_y_values" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_round_y_values', true)!=''?'checked':''; ?>>
197 Show only round numbers in Y axis ticks
198 </label>
199 </p>
200
201 <h4 class="gsql_h4">Remote MySQL Database Access Details</h4>
202
203 Leave empty if you are connecting to local DB.<p>
204 <input type="text" name="guaven_sqlcharts_dbhost" id="guaven_sqlcharts_dbhost" value="<?php
205 echo get_post_meta($post->ID, 'guaven_sqlcharts_dbhost', true);
206 ?>" placeholder="database host">
207
208 <input type="text" name="guaven_sqlcharts_dbname" id="guaven_sqlcharts_dbname" value="<?php
209 echo get_post_meta($post->ID, 'guaven_sqlcharts_dbname', true);
210 ?>" placeholder="database name">
211
212 <input type="text" name="guaven_sqlcharts_dblogin" id="guaven_sqlcharts_dblogin" value="<?php
213 echo get_post_meta($post->ID, 'guaven_sqlcharts_dblogin', true);
214 ?>" placeholder="database username">
215
216 <?php
217 $dbpass=get_post_meta($post->ID, 'guaven_sqlcharts_dbpass', true);
218 if(is_array($dbpass)){
219 $dbpass=guaven_sqlcharts_encrypt_decrypt('decrypt',$dbpass[1]);
220 }
221
222 ?>
223 <input type="password" name="guaven_sqlcharts_dbpass" id="guaven_sqlcharts_dbpass" value="<?php
224 echo $dbpass;
225 ?>" placeholder="database password">
226
227 </p>
228 <p>
229 <small>Note: WordPress supports MySQL only Databases, to use non-MySQL databases some custom PHP code&driver would be needed.
230 To discuss how to build that you can <a target="_blank" href="https://guaven.com/contact/solution-request/">contact us</a>.
231
232 </small><br>
233 </p>
234
235 <hr>
236
237
238 <style>
239 .gsql_h4{color:#4693dd;margin-top:5px;margin-bottom:5px}
240 .wpdberror{color:white;background: red;padding:10px;}
241 #guaven_sqlcharts_begin_with_0_y{margin-left:24px;}
242 </style>
243 <script>
244 if (jQuery("#post").attr("action").indexOf("#")==-1){
245 jQuery("#post").attr("action",jQuery("#post").attr("action")+"#sqldemo");
246 }
247 </script>
248 <?php
249 if (get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true) != '') {
250 if (strpos(get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true), "_l") !== false)
251 $postfix = '_2';
252 else
253 $postfix = '';
254 ?>
255 <div class="gf-alert-success gf-alert">
256 <h4>
257 Text shortcode: [gvn_schart<?php
258 echo $postfix;
259 ?> id="<?php
260 echo $post->ID;
261 ?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]
262 <br>
263 <br>
264 PHP shorcode: &lt;?php echo do_shortcode(' [gvn_schart<?php
265 echo $postfix;
266 ?> id="<?php
267 echo $post->ID;
268 ?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]'); ?&gt;
269 </h4>
270 <p>Note: Shortcodes supports width and height attributes. F.e. [gvn_schart<?php
271 echo $postfix;
272 ?> id="1" width="500" height="400"]. If no attributes, default width, height (which you enter in this page above) will be used.
273 </div>
274 <hr>
275 <h3 id="sqldemo" name="sqldemo">Save Changes and See Live Demo</h3>
276 <?php
277 echo do_shortcode(' [gvn_schart' . $postfix . ' id="' . $post->ID . '" '.(get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':'').']');
278
279 }
280