]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/views/view.sugarpdfsettings.php
Release 6.2.0beta4
[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 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 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($GLOBALS['sugar_config']['cache_dir'].'modules/Quotes/DetailView.tpl'))
90                         unlink($GLOBALS['sugar_config']['cache_dir'].'modules/Quotes/DetailView.tpl');
91                 }
92                 $focus->saveConfig();
93                 header('Location: index.php?module=Administration&action=index');
94             }
95         }
96         
97         if(!empty($_POST['restore'])){
98             $focus = new Administration();    
99             foreach($_POST as $key => $val) {
100                 $prefix = $focus->get_config_prefix($key);
101                 if(in_array($prefix[0], $focus->config_categories)) {
102                     $result = $focus->db->query("SELECT count(*) AS the_count FROM config WHERE category = '{$prefix[0]}' AND name = '{$prefix[1]}'");
103                     $row = $focus->db->fetchByAssoc( $result, -1, true );
104                     if( $row['the_count'] != 0){
105                         $focus->db->query("DELETE FROM config WHERE category = '{$prefix[0]}' AND name = '{$prefix[1]}'");
106                     }
107                 }
108             }
109             header('Location: index.php?module=Configurator&action=SugarpdfSettings');
110         }
111         
112         echo getClassicModuleTitle(
113                 "Administration", 
114                 array(
115                     "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
116                    $mod_strings['LBL_PDFMODULE_NAME'],
117                    ), 
118                 false
119                 );
120         
121         $pdf_class = array("TCPDF"=>"TCPDF","EZPDF"=>"EZPDF");
122         
123         $this->ss->assign('APP_LIST', $app_list_strings);
124         $this->ss->assign("JAVASCRIPT",get_set_focus_js());
125         $this->ss->assign("SugarpdfSettings", $SugarpdfSettings);
126         $this->ss->assign("pdf_enable_ezpdf", PDF_ENABLE_EZPDF);
127         if(PDF_ENABLE_EZPDF == "0" && PDF_CLASS == "EZPDF"){
128             $error = "ERR_EZPDF_DISABLE";
129             $this->ss->assign("selected_pdf_class", "TCPDF");
130         }else{
131             $this->ss->assign("selected_pdf_class", PDF_CLASS);
132         }
133         $this->ss->assign("pdf_class", $pdf_class);
134         
135         if(!empty($error)){
136             $this->ss->assign("error", $mod_strings[$error]);
137         }
138         if (!function_exists('imagecreatefrompng')) {
139             $this->ss->assign("GD_WARNING", 1);
140         }
141         else
142             $this->ss->assign("GD_WARNING", 0);
143         
144         $this->ss->display('modules/Configurator/tpls/SugarpdfSettings.tpl');
145         
146         require_once("include/javascript/javascript.php");
147         $javascript = new javascript();
148         $javascript->setFormName("ConfigureSugarpdfSettings");
149         foreach($SugarpdfSettings as $k=>$v){
150             if(isset($v["required"]) && $v["required"] == true)
151                 $javascript->addFieldGeneric($k, "varchar", $v['label'], TRUE, "");
152         }
153         
154         echo $javascript->getScript();
155     }
156     
157     private function checkUploadImage()
158     {
159         $error="";
160         $files = array('sugarpdf_pdf_header_logo'=>$_FILES['new_header_logo'], 'sugarpdf_pdf_small_header_logo'=>$_FILES['new_small_header_logo']);
161         foreach($files as $k=>$v){
162             if(empty($error) && isset($v) && !empty($v['name'])){
163                 $file_name = K_PATH_CUSTOM_IMAGES .'pdf_logo_'. basename($v['name']);
164                 if(file_exists($file_name))
165                     rmdir_recursive($file_name);
166                 if (!empty($v['error']))
167                     $error='ERR_ALERT_FILE_UPLOAD';
168                 if(!mkdir_recursive(K_PATH_CUSTOM_IMAGES))
169                    $error='ERR_ALERT_FILE_UPLOAD';
170                 if(empty($error)){
171                     if (!move_uploaded_file($v['tmp_name'], $file_name))
172                         die("Possible file upload attack!\n");
173                     if(file_exists($file_name) && is_file($file_name)){
174                         $img_size = getimagesize($file_name);
175                         $filetype = $img_size['mime'];
176                         if($filetype != 'image/jpeg' && !empty($_REQUEST['sugarpdf_pdf_class']) && $_REQUEST['sugarpdf_pdf_class'] == "EZPDF"){
177                             $error='LBL_ALERT_TYPE_IMAGE_EZPDF';
178                         }
179                         else if($filetype != 'image/jpeg' && $filetype != 'image/png'){
180                             $error='LBL_ALERT_TYPE_IMAGE';
181                         }else{
182                             $test=$img_size[0]/$img_size[1];
183                             if (($test>10 || $test<1)){
184                                 //$error='LBL_ALERT_SIZE_RATIO_QUOTES';
185                             }
186                         }
187                         if(!empty($error)){
188                             rmdir_recursive($file_name);
189                         }else{
190                             $_POST[$k]='pdf_logo_'. basename($v['name']);
191                         }
192                     }else{
193                         $error='ERR_ALERT_FILE_UPLOAD';
194                     }
195                 }
196             }
197         }
198         return $error;
199     }
200 }