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