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.
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 class ConfiguratorViewSugarpdfsettings extends SugarView
42 * @see SugarView::preDisplay()
44 public function preDisplay()
46 if(!is_admin($GLOBALS['current_user']))
47 sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
51 * @see SugarView::_getModuleTitleParams()
53 protected function _getModuleTitleParams($browserTitle = false)
58 "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
59 $mod_strings['LBL_PDFMODULE_NAME']
64 * @see SugarView::display()
66 public function display()
68 global $mod_strings, $app_strings, $app_list_strings;
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');
75 if(!empty($_POST['save'])){
77 $error=$this->checkUploadImage();
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]);
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');
93 header('Location: index.php?module=Administration&action=index');
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]}'");
109 header('Location: index.php?module=Configurator&action=SugarpdfSettings');
112 echo getClassicModuleTitle(
115 "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
116 $mod_strings['LBL_PDFMODULE_NAME'],
121 $pdf_class = array("TCPDF"=>"TCPDF","EZPDF"=>"EZPDF");
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");
131 $this->ss->assign("selected_pdf_class", PDF_CLASS);
133 $this->ss->assign("pdf_class", $pdf_class);
136 $this->ss->assign("error", $mod_strings[$error]);
138 if (!function_exists('imagecreatefrompng')) {
139 $this->ss->assign("GD_WARNING", 1);
142 $this->ss->assign("GD_WARNING", 0);
144 $this->ss->display('modules/Configurator/tpls/SugarpdfSettings.tpl');
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, "");
154 echo $javascript->getScript();
157 private function checkUploadImage()
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';
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 if(!empty($_REQUEST['sugarpdf_pdf_class']) && $_REQUEST['sugarpdf_pdf_class'] == "EZPDF") {
175 if(!verify_uploaded_image($file_name, true)) {
176 $error='LBL_ALERT_TYPE_IMAGE_EZPDF';
179 if(!verify_uploaded_image($file_name)) {
180 $error='LBL_ALERT_TYPE_IMAGE';
184 rmdir_recursive($file_name);
186 $_POST[$k]='pdf_logo_'. basename($v['name']);
189 $error='ERR_ALERT_FILE_UPLOAD';