• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Search/classes/class.ilSearchResultGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00035 include_once 'Services/Search/classes/class.ilSearchBaseGUI.php';
00036 
00037 class ilSearchresultGUI extends ilSearchBaseGUI
00038 {
00039         /*
00040          * Id of current user
00041          */
00042         var $user_id;
00043 
00048         function ilSearchResultGUI()
00049         {
00050                 global $ilUser;
00051 
00052 
00053                 parent::ilSearchBaseGUI();
00054 
00055                 $this->setUserId($ilUser->getId());
00056 
00057                 $this->__initFolderObject();
00058                 $this->ctrl->saveParameter($this,'folder_id');
00059                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00060 
00061         }
00062         // SET/GET
00063         function setUserId($a_user_id)
00064         {
00065                 $this->user_id = $a_user_id;
00066         }
00067         function getUserId()
00068         {
00069                 return $this->user_id;
00070         }
00071 
00072 
00077         function &executeCommand()
00078         {
00079                 global $rbacsystem;
00080 
00081                 $next_class = $this->ctrl->getNextClass($this);
00082                 $cmd = $this->ctrl->getCmd();
00083 
00084                 switch($next_class)
00085                 {
00086                         default:
00087                                 if($cmd == 'gateway')
00088                                 {
00089                                         if($_POST['action'] and is_numeric($_POST['action']))
00090                                         {
00091                                                 $this->prepareOutput();
00092                                                 $this->moveItem();
00093                                                 
00094                                                 return true;
00095                                         }
00096                                         $cmd = $_POST['action'];
00097                                 }
00098                                 if(!$cmd)
00099                                 {
00100                                         $cmd = "showResults";
00101                                 }
00102 
00103                                 $this->prepareOutput();
00104                                 $this->$cmd();
00105                                 break;
00106                 }
00107                 return true;
00108         }
00109 
00110         function cancel()
00111         {
00112                 unset($_POST['del_id']);
00113                 unset($_SESSION['search_rename']);
00114                 $this->showResults();
00115 
00116                 return true;
00117         }
00118 
00119         function create()
00120         {
00121                 // SHOW SEARCH ADMINISTRATION PAGE
00122                 $this->setLocator();
00123                 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
00124                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00125                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00126 
00127                 $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
00128                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_new_folder"));
00129                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
00130                 $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE","");
00131                 $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","save");
00132                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
00133                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("save"));
00134                 $this->tpl->parseCurrentBlock();
00135 
00136         }
00137 
00138         function save()
00139         {
00140                 if(!strlen($_POST['title']))
00141                 {
00142                         ilUtil::sendInfo($this->lng->txt('search_enter_title'));
00143                         $this->create();
00144 
00145                         return false;
00146                 }
00147 
00148                 $this->folder_obj->create(ilUtil::stripslashes($_POST["title"]));
00149                 ilUtil::sendInfo($this->lng->txt('search_added_new_folder'));
00150                 $this->showResults();
00151 
00152                 return true;
00153         }
00154 
00155         function update()
00156         {
00157                 if(!strlen($_POST['title']))
00158                 {
00159                         ilUtil::sendInfo($this->lng->txt('search_enter_title'));
00160                         $this->showResults();
00161 
00162                         return false;
00163                 }
00164 
00165                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00166 
00167                 $tmp_obj = ilSearchItemFactory::getInstance($_SESSION['search_rename']);
00168                 $tmp_obj->updateTitle(ilUtil::stripslashes($_POST["title"]));
00169 
00170                 ilUtil::sendInfo($this->lng->txt("search_object_renamed"));
00171                 $this->showResults();
00172                 
00173                 return true;
00174         }               
00175 
00176 
00177         function showResults($a_confirm_delete = false)
00178         {
00179                 $this->setLocator();
00180                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.search_results.html','Services/Search');
00181                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00182                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00183 
00184                 if($a_confirm_delete)
00185                 {
00186                         ilUtil::sendInfo($this->lng->txt("search_delete_sure"));
00187 
00188                         $this->tpl->setCurrentBlock("CONFIRM_DELETE");
00189                         $this->tpl->setVariable("TXT_DELETE_CANCEL",$this->lng->txt("cancel"));
00190                         $this->tpl->setVariable("TXT_DELETE_CONFIRM",$this->lng->txt("delete"));
00191                         $this->tpl->parseCurrentBlock();
00192                 }
00193 
00194                 $items = $this->folder_obj->getChilds();
00195                 if(count($items) or $this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
00196                 {
00197                         $counter = $this->__appendParentLink(count($items)) ? 0 : 1;
00198                         foreach($items as $item)
00199                         {
00200                                 if($item['type'] == 'seaf')
00201                                 {
00202                                         list($link,$target) = $this->__formatLink($item);
00203                                         $this->tpl->setCurrentBlock("folder");
00204                                         $this->tpl->setVariable("FOLDER_LINK",$link);
00205                                         $this->tpl->setVariable("FOLDER_TARGET",$target);
00206                                         $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle($item));
00207                                         $this->tpl->parseCurrentBlock();
00208                                         ++$counter;
00209                                 }
00210                                 else
00211                                 {
00212                                         include_once 'Services/Search/classes/class.ilSearchObjectListFactory.php';
00213                                         
00214                                         $item_data = unserialize(stripslashes($item['target']));
00215 
00216                                         $item_list_gui =& ilSearchObjectListFactory::_getInstance($item_data['type']);
00217                                         $item_list_gui->initItem($target['id'],ilObject::_lookupObjId($item_data['id']));
00218                                         $this->tpl->setCurrentBlock("link");
00219                                         $this->tpl->setVariable("HTML",$item_list_gui->getListItemHTML($item_data['id'],
00220                                                                                                                                                                    $id = ilObject::_lookupObjId($item_data['id']),
00221                                                                                                                                                                    ilObject::_lookupTitle($id),
00222                                                                                                                                                                    ilObject::_lookupDescription($id)));
00223                                                                                                                                                                                                                   
00224                                         $this->tpl->parseCurrentBlock();
00225                                 }
00226                                 $checked = (is_array($_POST["del_id"]) and in_array($item["obj_id"],$_POST["del_id"])) ? 1 : 0;
00227                                 $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
00228                                 $this->tpl->setVariable("CHECK",ilUtil::formCheckbox($checked,"del_id[]",$item["obj_id"]));
00229                                 $this->tpl->setVariable("ROWCOL",$counter % 2 ? "tblrow1" : "tblrow2");
00230                                 $this->tpl->parseCurrentBlock();
00231                         }
00232                         if(count($items))
00233                         {
00234                                 $this->tpl->setCurrentBlock("TBL_FOOTER");
00235                                 $this->tpl->setVariable("TBL_FOOTER_IMG_SRC",ilUtil::getImagePath("arrow_downright.gif"));
00236                                 $this->tpl->setVariable("TBL_FOOTER_SELECT",$this->__getActions());
00237                                 $this->tpl->setVariable("TBL_FOOTER_SUBMIT",$this->lng->txt("ok"));
00238                                 $this->tpl->parseCurrentBlock();
00239                         }
00240                 }
00241                 else
00242                 {
00243                         $this->tpl->setCurrentBlock("TBL_ROW_FOLDER");
00244                         $this->tpl->setVariable("TXT_NO_FOLDER",$this->lng->txt("search_no_results_saved"));
00245                         $this->tpl->parseCurrentBlock();
00246                 }
00247                 $this->tpl->setCurrentBlock("TBL_FOLDER");
00248                 $this->tpl->setVariable("COLSPAN",count($items) ? 2 : 1);
00249                 $this->tpl->setVariable("TXT_FOLDER_HEADER",$this->lng->txt("search_my_search_results"));
00250                 $this->tpl->setVariable("TXT_FOLDER_TITLE",$this->lng->txt("title"));
00251                 $this->tpl->parseCurrentBlock();
00252                 
00253         }
00254 
00255         function confirmDelete()
00256         {
00257                 if(!count($_POST["del_id"]))
00258                 {
00259                         ilUtil::sendInfo($this->lng->txt("search_no_selection"));
00260                         $this->showResults();
00261 
00262                         return false;
00263                 }
00264                 
00265                 $this->showResults(true);
00266 
00267                 return true;
00268         }
00269 
00270         function delete()
00271         {
00272                 foreach($_POST["del_id"] as $folder_id)
00273                 {
00274                         $this->folder_obj->delete($folder_id);
00275                 }
00276                 $this->message = $this->lng->txt("search_objects_deleted");
00277                 $this->showResults();
00278 
00279                 return true;
00280         }
00281 
00282         function setLocator()
00283         {
00284                 global $ilLocator;
00285                 
00286 return;
00287                 $ilLocator->addItem($this->lng->txt('search_search_results'),
00288                         $this->ctrl->getLinkTarget($this));
00289                 $this->tpl->setLocator();
00290         }
00291 
00292         function rename()
00293         {
00294                 // NO ITEM SELECTED
00295                 if(!count($_POST["del_id"]))
00296                 {
00297                         ilUtil::sendInfo($this->lng->txt("search_select_exactly_one_object"));
00298                         $this->showResults();
00299 
00300                         return false;
00301                 }
00302                 // TOO MANY ITEMS SELECTED
00303                 if(count($_POST["del_id"]) > 1)
00304                 {
00305                         ilUtil::sendInfo($this->lng->txt("search_select_exactly_one_object"));
00306                         $this->showResults();
00307 
00308                         return false;
00309                 }
00310                 // GET OLD TITLE
00311                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00312 
00313                 $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
00314                 
00315                 if($tmp_obj->getType() == 'sea')
00316                 {
00317                         ilUtil::sendInfo($this->lng->txt("search_select_folder"));
00318                         $this->showResults();
00319 
00320                         return false;
00321                 }
00322 
00323                 // SHOW SEARCH ADMINISTRATION PAGE
00324                 $this->setLocator();
00325                 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
00326                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00327                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00328                 
00329                 // GET OLD TITLE
00330                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00331 
00332                 $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
00333                 $this->__showRenameForm($tmp_obj->getTitle());
00334                 unset($tmp_obj);
00335 
00336                 // SET SESSION VARIABLE TO REMEMBER obj_id
00337                 $_SESSION["search_rename"] = $_POST["del_id"][0];
00338 
00339                 return true;
00340         }
00341 
00342         function moveItem()
00343         {
00344                 if(!count($_POST["del_id"]))
00345                 {
00346                         $this->showResults();
00347                         return false;
00348                 }
00349                 
00350                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00351 
00352                 // CHECK IF MOVE ACTION IS POSSIBLE
00353                 foreach($_POST["del_id"] as $id)
00354                 {
00355                         $tmp_obj = ilSearchItemFactory::getInstance($id);
00356 
00357                         if($tmp_obj->getType() == "seaf")
00358                         {
00359                                 ilUtil::sendInfo($this->lng->txt("search_move_folders_not_allowed"));
00360                                 $this->showResults();
00361                                 return false;
00362                         }
00363                         $objects[] =& $tmp_obj;
00364                         unset($tmp_obj);
00365                 }
00366                 include_once "Services/Search/classes/class.ilUserResult.php";
00367 
00368                 $tmp_folder =& new ilSearchFolder($this->getUserId(),$_POST["action"]);
00369                 
00370                 // MOVE ITEMS
00371                 foreach($objects as $obj)
00372                 {
00373                         // COPY DATA
00374                         $search_res_obj =& new ilUserResult($this->getUserId());
00375                         $search_res_obj->setTitle($obj->getTitle());
00376                         $search_res_obj->setTarget(addslashes(serialize($obj->getTarget())));
00377                         
00378                         $tmp_folder->assignResult($search_res_obj);
00379 
00380                         // AND FINALLY:
00381                         $this->folder_obj->delete($obj->getObjId());
00382                         unset($search_res_obj);
00383                 }
00384                 unset($objects);
00385                 ilUtil::sendInfo($this->lng->txt("search_objects_moved"));
00386                 $this->showResults();
00387 
00388                 return true;
00389         }
00390 
00391 
00392 
00393         function prepareOutput()
00394         {
00395                 parent::prepareOutput();
00396                 
00397                 // SHOW ADD FOLDER
00398                 $this->tpl->setCurrentBlock("add_commands");
00399                 // possible subobjects
00400                 $opts = ilUtil::formSelect("", "new_type", array("folder"));
00401                 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00402                 $this->tpl->setVariable("BTN_NAME", "create");
00403                 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00404                 $this->tpl->setVariable("H_FORMACTION",$this->ctrl->getFormAction($this));
00405                 $this->tpl->parseCurrentBlock();
00406 
00407                 $this->tpl->setCurrentBlock("header_image");
00408                 $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_src_b.gif"));
00409                 $this->tpl->parseCurrentBlock();
00410 
00411                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00412                 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('search_search_results'));
00413 
00414                 $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
00415 
00416                 $this->tpl->setCurrentBlock("tab");
00417                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00418                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
00419                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
00420                 $this->tpl->parseCurrentBlock();
00421 
00422                 $this->tpl->setCurrentBlock("tab");
00423                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00424                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('iladvancedsearchgui'));
00425                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
00426                 $this->tpl->parseCurrentBlock();
00427 
00428                 $this->tpl->setCurrentBlock("tab");
00429                 $this->tpl->setVariable("TAB_TYPE","tabactive");
00430                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00431                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
00432                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_search_results"));
00433                 $this->tpl->parseCurrentBlock();
00434 
00435                 // show top button if folder isn't root folder
00436                 if($this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
00437                 {
00438                         $this->tpl->setVariable("TXT_HEADER",$this->folder_obj->getTitle());
00439                         $this->tpl->setCurrentBlock("top");
00440                         $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00441                         $this->tpl->setVariable("LINK_TOP",$this->ctrl->getLinkTarget($this));
00442                         $this->tpl->setVariable("IMG_TOP",ilUtil::getImagePath("ic_top.gif"));
00443                         $this->tpl->parseCurrentBlock();
00444                 }
00445         }
00446 
00447         // PRIVATE
00448         function __initFolderObject()
00449         {
00450                 include_once 'Services/Search/classes/class.ilSearchFolder.php';
00451 
00452                 $this->folder_obj = new ilSearchFolder($this->getUserId(),(int) $_GET['folder_id']);
00453 
00454                 return true;
00455         }
00456 
00457         function __appendParentLink($nr_items)
00458         {
00459                 if($this->folder_obj->getFolderId() == $this->folder_obj->getRootId())
00460                 {
00461                         return false;
00462                 }
00463                 else
00464                 {
00465                         if($nr_items)
00466                         {
00467                                 $this->tpl->setVariable("CHECK","&nbsp;");
00468                         }
00469                         $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
00470                         $this->tpl->setVariable("ROWCOL","tblrow1");
00471 
00472                         list($link,$target) = $this->__formatLink(array("type" => "top"));
00473                         $this->tpl->setVariable("FOLDER_LINK",$link);
00474                         $this->tpl->setVariable("FOLDER_TARGET",$target);
00475                         $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle(array("type" => "top")));
00476                         $this->tpl->parseCurrentBlock();
00477                         return true;
00478                 }
00479         }
00480         function __formatTitle($a_item)
00481         {
00482                 switch($a_item["type"])
00483                 {
00484                         case "seaf":
00485                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00486                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00487                                 
00488                                 return $img.$a_item["title"];
00489 
00490                         case "sea":
00491                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00492                                         ilUtil::getImagePath("icon_bm.gif")."\">&nbsp;";
00493                                 
00494                                 return $img.$a_item["title"];
00495 
00496                         case "top":
00497                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00498                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00499 
00500                                 return $img."..";
00501                 }
00502         }
00503 
00504         function __formatLink($a_item)
00505         {
00506                 switch($a_item["type"])
00507                 {
00508                         case "seaf":
00509                                 $this->ctrl->setParameter($this,'folder_id',$a_item['obj_id']);
00510 
00511                                 return array($this->ctrl->getLinkTarget($this),
00512                                         ilFrameTargetInfo::_getFrame("MainContent"));
00513 
00514                         case "sea":
00515                                 include_once "Services/Search/classes/class.ilUserResult.php";
00516 
00517                                 $tmp_obj =& new ilUserResult($this->getUserId(),$a_item["obj_id"]);
00518 
00519                                 $link = $tmp_obj->createLink();
00520                                 unset($tmp_obj);
00521 
00522                                 return $link;
00523                                 
00524                         case "top":
00525                                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00526                                 
00527                                 return array($this->ctrl->getLinkTarget($this),
00528                                         ilFrameTargetInfo::_getFrame("MainContent"));
00529                 }
00530         }
00531         function __getActions()
00532         {
00533                 $options[0] = $this->lng->txt("search_select_one_action");
00534 
00535                 if($this->folder_obj->hasResults() and $this->folder_obj->countFolders())
00536                 {
00537                         // SHOW MOVE TO
00538                         $tree_data = $this->folder_obj->getTree();
00539 
00540                         foreach($tree_data as $node)
00541                         {
00542                                 $prefix = $this->lng->txt("search_move_to") ;
00543                                 for($i = 0; $i < $node["depth"];++$i)
00544                                 {
00545                                         $prefix .= "&nbsp;&nbsp;";
00546                                 }
00547                                 if($node["obj_id"] == $this->folder_obj->getRootId())
00548                                 {
00549                                         $options[$node["obj_id"]] = $prefix.$this->lng->txt("search_search_results");
00550                                 }
00551                                 else
00552                                 {
00553                                         $options[$node["obj_id"]] = $prefix.$node["title"];
00554                                 }
00555 
00556                         }                       
00557 
00558                 }
00559                 // SHOW RENAME
00560                 $options["rename"] = $this->lng->txt("rename");
00561 
00562                 // SHOW DELETE
00563                 $options["confirmDelete"] = $this->lng->txt("delete");
00564 
00565                 return ilUtil::formSelect($_POST["action"],"action",$options,false,true);
00566         }
00567 
00568         function __showRenameForm($a_old_title)
00569         {
00570                 $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
00571                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_rename_title"));
00572                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
00573                 $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE",$a_old_title);
00574                 $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","update");
00575                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
00576                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("rename"));
00577                 $this->tpl->parseCurrentBlock();
00578         }
00579 
00580 
00581 
00582 
00583 }
00584 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1