function merge_template($confirmation, $form, $entry, $ajax)
{
    if (isset($_POST['gform_save_state_' . $form['id']])) {
        return $confirmation;
    }
    /* this should never happend */
    global $wpdb;
    $return = "";
    $formid = $entry['form_id'];
    $where = 'form_id =' . $formid;
    $params = array('where' => $where);
    $templates = gettplList($params);
    $fieldmap = gettplFieldMap($params);
    $data_title = RGFormsModel::get_form($formid);
    $form_title = $data_title->title;
    if (!empty($templates['meta']['files'])) {
        $return = tpl_combine($entry, $templates, $fieldmap);
    }
    $letters = "";
    $invoices = "";
    if ($return != "") {
        $letters = LettersMerge($entry, $fieldmap);
        $invoices = InvoicesMerge($entry, $fieldmap);
        //TriggerOrderEmail($entry['id']);
        $doc_email_msg = TriggerDocumentEmail($entry['id']);
        if (!empty($doc_email_msg) && $doc_email_msg['status'] == 'success') {
            $confirmation .= $doc_email_msg['msg'];
        }
        $return = str_replace("\\", "/", $return);
        //$confirmation .= " <a href='".$return."' target='_blank'>You can also download the document here</a>";
        $confirmation .= " or You can Click and Download the links below: ";
        $confirmation .= "<ol><li><a href='" . $return . "' target='_blank'>" . $form_title . "</a>.</li>";
        if (!empty($invoices)) {
            $invoices = str_replace("\\", "/", $invoices);
            //$confirmation .= " And also <a href='".$invoices."' target='_blank'>download your Invoice document here.</a>";
            $confirmation .= "<li><a href='" . $invoices . "' target='_blank'>Tax Invoice</a></li>";
        }
        if (!empty($letters)) {
            $letters = str_replace("\\", "/", $letters);
            //$confirmation .= " And also <a href='".$letters."' target='_blank'>download your Letter document here.</a>";
            $confirmation .= "<li><a href='" . $letters . "' target='_blank'>Cover Letter</a></li>";
        }
        $confirmation .= "</ol>";
        if (isset($_GET["q"]) && $_GET["type"] == "edit") {
            $id = decrypt_doc_url(rgget("q"));
            TemplateData::delete_confirmation_saved($id);
        }
    }
    return $confirmation;
}