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