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