Exemplo n.º 1
0
function search_products($items, $conn)
{
    global $set, $db, $apx, $user;
    require_once BASEDIR . getmodulepath('products') . 'functions.php';
    //Suchstring generieren
    $tagmatches = products_match_tags($items);
    foreach ($items as $item) {
        $tagmatch = array_shift($tagmatches);
        $search[] = " ( " . iif($tagmatch, " id IN (" . implode(',', $tagmatch) . ") OR ") . " title LIKE '%" . addslashes_like($item) . "%' OR text LIKE '%" . addslashes_like($item) . "%' ) ";
    }
    $searchstring = implode($conn, $search);
    //Ergebnisse
    $data = $db->fetch("SELECT id,title FROM " . PRE . "_products WHERE ( active='1' AND searchable='1' AND ( " . $searchstring . " ) ) ORDER BY title ASC");
    if (count($data)) {
        foreach ($data as $res) {
            ++$i;
            $link = mklink('products.php?id=' . $res['id'], 'products,id' . $res['id'] . urlformat($res['title']) . '.html');
            $result[$i]['TITLE'] = strip_tags($res['title']);
            $result[$i]['LINK'] = $link;
        }
    }
    return $result;
}
Exemplo n.º 2
0
             }
         }
     }
     $apx->tmpl->assign('PRODUCT', $tabledata);
     $apx->tmpl->parse('search_result');
 } else {
     $where = '';
     //Alle Produkttypen sind nicht gewählt
     if (!is_array($_REQUEST['type']) || !count($_REQUEST['type'])) {
         $_REQUEST['type'] = $types;
     }
     //Suchbegriffe
     if ($_REQUEST['item']) {
         $items = array();
         $it = explode(' ', preg_replace('#[ ]{2,}#', ' ', trim($_REQUEST['item'])));
         $tagmatches = products_match_tags($it);
         foreach ($it as $item) {
             if (trim($item)) {
                 $string = preg_replace('#[\\s_-]+#', '[^0-9a-zA-Z]*', $item);
                 if (preg_match('#^[0-9a-zA-Z]+$#', $string)) {
                     $items[] = " LIKE '%" . addslashes_like($string) . "%' ";
                 } else {
                     $items[] = " REGEXP '" . addslashes($string) . "' ";
                 }
             }
         }
         if ($_REQUEST['conn'] == 'or') {
             $conn = ' OR ';
         } else {
             $conn = ' AND ';
         }