Globale Suche für CIS nach Content und Benutzern

This commit is contained in:
Andreas Österreicher
2012-01-27 12:29:27 +00:00
parent 9b7e99bdcf
commit 7e30670c29
8 changed files with 345 additions and 14 deletions
+20 -14
View File
@@ -92,26 +92,27 @@ function loadampel()
<td width="100%" ></td>
<td width="100%" ></td>
<td></td>
</tr>
<tr>
<td width="170" class="tdwrap" onclick="self.location.href='index.php'">
<div class="home_logo">&nbsp;</div>
</td>
<td id="header" colspan="2">
<div class="header_line" ></div>
<td id="header" colspan="2" valign="top">
<div class="header_line" ></div>
</td>
<td nowrap >
<div style="font-size: 10px;"><i>Powered by <a href="http://fhcomplete.technikum-wien.at/" target="blank">FH Complete 2.0</a></i></div>
</td>
<td nowrap>
<div style="font-size: 10px; text-align: right">
<i>Powered by <a href="http://fhcomplete.technikum-wien.at/" target="blank">FH Complete 2.0</a></i>
</div>
</td>
</tr>
<tr>
<td></td>
<td align="right" nowrap colspan="2">
<span id="ampel"></span>
<?php require_once('../include/'.EXT_FKT_PATH.'/cis_menu_global.inc.php'); ?>
</td>
<td align="right">
<?php
<td align="right" nowrap colspan="2">
<span id="ampel"></span>
<?php require_once('../include/'.EXT_FKT_PATH.'/cis_menu_global.inc.php'); ?>
<?php
$sprache = new sprache();
$sprache->getAll(true);
@@ -119,14 +120,19 @@ function loadampel()
{
echo ' <a href="#'.$row->sprache.'" title="'.$row->sprache.'" onclick="changeSprache(\''.$row->sprache.'\'); return false;"><img src="../cms/image.php?src=flag&sprache='.$row->sprache.'" alt="'.$row->sprache.'"></a>';
}
?>
?>
</td>
<td align="right" nowrap>
<form name="searchform" action="private/tools/suche.php" method="GET" target="content" style="display:inline">
<input type="search" size="10" name="search" placeholder="Suchbegriff ..."/>
<img src="../skin/images/search.png" height="14px" onclick="document.searchform.submit()" class="suchicon"/>
</form>
</td>
</tr>
</table>
<iframe id="menue" src="<?php echo $menu; ?>" name="menu" frameborder="0">
No iFrames
</iframe>
<!-- <iframe id="content" src="public/news.php" name="content" frameborder="0"> -->
<iframe id="content" src="<?php echo $content; ?>" name="content" frameborder="0">
No iFrames
</iframe>
+192
View File
@@ -0,0 +1,192 @@
<?php
/* Copyright (C) 2012 FH Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
/**
* Globale Suche
*/
require_once('../../../config/cis.config.inc.php');
require_once('../../../include/functions.inc.php');
require_once('../../../include/phrasen.class.php');
require_once('../../../include/content.class.php');
require_once('../../../include/benutzer.class.php');
$uid = get_uid();
$db = new basis_db();
$sprache = getSprache();
$p = new phrasen($sprache);
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../skin/tablesort.css" type="text/css"/>
<link href="../../../skin/style.css.php" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../../include/js/jquery.js"></script>
<title>Globale Suche</title>
</head>
<body>';
echo '<h1>',$p->t('tools/suche'),'</h1>';
$search = (isset($_REQUEST['search'])?$_REQUEST['search']:'');
echo '<form action="',$_SERVER['PHP_SELF'],'" name="searchform" method="GET">
<input type="search" placeholder="Suchbegriff ..." size="40" name="search" value="',$db->convert_html_chars($search),'" />
<img src="../../../skin/images/search.png" onclick="document.searchform.submit()" height="15px" class="suchicon"/>
</form>';
if($search=='')
exit;
$searchItems = explode(' ',$search);
searchContent($searchItems);
searchPerson($searchItems);
function searchPerson($searchItems)
{
global $db, $p;
$bn = new benutzer();
$bn->search($searchItems);
echo '<h2>',$p->t('global/personen'),'</h2>';
if(count($bn->result)>0)
{
echo '
<script type="text/javascript">
$(document).ready(function()
{
$("#personentable").tablesorter(
{
sortList: [[2,0]],
widgets: [\'zebra\']
});
}
);
</script>
<table class="tablesorter" id="personentable">
<thead>
<tr class="liste">
<th>',$p->t('global/titel'),'</th>
<th>',$p->t('global/vorname'),'</th>
<th>',$p->t('global/nachname'),'</th>
<th>',$p->t('global/titel'),'</th>
<th>',$p->t('global/studiengang'),'</th>
<th>',$p->t('global/telefonnummer'),'</th>
<th>',$p->t('global/mail'),'</th>
</tr>
</thead>
<tbody>
';
foreach($bn->result as $row)
{
echo '<tr>';
echo '<td>',$row->titelpre,'</td>';
echo '<td>',$row->vorname,'</td>';
echo '<td><a href="../profile/index.php?uid=',$row->uid,'">',$row->nachname,'</a></td>';
echo '<td>',$row->titelpost,'</td>';
echo '<td>',$row->studiengang,'</td>';
echo '<td>',$row->telefonklappe,'</td>';
if($row->alias!='')
$mail = $row->alias.'@'.DOMAIN;
else
$mail = $row->uid.'@'.DOMAIN;
echo '<td><a href="mailto:',$mail,'">',$mail,'</a></td>';
echo '</tr>';
echo "\n";
}
echo '</tbody></table>';
}
}
function searchContent($searchItems)
{
global $db,$p;
$cms = new content();
$cms->search($searchItems);
echo '<h2>',$p->t('tools/content'),'</h2>';
echo '<ul>';
foreach($cms->result as $row)
{
echo '<li><div class="suchergebnis">';
echo '<a href="../../../cms/content.php?content_id=',$db->convert_html_chars($row->content_id),'">',$db->convert_html_chars($row->titel),'</a><br>';
$preview = findAndMark($row->content, $searchItems);
echo $preview;
echo '<br /><br /></div></li>';
}
echo '</ul>';
}
function findAndMark($content, $items)
{
foreach($items as $row)
{
if($row!='')
{
$item = $row;
break;
}
}
//CDATA und HTML Tags entfernen
$content = mb_str_replace('<[CDATA[', '', $content);
$content = mb_str_replace(']]>', '', $content);
$content = strip_tags($content);
$item = mb_strtolower($item);
$beginn = mb_strpos(mb_strtolower($content), $item);
$len = mb_strlen($item);
//Im Content sind die Umlaute teilweise codiert gespeichert
//Wenn der Eintrag nicht gefunden wird, wird mit Codierten Zeichen nochmals gesucht
if($beginn=='')
{
$beginn = mb_strpos(mb_strtolower($content), htmlentities($item,ENT_NOQUOTES,'UTF-8'));
$len = mb_strlen(htmlentities($item,ENT_NOQUOTES,'UTF-8'));
}
if($beginn=='')
{
$beginn=0;
$len=0;
}
$start = (($beginn-100)>0?($beginn-100):0);
//echo "start: $start<br>beginn: $beginn<br>beginn-start: ".($beginn-$start);
//echo "<br>item:".$item.'<br>';
$preview='';
if($start!=0)
$preview='...';
$preview .= mb_substr($content, $start, ($beginn-$start));
$preview.='<span class="suchmarker">';
$preview.= mb_substr($content, $beginn, $len);
$preview.='</span>';
$preview.= mb_substr($content, $beginn+$len, 300);
$laenge = $beginn+$len+300;
if($laenge<mb_strlen($content))
$preview.='...';
return $preview;
}
echo '</body></html>';
?>
+58
View File
@@ -28,6 +28,7 @@ class benutzer extends person
public $bnaktiv=true; // boolean
public $alias; // varchar(256)
public $bn_ext_id;
public $result = array();
/**
* Konstruktor - Uebergibt die Connection und laedt optional einen Benutzer
@@ -257,5 +258,62 @@ class benutzer extends person
return false;
}
}
public function search($searchItems)
{
$qry = "SELECT * FROM (SELECT
distinct on (uid) vorname, nachname, uid, titelpre, titelpost,alias,
(SELECT UPPER(tbl_studiengang.typ || tbl_studiengang.kurzbz)
FROM public.tbl_student JOIN public.tbl_studiengang USING(studiengang_kz)
WHERE student_uid=tbl_benutzer.uid) as studiengang,
(SELECT tbl_kontakt.kontakt || ' - ' ||telefonklappe
FROM public.tbl_mitarbeiter
LEFT JOIN public.tbl_kontakt USING(standort_id)
WHERE
mitarbeiter_uid=tbl_benutzer.uid
AND (tbl_kontakt.kontakttyp='telefon' OR tbl_kontakt.kontakttyp is null)
) as klappe
FROM
public.tbl_person
JOIN public.tbl_benutzer USING(person_id)
WHERE
tbl_benutzer.aktiv
AND (";
$qry.=" lower(vorname || ' ' || nachname) like lower('%".addslashes(implode(' ',$searchItems))."%')";
$qry.=" OR lower(nachname || ' ' || vorname) like lower('%".addslashes(implode(' ',$searchItems))."%')";
$qry.=" OR lower(uid) like lower('%".addslashes(implode(' ',$searchItems))."%')";
foreach($searchItems as $value)
{
$qry.=" OR lower(uid) = lower('".addslashes($value)."')";
}
$qry.=")) a ORDER BY nachname, vorname";
if($result = $this->db_query($qry))
{
while($row = $this->db_fetch_object($result))
{
$obj = new benutzer();
$obj->titelpre = $row->titelpre;
$obj->vorname = $row->vorname;
$obj->nachname = $row->nachname;
$obj->titelpost = $row->titelpost;
$obj->uid = $row->uid;
$obj->studiengang = $row->studiengang;
$obj->telefonklappe = $row->klappe;
$obj->alias = $row->alias;
$this->result[] = $obj;
}
return true;
}
else
{
$this->errormsg = 'Fehler beim Laden der Daten';
return false;
}
}
}
?>
+41
View File
@@ -1234,5 +1234,46 @@ class content extends basis_db
}
}
/**
* Durchsucht den Content
*
* @param array $searchItems
*/
public function search($searchItems)
{
$qry = "SELECT
distinct on(content_id) *
FROM
campus.tbl_contentsprache
JOIN campus.tbl_content USING(content_id)
WHERE
sichtbar=true
AND aktiv=true
AND template_kurzbz IN('contentmittitel','contentohnetitel','redirect')";
foreach($searchItems as $value)
$qry.=" AND (lower(content::text) like lower('%".addslashes($value)."%')
OR lower(content::text) like lower('%".addslashes(htmlentities($value,ENT_NOQUOTES,'UTF-8'))."%'))";
$qry.=" ORDER BY content_id DESC";
if($result = $this->db_query($qry))
{
while($row = $this->db_fetch_object($result))
{
$obj = new content();
$obj->content_id = $row->content_id;
$obj->content = $row->content;
$obj->titel = $row->titel;
$this->result[] = $obj;
}
return true;
}
else
{
$this->errormsg = 'Fehler beim Laden der Daten';
return false;
}
}
}
?>
+5
View File
@@ -50,4 +50,9 @@ $this->phrasen['tools/datei']='Datei ';
$this->phrasen['tools/wurdeNichtGefunden']=' wurde nicht gefunden!';
$this->phrasen['tools/fehlerBeimLesenDerDatei']='Fehler beim Lesen der Datei ';
$this->phrasen['tools/keineDatenGefunden']='Keine Daten gefunden';
//Suche
$this->phrasen['tools/suche']='Globale Suche';
$this->phrasen['tools/content']='Content';
?>
+5
View File
@@ -50,4 +50,9 @@ $this->phrasen['tools/datei']='File ';
$this->phrasen['tools/wurdeNichtGefunden']=' was not found!';
$this->phrasen['tools/fehlerBeimLesenDerDatei']='Error reading file ';
$this->phrasen['tools/keineDatenGefunden']='No data found';
//Suche
$this->phrasen['tools/suche']='Global Search';
$this->phrasen['tools/content']='Content';
?>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

+24
View File
@@ -691,3 +691,27 @@ option.inactive
{
background-color: lightgreen;
}
.suchmarker
{
font-weight: bold;
text-decoration: underline;
font-size: medium;
}
.suchergebnis:hover
{
background-color: #EEEEEE;
}
.suchergebnis a
{
font-weight: bold;
}
.suchicon
{
margin:0px;
}
.suchicon:hover
{
cursor:pointer;
cursor:hand;
}