]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/Administration.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Administration / Administration.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 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
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                 return $this;
88             }
89
90                 $query = "SELECT category, name, value FROM {$this->table_name}";
91
92                 $result = $this->db->query($query, true, "Unable to retrieve system settings");
93
94                 if(empty($result)) {
95                         return NULL;
96                 }
97
98                 while($row = $this->db->fetchByAssoc($result, -1, true)) {
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']);
101                         else
102                             $this->settings[$row['category']."_".$row['name']] = $row['value'];
103                 }
104
105                 // outbound email settings
106                 $oe = new OutboundEmail();
107                 $oe->getSystemMailerSettings();
108
109                 foreach($oe->field_defs as $def) {
110                         if(strpos($def, "mail_") !== false)
111                                 $this->settings[$def] = $oe->$def;
112                 }
113
114                 // At this point, we have built a new array that should be cached.
115         sugar_cache_put('admin_settings_cache',$this->settings);
116                 return $this;
117         }
118
119         function saveConfig() {         
120                 
121                 
122                 // outbound email settings
123                 $oe = new OutboundEmail();
124
125                 foreach($_POST as $key => $val) {
126                         $prefix = $this->get_config_prefix($key);
127                         if(in_array($prefix[0], $this->config_categories)) {
128                             if(is_array($val)){
129                                 $val=implode(",",$val);
130                             }
131                                 $this->saveSetting($prefix[0], $prefix[1], $val);
132                         }
133                         if(strpos($key, "mail_") !== false) {
134                                 if(in_array($key, $oe->field_defs)) {
135                                         $oe->$key = $val;
136                                 }
137                         }
138                 }
139
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)) {
143                         $oe->saveSystem();
144                 }
145                 
146                 $this->retrieveSettings(false, true);           
147         }
148
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, -1, true );
152         $row_count = $row['the_count'];
153         
154         if($category."_".$key == 'ldap_admin_password' || $category."_".$key == 'proxy_password')
155             $value = $this->encrpyt_before_save($value);
156
157         if( $row_count == 0){
158             $result = $this->db->query("INSERT INTO config (value, category, name) VALUES ('$value','$category', '$key')");
159         }
160         else{
161             $result = $this->db->query("UPDATE config SET value = '{$value}' WHERE category = '{$category}' AND name = '{$key}'");
162         }
163         sugar_cache_clear('admin_settings_cache');
164         return $this->db->getAffectedRowCount();
165     }
166
167         function get_config_prefix($str) {
168                 return Array(substr($str, 0, strpos($str, "_")), substr($str, strpos($str, "_")+1));
169         }
170 }
171 ?>