]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Sugarpdf/SugarpdfFactory.php
Release 6.4.0
[Github/sugarcrm.git] / include / Sugarpdf / SugarpdfFactory.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-2011 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 class SugarpdfFactory{
42     /**
43      * load the correct Tcpdf
44      * @param string $type Tcpdf Type
45      * @return valid Tcpdf
46      */
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
51         $sugarpdf = null;
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);
59         }else{
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);
65             }
66         }    
67         // Default to Sugarpdf if still nothing found/built
68         if (!isset($sugarpdf)) 
69             $sugarpdf = new Sugarpdf($bean, $sugarpdf_object_map);
70         return $sugarpdf;
71     }
72     
73     /**
74      * Load the Sugarpdf_<Sugarpdf>_config.php file which holds options used by the tcpdf.
75      */
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);
88 //            } 
89 //            if(file_exists('modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name)){
90 //                require_once('modules/'.$sugarpdf->module.'/sugarpdf/'.$config_file_name);
91 //            }
92 //            if(file_exists('custom/include/Sugarpdf/sugarpdf/'.$config_file_name)){
93 //                require_once('custom/include/Sugarpdf/sugarpdf/'.$config_file_name);
94 //            }
95 //            if(file_exists('include/Sugarpdf/sugarpdf/'.$config_file_name)){
96 //                require_once('include/Sugarpdf/sugarpdf/'.$config_file_name);
97 //            }    
98 //            if(file_exists('include/Sugarpdf/sugarpdf/sugarpdf.config.php')){
99 //                require_once('include/Sugarpdf/sugarpdf/sugarpdf.config.php');
100 //            }
101 //        }
102 //
103 //    }    
104     
105     /**
106      * This is a private function which just helps the getSugarpdf function generate the
107      * proper Tcpdf object
108      * 
109      * @return a valid Sugarpdf
110      */
111     function _buildFromFile($file, &$bean, $sugarpdf_object_map, $type, $module){
112         require_once($file);
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);
119             }
120         }
121         return SugarpdfFactory::_buildClass($class, $bean, $sugarpdf_object_map);    
122     }
123     
124     /**
125      * instantiate the correct Tcpdf and call init to pass on any obejcts we need to
126      * from the controller.
127      * 
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.
132      * 
133      * @return Sugarpdf
134      */
135     function _buildClass($class, &$bean, $sugarpdf_object_map){
136         
137
138         $sugarpdf = new $class($bean, $sugarpdf_object_map);
139         //$sugarpdf->init($bean, $sugarpdf_object_map);
140         if($sugarpdf instanceof Sugarpdf){
141             return $sugarpdf;
142         }else
143             return new Sugarpdf($bean, $sugarpdf_object_map);
144     }
145 }
146 ?>