FusionDirectory
class_msgPool.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) 2003-2010 Cajus Pollmeier
5  Copyright (C) 2011-2020 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
30 class msgPool
31 {
37  public static function permDelete ($name = '')
38  {
39  if ($name == '') {
40  return htmlescape(_('You have no permission to delete this object!'));
41  }
42 
43  if (!is_array($name)) {
44  return htmlescape(_('You have no permission to delete the object:'))."<br/><br/><i>$name</i>";
45  }
46 
47  if (count($name) == 1) {
48  return htmlescape(_('You have no permission to delete the object:')).'<br/>'.msgPool::buildList($name);
49  }
50 
51  return htmlescape(_('You have no permission to delete these objects:')).'<br/>'.msgPool::buildList($name);
52  }
53 
59  public static function permCreate ($name = '')
60  {
61  if ($name == '') {
62  return htmlescape(_('You have no permission to create this object!'));
63  }
64 
65  if (!is_array($name)) {
66  return htmlescape(_('You have no permission to create the object:')).'<br/><br/><i>'.htmlescape($name).'</i>';
67  }
68 
69  if (count($name) == 1) {
70  return htmlescape(_('You have no permission to create the object:')).'<br/>'.msgPool::buildList($name);
71  }
72 
73  return htmlescape(_('You have no permission to create these objects:')).'<br/>'.msgPool::buildList($name);
74  }
75 
82  public static function permModify ($name = '', $field = '')
83  {
84  if ($name == '') {
85  return htmlescape(_('You have no permission to modify this object!'));
86  }
87 
88  if (!is_array($name)) {
89  if ($field != '') {
90  return htmlescape(sprintf(_('You have no permission to modify the field "%s" of object "%s"'), $field, $name));
91  } else {
92  return sprintf(htmlescape(_('You have no permission to modify the object:%s')), '<br/><br/><i>'.htmlescape($name).'</i>');
93  }
94  }
95 
96  if (count($name) == 1) {
97  return sprintf(htmlescape(_('You have no permission to modify the object:%s')), '<br/>'.msgPool::buildList($name));
98  }
99 
100  return sprintf(htmlescape(_('You have no permission to modify these objects:%s')), '<br/>'.msgPool::buildList($name));
101  }
102 
108  public static function permView ($name = '')
109  {
110  if ($name == '') {
111  return htmlescape(_('You have no permission to view this object!'));
112  }
113 
114  if (!is_array($name)) {
115  return htmlescape(_('You have no permission to view the object:'))."<br/><br/><i>".htmlescape($name)."</i>";
116  }
117 
118  if (count($name) == 1) {
119  return htmlescape(_('You have no permission to view the object:')).'<br/>'.msgPool::buildList($name);
120  }
121 
122  return htmlescape(_('You have no permission to view these objects:')).'<br/>'.msgPool::buildList($name);
123  }
124 
130  public static function permMove ($name = '')
131  {
132  if ($name == '') {
133  return htmlescape(_('You have no permission to move this object!'));
134  }
135 
136  if (!is_array($name)) {
137  return htmlescape(_('You have no permission to move the object:'))."<br/><br/><i>".htmlescape($name)."</i>";
138  }
139 
140  if (count($name) == 1) {
141  return htmlescape(_('You have no permission to move the object:')).'<br/>'.msgPool::buildList($name);
142  }
143 
144  return htmlescape(_('You have no permission to move these objects:')).'<br/>'.msgPool::buildList($name);
145  }
146 
152  public static function reserved ($name)
153  {
154  return htmlescape(sprintf(_('The field "%s" contains a reserved keyword!'), $name));
155  }
156 
166  public static function cmdexecfailed ($type, $command = '', $plugin = '')
167  {
168  if ($command == '') {
169  if ($plugin == '') {
170  return htmlescape(sprintf(_('Cannot execute "%s" command!'), $type));
171  } else {
172  return htmlescape(sprintf(_('Cannot execute "%s" command for plugin %s!'), $type, $plugin));
173  }
174  } else {
175  if ($plugin == '') {
176  return htmlescape(sprintf(_('Cannot execute "%s" command (%s)!'), $type, $command));
177  } else {
178  return htmlescape(sprintf(_('Cannot execute "%s" command (%s) for plugin %s!'), $type, $command, $plugin));
179  }
180  }
181  }
182 
190  public static function toobig ($name, $min = '')
191  {
192  if ($min == '') {
193  return htmlescape(sprintf(_('Value for "%s" is too large!'), $name));
194  } else {
195  return htmlescape(sprintf(_('"%s" must be smaller than %s!'), $name, $min));
196  }
197  }
198 
206  public static function toosmall ($name, $min = '')
207  {
208  if ($min == '') {
209  return htmlescape(sprintf(_('Value for "%s" is too small!'), $name));
210  } else {
211  return htmlescape(sprintf(_('"%s" must be %d or above!'), $name, $min));
212  }
213  }
214 
222  public static function depends ($name1, $name2)
223  {
224  return htmlescape(sprintf(_('"%s" depends on "%s" - please provide both values!'), $name1, $name2));
225  }
226 
233  public static function duplicated ($name, $dn = NULL)
234  {
235  if ($dn == NULL) {
236  return htmlescape(sprintf(_('There is already an entry with this "%s" attribute in the system!'), $name));
237  } else {
238  return htmlescape(sprintf(_('The entry "%s" already uses this "%s" attribute!'), $dn, $name));
239  }
240  }
241 
247  public static function required ($name)
248  {
249  return htmlescape(sprintf(_('The required field "%s" is empty!'), $name));
250  }
251 
261  public static function invalid (string $name, $data = '', string $example = ''): string
262  {
263  if (!is_string($data)) {
264  $data = var_export($data, TRUE);
265  }
266  $error = htmlescape(sprintf(_('The field "%s" contains an invalid value.'), $name));
267  $error .= '<br/><br/> "'.htmlescape($data).'"';
268 
269  /* Stylize example */
270  if ($example !== '') {
271  $error .= '<br/><br/><i>'.htmlescape(sprintf(_('Example: %s'), $example)).'</i> ';
272  }
273 
274  return $error;
275  }
276 
282  public static function missingext ($name)
283  {
284  return htmlescape(sprintf(_('Missing %s PHP extension!'), $name));
285  }
286 
292  public static function cancelButton ($escape = TRUE)
293  {
294  if ($escape) {
295  return htmlescape(_('Cancel'));
296  } else {
297  return _('Cancel');
298  }
299  }
300 
306  public static function okButton ($escape = TRUE)
307  {
308  if ($escape) {
309  return htmlescape(_('Ok'));
310  } else {
311  return _('Ok');
312  }
313  }
314 
320  public static function applyButton ($escape = TRUE)
321  {
322  if ($escape) {
323  return htmlescape(_('Apply'));
324  } else {
325  return _('Apply');
326  }
327  }
328 
334  public static function saveButton ($escape = TRUE)
335  {
336  if ($escape) {
337  return htmlescape(_('Save'));
338  } else {
339  return _('Save');
340  }
341  }
342 
348  public static function addButton ($escape = TRUE)
349  {
350  if ($escape) {
351  return htmlescape(_('Add'));
352  } else {
353  return _('Add');
354  }
355  }
356 
362  public static function delButton ($escape = TRUE)
363  {
364  if ($escape) {
365  return htmlescape(_('Delete'));
366  } else {
367  return _('Delete');
368  }
369  }
370 
376  public static function editButton ($escape = TRUE)
377  {
378  if ($escape) {
379  return htmlescape(_('Edit...'));
380  } else {
381  return _('Edit...');
382  }
383  }
384 
390  public static function backButton ($escape = TRUE)
391  {
392  if ($escape) {
393  return htmlescape(_('Back'));
394  } else {
395  return _('Back');
396  }
397  }
398 
404  public static function buildList ($data)
405  {
406  $objects = '<ul>';
407  foreach ($data as $key => $value) {
408  if (is_numeric($key)) {
409  $objects .= "<li>\n<i>".htmlescape($value)."</i></li>";
410  } else {
411  $objects .= "<li>\n".htmlescape($value)." (<i>".htmlescape($key)."</i>)</li>";
412  }
413  }
414  $objects .= '</ul>';
415  return $objects;
416  }
417 
423  public static function noValidExtension ($name)
424  {
425  return htmlescape(sprintf(_('This account has no valid %s extensions!'), $name));
426  }
427 
435  public static function featuresEnabled ($name, $depends = '')
436  {
437  if (($depends == '') || (is_array($depends) && (count($depends) == 0))) {
438  return htmlescape(sprintf(_('This account has %s settings enabled. You can disable them by clicking below.'), $name));
439  } else {
440  if (is_array($depends)) {
441  $depends = implode(' / ', $depends);
442  }
443  return htmlescape(sprintf(_('This account has %s settings enabled. To disable them, you\'ll need to remove the %s settings first!'), $name, $depends));
444  }
445  }
446 
456  public static function featuresDisabled ($name, array $depends = [], array $conflicts = [])
457  {
458  if (empty($depends) && empty($conflicts)) {
459  return htmlescape(sprintf(_('This account has %s settings disabled. You can enable them by clicking below.'), $name));
460  } elseif (!empty($depends)) {
461  return htmlescape(sprintf(_('This account has %s settings disabled. To enable them, you\'ll need to add the %s settings first!'), $name, implode(' / ', $depends)));
462  } else {
463  return htmlescape(sprintf(_('This account has %s settings disabled. To enable them, you\'ll need to disable the %s settings first!'), $name, implode(' / ', $conflicts)));
464  }
465  }
466 
472  public static function addFeaturesButton ($name)
473  {
474  return htmlescape(sprintf(_('Add %s settings'), $name));
475  }
476 
483  public static function removeFeaturesButton ($name)
484  {
485  return htmlescape(sprintf(_('Remove %s settings'), $name));
486  }
487 
491  public static function clickEditToChange ()
492  {
493  return htmlescape(_('Click the "Edit" button on the bottom right corner of the page to edit the fields'));
494  }
495 
499  public static function months ()
500  {
501  return [_('January'), _('February'), _('March'), _('April'),
502  _('May'), _('June'), _('July'), _('August'), _('September'),
503  _('October'), _('November'), _('December')];
504  }
505 
510  public static function weekdays ()
511  {
512  return [ _('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')];
513  }
514 
526  public static function ldaperror ($error, $dn = '', $type = 0, $plugin = '')
527  {
528  /* Assign headline depending on type */
529  $typemap = [1 => _('read operation'), _('add operation'), _('modify operation'),
530  _('delete operation'), _('search operation'), _('authentication')];
531 
532  if (isset($typemap[$type])) {
533  $msg = htmlescape(sprintf(_('LDAP %s failed!'), $typemap[$type]));
534  } else {
535  $msg = htmlescape(_('LDAP operation failed!'));
536  }
537 
538  /* Fill DN information */
539  if ($dn != '') {
540  $msg .= '<br/><br/><i>'.htmlescape(_('Object')).':</i> '.htmlescape($dn);
541  }
542 
543  $msg .= '<br/><br/><i>'.htmlescape(_('Error')).':</i> '.htmlescape($error);
544 
545  return $msg;
546  }
547 
553  public static function incorrectUpload ($reason = '')
554  {
555  if ($reason == '') {
556  return htmlescape(_('Upload failed!'));
557  }
558 
559  return sprintf(htmlescape(_('Upload failed: %s')), '<br/><br/><i>'.htmlescape($reason).'</i>');
560  }
561 
567  public static function siError ($error = '')
568  {
569  if ($error == '') {
570  return htmlescape(_('Communication failure with the infrastructure service!'));
571  }
572  return nl2br(htmlescape(sprintf(_("Communication failure with the infrastructure service:\n\nError: %s"), $error)));
573  }
574 
580  public static function checkingFor ($what)
581  {
582  return htmlescape(sprintf(_('Checking for %s support'), $what));
583  }
584 
590  public static function installPhpModule ($what)
591  {
592  return htmlescape(sprintf(_('Install and activate the %s PHP module.'), $what));
593  }
594 
598  public static function check_base ()
599  {
600  return htmlescape(_('The supplied base is not valid and has been reset to the previous value!'));
601  }
602 }
static incorrectUpload($reason='')
Display error about an incorrect upload.
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
static months()
Build an array with the months.
static invalid(string $name, $data='', string $example='')
Return error about invalid value.
static installPhpModule($what)
Display install or activate a PHP module.
static delButton($escape=TRUE)
Text for an delete button.
static cmdexecfailed($type, $command='', $plugin='')
Display that a command execution failed in this plugin.
static featuresEnabled($name, $depends='')
List the features settings enabled.
static required($name)
Display error about required field empty.
static addButton($escape=TRUE)
Text for an add button.
static checkingFor($what)
Display checking for a support.
static applyButton($escape=TRUE)
Text for an apply button.
static editButton($escape=TRUE)
Text for an edit button.
static addFeaturesButton($name)
Display Add features button.
static permCreate($name='')
Display that we have no permission to create an object.
static weekdays()
Build an array with the days of a week. Start by Sunday.
static featuresDisabled($name, array $depends=[], array $conflicts=[])
List the features settings disabled.
static reserved($name)
Display field contains reserved keyword.
static check_base()
Display error when checking the base.
static permDelete($name='')
Display that we have no permission to delete an object.
static duplicated($name, $dn=NULL)
Display error about existing entry in the system.
static siError($error='')
Display error about communication failure with the infrastructure service.
static cancelButton($escape=TRUE)
Text for a cancel button.
static noValidExtension($name)
Display error about invalid extension from account.
static ldaperror($error, $dn='', $type=0, $plugin='')
Display LDAP error.
This class contains all the messages for the various actions.
static toobig($name, $min='')
Display error about too larged value.
static permMove($name='')
Display that we have no permission to move an object.
static saveButton($escape=TRUE)
Text for a save button.
static missingext($name)
Display about missing PHP extension.
static permView($name='')
Display that we have no permission to view an object.
static backButton($escape=TRUE)
Text for a back button.
static okButton($escape=TRUE)
Text for a ok button.
static permModify($name='', $field='')
Display that we have no permission to modify an object.
static depends($name1, $name2)
Display a dependence between two objects.
static buildList($data)
a list from an array
static toosmall($name, $min='')
Display error about too small value.
static removeFeaturesButton($name)
Display Remove features button.
static clickEditToChange()
Display : Click the "Edit" button below to change information in this dialog.