00001 <?PHP
00017 include_once("Element.php");
00018
00029 class LabelText extends Element
00030 {
00031 public $m_FieldName;
00032 public $m_Label;
00033 public $m_DisplayFormat;
00034 public $m_Text;
00035 public $m_Link;
00036 public $m_Target;
00037 public $m_MaxLength;
00038 public $m_Percent;
00039
00040 public $m_StripTags;
00047 protected function readMetaData(&$xmlArr)
00048 {
00049 parent::readMetaData($xmlArr);
00050 $this->m_FieldName = isset($xmlArr["ATTRIBUTES"]["FIELDNAME"]) ? $xmlArr["ATTRIBUTES"]["FIELDNAME"] : null;
00051 $this->m_Label = isset($xmlArr["ATTRIBUTES"]["LABEL"]) ? $xmlArr["ATTRIBUTES"]["LABEL"] : null;
00052 $this->m_Text = isset($xmlArr["ATTRIBUTES"]["TEXT"]) ? $xmlArr["ATTRIBUTES"]["TEXT"] : null;
00053 $this->m_Link = isset($xmlArr["ATTRIBUTES"]["LINK"]) ? $xmlArr["ATTRIBUTES"]["LINK"] : null;
00054 $this->m_Target = isset($xmlArr["ATTRIBUTES"]["TARGET"]) ? $xmlArr["ATTRIBUTES"]["TARGET"] : null;
00055 $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGHT"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGHT"] : null;
00056 $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGTH"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGTH"] : null;
00057 $this->m_Percent = isset($xmlArr["ATTRIBUTES"]["PERCENT"]) ? $xmlArr["ATTRIBUTES"]["PERCENT"] : "N";
00058 $this->m_DisplayFormat = isset($xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"]) ? $xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"] : null;
00059 $this->m_StripTags = isset($xmlArr["ATTRIBUTES"]["STRIPTAGS"]) ? $xmlArr["ATTRIBUTES"]["STRIPTAGS"] : "N";
00060 }
00061
00068 protected function getTarget()
00069 {
00070 if ($this->m_Target == null)
00071 return null;
00072
00073 return "target='" . $this->m_Target ."'";
00074 ;
00075 }
00076
00082 protected function getLink()
00083 {
00084 if ($this->m_Link == null)
00085 return null;
00086 $formobj = $this->getFormObj();
00087 return Expression::evaluateExpression($this->m_Link, $formobj);
00088 }
00089
00095 protected function getText()
00096 {
00097 if ($this->m_Text == null)
00098 return null;
00099 $formObj = $this->getFormObj();
00100 return Expression::evaluateExpression($this->m_Text, $formObj);
00101 }
00102
00108 public function renderLabel()
00109 {
00110 return $this->m_Label;
00111 }
00112
00118 public function render()
00119 {
00120 $value = $this->m_Text ? $this->getText() : $this->m_Value;
00121 if ($value === null || $value ==="")
00122 return "";
00123
00124 $style = $this->getStyle();
00125 $id = $this->m_Name;
00126 $func = $this->getFunction();
00127
00128 if ($this->m_Translatable == 'Y')
00129 $value = $this->translateString($value);
00130 $value_org = strip_tags($value);
00131 if((int)$this->m_MaxLength>0){
00132 if(function_exists('mb_strlen') && function_exists('mb_substr')){
00133 if(mb_strlen($value,'UTF8') > (int)$this->m_MaxLength){
00134 $value = mb_substr($value,0,(int)$this->m_MaxLength,'UTF8').'...';
00135 }
00136 }else{
00137 if(strlen($value) > (int)$this->m_MaxLength){
00138 $value = substr($value,0,(int)$this->m_MaxLength).'...';
00139 }
00140 }
00141 }
00142
00143 if ($value!==null)
00144 {
00145 if($this->m_DisplayFormat)
00146 {
00147 $value = sprintf($this->m_DisplayFormat,$value);
00148 }
00149 if($this->m_Percent=='Y')
00150 {
00151 $value = sprintf("%.2f",$value*100).'%';
00152 }else{
00153 if(strtoupper($this->m_StripTags) =='Y')
00154 {
00155 $value = strip_tags($value);
00156 }
00157 else
00158 {
00159 $value = htmlentities($value, ENT_QUOTES, "UTF-8");
00160 }
00161 }
00162
00163
00164
00165 if ($this->m_Link)
00166 {
00167 $link = $this->getLink();
00168 $target = $this->getTarget();
00169
00170 $sHTML = "<a title=\"$value_org\" id=\"$id\" href=\"$link\" $target $func $style>" . $value . "</a>";
00171 }
00172 else
00173 {
00174 $sHTML = "<span title=\"$value_org\" $style $func>" . $value . "</span>";
00175 }
00176 if($this->m_BackgroundColor)
00177 {
00178 $bgcolor = $this->getBackgroundColor();
00179 if($bgcolor){
00180 $sHTML = "<div style=\"background-color:#".$bgcolor.";text-indent:10px;-moz-border-radius: 4px;border-radius: 4px;\" >$sHTML</div>";
00181 }
00182 }
00183 }
00184
00185 return $sHTML;
00186 }
00187
00188 }
00189
00190 ?>