SugarCRM View documents in browser.

SugarCRM View documents in browser.

July 23, 2012 PHP SugarCRM Uncategorized 0

( Currently Supported PDF and Text file )

- Make a directory called “doc” within the “custom” folder (rights: 777).

- Make a  php file called “showfile.php” (rights: 777) in the “prudento” folder.

- Place the following code within showfile.php:

for all doc:::::

<?php
$FileNaam=$_GET['file'];
$FileType=$_GET['type'];
$base = str_replace(‘/custom/doc/showfile.php’, ” ,$_SERVER['PHP_SELF'] );
echo ‘<body scroll=”no” style=”overflow:hide; height:480px;”>’;
echo ‘<div id=”bg_image” style=”position:absolute; top:0px; left:0px; height:100%; width:100%”>’;
echo ‘<embed src=”http://docs.google.com/gview?url=http://’ . $_SERVER['SERVER_NAME'] . $base . ‘/cache/upload/’. $FileNaam .’&embedded=true “id=”application/pdf” width=”100%” height=”480px” ></embed >’;
echo ‘</div>’;
?>

for pdf and text exclude doc::::::::

<?php
$FileNaam=$_GET['file'];
$FileType=$_GET['type'];
/************************************
* find root of the sugarinstallation
************************************/

$base = str_replace(‘/custom/doc/showfile.php’, ” ,$_SERVER['PHP_SELF'] );

/************************************
* build html page to show in iframe field
************************************/


echo ‘<body scroll=”no” style=”overflow:hidden; height:100%;”>’;
echo ‘<div id=”bg_image” style=”position:absolute; top:0px; left:0px; height:100%; width:100%”>’;
echo ‘<embed src=”http://’ . $_SERVER['SERVER_NAME'] . $base . ‘/cache/upload/’. $FileNaam .’” id=”imgPhoto” width=”100%” height=”100%” ></embed >’;
echo ‘</div>’;
?>

Go to studio=>documents=>fields an make a costum field with these properties:

- Datatype: Iframe

- Field label: Preview

- Generate URL: Yes

- Standard value: http://domain.com/custom/doc/showfile.php?file={document_revision_id}

- Maximun size: 225

- Iframe height: 500

- Save

- Go to studio=>documents=>layout=>detailview and make a panel called something like “preview”

- Place the “preview” block on the new panel and make it fit the whole line.

- Do a quick repair in the admin menu

- Open the .htaccess (if any) in the sugar root folder.

- Comment out or delete the 2 rows with the cache and temp folder ( otherwise Googledocs cant access the files)

 

Leave a Reply

Your email address will not be published. Required fields are marked *