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, |
6a488035 | 46 | 'versionCheck' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
466913fc | 47 | 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
6a488035 TO |
48 | 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
49 | 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
d5f1ee75 | 50 | 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
c1d3e6ee | 51 | 'checksumTimeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
6a488035 TO |
52 | ); |
53 | ||
66dc6009 | 54 | public $_uploadMaxSize; |
55 | ||
56 | /** | |
57 | * Basic setup | |
58 | */ | |
59 | ||
60 | public function preProcess() { | |
61 | $config = CRM_Core_Config::singleton(); | |
62 | $this->_uploadMaxSize = (int) ini_get('upload_max_filesize'); | |
63 | // check for post max size | |
64 | CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE); | |
65 | } | |
66 | ||
6a488035 | 67 | /** |
c490a46a | 68 | * Build the form object |
6a488035 | 69 | * |
355ba699 | 70 | * @return void |
6a488035 TO |
71 | * @access public |
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 | |
80 | $domain = new CRM_Core_DAO_Domain; | |
81 | $domain->find(TRUE); | |
94c11eeb | 82 | $attribs = $domain->locales || !$validTriggerPermission ? |
27b9f49a | 83 | array('disabled' => 'disabled') : array(); |
6a488035 TO |
84 | |
85 | $this->assign('validTriggerPermission', $validTriggerPermission); | |
86 | $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs); | |
87 | ||
94c11eeb DL |
88 | $this->addElement( |
89 | 'text', | |
90 | 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'), | |
6a488035 TO |
91 | array('size' => 64, 'maxlength' => 256) |
92 | ); | |
93 | ||
94c11eeb DL |
94 | $this->addElement( |
95 | 'text', 'recaptchaPublicKey', ts('Public Key'), | |
6a488035 TO |
96 | array('size' => 64, 'maxlength' => 64) |
97 | ); | |
94c11eeb DL |
98 | $this->addElement( |
99 | 'text', 'recaptchaPrivateKey', ts('Private Key'), | |
6a488035 TO |
100 | array('size' => 64, 'maxlength' => 64) |
101 | ); | |
102 | ||
94c11eeb DL |
103 | $this->addElement( |
104 | 'text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), | |
6a488035 TO |
105 | array('size' => 3, 'maxlength' => 5) |
106 | ); | |
c1d3e6ee | 107 | |
94c11eeb DL |
108 | $this->addElement( |
109 | 'text', 'recaptchaOptions', ts('Recaptcha Options'), | |
6a488035 TO |
110 | array('size' => 64, 'maxlength' => 64) |
111 | ); | |
112 | ||
31195a09 DL |
113 | $this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this); |
114 | ||
6a488035 | 115 | parent::buildQuickForm(); |
c1d3e6ee | 116 | $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger'); |
6a488035 TO |
117 | } |
118 | ||
31195a09 | 119 | /** |
100fef9d | 120 | * Global form rule |
31195a09 DL |
121 | * |
122 | * @param array $fields the input form values | |
123 | * @param array $files the uploaded files if any | |
124 | * @param array $options additional user data | |
125 | * | |
126 | * @return true if no errors, else array of errors | |
127 | * @access public | |
128 | * @static | |
129 | */ | |
130 | static function formRule($fields, $files, $options) { | |
131 | $errors = array(); | |
132 | ||
66dc6009 | 133 | // validate max file size |
134 | if ($fields['maxFileSize'] > $options->_uploadMaxSize) { | |
135 | $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini."); | |
136 | } | |
137 | ||
31195a09 DL |
138 | if (!empty($fields['wkhtmltopdfPath'])) { |
139 | // check and ensure that thi leads to the wkhtmltopdf binary | |
140 | // and it is a valid executable binary | |
1834031f | 141 | // Only check the first space separated piece to allow for a value |
142 | // such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292) | |
143 | $pieces = explode(' ', $fields['wkhtmltopdfPath']); | |
144 | $path = $pieces[0]; | |
31195a09 | 145 | if ( |
1834031f | 146 | !file_exists($path) || |
147 | !is_executable($path) | |
31195a09 DL |
148 | ) { |
149 | $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid'); | |
150 | } | |
151 | } | |
152 | return $errors; | |
153 | } | |
154 | ||
6a488035 TO |
155 | |
156 | public function postProcess() { | |
157 | // store the submitted values in an array | |
158 | $config = CRM_Core_Config::singleton(); | |
159 | $params = $this->controller->exportValues($this->_name); | |
160 | ||
66dc6009 | 161 | // update upload max size in DB |
162 | $params['maxImportFileSize'] = CRM_Core_Config_Defaults::formatUnitSize(ini_get('upload_max_filesize')); | |
163 | CRM_Core_BAO_ConfigSetting::create($params); | |
164 | ||
6a488035 TO |
165 | // get current logging status |
166 | $values = $this->exportValues(); | |
167 | ||
168 | parent::postProcess(); | |
169 | ||
170 | if ($config->logging != $values['logging']) { | |
171 | $logging = new CRM_Logging_Schema; | |
172 | if ($values['logging']) { | |
173 | $logging->enableLogging(); | |
174 | } | |
175 | else { | |
176 | $logging->disableLogging(); | |
177 | } | |
178 | } | |
179 | } | |
180 | } | |
181 |