PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_flexicontent/elements/fccheckbox.php

http://flexicontent.googlecode.com/
PHP | 135 lines | 81 code | 20 blank | 34 comment | 20 complexity | 96e644a9baf65b64dba96f2b38b902c3 MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @version 1.5 stable $Id: fccheckbox.php 967 2011-11-21 00:01:36Z ggppdk $
  4. * @package Joomla
  5. * @subpackage FLEXIcontent
  6. * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
  7. * @author ggppdk
  8. * @license GNU/GPL v2
  9. *
  10. * FLEXIcontent is a derivative work of the excellent QuickFAQ component
  11. * @copyright (C) 2008 Christoph Lukes
  12. * see www.schlu.net for more information
  13. *
  14. * FLEXIcontent is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. // Check to ensure this file is included in Joomla!
  20. defined('_JEXEC') or die('Restricted access');
  21. if (FLEXI_J16GE) {
  22. jimport('joomla.html.html');
  23. jimport('joomla.form.formfield');
  24. }
  25. /**
  26. * Renders a multi element checkbox (array of checkboxes)
  27. */
  28. class JElementFccheckbox extends JElement
  29. {
  30. /**
  31. * Element name
  32. *
  33. * @access protected
  34. * @var string
  35. */
  36. var $_name = 'Fccheckbox';
  37. function fetchElement($name, $value, &$node, $control_name)
  38. {
  39. if (FLEXI_J16GE) {
  40. $node = & $this->element;
  41. $attributes = get_object_vars($node->attributes());
  42. $attributes = $attributes['@attributes'];
  43. } else {
  44. $attributes = & $node->_attributes;
  45. }
  46. $values = FLEXI_J16GE ? $this->value : $value;
  47. if ( empty($values) ) $values = array();
  48. else if ( ! is_array($values) ) $values = !FLEXI_J16GE ? array($values) : explode("|", $values);
  49. $split_char = ",";
  50. // Get options and values
  51. $checkoptions = preg_split("/[\s]*".$split_char."[\s]*/", $attributes['checkoptions']);
  52. $checkvals = preg_split("/[\s]*".$split_char."[\s]*/", $attributes['checkvals']);
  53. $defaultvals = preg_split("/[\s]*".$split_char."[\s]*/", @$attributes['defaultvals']);
  54. // Verify defaultvals option
  55. if ( count($defaultvals)==1 && empty($defaultvals[0]) ) $defaultvals = array();
  56. if ( count($defaultvals) && @$attributes['display_useglobal'] ) {
  57. $defaultvals = array();
  58. echo "Cannot use field option 'defaultvals' together with 'display_useglobal' 'defaultvals' cleared";
  59. }
  60. // Make value an array if value is not already array, also load defaults, if field parameter never saved
  61. if ( count($values)==0 ) $values = $defaultvals;
  62. // Sanity check
  63. if (count($checkoptions)!=count($checkvals))
  64. return "Number of check options not equal to number of check values";
  65. $fieldname = FLEXI_J16GE ? $this->name : $control_name.'['.$name.']';
  66. $element_id = FLEXI_J16GE ? $this->id : $control_name.$name;
  67. // 'multiple' attribute in XML adds '[]' automatically in J2.5 and manually in J1.5
  68. // This field is always multiple, we will add '[]' WHILE checking for the attribute ...
  69. $is_multiple = @$attributes['multiple']=='multiple' || @$attributes['multiple']=='true';
  70. if (!FLEXI_J16GE || !$is_multiple)
  71. $fieldname .= '[]';
  72. $html = '<fieldset id="'.$element_id.'" class="radio" style="border-width:0px;'.(FLEXI_J16GE ? "width:60%; " : "").'">';
  73. $inline_style = "float:left; white-space:nowrap; ".(!FLEXI_J16GE ? "margin-right:12px; " : "");
  74. $disable_all = '';
  75. if ( @$attributes['display_useglobal'] ) {
  76. $check_global='';
  77. if (count($values) == 0) {
  78. $check_global = ' checked="checked" ';
  79. $disable_all = ' disabled="disabled" ';
  80. }
  81. $html .= '<div style="'.$inline_style.'" ><input id="'.$element_id.'_useglobal" type="checkbox" '.$check_global.' value="" onclick="toggle_options_fc_'.$element_id.'(this)" />';
  82. $html .= '<label for="'.$element_id.'_useglobal" >'.JText::_('FLEXI_USE_GLOBAL').'</label></div>';
  83. }
  84. // Create checkboxes
  85. foreach($checkoptions as $i => $o) {
  86. $curr_element_id = $element_id.$i;
  87. $html .= '<div style="'.$inline_style.'" ><input id="'.$curr_element_id.'" type="checkbox"'.$disable_all;
  88. $html .= in_array($checkvals[$i], $values) ? ' checked="checked"' : '' ;
  89. $html .= ' name="'.$fieldname.'" value="'.$checkvals[$i].'">';
  90. $html .= '<label for="'.$curr_element_id.'" >'.JText::_($checkoptions[$i]).'</label></div>';
  91. $html .= FLEXI_J16GE ? ' &nbsp; ' : '';
  92. }
  93. $html .= '<input id="'.$element_id.'9999" type="hidden" name="'.$fieldname.'" value="__SAVED__" '.$disable_all.'/> ';
  94. $html .= '</fieldset>';
  95. $js = "
  96. function toggle_options_fc_".$element_id."(element) {
  97. var panel = $('".$element_id."');
  98. var inputs = panel.getElements('input');
  99. if ( $(element).checked ) {
  100. inputs.each(function(el){
  101. el.setProperty('disabled', 'disabled');
  102. });
  103. } else {
  104. inputs.each(function(el){
  105. el.setProperty('disabled', '');
  106. });
  107. }
  108. element.setProperty('disabled', '');
  109. }";
  110. $doc = JFactory::getDocument();
  111. $doc->addScriptDeclaration($js);
  112. return $html;
  113. }
  114. }
  115. ?>