1 <?php
2 /*
3 This code is part of GOsa (https://oss.gonicus.de/labs/gosa/)
4 Copyright (C) 2007 Fabian Hickert
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /*
23 Data structure :
25 |->o_tab <-- dummy object, collects HTML posts, displays ui
26 |->a_handles <-- tab object for each given dn
27 |->tab object for dn 1
28 |->tab object for dn 2
29 ...
30 |->tab object for dn n
32 */
35 /*! \brief Handles multiple edits for a given set of dns.
36 \author Fabian Hickert
37 \version 1.01
38 \date 2007/12/07
40 This class edits multiple tab objects at once.
41 1. There is a dummy tab object initialized that collects the user input.
42 2. All given objects specified by '$dn' will be initialized and the collected
43 data from the dummy object will be populated to them.
44 */
45 class multi_plug
46 {
47 /* Tab handler for each given dn entry */
48 public $a_handles = array();
50 /* Dummy handler which collects the data */
51 private $o_tab = NULL;
53 public $dn = array();
54 public $config = NULL;
55 private $s_class= "";
56 public $current = "";
58 /*! \brief Creates a multi_plug object
59 @param object $config GOsa Configuration object
60 @param string $class The class name of the tab we want to edit. e.g. usertabs
61 @param string $tab The config tab name e.g. USERTABS
62 @param array $dns The object dns we want to edit.
63 @return object multi_plug
64 */
65 public function __construct($config,$class,$tab,$dns)
66 {
67 $this->dn = $dns;
68 $this->config = $config;
69 $this->s_class = $class;
71 /* Initialize collector object
72 * Used to display the ui and to collect the user input.
73 */
74 $this->o_tab = new $class($config,$tab,"new");
76 /* Check if the specified tab object supports multiple edits
77 */
78 if($this->o_tab->multiple_support_available()){
80 /* Enable multiple actions for the collector object
81 */
82 $this->o_tab->enable_multiple_support();
84 /* Initialize the objects we want to edit at once
85 */
86 foreach($dns as $dn){
87 $this->a_handles[] = new $class($config,$tab,$dn);
88 }
89 }
90 }
92 /*! \brief Returns the edit ui for multiple edit.
93 @return string HTML User interface for given tab object.
94 */
95 public function execute()
96 {
97 return($this->o_tab->execute());
98 }
101 /*! \brief Checks if one of the objects we want to edit is locked.
102 @return boolean Returns TRUE if at least one entry is locked, else false.
103 */
104 public function entries_locked()
105 {
106 return(FALSE);
107 }
110 /*! \brief Generates a lock message that can be displayed if an entry is locked.
111 @return string Returns a list of locked entries
112 */
113 public function display_lock_message()
114 {
115 return("sdf");
116 }
119 /*! \brief Locks all currently managed objects (array $this->dn)
120 @return boolean Returns TRUE
121 */
122 public function lock_entries($uid)
123 {
124 return(TRUE);
125 }
128 /*! \brief Checks if the given tab object supports multiple edit.
129 @return boolean Returns TRUE if the given tab objects supports multiple edit else FALSE.
130 */
131 public function multiple_available()
132 {
133 return($this->o_tab->multiple_support_available());
134 }
137 /*! \brief Sets the currently active tab. The tab that will be displayed by $this->execute().
138 */
139 public function set_active_tab($str)
140 {
141 $this->current = $str;
142 }
145 /*! \brief Returns the object info string, that can be displayed in the tab header.
146 @return string Returns an information string, containing the list of currently edited dns.
147 */
148 public function get_object_info()
149 {
150 return("Oi -----");
151 }
154 /*! \brief Handles all HTML posts from the dummy tab object.
155 */
156 public function save_object()
157 {
158 $this->o_tab->save_object();
159 }
162 /*! \brief Checks if the values fetched by $this->save_object() are valid.
163 @param array Returns an array containig all error messages.
164 */
165 public function check()
166 {
167 $this->populate_values();
168 $messages = $this->o_tab->check();
169 foreach($this->a_handles as $key => $obj){
170 $msgs = $obj->check();
171 foreach($msgs as $msg){
172 $messages[] = $msg;
173 }
174 }
175 return($messages);
176 }
179 /*! \brief Currently not implemented, later be used to trigger password changes.
180 @param boolean Returns TRUE if a password change is needed.
181 */
182 public function password_change_needed()
183 {
184 return(FALSE);
185 }
188 /*! \brief Populate all collected values to the target tab objects ($this->o_handles)
189 */
190 public function populate_values()
191 {
193 if($this->multiple_available() && is_array($this->a_handles)){
194 foreach($this->o_tab->by_object as $name => $obj){
195 $values = $this->o_tab->by_object[$name]->get_multi_edit_values();
196 foreach($values as $a_name => $a_value){
197 foreach($this->a_handles as $i_id => $o_handle){
198 $o_handle->by_object[$name]->$a_name = $a_value;
199 }
200 }
201 }
202 }
203 }
206 /*! \brief Save all edited tab objects ($this->o_handles).
207 */
208 public function save()
209 {
210 if($this->multiple_available() && is_array($this->a_handles)){
211 $this->populate_values();
212 foreach($this->a_handles as $i_id => $o_handle){
213 $o_handle->save();
214 }
215 }
216 }
217 }
219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
220 ?>