]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Sugarpdf/sugarpdf/sugarpdf.smarty.php
Release 6.5.0
[Github/sugarcrm.git] / include / Sugarpdf / sugarpdf / sugarpdf.smarty.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 require_once('include/Sugarpdf/Sugarpdf.php');
40
41 /**
42  * This is an helper class to generate PDF using smarty template.
43  * You have to extend this class, set the templateLocation to your smarty template
44  * location and assign the Smarty variables ($this->ss->assign()) in the overriden
45  * preDisplay method (don't forget to call the parent).
46  * 
47  * @author bsoufflet
48  *
49  */
50 class SugarpdfSmarty extends Sugarpdf{
51     
52     /**
53      * 
54      * @var String
55      */
56     protected $templateLocation = "";
57     /**
58      * The Sugar_Smarty object
59      * @var Sugar_Smarty
60      */
61     protected $ss;
62     /**
63      * These 5 variables are use for the writeHTML method.
64      * @see include/tcpdf/tcpdf.php writeHTML()
65      */
66     protected $smartyLn = true;
67     protected $smartyFill = false;
68     protected $smartyReseth = false;
69     protected $smartyCell = false;
70     protected $smartyAlign = "";
71     
72     function preDisplay(){
73         parent::preDisplay();
74         $this->print_header = false;
75         $this->print_footer = false;
76         $this->_initSmartyInstance();
77     }
78     
79     function display(){
80         //turn off all error reporting so that PHP warnings don't munge the PDF code
81         error_reporting(E_ALL);
82         set_time_limit(1800);
83         
84         //Create new page           
85         $this->AddPage();
86         $this->SetFont(PDF_FONT_NAME_MAIN,'',8);
87         
88         if(!empty($this->templateLocation)){
89             $str = $this->ss->fetch($this->templateLocation);
90             $this->writeHTML($str, $this->smartyLn, $this->smartyFill, $this->smartyReseth, $this->smartyCell, $this->smartyAlign);
91         }else{
92             $this->Error('The class SugarpdfSmarty has to be extended and you have to set a location for the Smarty template.');
93         }
94     }
95     
96     /**
97      * Init the Sugar_Smarty object.
98      */
99     private function _initSmartyInstance(){
100         if ( !($this->ss instanceof Sugar_Smarty) ) {
101             require_once('include/Sugar_Smarty.php');
102             $this->ss = new Sugar_Smarty();
103             $this->ss->assign('MOD', $GLOBALS['mod_strings']);
104             $this->ss->assign('APP', $GLOBALS['app_strings']);
105         }
106     }
107     
108 }