Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-01-20-54-24
[civicrm-core.git] / CRM / Admin / Form / Setting / Miscellaneous.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for Miscellaneous
38 *
39 */
40 class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
41
42 protected $_settings = array(
43 'max_attachments' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
44 'contact_undelete' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
45 'versionAlert' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
46 'versionCheck' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
47 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
48 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
49 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
50 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
51 );
52
53 /**
54 * Function to build the form
55 *
56 * @return void
57 * @access public
58 */
59 public function buildQuickForm() {
60 CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)'));
61
62 // also check if we can enable triggers
63 $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(FALSE);
64
65 // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted
66 $domain = new CRM_Core_DAO_Domain;
67 $domain->find(TRUE);
68 $attribs = $domain->locales || !$validTriggerPermission ?
69 array('disabled' => 'disabled') : array();
70
71 $this->assign('validTriggerPermission', $validTriggerPermission);
72 $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs);
73
74 $this->addElement(
75 'text',
76 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'),
77 array('size' => 64, 'maxlength' => 256)
78 );
79
80 $this->addElement(
81 'text', 'recaptchaPublicKey', ts('Public Key'),
82 array('size' => 64, 'maxlength' => 64)
83 );
84 $this->addElement(
85 'text', 'recaptchaPrivateKey', ts('Private Key'),
86 array('size' => 64, 'maxlength' => 64)
87 );
88
89 $this->addElement(
90 'text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'),
91 array('size' => 3, 'maxlength' => 5)
92 );
93 $this->addElement(
94 'text', 'checksumTimeout', ts('CheckSum Lifespan'),
95 array('size' => 2, 'maxlength' => 8)
96 );
97 $this->addElement(
98 'text', 'recaptchaOptions', ts('Recaptcha Options'),
99 array('size' => 64, 'maxlength' => 64)
100 );
101
102 $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger');
103
104 $this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this);
105
106 parent::buildQuickForm();
107 }
108
109 /**
110 * global form rule
111 *
112 * @param array $fields the input form values
113 * @param array $files the uploaded files if any
114 * @param array $options additional user data
115 *
116 * @return true if no errors, else array of errors
117 * @access public
118 * @static
119 */
120 static function formRule($fields, $files, $options) {
121 $errors = array();
122
123 if (!empty($fields['wkhtmltopdfPath'])) {
124 // check and ensure that thi leads to the wkhtmltopdf binary
125 // and it is a valid executable binary
126 // Only check the first space separated piece to allow for a value
127 // such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292)
128 $pieces = explode(' ', $fields['wkhtmltopdfPath']);
129 $path = $pieces[0];
130 if (
131 !file_exists($path) ||
132 !is_executable($path)
133 ) {
134 $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid');
135 }
136 }
137 return $errors;
138 }
139
140 function setDefaultValues() {
141 parent::setDefaultValues();
142
143 $this->_defaults['checksumTimeout'] =
144 CRM_Core_BAO_Setting::getItem(
145 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
146 'checksum_timeout',
147 NULL,
148 7
149 );
150 return $this->_defaults;
151 }
152
153 public function postProcess() {
154 // store the submitted values in an array
155 $config = CRM_Core_Config::singleton();
156 $params = $this->controller->exportValues($this->_name);
157
158 // get current logging status
159 $values = $this->exportValues();
160
161 parent::postProcess();
162
163 if ($config->logging != $values['logging']) {
164 $logging = new CRM_Logging_Schema;
165 if ($values['logging']) {
166 $logging->enableLogging();
167 }
168 else {
169 $logging->disableLogging();
170 }
171 }
172 }
173 }
174