]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/SugarpdfSettings.php
Release 6.1.5
[Github/sugarcrm.git] / modules / Configurator / SugarpdfSettings.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM 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
40
41 if(!is_admin($current_user)){
42     sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
43 }
44
45 require_once("modules/Configurator/metadata/SugarpdfSettingsdefs.php");
46 if(file_exists('custom/modules/Configurator/metadata/SugarpdfSettingsdefs.php')){
47     require_once('custom/modules/Configurator/metadata/SugarpdfSettingsdefs.php');
48 }
49
50 if(!empty($_POST['save'])){
51     // Save the logos
52     $error=checkUploadImage();
53     if(empty($error)){
54         $focus = new Administration();
55         foreach($SugarpdfSettings as $k=>$v){
56             if($v['type'] == 'password'){
57                 if(isset($_POST[$k])){
58                     $_POST[$k] = blowfishEncode(blowfishGetKey($k), $_POST[$k]);
59                 }
60             }
61         }
62         if(!empty($_POST["sugarpdf_pdf_class"]) && $_POST["sugarpdf_pdf_class"] != PDF_CLASS){
63             // clear the cache for quotes detailview in order to switch the pdf class.
64             if(is_file($GLOBALS['sugar_config']['cache_dir'].'modules/Quotes/DetailView.tpl'))
65                 unlink($GLOBALS['sugar_config']['cache_dir'].'modules/Quotes/DetailView.tpl');
66         }
67         $focus->saveConfig();
68         header('Location: index.php?module=Administration&action=index');
69     }
70 }
71
72 if(!empty($_POST['restore'])){
73     $focus = new Administration();
74     foreach($_POST as $key => $val) {
75         $prefix = $focus->get_config_prefix($key);
76         if(in_array($prefix[0], $focus->config_categories)) {
77             $result = $focus->db->query("SELECT count(*) AS the_count FROM config WHERE category = '{$prefix[0]}' AND name = '{$prefix[1]}'");
78             $row = $focus->db->fetchByAssoc( $result, -1, true );
79             if( $row['the_count'] != 0){
80                 $focus->db->query("DELETE FROM config WHERE category = '{$prefix[0]}' AND name = '{$prefix[1]}'");
81             }
82         }
83     }
84     header('Location: index.php?module=Configurator&action=SugarpdfSettings');
85 }
86
87 echo getClassicModuleTitle(
88         "Administration",
89         array(
90             "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
91            $mod_strings['LBL_PDFMODULE_NAME'],
92            ),
93         true
94         );
95
96 $pdf_class = array("TCPDF"=>"TCPDF","EZPDF"=>"EZPDF");
97
98 require_once('include/Sugar_Smarty.php');
99 $sugar_smarty = new Sugar_Smarty();
100
101 $sugar_smarty->assign('MOD', $mod_strings);
102 $sugar_smarty->assign('APP', $app_strings);
103 $sugar_smarty->assign('APP_LIST', $app_list_strings);
104 $sugar_smarty->assign("JAVASCRIPT",get_set_focus_js());
105 $sugar_smarty->assign("SugarpdfSettings", $SugarpdfSettings);
106 $sugar_smarty->assign("pdf_enable_ezpdf", PDF_ENABLE_EZPDF);
107 if(PDF_ENABLE_EZPDF == "0" && PDF_CLASS == "EZPDF"){
108     $error = "ERR_EZPDF_DISABLE";
109     $sugar_smarty->assign("selected_pdf_class", "TCPDF");
110 }else{
111     $sugar_smarty->assign("selected_pdf_class", PDF_CLASS);
112 }
113 $sugar_smarty->assign("pdf_class", $pdf_class);
114
115 if(!empty($error)){
116     $sugar_smarty->assign("error", $mod_strings[$error]);
117 }
118 if (!function_exists('imagecreatefrompng')) {
119         $sugar_smarty->assign("GD_WARNING", 1);
120 }
121 else
122         $sugar_smarty->assign("GD_WARNING", 0);
123
124 $sugar_smarty->display('modules/Configurator/tpls/SugarpdfSettings.tpl');
125
126 require_once("include/javascript/javascript.php");
127 $javascript = new javascript();
128 $javascript->setFormName("ConfigureSugarpdfSettings");
129 foreach($SugarpdfSettings as $k=>$v){
130     if(isset($v["required"]) && $v["required"] == true)
131         $javascript->addFieldGeneric($k, "varchar", $v['label'], TRUE, "");
132 }
133
134 echo $javascript->getScript();
135
136 function checkUploadImage(){
137     $error="";
138     $files = array('sugarpdf_pdf_header_logo'=>$_FILES['new_header_logo'], 'sugarpdf_pdf_small_header_logo'=>$_FILES['new_small_header_logo']);
139     foreach($files as $k=>$v){
140         if(empty($error) && isset($v) && !empty($v['name'])){
141             $file_name = K_PATH_CUSTOM_IMAGES .'pdf_logo_'. basename($v['name']);
142             if(file_exists($file_name))
143                 rmdir_recursive($file_name);
144             if (!empty($v['error']))
145                 $error='ERR_ALERT_FILE_UPLOAD';
146             if(!mkdir_recursive(K_PATH_CUSTOM_IMAGES))
147                $error='ERR_ALERT_FILE_UPLOAD';
148             if(empty($error)){
149                 if (!move_uploaded_file($v['tmp_name'], $file_name))
150                     die("Possible file upload attack!\n");
151                 if(file_exists($file_name) && is_file($file_name)){
152                     if(!empty($_REQUEST['sugarpdf_pdf_class']) && $_REQUEST['sugarpdf_pdf_class'] == "EZPDF") {
153                         if(!verify_uploaded_image($file_name, true)) {
154                             $error='LBL_ALERT_TYPE_IMAGE_EZPDF';
155                         }
156                     } else {
157                         if(!verify_uploaded_image($file_name)) {
158                             $error='LBL_ALERT_TYPE_IMAGE';
159                         }
160                     }
161                     if(!empty($error)){
162                         rmdir_recursive($file_name);
163                     }else{
164                         $_POST[$k]='pdf_logo_'. basename($v['name']);
165                     }
166                 }else{
167                     $error='ERR_ALERT_FILE_UPLOAD';
168                 }
169             }
170         }
171     }
172     return $error;
173 }
174 ?>