94fce1edafdff58da5ca2cb6993643475da581ea
[civicrm-core.git] / CRM / Admin / Form / Setting / Miscellaneous.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for Miscellaneous.
20 */
21 class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
22
23 protected $_settings = [
24 'max_attachments' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
25 'max_attachments_backend' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
26 'contact_undelete' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
27 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
28 'logging' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
29 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
30 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
31 'recordGeneratedLetters' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
32 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
33 'checksum_timeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
34 'recaptchaOptions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
35 'recaptchaPublicKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
36 'recaptchaPrivateKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
37 'forceRecaptcha' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
38 'wkhtmltopdfPath' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
39 'recentItemsMaxCount' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
40 'recentItemsProviders' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
41 'dedupe_default_limit' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
42 'remote_profile_submissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
43 'allow_alert_autodismissal' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
44 'prevNextBackend' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
45 ];
46
47 public $_uploadMaxSize;
48
49 /**
50 * Basic setup.
51 */
52 public function preProcess() {
53 $this->_uploadMaxSize = (int) ini_get('upload_max_filesize');
54 // check for post max size
55 CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
56 // This is a temp hack for the fact we really don't need to hard-code each setting in the tpl but
57 // we haven't worked through NOT doing that. These settings have been un-hardcoded.
58 $this->assign('pure_config_settings', [
59 'empoweredBy',
60 'max_attachments',
61 'max_attachments_backend',
62 'maxFileSize',
63 'secondDegRelPermissions',
64 'recentItemsMaxCount',
65 'recentItemsProviders',
66 'dedupe_default_limit',
67 'prevNextBackend',
68 ]);
69 }
70
71 /**
72 * Build the form object.
73 */
74 public function buildQuickForm() {
75 CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)'));
76
77 $this->assign('validTriggerPermission', CRM_Core_DAO::checkTriggerViewPermission(FALSE));
78 // dev/core#1812 Assign multilingual status.
79 $this->assign('isMultilingual', CRM_Core_I18n::isMultilingual());
80
81 $this->addFormRule(['CRM_Admin_Form_Setting_Miscellaneous', 'formRule'], $this);
82
83 parent::buildQuickForm();
84 $this->addRule('checksum_timeout', ts('Value should be a positive number'), 'positiveInteger');
85 }
86
87 /**
88 * Global form rule.
89 *
90 * @param array $fields
91 * The input form values.
92 * @param array $files
93 * The uploaded files if any.
94 * @param array $options
95 * Additional user data.
96 *
97 * @return bool|array
98 * true if no errors, else array of errors
99 */
100 public static function formRule($fields, $files, $options) {
101 $errors = [];
102
103 // validate max file size
104 if ($fields['maxFileSize'] > $options->_uploadMaxSize) {
105 $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini.");
106 }
107
108 // validate recent items stack size
109 if ($fields['recentItemsMaxCount'] && ($fields['recentItemsMaxCount'] < 1 || $fields['recentItemsMaxCount'] > CRM_Utils_Recent::MAX_ITEMS)) {
110 $errors['recentItemsMaxCount'] = ts("Illegal stack size. Use values between 1 and %1.", [1 => CRM_Utils_Recent::MAX_ITEMS]);
111 }
112
113 if (!empty($fields['wkhtmltopdfPath'])) {
114 // check and ensure that thi leads to the wkhtmltopdf binary
115 // and it is a valid executable binary
116 // Only check the first space separated piece to allow for a value
117 // such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292)
118 $pieces = explode(' ', $fields['wkhtmltopdfPath']);
119 $path = $pieces[0];
120 if (
121 !file_exists($path) ||
122 !is_executable($path)
123 ) {
124 $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid');
125 }
126 }
127 return $errors;
128 }
129
130 }