PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/ php-ppcms/lib/Smarty-2.6.14/libs/plugins/function.pp_inputcheckboxall.php

http://php-ppcms.googlecode.com/
PHP | 152 lines | 89 code | 24 blank | 39 comment | 13 complexity | 99fe604b9388b588c3edda737d556633 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty {pp_inputcheckboxall} function plugin
  9. *
  10. * File: function.pp_inputcheckboxall.php<br>
  11. * Type: function<br>
  12. * Name: pp_inputcheckboxall<br>
  13. * Date: 24.Feb.2003<br>
  14. * Purpose: Prints out a list of checkbox input types<br>
  15. * Input:<br>
  16. * - name (optional) - string default "checkbox"
  17. * - value (required) - array
  18. * - options (optional) - associative array
  19. * - checked (optional) - array default not set
  20. * - separator (optional) - ie <br> or &nbsp;
  21. * - output (optional) - the output next to each checkbox
  22. * - assign (optional) - assign the output as an array to this variable
  23. * Examples:
  24. * <pre>
  25. * {pp_inputcheckboxall values=$ids output=$names}
  26. * {pp_inputcheckboxall values=$ids name='box' separator='<br>' output=$names}
  27. * {pp_inputcheckboxall values=$ids checked=$checked separator='<br>' output=$names}
  28. * </pre>
  29. * @link http://smarty.php.net/manual/en/language.function.html.inputcheckbox.php {pp_inputcheckboxall}
  30. * (Smarty online manual)
  31. * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
  32. * @author credits to Monte Ohrt <monte at ohrt dot com>
  33. * @version 1.0
  34. * @param array
  35. * @param Smarty
  36. * @return string
  37. * @uses smarty_function_escape_special_chars()
  38. */
  39. function smarty_function_pp_inputcheckboxall($params, &$smarty)
  40. {
  41. require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
  42. $name = NULL;
  43. $value = NULL;
  44. $values = NULL;
  45. $selected = NULL;
  46. $target = NULL;
  47. $separator = '';
  48. $label = true;
  49. $output = NULL;
  50. $onclick = NULL;
  51. $extra = '';
  52. foreach($params as $_key => $_val) {
  53. switch($_key) {
  54. case 'name':
  55. case 'separator':
  56. $$_key = $_val;
  57. break;
  58. case 'label':
  59. $$_key = (bool)$_val;
  60. break;
  61. case 'option':
  62. $$_key = (array)$_val;
  63. break;
  64. case 'value':
  65. case 'output':
  66. $$_key = (string)$_val;
  67. break;
  68. case 'values':
  69. $$_key = (string)$_val;
  70. break;
  71. case 'onclick':
  72. $$_key = (string)$_val;
  73. break;
  74. case 'output':
  75. $$_key = array_values((array)$_val);
  76. break;
  77. case 'checked':
  78. case 'selected':
  79. $selected = array_map('strval', array_values((array)$_val));
  80. break;
  81. case 'class':
  82. break;
  83. case 'inputcheckbox':
  84. $smarty->trigger_error('pp_inputcheckboxall: the use of the "inputcheckbox" attribute is deprecated, use "options" instead', E_USER_WARNING);
  85. $options = (array)$_val;
  86. break;
  87. case 'assign':
  88. break;
  89. default:
  90. if(!is_array($_val)) {
  91. $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
  92. } else {
  93. $smarty->trigger_error("pp_inputcheckboxall: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
  94. }
  95. break;
  96. }
  97. }
  98. //
  99. $_html_result = smarty_function_pp_inputcheckboxall_output($name, $value, $values, $selected, $onclick, $extra, $separator, $label);
  100. return $_html_result;
  101. }
  102. function smarty_function_pp_inputcheckboxall_output($name, $value, $values, $selected, $onclick, $extra, $separator, $label) {
  103. $_output = '';
  104. if( !isset($name) ) {
  105. $name = 'sla';
  106. }
  107. if( !isset($values) || $values == '' ) {
  108. $values = 'cb';
  109. }
  110. if ($label) $_output .= '<label>';
  111. $_output .= '<input type="checkbox" name="'
  112. . smarty_function_escape_special_chars($name) . '" value="'
  113. . smarty_function_escape_special_chars($value) . '"';
  114. $_output .= ' onClick="PJS.list.selectAll(this, \'' . $values . '\');';
  115. if( isset($onclick) && $onclick != '' ) {
  116. $_output .= '' . $onclick . '';
  117. }
  118. $_output .= '"';
  119. if( is_array($selected) && in_array((string)$value, $selected)) {
  120. $_output .= ' checked="checked"';
  121. }
  122. $_output .= $extra . '>' . $output;
  123. if ($label) $_output .= '</label>';
  124. $_output .= $separator;
  125. return $_output;
  126. }
  127. //
  128. ?>