]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Sugarpdf/sugarpdf_config.php
Release 6.5.0
[Github/sugarcrm.git] / include / Sugarpdf / sugarpdf_config.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 require_once('include/Sugarpdf/sugarpdf_default.php');
39 if(file_exists('custom/include/Sugarpdf/sugarpdf_default.php')){
40     require_once('custom/include/Sugarpdf/sugarpdf_default.php');
41 }
42 // set alternative config file
43 if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
44     
45     /*
46      *  Installation path of TCPDF
47      */
48     define ("K_PATH_MAIN", $sugarpdf_default["K_PATH_MAIN"]);
49     /**
50      * URL path to tcpdf installation folder
51      */
52     define ("K_PATH_URL", $sugarpdf_default["K_PATH_URL"]);
53     /**
54      * custom path for PDF fonts (Use for non core added fonts)
55      */
56     define ("K_PATH_CUSTOM_FONTS", $sugarpdf_default["K_PATH_CUSTOM_FONTS"]);
57      /**
58      * path for PDF fonts
59      */
60     define ("K_PATH_FONTS", $sugarpdf_default["K_PATH_FONTS"]);
61     /**
62      * cache directory for temporary files (full path)
63      */
64     define ("K_PATH_CACHE", $sugarpdf_default["K_PATH_CACHE"]);
65     /**
66      * cache directory for temporary files (url path)
67      */
68     define ("K_PATH_URL_CACHE", $sugarpdf_default["K_PATH_URL_CACHE"]);
69
70     /*
71      * Custom path for images (use for loaded logos)
72      */ 
73     define ("K_PATH_CUSTOM_IMAGES", $sugarpdf_default["K_PATH_CUSTOM_IMAGES"]);
74     /*
75      * Default path for images
76      */ 
77     define ("K_PATH_IMAGES", $sugarpdf_default["K_PATH_IMAGES"]);
78     /*
79      * Blank image
80      */
81     define ("K_BLANK_IMAGE", $sugarpdf_default["K_BLANK_IMAGE"]);
82     /*
83      * The format used for pages.
84      * It can be either one of the following values (case insensitive)
85      * or a custom format in the form of a two-element array containing
86      * the width and the height (expressed in the unit given by unit).
87      * 4A0, 2A0, A0, A1, A2, A3, A4 (default), A5, A6, A7, A8, A9, A10, 
88      * B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, C0, C1, C2, C3, C4, 
89      * C5, C6, C7, C8, C9, C10, RA0, RA1, RA2, RA3, RA4, SRA0, SRA1, 
90      * SRA2, SRA3, SRA4, LETTER, LEGAL, EXECUTIVE, FOLIO.
91      */
92     defineFromUserPreference ("PDF_PAGE_FORMAT", $sugarpdf_default["PDF_PAGE_FORMAT"]);
93     define("PDF_PAGE_FORMAT_LIST", $sugarpdf_default["PDF_PAGE_FORMAT_LIST"]);
94     /*
95      * page orientation. Possible values are (case insensitive):P or Portrait (default), L or Landscape.
96      */
97     defineFromUserPreference ("PDF_PAGE_ORIENTATION", $sugarpdf_default["PDF_PAGE_ORIENTATION"]);
98     define("PDF_PAGE_ORIENTATION_LIST", $sugarpdf_default["PDF_PAGE_ORIENTATION_LIST"]);
99     /*
100      * Defines the creator of the document. This is typically the name of the application that generates the PDF.
101      */
102     defineFromConfig("PDF_CREATOR", $sugarpdf_default["PDF_CREATOR"]);
103     /*
104      * Defines the author of the document.
105      */
106     defineFromConfig("PDF_AUTHOR", $sugarpdf_default["PDF_AUTHOR"]);
107      /**
108      * header title
109      */
110     defineFromConfig("PDF_HEADER_TITLE", $sugarpdf_default["PDF_HEADER_TITLE"]);
111      /**
112      * header description string
113      */
114     defineFromConfig("PDF_HEADER_STRING", $sugarpdf_default["PDF_HEADER_STRING"]);
115     /**
116      * image logo for the default Header
117      */
118     defineFromConfig("PDF_HEADER_LOGO", $sugarpdf_default["PDF_HEADER_LOGO"]);
119     /**
120      * header logo image width [mm]
121      */
122     defineFromConfig("PDF_HEADER_LOGO_WIDTH", $sugarpdf_default["PDF_HEADER_LOGO_WIDTH"]);
123         /**
124      * image logo for the default Header
125      */
126     defineFromConfig("PDF_SMALL_HEADER_LOGO", $sugarpdf_default["PDF_SMALL_HEADER_LOGO"]);
127     /**
128      * header logo image width [mm]
129      */
130     defineFromConfig("PDF_SMALL_HEADER_LOGO_WIDTH", $sugarpdf_default["PDF_SMALL_HEADER_LOGO_WIDTH"]);
131     
132     /**
133      *  document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch]
134      */
135     defineFromConfig('PDF_UNIT', $sugarpdf_default["PDF_UNIT"]);
136     
137     /**
138      * header margin
139      */
140     defineFromUserPreference ('PDF_MARGIN_HEADER', $sugarpdf_default["PDF_MARGIN_HEADER"]);
141     
142     /**
143      * footer margin
144      */
145     defineFromUserPreference ('PDF_MARGIN_FOOTER', $sugarpdf_default["PDF_MARGIN_FOOTER"]);
146     
147     /**
148      * top margin
149      */
150     defineFromUserPreference ('PDF_MARGIN_TOP', $sugarpdf_default["PDF_MARGIN_TOP"]);
151     
152     /**
153      * bottom margin
154      */
155     defineFromUserPreference ('PDF_MARGIN_BOTTOM', $sugarpdf_default["PDF_MARGIN_BOTTOM"]);
156     
157     /**
158      * left margin
159      */
160     defineFromUserPreference ('PDF_MARGIN_LEFT', $sugarpdf_default["PDF_MARGIN_LEFT"]);
161     
162     /**
163      * right margin
164      */
165     defineFromUserPreference ('PDF_MARGIN_RIGHT', $sugarpdf_default["PDF_MARGIN_RIGHT"]);
166     
167     /**
168      * main font name
169      */
170     defineFromUserPreference ('PDF_FONT_NAME_MAIN', $sugarpdf_default["PDF_FONT_NAME_MAIN"]);
171     
172     /**
173      * main font size
174      */
175     defineFromUserPreference ("PDF_FONT_SIZE_MAIN", $sugarpdf_default["PDF_FONT_SIZE_MAIN"]);
176     /**
177      * data font name
178      */
179     defineFromUserPreference ('PDF_FONT_NAME_DATA', $sugarpdf_default["PDF_FONT_NAME_DATA"]);
180     
181     /**
182      * data font size
183      */
184     defineFromUserPreference ('PDF_FONT_SIZE_DATA', $sugarpdf_default["PDF_FONT_SIZE_DATA"]);
185     
186     /**
187      * Ratio used to scale the images
188      */
189     defineFromConfig('PDF_IMAGE_SCALE_RATIO', $sugarpdf_default["PDF_IMAGE_SCALE_RATIO"]);
190     
191     /**
192      * magnification factor for titles
193      */
194     defineFromConfig('HEAD_MAGNIFICATION', $sugarpdf_default["HEAD_MAGNIFICATION"]);
195     
196     /**
197      * height of cell repect font height
198      */
199     defineFromConfig('K_CELL_HEIGHT_RATIO', $sugarpdf_default["K_CELL_HEIGHT_RATIO"]);
200     
201     /**
202      * title magnification respect main font size
203      */
204     defineFromConfig('K_TITLE_MAGNIFICATION', $sugarpdf_default["K_TITLE_MAGNIFICATION"]);
205     
206     /**
207      * reduction factor for small font
208      */
209     defineFromConfig('K_SMALL_RATIO', $sugarpdf_default["K_SMALL_RATIO"]);
210
211 }
212 // Sugarpdf define
213 /**
214  * PDF class use to generate pdf : EZPDF or TCPDF
215  */
216 defineFromConfig("PDF_CLASS", $sugarpdf_default["PDF_CLASS"]);
217 /**
218  * Enable or not the EZPDF class (enable for upgraded system disable otherwise) : 1 or 0
219  */
220 defineFromConfig("PDF_ENABLE_EZPDF", $sugarpdf_default["PDF_ENABLE_EZPDF"]);
221 /**
222  * Default file name for the generated pdf file.
223  */
224 defineFromConfig("PDF_FILENAME", $sugarpdf_default["PDF_FILENAME"]);
225
226 /**
227  * Title of the document
228  */
229 defineFromConfig("PDF_TITLE", $sugarpdf_default["PDF_TITLE"]);
230
231 /**
232  * Keywords of the PDF document
233  */
234 defineFromConfig("PDF_KEYWORDS", $sugarpdf_default["PDF_KEYWORDS"]);
235
236 /**
237  * Subject of the PDF document
238  */
239 defineFromConfig("PDF_SUBJECT", $sugarpdf_default["PDF_SUBJECT"]);
240
241 /**
242  * Compression of the PDF Document
243  */
244 defineFromConfig("PDF_COMPRESSION", $sugarpdf_default["PDF_COMPRESSION"]);
245
246 /**
247  * Quality of the JPEG images (0 to 100)
248  */
249 defineFromConfig("PDF_JPEG_QUALITY", $sugarpdf_default["PDF_JPEG_QUALITY"]);
250
251 /**
252  * PDF version of the PDF document
253  */
254 defineFromConfig("PDF_PDF_VERSION", $sugarpdf_default["PDF_PDF_VERSION"]);
255
256 /**
257  * Set document protection (available are: copy, print, modify, annot-forms. Seperate with a coma) 
258  */
259 defineFromConfig("PDF_PROTECTION", $sugarpdf_default["PDF_PROTECTION"]);
260
261 /**
262  * User password to view the document. If empty no password
263  */
264 defineFromConfig("PDF_USER_PASSWORD", $sugarpdf_default["PDF_USER_PASSWORD"]);
265
266 /**
267  * master password to get full access.
268  */
269 defineFromConfig("PDF_OWNER_PASSWORD", $sugarpdf_default["PDF_OWNER_PASSWORD"]);
270
271 /**
272  * Default ACL access value for the generation of a PDF (detail, list, edit, export)
273  */
274 defineFromConfig("PDF_ACL_ACCESS", $sugarpdf_default["PDF_ACL_ACCESS"]);
275
276 /**
277  * Available encoding tables when adding a new font
278  */
279 define("PDF_ENCODING_TABLE_LIST", $sugarpdf_default["PDF_ENCODING_TABLE_LIST"]);
280
281 /**
282  * Available encoding tables when adding a new font (Label)
283  */
284 define("PDF_ENCODING_TABLE_LABEL_LIST", $sugarpdf_default["PDF_ENCODING_TABLE_LABEL_LIST"]);
285
286 if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
287     define("K_TCPDF_EXTERNAL_CONFIG", true);
288 }
289
290 /**
291  * Function to define a sugarpdf seeting from the admin application settings (config table).
292  * This function use the default value if there is nothing in the table.
293  * @param $value    settings to search
294  * @param $default  default value
295  */
296 function defineFromConfig($value, $default){
297     $lowerValue = strtolower($value);
298    require_once("modules/Administration/Administration.php");
299     $focus = new Administration();
300     $focus->retrieveSettings();
301     if(isset($focus->settings["sugarpdf_".$lowerValue])){
302         define($value, $focus->settings["sugarpdf_".$lowerValue]);
303     }else{
304         define($value, $default);
305     }
306 }
307
308 /**
309  * This function define a Sugarpdf setting from the user preferences.
310  * This function use the default value if there is no preference.
311  * If SUGARPDF_USE_DEFAULT_SETTINGS is define the function will always
312  * use the default value.
313  * SUGARPDF_USE_FOCUS is use to load the preference of the none current user. To use
314  * this constant you have to define a global variable $focus_user.
315  * 
316  * @param $value    settings to search
317  * @param $default  default value
318  */
319 function defineFromUserPreference($value, $default){
320     global $focus_user, $current_user;
321     $lowerValue = strtolower($value);
322     if(defined('SUGARPDF_USE_FOCUS')){
323         $pref = $focus_user->getPreference("sugarpdf_".$lowerValue);
324     }else{
325         $pref = $current_user->getPreference("sugarpdf_".$lowerValue);
326     }
327     if(strpos($value, "PDF_FONT_NAME_") !== false){
328         require_once('include/Sugarpdf/FontManager.php');
329         $fontManager = new FontManager();
330         $fontManager->listFontFiles();
331         if(!isset($fontManager->fontList[$pref]) || !$fontManager->fontFileExist($fontManager->fontList[$pref]['filename'])){
332             $pref = $default;
333         }
334     }
335     if(isset($pref) && !defined('SUGARPDF_USE_DEFAULT_SETTINGS')){
336         define($value, $pref);
337     }else{
338         define($value, $default);
339     }
340     
341 }