3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
39 class CRM_Core_BAO_Preferences
{
41 static function fixAndStoreDirAndURL(&$params) {
43 SELECT v.name as valueName, g.name as optionName
44 FROM civicrm_option_value v,
45 civicrm_option_group g
46 WHERE ( g.name = 'directory_preferences'
47 OR g.name = 'url_preferences' )
48 AND v.option_group_id = g.id
54 $dao = CRM_Core_DAO
::executeQuery($sql);
55 while ($dao->fetch()) {
56 if (!isset($params[$dao->valueName
])) {
59 if ($dao->optionName
== 'directory_preferences') {
60 $dirParams[$dao->valueName
] = CRM_Utils_Array
::value($dao->valueName
, $params, '');
63 $urlParams[$dao->valueName
] = CRM_Utils_Array
::value($dao->valueName
, $params, '');
65 unset($params[$dao->valueName
]);
68 if (!empty($dirParams)) {
69 CRM_Core_BAO_Preferences
::storeDirectoryOrURLPreferences($dirParams, 'directory');
72 if (!empty($urlParams)) {
73 CRM_Core_BAO_Preferences
::storeDirectoryOrURLPreferences($urlParams, 'url');
77 static function storeDirectoryOrURLPreferences(&$params, $type = 'directory') {
78 $optionName = ($type == 'directory') ?
'directory_preferences' : 'url_preferences';
81 UPDATE civicrm_option_value v,
82 civicrm_option_group g
86 AND v.option_group_id = g.id
90 foreach ($params as $name => $value) {
91 // always try to store relative directory or url from CMS root
92 if ($type == 'directory') {
93 $value = CRM_Utils_File
::relativeDirectory($value);
96 $value = CRM_Utils_System
::relativeURL($value);
98 $sqlParams = array(1 => array($value, 'String'),
99 2 => array($optionName, 'String'),
100 3 => array($name, 'String'),
102 CRM_Core_DAO
::executeQuery($sql, $sqlParams);
106 static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) {
108 $config = CRM_Core_Config
::singleton();
112 SELECT v.name as valueName, v.value, g.name as optionName
113 FROM civicrm_option_value v,
114 civicrm_option_group g
115 WHERE ( g.name = 'directory_preferences'
116 OR g.name = 'url_preferences' )
117 AND v.option_group_id = g.id
122 $dao = CRM_Core_DAO
::executeQuery($sql);
123 while ($dao->fetch()) {
127 if ($dao->optionName
== 'directory_preferences') {
128 $value = CRM_Utils_File
::absoluteDirectory($dao->value
);
131 // CRM-7622: we need to remove the language part
132 $value = CRM_Utils_System
::absoluteURL($dao->value
, TRUE);
134 $params[$dao->valueName
] = $value;
136 $config->{$dao->valueName
} = $value;