Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
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 | /** | |
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 | ||
6a488035 | 69 | /** |
c490a46a | 70 | * Build the form object |
6a488035 | 71 | * |
355ba699 | 72 | * @return void |
6a488035 TO |
73 | * @access public |
74 | */ | |
75 | public function buildQuickForm() { | |
d718034a | 76 | CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)')); |
6a488035 | 77 | |
6a488035 TO |
78 | // also check if we can enable triggers |
79 | $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(FALSE); | |
80 | ||
81 | // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted | |
82 | $domain = new CRM_Core_DAO_Domain; | |
83 | $domain->find(TRUE); | |
94c11eeb | 84 | $attribs = $domain->locales || !$validTriggerPermission ? |
27b9f49a | 85 | array('disabled' => 'disabled') : array(); |
6a488035 TO |
86 | |
87 | $this->assign('validTriggerPermission', $validTriggerPermission); | |
88 | $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs); | |
89 | ||
94c11eeb DL |
90 | $this->addElement( |
91 | 'text', | |
92 | 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'), | |
6a488035 TO |
93 | array('size' => 64, 'maxlength' => 256) |
94 | ); | |
95 | ||
94c11eeb DL |
96 | $this->addElement( |
97 | 'text', 'recaptchaPublicKey', ts('Public Key'), | |
6a488035 TO |
98 | array('size' => 64, 'maxlength' => 64) |
99 | ); | |
94c11eeb DL |
100 | $this->addElement( |
101 | 'text', 'recaptchaPrivateKey', ts('Private Key'), | |
6a488035 TO |
102 | array('size' => 64, 'maxlength' => 64) |
103 | ); | |
104 | ||
94c11eeb DL |
105 | $this->addElement( |
106 | 'text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), | |
6a488035 TO |
107 | array('size' => 3, 'maxlength' => 5) |
108 | ); | |
c1d3e6ee | 109 | |
94c11eeb DL |
110 | $this->addElement( |
111 | 'text', 'recaptchaOptions', ts('Recaptcha Options'), | |
6a488035 TO |
112 | array('size' => 64, 'maxlength' => 64) |
113 | ); | |
114 | ||
31195a09 DL |
115 | $this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this); |
116 | ||
6a488035 | 117 | parent::buildQuickForm(); |
c1d3e6ee | 118 | $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger'); |
6a488035 TO |
119 | } |
120 | ||
31195a09 | 121 | /** |
100fef9d | 122 | * Global form rule |
31195a09 DL |
123 | * |
124 | * @param array $fields the input form values | |
125 | * @param array $files the uploaded files if any | |
126 | * @param array $options additional user data | |
127 | * | |
128 | * @return true if no errors, else array of errors | |
129 | * @access public | |
130 | * @static | |
131 | */ | |
132 | static function formRule($fields, $files, $options) { | |
133 | $errors = array(); | |
134 | ||
66dc6009 | 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 | ||
31195a09 DL |
140 | if (!empty($fields['wkhtmltopdfPath'])) { |
141 | // check and ensure that thi leads to the wkhtmltopdf binary | |
142 | // and it is a valid executable binary | |
1834031f | 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]; | |
31195a09 | 147 | if ( |
1834031f | 148 | !file_exists($path) || |
149 | !is_executable($path) | |
31195a09 DL |
150 | ) { |
151 | $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid'); | |
152 | } | |
153 | } | |
154 | return $errors; | |
155 | } | |
156 | ||
6a488035 TO |
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 | ||
0715cdf2 CW |
163 | // update upload max size in $config |
164 | // Fixme: why are we storing this php setting in $config? | |
165 | $hiddenSettings = array( | |
166 | 'maxImportFileSize' => CRM_Core_Config_Defaults::formatUnitSize(ini_get('upload_max_filesize')) | |
167 | ); | |
168 | CRM_Core_BAO_ConfigSetting::create($hiddenSettings); | |
66dc6009 | 169 | |
6a488035 TO |
170 | // get current logging status |
171 | $values = $this->exportValues(); | |
172 | ||
173 | parent::postProcess(); | |
174 | ||
175 | if ($config->logging != $values['logging']) { | |
176 | $logging = new CRM_Logging_Schema; | |
177 | if ($values['logging']) { | |
178 | $logging->enableLogging(); | |
179 | } | |
180 | else { | |
181 | $logging->disableLogging(); | |
182 | } | |
183 | } | |
184 | } | |
185 | } | |
186 |