HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/php/page_searchresults.php
<?php


function initSearchResults(){
	// init searchresults \\
	$output = '';
	
	if($_SESSION['search']){
		$search = strip_tags($_SESSION['search']);
		
		$output .= '<h1>Je zocht voor "'.$search.'"</h1>';
		
		$searchoutput = '';
		$searchoutput .= searchForItems($search);
		$searchoutput .= searchForCollection($search);
		
		$trim = trim($searchoutput);
		if(!empty($trim)){
			$output .= $searchoutput;	
		}
		else{
			$output .= 'Er zijn helaas geen resultaten gevonden, controleer je spelling of probeer een ander zoekwoord.';	
		}
	}
	
	return $output;
}


function searchForCollection($search){
	global $mysqli;
	$output = '';

	$search = inDatabase($search);

	$query = 'SELECT product.id as productId,
					 product.titleNL,
					 product.published,
					 product.catId,
					 product.price,
					 product.discountPrice,
					 product.isNew,
					 product.thumb,
					 product.hover,
					 product.color,

					 routes.route_nl,
					 routes.route_en
			  	FROM product_products AS product

			  	RIGHT JOIN content_status AS stat ON stat.itemId = product.id

			  	LEFT JOIN routes ON routes.routeable_id = product.id
			  	AND routes.routeable_type = "product"

			  	LEFT JOIN product_searchtags AS tags ON tags.productId = product.id

			  	WHERE stat.active = 1
              	AND stat.linkname = "product_products"

				AND( product.titleNL LIKE "%'.$search.' %"
					OR product.descriptionNL LIKE "% '.$search.' %"
					OR product.specsNL LIKE "%'.$search.' %"
					OR product.titleEN LIKE "%'.$search.' %"
					OR product.descriptionEN LIKE " %'.$search.' %"
					OR product.specsEN LIKE "% '.$search.' %"
					OR tags.searchtag LIKE "%'.$search.'%" )

			  GROUP BY product.id,
					 product.titleNL,
					 product.published,
					 product.catId,
					 product.price,
					 product.discountPrice,
					 product.isNew,
					 product.thumb,
					 product.hover,
					 product.color,

					 routes.route_nl,
					 routes.route_en';


	/*$query = 'SELECT DISTINCT i.id AS instanceId, i.productId, i.shortcode, i.color, p.titleNL, p.published, p.catId, p.price, p.discountPrice, p.isNew, p.thumb, p.hover
								 FROM product_products AS p, product_instances AS i, content_status AS s, product_searchtags AS t
								 WHERE s.active = 1
								 AND s.linkname = "product_products"
								 AND s.itemId = p.id
								 AND p.id = i.productId
								 AND p.id = t.productId
								 AND p.published = 1
								 AND( p.titleNL LIKE "%'.$search.' %"
								 OR p.descriptionNL LIKE "% '.$search.' %"
								 OR p.specsNL LIKE "%'.$search.' %"
								 OR p.titleEN LIKE "%'.$search.' %"
								 OR p.descriptionEN LIKE " %'.$search.' %"
								 OR p.specsEN LIKE "% '.$search.' %"
								 OR t.searchtag LIKE "%'.$search.'%" )';*/




	if($result = $mysqli->query($query)){
		if($result->num_rows > 0){

			$output .= '<h2>gevonden in onze collectie</h2><br /><br />';
			$output .= '<div class="clear"></div>';
		
			$output .= '<div class="collection-items quintuple-column">'; 
				
				$_SESSION['colorCatArr'] = array();

		
				while($record = $result->fetch_assoc()){
					$titleNL = $record['titleNL'];

					//create productid
					$productId = $record['productId'];

					$route = $record['route_nl'];

					$title = $record['titleNL'];
					$linkTitle = linkname($title);
					$hexcolor = $record['color'];

					//price
					$price = $record['price'];

					//new ? 
					$new = 0;
					
					#color category
					$hexR = substr($hexcolor,0,2);
					$hexG = substr($hexcolor,2,2);
					$hexB = substr($hexcolor,4,2);
		
					$decR = hexdec($hexR);
					$decG = hexdec($hexG);
					$decB = hexdec($hexB);
					
					$hsl = rgbhsv($decR,$decG,$decB);
					$colorName = returnColorName($hsl);
					$colorCat = returnColorCat($colorName);

                    //thumbnail
                    $thumbShortCode = $record['thumb'];
                    $hoverShortCode = $record['hover'];

                    $thumb = '';
                    $thumbQuery =  'SELECT title, filename_medium, filename_small
										FROM media_files
										WHERE shortcode = "'.$thumbShortCode.'" LIMIT 1';
                    if($thumbResult = $mysqli->query($thumbQuery)){
                        $thumbRecord = $thumbResult->fetch_assoc();
                        #thumb
                        if(!empty($thumbRecord['filename_small']) && is_file(DOCUMENT_ROOT . '/images/uploads/'.$thumbRecord['filename_small']) ){ $thumb = '/images/uploads/'.$thumbRecord['filename_small']; }
                        else{ $thumb = '/images/uploads/'.$thumbRecord['filename_medium']; }
                    }

                    # hover ?
                    if($hoverShortCode != $thumbShortCode && ! empty($hoverShortCode))
                    {
                        $hoverQuery =  'SELECT filename_medium, filename_small
										FROM media_files
										WHERE shortcode = "'.$hoverShortCode.'" LIMIT 1';
                        if($hoverResult = $mysqli->query($hoverQuery)){
                            $hoverRecord = $hoverResult->fetch_assoc();
                            #hover
                            if(!empty($hoverRecord['filename_small']) && is_file(DOCUMENT_ROOT . '/images/uploads/'.$hoverRecord['filename_small']) ){ $hover = '/images/uploads/'.$hoverRecord['filename_small']; }
                            else{ $hover = '/images/uploads/'.$hoverRecord['filename_medium']; }
                        }
                    }
                    else
                    {
                        $hover = '';
                    }

                    if(empty($thumb)){
                        // if no image
                        $thumb = '/images/structure/noimage.jpg';
                    }
				
					$output .= '<div class="product-thumb-holder" data-color="'.$colorCat.'">';
						//output image
						$output .= '<div class="product-thumb-image">';
							if($new == 1) $output .= '<div class="product-thumb-new"><h3>nieuw!</h3></div>';
							
							$output .= '<a href="/' . $route . '">';
								// if empty hover show original image as hover
								if(!empty($hover)){ $output .= '<img src="'.$hover.'" alt="Deense Kroon sieraad genaamd '.$title.'" width="160" class="collection_hover" id="product"/>'; }
								else{  $output .= '<img src="'.$thumb.'" alt="Deense Kroon sieraad genaamd '.$title.'" width="160" class="collection_hover" id="product"/>'; }
								$output .= '<img src="/images/structure/spacer.gif" data-src="'.$thumb.'" alt="Deense Kroon sieraad genaamd '.$title.'"  width="160" class="non-hover preload"/>';
							$output .= '</a>';
						$output .= '</div>';
						
						//output title
						$output .= '<div class="product-thumb-title">
										<a href="/' . $route . '">'.$title.'</a>
									</div>';
						//output bottom
						$output .= '<a href="/' . $route . '""><span class="icon-arrow"></span></a>';
					$output .= '</div>';
			}				
			$output .= '<div class="clear"></div>';
			$output .= '</div>';

		}
	
	}
	
	return $output;
}

function searchForItems($search){
	global $mysqli;
	$output = '';
	
	
	$searchMpArr = array();

	$searchMpArr[] = 'over';
	$searchMpArr[] = 'merken';
	$searchMpArr[] = 'contact';
	$searchMpArr[] = 'voorwaarden';
	$searchMpArr[] = 'levering';
	$searchMpArr[] = 'betalen';
	$searchMpArr[] = 'faq';
	foreach($searchMpArr as $key => $value){
	
		if($result = $mysqli->query('SELECT p.title 
									 FROM '.$value.' AS p, content_status AS s
									 WHERE s.active = 1
									 AND s.linkname = "'.$value.'"
									 AND s.itemId = p.id
									 AND ( p.title LIKE "% '.$search.' %"
									 OR p.description LIKE "% '.$search.' %" )')){
										 
			if($result->num_rows > 0){							 
				$output .= '<h2>resultaat in '.$value.'</h2>';
				$output .= '<div class="clear"></div>';
			
				while($record = $result->fetch_assoc()){
					$title = $record['title'];
					$linkname = linkname($record['title']);
					
					switch($value){
						case 'over':
							$output .= '<a href="/vertelt-over-zichzelf/">'.$title.'</a><br />';
						break;	
						case 'merken':
							$output .= '<a href="/toont-haar-collectie/van-het-merk/'.$linkname.'/">'.$title.'</a><br />';
						break;		
						case 'contact':
							$output .= '<a href="/contact/">'.$title.'</a><br />';
						break;	
						case 'voorwaarden':
							$output .= '<a href="/voorwaarden/">'.$title.'</a><br />';
						break;	
						case 'levering':
							$output .= '<a href="/levering/">'.$title.'</a><br />';
						break;	
						case 'betalen':
							$output .= '<a href="/betalen/">'.$title.'</a><br />';
						break;	
					}
				}
			}
		}
	}
	if(!empty($output)){
		$output .= '<div class="clear"></div>';
		$output .= '<hr />';
	}
	return $output;
}




?>