ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRepUtilGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13 
20  function __construct($a_parent_gui, $a_parent_cmd = "")
21  {
22  $this->parent_gui = $a_parent_gui;
23  $this->parent_cmd = $a_parent_cmd;
24  }
25 
26 
30  function showDeleteConfirmation($a_ids, $a_supress_message = false)
31  {
32  global $lng, $ilSetting, $ilCtrl, $tpl, $objDefinition;
33 
34  if (!is_array($a_ids) || count($a_ids) == 0)
35  {
36  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
37  return false;
38  }
39 
40  // Remove duplicate entries
41  $a_ids = array_unique((array) $a_ids);
42 
43  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
44  $cgui = new ilConfirmationGUI();
45 
46  if(!$a_supress_message)
47  {
48  $msg = $lng->txt("info_delete_sure");
49 
50  if (!$ilSetting->get('enable_trash'))
51  {
52  $msg .= "<br/>".$lng->txt("info_delete_warning_no_trash");
53  }
54 
55  $cgui->setHeaderText($msg);
56  }
57  $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
58  $cgui->setCancel($lng->txt("cancel"), "cancelDelete");
59  $cgui->setConfirm($lng->txt("confirm"), "confirmedDelete");
60 
61  $form_name = "cgui_".md5(uniqid());
62  $cgui->setFormName($form_name);
63 
64  $deps = array();
65  foreach ($a_ids as $ref_id)
66  {
67  $obj_id = ilObject::_lookupObjId($ref_id);
68  $type = ilObject::_lookupType($obj_id);
69  $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'),$obj_id);
70  $alt = ($objDefinition->isPlugin($type))
71  ? $lng->txt("icon")." ".ilPlugin::lookupTxt("rep_robj", $type, "obj_".$type)
72  : $lng->txt("icon")." ".$lng->txt("obj_".$type);
73 
74  $title .= $this->handleMultiReferences($obj_id, $ref_id, $form_name);
75 
76  $cgui->addItem("id[]", $ref_id, $title,
77  ilObject::_getIcon($obj_id, "small", $type),
78  $alt);
79 
80  ilObject::collectDeletionDependencies($deps, $ref_id, $obj_id, $type);
81  }
82  $deps_html = "";
83 
84  if (is_array($deps) && count($deps) > 0)
85  {
86  include_once("./Services/Repository/classes/class.ilRepDependenciesTableGUI.php");
87  $tab = new ilRepDependenciesTableGUI($deps);
88  $deps_html = "<br/><br/>".$tab->getHTML();
89  }
90 
91  $tpl->setContent($cgui->getHTML().$deps_html);
92  return true;
93  }
94 
103  function handleMultiReferences($a_obj_id, $a_ref_id, $a_form_name)
104  {
105  global $lng, $ilAccess, $tree;
106 
107  // process
108 
109  $all_refs = ilObject::_getAllReferences($a_obj_id);
110  if(sizeof($all_refs) > 1)
111  {
112  $lng->loadLanguageModule("rep");
113 
114  $may_delete_any = 0;
115  $counter = 0;
116  $items = array();
117  foreach($all_refs as $mref_id)
118  {
119  // not the already selected reference, no refs from trash
120  if($mref_id != $a_ref_id && !$tree->isDeleted($mref_id))
121  {
122  if($ilAccess->checkAccess("read", "", $mref_id))
123  {
124  $may_delete = false;
125  if($ilAccess->checkAccess("delete", "", $mref_id))
126  {
127  $may_delete = true;
128  $may_delete_any++;
129  }
130 
131  $items[] = array("id" => $mref_id,
132  "path" => array_shift($this->buildPath(array($mref_id))),
133  "delete" => $may_delete);
134  }
135  else
136  {
137  $counter++;
138  }
139  }
140  }
141 
142 
143  // render
144 
145  $tpl = new ilTemplate("tpl.rep_multi_ref.html", true, true, "Services/Repository");
146 
147  $tpl->setVariable("TXT_INTRO", $lng->txt("rep_multiple_reference_deletion_intro"));
148 
149  if($may_delete_any)
150  {
151  $tpl->setVariable("TXT_INSTRUCTION", $lng->txt("rep_multiple_reference_deletion_instruction"));
152  }
153 
154  if($items)
155  {
156  $var_name = "mref_id[]";
157 
158  foreach($items as $item)
159  {
160  if($item["delete"])
161  {
162  $tpl->setCurrentBlock("cbox");
163  $tpl->setVariable("ITEM_NAME", $var_name);
164  $tpl->setVariable("ITEM_VALUE", $item["id"]);
165  $tpl->parseCurrentBlock();
166  }
167  else
168  {
169  $tpl->setCurrentBlock("item_info");
170  $tpl->setVariable("TXT_ITEM_INFO", $lng->txt("rep_no_permission_to_delete"));
171  $tpl->parseCurrentBlock();
172  }
173 
174  $tpl->setCurrentBlock("item");
175  $tpl->setVariable("ITEM_TITLE", $item["path"]);
176  $tpl->parseCurrentBlock();
177  }
178 
179  if($may_delete_any > 1)
180  {
181  $tpl->setCurrentBlock("cbox");
182  $tpl->setVariable("ITEM_NAME", "sall_".$a_ref_id);
183  $tpl->setVariable("ITEM_VALUE", "");
184  $tpl->setVariable("ITEM_ADD", " onclick=\"il.Util.setChecked('".
185  $a_form_name."', '".$var_name."', document.".$a_form_name.
186  ".sall_".$a_ref_id.".checked)\"");
187  $tpl->parseCurrentBlock();
188 
189  $tpl->setCurrentBlock("item");
190  $tpl->setVariable("ITEM_TITLE", $lng->txt("select_all"));
191  $tpl->parseCurrentBlock();
192  }
193  }
194 
195  if($counter)
196  {
197  $tpl->setCurrentBlock("add_info");
198  $tpl->setVariable("TXT_ADDITIONAL_INFO",
199  sprintf($lng->txt("rep_object_references_cannot_be_read"), $counter));
200  $tpl->parseCurrentBlock();
201  }
202 
203  return $tpl->get();
204  }
205  }
206 
212  function showTrashTable($a_ref_id)
213  {
214  global $tpl, $tree, $lng;
215 
216  $objects = $tree->getSavedNodeData($a_ref_id);
217 
218  if (count($objects) == 0)
219  {
220  ilUtil::sendInfo($lng->txt("msg_trash_empty"));
221  return;
222  }
223  include_once("./Services/Repository/classes/class.ilTrashTableGUI.php");
224  $ttab = new ilTrashTableGUI($this->parent_gui, "trash");
225  $ttab->setData($objects);
226 
227  $tpl->setContent($ttab->getHTML());
228  }
229 
236  function restoreObjects($a_cur_ref_id, $a_ref_ids)
237  {
238  global $lng;
239 
240  if (!is_array($a_ref_ids) || count($a_ref_ids) == 0)
241  {
242  ilUtil::sendFailure($lng->txt("no_checkbox"),true);
243  return false;
244  }
245  else
246  {
247  try
248  {
249  include_once("./Services/Repository/classes/class.ilRepUtil.php");
250  ilRepUtil::restoreObjects($a_cur_ref_id, $a_ref_ids);
251  ilUtil::sendSuccess($lng->txt("msg_undeleted"),true);
252  }
253  catch (Exception $e)
254  {
255  ilUtil::sendFailure($e->getMessage(),true);
256  return false;
257  }
258  }
259  return true;
260  }
261 
265  function deleteObjects($a_cur_ref_id, $a_ref_ids)
266  {
267  global $ilSetting, $lng;
268 
269  if (!is_array($a_ref_ids) || count($a_ref_ids) == 0)
270  {
271  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
272  return false;
273  }
274  else
275  {
276  include_once("./Services/Repository/classes/class.ilRepUtil.php");
277  try
278  {
279  ilRepUtil::deleteObjects($a_cur_ref_id, $a_ref_ids);
280  if ($ilSetting->get('enable_trash'))
281  {
282  ilUtil::sendSuccess($lng->txt("info_deleted"),true);
283  }
284  else
285  {
286  ilUtil::sendSuccess($lng->txt("msg_removed"),true);
287  }
288  }
289  catch (Exception $e)
290  {
291  ilUtil::sendFailure($e->getMessage(), true);
292  return false;
293  }
294  }
295  }
296 
300  function removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder = false)
301  {
302  global $lng;
303 
304  if (!is_array($a_ref_ids) || count($a_ref_ids) == 0)
305  {
306  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
307  return false;
308  }
309  else
310  {
311  include_once("./Services/Repository/classes/class.ilRepUtil.php");
312  try
313  {
314  ilRepUtil::removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder);
315  ilUtil::sendSuccess($lng->txt("msg_removed"),true);
316  }
317  catch (Exception $e)
318  {
319  ilUtil::sendFailure($e->getMessage(), true);
320  return false;
321  }
322  }
323 
324  return true;
325  }
326 
333  protected function buildPath($ref_ids)
334  {
335  global $tree;
336 
337  include_once 'Services/Link/classes/class.ilLink.php';
338 
339  if(!count($ref_ids))
340  {
341  return false;
342  }
343 
344  $result = array();
345  foreach($ref_ids as $ref_id)
346  {
347  $path = "";
348  $path_full = $tree->getPathFull($ref_id);
349  foreach($path_full as $idx => $data)
350  {
351  if($idx)
352  {
353  $path .= " &raquo; ";
354  }
355  if($ref_id != $data['ref_id'])
356  {
357  $path .= $data['title'];
358  }
359  else
360  {
361  $path .= ('<a target="_top" href="'.
362  ilLink::_getLink($data['ref_id'],$data['type']).'">'.
363  $data['title'].'</a>');
364  }
365 
366  }
367 
368  $result[] = $path;
369  }
370  return $result;
371  }
372 
378  public function confirmRemoveFromSystemObject($a_ids)
379  {
380  global $ilCtrl, $lng, $objDefinition, $tpl;
381  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
382 
383  if(!is_array($a_ids))
384  {
385  $a_ids = array($a_ids);
386  }
387 
388  $cgui = new ilConfirmationGUI();
389  $cgui->setFormAction($ilCtrl->getFormAction($this->parent_gui));
390  $cgui->setCancel($lng->txt("cancel"), "trash");
391  $cgui->setConfirm($lng->txt("confirm"), "removeFromSystem");
392  $cgui->setFormName("trash_confirmation");
393  $cgui->setHeaderText($lng->txt("info_delete_sure"));
394 
395  foreach($a_ids as $id)
396  {
397  $obj_id = ilObject::_lookupObjId($id);
398  $type = ilObject::_lookupType($obj_id);
399  $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'),$obj_id);
400  $alt = ($objDefinition->isPlugin($type))
401  ? $lng->txt("icon")." ".ilPlugin::lookupTxt("rep_robj", $type, "obj_".$type)
402  : $lng->txt("icon")." ".$lng->txt("obj_".$type);
403 
404  $cgui->addItem("trash_id[]", $id, $title,
405  ilObject::_getIcon($obj_id, "small", $type),
406  $alt);
407  }
408 
409  $tpl->setContent($cgui->getHTML());
410  }
411 }
412 ?>