setupCustomFields('Administration'); } function retrieveSettings($category = FALSE, $clean=false) { // declare a cache for all settings $settings_cache = sugar_cache_retrieve('admin_settings_cache'); if($clean) { $settings_cache = array(); } // Check for a cache hit if(!empty($settings_cache)) { $this->settings = $settings_cache; return $this; } $query = "SELECT category, name, value FROM {$this->table_name}"; $result = $this->db->query($query, true, "Unable to retrieve system settings"); if(empty($result)) { return NULL; } while($row = $this->db->fetchByAssoc($result)) { if($row['category']."_".$row['name'] == 'ldap_admin_password' || $row['category']."_".$row['name'] == 'proxy_password') $this->settings[$row['category']."_".$row['name']] = $this->decrypt_after_retrieve($row['value']); else $this->settings[$row['category']."_".$row['name']] = $row['value']; } // outbound email settings $oe = new OutboundEmail(); $oe->getSystemMailerSettings(); foreach($oe->field_defs as $def) { if(strpos($def, "mail_") !== false) $this->settings[$def] = $oe->$def; } // At this point, we have built a new array that should be cached. sugar_cache_put('admin_settings_cache',$this->settings); return $this; } function saveConfig() { // outbound email settings $oe = new OutboundEmail(); foreach($_POST as $key => $val) { $prefix = $this->get_config_prefix($key); if(in_array($prefix[0], $this->config_categories)) { if(is_array($val)){ $val=implode(",",$val); } $this->saveSetting($prefix[0], $prefix[1], $val); } if(strpos($key, "mail_") !== false) { if(in_array($key, $oe->field_defs)) { $oe->$key = $val; } } } //saving outbound email from here is probably redundant, adding a check to make sure //smtpserver name is set. if (!empty($oe->mail_smtpserver)) { $oe->saveSystem(); } $this->retrieveSettings(false, true); } function saveSetting($category, $key, $value) { $result = $this->db->query("SELECT count(*) AS the_count FROM config WHERE category = '{$category}' AND name = '{$key}'"); $row = $this->db->fetchByAssoc($result); $row_count = $row['the_count']; if($category."_".$key == 'ldap_admin_password' || $category."_".$key == 'proxy_password') $value = $this->encrpyt_before_save($value); if( $row_count == 0){ $result = $this->db->query("INSERT INTO config (value, category, name) VALUES ('$value','$category', '$key')"); } else{ $result = $this->db->query("UPDATE config SET value = '{$value}' WHERE category = '{$category}' AND name = '{$key}'"); } sugar_cache_clear('admin_settings_cache'); return $this->db->getAffectedRowCount($result); } function get_config_prefix($str) { return Array(substr($str, 0, strpos($str, "_")), substr($str, strpos($str, "_")+1)); } } ?>