FusionDirectory
 All Data Structures Files Functions Variables
class_multiPlugin.inc
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-2016 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 
27 {
28  /* attribute list for save action */
29  var $objectclasses = array();
30  var $ignore_account = TRUE;
31  var $plugin = array();
32 
33  var $tabClass = '';
34 
35  static function getAttributesInfo ()
36  {
37  return array();
38  }
39 
40  function __construct ($dn = NULL, $object = NULL, $parent = NULL)
41  {
42  global $config;
43  parent::__construct($dn, $object, $parent, FALSE);
44 
45  $plInfos = pluglist::pluginInfos(get_class($this));
46 
47  /* Load accounts */
48  foreach ($config->data['TABS'][$this->tabClass] as $plug) {
49  if (!plugin_available($plug['CLASS'])) {
50  continue;
51  }
52  $name = $plug['CLASS'];
53  $this->plugin[$name] = new $name($dn, $object, $parent);
54 
55  /* Acl base && category configuration,
56  these settings will be overloaded in main.inc,
57  if we are editing ourself */
58  $this->plugin[$name]->set_acl_category($plInfos['plCategory'][0]);
59  $this->plugin[$name]->set_acl_base($this->dn);
60  }
61  }
62 
63  function execute()
64  {
65  $display = "";
66 
67  /* Do we represent a valid account? */
68  if ($this->parent === NULL) {
69  $enabled = FALSE;
70  foreach ($this->plugin as &$plug) {
71  if ($plug->is_account) {
72  $enabled = TRUE;
73  break;
74  }
75  }
76  unset($plug);
77  if (!$enabled) {
78  $display = '<img alt="" src="geticon.php?context=status&amp;icon=dialog-error&amp;size=16" align="middle"/>&nbsp;<b>'.
80  $display .= back_to_main();
81  return $display;
82  }
83  }
84 
85  /* Execude objects */
86  $is_first = TRUE;
87 
88  $readOnly = $this->readOnly();
89 
90  foreach ($this->plugin as &$plug) {
91  $plug->read_only = $readOnly;
92  if (!$is_first) {
93  $display .= '<p class="seperator plugbottom">&nbsp;</p>';
94  } else {
95  $is_first = FALSE;
96  }
97  $display .= $plug->execute();
98  }
99  unset($plug);
100 
101  return $display;
102  }
103 
104 
105  /* Save data to object */
106  function save_object()
107  {
108  foreach ($this->plugin as &$plug) {
109  $plug->save_object();
110  }
111  unset($plug);
112  }
113 
114  function check()
115  {
116  $message = parent::check();
117 
118  foreach ($this->plugin as &$plug) {
119  if ($plug->is_account || $plug->ignore_account) {
120  $tmp = $plug->check();
121  $message = array_merge($message, $tmp);
122  }
123  }
124  unset($plug);
125 
126  return $message;
127  }
128 
129  function set_acl_category($cat)
130  {
131  parent::set_acl_category($cat);
132  foreach ($this->plugin as &$plug) {
133  $plug->set_acl_category($cat);
134  }
135  unset($plug);
136  }
137 
138  function set_acl_base($base)
139  {
140  parent::set_acl_base($base);
141  foreach ($this->plugin as &$plug) {
142  $plug->set_acl_base($base);
143  }
144  unset($plug);
145  }
146 
147  public function setNeedEditMode ($bool)
148  {
149  parent::setNeedEditMode($bool);
150  foreach ($this->plugin as &$plug) {
151  $plug->setNeedEditMode($bool);
152  }
153  unset($plug);
154  }
155 
156  /* Save to LDAP */
157  function save()
158  {
159  $errors = array();
160  /* Save objects */
161  foreach ($this->plugin as &$plug) {
162  $plug->dn = $this->dn;
163  if ($plug->is_account || $plug->ignore_account) {
164  $result = $plug->save();
165  } else {
166  $result = $plug->remove_from_parent();
167  }
168  if (!empty($result)) {
169  $errors = array_merge($errors, $result);
170  }
171  }
172  unset($plug);
173  return $errors;
174  }
175 
176  function remove_from_parent()
177  {
178  $errors = array();
179  /* Remove objects */
180  foreach ($this->plugin as &$plug) {
181  $plug->dn = $this->dn;
182  $result = $plug->remove_from_parent();
183  if (!empty($result)) {
184  $errors = array_merge($errors, $result);
185  }
186  }
187  unset($plug);
188  return $errors;
189  }
190 
191  function adapt_from_template($attrs, $skip = array())
192  {
193  /* Adapt objects */
194  foreach ($this->plugin as &$plug) {
195  $plug->dn = $this->dn;
196  $plug->adapt_from_template($attrs, $skip);
197  }
198  unset($plug);
199  }
200 
201  function resetCopyInfos()
202  {
203  $this->dn = 'new';
204  foreach ($this->plugin as &$plug) {
205  $plug->resetCopyInfos();
206  }
207  unset($plug);
208  }
209 }
210 
211 ?>
$parent
Reference to parent object.
This class is made for easy plugin creation for editing LDAP attributes.
multiPlugin This class provides the functionality to have multiple plugins in a single tab ...
$dn
dn of the opened object
static noValidExtension($name)
Display error about invalid extension from account.
$attrs
Represent temporary LDAP data.
plugin_available($plugin)
Check if plugin is available.
Definition: functions.inc:146
readOnly()
Indicates if this object is opened as read-only (because of locks)
back_to_main()
Generate HTML for the 'Back' button.
Definition: functions.inc:1370