3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
39 class CRM_Core_BAO_Preferences
{
44 static function fixAndStoreDirAndURL(&$params) {
46 SELECT v.name as valueName, g.name as optionName
47 FROM civicrm_option_value v,
48 civicrm_option_group g
49 WHERE ( g.name = 'directory_preferences'
50 OR g.name = 'url_preferences' )
51 AND v.option_group_id = g.id
57 $dao = CRM_Core_DAO
::executeQuery($sql);
58 while ($dao->fetch()) {
59 if (!isset($params[$dao->valueName
])) {
62 if ($dao->optionName
== 'directory_preferences') {
63 $dirParams[$dao->valueName
] = CRM_Utils_Array
::value($dao->valueName
, $params, '');
66 $urlParams[$dao->valueName
] = CRM_Utils_Array
::value($dao->valueName
, $params, '');
68 unset($params[$dao->valueName
]);
71 if (!empty($dirParams)) {
72 CRM_Core_BAO_Preferences
::storeDirectoryOrURLPreferences($dirParams, 'directory');
75 if (!empty($urlParams)) {
76 CRM_Core_BAO_Preferences
::storeDirectoryOrURLPreferences($urlParams, 'url');
84 static function storeDirectoryOrURLPreferences(&$params, $type = 'directory') {
85 $optionName = ($type == 'directory') ?
'directory_preferences' : 'url_preferences';
88 UPDATE civicrm_option_value v,
89 civicrm_option_group g
93 AND v.option_group_id = g.id
97 foreach ($params as $name => $value) {
98 // always try to store relative directory or url from CMS root
99 if ($type == 'directory') {
100 $value = CRM_Utils_File
::relativeDirectory($value);
103 $value = CRM_Utils_System
::relativeURL($value);
105 $sqlParams = array(1 => array($value, 'String'),
106 2 => array($optionName, 'String'),
107 3 => array($name, 'String'),
109 CRM_Core_DAO
::executeQuery($sql, $sqlParams);
115 * @param bool $setInConfig
117 static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) {
119 $config = CRM_Core_Config
::singleton();
123 SELECT v.name as valueName, v.value, g.name as optionName
124 FROM civicrm_option_value v,
125 civicrm_option_group g
126 WHERE ( g.name = 'directory_preferences'
127 OR g.name = 'url_preferences' )
128 AND v.option_group_id = g.id
133 $dao = CRM_Core_DAO
::executeQuery($sql);
134 while ($dao->fetch()) {
138 if ($dao->optionName
== 'directory_preferences') {
139 $value = CRM_Utils_File
::absoluteDirectory($dao->value
);
142 // CRM-7622: we need to remove the language part
143 $value = CRM_Utils_System
::absoluteURL($dao->value
, TRUE);
145 $params[$dao->valueName
] = $value;
147 $config->{$dao->valueName
} = $value;