]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/controller.php
Release 6.5.15
[Github/sugarcrm.git] / modules / Configurator / controller.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-2013 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 require_once('include/MVC/Controller/SugarController.php');
40 class ConfiguratorController extends SugarController
41 {
42     /**
43      * Go to the font manager view
44      */
45     function action_FontManager(){
46         global $current_user;
47         if(!is_admin($current_user)){
48             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
49         }
50         $this->view = 'fontmanager';
51     }
52
53     /**
54      * Delete a font and go back to the font manager
55      */
56     function action_deleteFont(){
57         global $current_user;
58         if(!is_admin($current_user)){
59             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
60         }
61         $urlSTR = 'index.php?module=Configurator&action=FontManager';
62         if(!empty($_REQUEST['filename'])){
63             require_once('include/Sugarpdf/FontManager.php');
64             $fontManager = new FontManager();
65             $fontManager->filename = $_REQUEST['filename'];
66             if(!$fontManager->deleteFont()){
67                 $urlSTR .='&error='.urlencode(implode("<br>",$fontManager->errors));
68             }
69         }
70         header("Location: $urlSTR");
71     }
72
73     function action_listview(){
74         global $current_user;
75         if(!is_admin($current_user)){
76             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
77         }
78         $this->view = 'edit';
79     }
80     /**
81      * Show the addFont view
82      */
83     function action_addFontView(){
84         global $current_user;
85         if(!is_admin($current_user)){
86             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
87         }
88         $this->view = 'addFontView';
89     }
90     /**
91      * Add a new font and show the addFontResult view
92      */
93     function action_addFont(){
94         global $current_user, $mod_strings;
95         if(!is_admin($current_user)){
96             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
97         }
98         if(empty($_FILES['pdf_metric_file']['name'])){
99             $this->errors[]=translate("ERR_MISSING_REQUIRED_FIELDS")." ".translate("LBL_PDF_METRIC_FILE", "Configurator");
100             $this->view = 'addFontView';
101             return;
102         }
103         if(empty($_FILES['pdf_font_file']['name'])){
104             $this->errors[]=translate("ERR_MISSING_REQUIRED_FIELDS")." ".translate("LBL_PDF_FONT_FILE", "Configurator");
105             $this->view = 'addFontView';
106             return;
107         }
108         $path_info = pathinfo($_FILES['pdf_font_file']['name']);
109         $path_info_metric = pathinfo($_FILES['pdf_metric_file']['name']);
110         if(($path_info_metric['extension']!="afm" && $path_info_metric['extension']!="ufm") ||
111         ($path_info['extension']!="ttf" && $path_info['extension']!="otf" && $path_info['extension']!="pfb")){
112             $this->errors[]=translate("JS_ALERT_PDF_WRONG_EXTENSION", "Configurator");
113             $this->view = 'addFontView';
114             return;
115         }
116
117         if($_REQUEST['pdf_embedded'] == "false"){
118             if(empty($_REQUEST['pdf_cidinfo'])){
119                 $this->errors[]=translate("ERR_MISSING_CIDINFO", "Configurator");
120                 $this->view = 'addFontView';
121                 return;
122             }
123             $_REQUEST['pdf_embedded']=false;
124         }else{
125             $_REQUEST['pdf_embedded']=true;
126             $_REQUEST['pdf_cidinfo']="";
127         }
128         if(empty($_REQUEST['pdf_patch'])){
129             $_REQUEST['pdf_patch']="return array();";
130         }else{
131             $_REQUEST['pdf_patch']="return {$_REQUEST['pdf_patch']};";
132         }
133         $this->view = 'addFontResult';
134     }
135     function action_saveadminwizard()
136     {
137         global $current_user;
138         if(!is_admin($current_user)){
139             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
140         }
141         $focus = new Administration();
142         $focus->retrieveSettings();
143         $focus->saveConfig();
144
145         $configurator = new Configurator();
146         $configurator->populateFromPost();
147         $configurator->handleOverride();
148         $configurator->parseLoggerSettings();
149         $configurator->saveConfig();
150
151         // Bug 37310 - Delete any existing currency that matches the one we've just set the default to during the admin wizard
152         $currency = new Currency;
153         $currency->retrieve($currency->retrieve_id_by_name($_REQUEST['default_currency_name']));
154         if ( !empty($currency->id)
155                 && $currency->symbol == $_REQUEST['default_currency_symbol']
156                 && $currency->iso4217 == $_REQUEST['default_currency_iso4217'] ) {
157             $currency->deleted = 1;
158             $currency->save();
159         }
160
161         SugarApplication::redirect('index.php?module=Users&action=Wizard&skipwelcome=1');
162     }
163
164     function action_saveconfig()
165     {
166         global $current_user;
167         if(!is_admin($current_user)){
168             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
169         }
170         $configurator = new Configurator();
171         if ($configurator->saveConfig() === false)
172         {
173             $this->errors = array(
174                 'company_logo' => $configurator->getError(),
175             );
176             $this->view = 'edit';
177             return;
178         }
179
180         $focus = new Administration();
181         $focus->saveConfig();
182
183         // Clear the Contacts file b/c portal flag affects rendering
184         if (file_exists($cachedfile = sugar_cached('modules/Contacts/EditView.tpl')))
185            unlink($cachedfile);
186
187         SugarApplication::redirect('index.php?module=Administration&action=index');
188     }
189
190     function action_detail()
191     {
192         global $current_user;
193         if(!is_admin($current_user)){
194             sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']); 
195         }
196         $this->view = 'edit';
197     }
198
199     /**
200      * Define correct view for action
201      */
202     function action_historyContactsEmails()
203     {
204         $this->view = 'historyContactsEmails';
205     }
206
207     /**
208      * Generates custom field_defs for selected fields
209      */
210     function action_historyContactsEmailsSave()
211     {
212         if (!empty($_POST['modules']) && is_array($_POST['modules'])) {
213             require_once('include/SubPanel/SubPanelDefinitions.php');
214
215             $modules = array();
216             foreach ($_POST['modules'] as $moduleName => $enabled) {
217                 $bean = BeanFactory::getBean($moduleName);
218
219                 if (!($bean instanceof SugarBean)) {
220                     continue;
221                 }
222                 if (empty($bean->field_defs)) {
223                     continue;
224                 }
225
226                 $subPanel = new SubPanelDefinitions($bean);
227                 if (empty($subPanel->layout_defs)) {
228                     continue;
229                 }
230                 if (empty($subPanel->layout_defs['subpanel_setup'])) {
231                     continue;
232                 }
233
234                 $isValid = false;
235                 foreach ($subPanel->layout_defs['subpanel_setup'] as $subPanelDef) {
236                     if (empty($subPanelDef['module']) || $subPanelDef['module'] != 'History') {
237                         continue;
238                     }
239                     if (empty($subPanelDef['collection_list'])) {
240                         continue;
241                     }
242                     foreach ($subPanelDef['collection_list'] as $v) {
243                         if (!empty($v['get_subpanel_data']) && $v['get_subpanel_data'] == 'function:get_emails_by_assign_or_link') {
244                             $isValid = true;
245                             break 2;
246                         }
247                     }
248                 }
249                 if (!$isValid) {
250                     continue;
251                 }
252
253                 $bean->load_relationships();
254                 foreach ($bean->get_linked_fields() as $fieldName => $fieldDef) {
255                     if ($bean->$fieldName->getRelatedModuleName() == 'Contacts') {
256                         $modules[$moduleName] = !$enabled;
257                         break;
258                     }
259                 }
260             }
261
262             $configurator = new Configurator();
263             $configurator->config['hide_history_contacts_emails'] = $modules;
264             $configurator->handleOverride();
265         }
266
267         SugarApplication::redirect('index.php?module=Administration&action=index');
268     }
269 }