• Main Page
  • Related Pages
  • 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-2001 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->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
00123                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00124                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00125 
00126                 $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
00127                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_new_folder"));
00128                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
00129                 $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE","");
00130                 $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","save");
00131                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
00132                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("save"));
00133                 $this->tpl->parseCurrentBlock();
00134 
00135         }
00136 
00137         function save()
00138         {
00139                 if(!strlen($_POST['title']))
00140                 {
00141                         sendInfo($this->lng->txt('search_enter_title'));
00142                         $this->create();
00143 
00144                         return false;
00145                 }
00146 
00147                 $this->folder_obj->create(ilUtil::stripslashes($_POST["title"]));
00148                 sendInfo($this->lng->txt('search_added_new_folder'));
00149                 $this->showResults();
00150 
00151                 return true;
00152         }
00153 
00154         function update()
00155         {
00156                 if(!strlen($_POST['title']))
00157                 {
00158                         sendInfo($this->lng->txt('search_enter_title'));
00159                         $this->showResults();
00160 
00161                         return false;
00162                 }
00163 
00164                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00165 
00166                 $tmp_obj = ilSearchItemFactory::getInstance($_SESSION['search_rename']);
00167                 $tmp_obj->updateTitle(ilUtil::stripslashes($_POST["title"]));
00168 
00169                 sendInfo($this->lng->txt("search_object_renamed"));
00170                 $this->showResults();
00171                 
00172                 return true;
00173         }               
00174 
00175 
00176         function showResults($a_confirm_delete = false)
00177         {
00178                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.search_results.html','Services/Search');
00179                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00180                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00181 
00182                 if($a_confirm_delete)
00183                 {
00184                         sendInfo($this->lng->txt("search_delete_sure"));
00185 
00186                         $this->tpl->setCurrentBlock("CONFIRM_DELETE");
00187                         $this->tpl->setVariable("TXT_DELETE_CANCEL",$this->lng->txt("cancel"));
00188                         $this->tpl->setVariable("TXT_DELETE_CONFIRM",$this->lng->txt("delete"));
00189                         $this->tpl->parseCurrentBlock();
00190                 }
00191 
00192                 $items = $this->folder_obj->getChilds();
00193                 if(count($items) or $this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
00194                 {
00195                         $counter = $this->__appendParentLink(count($items)) ? 0 : 1;
00196                         foreach($items as $item)
00197                         {
00198                                 if($item['type'] == 'seaf')
00199                                 {
00200                                         list($link,$target) = $this->__formatLink($item);
00201                                         $this->tpl->setCurrentBlock("folder");
00202                                         $this->tpl->setVariable("FOLDER_LINK",$link);
00203                                         $this->tpl->setVariable("FOLDER_TARGET",$target);
00204                                         $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle($item));
00205                                         $this->tpl->parseCurrentBlock();
00206                                         ++$counter;
00207                                 }
00208                                 else
00209                                 {
00210                                         include_once 'Services/Search/classes/class.ilSearchObjectListFactory.php';
00211                                         
00212                                         $item_data = unserialize(stripslashes($item['target']));
00213 
00214                                         $item_list_gui =& ilSearchObjectListFactory::_getInstance($item_data['type']);
00215                                         $item_list_gui->initItem($target['id'],ilObject::_lookupObjId($item_data['id']));
00216                                         $this->tpl->setCurrentBlock("link");
00217                                         $this->tpl->setVariable("HTML",$item_list_gui->getListItemHTML($item_data['id'],
00218                                                                                                                                                                    $id = ilObject::_lookupObjId($item_data['id']),
00219                                                                                                                                                                    ilObject::_lookupTitle($id),
00220                                                                                                                                                                    ilObject::_lookupDescription($id)));
00221                                                                                                                                                                                                                   
00222                                         $this->tpl->parseCurrentBlock();
00223                                 }
00224                                 $checked = (is_array($_POST["del_id"]) and in_array($item["obj_id"],$_POST["del_id"])) ? 1 : 0;
00225                                 $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
00226                                 $this->tpl->setVariable("CHECK",ilUtil::formCheckbox($checked,"del_id[]",$item["obj_id"]));
00227                                 $this->tpl->setVariable("ROWCOL",$counter % 2 ? "tblrow1" : "tblrow2");
00228                                 $this->tpl->parseCurrentBlock();
00229                         }
00230                         if(count($items))
00231                         {
00232                                 $this->tpl->setCurrentBlock("TBL_FOOTER");
00233                                 $this->tpl->setVariable("TBL_FOOTER_IMG_SRC",ilUtil::getImagePath("arrow_downright.gif"));
00234                                 $this->tpl->setVariable("TBL_FOOTER_SELECT",$this->__getActions());
00235                                 $this->tpl->setVariable("TBL_FOOTER_SUBMIT",$this->lng->txt("ok"));
00236                                 $this->tpl->parseCurrentBlock();
00237                         }
00238                 }
00239                 else
00240                 {
00241                         $this->tpl->setCurrentBlock("TBL_ROW_FOLDER");
00242                         $this->tpl->setVariable("TXT_NO_FOLDER",$this->lng->txt("search_no_results_saved"));
00243                         $this->tpl->parseCurrentBlock();
00244                 }
00245                 $this->tpl->setCurrentBlock("TBL_FOLDER");
00246                 $this->tpl->setVariable("COLSPAN",count($items) ? 2 : 1);
00247                 $this->tpl->setVariable("TXT_FOLDER_HEADER",$this->lng->txt("search_my_search_results"));
00248                 $this->tpl->setVariable("TXT_FOLDER_TITLE",$this->lng->txt("title"));
00249                 $this->tpl->parseCurrentBlock();
00250                 
00251         }
00252 
00253         function confirmDelete()
00254         {
00255                 if(!count($_POST["del_id"]))
00256                 {
00257                         sendInfo($this->lng->txt("search_no_selection"));
00258                         $this->showResults();
00259 
00260                         return false;
00261                 }
00262                 
00263                 $this->showResults(true);
00264 
00265                 return true;
00266         }
00267 
00268         function delete()
00269         {
00270                 foreach($_POST["del_id"] as $folder_id)
00271                 {
00272                         $this->folder_obj->delete($folder_id);
00273                 }
00274                 $this->message = $this->lng->txt("search_objects_deleted");
00275                 $this->showResults();
00276 
00277                 return true;
00278         }
00279 
00280         function rename()
00281         {
00282                 // NO ITEM SELECTED
00283                 if(!count($_POST["del_id"]))
00284                 {
00285                         sendInfo($this->lng->txt("search_select_exactly_one_object"));
00286                         $this->showResults();
00287 
00288                         return false;
00289                 }
00290                 // TOO MANY ITEMS SELECTED
00291                 if(count($_POST["del_id"]) > 1)
00292                 {
00293                         sendInfo($this->lng->txt("search_select_exactly_one_object"));
00294                         $this->showResults();
00295 
00296                         return false;
00297                 }
00298                 // GET OLD TITLE
00299                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00300 
00301                 $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
00302                 
00303                 if($tmp_obj->getType() == 'sea')
00304                 {
00305                         sendInfo($this->lng->txt("search_select_folder"));
00306                         $this->showResults();
00307 
00308                         return false;
00309                 }
00310 
00311                 // SHOW SEARCH ADMINISTRATION PAGE
00312                 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.search_results.html",'Services/Search');
00313                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00314                 $this->tpl->setVariable("SEARCH_ADMINISTRATION_ACTION",$this->ctrl->getFormAction($this));
00315                 
00316                 // GET OLD TITLE
00317                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00318 
00319                 $tmp_obj = ilSearchItemFactory::getInstance($_POST["del_id"][0]);
00320                 $this->__showRenameForm($tmp_obj->getTitle());
00321                 unset($tmp_obj);
00322 
00323                 // SET SESSION VARIABLE TO REMEMBER obj_id
00324                 $_SESSION["search_rename"] = $_POST["del_id"][0];
00325 
00326                 return true;
00327         }
00328 
00329         function moveItem()
00330         {
00331                 if(!count($_POST["del_id"]))
00332                 {
00333                         $this->showResults();
00334                         return false;
00335                 }
00336                 
00337                 include_once "Services/Search/classes/class.ilSearchItemFactory.php";
00338 
00339                 // CHECK IF MOVE ACTION IS POSSIBLE
00340                 foreach($_POST["del_id"] as $id)
00341                 {
00342                         $tmp_obj = ilSearchItemFactory::getInstance($id);
00343 
00344                         if($tmp_obj->getType() == "seaf")
00345                         {
00346                                 sendInfo($this->lng->txt("search_move_folders_not_allowed"));
00347                                 $this->showResults();
00348                                 return false;
00349                         }
00350                         $objects[] =& $tmp_obj;
00351                         unset($tmp_obj);
00352                 }
00353                 include_once "Services/Search/classes/class.ilUserResult.php";
00354 
00355                 $tmp_folder =& new ilSearchFolder($this->getUserId(),$_POST["action"]);
00356                 
00357                 // MOVE ITEMS
00358                 foreach($objects as $obj)
00359                 {
00360                         // COPY DATA
00361                         $search_res_obj =& new ilUserResult($this->getUserId());
00362                         $search_res_obj->setTitle($obj->getTitle());
00363                         $search_res_obj->setTarget(addslashes(serialize($obj->getTarget())));
00364                         
00365                         $tmp_folder->assignResult($search_res_obj);
00366 
00367                         // AND FINALLY:
00368                         $this->folder_obj->delete($obj->getObjId());
00369                         unset($search_res_obj);
00370                 }
00371                 unset($objects);
00372                 sendInfo($this->lng->txt("search_objects_moved"));
00373                 $this->showResults();
00374 
00375                 return true;
00376         }
00377 
00378 
00379 
00380         function prepareOutput()
00381         {
00382                 parent::prepareOutput();
00383                 
00384                 // SHOW ADD FOLDER
00385                 $this->tpl->setCurrentBlock("commands");
00386                 // possible subobjects
00387                 $opts = ilUtil::formSelect("", "new_type", array("folder"));
00388                 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00389                 $this->tpl->setVariable("BTN_NAME", "create");
00390                 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00391                 $this->tpl->parseCurrentBlock();
00392 
00393                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00394                 $this->tpl->setVariable("H_FORMACTION",$this->ctrl->getFormAction($this));
00395                 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('search_search_results'));
00396 
00397                 $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
00398 
00399                 $this->tpl->setCurrentBlock("tab");
00400                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00401                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
00402                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
00403                 $this->tpl->parseCurrentBlock();
00404 
00405                 $this->tpl->setCurrentBlock("tab");
00406                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00407                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('iladvancedsearchgui'));
00408                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
00409                 $this->tpl->parseCurrentBlock();
00410 
00411                 $this->tpl->setCurrentBlock("tab");
00412                 $this->tpl->setVariable("TAB_TYPE","tabactive");
00413                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00414                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
00415                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_search_results"));
00416                 $this->tpl->parseCurrentBlock();
00417 
00418                 // show top button if folder isn't root folder
00419                 if($this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
00420                 {
00421                         $this->tpl->setVariable("TXT_HEADER",$this->folder_obj->getTitle());
00422                         $this->tpl->setCurrentBlock("top");
00423                         $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00424                         $this->tpl->setVariable("LINK_TOP",$this->ctrl->getLinkTarget($this));
00425                         $this->tpl->setVariable("IMG_TOP",ilUtil::getImagePath("ic_top.gif"));
00426                         $this->tpl->parseCurrentBlock();
00427                 }
00428         }
00429 
00430         // PRIVATE
00431         function __initFolderObject()
00432         {
00433                 include_once 'Services/Search/classes/class.ilSearchFolder.php';
00434 
00435                 $this->folder_obj = new ilSearchFolder($this->getUserId(),(int) $_GET['folder_id']);
00436 
00437                 return true;
00438         }
00439 
00440         function __appendParentLink($nr_items)
00441         {
00442                 if($this->folder_obj->getFolderId() == $this->folder_obj->getRootId())
00443                 {
00444                         return false;
00445                 }
00446                 else
00447                 {
00448                         if($nr_items)
00449                         {
00450                                 $this->tpl->setVariable("CHECK","&nbsp;");
00451                         }
00452                         $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
00453                         $this->tpl->setVariable("ROWCOL","tblrow1");
00454 
00455                         list($link,$target) = $this->__formatLink(array("type" => "top"));
00456                         $this->tpl->setVariable("FOLDER_LINK",$link);
00457                         $this->tpl->setVariable("FOLDER_TARGET",$target);
00458                         $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle(array("type" => "top")));
00459                         $this->tpl->parseCurrentBlock();
00460                         return true;
00461                 }
00462         }
00463         function __formatTitle($a_item)
00464         {
00465                 switch($a_item["type"])
00466                 {
00467                         case "seaf":
00468                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00469                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00470                                 
00471                                 return $img.$a_item["title"];
00472 
00473                         case "sea":
00474                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00475                                         ilUtil::getImagePath("icon_bm.gif")."\">&nbsp;";
00476                                 
00477                                 return $img.$a_item["title"];
00478 
00479                         case "top":
00480                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00481                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00482 
00483                                 return $img."..";
00484                 }
00485         }
00486 
00487         function __formatLink($a_item)
00488         {
00489                 switch($a_item["type"])
00490                 {
00491                         case "seaf":
00492                                 $this->ctrl->setParameter($this,'folder_id',$a_item['obj_id']);
00493 
00494                                 return array($this->ctrl->getLinkTarget($this),'bottom');
00495 
00496                         case "sea":
00497                                 include_once "Services/Search/classes/class.ilUserResult.php";
00498 
00499                                 $tmp_obj =& new ilUserResult($this->getUserId(),$a_item["obj_id"]);
00500 
00501                                 $link = $tmp_obj->createLink();
00502                                 unset($tmp_obj);
00503 
00504                                 return $link;
00505                                 
00506                         case "top":
00507                                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00508                                 
00509                                 return array($this->ctrl->getLinkTarget($this),'bottom');
00510                 }
00511         }
00512         function __getActions()
00513         {
00514                 $options[0] = $this->lng->txt("search_select_one_action");
00515 
00516                 if($this->folder_obj->hasResults() and $this->folder_obj->countFolders())
00517                 {
00518                         // SHOW MOVE TO
00519                         $tree_data = $this->folder_obj->getTree();
00520 
00521                         foreach($tree_data as $node)
00522                         {
00523                                 $prefix = $this->lng->txt("search_move_to") ;
00524                                 for($i = 0; $i < $node["depth"];++$i)
00525                                 {
00526                                         $prefix .= "&nbsp;&nbsp;";
00527                                 }
00528                                 if($node["obj_id"] == $this->folder_obj->getRootId())
00529                                 {
00530                                         $options[$node["obj_id"]] = $prefix.$this->lng->txt("search_search_results");
00531                                 }
00532                                 else
00533                                 {
00534                                         $options[$node["obj_id"]] = $prefix.$node["title"];
00535                                 }
00536 
00537                         }                       
00538 
00539                 }
00540                 // SHOW RENAME
00541                 $options["rename"] = $this->lng->txt("rename");
00542 
00543                 // SHOW DELETE
00544                 $options["confirmDelete"] = $this->lng->txt("delete");
00545 
00546                 return ilUtil::formSelect($_POST["action"],"action",$options,false,true);
00547         }
00548 
00549         function __showRenameForm($a_old_title)
00550         {
00551                 $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
00552                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_rename_title"));
00553                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
00554                 $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE",$a_old_title);
00555                 $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","update");
00556                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
00557                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("rename"));
00558                 $this->tpl->parseCurrentBlock();
00559         }
00560 
00561 
00562 
00563 
00564 }
00565 ?>

Generated on Fri Dec 13 2013 10:18:31 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1