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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
45 require_once('data/SugarBean.php');
46 require_once('include/OutboundEmail/OutboundEmail.php');
48 class Administration extends SugarBean {
50 var $table_name = "config";
51 var $object_name = "Administration";
52 var $new_schema = true;
53 var $module_dir = 'Administration';
54 var $config_categories = array(
55 // 'mail', // cn: moved to include/OutboundEmail
56 'disclosure', // appended to all outbound emails
67 var $disable_custom_fields = true;
68 var $checkbox_fields = Array("notify_send_by_default", "mail_smtpauth_req", "notify_on", 'portal_on', 'skypeout_on', 'system_mailmerge_on', 'proxy_auth', 'proxy_on', 'system_ldap_enabled','captcha_on');
70 function Administration() {
73 $this->setupCustomFields('Administration');
76 function retrieveSettings($category = FALSE, $clean=false) {
77 // declare a cache for all settings
78 $settings_cache = sugar_cache_retrieve('admin_settings_cache');
81 $settings_cache = array();
84 // Check for a cache hit
85 if(!empty($settings_cache)) {
86 $this->settings = $settings_cache;
90 $query = "SELECT category, name, value FROM {$this->table_name}";
92 $result = $this->db->query($query, true, "Unable to retrieve system settings");
98 while($row = $this->db->fetchByAssoc($result)) {
99 if($row['category']."_".$row['name'] == 'ldap_admin_password' || $row['category']."_".$row['name'] == 'proxy_password')
100 $this->settings[$row['category']."_".$row['name']] = $this->decrypt_after_retrieve($row['value']);
102 $this->settings[$row['category']."_".$row['name']] = $row['value'];
105 // outbound email settings
106 $oe = new OutboundEmail();
107 $oe->getSystemMailerSettings();
109 foreach($oe->field_defs as $def) {
110 if(strpos($def, "mail_") !== false)
111 $this->settings[$def] = $oe->$def;
114 // At this point, we have built a new array that should be cached.
115 sugar_cache_put('admin_settings_cache',$this->settings);
119 function saveConfig() {
122 // outbound email settings
123 $oe = new OutboundEmail();
125 foreach($_POST as $key => $val) {
126 $prefix = $this->get_config_prefix($key);
127 if(in_array($prefix[0], $this->config_categories)) {
129 $val=implode(",",$val);
131 $this->saveSetting($prefix[0], $prefix[1], $val);
133 if(strpos($key, "mail_") !== false) {
134 if(in_array($key, $oe->field_defs)) {
140 //saving outbound email from here is probably redundant, adding a check to make sure
141 //smtpserver name is set.
142 if (!empty($oe->mail_smtpserver)) {
146 $this->retrieveSettings(false, true);
149 function saveSetting($category, $key, $value) {
150 $result = $this->db->query("SELECT count(*) AS the_count FROM config WHERE category = '{$category}' AND name = '{$key}'");
151 $row = $this->db->fetchByAssoc($result);
152 $row_count = $row['the_count'];
154 if($category."_".$key == 'ldap_admin_password' || $category."_".$key == 'proxy_password')
155 $value = $this->encrpyt_before_save($value);
157 if( $row_count == 0){
158 $result = $this->db->query("INSERT INTO config (value, category, name) VALUES ('$value','$category', '$key')");
161 $result = $this->db->query("UPDATE config SET value = '{$value}' WHERE category = '{$category}' AND name = '{$key}'");
163 sugar_cache_clear('admin_settings_cache');
164 return $this->db->getAffectedRowCount($result);
167 function get_config_prefix($str) {
168 return Array(substr($str, 0, strpos($str, "_")), substr($str, strpos($str, "_")+1));