]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/Administration.php
Release 6.5.5
[Github/sugarcrm.git] / modules / Administration / Administration.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-2012 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
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');
47
48 class Administration extends SugarBean {
49     var $settings;
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
57         'notify',
58         'system',
59         'portal',
60         'proxy',
61         'massemailer',
62         'ldap',
63         'captcha',
64         'sugarpdf',
65
66     );
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');
69
70     function Administration() {
71         parent::SugarBean();
72
73         $this->setupCustomFields('Administration');
74     }
75
76     function retrieveSettings($category = FALSE, $clean=false) {
77         // declare a cache for all settings
78         $settings_cache = sugar_cache_retrieve('admin_settings_cache');
79
80         if($clean) {
81             $settings_cache = array();
82         }
83
84         // Check for a cache hit
85         if(!empty($settings_cache)) {
86             $this->settings = $settings_cache;
87             if (!empty($this->settings[$category]))
88             {
89                 return $this;
90             }
91         }
92
93         if ( ! empty($category) ) {
94             $query = "SELECT category, name, value FROM {$this->table_name} WHERE category = '{$category}'";
95         } else {
96             $query = "SELECT category, name, value FROM {$this->table_name}";
97         }
98
99         $result = $this->db->query($query, true, "Unable to retrieve system settings");
100
101         if(empty($result)) {
102             return NULL;
103         }
104
105         while($row = $this->db->fetchByAssoc($result)) {
106             if($row['category']."_".$row['name'] == 'ldap_admin_password' || $row['category']."_".$row['name'] == 'proxy_password')
107                 $this->settings[$row['category']."_".$row['name']] = $this->decrypt_after_retrieve($row['value']);
108             else
109                 $this->settings[$row['category']."_".$row['name']] = $row['value'];
110         }
111         $this->settings[$category] = true;
112
113         // outbound email settings
114         $oe = new OutboundEmail();
115         $oe->getSystemMailerSettings();
116
117         foreach($oe->field_defs as $def) {
118             if(strpos($def, "mail_") !== false)
119                 $this->settings[$def] = $oe->$def;
120         }
121
122         // At this point, we have built a new array that should be cached.
123         sugar_cache_put('admin_settings_cache',$this->settings);
124         return $this;
125     }
126
127     function saveConfig() {
128
129
130         // outbound email settings
131         $oe = new OutboundEmail();
132
133         foreach($_POST as $key => $val) {
134             $prefix = $this->get_config_prefix($key);
135             if(in_array($prefix[0], $this->config_categories)) {
136                 if(is_array($val)){
137                     $val=implode(",",$val);
138                 }
139                 $this->saveSetting($prefix[0], $prefix[1], $val);
140             }
141             if(strpos($key, "mail_") !== false) {
142                 if(in_array($key, $oe->field_defs)) {
143                     $oe->$key = $val;
144                 }
145             }
146         }
147
148         //saving outbound email from here is probably redundant, adding a check to make sure
149         //smtpserver name is set.
150         if (!empty($oe->mail_smtpserver)) {
151             $oe->saveSystem();
152         }
153
154         $this->retrieveSettings(false, true);
155     }
156
157     function saveSetting($category, $key, $value) {
158         $result = $this->db->query("SELECT count(*) AS the_count FROM config WHERE category = '{$category}' AND name = '{$key}'");
159         $row = $this->db->fetchByAssoc($result);
160         $row_count = $row['the_count'];
161
162         if($category."_".$key == 'ldap_admin_password' || $category."_".$key == 'proxy_password')
163             $value = $this->encrpyt_before_save($value);
164
165         if( $row_count == 0){
166             $result = $this->db->query("INSERT INTO config (value, category, name) VALUES ('$value','$category', '$key')");
167         }
168         else{
169             $result = $this->db->query("UPDATE config SET value = '{$value}' WHERE category = '{$category}' AND name = '{$key}'");
170         }
171         sugar_cache_clear('admin_settings_cache');
172         return $this->db->getAffectedRowCount($result);
173     }
174
175     function get_config_prefix($str) {
176         return Array(substr($str, 0, strpos($str, "_")), substr($str, strpos($str, "_")+1));
177     }
178 }
179 ?>