• 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("add_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->setVariable("H_FORMACTION",$this->ctrl->getFormAction($this));
00392                 $this->tpl->parseCurrentBlock();
00393 
00394                 $this->tpl->setCurrentBlock("header_image");
00395                 $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_src_b.gif"));
00396                 $this->tpl->parseCurrentBlock();
00397 
00398                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00399                 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('search_search_results'));
00400 
00401                 $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
00402 
00403                 $this->tpl->setCurrentBlock("tab");
00404                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00405                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
00406                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
00407                 $this->tpl->parseCurrentBlock();
00408 
00409                 $this->tpl->setCurrentBlock("tab");
00410                 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00411                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('iladvancedsearchgui'));
00412                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
00413                 $this->tpl->parseCurrentBlock();
00414 
00415                 $this->tpl->setCurrentBlock("tab");
00416                 $this->tpl->setVariable("TAB_TYPE","tabactive");
00417                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getFolderId());
00418                 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
00419                 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_search_results"));
00420                 $this->tpl->parseCurrentBlock();
00421 
00422                 // show top button if folder isn't root folder
00423                 if($this->folder_obj->getFolderId() != $this->folder_obj->getRootId())
00424                 {
00425                         $this->tpl->setVariable("TXT_HEADER",$this->folder_obj->getTitle());
00426                         $this->tpl->setCurrentBlock("top");
00427                         $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00428                         $this->tpl->setVariable("LINK_TOP",$this->ctrl->getLinkTarget($this));
00429                         $this->tpl->setVariable("IMG_TOP",ilUtil::getImagePath("ic_top.gif"));
00430                         $this->tpl->parseCurrentBlock();
00431                 }
00432         }
00433 
00434         // PRIVATE
00435         function __initFolderObject()
00436         {
00437                 include_once 'Services/Search/classes/class.ilSearchFolder.php';
00438 
00439                 $this->folder_obj = new ilSearchFolder($this->getUserId(),(int) $_GET['folder_id']);
00440 
00441                 return true;
00442         }
00443 
00444         function __appendParentLink($nr_items)
00445         {
00446                 if($this->folder_obj->getFolderId() == $this->folder_obj->getRootId())
00447                 {
00448                         return false;
00449                 }
00450                 else
00451                 {
00452                         if($nr_items)
00453                         {
00454                                 $this->tpl->setVariable("CHECK","&nbsp;");
00455                         }
00456                         $this->tpl->setCurrentBlock("TBL_FOLDER_ROW");
00457                         $this->tpl->setVariable("ROWCOL","tblrow1");
00458 
00459                         list($link,$target) = $this->__formatLink(array("type" => "top"));
00460                         $this->tpl->setVariable("FOLDER_LINK",$link);
00461                         $this->tpl->setVariable("FOLDER_TARGET",$target);
00462                         $this->tpl->setVariable("FOLDER_TITLE",$this->__formatTitle(array("type" => "top")));
00463                         $this->tpl->parseCurrentBlock();
00464                         return true;
00465                 }
00466         }
00467         function __formatTitle($a_item)
00468         {
00469                 switch($a_item["type"])
00470                 {
00471                         case "seaf":
00472                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00473                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00474                                 
00475                                 return $img.$a_item["title"];
00476 
00477                         case "sea":
00478                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00479                                         ilUtil::getImagePath("icon_bm.gif")."\">&nbsp;";
00480                                 
00481                                 return $img.$a_item["title"];
00482 
00483                         case "top":
00484                                 $img = "<img border=\"0\" vspace=\"0\" align=\"left\" src=\"".
00485                                         ilUtil::getImagePath("icon_cat.gif")."\">&nbsp;";
00486 
00487                                 return $img."..";
00488                 }
00489         }
00490 
00491         function __formatLink($a_item)
00492         {
00493                 switch($a_item["type"])
00494                 {
00495                         case "seaf":
00496                                 $this->ctrl->setParameter($this,'folder_id',$a_item['obj_id']);
00497 
00498                                 return array($this->ctrl->getLinkTarget($this),'bottom');
00499 
00500                         case "sea":
00501                                 include_once "Services/Search/classes/class.ilUserResult.php";
00502 
00503                                 $tmp_obj =& new ilUserResult($this->getUserId(),$a_item["obj_id"]);
00504 
00505                                 $link = $tmp_obj->createLink();
00506                                 unset($tmp_obj);
00507 
00508                                 return $link;
00509                                 
00510                         case "top":
00511                                 $this->ctrl->setParameter($this,'folder_id',$this->folder_obj->getParentId());
00512                                 
00513                                 return array($this->ctrl->getLinkTarget($this),'bottom');
00514                 }
00515         }
00516         function __getActions()
00517         {
00518                 $options[0] = $this->lng->txt("search_select_one_action");
00519 
00520                 if($this->folder_obj->hasResults() and $this->folder_obj->countFolders())
00521                 {
00522                         // SHOW MOVE TO
00523                         $tree_data = $this->folder_obj->getTree();
00524 
00525                         foreach($tree_data as $node)
00526                         {
00527                                 $prefix = $this->lng->txt("search_move_to") ;
00528                                 for($i = 0; $i < $node["depth"];++$i)
00529                                 {
00530                                         $prefix .= "&nbsp;&nbsp;";
00531                                 }
00532                                 if($node["obj_id"] == $this->folder_obj->getRootId())
00533                                 {
00534                                         $options[$node["obj_id"]] = $prefix.$this->lng->txt("search_search_results");
00535                                 }
00536                                 else
00537                                 {
00538                                         $options[$node["obj_id"]] = $prefix.$node["title"];
00539                                 }
00540 
00541                         }                       
00542 
00543                 }
00544                 // SHOW RENAME
00545                 $options["rename"] = $this->lng->txt("rename");
00546 
00547                 // SHOW DELETE
00548                 $options["confirmDelete"] = $this->lng->txt("delete");
00549 
00550                 return ilUtil::formSelect($_POST["action"],"action",$options,false,true);
00551         }
00552 
00553         function __showRenameForm($a_old_title)
00554         {
00555                 $this->tpl->setCurrentBlock("FOLDER_CREATE_FORM");
00556                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TXT",$this->lng->txt("search_rename_title"));
00557                 $this->tpl->setVariable("FOLDER_CREATE_FORM_TITLE_TXT",$this->lng->txt("title"));
00558                 $this->tpl->setVariable("FOLDER_CREATE_FORM_VALUE",$a_old_title);
00559                 $this->tpl->setVariable("FOLDER_CREATE_FORM_CMD","update");
00560                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_1",$this->lng->txt("cancel"));
00561                 $this->tpl->setVariable("FOLDER_CREATE_FORM_SUBMIT_2",$this->lng->txt("rename"));
00562                 $this->tpl->parseCurrentBlock();
00563         }
00564 
00565 
00566 
00567 
00568 }
00569 ?>

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1