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