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-2013 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($cachedfile = sugar_cached('modules/Quotes/DetailView.tpl'))) {
94 header('Location: index.php?module=Administration&action=index');
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]}'");
110 header('Location: index.php?module=Configurator&action=SugarpdfSettings');
113 echo getClassicModuleTitle(
116 "<a href='index.php?module=Administration&action=index'>".translate('LBL_MODULE_NAME','Administration')."</a>",
117 $mod_strings['LBL_PDFMODULE_NAME'],
122 $pdf_class = array("TCPDF"=>"TCPDF","EZPDF"=>"EZPDF");
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");
132 $this->ss->assign("selected_pdf_class", PDF_CLASS);
134 $this->ss->assign("pdf_class", $pdf_class);
137 $this->ss->assign("error", $mod_strings[$error]);
139 if (!function_exists('imagecreatefrompng')) {
140 $this->ss->assign("GD_WARNING", 1);
143 $this->ss->assign("GD_WARNING", 0);
145 $this->ss->display('modules/Configurator/tpls/SugarpdfSettings.tpl');
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, "");
155 echo $javascript->getScript();
158 private function checkUploadImage()
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';
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';
180 if(!verify_uploaded_image($file_name)) {
181 $error='LBL_ALERT_TYPE_IMAGE';
185 rmdir_recursive($file_name);
187 $_POST[$k]='pdf_logo_'. basename($v['name']);
190 $error='ERR_ALERT_FILE_UPLOAD';