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.
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.
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
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
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.
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.
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 ********************************************************************************/
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');
42 // set alternative config file
43 if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
46 * Installation path of TCPDF
48 define ("K_PATH_MAIN", $sugarpdf_default["K_PATH_MAIN"]);
50 * URL path to tcpdf installation folder
52 define ("K_PATH_URL", $sugarpdf_default["K_PATH_URL"]);
54 * custom path for PDF fonts (Use for non core added fonts)
56 define ("K_PATH_CUSTOM_FONTS", $sugarpdf_default["K_PATH_CUSTOM_FONTS"]);
60 define ("K_PATH_FONTS", $sugarpdf_default["K_PATH_FONTS"]);
62 * cache directory for temporary files (full path)
64 define ("K_PATH_CACHE", $sugarpdf_default["K_PATH_CACHE"]);
66 * cache directory for temporary files (url path)
68 define ("K_PATH_URL_CACHE", $sugarpdf_default["K_PATH_URL_CACHE"]);
71 * Custom path for images (use for loaded logos)
73 define ("K_PATH_CUSTOM_IMAGES", $sugarpdf_default["K_PATH_CUSTOM_IMAGES"]);
75 * Default path for images
77 define ("K_PATH_IMAGES", $sugarpdf_default["K_PATH_IMAGES"]);
81 define ("K_BLANK_IMAGE", $sugarpdf_default["K_BLANK_IMAGE"]);
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.
92 defineFromUserPreference ("PDF_PAGE_FORMAT", $sugarpdf_default["PDF_PAGE_FORMAT"]);
93 define("PDF_PAGE_FORMAT_LIST", $sugarpdf_default["PDF_PAGE_FORMAT_LIST"]);
95 * page orientation. Possible values are (case insensitive):P or Portrait (default), L or Landscape.
97 defineFromUserPreference ("PDF_PAGE_ORIENTATION", $sugarpdf_default["PDF_PAGE_ORIENTATION"]);
98 define("PDF_PAGE_ORIENTATION_LIST", $sugarpdf_default["PDF_PAGE_ORIENTATION_LIST"]);
100 * Defines the creator of the document. This is typically the name of the application that generates the PDF.
102 defineFromConfig("PDF_CREATOR", $sugarpdf_default["PDF_CREATOR"]);
104 * Defines the author of the document.
106 defineFromConfig("PDF_AUTHOR", $sugarpdf_default["PDF_AUTHOR"]);
110 defineFromConfig("PDF_HEADER_TITLE", $sugarpdf_default["PDF_HEADER_TITLE"]);
112 * header description string
114 defineFromConfig("PDF_HEADER_STRING", $sugarpdf_default["PDF_HEADER_STRING"]);
116 * image logo for the default Header
118 defineFromConfig("PDF_HEADER_LOGO", $sugarpdf_default["PDF_HEADER_LOGO"]);
120 * header logo image width [mm]
122 defineFromConfig("PDF_HEADER_LOGO_WIDTH", $sugarpdf_default["PDF_HEADER_LOGO_WIDTH"]);
124 * image logo for the default Header
126 defineFromConfig("PDF_SMALL_HEADER_LOGO", $sugarpdf_default["PDF_SMALL_HEADER_LOGO"]);
128 * header logo image width [mm]
130 defineFromConfig("PDF_SMALL_HEADER_LOGO_WIDTH", $sugarpdf_default["PDF_SMALL_HEADER_LOGO_WIDTH"]);
133 * document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch]
135 defineFromConfig('PDF_UNIT', $sugarpdf_default["PDF_UNIT"]);
140 defineFromUserPreference ('PDF_MARGIN_HEADER', $sugarpdf_default["PDF_MARGIN_HEADER"]);
145 defineFromUserPreference ('PDF_MARGIN_FOOTER', $sugarpdf_default["PDF_MARGIN_FOOTER"]);
150 defineFromUserPreference ('PDF_MARGIN_TOP', $sugarpdf_default["PDF_MARGIN_TOP"]);
155 defineFromUserPreference ('PDF_MARGIN_BOTTOM', $sugarpdf_default["PDF_MARGIN_BOTTOM"]);
160 defineFromUserPreference ('PDF_MARGIN_LEFT', $sugarpdf_default["PDF_MARGIN_LEFT"]);
165 defineFromUserPreference ('PDF_MARGIN_RIGHT', $sugarpdf_default["PDF_MARGIN_RIGHT"]);
170 defineFromUserPreference ('PDF_FONT_NAME_MAIN', $sugarpdf_default["PDF_FONT_NAME_MAIN"]);
175 defineFromUserPreference ("PDF_FONT_SIZE_MAIN", $sugarpdf_default["PDF_FONT_SIZE_MAIN"]);
179 defineFromUserPreference ('PDF_FONT_NAME_DATA', $sugarpdf_default["PDF_FONT_NAME_DATA"]);
184 defineFromUserPreference ('PDF_FONT_SIZE_DATA', $sugarpdf_default["PDF_FONT_SIZE_DATA"]);
187 * Ratio used to scale the images
189 defineFromConfig('PDF_IMAGE_SCALE_RATIO', $sugarpdf_default["PDF_IMAGE_SCALE_RATIO"]);
192 * magnification factor for titles
194 defineFromConfig('HEAD_MAGNIFICATION', $sugarpdf_default["HEAD_MAGNIFICATION"]);
197 * height of cell repect font height
199 defineFromConfig('K_CELL_HEIGHT_RATIO', $sugarpdf_default["K_CELL_HEIGHT_RATIO"]);
202 * title magnification respect main font size
204 defineFromConfig('K_TITLE_MAGNIFICATION', $sugarpdf_default["K_TITLE_MAGNIFICATION"]);
207 * reduction factor for small font
209 defineFromConfig('K_SMALL_RATIO', $sugarpdf_default["K_SMALL_RATIO"]);
214 * PDF class use to generate pdf : EZPDF or TCPDF
216 defineFromConfig("PDF_CLASS", $sugarpdf_default["PDF_CLASS"]);
218 * Enable or not the EZPDF class (enable for upgraded system disable otherwise) : 1 or 0
220 defineFromConfig("PDF_ENABLE_EZPDF", $sugarpdf_default["PDF_ENABLE_EZPDF"]);
222 * Default file name for the generated pdf file.
224 defineFromConfig("PDF_FILENAME", $sugarpdf_default["PDF_FILENAME"]);
227 * Title of the document
229 defineFromConfig("PDF_TITLE", $sugarpdf_default["PDF_TITLE"]);
232 * Keywords of the PDF document
234 defineFromConfig("PDF_KEYWORDS", $sugarpdf_default["PDF_KEYWORDS"]);
237 * Subject of the PDF document
239 defineFromConfig("PDF_SUBJECT", $sugarpdf_default["PDF_SUBJECT"]);
242 * Compression of the PDF Document
244 defineFromConfig("PDF_COMPRESSION", $sugarpdf_default["PDF_COMPRESSION"]);
247 * Quality of the JPEG images (0 to 100)
249 defineFromConfig("PDF_JPEG_QUALITY", $sugarpdf_default["PDF_JPEG_QUALITY"]);
252 * PDF version of the PDF document
254 defineFromConfig("PDF_PDF_VERSION", $sugarpdf_default["PDF_PDF_VERSION"]);
257 * Set document protection (available are: copy, print, modify, annot-forms. Seperate with a coma)
259 defineFromConfig("PDF_PROTECTION", $sugarpdf_default["PDF_PROTECTION"]);
262 * User password to view the document. If empty no password
264 defineFromConfig("PDF_USER_PASSWORD", $sugarpdf_default["PDF_USER_PASSWORD"]);
267 * master password to get full access.
269 defineFromConfig("PDF_OWNER_PASSWORD", $sugarpdf_default["PDF_OWNER_PASSWORD"]);
272 * Default ACL access value for the generation of a PDF (detail, list, edit, export)
274 defineFromConfig("PDF_ACL_ACCESS", $sugarpdf_default["PDF_ACL_ACCESS"]);
277 * Available encoding tables when adding a new font
279 define("PDF_ENCODING_TABLE_LIST", $sugarpdf_default["PDF_ENCODING_TABLE_LIST"]);
282 * Available encoding tables when adding a new font (Label)
284 define("PDF_ENCODING_TABLE_LABEL_LIST", $sugarpdf_default["PDF_ENCODING_TABLE_LABEL_LIST"]);
286 if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
287 define("K_TCPDF_EXTERNAL_CONFIG", true);
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
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]);
304 define($value, $default);
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.
316 * @param $value settings to search
317 * @param $default default value
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);
325 $pref = $current_user->getPreference("sugarpdf_".$lowerValue);
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'])){
335 if(isset($pref) && !defined('SUGARPDF_USE_DEFAULT_SETTINGS')){
336 define($value, $pref);
338 define($value, $default);