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