root/trunk/includes/smarty_plugins/function.html_access_options.php
| Revision 1, 3.6 KB (checked in by anonymous, 7 years ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /****************************************************** Open .node *** |
| 3 | * Description: |
| 4 | * Status: Stable. |
| 5 | * Author: Alexandre Dath <alexandre@dotnode.com> |
| 6 | * $Id$ |
| 7 | * |
| 8 | * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software Foundation, |
| 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 | ******************** http://opensource.ikse.net/projects/dotnode ***/ |
| 24 | |
| 25 | /** |
| 26 | * Smarty plugin |
| 27 | * @package Smarty |
| 28 | * @subpackage plugins |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * Smarty {html_options} function plugin |
| 34 | * |
| 35 | * Type: function<br> |
| 36 | * Name: html_options<br> |
| 37 | * Input:<br> |
| 38 | * - name (optional) - string default "select" |
| 39 | * - values (required if no options supplied) - array |
| 40 | * - options (required if no values supplied) - associative array |
| 41 | * - selected (optional) - string default not set |
| 42 | * - output (required if not options supplied) - array |
| 43 | * Purpose: Prints the list of <option> tags generated from |
| 44 | * the passed parameters |
| 45 | * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image} |
| 46 | * (Smarty online manual) |
| 47 | * @param array |
| 48 | * @param Smarty |
| 49 | * @return string |
| 50 | * @uses smarty_function_escape_special_chars() |
| 51 | */ |
| 52 | function smarty_function_html_access_options($params, &$smarty) |
| 53 | { |
| 54 | global $labels; |
| 55 | global $access_list; |
| 56 | require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); |
| 57 | |
| 58 | $name = null; |
| 59 | $values = null; |
| 60 | $options = $labels['access']; |
| 61 | $selected = array(); |
| 62 | $output = null; |
| 63 | |
| 64 | $extra = ''; |
| 65 | |
| 66 | foreach($params as $_key => $_val) { |
| 67 | switch($_key) { |
| 68 | case 'name': |
| 69 | case 'table': |
| 70 | case 'field': |
| 71 | $$_key = (string)$_val; |
| 72 | break; |
| 73 | |
| 74 | default: |
| 75 | if(!is_array($_val)) { |
| 76 | $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; |
| 77 | } else { |
| 78 | $smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); |
| 79 | } |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | array_push($selected, $access_list[$table][$field]); |
| 85 | |
| 86 | // print "<pre>"; print_r($selected); |
| 87 | |
| 88 | if (!isset($options) && !isset($values)) |
| 89 | return ''; /* raise error here? */ |
| 90 | |
| 91 | $_html_result = ''; |
| 92 | |
| 93 | if (is_array($options)) { |
| 94 | |
| 95 | foreach ($options as $_key=>$_val) |
| 96 | $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); |
| 97 | |
| 98 | } else { |
| 99 | |
| 100 | foreach ((array)$values as $_i=>$_key) { |
| 101 | $_val = isset($output[$_i]) ? $output[$_i] : ''; |
| 102 | $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | if(!empty($name)) { |
| 108 | $_html_result = '<img src="/img/lock.gif" alt="lock" /> <select name="' . $name . '[' . $table . '][' . $field . ']"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; |
| 109 | } |
| 110 | |
| 111 | return $_html_result; |
| 112 | |
| 113 | } |
| 114 | /* vim: set expandtab: */ |
| 115 | |
| 116 | ?> |
Note: See TracBrowser
for help on using the browser.
