PluginProbe
SQL Chart Builder / 2.3.3
SQL Chart Builder v2.3.3
3.0.5 3.0.4 3.0.3 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.3, at admin_metabox.php

304 lines 13.6 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 <p>
182 Legend block
183 <br>
184 <?php $guaven_sqlcharts_legend_position=get_post_meta($post->ID, 'guaven_sqlcharts_legend_position', true);?>
185 <select name="guaven_sqlcharts_legend_position" id="guaven_sqlcharts_legend_position">
186 <option value="default">Default</option>
187 <option value="top" <?php echo $guaven_sqlcharts_legend_position=='top'?"selected":''; ?>>Shop at the top</option>
188 <option value="bottom" <?php echo $guaven_sqlcharts_legend_position=='bottom'?"selected":''; ?>>Shop at the bottom</option>
189 <option value="left" <?php echo $guaven_sqlcharts_legend_position=='left'?"selected":''; ?>>Shop at the left</option>
190 <option value="right" <?php echo $guaven_sqlcharts_legend_position=='right'?"selected":''; ?>>Shop at the right</option>
191 <option value="hide" <?php echo $guaven_sqlcharts_legend_position=='hide'?"selected":''; ?>>Hide legend</option>
192 </select>
193 <br><small>Legend in a chart is Y values which usually appears at the top/right part of the graph</small>
194 </p>
195
196 <h4 class="gsql_h4">X and Y Axis Ticks (for Line and Bar charts)</h4>
197 <p>
198 <label for="guaven_sqlcharts_begin_with_0_x">
199 <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':''; ?>>
200 Force start X axes at 0
201 </label>
202
203 <label for="guaven_sqlcharts_begin_with_0_y">
204 <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':''; ?>>
205 Force start X axes at 0
206 </label>
207 </p>
208
209 <p>
210 <label for="guaven_sqlcharts_round_y_values">
211 <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':''; ?>>
212 Show only round numbers in Y axis ticks
213 </label>
214
215
216 <label for="guaven_sqlcharts_nostacked">
217 <input type="checkbox" name="guaven_sqlcharts_nostacked" id="guaven_sqlcharts_nostacked" value="1" <?php echo get_post_meta($post->ID, 'guaven_sqlcharts_nostacked', true)!=''?'checked':''; ?>
218 >Disable "stackedness" for datasets
219 </label>
220
221 </p>
222
223
224
225 <h4 class="gsql_h4">Remote MySQL Database Access Details</h4>
226
227 Leave empty if you are connecting to local DB.<p>
228 <input type="text" name="guaven_sqlcharts_dbhost" id="guaven_sqlcharts_dbhost" value="<?php
229 echo get_post_meta($post->ID, 'guaven_sqlcharts_dbhost', true);
230 ?>" placeholder="database host">
231
232 <input type="text" name="guaven_sqlcharts_dbname" id="guaven_sqlcharts_dbname" value="<?php
233 echo get_post_meta($post->ID, 'guaven_sqlcharts_dbname', true);
234 ?>" placeholder="database name">
235
236 <input type="text" name="guaven_sqlcharts_dblogin" id="guaven_sqlcharts_dblogin" value="<?php
237 echo get_post_meta($post->ID, 'guaven_sqlcharts_dblogin', true);
238 ?>" placeholder="database username">
239
240 <?php
241 $dbpass=get_post_meta($post->ID, 'guaven_sqlcharts_dbpass', true);
242 if(is_array($dbpass)){
243 $dbpass=guaven_sqlcharts_encrypt_decrypt('decrypt',$dbpass[1]);
244 }
245
246 ?>
247 <input type="password" name="guaven_sqlcharts_dbpass" id="guaven_sqlcharts_dbpass" value="<?php
248 echo $dbpass;
249 ?>" placeholder="database password">
250
251 </p>
252 <p>
253 <small>Note: WordPress supports MySQL only Databases, to use non-MySQL databases some custom PHP code&driver would be needed.
254 To discuss how to build that you can <a target="_blank" href="https://guaven.com/contact/solution-request/">contact us</a>.
255
256 </small><br>
257 </p>
258
259 <hr>
260
261
262 <style>
263 .gsql_h4{color:#4693dd;margin-top:5px;margin-bottom:5px}
264 .wpdberror{color:white;background: red;padding:10px;}
265 #guaven_sqlcharts_begin_with_0_y{margin-left:24px;}
266 </style>
267 <script>
268 if (jQuery("#post").attr("action").indexOf("#")==-1){
269 jQuery("#post").attr("action",jQuery("#post").attr("action")+"#sqldemo");
270 }
271 </script>
272 <?php
273 if (get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true) != '') {
274 if (strpos(get_post_meta($post->ID, 'guaven_sqlcharts_graphtype', true), "_l") !== false)
275 $postfix = '_2';
276 else
277 $postfix = '';
278 ?>
279 <div class="gf-alert-success gf-alert">
280 <h4>
281 Text shortcode: [gvn_schart<?php
282 echo $postfix;
283 ?> id="<?php
284 echo $post->ID;
285 ?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]
286 <br>
287 <br>
288 PHP shorcode: &lt;?php echo do_shortcode(' [gvn_schart<?php
289 echo $postfix;
290 ?> id="<?php
291 echo $post->ID;
292 ?>"<?php echo get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':''; ?>]'); ?&gt;
293 </h4>
294 <p>Note: Shortcodes supports width and height attributes. F.e. [gvn_schart<?php
295 echo $postfix;
296 ?> id="1" width="500" height="400"]. If no attributes, default width, height (which you enter in this page above) will be used.
297 </div>
298 <hr>
299 <h3 id="sqldemo" name="sqldemo">Save Changes and See Live Demo</h3>
300 <?php
301 echo do_shortcode(' [gvn_schart' . $postfix . ' id="' . $post->ID . '" '.(get_post_meta($post->ID,'guaven_sqlcharts_tablepart',true)!=''?' table="1"':'').']');
302
303 }
304