full_report.php is not reachable via the user interface, and does not check any ACLs...
[openemr.git] / phpmyadmin / libraries / plugin_interface.lib.php
blobae4c04e583984575196c7828b32b1a9d35eceeb0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Generic plugin interface.
6 * @version $Id$
7 */
9 /**
10 * array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
12 * Reads all plugin information from directory $plugins_dir.
14 * @uses ksort()
15 * @uses opendir()
16 * @uses readdir()
17 * @uses is_file()
18 * @uses eregi()
19 * @param string $plugins_dir directrory with plugins
20 * @param mixed $plugin_param parameter to plugin by which they can decide whether they can work
21 * @return array list of plugins
23 function PMA_getPlugins($plugins_dir, $plugin_param)
25 /* Scan for plugins */
26 $plugin_list = array();
27 if ($handle = @opendir($plugins_dir)) {
28 $is_first = 0;
29 while ($file = @readdir($handle)) {
30 // In some situations, Mac OS creates a new file for each file
31 // (for example ._csv.php) so the following regexp
32 // matches a file which does not start with a dot but ends
33 // with ".php"
34 if (is_file($plugins_dir . $file) && preg_match('@^[^\.](.)*\.php$@i', $file)) {
35 include $plugins_dir . $file;
39 ksort($plugin_list);
40 return $plugin_list;
43 /**
44 * string PMA_getString(string $name)
46 * returns locale string for $name or $name if no locale is found
48 * @uses $GLOBALS
49 * @param string $name for local string
50 * @return string locale string for $name
52 function PMA_getString($name)
54 return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
57 /**
58 * string PMA_pluginCheckboxCheck(string $section, string $opt)
60 * returns html input tag option 'checked' if plugin $opt should be set by config or request
62 * @uses $_REQUEST
63 * @uses $GLOBALS['cfg']
64 * @uses $GLOBALS['timeout_passed']
65 * @param string $section name of config section in
66 * $GLOBALS['cfg'][$section] for plugin
67 * @param string $opt name of option
68 * @return string hmtl input tag option 'checked'
70 function PMA_pluginCheckboxCheck($section, $opt)
72 if ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
73 (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt])) {
74 return ' checked="checked"';
76 return '';
79 /**
80 * string PMA_pluginGetDefault(string $section, string $opt)
82 * returns default value for option $opt
84 * @uses htmlspecialchars()
85 * @uses $_REQUEST
86 * @uses $GLOBALS['cfg']
87 * @uses $GLOBALS['timeout_passed']
88 * @param string $section name of config section in
89 * $GLOBALS['cfg'][$section] for plugin
90 * @param string $opt name of option
91 * @return string default value for option $opt
93 function PMA_pluginGetDefault($section, $opt)
95 if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
96 return htmlspecialchars($_REQUEST[$opt]);
97 } elseif (isset($GLOBALS['cfg'][$section][$opt])) {
98 $matches = array();
99 /* Possibly replace localised texts */
100 if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
101 $val = $GLOBALS['cfg'][$section][$opt];
102 foreach($matches[0] as $match) {
103 if (isset($GLOBALS[$match])) {
104 $val = str_replace($match, $GLOBALS[$match], $val);
107 return htmlspecialchars($val);
108 } else {
109 return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
112 return '';
116 * string PMA_pluginIsActive(string $section, string $opt, string $val)
118 * returns html input tag option 'checked' if option $opt should be set by config or request
120 * @uses $_REQUEST
121 * @uses $GLOBALS['cfg']
122 * @uses $GLOBALS['timeout_passed']
123 * @param string $section name of config section in
124 * $GLOBALS['cfg'][$section] for plugin
125 * @param string $opt name of option
126 * @param string $val value of option to check against
127 * @return string html input tag option 'checked'
129 function PMA_pluginIsActive($section, $opt, $val)
131 if (! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
132 if ($_REQUEST[$opt] == $val) {
133 return ' checked="checked"';
135 } elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
136 return ' checked="checked"';
138 return '';
142 * string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
144 * returns html radio form element for plugin choice
146 * @uses PMA_pluginIsActive()
147 * @uses PMA_getString()
148 * @param string $section name of config section in
149 * $GLOBALS['cfg'][$section] for plugin
150 * @param string $name name of radio element
151 * @param array &$list array with plugin configuration defined in plugin file
152 * @param string $cfgname name of config value, if none same as $name
153 * @return string html input radio tag
155 function PMA_pluginGetChoice($section, $name, &$list, $cfgname = NULL)
157 if (!isset($cfgname)) {
158 $cfgname = $name;
160 $ret = '';
161 foreach ($list as $plugin_name => $val) {
162 $ret .= '<!-- ' . $plugin_name . ' -->' . "\n";
163 $ret .= '<input type="radio" name="' . $name . '" value="' . $plugin_name . '"'
164 . ' id="radio_plugin_' . $plugin_name . '"'
165 . ' onclick="if(this.checked) { hide_them_all();';
166 if (isset($val['force_file'])) {
167 $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;';
169 $ret .= ' document.getElementById(\'' . $plugin_name . '_options\').style.display = \'block\'; };'
170 .' return true"'
171 . PMA_pluginIsActive($section, $cfgname, $plugin_name) . '/>' . "\n";
172 $ret .= '<label for="radio_plugin_' . $plugin_name . '">'
173 . PMA_getString($val['text']) . '</label>' . "\n";
174 $ret .= '<br /><br />' . "\n";
176 return $ret;
180 * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
182 * returns single option in a table row
184 * @uses PMA_getString()
185 * @uses PMA_pluginCheckboxCheck()
186 * @uses PMA_pluginGetDefault()
187 * @param string $section name of config section in
188 * $GLOBALS['cfg'][$section] for plugin
189 * @param string $plugin_name unique plugin name
190 * @param string $id option id
191 * @param array &$opt plugin option details
192 * @return string table row with option
194 function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
196 $ret = "\n";
197 if ($opt['type'] == 'bool') {
198 $ret .= '<div class="formelementrow">' . "\n";
199 $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
200 . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
201 . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
202 if (isset($opt['force'])) {
203 /* Same code is also few lines lower, update both if needed */
204 $ret .= ' onclick="if (!this.checked &amp;&amp; '
205 . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
206 . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
207 . 'return false; else return true;"';
209 $ret .= ' />';
210 $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
211 . PMA_getString($opt['text']) . '</label>';
212 $ret .= '</div>' . "\n";
213 } elseif ($opt['type'] == 'text') {
214 $ret .= '<div class="formelementrow">' . "\n";
215 $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
216 . PMA_getString($opt['text']) . '</label>';
217 $ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
218 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
219 . ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
220 . (isset($opt['size']) ? ' size="' . $opt['size'] . '"' : '')
221 . (isset($opt['len']) ? ' maxlength="' . $opt['len'] . '"' : '') . ' />';
222 $ret .= '</div>' . "\n";
223 } elseif ($opt['type'] == 'message_only') {
224 $ret .= '<div class="formelementrow">' . "\n";
225 $ret .= '<p class="desc">' . PMA_getString($opt['text']) . '</p>';
226 $ret .= '</div>' . "\n";
227 } elseif ($opt['type'] == 'select') {
228 $ret .= '<div class="formelementrow">' . "\n";
229 $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
230 . PMA_getString($opt['text']) . '</label>';
231 $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
232 . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
233 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
234 foreach($opt['values'] as $key => $val) {
235 $ret .= '<option value="' . $key . '"';
236 if ($key == $default) {
237 $ret .= ' selected="selected"';
239 $ret .= '>' . PMA_getString($val) . '</option>';
241 $ret .= '</select>';
242 $ret .= '</div>' . "\n";
243 } elseif ($opt['type'] == 'hidden') {
244 $ret .= '<input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
245 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' />';
246 } elseif ($opt['type'] == 'bgroup') {
247 $ret .= '<fieldset><legend>';
248 /* No checkbox without name */
249 if (!empty($opt['name'])) {
250 $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
251 . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
252 . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
253 if (isset($opt['force'])) {
254 /* Same code is also few lines higher, update both if needed */
255 $ret .= ' onclick="if (!this.checked &amp;&amp; '
256 . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
257 . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
258 . 'return false; else return true;"';
260 $ret .= ' />';
261 $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
262 . PMA_getString($opt['text']) . '</label>';
263 } else {
264 $ret .= PMA_getString($opt['text']);
266 $ret .= '</legend>';
267 } elseif ($opt['type'] == 'egroup') {
268 $ret .= '</fieldset>';
269 } else {
270 /* This should be seen only by plugin writers, so I do not thing this
271 * needs translation. */
272 $ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
274 if (isset($opt['doc'])) {
275 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
277 $ret .= "\n";
278 return $ret;
282 * string PMA_pluginGetOptions(string $section, array &$list)
284 * return html fieldset with editable options for plugin
286 * @uses PMA_getString()
287 * @uses PMA_pluginGetOneOption()
288 * @param string $section name of config section in $GLOBALS['cfg'][$section]
289 * @param array &$list array with plugin configuration defined in plugin file
290 * @return string html fieldset with plugin options
292 function PMA_pluginGetOptions($section, &$list)
294 $ret = '';
295 // Options for plugins that support them
296 foreach ($list as $plugin_name => $val) {
297 $ret .= '<fieldset id="' . $plugin_name . '_options" class="options">';
298 $ret .= '<legend>' . PMA_getString($val['options_text']) . '</legend>';
299 $count = 0;
300 if (isset($val['options']) && count($val['options']) > 0) {
301 foreach ($val['options'] as $id => $opt) {
302 if ($opt['type'] != 'hidden') $count++;
303 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
306 if ($count == 0) {
307 $ret .= $GLOBALS['strNoOptions'];
309 $ret .= '</fieldset>';
311 return $ret;
315 * string PMA_pluginGetJavascript(array &$list)
317 * return html/javascript code which is needed for handling plugin stuff
319 * @param array &$list array with plugin configuration defined in plugin file
320 * @return string html fieldset with plugin options
322 function PMA_pluginGetJavascript(&$list) {
323 $ret = '
324 <script type="text/javascript">
325 //<![CDATA[
326 function hide_them_all() {
328 foreach ($list as $plugin_name => $val) {
329 $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n";
331 $ret .= '
334 function init_options() {
335 hide_them_all();
337 foreach ($list as $plugin_name => $val) {
338 $ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n";
339 if (isset($val['force_file'])) {
340 $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;' . "\n";
342 $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n";
343 $ret .= ' } else ' . "\n";
345 $ret .= '
351 function match_file(fname) {
352 farr = fname.toLowerCase().split(".");
353 if (farr.length != 0) {
354 len = farr.length
355 if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--;
356 switch (farr[len - 1]) {
358 foreach ($list as $plugin_name => $val) {
359 $ret .= 'case "' . $val['extension'] . '" :';
360 $ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;';
361 $ret .= 'init_options();';
362 $ret .= 'break;' . "\n";
364 $ret .='
368 //]]>
369 </script>
371 return $ret;