00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 include_once 'Services/Search/classes/class.ilSearchBaseGUI.php';
00036
00037 define('SEARCH_FAST',1);
00038 define('SEARCH_DETAILS',2);
00039 define('SEARCH_AND','and');
00040 define('SEARCH_OR','or');
00041
00042 class ilSearchGUI extends ilSearchBaseGUI
00043 {
00044 var $root_node;
00045 var $combination;
00046 var $string;
00047 var $type;
00048
00053 function ilSearchGUI()
00054 {
00055 $this->root_node = $_SESSION['search_root'] ? $_SESSION['search_root'] : ROOT_FOLDER_ID;
00056 $this->setType($_POST['search']['type'] ? $_POST['search']['type'] : $_SESSION['search']['type']);
00057 $this->setCombination($_POST['search']['combination'] ? $_POST['search']['combination'] : $_SESSION['search']['combination']);
00058 $this->setString($_POST['search']['string'] ? $_POST['search']['string'] : $_SESSION['search']['string']);
00059 $this->setDetails($_POST['search']['details'] ? $_POST['search']['details'] : $_SESSION['search']['details']);
00060
00061 parent::ilSearchBaseGUI();
00062 }
00063
00064
00069 function setType($a_type)
00070 {
00071 $_SESSION['search']['type'] = $this->type = $a_type;
00072 }
00073 function getType()
00074 {
00075 return $this->type ? $this->type : SEARCH_FAST;
00076 }
00081 function setCombination($a_combination)
00082 {
00083 $_SESSION['search']['combination'] = $this->combination = $a_combination;
00084 }
00085 function getCombination()
00086 {
00087 return $this->combination ? $this->combination : SEARCH_OR;
00088 }
00093 function setString($a_str)
00094 {
00095 $_SESSION['search']['string'] = $this->string = $a_str;
00096 }
00097 function getString()
00098 {
00099 return $this->string;
00100 }
00105 function setDetails($a_details)
00106 {
00107 $_SESSION['search']['details'] = $this->details = $a_details;
00108 }
00109 function getDetails()
00110 {
00111 return $this->details ? $this->details : array();
00112 }
00113
00114
00115 function getRootNode()
00116 {
00117 return $this->root_node ? $this->root_node : ROOT_FOLDER_ID;
00118 }
00119 function setRootNode($a_node_id)
00120 {
00121 $_SESSION['search_root'] = $this->root_node = $a_node_id;
00122 }
00123
00128 function &executeCommand()
00129 {
00130 global $rbacsystem;
00131
00132 $next_class = $this->ctrl->getNextClass($this);
00133 $cmd = $this->ctrl->getCmd();
00134
00135 switch($next_class)
00136 {
00137 default:
00138 if(!$cmd)
00139 {
00140 $cmd = "showSavedResults";
00141 }
00142
00143 $this->prepareOutput();
00144 $this->$cmd();
00145 break;
00146 }
00147 return true;
00148 }
00149
00150 function saveResult()
00151 {
00152 include_once 'Services/Search/classes/class.ilUserResult.php';
00153 include_once 'Services/Search/classes/class.ilSearchFolder.php';
00154
00155 global $ilUser;
00156
00157 if(!$_POST['folder'])
00158 {
00159 sendInfo($this->lng->txt('search_select_one'));
00160 $this->showSavedResults();
00161
00162 return false;
00163 }
00164 if(!count($_POST['id']))
00165 {
00166 sendInfo($this->lng->txt('search_select_one_result'));
00167 $this->showSavedResults();
00168
00169 return false;
00170 }
00171
00172 $folder_obj =& new ilSearchFolder($ilUser->getId(),(int) $_POST['folder']);
00173
00174 foreach($_POST['id'] as $ref_id)
00175 {
00176 $title = ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id));
00177 $target = addslashes(serialize(array('type' => ilObject::_lookupType(ilObject::_lookupObjId($ref_id)),
00178 'id' => $ref_id)));
00179
00180 $search_res_obj =& new ilUserResult($ilUser->getId());
00181 $search_res_obj->setTitle($title);
00182 $search_res_obj->setTarget($target);
00183
00184 $folder_obj->assignResult($search_res_obj);
00185 unset($search_res_obj);
00186 }
00187 sendInfo($this->lng->txt('search_results_saved'));
00188 $this->showSavedResults();
00189
00190 }
00191
00192
00193 function showSearch()
00194 {
00195 global $ilLocator;
00196
00197
00198
00199
00200
00201
00202 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.search.html','Services/Search');
00203
00204 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('search'));
00205 $this->tpl->setVariable("TXT_SEARCHAREA",$this->lng->txt('search_area'));
00206 $this->tpl->setVariable("SEARCH_ACTION",$this->ctrl->getFormAction($this));
00207 $this->tpl->setVariable("TXT_SEARCHTERM",$this->lng->txt("search_search_term"));
00208 $this->tpl->setVariable("TXT_AND",$this->lng->txt('search_all_words'));
00209 $this->tpl->setVariable("TXT_OR",$this->lng->txt('search_any_word'));
00210 $this->tpl->setVariable("BTN_SEARCH",$this->lng->txt('search'));
00211
00212
00213 if($this->getCombination() == SEARCH_AND)
00214 {
00215 $this->tpl->setVariable("AND_CHECKED",'checked=checked');
00216 }
00217 else
00218 {
00219 $this->tpl->setVariable("OR_CHECKED",'checked=checked');
00220 }
00221
00222 $this->tpl->setVariable("FORM_SEARCH_STR",ilUtil::prepareFormOutput($this->getString(),true));
00223
00224 $this->tpl->setVariable("HREF_UPDATE_AREA",$this->ctrl->getLinkTarget($this,'showSelectRoot'));
00225 $this->tpl->setVariable("UPDATE_AREA",$this->lng->txt('search_change'));
00226
00227
00228 $this->tpl->setVariable("TXT_SEARCH_TYPE",$this->lng->txt('search_type'));
00229 $this->tpl->setVariable("INFO_FAST",$this->lng->txt('search_fast_info'));
00230 $this->tpl->setVariable("INFO_DETAILS",$this->lng->txt('search_details_info'));
00231
00232 $this->tpl->setVariable("CHECK_FAST",ilUtil::formRadioButton($this->getType() == SEARCH_FAST ? 1 : 0,
00233 'search[type]',
00234 SEARCH_FAST ));
00235
00236 $this->tpl->setVariable("CHECK_DETAILS",ilUtil::formRadioButton($this->getType() == SEARCH_DETAILS ? 1 : 0,
00237 'search[type]',
00238 SEARCH_DETAILS));
00239
00240 $this->tpl->setVariable("LMS",$this->lng->txt('learning_resources'));
00241 $this->tpl->setVariable("GLO",$this->lng->txt('objs_glo'));
00242 $this->tpl->setVariable("MEP",$this->lng->txt('objs_mep'));
00243 $this->tpl->setVariable("TST",$this->lng->txt('search_tst_svy'));
00244 $this->tpl->setVariable("FOR",$this->lng->txt('objs_frm'));
00245 $this->tpl->setVariable("EXC",$this->lng->txt('objs_exc'));
00246 $this->tpl->setVariable("FIL",$this->lng->txt('objs_file'));
00247
00248
00249 $details = $this->getDetails();
00250 $this->tpl->setVariable("CHECK_GLO",ilUtil::formCheckbox($details['glo'] ? 1 : 0,'search[details][glo]',1));
00251 $this->tpl->setVariable("CHECK_LMS",ilUtil::formCheckbox($details['lms'] ? 1 : 0,'search[details][lms]',1));
00252 $this->tpl->setVariable("CHECK_MEP",ilUtil::formCheckbox($details['mep'] ? 1 : 0,'search[details][mep]',1));
00253 $this->tpl->setVariable("CHECK_TST",ilUtil::formCheckbox($details['tst'] ? 1 : 0,'search[details][tst]',1));
00254 $this->tpl->setVariable("CHECK_FOR",ilUtil::formCheckbox($details['frm'] ? 1 : 0,'search[details][frm]',1));
00255 $this->tpl->setVariable("CHECK_EXC",ilUtil::formCheckbox($details['exc'] ? 1 : 0,'search[details][exc]',1));
00256 $this->tpl->setVariable("CHECK_FIL",ilUtil::formCheckbox($details['fil'] ? 1 : 0,'search[details][fil]',1));
00257
00258
00259
00260
00261 if($this->getRootNode() == ROOT_FOLDER_ID)
00262 {
00263 $this->tpl->setVariable("SEARCHAREA",$this->lng->txt('search_in_magazin'));
00264 }
00265 else
00266 {
00267 $text = $this->lng->txt('search_below')." '";
00268 $text .= ilObject::_lookupTitle(ilObject::_lookupObjId($this->getRootNode()));
00269 $text .= "'";
00270 $this->tpl->setVariable("SEARCHAREA",$text);
00271 }
00272
00273 return true;
00274 }
00275
00276 function showSelectRoot()
00277 {
00278 global $tree;
00279
00280 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.search_root_selector.html','Services/Search');
00281
00282 include_once 'Services/Search/classes/class.ilSearchRootSelector.php';
00283
00284 sendInfo($this->lng->txt('search_area_info'));
00285
00286 $exp = new ilSearchRootSelector($this->ctrl->getLinkTarget($this,'showSelectRoot'));
00287 $exp->setExpand($_GET["search_root_expand"] ? $_GET["search_root_expand"] : $tree->readRootId());
00288 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'showSelectRoot'));
00289
00290
00291 $exp->setOutput(0);
00292
00293 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00294 }
00295
00296 function selectRoot()
00297 {
00298 $this->setRootNode((int) $_GET['root_id']);
00299 $this->showSavedResults();
00300
00301 return true;
00302 }
00303
00304
00305 function showSavedResults()
00306 {
00307 global $ilUser;
00308
00309
00310 include_once 'Services/Search/classes/class.ilSearchResult.php';
00311
00312 $result_obj = new ilSearchResult($ilUser->getId());
00313 $result_obj->read();
00314 $result_obj->filterResults($this->getRootNode());
00315
00316 $this->showSearch();
00317
00318
00319 if(count($result_obj->getResults()))
00320 {
00321 $this->__showSearchInResults();
00322
00323 include_once 'Services/Search/classes/class.ilSearchResultPresentationGUI.php';
00324
00325 $search_result_presentation = new ilSearchResultPresentationGUI($result_obj);
00326 $this->tpl->setVariable("RESULTS",$search_result_presentation->showResults());
00327 }
00328
00329 return true;
00330 }
00331
00332 function searchInResults()
00333 {
00334 $this->search_mode = 'in_results';
00335 $this->performSearch();
00336
00337 return true;
00338 }
00339
00340
00341 function performSearch()
00342 {
00343 global $ilUser;
00344
00345 if($this->getType() == SEARCH_DETAILS and !$this->getDetails())
00346 {
00347 sendInfo($this->lng->txt('search_choose_object_type'));
00348 $this->showSearch();
00349
00350 return false;
00351 }
00352
00353
00354
00355 if(!is_object($query_parser =& $this->__parseQueryString()))
00356 {
00357 sendInfo($query_parser);
00358 $this->showSearch();
00359
00360 return false;
00361 }
00362
00363 $result =& $this->__searchObjects($query_parser);
00364
00365
00366 $result_meta =& $this->__searchMeta($query_parser,'keyword');
00367 $result->mergeEntries($result_meta);
00368
00369 $result_meta =& $this->__searchMeta($query_parser,'contribute');
00370 $result->mergeEntries($result_meta);
00371
00372
00373 if($this->getType() == SEARCH_DETAILS)
00374 {
00375 $result = $this->__performDetailsSearch($query_parser,$result);
00376 }
00377
00378 if($this->search_mode == 'in_results')
00379 {
00380 include_once 'Services/Search/classes/class.ilSearchResult.php';
00381
00382 $old_result_obj = new ilSearchResult($ilUser->getId());
00383 $old_result_obj->read();
00384
00385 $result->diffEntriesFromResult($old_result_obj);
00386 }
00387
00388
00389
00390 $result->filter($this->getRootNode(),$query_parser->getCombination() == 'and');
00391 $this->showSearch();
00392
00393 if(!count($result->getResults()))
00394 {
00395 sendInfo($this->lng->txt('search_no_match'));
00396 }
00397 else
00398 {
00399 $this->__showSearchInResults();
00400 }
00401
00402 if($result->isLimitReached())
00403 {
00404 $message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
00405 sendInfo($message);
00406 }
00407
00408
00409 include_once 'Services/Search/classes/class.ilSearchResultPresentationGUI.php';
00410
00411 $search_result_presentation = new ilSearchResultPresentationGUI($result);
00412 $this->tpl->setVariable("RESULTS",$search_result_presentation->showResults());
00413
00414
00415 $result->setUserId($ilUser->getId());
00416 $result->save();
00417
00418 return true;
00419 }
00420
00421
00422
00423 function prepareOutput()
00424 {
00425 parent::prepareOutput();
00426
00427 $this->tpl->setCurrentBlock("header_image");
00428 $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_src_b.gif"));
00429 $this->tpl->parseCurrentBlock();
00430
00431 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt('search'));
00432
00433 $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
00434
00435 $this->tpl->setCurrentBlock("tab");
00436 $this->tpl->setVariable("TAB_TYPE","tabactive");
00437 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
00438 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
00439 $this->tpl->parseCurrentBlock();
00440
00441 $this->tpl->setCurrentBlock("tab");
00442 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00443 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('iladvancedsearchgui'));
00444 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
00445 $this->tpl->parseCurrentBlock();
00446
00447 $this->tpl->setCurrentBlock("tab");
00448 $this->tpl->setVariable("TAB_TYPE","tabinactive");
00449 $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchresultgui'));
00450 $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_search_results"));
00451 $this->tpl->parseCurrentBlock();
00452
00453 }
00454
00455
00456 function &__performDetailsSearch(&$query_parser,&$result)
00457 {
00458 foreach($this->getDetails() as $type => $always_one)
00459 {
00460 switch($type)
00461 {
00462 case 'lms':
00463 $content_search =& ilObjectSearchFactory::_getLMContentSearchInstance($query_parser);
00464 $content_search->setFilter(array('lm','dbk'));
00465 $result->mergeEntries($content_search->performSearch());
00466
00467 $result_meta =& $this->__searchMeta($query_parser,'title');
00468 $result->mergeEntries($result_meta);
00469 $result_meta =& $this->__searchMeta($query_parser,'description');
00470 $result->mergeEntries($result_meta);
00471 if($this->settings->enabledLucene())
00472 {
00473 $htlm_search =& ilObjectSearchFactory::_getHTLMSearchInstance($query_parser);
00474 $result->mergeEntries($htlm_search->performSearch());
00475 }
00476 break;
00477
00478 case 'frm':
00479 $forum_search =& ilObjectSearchFactory::_getForumSearchInstance($query_parser);
00480 $result->mergeEntries($forum_search->performSearch());
00481 break;
00482
00483 case 'glo':
00484
00485 $gdf_search =& ilObjectSearchFactory::_getLMContentSearchInstance($query_parser);
00486 $gdf_search->setFilter(array('gdf'));
00487 $result->mergeEntries($gdf_search->performSearch());
00488
00489
00490 $gdf_term_search =& ilObjectSearchFactory::_getGlossaryDefinitionSearchInstance($query_parser);
00491 $result->mergeEntries($gdf_term_search->performSearch());
00492 break;
00493
00494 case 'exc':
00495 $exc_search =& ilObjectSearchFactory::_getExerciseSearchInstance($query_parser);
00496 $result->mergeEntries($exc_search->performSearch());
00497 break;
00498
00499 case 'tst':
00500 $tst_search =& ilObjectSearchFactory::_getTestSearchInstance($query_parser);
00501 $result->mergeEntries($tst_search->performSearch());
00502 break;
00503
00504 case 'mep':
00505 $mep_search =& ilObjectSearchFactory::_getMediaPoolSearchInstance($query_parser);
00506 $result->mergeEntries($mep_search->performSearch());
00507 break;
00508
00509 case 'fil':
00510 if($this->settings->enabledLucene())
00511 {
00512 $file_search =& ilObjectSearchFactory::_getFileSearchInstance($query_parser);
00513 $result->mergeEntries($file_search->performSearch());
00514 }
00515 break;
00516 }
00517 }
00518 return $result;
00519 }
00520
00526 function &__parseQueryString()
00527 {
00528 include_once 'Services/Search/classes/class.ilQueryParser.php';
00529
00530 $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->getString()));
00531 $query_parser->setCombination($this->getCombination());
00532 $query_parser->parse();
00533
00534 if(!$query_parser->validate())
00535 {
00536 return $query_parser->getMessage();
00537 }
00538 return $query_parser;
00539 }
00545 function &__searchObjects(&$query_parser)
00546 {
00547 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
00548
00549 $obj_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
00550
00551 if($this->getType() == SEARCH_DETAILS)
00552 {
00553 $obj_search->setFilter($this->__getFilter());
00554 }
00555 return $obj_search->performSearch();
00556 }
00557
00558
00564 function &__searchMeta(&$query_parser,$a_type)
00565 {
00566 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
00567
00568 $meta_search =& ilObjectSearchFactory::_getMetaDataSearchInstance($query_parser);
00569 if($this->getType() == SEARCH_DETAILS)
00570 {
00571 $meta_search->setFilter($this->__getFilter());
00572 }
00573 switch($a_type)
00574 {
00575 case 'keyword':
00576 $meta_search->setMode('keyword');
00577 break;
00578
00579 case 'contribute':
00580 $meta_search->setMode('contribute');
00581 break;
00582
00583 case 'title':
00584 $meta_search->setFilter(array('pg','st'));
00585 $meta_search->setMode('title');
00586 break;
00587
00588 case 'description':
00589 $meta_search->setFilter(array('pg','st'));
00590 $meta_search->setMode('description');
00591 break;
00592 }
00593 return $meta_search->performSearch();
00594 }
00600 function __getFilter()
00601 {
00602 foreach($this->getDetails() as $key => $detail_type)
00603 {
00604 switch($key)
00605 {
00606 case 'lms':
00607 $filter[] = 'lm';
00608 $filter[] = 'dbk';
00609 $filter[] = 'pg';
00610 $filter[] = 'st';
00611 $filter[] = 'sahs';
00612 $filter[] = 'htlm';
00613 break;
00614
00615 case 'frm':
00616 $filter[] = 'frm';
00617 break;
00618
00619 case 'glo':
00620 $filter[] = 'glo';
00621 break;
00622
00623 case 'exc':
00624 $filter[] = 'exc';
00625 break;
00626
00627 case 'tst':
00628 $filter[] = 'tst';
00629 $filter[] = 'svy';
00630 $filter[] = 'qpl';
00631 $filter[] = 'spl';
00632 break;
00633
00634 case 'mep':
00635 $filter[] = 'mep';
00636 $filter[] = 'mob';
00637 break;
00638
00639 case 'fil':
00640 $filter[] = 'file';
00641 break;
00642 }
00643 }
00644 return $filter ? $filter : array();
00645 }
00646
00652 function __showSearchInResults()
00653 {
00654 $this->tpl->setCurrentBlock("search_results");
00655 $this->tpl->setVariable("BTN_SEARCHRESULTS",$this->lng->txt('search_in_result'));
00656 $this->tpl->parseCurrentBlock();
00657
00658 $this->tpl->setCurrentBlock("save_result");
00659 $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
00660 $this->tpl->setVariable("BTN_SAVE_RESULT",$this->lng->txt('save'));
00661 $this->tpl->setVariable("SELECT_FOLDER",$this->__getFolderSelect());
00662 $this->tpl->parseCurrentBlock();
00663
00664 return true;
00665 }
00666
00667 function __getFolderSelect()
00668 {
00669 global $ilUser;
00670
00671 include_once 'Services/Search/classes/class.ilSearchFolder.php';
00672
00673
00674 $folder_obj =& new ilSearchFolder($ilUser->getId());
00675
00676
00677 $subtree = $folder_obj->getSubtree();
00678
00679 $options[0] = $this->lng->txt("search_select_one_folder_select");
00680 $options[$folder_obj->getRootId()] = $this->lng->txt("search_save_as_select")." ".$this->lng->txt("search_search_results");
00681
00682 foreach($subtree as $node)
00683 {
00684 if($node["obj_id"] == $folder_obj->getRootId())
00685 {
00686 continue;
00687 }
00688
00689 $prefix = $this->lng->txt("search_save_as_select");
00690 for($i = 1; $i < $node["depth"];++$i)
00691 {
00692 $prefix .= " ";
00693 }
00694 $options[$node["obj_id"]] = $prefix.$node["title"];
00695 }
00696 return ilUtil::formSelect(0,'folder',$options,false,true);
00697 }
00698
00699 }
00700 ?>