ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchResultGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 include_once 'Services/Search/classes/class.ilSearchBaseGUI.php';
36 
38 {
39  /*
40  * Id of current user
41  */
42  var $user_id;
43 
48  function ilSearchResultGUI()
49  {
50  global $ilUser;
51 
52 
54 
55  $this->setUserId($ilUser->getId());
56 
57  $this->__initFolderObject();
58  $this->ctrl->saveParameter($this,'folder_id');
59  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
60 
61  }
62  // SET/GET
63  function setUserId($a_user_id)
64  {
65  $this->user_id = $a_user_id;
66  }
67  function getUserId()
68  {
69  return $this->user_id;
70  }
71 
72 
77  function &executeCommand()
78  {
79  global $rbacsystem;
80 
81  $next_class = $this->ctrl->getNextClass($this);
82  $cmd = $this->ctrl->getCmd();
83 
84  switch($next_class)
85  {
86  default:
87  if($cmd == 'gateway')
88  {
89  if($_POST['action'] and is_numeric($_POST['action']))
90  {
91  $this->prepareOutput();
92  $this->moveItem();
93 
94  return true;
95  }
96  $cmd = $_POST['action'];
97  }
98  if(!$cmd)
99  {
100  $cmd = "showResults";
101  }
102 
103  $this->prepareOutput();
104  $this->$cmd();
105  break;
106  }
107  return true;
108  }
109 
110  function cancel()
111  {
112  unset($_POST['del_id']);
113  unset($_SESSION['search_rename']);
114  $this->showResults();
115 
116  return true;
117  }
118 
119  function create()
120  {
121  // SHOW SEARCH ADMINISTRATION PAGE
122  $this->setLocator();
123  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
124  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
125  $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
126 
127  $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
128  $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_new_folder"));
129  $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
130  $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE","");
131  $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","save");
132  $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
133  $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("save"));
134  $this->tpl->parseCurrentBlock();
135 
136  }
137 
138  function save()
139  {
140  if(!strlen($_POST['title']))
141  {
142  ilUtil::sendInfo($this->lng->txt('search_enter_title'));
143  $this->create();
144 
145  return false;
146  }
147 
148  $this->folder_obj->create(ilUtil::stripslashes($_POST["title"]));
149  ilUtil::sendInfo($this->lng->txt('search_added_new_folder'));
150  $this->showResults();
151 
152  return true;
153  }
154 
155  function update()
156  {
157  if(!strlen($_POST['title']))
158  {
159  ilUtil::sendInfo($this->lng->txt('search_enter_title'));
160  $this->showResults();
161 
162  return false;
163  }
164 
165  include_once "Services/Search/classes/class.ilSearchItemFactory.php";
166 
167  $tmp_obj = ilSearchItemFactory::getInstance($_SESSION['search_rename']);
168  $tmp_obj->updateTitle(ilUtil::stripslashes($_POST["title"]));
169 
170  ilUtil::sendInfo($this->lng->txt("search_object_renamed"));
171  $this->showResults();
172 
173  return true;
174  }
175 
176 
177  function showResults($a_confirm_delete = false)
178  {
179  $this->setLocator();
180  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.search_results.html','Services/Search');
181  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
182  $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
183 
184  if($a_confirm_delete)
185  {
186  ilUtil::sendInfo($this->lng->txt("search_delete_sure"));
187 
188  $this->tpl->setCurrentBlock("CONFIRM_DELETE");
189  $this->tpl->setVariable("TXT_DELETE_CANCEL",$this->lng->txt("cancel"));
190  $this->tpl->setVariable("TXT_DELETE_CONFIRM",$this->lng->txt("delete"));
191  $this->tpl->parseCurrentBlock();
192  }
193 
194  $items = $this->folder_obj->getChilds();
195  if(count($items) or $this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
196  {
197  $counter = $this->__appendParentLink(count($items)) ? 0 : 1;
198  foreach($items as $item)
199  {
200  if($item['type'] == 'seaf')
201  {
202  list($link,$target) = $this->__formatLink($item);
203  $this->tpl->setCurrentBlock("folder");
204  $this->tpl->setVariable("FOLDER_LINK",$link);
205  $this->tpl->setVariable("FOLDER_TARGET",$target);
206  $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle($item));
207  $this->tpl->parseCurrentBlock();
208  ++$counter;
209  }
210  else
211  {
212  include_once 'Services/Search/classes/class.ilSearchObjectListFactory.php';
213 
214  $item_data = unserialize(stripslashes($item['target']));
215 
216  $item_list_gui =& ilSearchObjectListFactory::_getInstance($item_data['type']);
217  $item_list_gui->initItem($target['id'],ilObject::_lookupObjId($item_data['id']));
218  $this->tpl->setCurrentBlock("link");
219  $this->tpl->setVariable("HTML",$item_list_gui->getListItemHTML($item_data['id'],
220  $id = ilObject::_lookupObjId($item_data['id']),
223 
224  $this->tpl->parseCurrentBlock();
225  }
226  $checked = (is_array($_POST["del_id"]) and in_array($item["obj_id"],$_POST["del_id"])) ? 1 : 0;
227  $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
228  $this->tpl->setVariable("CHECK",ilUtil::formCheckbox($checked,"del_id[]",$item["obj_id"]));
229  $this->tpl->setVariable("ROWCOL",$counter % 2 ? "tblrow1" : "tblrow2");
230  $this->tpl->parseCurrentBlock();
231  }
232  if(count($items))
233  {
234  $this->tpl->setCurrentBlock("TBL_FOOTER");
235  $this->tpl->setVariable("TBL_FOOTER_IMG_SRC",ilUtil::getImagePath("arrow_downright.gif"));
236  $this->tpl->setVariable("TBL_FOOTER_SELECT",$this->__getActions());
237  $this->tpl->setVariable("TBL_FOOTER_SUBMIT",$this->lng->txt("ok"));
238  $this->tpl->parseCurrentBlock();
239  }
240  }
241  else
242  {
243  $this->tpl->setCurrentBlock("TBL_ROW_FOLDER");
244  $this->tpl->setVariable("TXT_NO_FOLDER",$this->lng->txt("search_no_results_saved"));
245  $this->tpl->parseCurrentBlock();
246  }
247  $this->tpl->setCurrentBlock("TBL_FOLDER");
248  $this->tpl->setVariable("COLSPAN",count($items) ? 2 : 1);
249  $this->tpl->setVariable("TXT_FOLDER_HEADER",$this->lng->txt("search_my_search_results"));
250  $this->tpl->setVariable("TXT_FOLDER_TITLE",$this->lng->txt("title"));
251  $this->tpl->parseCurrentBlock();
252 
253  }
254 
255  function confirmDelete()
256  {
257  if(!count($_POST["del_id"]))
258  {
259  ilUtil::sendInfo($this->lng->txt("search_no_selection"));
260  $this->showResults();
261 
262  return false;
263  }
264 
265  $this->showResults(true);
266 
267  return true;
268  }
269 
270  function delete()
271  {
272  foreach($_POST["del_id"] as $folder_id)
273  {
274  $this->folder_obj->delete($folder_id);
275  }
276  $this->message = $this->lng->txt("search_objects_deleted");
277  $this->showResults();
278 
279  return true;
280  }
281 
282  function setLocator()
283  {
284  global $ilLocator;
285 
286 return;
287  $ilLocator->addItem($this->lng->txt('search_search_results'),
288  $this->ctrl->getLinkTarget($this));
289  $this->tpl->setLocator();
290  }
291 
292  function rename()
293  {
294  // NO ITEM SELECTED
295  if(!count($_POST["del_id"]))
296  {
297  ilUtil::sendInfo($this->lng->txt("search_select_exactly_one_object"));
298  $this->showResults();
299 
300  return false;
301  }
302  // TOO MANY ITEMS SELECTED
303  if(count($_POST["del_id"]) > 1)
304  {
305  ilUtil::sendInfo($this->lng->txt("search_select_exactly_one_object"));
306  $this->showResults();
307 
308  return false;
309  }
310  // GET OLD TITLE
311  include_once "Services/Search/classes/class.ilSearchItemFactory.php";
312 
313  $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
314 
315  if($tmp_obj->getType() == 'sea')
316  {
317  ilUtil::sendInfo($this->lng->txt("search_select_folder"));
318  $this->showResults();
319 
320  return false;
321  }
322 
323  // SHOW SEARCH ADMINISTRATION PAGE
324  $this->setLocator();
325  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
326  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
327  $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
328 
329  // GET OLD TITLE
330  include_once "Services/Search/classes/class.ilSearchItemFactory.php";
331 
332  $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
333  $this->__showRenameForm($tmp_obj->getTitle());
334  unset($tmp_obj);
335 
336  // SET SESSION VARIABLE TO REMEMBER obj_id
337  $_SESSION["search_rename"] = $_POST["del_id"][0];
338 
339  return true;
340  }
341 
342  function moveItem()
343  {
344  if(!count($_POST["del_id"]))
345  {
346  $this->showResults();
347  return false;
348  }
349 
350  include_once "Services/Search/classes/class.ilSearchItemFactory.php";
351 
352  // CHECK IF MOVE ACTION IS POSSIBLE
353  foreach($_POST["del_id"] as $id)
354  {
355  $tmp_obj = ilSearchItemFactory::getInstance($id);
356 
357  if($tmp_obj->getType() == "seaf")
358  {
359  ilUtil::sendInfo($this->lng->txt("search_move_folders_not_allowed"));
360  $this->showResults();
361  return false;
362  }
363  $objects[] =& $tmp_obj;
364  unset($tmp_obj);
365  }
366  include_once "Services/Search/classes/class.ilUserResult.php";
367 
368  $tmp_folder =& new ilSearchFolder($this->getUserId(),$_POST["action"]);
369 
370  // MOVE ITEMS
371  foreach($objects as $obj)
372  {
373  // COPY DATA
374  $search_res_obj =& new ilUserResult($this->getUserId());
375  $search_res_obj->setTitle($obj->getTitle());
376  $search_res_obj->setTarget(addslashes(serialize($obj->getTarget())));
377 
378  $tmp_folder->assignResult($search_res_obj);
379 
380  // AND FINALLY:
381  $this->folder_obj->delete($obj->getObjId());
382  unset($search_res_obj);
383  }
384  unset($objects);
385  ilUtil::sendInfo($this->lng->txt("search_objects_moved"));
386  $this->showResults();
387 
388  return true;
389  }
390 
391 
392 
393  function prepareOutput()
394  {
396 
397  // SHOW ADD FOLDER
398  $this->tpl->setCurrentBlock("add_commands");
399  // possible subobjects
400  $opts = ilUtil::formSelect("", "new_type", array("folder"));
401  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
402  $this->tpl->setVariable("BTN_NAME", "create");
403  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
404  $this->tpl->setVariable("H_FORMACTION",$this->ctrl->getFormAction($this));
405  $this->tpl->parseCurrentBlock();
406 
407  $this->tpl->setCurrentBlock("header_image");
408  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_src_b.gif"));
409  $this->tpl->parseCurrentBlock();
410 
411  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
412  $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('search_search_results'));
413 
414  $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
415 
416  $this->tpl->setCurrentBlock("tab");
417  $this->tpl->setVariable("TAB_TYPE","tabinactive");
418  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
419  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
420  $this->tpl->parseCurrentBlock();
421 
422  $this->tpl->setCurrentBlock("tab");
423  $this->tpl->setVariable("TAB_TYPE","tabinactive");
424  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('iladvancedsearchgui'));
425  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
426  $this->tpl->parseCurrentBlock();
427 
428  $this->tpl->setCurrentBlock("tab");
429  $this->tpl->setVariable("TAB_TYPE","tabactive");
430  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
431  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
432  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_search_results"));
433  $this->tpl->parseCurrentBlock();
434 
435  // show top button if folder isn't root folder
436  if($this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
437  {
438  $this->tpl->setVariable("TXT_HEADER",$this->folder_obj->getTitle());
439  $this->tpl->setCurrentBlock("top");
440  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
441  $this->tpl->setVariable("LINK_TOP",$this->ctrl->getLinkTarget($this));
442  $this->tpl->setVariable("IMG_TOP",ilUtil::getImagePath("ic_top.gif"));
443  $this->tpl->parseCurrentBlock();
444  }
445  }
446 
447  // PRIVATE
449  {
450  include_once 'Services/Search/classes/class.ilSearchFolder.php';
451 
452  $this->folder_obj = new ilSearchFolder($this->getUserId(),(int) $_GET['folder_id']);
453 
454  return true;
455  }
456 
457  function __appendParentLink($nr_items)
458  {
459  if($this->folder_obj->getFolderId() == $this->folder_obj->getRootId())
460  {
461  return false;
462  }
463  else
464  {
465  if($nr_items)
466  {
467  $this->tpl->setVariable("CHECK","&nbsp;");
468  }
469  $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
470  $this->tpl->setVariable("ROWCOL","tblrow1");
471 
472  list($link,$target) = $this->__formatLink(array("type" => "top"));
473  $this->tpl->setVariable("FOLDER_LINK",$link);
474  $this->tpl->setVariable("FOLDER_TARGET",$target);
475  $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle(array("type" => "top")));
476  $this->tpl->parseCurrentBlock();
477  return true;
478  }
479  }
480  function __formatTitle($a_item)
481  {
482  switch($a_item["type"])
483  {
484  case "seaf":
485  $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
486  ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
487 
488  return $img.$a_item["title"];
489 
490  case "sea":
491  $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
492  ilUtil::getImagePath("icon_bm.gif")."\">&nbsp;";
493 
494  return $img.$a_item["title"];
495 
496  case "top":
497  $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
498  ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
499 
500  return $img."..";
501  }
502  }
503 
504  function __formatLink($a_item)
505  {
506  switch($a_item["type"])
507  {
508  case "seaf":
509  $this->ctrl->setParameter($this,'folder_id',$a_item['obj_id']);
510 
511  return array($this->ctrl->getLinkTarget($this),
512  ilFrameTargetInfo::_getFrame("MainContent"));
513 
514  case "sea":
515  include_once "Services/Search/classes/class.ilUserResult.php";
516 
517  $tmp_obj =& new ilUserResult($this->getUserId(),$a_item["obj_id"]);
518 
519  $link = $tmp_obj->createLink();
520  unset($tmp_obj);
521 
522  return $link;
523 
524  case "top":
525  $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
526 
527  return array($this->ctrl->getLinkTarget($this),
528  ilFrameTargetInfo::_getFrame("MainContent"));
529  }
530  }
531  function __getActions()
532  {
533  $options[0] = $this->lng->txt("search_select_one_action");
534 
535  if($this->folder_obj->hasResults() and $this->folder_obj->countFolders())
536  {
537  // SHOW MOVE TO
538  $tree_data = $this->folder_obj->getTree();
539 
540  foreach($tree_data as $node)
541  {
542  $prefix = $this->lng->txt("search_move_to") ;
543  for($i = 0; $i < $node["depth"];++$i)
544  {
545  $prefix .= "&nbsp;&nbsp;";
546  }
547  if($node["obj_id"] == $this->folder_obj->getRootId())
548  {
549  $options[$node["obj_id"]] = $prefix.$this->lng->txt("search_search_results");
550  }
551  else
552  {
553  $options[$node["obj_id"]] = $prefix.$node["title"];
554  }
555 
556  }
557 
558  }
559  // SHOW RENAME
560  $options["rename"] = $this->lng->txt("rename");
561 
562  // SHOW DELETE
563  $options["confirmDelete"] = $this->lng->txt("delete");
564 
565  return ilUtil::formSelect($_POST["action"],"action",$options,false,true);
566  }
567 
568  function __showRenameForm($a_old_title)
569  {
570  $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
571  $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_rename_title"));
572  $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
573  $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE",$a_old_title);
574  $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","update");
575  $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
576  $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("rename"));
577  $this->tpl->parseCurrentBlock();
578  }
579 
580 
581 
582 
583 }
584 ?>