00001 <?PHP 00017 include_once("OptionElement.php"); 00018 00027 class Checkbox extends OptionElement 00028 { 00029 protected $m_DefaultChecked ; 00030 00031 protected function readMetaData(&$xmlArr) 00032 { 00033 parent::readMetaData($xmlArr); 00034 $this->m_DefaultChecked = isset($xmlArr["ATTRIBUTES"]["DEFAULTCHECKED"]) ? $xmlArr["ATTRIBUTES"]["DEFAULTCHECKED"] : "N"; 00035 } 00036 public function getDefaultChecked() 00037 { 00038 $formObj = $this->getFormObj(); 00039 return Expression::evaluateExpression($this->m_DefaultChecked, $formObj); 00040 } 00046 public function getValue() 00047 { 00048 if(strtoupper($this->getDefaultChecked())=='Y') 00049 { 00050 $this->m_Value = $this->getSelectFrom(); 00051 return $this->m_Value; 00052 } 00053 if($this->m_Value!=null) 00054 { 00055 return $this->m_Value; 00056 } 00057 else 00058 { 00059 return $this->m_DefaultValue; 00060 } 00061 } 00062 00063 00069 public function render() 00070 { 00071 $boolValue = $this->getSelectFrom(); 00072 $disabledStr = ($this->getEnabled() == "N") ? "DISABLED=\"true\"" : ""; 00073 $checkedStr = ($boolValue == $this->getValue()) ? "CHECKED" : ""; 00074 $style = $this->getStyle(); 00075 $text = $this->getText(); 00076 $func = $this->getFunction(); 00077 $sHTML = ''; 00078 $fromList = array(); 00079 $this->getFromList($fromList); 00080 00081 if (count($fromList) > 1) 00082 { 00083 $valueArr = explode(',', $this->getValue()); 00084 00085 foreach ($fromList as $opt) 00086 { 00087 $test = array_search($opt['val'], $valueArr); 00088 if ($test === false) 00089 { 00090 $checkedStr = ''; 00091 } 00092 else 00093 { 00094 $checkedStr = "CHECKED"; 00095 } 00096 $sHTML .= "<INPUT TYPE=CHECKBOX NAME='".$this->m_Name."[]' ID=\"" . $this->m_Name ."\" VALUE=\"" . $opt['val'] . "\" $checkedStr $disabledStr $this->m_HTMLAttr $func /> " . $opt['txt'] . ""; 00097 } 00098 } 00099 else 00100 { 00101 $sHTML = "<INPUT TYPE=\"CHECKBOX\" NAME=\"" . $this->m_Name . "\" ID=\"" . $this->m_Name ."\" VALUE='$boolValue' $checkedStr $disabledStr $this->m_HTMLAttr $style $func /> ".$text.""; 00102 } 00103 00104 return $sHTML; 00105 } 00106 } 00107 00108 ?>