Skip to content

Instantly share code, notes, and snippets.

@Palestinian
Created April 22, 2015 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Palestinian/35d3aa54cc6527323c6a to your computer and use it in GitHub Desktop.
Save Palestinian/35d3aa54cc6527323c6a to your computer and use it in GitHub Desktop.
// returns all values in an array
<?php
foreach(fmsValueListItems2($FMTimesheet,'rp_timesheet','sor number',"",null,"") as $list_item) {
if (html_entity_decode($list_item[0]) == "") {
} else {
echo "{value:\"{$list_item[0]}\",label:\"{$list_item[1]}\"},";
}
}
?>
// function fmsValueListItems2
function fmsValueListItems2($conn, $layout, $list, $recid = null, $empty = null, $currentValue = null) {
if($recid == "") $recid = null;
global $VALUE_LIST_CACHE;
$cache = fmsGetCache(func_get_args(),$VALUE_LIST_CACHE);
if($cache !== false) return $cache;
$layoutValueLists = fmsGetCache(array($conn,$layout,$recid),$VALUE_LIST_CACHE);
if($layoutValueLists === false) {
$properties = $conn->getProperties();
$request = '/fmi/xml/FMPXMLLAYOUT.xml?-db='.urlencode($properties['database']).'&-lay='.urlencode($layout).'&-view';
if($recid && (int)$recid>0) $request.='&-recid='.urlencode((int)$recid);
$ret = fmsExecuteXMLRequest($conn,$request);
if(isset($ret['error'])) {
//die('Failed getting value list ('. $list .'). Error: '.$ret['error']); // Uncomment this line to debug
return fmsStoreCache(func_get_args(),$VALUE_LIST_CACHE,array());
}
$ret = $ret['data'];
$layoutValueLists = fmsXMLGetValueByPath($ret,'/FMPXMLLAYOUT/VALUELISTS');
fmsStoreCache(array($conn,$layout,$recid),$VALUE_LIST_CACHE,$layoutValueLists);
}
foreach($layoutValueLists as $valueList) {
if($valueList['name'] != "VALUELIST") continue;
if($valueList['attributes']['NAME'] != $list) continue;
$retVL = array();
if($empty !== null) {
$retVL[] = array("",htmlspecialchars($empty));
}
foreach($valueList as $key=>$valueListValue) {
if(!is_int($key) || $valueListValue['name'] != "VALUE") continue;
$value = "";
if(isset($valueListValue['value'])) $value = $valueListValue['value'];
$display = $value;
if(isset($valueListValue['attributes']) && isset($valueListValue['attributes']['DISPLAY'])) $display = $valueListValue['attributes']['DISPLAY'];
$retVL[] = array(htmlspecialchars($value),htmlspecialchars($display));
}
if($currentValue !== null) {
$found = false;
foreach($retVL as $value) {
if($value[0] == $currentValue) {
$found = true;
break;
}
}
if(!$found && count($retVL)) $retVL[] = array(htmlspecialchars($currentValue),htmlspecialchars($currentValue));
}
return fmsStoreCache(func_get_args(),$VALUE_LIST_CACHE,$retVL);
}
return fmsStoreCache(func_get_args(),$VALUE_LIST_CACHE,array());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment