_key = $key; $this->_type = $type; $this->_label = $label; $this->_minVal = $min; $this->_maxVal = $max; $this->_inputType = $inputType; $this->_inputAttr = $inputAttr; $this->_multiInd = $multiInd; $this->_helpKey = ($helpKey == null) ? $key : $helpKey; $this->_bitFlag = $allowNull ? 0 : self::BM_NOTNULL; } public function SetGlue($glue) { $this->_glue = $glue; } public function SetFlag($flag) { $this->_bitFlag |= $flag; } public function IsFlagOn($flag) { return (($this->_bitFlag & $flag) == $flag ); } public function GetKey() { return $this->_key; } public function dup($key, $label, $helpkey) { $cname = get_class($this); $d = new $cname($this->_key, $this->_type, $this->_label, $this->_inputType, true, $this->_minVal, $this->_maxVal, $this->_inputAttr, $this->_multiInd, $this->_helpKey); $d->_glue = $this->_glue; $d->_href = $this->_href; $d->_hrefLink = $this->_hrefLink; $d->_bitFlag = $this->_bitFlag; $d->_note = $this->_note; $d->_icon = $this->_icon; if ($key != null) { $d->_key = $key; } if ($label != null) $d->_label = $label; if ($helpkey != null) $d->_helpKey = $helpkey; return $d; } protected function extractCheckBoxOr() { $value = 0; $novalue = 1; foreach ($this->_maxVal as $val => $disp) { $name = $this->_key . $val; if (isset($_POST[$name])) { $novalue = 0; $value = $value | $val; } } return ( $novalue ? '' : (string) $value ); } protected function extractSplitMultiple(&$value) { if ($this->_glue == ' ') $vals = preg_split("/[,; ]+/", $value, -1, PREG_SPLIT_NO_EMPTY); else $vals = preg_split("/[,;]+/", $value, -1, PREG_SPLIT_NO_EMPTY); $vals1 = array(); foreach ($vals as $val) { $val1 = trim($val); if (strlen($val1) > 0 && !in_array($val1, $vals1)) { $vals1[] = $val1; } } if ($this->_glue == ' ') $value = implode(' ', $vals1); else $value = implode(', ', $vals1); } protected function toHtmlContent($node, $refUrl = null) { if ($node == null || !$node->HasVal()) return '' . ATTR_VAL_NOT_SET . ''; $o = ''; $value = $node->Get(CNode::FLD_VAL); $err = $node->Get(CNode::FLD_ERR); if ($this->_type == 'sel1' && $value != null && !array_key_exists($value, $this->_maxVal)) { $err = 'Invalid value - ' . htmlspecialchars($value, ENT_QUOTES); } else if ($err != null) { $type3 = substr($this->_type, 0, 3); if ($type3 == 'fil' || $type3 == 'pat') { $validator = new ConfValidation(); $validator->chkAttr_file_val($this, $value, $err); } } if ($err) { $node->SetErr($err); $o .= '*' . $err . '
'; } if ($this->_href) { $link = $this->_hrefLink; if (strpos($link, '$V')) { $link = str_replace('$V', urlencode($value), $link); } $o .= ''; } elseif ($refUrl != null) { $o .= ''; } if ($this->_type === 'bool') { if ($value === '1') { $o .= ATTR_VAL_BOOL_YES; } elseif ($value === '0') { $o .= ATTR_VAL_BOOL_NO; } else { $o .= '' . ATTR_VAL_NOT_SET . ''; } } elseif ($this->_type == 'ctxseq') { $o = $value . ' '; } else if ($this->_key == "note") { $o .= ''; } elseif ($this->_type === 'sel' || $this->_type === 'sel1') { if ($this->_maxVal != null && array_key_exists($value, $this->_maxVal)) { $o .= $this->_maxVal[$value]; } else { $o .= htmlspecialchars($value, ENT_QUOTES); } } elseif ($this->_type === 'checkboxOr') { if ($this->_minVal !== null && ($value === '' || $value === null)) { // has default value, for "Not set", set default val $value = $this->_minVal; } foreach ($this->_maxVal as $val => $name) { if (($value & $val) || ($value === $val) || ($value === '0' && $val === 0)) { $o .= ''; } else { $o .= ''; } $o .= ' '; $o .= $name . '    '; } } elseif ($this->_inputType === 'textarea1') { $o .= ''; } elseif ($this->_inputType === 'text') { $o .= '' . htmlspecialchars($value, ENT_QUOTES) . ''; } else { $o .= htmlspecialchars($value); } if ($this->_href || $refUrl != null) { $o .= ''; } return $o; } protected function getNote() { if ($this->_note != null) return $this->_note; if ($this->_type == 'uint') { if ($this->_maxVal) return ATTR_NOTE_NUM_RANGE . ': ' . $this->_minVal . ' - ' . $this->_maxVal; elseif ($this->_minVal !== null) return ATTR_NOTE_NUM_RANGE . ' >= ' . $this->_minVal; } return null; } public function extractPost($parent) { if ($this->_type == 'checkboxOr') $value = $this->extractCheckBoxOr(); else { $value = UIBase::GrabInput("post", $this->_key); if (get_magic_quotes_gpc()) $value = stripslashes($value); } $key = $this->_key; $node = $parent; while (($pos = strpos($key, ':')) > 0) { $key0 = substr($key, 0, $pos); $key = substr($key, $pos + 1); if ($node->HasDirectChildren($key0)) $node = $node->GetChildren($key0); else { $child = new CNode($key0, '', CNode::T_KB); $node->AddChild($child); $node = $child; } } if ($this->_multiInd == 2 && $value != null) { $v = preg_split("/\n+/", $value, -1, PREG_SPLIT_NO_EMPTY); foreach ($v as $vi) $node->AddChild(new CNode($key, trim($vi))); } elseif ($this->_type == 'checkboxOr') { $node->AddChild(new CNode($key, $value)); } else { if ($this->_multiInd == 1 && $value != null) { $this->extractSplitMultiple($value); } $node->AddChild(new CNode($key, $value)); } return true; } public function toHtml($pnode, $refUrl = null) { $node = ($pnode == null) ? null : $pnode->GetChildren($this->_key); $o = ''; if (is_array($node)) { foreach ($node as $nd) { $o .= $this->toHtmlContent($nd, $refUrl); $o .= '
'; } } else { $o .= $this->toHtmlContent($node, $refUrl); } return $o; } public function toInputGroup($pnode, $is_blocked, $helppop) { $node = ($pnode == null) ? null : $pnode->GetChildren($this->_key); $err = ''; $value = ''; if (is_array($node)) { $value = array(); foreach ($node as $d) { $value[] = $d->Get(CNode::FLD_VAL); $e1 = $d->Get(CNode::FLD_ERR); if ($e1 != null) $err .= $e1 . '
'; } } else { if ($node != null) { $value = $node->Get(CNode::FLD_VAL); $err = $node->Get(CNode::FLD_ERR); } else { $value = null; } } $buf = '
' : '">'); if ($this->_label) { $buf .= '\n"; $buf .= '
'; } else { $buf .= '
'; } $buf .= $this->toHtmlInput($helppop, $is_blocked, $err, $value); $buf .= "
\n"; return $buf; } protected function toHtmlInput($helppop, $isDisabled, $err, $value) { $spacer = '    '; $checked = ' checked="checked"'; $input = '
'; $input .= '' . $helppop . '' . "\n"; // need this even empty, for alignment if (is_array($value) && $this->_inputType != 'checkbox') { if ($this->_multiInd == 1) $glue = ', '; else $glue = "\n"; $value = implode($glue, $value); } $name = $this->_key; $inputAttr = $this->_inputAttr; if ($isDisabled) $inputAttr .= ' disabled="disabled"'; $style = 'form-control'; if ($this->_inputType == 'text') { $input .= ''; } elseif ($this->_inputType == 'password') { $input .= ''; } elseif ($this->_inputType == 'textarea' || $this->_inputType == 'textarea1') { $input .= ''; } elseif ($this->_inputType == 'radio' && $this->_type == 'bool') { $input .= '
'; } elseif ($this->_inputType == 'checkboxgroup') { $input .= '
'; if ($this->_minVal !== null && ($value === '' || $value === null)) { // has default value, for "Not set", set default val $value = $this->_minVal; } $js0 = $js1 = ''; if (array_key_exists('0', $this->_maxVal)) { $chval = array_keys($this->_maxVal); foreach ($chval as $chv) { if ($chv == '0') $js1 = "document.confform.$name$chv.checked=false;"; else $js0 .= "document.confform.$name$chv.checked=false;"; } $js1 = " onclick=\"$js1\""; $js0 = " onclick=\"$js0\""; } foreach ($this->_maxVal as $val => $disp) { $id = $name . $val; $input .= " $disp $spacer"; } $input .= '
'; } elseif ($this->_inputType == 'select') { $input .= ''; } $input .= "
\n"; if ($err != '') { $input .= ' '; $type3 = substr($this->_type, 0, 3); $input .= ( $type3 == 'fil' || $type3 == 'pat' ) ? $err : htmlspecialchars($err, ENT_QUOTES); $input .= ''; } $note = $this->getNote(); if ($note) $input .= '

' . htmlspecialchars($note, ENT_QUOTES) . '

'; return $input; } public function SetDerivedSelOptions($derived) { $options = ($derived) ? $derived : array(); if (!$this->IsFlagOn(self::BM_NOTNULL)) $options[''] = ''; $this->_maxVal = $options; } }