čtvrtek 16. února 2012
List of keywords
Here's a small plugin that takes a search queue and displays a list of keywords from selected field. Ie, I needed to be able to display all the order names in 2011, so now I just have to do a search using the native RS search, and I got the list of keywords on top.
<?php
function HookListSearchBeforesearchresults()
{
global $archive, $search, $restypes,$order_by,$archive,$sort,$starsearch ;
?>
<!-- Javascript for displaying/hiding the div, and css styling begins here -->
<script language="javascript">
function toggle2(showHideDiv, switchTextDiv) {
var ele = document.getElementById(showHideDiv);
var text = document.getElementById(switchTextDiv);
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "+ Seznam zakazek";
}
else {
ele.style.display = "block";
text.innerHTML = "- Skryt";
}
}
</script>
<style type="text/css">
#headerDiv, #contentDiv {
width: 300px;
}
#titleText {
float: left;
font-size: 1.1em;
font-weight: bold;
margin: 5px;
}
#headerDiv {
background-color: #0037DB;
color: #9EB6FF;
}
#contentDiv {
background-color: black;
}
#myContent {
margin: 5px 10px;
}
#myContent a {
font-size: 16px;
margin: 0 0 10px 0!important;
}
#headerDiv a {
float: right;
}
#headerDiv a:hover {
color: #FFFFFF;
}
</style>
<!-- Javascript for displaying/hiding the div, and css styling ends here -->
<!-- content -->
<div id="headerDiv">
<div id="titleText"></div><a id="myHeader" href="javascript:toggle2('myContent','myHeader');" > + Seznam zakazek</a>
</div>
<div id="contentDiv">
<div id="myContent" style="display: none;">
<?php
// use the actual search
$result2=do_search($search,$restypes,$order_by,$archive,'10000000',$sort,false,$starsearch);
// get list of resource ref's
if (!empty($result2)) {
foreach ($result2 as $res) {
$ref1[] = $res['ref'];
}
// implode for use in mysql query
$list = implode(",",$ref1);
// the actual query, replace resource_type_field value with anything you need
$result = mysql_query("SELECT distinct r1.value as nazev FROM `resource_data` r1 where r1.`resource_type_field`=8 and r1.`resource` IN ($list) ");
// create array with the names
$names=array();
while($row = mysql_fetch_array($result)){
// this is here because ie. dynamic keyword list adds "," at the beginning of the keyword
$name=str_replace(",","",$row['nazev']);
array_push($names,$name);
}
// remove duplicates
$unique_names=array_unique($names);
// sort alphabetically
asort($unique_names);
// create the list
foreach ($unique_names as $name){
?> <a href="search.php?search=<?php echo $name;?>"><?php echo $name;?></a><br />
<?php
}}
?>
</div>
</div>
<?php }
?>
Any feedback welcome...
Přihlásit se k odběru:
Komentáře k příspěvku (Atom)

Žádné komentáře:
Okomentovat