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-2013 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 ********************************************************************************/
39 require_once('include/Sugarpdf/Sugarpdf.php');
41 class SugarpdfFactory{
43 * load the correct Tcpdf
44 * @param string $type Tcpdf Type
47 function loadSugarpdf($type = 'default', $module, $bean = null, $sugarpdf_object_map = array()){
48 $type = strtolower(basename($type));
49 //SugarpdfFactory::_loadConfig($sugarpdf, $type);
50 //first let's check if the module handles this Tcpdf
52 $path = '/sugarpdf/sugarpdf.'.$type.'.php';
53 if(file_exists('custom/modules/'.$module.$path)){
54 $sugarpdf = SugarpdfFactory::_buildFromFile('custom/modules/'.$module.$path, $bean, $sugarpdf_object_map, $type, $module);
55 }else if(file_exists('modules/'.$module.$path)){
56 $sugarpdf = SugarpdfFactory::_buildFromFile('modules/'.$module.$path, $bean, $sugarpdf_object_map, $type, $module);
57 }else if(file_exists('custom/include/Sugarpdf'.$path)){
58 $sugarpdf = SugarpdfFactory::_buildFromFile('custom/include/Sugarpdf'.$path, $bean, $sugarpdf_object_map, $type, $module);
60 //if the module does not handle this Sugarpdf, then check if Sugar handles it OOTB
61 $file = 'include/Sugarpdf'.$path;
62 if(file_exists($file)){
63 //it appears Sugar does have the proper logic for this file.
64 $sugarpdf = SugarpdfFactory::_buildFromFile($file, $bean, $sugarpdf_object_map, $type, $module);
67 // Default to Sugarpdf if still nothing found/built
68 if (!isset($sugarpdf))
69 $sugarpdf = new Sugarpdf($bean, $sugarpdf_object_map);
74 * Load the Sugarpdf_<Sugarpdf>_config.php file which holds options used by the tcpdf.
76 // function _loadConfig(&$sugarpdf, $type){
77 //// $sugarpdf_config_custom = array();
78 //// $sugarpdf_config_module = array();
79 //// $sugarpdf_config_root_cstm = array();
80 //// $sugarpdf_config_root = array();
81 //// $sugarpdf_config_app = array();
82 // $config_file_name = 'sugarpdf.'.$type.'.config.php';
83 // //echo ' <br /> '.$config_file_name.' <br />';
84 // //$sugarpdf_config = sugar_cache_retrieve("SUGARPDF_CONFIG_FILE_".$sugarpdf->module."_TYPE_".$type);
85 // if(!$sugarpdf_config){
86 // if(file_exists('custom/modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name)){
87 // require_once('custom/modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name);
89 // if(file_exists('modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name)){
90 // require_once('modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name);
92 // if(file_exists('custom/include/Sugarpdf/sugarpdf/'.$config_file_name)){
93 // require_once('custom/include/Sugarpdf/sugarpdf/'.$config_file_name);
95 // if(file_exists('include/Sugarpdf/sugarpdf/'.$config_file_name)){
96 // require_once('include/Sugarpdf/sugarpdf/'.$config_file_name);
98 // if(file_exists('include/Sugarpdf/sugarpdf/sugarpdf.config.php')){
99 // require_once('include/Sugarpdf/sugarpdf/sugarpdf.config.php');
106 * This is a private function which just helps the getSugarpdf function generate the
107 * proper Tcpdf object
109 * @return a valid Sugarpdf
111 function _buildFromFile($file, &$bean, $sugarpdf_object_map, $type, $module){
113 //try ModuleSugarpdfType first then try SugarpdfType if that fails then use Sugarpdf
114 $class = ucfirst($module).'Sugarpdf'.ucfirst($type);
115 if(!class_exists($class)){
116 $class = 'Sugarpdf'.ucfirst($type);
117 if(!class_exists($class)){
118 return new Sugarpdf($bean, $sugarpdf_object_map);
121 return SugarpdfFactory::_buildClass($class, $bean, $sugarpdf_object_map);
125 * instantiate the correct Tcpdf and call init to pass on any obejcts we need to
126 * from the controller.
128 * @param string class - the name of the class to instantiate
129 * @param object bean = the bean to pass to the Sugarpdf
130 * @param array Sugarpdf_object_map - the array which holds obejcts to pass between the
131 * controller and the tcpdf.
135 function _buildClass($class, &$bean, $sugarpdf_object_map){
138 $sugarpdf = new $class($bean, $sugarpdf_object_map);
139 //$sugarpdf->init($bean, $sugarpdf_object_map);
140 if($sugarpdf instanceof Sugarpdf){
143 return new Sugarpdf($bean, $sugarpdf_object_map);