* */ error_reporting(E_ALL ^ E_NOTICE); require_once "lib/DB.php"; require_once "db.conf.php"; require_once "lib/class.Template.php"; $db = new DB(); $tpl = & new Template(); if(empty($_POST['store_uid'])) { $_POST['store_uid'] = $_GET['store_uid']>0?$_GET['store_uid']:1; } if(isset($_POST['form_reset'])) { $_POST = array('store_uid'=>intval($_POST['store_uid'])); } ////http://jsfiddle.net/arunpjohny/6c6zr/1/ $q = trim($_POST['query']); if($_POST['qsubmit'] && $q!='') { $q = trim($_POST['query']); $sql = "SELECT uid as article_uid FROM modus_articles WHERE store_uid = '".intval($_POST['store_uid'])."' ".( $q!=''?"AND model LIKE '%".$db->escapeString($q)."%'":""); //NEU 29.06.19 $sql = "SELECT uid as article_uid FROM modus_articles WHERE model LIKE '%".$db->escapeString($q)."%'"; $_POST = array('query' => $q, 'store_uid'=>intval($_POST['store_uid'])); } else if($_POST['fsubmit'] && count($_POST['filterval'])) { unset($_POST['query']); $loop = 0; foreach($_POST['filterval'] as $attribute_uid => $attribute_values) { $alias = 'a'.$loop; if($loop++ == 0) { $sql = " SELECT * FROM ( SELECT article_uid FROM modus_articles_attributes WHERE store_uid = '".intval($_POST['store_uid'])."' AND attribute_uid = ".$attribute_uid." AND attribute_value IN ('".implode("','", $attribute_values)."')) as ".$alias; } else { $sql .= " INNER JOIN ( SELECT article_uid FROM modus_articles_attributes WHERE store_uid = '".intval($_POST['store_uid'])."' AND attribute_uid = ".$attribute_uid." AND attribute_value IN ('".implode("','", $attribute_values)."')) as ".$alias." USING (article_uid) "; } } } else { $sql = "SELECT article_uid FROM modus_articles_attributes WHERE store_uid = '".intval($_POST['store_uid'])."'"; } $subres = $db->query($sql); $articleUids = array(); $suggestPreset = array(); if($db->getNumRows($subres)) { while($subnext = $db->fetchAssocRow($subres)) { $articleUids[] = $subnext['article_uid']; } // $articleUids = array_unique($articleUids); $sql = "SELECT * FROM modus_articles WHERE uid IN (".implode(',', $articleUids).") ORDER by size ASC , model ASC"; $articleData = $db->fetchAssocArray($sql, 'uid'); //print_r($articleData); $sql = "SELECT cat.name as cat_name,cat.uid as cat_uid, av.article_uid, av.`attribute_value`, attr.uid as attr_uid, attr.unit FROM `modus_articles_attributes` AS av LEFT JOIN modus_cat_attributes as attr ON av.attribute_uid = attr.uid LEFT JOIN modus_cats as cat ON cat.uid = attr.cat_uid WHERE article_uid IN (".implode(',', $articleUids).") AND cat.filter_mode !=-1"; // AND cat.uid IN (3, 4, 5, 6, 7, 8, 9, 11,10, 12, 14)" ; $articleAttributeData= $db->fetchAssocArray($sql); foreach($articleAttributeData as $attributeData) { if(sizeof($articleData[$attributeData['article_uid']]['attributes'][$attributeData['cat_name']][$attributeData['attr_uid']])>0) $articleData[$attributeData['article_uid']]['attributes'][$attributeData['cat_name']][$attributeData['attr_uid']] .= ', '.$attributeData['attribute_value'].($attributeData['unit']?' '.$attributeData['unit']:''); else $articleData[$attributeData['article_uid']]['attributes'][$attributeData['cat_name']][$attributeData['attr_uid']] = $attributeData['attribute_value'].($attributeData['unit']?' '.$attributeData['unit']:''); $suggestPreset[$attributeData['attr_uid']][] = $attributeData['attribute_value']; } $tpl->set('articles', $articleData); } if($_POST['intellifilter']) { $suggestKeys = array_keys($suggestPreset); } else $suggestKeys = array(); //print_r($suggestKeys); $sql = "SELECT A.*, (SELECT count(uid) FROM modus_cat_attributes WHERE store_uid = '".intval($_POST['store_uid'])."' AND cat_uid = A.uid AND filter_mode=0) as activeAttrCount FROM modus_cats as A LEFT JOIN modus_cat_attributes as B ON B.cat_uid = A.uid LEFT JOIN modus_articles_attributes as C ON C.attribute_uid = B.uid ".(empty($suggestKeys)==false?"WHERE B.uid IN (".implode(',', $suggestKeys).")":"WHERE A.store_uid = '".intval($_POST['store_uid'])."'")." GROUP by A.uid ORDER by A.filter_mode DESC, uid "; $categories = $db->fetchAssocArray($sql); $resultCatsUids = array(); foreach($categories as $_nextC) { $resultCatsUids[] = $_nextC['uid']; } $sql = "SELECT * FROM modus_cats WHERE uid in (".implode(',', $resultCatsUids).") ORDER by uid "; $resultCats = $db->fetchAssocArray($sql); $tpl->set('hasCats', true); $sql = "SELECT * FROM modus_cat_attributes ORDER by filter_mode DESC, uid ASC"; $attributes = $db->fetchAssocArray($sql); foreach ($categories as &$nextCat) { foreach ($attributes as $nextAtt) { if ($nextCat['uid'] == $nextAtt['cat_uid']) { if(empty($suggestKeys)== false && !in_array($nextAtt['uid'], $suggestKeys)) { continue; } $nextCat['attributes'][$nextAtt['uid']] = $nextAtt; } } } $sql = "SELECT A.attribute_uid, A.attribute_value, CAST(A.attribute_value as SIGNED) as bin_value, A.article_count,B.unit FROM modus_articles_attributes AS A LEFT JOIN modus_cat_attributes as B on B.uid = A.attribute_uid WHERE A.store_uid = '".intval($_POST['store_uid'])."' GROUP BY A.attribute_uid, A.attribute_value ORDER by bin_value ASC, A.attribute_value ASC "; $attributeValuesData = $db->fetchAssocArray($sql); $attributeValues = array(); if(empty($suggestKeys)== false ) { foreach ($attributeValuesData as $key => $nextAttributeData) { if(is_array( $suggestPreset[$nextAttributeData['attribute_uid']]) == false) { // print_r($nextAttributeData); continue; } if(in_array($nextAttributeData['attribute_value'], $suggestPreset[$nextAttributeData['attribute_uid']]) ) $attributeValues[$nextAttributeData['attribute_uid']][] = $nextAttributeData; } } else { foreach ($attributeValuesData as $key => $nextAttributeData) { $attributeValues[$nextAttributeData['attribute_uid']][] = $nextAttributeData; } } //print_r($categories); //echo '
'; //print_r($attributeValues); $tpl->set('postData', $_POST); $tpl->set('categories', $categories); $tpl->set('resultCategories', $resultCats); $tpl->set('attributeValues', $attributeValues); echo $tpl->fetch('templates/searchNEW.tpl');