Merge pull request #15321 from yashodha/dev_1065
[civicrm-core.git] / CRM / Admin / Form / Setting / Miscellaneous.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33
34 /**
35 * This class generates form components for Miscellaneous.
36 */
37 class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
38
39 protected $_settings = [
40 'max_attachments' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
41 'max_attachments_backend' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
42 'contact_undelete' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
43 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
44 'logging' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
45 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
46 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
47 'recordGeneratedLetters' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
48 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
49 'checksum_timeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
50 'recaptchaOptions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
51 'recaptchaPublicKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
52 'recaptchaPrivateKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
53 'forceRecaptcha' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
54 'wkhtmltopdfPath' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
55 'recentItemsMaxCount' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
56 'recentItemsProviders' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
57 'dedupe_default_limit' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
58 'remote_profile_submissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
59 'allow_alert_autodismissal' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
60 'prevNextBackend' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
61 ];
62
63 public $_uploadMaxSize;
64
65 /**
66 * Basic setup.
67 */
68 public function preProcess() {
69 $this->_uploadMaxSize = (int) ini_get('upload_max_filesize');
70 // check for post max size
71 CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
72 // This is a temp hack for the fact we really don't need to hard-code each setting in the tpl but
73 // we haven't worked through NOT doing that. These settings have been un-hardcoded.
74 $this->assign('pure_config_settings', [
75 'empoweredBy',
76 'max_attachments',
77 'max_attachments_backend',
78 'maxFileSize',
79 'secondDegRelPermissions',
80 'recentItemsMaxCount',
81 'recentItemsProviders',
82 'dedupe_default_limit',
83 'prevNextBackend',
84 ]);
85 }
86
87 /**
88 * Build the form object.
89 */
90 public function buildQuickForm() {
91 CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)'));
92
93 $this->assign('validTriggerPermission', CRM_Core_DAO::checkTriggerViewPermission(FALSE));
94
95 $this->addFormRule(['CRM_Admin_Form_Setting_Miscellaneous', 'formRule'], $this);
96
97 parent::buildQuickForm();
98 $this->addRule('checksum_timeout', ts('Value should be a positive number'), 'positiveInteger');
99 }
100
101 /**
102 * Global form rule.
103 *
104 * @param array $fields
105 * The input form values.
106 * @param array $files
107 * The uploaded files if any.
108 * @param array $options
109 * Additional user data.
110 *
111 * @return bool|array
112 * true if no errors, else array of errors
113 */
114 public static function formRule($fields, $files, $options) {
115 $errors = [];
116
117 // validate max file size
118 if ($fields['maxFileSize'] > $options->_uploadMaxSize) {
119 $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini.");
120 }
121
122 // validate recent items stack size
123 if ($fields['recentItemsMaxCount'] && ($fields['recentItemsMaxCount'] < 1 || $fields['recentItemsMaxCount'] > CRM_Utils_Recent::MAX_ITEMS)) {
124 $errors['recentItemsMaxCount'] = ts("Illegal stack size. Use values between 1 and %1.", [1 => CRM_Utils_Recent::MAX_ITEMS]);
125 }
126
127 if (!empty($fields['wkhtmltopdfPath'])) {
128 // check and ensure that thi leads to the wkhtmltopdf binary
129 // and it is a valid executable binary
130 // Only check the first space separated piece to allow for a value
131 // such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292)
132 $pieces = explode(' ', $fields['wkhtmltopdfPath']);
133 $path = $pieces[0];
134 if (
135 !file_exists($path) ||
136 !is_executable($path)
137 ) {
138 $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid');
139 }
140 }
141 return $errors;
142 }
143
144 }