00001 <?PHP
00017 include_once("InputElement.php");
00018
00034 class OptionElement extends InputElement
00035 {
00036 public $m_SelectFrom;
00037 public $m_SelectFromSQL;
00038 public $m_SelectedList;
00039
00046 protected function readMetaData(&$xmlArr)
00047 {
00048 parent::readMetaData($xmlArr);
00049 $this->m_SelectFrom = isset($xmlArr["ATTRIBUTES"]["SELECTFROM"]) ? $xmlArr["ATTRIBUTES"]["SELECTFROM"] : null;
00050 $this->m_SelectedList = isset($xmlArr["ATTRIBUTES"]["SELECTEDLIST"]) ? $xmlArr["ATTRIBUTES"]["SELECTEDLIST"] : null;
00051 $this->m_SelectFromSQL = isset($xmlArr["ATTRIBUTES"]["SELECTFROMSQL"]) ? $xmlArr["ATTRIBUTES"]["SELECTFROMSQL"] : null;
00052 }
00053
00059 protected function getSelectFrom()
00060 {
00061 $formobj = $this->getFormObj();
00062 return Expression::evaluateExpression($this->m_SelectFrom, $formobj);
00063 }
00064
00065 protected function getSelectedList()
00066 {
00067 $formobj = $this->getFormObj();
00068 return Expression::evaluateExpression($this->m_SelectedList, $formobj);
00069 }
00070
00071 protected function getSelectFromSQL()
00072 {
00073 $formobj = $this->getFormObj();
00074 return Expression::evaluateExpression($this->m_SelectFromSQL, $formobj);
00075 }
00076
00082 public function render()
00083 {
00084 return "";
00085 }
00086
00093 public function getFromList(&$list, $selectFrom=null)
00094 {
00095 if (!$selectFrom) {
00096 $selectFrom = $this->getSelectFrom();
00097 }
00098 if (!$selectFrom) {
00099 return $this->getSQLFromList($list);
00100 }
00101 $this->getXMLFromList($list, $selectFrom);
00102 if ($list != null)
00103 return;
00104 $this->getDOFromList($list, $selectFrom);
00105 if ($list != null)
00106 return;
00107 $this->getSimpleFromList($list, $selectFrom);
00108 if ($list != null)
00109 return;
00110
00111 return;
00112 }
00113
00114 protected function getXMLFromList(&$list, $selectFrom)
00115 {
00116 $pos0 = strpos($selectFrom, "(");
00117 $pos1 = strpos($selectFrom, ")");
00118 if ($pos0>0 && $pos1 > $pos0)
00119 {
00120 $xmlFile = substr($selectFrom, 0, $pos0);
00121 $tag = substr($selectFrom, $pos0 + 1, $pos1 - $pos0-1);
00122 $tag = strtoupper($tag);
00123 $xmlFile = BizSystem::GetXmlFileWithPath ($xmlFile);
00124 if (!$xmlFile) return false;
00125
00126 $xmlArr = &BizSystem::getXmlArray($xmlFile);
00127 if ($xmlArr)
00128 {
00129 $i = 0;
00130 if (!key_exists($tag, $xmlArr["SELECTION"]))
00131 return false;
00132 if(!$xmlArr["SELECTION"][$tag][0]){
00133 $array = $xmlArr["SELECTION"][$tag];
00134 unset($xmlArr["SELECTION"][$tag]);
00135 $xmlArr["SELECTION"][$tag][0]=$array;
00136 }
00137 foreach($xmlArr["SELECTION"][$tag] as $node)
00138 {
00139 $list[$i]['val'] = $node["ATTRIBUTES"]["VALUE"];
00140 $list[$i]['pic'] = $node["ATTRIBUTES"]["PICTURE"];
00141 if ($node["ATTRIBUTES"]["TEXT"])
00142 {
00143 $list[$i]['txt'] = $node["ATTRIBUTES"]["TEXT"];
00144 }
00145 else
00146 {
00147 $list[$i]['txt'] = $list[$i]['val'];
00148 }
00149 $i++;
00150
00151 }
00152 $this->translateList($list, $tag);
00153 }
00154 return true;
00155 }
00156 return false;
00157 }
00158
00159 protected function getDOFromList(&$list, $selectFrom)
00160 {
00161 $pos0 = strpos($selectFrom, "[");
00162 $pos1 = strpos($selectFrom, "]");
00163 if ($pos0 > 0 && $pos1 > $pos0)
00164 {
00165
00166
00167
00168 $bizObjName = substr($selectFrom, 0, $pos0);
00169 $pos3 = strpos($selectFrom, ":");
00170 if($pos3 > $pos0 && $pos3 < $pos1)
00171 {
00172 $fieldName = substr($selectFrom, $pos0 + 1, $pos3 - $pos0 - 1);
00173 $fieldName_v = substr($selectFrom, $pos3 + 1, $pos1 - $pos3 - 1);
00174 }
00175 else
00176 {
00177 $fieldName = substr($selectFrom, $pos0 + 1, $pos1 - $pos0 - 1);
00178 $fieldName_v = $fieldName;
00179 }
00180 $pos4 = strpos($fieldName_v, ":");
00181 if($pos4){
00182 $fieldName_v_mixed = $fieldName_v;
00183 $fieldName_v = substr($fieldName_v_mixed,0,$pos4);
00184 $fieldName_p = substr($fieldName_v_mixed, $pos4+1, strlen($fieldName_v_mixed)-$pos4-1);
00185 unset($fieldName_v_mixed);
00186 }
00187 $commaPos = strpos($selectFrom, ",", $pos1);
00188 if ($commaPos > $pos1)
00189 $searchRule = trim(substr($selectFrom, $commaPos + 1));
00190
00191
00192 $bizObj = BizSystem::getObject($bizObjName);
00193 if (!$bizObj)
00194 return false;
00195
00196 $recList = array();
00197 $oldAssoc = $bizObj->m_Association;
00198 $bizObj->m_Association = null;
00199 QueryStringParam::reset();
00200 $recList = $bizObj->directFetch($searchRule);
00201 $bizObj->m_Association = $oldAssoc;
00202
00203 foreach ($recList as $rec)
00204 {
00205 $list[$i]['val'] = $rec[$fieldName_v];
00206 $list[$i]['txt'] = $rec[$fieldName];
00207 $list[$i]['pic'] = $rec[$fieldName_p];
00208 $i++;
00209 }
00210
00211 return true;
00212 }
00213 return false;
00214 }
00215
00216 protected function getSimpleFromList(&$list, $selectFrom)
00217 {
00218
00219 if (strpos($selectFrom, "[") > 0 || strpos($selectFrom, "(") > 0)
00220 return;
00221 $recList = explode('|',$selectFrom);
00222 foreach ($recList as $rec)
00223 {
00224 $list[$i]['val'] = $rec;
00225 $list[$i]['txt'] = $rec;
00226 $list[$i]['pic'] = $rec;
00227 $i++;
00228 }
00229 }
00230
00231 public function getSQLFromList(&$list)
00232 {
00233 $sql = $this->getSelectFromSQL();
00234 if (!$sql) return;
00235 $formObj = $this->getFormObj();
00236 $do = $formObj->getDataObj();
00237 $db = $do->getDBConnection();
00238 try {
00239 $resultSet = $db->query($sql);
00240 $recList = $resultSet->fetchAll();
00241 foreach ($recList as $rec)
00242 {
00243 $list[$i]['val'] = $rec[0];
00244 $list[$i]['txt'] = isset($rec[1]) ? $rec[1] : $rec[0];
00245 $i++;
00246 }
00247 }
00248 catch (Exception $e)
00249 {
00250 BizSystem::log(LOG_ERR, "DATAOBJ", "Query Error: ".$e->getMessage());
00251 $this->m_ErrorMessage = "Error in SQL query: ".$sql.". ".$e->getMessage();
00252 throw new BDOException($this->m_ErrorMessage);
00253 return null;
00254 }
00255 }
00256
00257 protected function translateList(&$list, $tag)
00258 {
00259 $module = $this->getModuleName($this->m_SelectFrom);
00260 if (empty($module))
00261 $module = $this->getModuleName($this->m_FormName);
00262 for ($i=0; $i<count($list); $i++)
00263 {
00264 $key = 'SELECTION_'.strtoupper($tag).'_'.$i.'_TEXT';
00265 $list[$i]['txt'] = I18n::t($list[$i]['txt'], $key, $module);
00266 }
00267 }
00268 }
00269
00270 ?>