Beispiel #1
0
 function fetchRecordLabelForId($id, $user)
 {
     $value = null;
     if (isset($this->resolvedValueCache[$id])) {
         $value = $this->resolvedValueCache[$id];
     } else {
         if (!empty($id)) {
             $value = trim(vtws_getName($id, $user));
             $this->resolvedValueCache[$id] = $value;
         } else {
             $value = $id;
         }
     }
     return $value;
 }
Beispiel #2
0
 function getContent(Mobile_API_Request $request)
 {
     $comment = $request->get('comment');
     $parentid = $request->get('parentid');
     if (isset($comment) && !empty($comment)) {
         $parentmodule = Mobile_WS_Utils::detectModulenameFromRecordId($parentid);
         if ($parentmodule != 'HelpDesk') {
             include_once 'include/Webservices/Create.php';
             $current_user = $this->getActiveUser();
             $userid = Mobile_WS_Utils::getEntityModuleWSId('Users') . "x" . $current_user->id;
             $arr_comment = array('commentcontent' => $comment, 'related_to' => $parentid, 'creator' => $userid, 'assigned_user_id' => $userid);
             $ele = vtws_create('ModComments', $arr_comment, $current_user);
         } else {
             $parentrecordid = vtws_getIdComponents($parentid);
             $parentrecordid = $parentrecordid[1];
             //there is currently no vtws service available for ticket comments
             $current_user = $this->getActiveUser();
             $current_user_id = $current_user->id;
             $userrecordid = vtws_getIdComponents($current_user_id);
             $userrecordid = $userrecordid[1];
             $arr_comment = array('commentcontent' => $comment, 'related_to' => $parentrecordid, 'creator' => $current_user_id);
             //$ele = vtws_create('ModComments', $arr_comment, $current_user);
             $saverecord = Mobile_WS_Utils::createTicketComment($arr_comment);
             if ($saverecord == true) {
                 $userid = Mobile_WS_Utils::getEntityModuleWSId('Users') . "x" . $current_user_id;
                 $ele['commentcontent'] = $arr_comment['commentcontent'];
                 $ele['creator'] = $userid;
                 $ele['assigned_user_id'] = $userid;
                 $ele['related_to'] = $parentid;
                 $ele['id'] = '';
                 $ele['createdtime'] = DateTimeField::convertToUserFormat(date('Y-m-d H:i:s'));
             }
         }
     }
     $response = new Mobile_API_Response();
     $ele['assigned_user_id'] = vtws_getName($ele['creator'], $current_user);
     $response->setResult(array('comment' => $ele));
     return $response;
 }
/**
 * this function processes the given result and returns the value :: for now we are getting the values for the
 * reference, owner fields, booleans and currency fields; other processing might be added later if required
 * @param array $result - the webservices result object
 * @param array $descObj - the webservices describe object
 * @return array $result - the processes webservices result object
 */
function vttooltip_processResult($result, $descObj)
{
    global $current_user;
    foreach ($descObj['fields'] as $field) {
        $name = $field['name'];
        $value = $result[0][$name];
        if ($field['type']['name'] == 'reference') {
            $name = $field['name'];
            if (!empty($value)) {
                $result[0][$name] = vtws_getName($value, $current_user);
            } else {
                $result[0][$name] = '';
            }
        } elseif ($field['type']['name'] == 'owner') {
            list($info, $id) = explode("x", $value);
            $result[0][$name] = getOwnerName($id);
        } elseif ($field['type']['name'] == 'boolean') {
            if ($result[0][$name] == 1) {
                $result[0][$name] = "on";
            } else {
                $result[0][$name] = "off";
            }
        } elseif ($field['type']['name'] == 'picklist') {
            $temp = '';
            foreach ($field['type']['picklistValues'] as $value) {
                if (strcmp($value['value'], $result[0][$name]) == 0) {
                    $temp = $value['value'];
                }
            }
            $result[0][$name] = $temp;
        } elseif ($field['type']['name'] == 'date') {
            $result[0][$name] = DateTimeField::convertToUserFormat($value);
        } elseif ($field['type']['name'] == 'datetime') {
            $date = new DateTimeField($value);
            $result[0][$name] = $date->getDisplayDateTimeValue();
        } elseif ($field['type']['name'] == 'time') {
            $date = new DateTimeField($value);
            $result[0][$name] = $date->getDisplayTime();
        } elseif ($field['type']['name'] == 'currency') {
            $currencyField = new CurrencyField($value);
            $result[0][$name] = $currencyField->getDisplayValueWithSymbol();
        }
    }
    return $result;
}
/**
 * this function processes the given result and returns the value :: for now we are getting the values for the
 * reference, owner fields, booleans and currency fields; other processing might be added later if required
 * @param array $result - the webservices result object
 * @param array $descObj - the webservices describe object
 * @return array $result - the processes webservices result object
 */
function vttooltip_processResult($result, $descObj)
{
    global $current_user;
    foreach ($descObj['fields'] as $field) {
        if ($field['type']['name'] == 'reference') {
            $name = $field['name'];
            $value = $result[0][$name];
            if (!empty($value)) {
                $result[0][$name] = vtws_getName($value, $current_user);
            } else {
                $result[0][$name] = '';
            }
        } elseif ($field['type']['name'] == 'owner') {
            $name = $field['name'];
            $value = $result[0][$name];
            list($info, $id) = explode("x", $value);
            $result[0][$name] = getOwnerName($id);
        } elseif ($field['type']['name'] == 'boolean') {
            $name = $field['name'];
            if ($result[0][$name] == 1) {
                $result[0][$name] = "on";
            } else {
                $result[0][$name] = "off";
            }
        } elseif ($field['type']['name'] == 'picklist') {
            $name = $field['name'];
            $temp = '';
            foreach ($field['type']['picklistValues'] as $value) {
                if (strcmp($value['value'], $result[0][$name]) == 0) {
                    $temp = $value['value'];
                }
            }
            $result[0][$name] = $temp;
        }
    }
    return $result;
}
 function getFieldDisplayValue($moduleName, $recordId, $fieldInstance, $value)
 {
     global $current_user;
     $adb = PearDatabase::getInstance();
     $fieldName = $fieldInstance->getFieldName();
     $uitype = $fieldInstance->getUIType();
     if ($moduleName == 'Documents') {
         if ($fieldName == 'filesize') {
             $filesize = $value;
             if (empty($fieldsize)) {
                 $value = '--';
             } elseif ($filesize < 1024) {
                 $value = $filesize . ' B';
             } elseif ($filesize > 1024 && $filesize < 1048576) {
                 $value = round($filesize / 1024, 2) . ' KB';
             } else {
                 if ($filesize > 1048576) {
                     $value = round($filesize / (1024 * 1024), 2) . ' MB';
                 }
             }
         }
         if ($fieldName == 'filestatus') {
             if ($value == 1) {
                 $value = getTranslatedString('yes', $moduleName);
             } elseif ($value == 0) {
                 $value = getTranslatedString('no', $moduleName);
             } else {
                 $value = '--';
             }
         }
         if ($fieldName == 'filetype') {
             if ($value == 1) {
                 $value = getTranslatedString('yes', $moduleName);
             } elseif ($value == 0) {
                 $value = getTranslatedString('no', $moduleName);
             } else {
                 $value = '--';
             }
         }
     }
     if ($fieldInstance->getUIType() == '27') {
         if ($value == 'I') {
             $value = getTranslatedString('LBL_INTERNAL', $moduleName);
         } elseif ($value == 'E') {
             $value = getTranslatedString('LBL_EXTERNAL', $moduleName);
         } else {
             $value = ' --';
         }
     }
     if ($fieldInstance->getFieldDataType() == 'picklist') {
         $isRoleBased = vtws_isRoleBasedPicklist($fieldName);
         if ($isRoleBased && ($fieldName != 'activitytype' || $value != 'Task')) {
             $accessiblePicklistValues = getAssignedPicklistValues($fieldName, $current_user->roleid, $adb);
             if (!empty($value) && !is_admin($current_user) && !in_array($value, $accessiblePicklistValues)) {
                 $value = "<font color='red'>" . getTranslatedString('LBL_NOT_ACCESSIBLE', $moduleName) . "</font>";
             } else {
                 $value = getTranslatedString($value, $moduleName);
             }
         } else {
             $value = getTranslatedString($value, $moduleName);
         }
     }
     if ($fieldInstance->getFieldDataType() == 'date' || $fieldInstance->getFieldDataType() == 'datetime' || $fieldInstance->getFieldDataType() == 'time') {
         if ($value != '' && $value != '0000-00-00') {
             $date = new DateTimeField($value);
             if ($fieldInstance->getFieldDataType() == 'date') {
                 $value = $date->getDisplayDate();
             }
             if ($fieldInstance->getFieldDataType() == 'datetime') {
                 $value = $date->getDisplayDateTimeValue();
             }
             if ($fieldInstance->getFieldDataType() == 'time') {
                 $value = $date->getDisplayTime();
             }
         } else {
             $value = '';
         }
     }
     if ($fieldInstance->getFieldDataType() == 'currency') {
         if ($value != '' && $value != 0) {
             if ($fieldInstance->getUIType() == 72) {
                 if ($fieldName == 'unit_price') {
                     $currencyId = getProductBaseCurrency($recordId, $moduleName);
                     $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                     $currencySymbol = $cursym_convrate['symbol'];
                 } else {
                     $currencyInfo = getInventoryCurrencyInfo($moduleName, $recordId);
                     $currencySymbol = $currencyInfo['currency_symbol'];
                 }
                 $currencyValue = CurrencyField::convertToUserFormat($value, null, true);
                 $value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol);
             } else {
                 $currencyField = new CurrencyField($value);
                 $value = $currencyField->getDisplayValueWithSymbol();
             }
         }
     }
     if ($fieldInstance->getFieldDataType() == 'url') {
         $matchPattern = "^[\\w]+:\\/\\/^";
         preg_match($matchPattern, $value, $matches);
         if (!empty($matches[0])) {
             $value = '<a href="' . $value . '" target="_blank">' . $value . '</a>';
         } else {
             $value = '<a href="http://' . $value . '" target="_blank">' . $value . '</a>';
         }
     }
     if ($fieldInstance->getFieldDataType() == 'boolean') {
         if ($value == 1) {
             $value = getTranslatedString('yes', $moduleName);
         } elseif ($value == 0) {
             $value = getTranslatedString('no', $moduleName);
         } else {
             $value = '--';
         }
     }
     if ($fieldInstance->getFieldDataType() == 'multipicklist') {
         $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
         $isRoleBased = vtws_isRoleBasedPicklist($fieldName);
         if (!is_admin($current_user) && $value != '' && $isRoleBased) {
             $accessiblePicklistValues = getAssignedPicklistValues($fieldName, $current_user->roleid, $adb);
             $valueArray = $value != "" ? explode(', ', $value) : array();
             $notaccess = '<font color="red">' . getTranslatedString('LBL_NOT_ACCESSIBLE', $moduleName) . "</font>";
             $tmpArray = array();
             foreach ($valueArray as $index => $val) {
                 if (!in_array(trim($val), $accessiblePicklistValues)) {
                     $tmpArray[] = $notaccess;
                 } else {
                     $tmpArray[] = $val;
                 }
             }
             $value = implode(', ', $tmpArray);
         }
     }
     if ($fieldInstance->getFieldDataType() == 'reference') {
         if (!empty($value)) {
             $referenceList = $fieldInstance->getReferenceList();
             if (count($referenceList) > 0) {
                 $firstReferenceModule = $referenceList[0];
                 if ($firstReferenceModule == 'Users') {
                     $value = getUserFullName($value);
                 } elseif ($firstReferenceModule == 'DocumentFolders') {
                     $wsFolderId = vtws_getWebserviceEntityId('DocumentFolders', $value);
                     $value = vtws_getName($wsFolderId, $current_user);
                 } elseif ($firstReferenceModule == 'Currency') {
                     $value = getCurrencyName($value);
                 } else {
                     $referenceModule = getSalesEntityType($value);
                     $entityNames = getEntityName($referenceModule, array($value));
                     $value = $entityNames[$value];
                 }
             } else {
                 $value = '--';
             }
         } else {
             $value = '--';
         }
     }
     if ($fieldInstance->getFieldDataType() == 'owner') {
         $ownerName = trim(getUserFullName($value));
         if (empty($ownerName)) {
             $ownerInfo = getGroupName($value);
             $ownerName = $ownerInfo[0];
         }
         $value = $ownerName;
     }
     return $value;
 }