PDA

View Full Version : MS Word Letter Link?


Peekay
30-03-06, 04:00 AM
It would be great (IMHO) :rolleyes: if you could select a contact, press a 'Send Letter' button and have MS Word fire up with the contact's name and address in place. I use this feature all the time in Outlook and it's a real time saver for letters, estimates, invoices etc.

Alternatively, perhaps a 'Copy contact's name and address to clipboard' option?

I think the companies database is fine, but due to the field layout, you can't copy name, company and address together.

cyberhorse
30-03-06, 10:34 AM
That's not really possible due to loose integration between browsers and OS. The closest you can get is generate an .rtf file with the contact's name and address, which will be opened by word (if your browser is so setup).

opto
04-04-06, 06:50 AM
I posted this a few hours ago, but apparently something went wrong, so here it is again:



Actually, a mailmerge is possible in a LAN with the following changes:
The following is very incomplete, as I only did a proof of concept, so the code may contain errors.




contacts: next to the vcard edit, add a clickable mailmerge:

&nbsp;<a title="<?php echo $AppUI->_('MailMerge'); ?>" href="?m=contacts&a=sendcontact&contact_id=<?php echo $contactid; ?>"><?php echo $AppUI->_('MailMerge'); ?></a>


create a file sendcontact.php in the contacts module:

this should write the required fields of the contact into a textfile.

for single user version: no problem, php can write to local file system
for LAN: in principle, php can check for the ip of the requester, translate this into into the computer name (gethostbyaddr), and write the file there if the directory/file is write enabled. Problem in my network (peer to peer): takes extremely long (5-10s) to find the host name, maybe because we have no DNS server or I set the network incorrect. Due to the low speed, I have considered to add a table of ip versus computer name for a LAN. Any better ideas are appreciated.

Now create a Word mailmerge document and add as data source the (local) file that is created by php. Must be same filename/directory on all computers where it is supposed to run.

load this Word document into the template tab of the files tab.

sendcontact.php redirects to the files module, template tab. In the template tab, you now have to click the file you want to use, and after a request whether you want to save or open (choose open) you get word with the mailmerge document. If you see the field names instead the inserted values, you have to click the button <<ABC>> (at least in office 2000).

Problem: the fileviewer MUST display the files as attachment, not as inline. Solution: copy files module to module crmfiles, change the fileviewer in there and redirect to that fileviewer. Or add a parameter to fileviewer that decides whether downloaded inline or as attachment.


There is also a solution for WAN which I did not test, but works somewhat like this: It is based on an article in the German computer magazine ct, and the author (using it for some other application) has posted his sourcecode on sourceforge.
I don't have the magazine at my present location, but it works somewhat like this:

php: create a multipart message. One part is the master document, the other the mailmerge insertions.
Also, send this with an individual mime code (outside of the official ones).
Apparently, in your browser you can register applications to deal with documents having a specific mime code.
In the original article, the author locally installed perl and wrote a perl script to be started if that mime code appeared. The local script separated the multipart message and started word in mailmerge mode.

Other option for openoffice: the openoffice documents contain mailmerge data and original document in its zipped document. Unzip the document, replace the corresponding fields , zip again, send to local browser (see e.g. German php magazin)

I haven't realised this in code, but the info may be of interest to experienced programmers.

Also, in vtiger there is a thread how to do this for rtf documents. They claim this has some advantages over the Word version because easier handling of rtf versus doc by browser. see those threads.



sendcontact.php



<?php /* CONTACTS $Id: addedit.php,v 1.34 2005/03/03 23:13:47 jcgonz Exp $ */
GLOBAL $AppUI, $deny1, $canRead, $canEdit, $canAdmin;
global $company_id, $project_id, $task_id;





$contact_id = intval( dPgetParam( $_GET, 'contact_id', 0 ) );
$company_id = intval( dPgetParam( $_REQUEST, 'company_id', 0 ) );
$company_name = dPgetParam( $_REQUEST, 'company_name', null );

// check permissions for this record
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'contacts', 'view', $contact_id )) ) {
$AppUI->redirect( "m=public&a=access_denied" );
}

// load the record data
$msg = '';
$row = new CContact();
//$canDelete = $row->canDelete( $msg, $contact_id );

if (!$row->load( $contact_id ) && $contact_id > 0) {
$AppUI->setMsg( 'Contact' );
$AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
$AppUI->redirect();
} else if ($row->contact_private && $row->contact_owner != $AppUI->user_id
&& $row->contact_owner && $contact_id != 0) {
// check only owner can edit
$AppUI->redirect( "m=public&a=access_denied" );
}



?>



<?php
?>
<?php
//for single computer solution, other wise use something like
//$filecrm=fopen("//".gethostbyaddr('192.168.0.1')."/c/dotProject/testid.txt'","w");
//and get ip from html/php

$FileName='c:\\dotProject\\testid.txt';
$Err=$filecrm=fopen($FileName,'w');
fwrite($filecrm,$row->contact_first_name.';'.$row->contact_last_name);
fclose($filecrm);

$AppUI->redirect("m=crmfiles&tab=4");
?>

Peekay
04-04-06, 07:07 PM
Thx optosolar. Gonna try that out ASAP. :D