FusionDirectory
class_ldapSizeLimit.inc
Go to the documentation of this file.
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2017-2018 FusionDirectory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
32 {
34  protected $sizeLimit;
35 
37  protected $ignore;
38 
40  protected $limitExceeded;
41 
42  function __construct ()
43  {
44  global $config;
45 
46  $this->sizeLimit = $config->get_cfg_value('LDAPSIZELIMIT', 200);
47  $this->ignore = preg_match('/true/i', $config->get_cfg_value('LDAPSIZEIGNORE', 'TRUE'));
48  }
49 
50  function getSizeLimit ()
51  {
52  return $this->sizeLimit;
53  }
54 
55  function setSizeLimit ($limit)
56  {
57  $this->sizeLimit = $limit;
58  }
59 
60  function setLimitExceeded ($exceeded = TRUE)
61  {
62  $this->limitExceeded = $exceeded;
63  }
64 
68  function update ()
69  {
70  if (isset($_POST['set_size_action']) && isset($_POST['action'])) {
71  switch ($_POST['action']) {
72  case 'newlimit':
73  if (isset($_POST['new_limit']) && tests::is_id($_POST['new_limit'])) {
74  if (($error = static::checkMaxInputVars($_POST['new_limit'])) !== FALSE) {
75  $error->display();
76  } else {
77  $this->sizeLimit = intval($_POST['new_limit']);
78  $this->ignore = FALSE;
79  }
80  }
81  break;
82  case 'ignore':
83  $this->sizeLimit = 0;
84  $this->ignore = TRUE;
85  break;
86  case 'limited':
87  $this->ignore = TRUE;
88  break;
89  default:
90  break;
91  }
92  }
93 
94  /* Allow fallback to dialog */
95  if (isset($_POST['edit_sizelimit'])) {
96  $this->ignore = FALSE;
97  }
98  }
99 
106  function check ()
107  {
108  global $config;
109 
110  /* Ignore dialog? */
111  if ($this->ignore) {
112  return '';
113  }
114 
115  /* Eventually show dialog */
116  if ($this->limitExceeded) {
117  $smarty = get_smarty();
118  $smarty->assign('sizelimit', $this->sizeLimit);
119  return $smarty->fetch(get_template_path('sizelimit.tpl'));
120  }
121 
122  return '';
123  }
124 
131  function renderWarning ()
132  {
133  if ($this->limitExceeded) {
134  $config = '<input type="submit" name="edit_sizelimit" value="'.htmlescape(_('Configure')).'" formnovalidate="formnovalidate"/>';
135  return '('.htmlescape(_('incomplete')).') '.$config;
136  }
137  return '';
138  }
139 
145  static public function checkMaxInputVars (int $newLimit, string $messageTemplate = NULL)
146  {
147  $maxInputVars = ini_get('max_input_vars');
148 
149  if (($maxInputVars != '') && (($newLimit + 10) >= intval($maxInputVars))) {
150  return new FusionDirectoryError(
151  htmlescape(sprintf(
152  $messageTemplate ?? _('Limit %d is greater than or too close to configured max_input_vars PHP ini setting of %d. Please change max_input_vars ini setting to a higher value if you wish to set the limit higher.'),
153  $newLimit,
154  $maxInputVars
155  ))
156  );
157  }
158 
159  return FALSE;
160  }
161 }
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
update()
Handle sizelimit dialog related posts.
get_template_path($filename='', $plugin=FALSE, $path='')
Return themed path for specified base file.
Definition: functions.inc:174
Class ldapSizeLimit This class contains all informations and functions to handle the LDAP size limit ...
& get_smarty()
Get global smarty object.
Definition: functions.inc:324
static checkMaxInputVars(int $newLimit, string $messageTemplate=NULL)
renderWarning()
Print a sizelimit warning.
$sizeLimit
Current size limit.
$limitExceeded
Limit was exceeded.
Parent class for all errors in FusionDirectory.
check()
Show sizelimit configuration dialog.
$ignore
Ignore dialogs.
static is_id($id)
Check if the given argument is an id.