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