<?php
/**
* @version 2.1.1
* @package kwalbum
* @since 2.0 2008-08-20
*/
require_once pathinfo(__FILE__, PATHINFO_DIRNAME).'/../include/DBConnection.php';
$DB = new DBConnection();
$limit = 5;
$tags = explode(',', $DB->FilterString($P['people']));
if (!$size = count($tags))
exit;
$has = false;
$where = '';
$oldTags = '';
$found = false;
for($i = 0; $i < $size; $i++)
{
$tag = trim($tags[$i]);
if (!empty($tags[$i]))
{
if ($i < $size-1)
{
$where .= " AND PeopleName != '$tags[$i]'";
$oldTags .= ($has ? ',' : null).$tag;
}
$has = true;
}
}
if (!$has or !$tag)
exit;
if ($oldTags)
$oldTags .= ',';
echo '<ul>';
$query = 'SELECT PeopleName FROM '.PEOPLE_TABLE .
" WHERE PeopleName = '$tag' " .$where.
"ORDER BY PeopleCount DESC " .
"LIMIT $limit";
$result1 = $DB->Query($query);
if (0 < $result1->num_rows)
while ($row = $result1->fetch_array())
{
$where .= " AND PeopleName != '$row[0]'";
$found = true;
$pos1 = stripos($row[0], $tag);
$len = strlen($tag);
$pos2 = $pos1+$len;
echo "<li>$oldTags<b><big><big>$row[0]</big></big></b></li>";
}
$query = 'SELECT PeopleName FROM '.PEOPLE_TABLE .
" WHERE PeopleName LIKE '$tag%' " .$where.
"ORDER BY PeopleCount DESC " .
"LIMIT $limit";
$result1 = $DB->Query($query);
if (0 < $result1->num_rows)
while ($row = $result1->fetch_array())
{
$where .= " AND PeopleName != '$row[0]'";
$len = strlen($tag);
echo "<li>$oldTags<b><big><big>".
substr($row[0], 0, $len).'</big></big></b>'.
substr($row[0], $len).'</li>';
}
if (!$found)
echo "<li>$oldTags<b><big><big>$tag</big></big></b></li>";
$limit -= $result1->num_rows;
$query = 'SELECT PeopleName FROM '.PEOPLE_TABLE .
" WHERE PeopleName LIKE '%$tag%' " .$where.
"ORDER BY PeopleCount DESC " .
"LIMIT $limit";
$result2 = $DB->Query($query);
if (0 < $result2->num_rows)
while ($row = $result2->fetch_array())
{
$pos = stripos($row[0], $tag);
$len = strlen($tag);
echo "<li>$oldTags".substr($row[0], 0, $pos).'<b><big><big>'.
substr($row[0], $pos, $len).'</big></big></b>'.
substr($row[0], $pos+$len).'</li>';
}
?>
</ul>