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