1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135:
<?php
defined('ICMS_ROOT_PATH') or die("ImpressCMS root path not defined");
class icms_ipf_form_elements_Checkbox extends icms_form_elements_Checkbox {
private $_delimeter = " ";
public function __construct($object, $key) {
$control = $object->getControl($key);
if(isset($control['delimeter'])) {
$this->_delimeter = $control['delimeter'];
}
parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key), $this->_delimeter);
if (isset($control['options'])) {
$this->addOptionArray($control['options']);
} else {
if (isset($control['object'])) {
if (method_exists($control['object'], $control['method'])) {
if ($option_array = $control['object']->$control['method']()) {
$this->addOptionArray($option_array);
}
}
} else {
if (isset($control['itemHandler'])) {
if (!isset($control['module'])) {
$control_handler = icms::handler($control['itemHandler']);
} else {
$control_handler =& icms_getModuleHandler($control['itemHandler'], $control['module']);
}
} else {
$control_handler =& $object->handler;
}
if (method_exists($control_handler, $control['method'])) {
$option_array = call_user_func_array(array($control_handler, $control['method']),
isset($control['params']) ? $control['params'] : array());
if (is_array($option_array) && count($option_array) > 0) {
$this->addOptionArray($option_array);
}
}
}
}
}
public function render() {
$ret = "<div class='grouped'>";
$ele_name = $this->getName();
$ele_value = $this->getValue();
$ele_options = $this->getOptions();
$ele_extra = $this->getExtra();
$ele_delimeter = $this->getDelimeter();
if (count($ele_options) > 1 && substr($ele_name, -2, 2) != "[]") {
$ele_name = $ele_name . "[]";
$this->setName($ele_name);
}
foreach ($ele_options as $value => $name) {
$ret .= "<span class='icms_checkboxoption'><input type='checkbox' name='" . $ele_name
. "' id='" . $ele_name . "_item_" . $value . "' value='" . htmlspecialchars($value, ENT_QUOTES) . "'";
if (count($ele_value) > 0 && in_array($value, $ele_value)) {
$ret .= " checked='checked'";
}
$ret .= $ele_extra . " /><label for='" . $ele_name . "_item_" . $value . "'>" . $name . "</label></span>" . $ele_delimeter;
}
if (count($ele_options) > 1) {
$ret .= "<div class='icms_checkboxoption'><input type='checkbox' id='"
. $ele_name . "_checkemall' class='checkemall' /><label for='"
. $ele_name . "_checkemall'>" . _CHECKALL . "</label></div>";
}
$ret .= "</div>";
return $ret;
}
public function renderValidationJS() {
$js = "";
$js .= "var hasSelections = false;";
$eltname = $this->getName();
$eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
$eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
if (strpos($eltname, '[') === false) $eltname = $eltname . "[]";
$js .=
"for (var i = 0; i < myform['" . $eltname . "'].length; i++) {
if (myform['" . $eltname . "'][i].checked) {
hasSelections = true;
}
}
if (hasSelections == false) {
window.alert(\"{$eltmsg}\");
myform['" . $eltname . "'][0].focus();
return false;
}\n";
return $js;
}
}