示例#1
0
文件: CommonUtils.php 项目: p6/VF
/**
 * 	This function is used to merge the Template Details with the email description  
 *  @param string $description  -body of the mail(ie template)
 *	@param integer $tid  - Id of the entity
 *  @param string $parent_type - module of the entity
 * 	return string $description - Returns description, merged with the input template.
*/
function getMergedDescription($description, $id, $parent_type)
{
    global $adb, $log;
    $log->debug("Entering getMergedDescription ...");
    $token_data_pair = explode('$', $description);
    $fields = array();
    for ($i = 1; $i < count($token_data_pair); $i += 2) {
        $module = explode('-', $token_data_pair[$i]);
        $fields[$module[0]][] = $module[1];
    }
    //replace the tokens with the values for the selected parent
    switch ($parent_type) {
        case 'Accounts':
            if (is_array($fields["accounts"])) {
                $columnfields = implode(',', $fields["accounts"]);
                $query = "select {$columnfields} from vtiger_account inner join vtiger_accountscf where vtiger_account.accountid =? and vtiger_accountscf.accountid =?";
                $result = $adb->pquery($query, array($id, $id));
                foreach ($fields["accounts"] as $columnname) {
                    $token_data = '$accounts-' . $columnname . '$';
                    $description = str_replace($token_data, $adb->query_result($result, 0, $columnname), $description);
                }
            }
            break;
        case 'Contacts':
            if (is_array($fields["contacts"])) {
                //Checking for salutation type and checking the table column to be queried
                $key = array_search('salutationtype', $fields["contacts"]);
                if (isset($key) && $key != '') {
                    $fields["contacts"][$key] = 'salutation';
                }
                $columnfields = implode(',', $fields["contacts"]);
                $query = "select {$columnfields} from vtiger_contactdetails inner join vtiger_contactscf inner join vtiger_customerdetails on vtiger_customerdetails.customerid=vtiger_contactdetails.contactid and vtiger_customerdetails.customerid=vtiger_contactscf.contactid where vtiger_contactdetails.contactid=?";
                $result = $adb->pquery($query, array($id, $id));
                foreach ($fields["contacts"] as $columnname) {
                    $token_data = '$contacts-' . $columnname . '$';
                    $token_value = $adb->query_result($result, 0, $columnname);
                    // Fix for #5417
                    if ($columnname == 'salutation') {
                        $token_value = getTranslatedString($token_value, 'Contacts');
                    }
                    $description = str_replace($token_data, $token_value, $description);
                }
            }
            break;
        case 'Leads':
            if (is_array($fields["leads"])) {
                //Checking for salutation type and checking the table column to be queried
                $key = array_search('salutationtype', $fields["leads"]);
                if (isset($key) && $key != '') {
                    $fields["leads"][$key] = 'salutation';
                }
                $columnfields = implode(',', $fields["leads"]);
                $query = "select {$columnfields} from vtiger_leaddetails inner join vtiger_leadscf where vtiger_leaddetails.leadid=? and vtiger_leadscf.leadid=?";
                $result = $adb->pquery($query, array($id, $id));
                foreach ($fields["leads"] as $columnname) {
                    $token_data = '$leads-' . $columnname . '$';
                    $token_value = $adb->query_result($result, 0, $columnname);
                    // Fix for #5417
                    if ($columnname == 'salutation') {
                        $token_value = getTranslatedString($token_value, 'Leads');
                    }
                    $description = str_replace($token_data, $token_value, $description);
                }
            }
            break;
        case 'Users':
            if (is_array($fields["users"])) {
                $columnfields = implode(',', $fields["users"]);
                $query = "select {$columnfields} from vtiger_users where id=?";
                $result = $adb->pquery($query, array($id));
                foreach ($fields["users"] as $columnname) {
                    $token_data = '$users-' . $columnname . '$';
                    $description = str_replace($token_data, $adb->query_result($result, 0, $columnname), $description);
                }
            }
            break;
    }
    $description = getMergedDescriptionCustomVars($fields, $description);
    //Puneeth : Added for custom date & time fields
    $log->debug("Exiting from getMergedDescription ...");
    return $description;
}
示例#2
0
/**
 * 	This function is used to merge the Template Details with the email description
 *  @param string $description  -body of the mail(ie template)
 *	@param integer $tid  - Id of the entity
 *  @param string $parent_type - module of the entity
 * 	return string $description - Returns description, merged with the input template.
*/
function getMergedDescription($description, $id, $parent_type)
{
    global $adb, $log;
    $log->debug("Entering getMergedDescription ...");
    $token_data_pair = explode('$', $description);
    global $current_user;
    $emailTemplate = new EmailTemplate($parent_type, $description, $id, $current_user);
    $description = $emailTemplate->getProcessedDescription();
    $templateVariablePair = explode('$', $description);
    $tokenDataPair = explode('$', $description);
    $fields = array();
    for ($i = 1; $i < count($token_data_pair); $i += 2) {
        $module = explode('-', $tokenDataPair[$i]);
        $fields[$module[0]][] = $module[1];
    }
    if (is_array($fields['custom']) && count($fields['custom']) > 0) {
        //Puneeth : Added for custom date & time fields
        $description = getMergedDescriptionCustomVars($fields, $description);
    }
    $log->debug("Exiting from getMergedDescription ...");
    return $description;
}
示例#3
0
/**
 * 	This function is used to merge the Template Details with the email description
 *  @param string $description  -body of the mail(ie template)
 * 	@param integer $tid  - Id of the entity
 *  @param string $parent_type - module of the entity
 * 	return string $description - Returns description, merged with the input template.
 */
function getMergedDescription($description, $id, $parent_type)
{
    global $adb, $log;
    $log->debug("Entering getMergedDescription ...");
    $token_data_pair = explode('$', $description);
    global $current_user;
    if ($parent_type != 'Users') {
        $emailTemplate = new EmailTemplate($parent_type, $description, $id, $current_user);
        $description = $emailTemplate->getProcessedDescription();
    }
    $templateVariablePair = explode('$', $description);
    $tokenDataPair = explode('$', $description);
    $fields = array();
    for ($i = 1; $i < count($token_data_pair); $i += 2) {
        $module = explode('-', $tokenDataPair[$i]);
        $fields[$module[0]][] = $module[1];
    }
    if (is_array($fields['custom']) && count($fields['custom']) > 0) {
        //Puneeth : Added for custom date & time fields
        $description = getMergedDescriptionCustomVars($fields, $description);
    }
    if ($parent_type == 'Users' && is_array($fields["users"])) {
        $columnfields = implode(',', $fields["users"]);
        $query = "select {$columnfields} from vtiger_users where id=?";
        $result = $adb->pquery($query, array($id));
        foreach ($fields["users"] as $columnname) {
            $token_data = '$users-' . $columnname . '$';
            $description = str_replace($token_data, $adb->query_result($result, 0, $columnname), $description);
        }
    }
    $log->debug("Exiting from getMergedDescription ...");
    return $description;
}