FusionDirectory
 All Data Structures Files Functions Variables
class_CopyPasteHandler.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-2017 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 
31 {
32  var $current;
33 
37  protected $objectList = array();
41  protected $queue = array();
42 
46  var $lastdn = "";
47 
48  var $disallowed_objects = array();
49  var $objects_to_fix = array();
50  var $clean_objects = array();
51  var $require_update = FALSE;
52 
58  function __construct()
59  {
60  $this->current = NULL;
61  $this->queue = array();
62  }
63 
64 
78  function add_to_queue($dn, $action, $type)
79  {
80  @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'add_to_queue');
81 
82  if (!in_array($action, array('cut','copy'))) {
83  trigger_error(sprintf('Specified action "%s" does not exists for copy & paste.', $action));
84  return FALSE;
85  }
86 
87  $tmp = array();
88 
89  $tmp['method'] = $action;
90  $tmp['dn'] = $dn;
91  $tmp['type'] = $type;
92 
93  $infos = objects::infos($type);
94  $tmp['aclCategory'] = $infos['aclCategory'];
95  $tmp['mainTab'] = $infos['mainTab'];
96  $tmp['parent'] = NULL;
97 
98  $this->queue[] = $tmp;
99  if ($action == 'copy') {
100  $this->objectList[] = $tmp;
101  }
102  $this->require_update = TRUE;
103 
104  return TRUE;
105  }
106 
107 
113  function cleanup_queue()
114  {
115  $this->current = FALSE;
116  $this->require_update = TRUE;
117  $this->queue = array();
118  $this->objectList = array();
119  }
120 
124  function resetPaste()
125  {
126  $this->current = FALSE;
127  $this->require_update = TRUE;
128  $this->queue = $this->objectList;
129  }
130 
134  function entries_queued()
135  {
136  return ((count($this->queue) > 0) || ($this->current != FALSE));
137  }
138 
142  protected function load_entry_from_ldap($entry, $base)
143  {
144  @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $entry['dn'], 'load_entry_from_ldap');
145  if (!isset($entry['tab_class']) && !isset($entry['type'])) {
146  return array();
147  }
148 
149  $entry['object'] = objects::open($entry['dn'], $entry['type']);
150 
151  $entry['object']->set_acl_base($base);
152  if ($entry['parent'] !== NULL) {
153  $entry['object']->parent = $entry['parent'];
154  }
155 
156  if ($entry['method'] == 'copy') {
157  $entry['object']->resetCopyInfos();
158  }
159 
160  $entry['object']->resetBase();
161 
162  return $entry;
163  }
164 
169  function execute($base)
170  {
171  $ui = get_userinfo();
172 
173  /* Check which entries can be pasted directly.
174  * Create a list of all entries that can be pasted directly.
175  */
176  if ($this->require_update) {
177  $this->clean_objects = array();
178  $this->objects_to_fix = array();
179  $this->disallowed_objects = array();
180 
181  /* Put each queued object in one of the above arrays */
182  foreach ($this->queue as $key => $entry) {
183 
184  /* Update entries on demand */
185  if (!isset($entry['object'])) {
186  $entry = $this->load_entry_from_ldap($entry, $base);
187  $this->queue[$key] = $entry;
188  }
189 
190  /* Retrieve ACL infos */
191  $copy_acl = $ui->is_copyable($entry['dn'], $entry['aclCategory']);
192  $cut_acl = $ui->is_cutable($entry['dn'], $entry['aclCategory'], $entry['mainTab']);
193 
194  /* Check permissions */
195  if (($entry['method'] == 'copy') && !$copy_acl) {
196  $this->disallowed_objects[$key] = $entry;
197  } elseif (($entry['method'] == 'cut') && !$cut_acl) {
198  $this->disallowed_objects[$key] = $entry;
199  } else {
200  $this->clean_objects[$key] = $entry;
201  }
202  }
203  if (count($this->disallowed_objects)) {
204  $dns = array();
205  foreach ($this->disallowed_objects as $entry) {
206  $dns[] = $entry['dn'];
207  }
208  msg_dialog::display(_('Permission'), msgPool::permCreate($dns), INFO_DIALOG);
209  }
210  $this->require_update = FALSE;
211  }
212 
213  /* Save objects that can be pasted directly */
214  if (count($this->clean_objects)) {
215  $this->save_object();
216  foreach ($this->clean_objects as $key => $entry) {
217  $this->current = $entry;
218  $errors = $this->current['object']->save();
219 
220  if (empty($errors)) {
221  $this->current_saved();
222  /* Remove from queue -> avoid saving twice */
223  unset($this->queue[$key]);
224  } else {
225  $this->objects_to_fix[$key] = $entry;
226  }
227  unset($this->clean_objects[$key]);
228  }
229  $this->current = FALSE;
230  }
231 
232  /* Save edited entry and force loading new one */
233  if (isset($this->current['object'])) {
234  $this->current['object']->save_object();
235  /* Save current object if edition is finished */
236  if (isset($_POST['edit_finish'])) {
237  $errors = $this->current['object']->save();
238 
239  if (empty($errors)) {
240  $this->current_saved();
241  } else {
242  msg_dialog::displayChecks($errors);
243  }
244  }
245  }
246 
247  /* Display a list of all pastable entries */
248  if ($this->current || count($this->objects_to_fix)) {
249  $this->save_object();
250  if (!$this->current) {
251  $key = key($this->objects_to_fix);
252  if ($key !== NULL) {
253  $this->current = $this->objects_to_fix[$key];
254  unset($this->objects_to_fix[$key]);
255  unset($this->queue[$key]);
256  }
257  }
258  if ($this->current) {
259  $display = $this->current['object']->execute();
260  if ($this->current['object']->dialogOpened()) {
261  return $display;
262  } else {
263  // Display ok, (apply) and cancel buttons
264  $display .= '<p class="plugbottom">'."\n";
265  $display .= '<input type="submit" name="edit_finish" style="width:80px" value="'.msgPool::okButton().'"/>'."\n";
266  $display .= "&nbsp;\n";
267  $display .= '<input type="submit" name="abort_current_cut-copy_operation" value="'.msgPool::cancelButton().'"/>'."\n";
268  $display .= '<input type="submit" name="abort_all_cut-copy_operations" value="'._('Cancel all').'"/>'."\n";
269  $display .= '</p>';
270  return $display;
271  }
272  }
273  }
274  return '';
275  }
276 
277  private function current_saved()
278  {
279  $this->lastdn = $this->current['object']->dn;
280  $this->handleReferences();
281  $this->current = FALSE;
282  }
283 
289  function last_entry()
290  {
291  return $this->lastdn;
292  }
293 
294 
298  function save_object()
299  {
300  if (isset($_POST['abort_current_cut-copy_operation'])) {
301  $this->current = FALSE;
302  }
303 
304  if (isset($_POST['abort_all_cut-copy_operations'])) {
305  $this->cleanup_queue();
306  $this->current = FALSE;
307  }
308  }
309 
310  function handleReferences()
311  {
312  $dst_dn = $this->current['object']->dn;
313  $src_dn = $this->current['dn'];
314 
315  $this->current['object']->getBaseObject()->handleForeignKeys(
316  $src_dn,
317  $dst_dn,
318  ($this->current['method'] == 'cut' ? 'move' : 'copy')
319  );
320  }
321 
327  function generatePasteIcon()
328  {
329  $Copy_Paste = "&nbsp;<img class='center' src='images/lists/seperator.png' alt='' height='16' width='1'>&nbsp;";
330  if ($this->entries_queued()) {
331  $Copy_Paste .= "<input type='image' name='editPaste' class='center'
332  src='geticon.php?context=actions&amp;icon=edit-paste&amp;size=16' alt='"._("Paste")."'>&nbsp;";
333  } else {
334  $Copy_Paste .= "<img class='center' src='geticon.php?context=actions&amp;icon=edit-paste&amp;size=16&amp;disabled=1' alt=\""._("Cannot paste")."\">&nbsp;";
335  }
336  return $Copy_Paste;
337  }
338 }
339 ?>
add_to_queue($dn, $action, $type)
Entry entry to Copy & Paste queue. A Queue entry is represented as follows. array['method'] - 'copy' or '...
cleanup_queue()
This removes all objects from queue. Remove hdd dumps of current entries too. Remove entries older th...
entries_queued()
Check if there are still entries the object queue.
generatePasteIcon()
Generate the paste icon for headpages.
$objectList
This array contains all dns of the currently copied objects.
execute($base)
Displays a dialog which allows the user to fix all dependencies of this object. Create unique names...
resetPaste()
This resets the queue to allow pasting again.
& get_userinfo()
Return the current userinfo object.
Definition: functions.inc:922
This class contains all function to copy and paste.
__construct()
Create CP handler.
last_entry()
Get the last endited entry.
$lastdn
The dn of the last edited object.
DEBUG($level, $line, $function, $file, $data, $info= '')
Debug level action.
Definition: functions.inc:200
static permCreate($name="")
Display that we have no permission to create an object.
static display($s_title, $s_message, $i_type=INFO_DIALOG)
Display a message dialog.
$queue
This array contains all remaining objects to paste.
load_entry_from_ldap($entry, $base)
Paste one entry from LDAP.
static open($dn, $type)
Create the tab object for the given dn.
save_object()
Save new values posted by copy & paste dialog.