FusionDirectory
class_SimplePluginLdapError.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2019-2020 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 
25 {
26  protected $dn;
27  protected $operation;
28 
29  public function __construct ($origin, string $dn = NULL, int $operation = NULL, string $ldapError = '', int $code = 0, Throwable $previous = NULL)
30  {
31  $this->dn = $dn;
32  $this->operation = $operation;
33 
34  parent::__construct($origin, htmlescape($ldapError), $code, $previous);
35  }
36 
37  public function toArray (): array
38  {
39  $array = parent::toArray();
40 
41  $typemap = [1 => 'read','add','modify','delete','search','authentication'];
42 
43  $array['dn'] = $this->dn;
44  if (isset($this->operation)) {
45  $array['operation'] = $typemap[$this->operation];
46  }
47  $array['errno'] = $this->getCode();
48 
49  return $array;
50  }
51 
52  public function computeMsgDialogParameters (): array
53  {
54  $html = '';
55 
56  if (isset($this->object->dn)) {
57  $html .= htmlescape($this->object->dn.' > ');
58  }
59 
60  if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
61  $html .= htmlescape($this->tab->parent->by_name[get_class($this->tab)].' > ');
62  }
63 
64  if (isset($this->attribute)) {
65  $label = $this->attribute->getLabel();
66  if (empty($label)) {
67  $html .= '<i>'.htmlescape($this->attribute->getLdapName()).'</i>';
68  } else {
69  $html .= htmlescape($label);
70  }
71  }
72 
73  $html .= '<br/><br/>';
74 
75  /* Assign headline depending on type */
76  $typemap = [1 => _('read operation'), _('add operation'), _('modify operation'),
77  _('delete operation'), _('search operation'), _('authentication')];
78 
79  if (isset($this->operation)) {
80  $html .= htmlescape(sprintf(_('LDAP %s failed!'), $typemap[$this->operation]));
81  } else {
82  $html .= htmlescape(_('LDAP operation failed!'));
83  }
84 
85  if (!empty($this->dn)) {
86  $html .= '<br/><br/><i>'.htmlescape(_('Object:')).'</i> '.htmlescape($this->dn);
87  }
88 
89  $html .= '<br/><br/><i>'.htmlescape(_('Error:')).'</i> '.$this->htmlMessage;
90 
91  return [_('LDAP error'), $html, LDAP_ERROR, FusionDirectoryError::formatTrace($this)];
92  }
93 }
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
Error returned by any method of SimplePlugin.
Error returned by an LDAP operation called from SimplePlugin.