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