protected function transformToBlocks($module) { $current_user = $this->getActiveUser(); $moduleFieldGroups = Mobile_WS_Utils::gatherModuleFieldGroupInfo($module); $describeInfo = vtws_describe($module, $current_user); Mobile_WS_Utils::fixDescribeFieldInfo($module, $describeInfo, $current_user); $modifiedResult = array(); $blocks = array(); $labelFields = false; foreach ($moduleFieldGroups as $blocklabel => $fieldgroups) { $fields = array(); foreach ($fieldgroups as $fieldname => $fieldinfo) { $field['name'] = $fieldname; $field['value'] = ''; $field['label'] = $fieldinfo['label']; $field['uitype'] = $fieldinfo['uitype']; $field['typeofdata'] = $fieldinfo['typeofdata']; foreach ($describeInfo['fields'] as $describeField) { if ($describeField['name'] == $fieldname) { $field['type'] = ''; if (isset($describeField['type']) && $describeField['type'] != '') { $picklistValues = $describeField['type']['picklistValues']; $field['type']['value'] = array('value' => $picklistValues, 'name' => $fieldname); } } } if ($field['uitype'] == '51' || $field['uitype'] == '59' || $field['uitype'] == '10') { $field['relatedmodule'] = Mobile_WS_Utils::getEntityName($field['name'], $module); } $fields[] = $field; } $blocks[] = array('label' => $blocklabel, 'fields' => $fields); } $sections = array(); $moduleFieldGroupKeys = array_keys($moduleFieldGroups); foreach ($moduleFieldGroupKeys as $blocklabel) { // eliminate empty blocks if (isset($groups[$blocklabel]) && !empty($groups[$blocklabel])) { $sections[] = array('label' => $blocklabel, 'count' => count($groups[$blocklabel])); } } $modifiedResult = array('blocks' => $blocks, 'id' => $resultRecord['id']); if ($labelFields) { $modifiedResult['labelFields'] = $labelFields; } return $modifiedResult; }
protected function transformRecordWithGrouping($resultRecord, $module, $isTemplateRecord = false) { $current_user = $this->getActiveUser(); $moduleFieldGroups = Mobile_WS_Utils::gatherModuleFieldGroupInfo($module); $modifiedResult = array(); $blocks = array(); $labelFields = false; foreach ($moduleFieldGroups as $blocklabel => $fieldgroups) { $fields = array(); foreach ($fieldgroups as $fieldname => $fieldinfo) { $value = $resultRecord[$fieldname]; $fieldlabel = $fieldinfo['label']; // get field information if (isset($resultRecord[$fieldname])) { //get standard content & perform special settings if ($fieldinfo['uitype'] == 17 && strlen($resultRecord[$fieldname])) { //www fields if ($_REQUEST['_operation'] == 'edit') { $resultRecord[$fieldname] = $resultRecord[$fieldname]; } else { $htmlstring = str_replace("http://", "", $resultRecord[$fieldname]); $resultRecord[$fieldname] = "<A HREF=\"#\" onclick=\"window.location.href ='http://" . $htmlstring . "';\" rel=external>" . $htmlstring . "</A>"; } } if ($fieldinfo['uitype'] == 13 && strlen($resultRecord[$fieldname])) { // email fields if ($_REQUEST['_operation'] == 'edit') { $resultRecord[$fieldname] = $resultRecord[$fieldname]; } else { $resultRecord[$fieldname] = "<A HREF=\"#\" onclick=\"window.location.href ='mailto:" . $resultRecord[$fieldname] . "';\">" . $resultRecord[$fieldname] . "</A>"; } } if ($fieldinfo['uitype'] == 72 && strlen($resultRecord[$fieldname])) { //currency fields $resultRecord[$fieldname] = round($resultRecord[$fieldname], 2); } $field = array('name' => $fieldname, 'value' => $resultRecord[$fieldname], 'label' => $fieldinfo['label'], 'uitype' => $fieldinfo['uitype'], 'typeofdata' => $fieldinfo['typeofdata']); // Template record requested, send more details if available if ($isTemplateRecord) { $describeFieldInfo = $this->cachedDescribeFieldInfo($fieldname); foreach ($describeFieldInfo as $k => $v) { if (isset($field[$k])) { continue; } $field[$k] = $v; } // Entity fieldnames $labelFields = $this->cachedEntityFieldnames($module); } //handling for special UI types: modify $field if ($field['uitype'] == '53') { //assigned user global $adb; $output = array_chunk($value, 1); $recordarray = explode('x', $output[0][0]); $recordprefix = $recordarray[0]; $value = $output[0][0]; if ($value != '' && $value != 0) { $assigned_user_id = $value; } else { $assigned_user_id = $current_user->id; } $fieldvalue = Mobile_WS_Utils::getassignedtoValues($current_user, $assigned_user_id); $field['type']['value'] = array('value' => $fieldvalue, 'name' => $fieldname); //end UI 53 } else { if ($field['uitype'] == '117') { $field['type']['defaultValue'] = $field['value']; } else { if ($field['uitype'] == '15' || $field['uitype'] == '16' || $field['uitype'] == '33') { //picklists global $adb; require_once 'modules/PickList/PickListUtils.php'; $fieldvalue = array(); $options = array(); $chk_val = ""; $roleid = $current_user->roleid; $picklistValues = getAssignedPicklistValues($fieldname, $roleid, $adb); $valueArr = explode("|##|", $value); $pickcount = 0; //get values if (!empty($picklistValues)) { foreach ($picklistValues as $order => $pickListValue) { if (in_array(trim($pickListValue), array_map("trim", $valueArr))) { $chk_val = "selected"; $pickcount++; } else { $chk_val = ''; } if (isset($_REQUEST['file']) && $_REQUEST['file'] == 'QuickCreate') { $options[] = array('label' => htmlentities(getTranslatedString($pickListValue), ENT_QUOTES, $default_charset), 'value' => $pickListValue, 'selected' => $chk_val); } else { $options[] = array('label' => getTranslatedString($pickListValue), 'value' => $pickListValue, 'selected' => $chk_val); } } if ($pickcount == 0 && !empty($value)) { $options[] = array('label' => $app_strings['LBL_NOT_ACCESSIBLE'], 'value' => $value, 'selected'); } } $editview_label[] = getTranslatedString($fieldlabel, $module); if ($field['uitype'] == '33') { $field['value'] = implode(',', $valueArr); } $fieldvalue[] = $options; $field['type']['value'] = array('value' => $options, 'name' => $fieldname); //end picklists } else { if ($field['uitype'] == '51' || $field['uitype'] == '59' || $field['uitype'] == '10') { $field['relatedmodule'] = Mobile_WS_Utils::getEntityName($field['name'], $module); } } } } $fields[] = $field; } } // build address for "open address in maps" button // array with all different address fieldnames for each module $fieldnamesByModule = array("Accounts" => array("bill_street", "ship_street", "bill_city", "ship_city", "bill_state", "ship_state", "bill_code", "ship_code", "bill_country", "ship_country", "ship_address", "bill_address"), "SalesOrder" => array("bill_street", "ship_street", "bill_city", "ship_city", "bill_state", "ship_state", "bill_code", "ship_code", "bill_country", "ship_country", "ship_address", "bill_address"), "Contacts" => array("mailingstreet", "otherstreet", "mailingcity", "othercity", "mailingstate", "otherstate", "mailingzip", "otherzip", "mailingcountry", "othercountry", "mailingaddress", "otheraddress"), "Leads" => array("lane", "", "city", "", "state", "", "code", "", "country", "", "mailingaddress", "")); // get the right array depending on current module $fieldnames = $fieldnamesByModule[$module]; /* 0 = appears if fieldgroup is not address information 1 = address values are set, show button -1 = city or street is missing, don't show the button and avoid set back to 1 */ $mailingAddressOK = 0; $otherAddressOK = 0; $mailingAddress = ""; $otherAddress = ""; // go through all fields foreach ($fieldgroups as $fieldname => $fieldinfo) { if (!is_array($resultRecord[$fieldname]) and !is_object($resultRecord[$fieldname])) { $value = trim($resultRecord[$fieldname]); // check street and city for first address if ($mailingAddressOK != -1 and ($fieldname == $fieldnames[0] or $fieldname == $fieldnames[2])) { $mailingAddressOK = 1; if (strlen($value) > 0) { $mailingAddress .= $value . " "; } else { $mailingAddressOK = -1; } } else { if ($otherAddressOK != -1 and ($fieldname == $fieldnames[1] or $fieldname == $fieldnames[3])) { $otherAddressOK = 1; if (strlen($value) > 0) { $otherAddress .= $value . " "; } else { $otherAddressOK = -1; } } else { if (in_array($fieldname, array($fieldnames[4], $fieldnames[6])) and strlen($value) > 0) { $mailingAddress .= $value . " "; } else { if (in_array($fieldname, array($fieldnames[5], $fieldnames[7])) and strlen($value) > 0) { $otherAddress .= $value . " "; } } } } } } if ($mailingAddressOK == 1) { if ($module == 'Contacts') { $label = getTranslatedString("address", "Mobile"); } else { $label = getTranslatedString("bill_address", "Mobile"); } $fields[] = array("name" => $fieldnames[10], "value" => $mailingAddress, "label" => $label, "uitype" => "crm_app_map", "typeofdata" => "O"); } if ($otherAddressOK == 1) { if ($module == 'Contacts') { $label = getTranslatedString("otheraddress", "Mobile"); } else { $label = getTranslatedString("ship_address", "Mobile"); } $fields[] = array("name" => $fieldnames[11], "value" => $otherAddress, "label" => $label, "uitype" => "crm_app_map", "typeofdata" => "O"); } $blocks[] = array('label' => $blocklabel, 'fields' => $fields); } $sections = array(); $moduleFieldGroupKeys = array_keys($moduleFieldGroups); foreach ($moduleFieldGroupKeys as $blocklabel) { // eliminate empty blocks if (isset($groups[$blocklabel]) && !empty($groups[$blocklabel])) { $sections[] = array('label' => $blocklabel, 'count' => count($groups[$blocklabel])); } } $modifiedResult = array('blocks' => $blocks, 'id' => $resultRecord['id']); if ($labelFields) { $modifiedResult['labelFields'] = $labelFields; } return $modifiedResult; }