<?php
	include_once "system_start.php";
	if ( isset( $_REQUEST[ "id" ] ) ) {
		$array_store = query_array_row( "SELECT * FROM `priv_stores` LEFT JOIN `priv_sites_countries` ON `sico_id` = `stor_country` WHERE `stor_active` = '1' AND `stor_link` = '" . res( $_REQUEST[ "id" ] ) . "'" );
		if ( count( $array_store ) > 0 ) {
			$array_store_parent = query_array_row( "SELECT `stor_link` FROM `priv_stores_sons` LEFT JOIN `priv_stores` ON `stor_id` = `stso_store` WHERE `stso_son` = '" . res( $array_store[ "stor_id" ] ) . "'" );
			if ( count( $array_store_parent ) > 0 ) {
				header( "location: /store/" . $array_store_parent[ "stor_link" ] );
			} else {
				if ( count( $array_store ) > 0 ) {
                    $result_store_deals = query_array_all( "SELECT `deal_id` FROM `priv_deals` LEFT JOIN `priv_deals_discounts` ON `dedi_id` = `deal_discount` WHERE `deal_active` = '1' AND `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' ORDER BY IFNULL( ( SELECT ( `nepr_priority` + `netw_priority` ) AS `priority` FROM `priv_networks_stores` LEFT JOIN `priv_networks` ON `netw_id` = `nest_network` LEFT JOIN `priv_networks_affiliations` ON `neaf_network_store` = `nest_id` LEFT JOIN `priv_networks_accounts` ON `neac_id` = `neaf_account` LEFT JOIN `priv_networks_profiles` ON `nepr_id` = `neac_profile` WHERE `netw_active` = '1' AND `neaf_active` = '1' AND `neaf_approved` = '1' AND `neac_active` = '1' AND `nepr_active` = '1' AND `nest_store` = `deal_store` AND `neaf_coupon` =  `deal_code` ), -1 ) DESC, `dedi_order` ASC, `deal_discount_amount` DESC LIMIT 100" );
                    // $result_store_deals = query_array_all( "SELECT `deal_id` FROM `priv_deals` LEFT JOIN `priv_deals_discounts` ON `dedi_id` = `deal_discount` WHERE `deal_active` = '1' AND `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' ORDER BY `dedi_order` ASC, `deal_discount_amount` DESC LIMIT 100" );
					// $row_store_followers = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count` FROM `priv_stores_followers` WHERE `foll_owner` = '" . res( $array_store[ "stor_id" ] ) . "'" );
					$row_store_votes = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count`, ROUND( IFNULL( AVG( `vote_value` ), 5 ), 1 ) AS `avg` FROM `priv_stores_votes` WHERE `vote_owner` = '" . res( $array_store[ "stor_id" ] ) . "'" );
					// $row_store_alerts = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count` FROM `priv_stores_alerts` WHERE `aler_owner` = '" . res( $array_store[ "stor_id" ] ) . "'" );
					$row_store_networks = query_array_row( "SELECT `neaf_link` FROM `priv_networks_affiliations` LEFT JOIN `priv_networks_stores` ON `nest_id` = `neaf_network_store` LEFT JOIN `priv_networks_accounts` ON `neac_id` = `neaf_account` LEFT JOIN `priv_networks_profiles` ON `nepr_id` = `neac_profile` LEFT JOIN `priv_stores` ON `stor_id` = `nest_store` LEFT JOIN `priv_networks` ON `netw_id` = `neac_network` WHERE `nest_store` = '" . res( $array_store[ "stor_id" ] ) . "' AND `stor_active` = '1' AND `netw_active` = '1' AND `neaf_active` = '1' AND `nepr_active` = '1' AND `nest_active` = '1' AND `neac_active` = '1' AND `neaf_approved` = '1' ORDER BY `nepr_priority` DESC, `netw_priority` DESC, RAND()" );
					if ( user_login() ) {
						$row_store_follower = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count` FROM `priv_stores_followers` WHERE `foll_owner` = '" . res( $array_store[ "stor_id" ] ) . "' AND `foll_user` = '" . res( user_id() ) . "'" );
						$row_store_vote = query_array_row( "SELECT `vote_value` FROM `priv_stores_votes` WHERE `vote_owner` = '" . res( $array_store[ "stor_id" ] ) . "' AND `vote_user` = '" . res( user_id() ) . "'" );
						$row_store_alert = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count` FROM `priv_stores_alerts` WHERE `aler_owner` = '" . res( $array_store[ "stor_id" ] ) . "' AND `aler_user` = '" . res( user_id() ) . "'" );
						// $row_store_comment = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `count` FROM `priv_stores_comments` WHERE `comm_owner` = '" . res( $array_store[ "stor_id" ] ) . "' AND `comm_user` = '" . res( user_id() ) . "'" );
					}
					query( "INSERT INTO `priv_stores_views` ( `stvi_site`, `stvi_store`, `stvi_user` ) VALUES( '" . res( $array_system_site[ "site_id" ] ) . "', '" . res( $array_store[ "stor_id" ] ) . "', " . isnullforquery( user_id() ) . " )" );
					echo "<!doctype html>";
					echo "<html lang='" . htm( $system_language_code ) . "'>";
						echo "<head>";
							include_once "system_heads.php";
							$title = $array_store[ "stor_name" ] . " " . tra( "discount codes, coupons & deals" );
							$description = tra( "Best deals, codes and coupons of VAR1. Newest and most accurate coupons, deals and offers we find from all online stores.", array( $array_store[ "stor_name" ] ) ) . " " . $array_system_site[ "site_name" ] . ". " . tra( date( "M" ) ) . " " . date( "Y" ) . "." ;
							$domain = "https://" . $_SERVER[ "HTTP_HOST" ];
							$image = $domain . "/images/stores/" . $array_store[ "stor_logo_name" ];
							$url = $domain . $_SERVER[ "REQUEST_URI" ];
							echo "<link rel='canonical' href='https://" . $array_system_site[ "site_domain" ] . "/" . strtolower( tra( "store" ) ) . "/" . $array_store[ "stor_link" ] . "'>";
							echo "<meta name='keywords' content='" . htm( $array_system_site[ "site_keywords" ] ) . "'>";
							echo "<meta name='robots' content='" . ( $robot = ( count(  $result_store_deals ) > 0 ? "index" : "noindex" ) . ", follow" ) . "'>";
							echo "<meta name='googlebot' content='" . $robot . "'>";
							echo "<meta name='bingbot' content='" . $robot . "'>";
							echo "<meta name='description' content='" . htm( $description ) . "'>";
							echo "<meta property='og:title' content='" . htm( $title ) . "'>";
							echo "<meta property='og:image' content='" . $image . "'>";
							echo "<meta property='og:description' content='" . htm( $description ) . "'>";
							echo "<meta property='og:url' content='" . $url . "'>";
							echo "<meta property='og:type' content='website'>";
							echo "<meta name='twitter:card' content='summary_large_image'>";
							echo "<meta name='twitter:site' content='@couponifier1'>";
							echo "<meta name='twitter:title' content='" . htm( $title ) . "'>";
							echo "<meta name='twitter:description' content='" . htm( $description ) . "'>";
							echo "<meta name='twitter:creator' content='@couponifier1'>";
							echo "<meta name='twitter:image' content='" . $image . "'>";
							echo "<meta name='twitter:domain' content='" . $domain . "'>";
							echo "<title>" . htm( $array_store[ "stor_name" ] ) . " " . tra( "discount codes" ) . ". " . tra( date( "M" ) ) . " " . date( "Y" ) . " - " . htm( $array_system_site[ "site_title" ] ) . "</title>";
						echo "</head>";
						echo "<body>";
							echo "<main>";
								include_once "system_header.php";
								echo "<content>";
									echo "<div class='container'>";
										echo "<div class='row'>";
											echo "<div class='col'><br>";
												echo "<div class='row'>";
													echo "<div class='col-auto'>";
														echo "<img class='object-fit-contain bg-white border shadow p-2' src='" . image_store( $array_store[ "stor_logo_name" ] ) . "' width='200' height='100' alt='" . htm( $array_store[ "stor_name" ] ) . "' title='" . htm( $array_store[ "stor_name" ] ) . "'>";
													echo "</div>";
													echo "<div class='col-auto'>";
														echo "<div class='row'>";
															echo "<h1>" . htm( $array_store[ "stor_name" ] ) . " " . tra( "discount codes, coupons & deals" ) . "</h1>";
														echo "</div>";
														echo "<div class='row row-cols-auto align-items-start'>";
															echo "<div class='col'><a href='" . ( count( $row_store_networks ) > 0 ? $row_store_networks[ "neaf_link" ] : "https://" . $array_store[ "stor_link" ] ) . "' target='_BLANK'><i class='fas fa-store'></i> " . $array_store[ "stor_link" ] . "</a></div>";
															echo "<div class='col'><a class='text-" . ( $row_store_follower[ "count" ] > 0 ? "primary" : "secondary" ) . "' href='" . ( user_login() ? "/follow/stores/" . $array_store[ "stor_id" ] . "/" . md5( $array_store[ "stor_id" ] . $_SESSION[ "user_token" ] ) : "/login/" . base64url_encode( $_SERVER[ "REQUEST_URI" ] ) ) . "' rel='nofollow'><i class='fas fa-heart'></i> " . tra( "Follow" ) . "</a></div>";
															echo "<div class='col'><a class='text-" . ( $row_store_alert[ "count" ] > 0 ? "primary" : "secondary" ) . "' href='" . ( user_login() ? "/alert/stores/" . $array_store[ "stor_id" ] . "/" . md5( "alert" . $_SESSION[ "user_token" ] . $array_store[ "stor_id" ] ) : "/login/" . base64url_encode( $_SERVER[ "REQUEST_URI" ] ) ) . "' rel='nofollow'><i class='fas fa-bell'></i> " . tra( "Alert" ) . "</a></div>";
															echo "<div class='col'>";
																sharemenu( tra( "Share" ), urlfull() );
															echo "</div>";
															echo "<div class='col'>";
																for ( $i = 1; $i <= 5; $i++ ) {
																	echo "<a href='" . ( user_login() ? ( "/vote/stores/" . $array_store[ "stor_id" ] . "/" . $i . "/" . md5( $array_store[ "stor_id" ] . $i . $_SESSION[ "user_token" ] ) ) : ( "/login/" . base64url_encode( $_SERVER[ "REQUEST_URI" ] ) ) ) . "' class='" . ( $row_store_vote[ "vote_value" ] < $i ? "text-muted " : "" ) . "me-1' onmouseover='vote( this, " . $i . " );' onmouseout='vote( this, " . round( $row_store_vote[ "vote_value" ] ) . " );' rel='nofollow'><i class='" . ( $i > round( $row_store_votes[ "avg" ] ) ? "far" : "fas" ) . " fa-star'></i></a>";
																}
																echo " " . $row_store_votes[ "avg" ] . " (" . $row_store_votes[ "count" ] . ")";
															echo "</div>";
															echo "<div class='col'><a href='" . ( user_login() ? ( "/report/stores/" . $array_store[ "stor_id" ] . "/" . base64url_encode( $array_store[ "stor_name" ] ) ) : ( "/login/" . base64url_encode( $_SERVER[ "REQUEST_URI" ] ) ) ) . "' rel='nofollow'><i class='fas fa-flag'></i> " . tra( "Report" ) . "</a></div>";
															$row_store_socialnetworks = query_array_all( "SELECT `soli_link`, `stso_name`, `stso_icon` FROM `priv_stores_socialnetworks_lists` LEFT JOIN `priv_stores_socialnetworks` ON `stso_id` = `soli_socialnetwork` WHERE `soli_store` = '" . res( $array_store[ "stor_id" ] ) . "' ORDER BY `stso_order` ASC" );
															if ( count( $row_store_socialnetworks ) > 0 ) {
																echo "<div class='col'>";
																	foreach ( $row_store_socialnetworks as $row_store_socialnetwork ) {
																		echo "<a href='" . htm( $row_store_socialnetwork[ "soli_link" ] ) . "' title='" . htm( $row_store_socialnetwork[ "stso_name" ] ) . "' target='_BLANK' rel='nofollow' class='me-1'><i class='" . htm( $row_store_socialnetwork[ "stso_icon" ] ) . "'></i></a>";
																	}
																echo "</div>";
															}
															$row_store_payments_methods = query_array_all( "SELECT `pame_link`, `pame_name`, `pame_icon` FROM `priv_stores_payments_methods` LEFT JOIN `priv_stores_payments_methods_lists` ON `meli_payment_method` = `pame_id` AND `meli_store` = '" . res( $array_store[ "stor_id" ] ) . "' WHERE `meli_id` IS NOT NULL ORDER BY `pame_order` ASC" );
															if ( count( $row_store_payments_methods ) > 0 ) {
																echo "<div class='col'>";
																	foreach ( $row_store_payments_methods as $row_store_payments_method ) {
																		echo "<a href='" . htm( $row_store_payments_method[ "pame_link" ] ) . "' title='" . htm( $row_store_payments_method[ "pame_name" ] ) . "' target='_BLANK' rel='nofollow' class='me-1'><i class='" . htm( $row_store_payments_method[ "pame_icon" ] ) . "'></i></a>";
																	}
																echo "</div>";
															}
															if ( !empty( $array_store[ "stor_country" ] ) and $array_store[ "stor_country" ] <> "999" ) {
																echo "<div class='col'>";
																	$image_country = "images/countries/" . htm( strtolower( $array_store[ "sico_code" ] ) ) . ".svg";
																	if ( file_exists( $image_country ) ) {
																		echo "<img src='/" . $image_country . "' width='20' height='15' class='object-fit-contain bg-white me-1' alt='" . htm( $array_store[ "sico_name" ] ) . "' title='" . htm( $array_store[ "sico_name" ] ) . "'>";
																	}
																	echo tra( $array_store[ "sico_name" ] );
																echo "</div>";
															}
															if ( user_can( "admin_deal_insert.php" ) ) {
																echo "<div class='col'><a href='/admin_deal_insert.php?step=deal&store=" . htm( $array_store[ "stor_id" ] ) . "' rel='nofollow'><i class='fas fa-plus'></i> Add deal</a></div>";
															}
															if ( user_can( "admin_store.php" ) ) {
																echo "<div class='col'><a href='/admin_store.php?id=" . htm( $array_store[ "stor_id" ] ) . "' rel='nofollow'><i class='fas fa-edit'></i> Edit</a></div>";
															}
														echo "</div>";
													echo "</div>";
												echo "</div><br>";
												
												if ( count( $result_store_deals ) > 0 ) {
													echo "<div class='card mb-3'>";
														echo "<div class='card-header border-bottom'><h5 class='mt-2'>" . tra( "Codes and promotions" ) . "</h5></div>";
														echo "<div class='table-responsive scrollbar'>";
															echo "<table class='table table-striped table-hover'>";
																echo "<thead>";
																	echo "<tr>";
																		echo "<th scope='col'><i class='fas fa-image'></i> " . tra( "Image" ) . "</th>";
																		echo "<th scope='col'><i class='fas fa-heading'></i> " . tra( "Title" ) . "</th>";
																		echo "<th scope='col'><i class='fas fa-comments'></i> " . tra( "Comments" ) . "</th>";
																		echo "<th scope='col'><i class='fas fa-ticket'></i> " . tra( "Coupon" ) . "</th>";
																	echo "</tr>";
																echo "</thead>";
																echo "<tbody>";
																	foreach ( $result_store_deals as $row_store_deal ) {
																		$row_store_deal     = query_array_row( "SELECT * FROM `priv_deals` LEFT JOIN `priv_deals_discounts` ON `dedi_id` = `deal_discount` WHERE `deal_id` = '" . res( $row_store_deal[ "deal_id" ] ) . "'" );
																		// $row_deal_followers = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `total` FROM `priv_deals_followers` WHERE `foll_owner` = '" . res( $row_store_deal[ "deal_id" ] ) . "'" ); 
																		$row_deal_votes     = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `total`, IFNULL( SUM( IF( `vote_value` > 0, 1, 0 ) ), 0 ) AS `positives`, IFNULL( SUM( IF( vote_value < 0, 1, 0 ) ), 0 ) AS `negatives` FROM `priv_deals_votes` WHERE `vote_owner` = '" . res( $row_store_deal[ "deal_id" ] ) . "'" );
																		// $row_deal_views     = query_array_row( "SELECT IFNULL( SUM( 1 ), 0 ) AS `total` FROM `priv_deals_views` WHERE `devi_deal` = '" . res( $row_store_deal[ "deal_id" ] ) . "'" );
																		$row_deal_comments  = query_array_row( "SELECT COUNT( `comm_id` ) AS `total` FROM `priv_deals_comments` LEFT JOIN `priv_users` ON `user_id` = `comm_user` WHERE `comm_owner` = '" . res( $row_store_deal[ "deal_id" ] ) . "' AND `user_site` = '" . res( $array_system_site[ "site_id" ] ) . "'" );
																		if ( user_login() ) {
																			$result_deal_follow = $mysqli->query( "SELECT `foll_id` FROM `priv_deals_followers` WHERE `foll_owner` = '" . res( $row_store_deal[ "deal_id" ] ) . "' AND `foll_user` = '" . res( user_id() ) . "'" );
																			$row_deal_follow = ( ( $result_deal_follow->num_rows > 0 ) ? $result_deal_follow->fetch_assoc() : array() );
																		} else {
																			$row_deal_follow = array();
																		}
																		if ( user_login() and ( $row_deal_votes[ "total" ] > 0 ) ) {
																			$result_deal_vote = $mysqli->query( "SELECT `devo_value` FROM `priv_deals_votes` WHERE `devo_deal` = '" . res( $row_store_deal[ "deal_id" ] ) . "' AND `devo_user` = '" . res( user_id() ) . "'" );
																			$row_deal_vote = ( ( $result_deal_vote->num_rows > 0 ) ? $result_deal_vote->fetch_assoc() : array() );
																		} else {
																			$row_deal_vote = array();
																		}
																		echo "<tr" . ( ( !empty( $row_store_deal[ "neaf_id" ] ) and 1 === 2 ) ? " class='table-primary'" : "" ) . ">";
																			echo "<td><a href='/" . image_deal( $row_store_deal[ "deal_id" ] ) . "' target='_BLANK' rel='nofollow'><img class='object-fit-contain bg-white border shadow p-2' src='" . image_deal( $row_store_deal[ "deal_id" ] ) . "' width='150' height='75' alt='" . htm( $array_store[ "stor_name" ] ) . " discount code' title='" . htm( $array_store[ "stor_name" ] ) . "'></a></td>";
																			echo "<td><i class='" . htm( $row_store_deal[ "dedi_icon" ] ) . "'></i> " . htm( $row_store_deal[ "deal_title" ] ) . " at " . htm( $array_store[ "stor_name" ] ) . ( ( !empty( $row_store_deal[ "neaf_id" ] ) and 1 === 2 ) ? "<br><br><i class='fas fa-circle-check'></i> Verified" : "" ) . "</td>";
																			echo "<td><a href='/" . strtolower( tra( "deal" ) ) . "/" . $array_store[ "stor_link" ] . "/" . $row_store_deal[ "deal_id" ] . "#comments' rel='nofollow'>" . htm( $row_deal_comments[ "total" ] ) . "</a></td>";
																			echo "<td><h5>" . tra( "COPY CODE" ) .": <a href='https://" . $array_store[ "stor_link" ]  . "' onclick='copyToClipboard( `" . htm( $row_store_deal[ "deal_code" ] ) . "` ); window.open( `" . ( count( $row_store_networks ) > 0 ? $row_store_networks[ "neaf_link" ] : "https://" . $array_store[ "stor_link" ] ) . "`, `_self` ); window.open( `/store/" . $array_store[ "stor_link" ] . "`, `_blank` ); event.preventDefault();" . "' rel='nofollow'><i class='fas fa-copy'></i> " . htm( strtoupper( $row_store_deal[ "deal_code" ] ) ) . "</a></h5></td>";
																		echo "</tr>";
																	}
																echo "</tbody>";
															echo "</table>";
														echo "</div>";
													echo "</div>";
												}
                                                $result_store_description = query_array_row( "SELECT `stde_description` FROM `priv_stores_descriptions` WHERE `stde_language` = '" . res( $array_system_site[ "site_language" ] ) . "' AND `stde_store` = '" . res( $array_store[ "stor_id" ] ) . "'" );
												if ( count( $result_store_description ) > 0 ) {
                                                    echo "<div class='card mb-3'>";
                                                        echo "<div class='card-body'>";
                                                            echo "<h4>" . htm( $array_store[ "stor_name" ] ) . " " . tra( "description" ) . "</h4>";
                                                            echo "<p>" . nl2br( htm( $result_store_description[ "stde_description" ] ) ) . "</p>";
                                                        echo "</div>";
                                                    echo "</div>";
                                                }
												$result_store_categories = query_array_all( "SELECT `stca_id`, `stca_name` FROM `priv_stores_categories_lists` LEFT JOIN `priv_stores_categories` ON `stca_id` = `cali_category` WHERE `cali_store` = '" . res( $array_store[ "stor_id" ] ) . "' ORDER BY `stca_name` ASC" );
												if ( count( $result_store_categories ) > 0 ) {
													echo "<div class='card mb-3'>";
														echo "<div class='card-body'>";
															echo "<h4>" . tra( "Store categories" ) . "</h4>";
															foreach ( $result_store_categories as $result_store_category ) {
																echo "<a class='btn btn-primary m-1' href='/category/" . htm( strtolower( $result_store_category[ "stca_name" ] ) ) . "' role='button'>" . htm( $result_store_category[ "stca_name" ] ) . "</a>";
															}
														echo "</div>";
													echo "</div>";
												}
												// $result_deal_times = query_array_all( "SELECT UPPER( `deal_code` ) AS `code`, COUNT( `deal_code` ) AS `times` FROM `priv_deals_logs` WHERE `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' AND `deal_active` = '1' GROUP BY `deal_code` HAVING `times` > '1' ORDER BY `times` DESC LIMIT 20" );
												// if ( count( $result_deal_times ) > 0 ) {
												// 	echo "<div class='card mb-3'>";
												// 		echo "<div class='card-body'>";
												// 			echo "<h4>" . tra( "Coupon code phrases" ) . "</h4>";
												// 			foreach ( $result_deal_times as $result_deal_time ) {
												// 				echo "<span class='badge text-bg-primary m-1'>" . $result_deal_time[ "code" ] . " (" . $result_deal_time[ "times" ] . " " . tra( "times" ) . ")</span>";
												// 			}
												// 		echo "</div>";
												// 	echo "</div>";
												// }
                                                $result_captures = query_array_all( "SELECT `stan_id`, `stan_insert` FROM `priv_stores_answers` WHERE `stan_store` = '" . res( $array_store[ "stor_id" ] ) . "' ORDER BY `stan_insert` DESC" );
                                                if ( count( $result_captures ) > 0 ) {
                                                    echo "<div class='card mb-3'>";
                                                        echo "<div class='card-body'>";
                                                            echo "<h4>" . tra( "Captures" ) . "</h4>";
                                                            echo "<div class='row row-cols-1 row-cols-md-4 g-4'>";
                                                                foreach ( $result_captures as $result_capture ) {
                                                                    echo "<div class='col'>";
                                                                        $image_store_thumbnail = "images/stores_thumbnails/store_thumbnail_" . str_pad( $result_capture[ "stan_id" ], 8, "0", STR_PAD_LEFT ) . ".jpg";
                                                                        if ( file_exists( $image_store_thumbnail ) ) {
                                                                            echo "<a href='/images/stores_screenshots/store_screenshot_" . str_pad( $result_capture[ "stan_id" ], 8, "0", STR_PAD_LEFT ) . ".jpg' target='_BLANK'><img class='object-fit-contain bg-white border shadow p-2 mt-3' src='/" . $image_store_thumbnail . "' width='300' height='200' alt='" . ( $capture_alt = htm( $array_store[ "stor_name" ] . " " . tra( "capture" ) . " - " . $result_capture[ "stan_insert" ] ) ) . "' title='" . $capture_alt . "'></a><br>";
                                                                        }
                                                                    echo "</div>";
                                                                }
                                                            echo "</div>";
                                                        echo "</div>";
                                                    echo "</div>";
                                                }
												// $result_products = query_array_all( "SELECT `prod_id` FROM `priv_products` WHERE `prod_store` = '" . res( $array_store[ "stor_id" ] ) . "' UNION DISTINCT SELECT `stpr_product` FROM `priv_stores_products` WHERE `stpr_store` = '" . res( $array_store[ "stor_id" ] ) . "'" );
												// if ( count( $result_products ) > 0 ) {
												// 	echo "<h5>Products</h5>";
												// 	echo "<div class='row justify-content-center'>";
												// 	foreach ( $result_products as $result_product ) {
												// 		$result_product = query_array_row( "SELECT * FROM `priv_products` WHERE `prod_id` = '" . res( $result_product[ "prod_id" ]) . "'" );
												// 		echo "<div class='col'>";
												// 			echo "<div class='card m-1 shadow-sm' style='width: 18rem;'>";
												// 				echo "<div class='card-header'>" . htm( $result_product[ "prod_name" ] ) . "</div>";
												// 				echo "<div class='card-body'>";
												// 					echo "<a href='/product.php?id=" . htm( $result_product[ "prod_id" ] ) . "'>";
												// 						echo "<div class='text-center'>";
												// 							echo "<img src='" . image_product( $result_product[ "prod_id" ] ) . "' width='80' height='80' class='object-fit-contain bg-white border rounded shadow p-2' alt='" . htm( $result_product[ "prod_name" ] ) . "' title='" . htm( $result_product[ "prod_name" ] ) . "'>";
												// 						echo "</div>";
												// 					echo "</a>";
												// 				echo "</div>";
												// 				echo "<div class='card-footer'>";
												// 					echo "<div class='text-center justify-content-around d-flex flex-row'>";
												// 					echo "</div>";
												// 				echo "</div>";
												// 			echo "</div>";
												// 		echo "</div>";
												// 	}
												// 	echo "</div>";
												// }
												$array_deals_details = array();
												$array_deals_details[] = array( "title" => tra( "Scopes"            ), "query" => "SELECT `desc_name` AS `name`, COUNT( `deal_scope` ) AS `total`, ( 'fas fa-tag' ) AS `icon` FROM `priv_deals_scopes` LEFT JOIN `priv_deals` ON `deal_scope` = `desc_id` AND `deal_active` = '1' AND `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' GROUP BY `desc_id`" );
												$array_deals_details[] = array( "title" => tra( "Discounts"         ), "query" => "SELECT `dedi_name` AS `name`, COUNT( `deal_discount` ) AS `total`, ( `dedi_icon` ) AS `icon` FROM `priv_deals_discounts` LEFT JOIN `priv_deals` ON `deal_discount` = `dedi_id` AND `deal_active` = '1' AND `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' GROUP BY `dedi_id`" );
												$array_deals_details[] = array( "title" => tra( "Coupons per month" ), "query" => "SELECT `month_list`.`month_number`, MONTHNAME( CONCAT( '2020-', `month_list`.`month_number`, '-01' ) ) AS `name`, LEFT( MONTHNAME( CONCAT( '2020-', `month_list`.`month_number`, '-01' ) ), 3 ) AS `month_abbreviation`, IFNULL( `month_data`.`month_total`, 0 ) AS `total`, ( 'fas fa-calendar-days' ) AS `icon` FROM ( SELECT 1 AS `month_number` UNION SELECT 2 AS `month_number` UNION SELECT 3 AS `month_number` UNION SELECT 4 AS `month_number` UNION SELECT 5 AS `month_number` UNION SELECT 6 AS `month_number` UNION SELECT 7 AS `month_number` UNION SELECT 8 AS `month_number` UNION SELECT 9 AS `month_number` UNION SELECT 10 AS `month_number` UNION SELECT 11 AS `month_number` UNION SELECT 12 AS `month_number` ) AS `month_list` LEFT JOIN ( SELECT MONTH( `deal_insert` ) AS `month_number`, COUNT( `deal_id` ) AS `month_total` FROM `priv_deals` WHERE `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' GROUP BY MONTH( `deal_insert` ) ORDER BY `month_number` ASC ) `month_data` ON `month_data`.`month_number` = `month_list`.`month_number`" );
												if ( count( $array_deals_details ) > 0 ) {
													echo "<div class='row row-cols-1 row-cols-sm-1 row-cols-md-3 mb-2'>";
														foreach ( $array_deals_details as $array_deals_detail ) {
															$array_deals_types = query_array_all( $array_deals_detail[ "query" ] );
															if ( count( $array_deals_types ) > 0 ) {
																echo "<div class='col'>";
																	echo "<div class='card mb-2 h-100'>";
																		echo "<div class='card-header'>"  . htm( $array_deals_detail[ "title" ] ) . "</div>";
																		echo "<ul class='list-group list-group-flush'>";
																			foreach ( $array_deals_types as $array_deals_type ) {
																				echo "<li class='list-group-item'>" . ( $array_deals_type[ "icon" ] <> "" ? "<i class='" . htm( $array_deals_type[ "icon" ] ) . "'></i> " : "" ) . htm( $array_deals_type[ "name" ] ) . ": <a href='#' rel='nofollow' onclick='event.preventDefault();'>" . htm( $array_deals_type[ "total" ] ) . "</a></li>";
																			}
																		echo "</ul>";
																	echo "</div>";
																echo "</div>";
															}
														}
													echo "</div>";
												}
												$array_months = query_array_all( "SELECT `t1`.`Month`, IFNULL( `t2`.`Total`, 0 ) AS `Total` FROM ( SELECT MONTHNAME( '2000-01-01' ) AS `Month` UNION SELECT MONTHNAME( '2000-02-01' ) UNION SELECT MONTHNAME( '2000-03-01' ) UNION SELECT MONTHNAME( '2000-04-01' ) UNION SELECT MONTHNAME( '2000-05-01' ) UNION SELECT MONTHNAME( '2000-06-01' ) UNION SELECT MONTHNAME( '2000-07-01' ) UNION SELECT MONTHNAME( '2000-08-01' ) UNION SELECT MONTHNAME( '2000-09-01' ) UNION SELECT MONTHNAME( '2000-10-01' ) UNION SELECT MONTHNAME( '2000-11-01' ) UNION SELECT MONTHNAME( '2000-12-01' ) ) AS `t1` LEFT JOIN ( SELECT MONTHNAME( `deal_insert` ) AS `Month`, COUNT( * ) AS `Total` FROM `priv_deals` WHERE `deal_store` = '" . res( $array_store[ "stor_id" ] ) . "' GROUP BY `Month` ORDER BY `Month` ASC ) AS `t2` ON `t2`.`Month` = `t1`.`Month`" );
												if ( count( $array_months ) > 0 ) {
													echo "<div class='card'>";
														echo "<div class='card-header'>";
															echo "<h4>Stores</h4>";
														echo "</div>";
														echo "<div class='card-body'>";
															echarts_bars( $array_months, "", "auto", 500 );
														echo "</div>";
													echo "</div>";
												}
												comment_section( "stores", $array_store[ "stor_id" ] );
												$array_stores1 = query_array_all( "SELECT `stor_id` FROM `priv_networks_affiliations` LEFT JOIN `priv_networks_stores` ON `nest_id` = `neaf_network_store` LEFT JOIN `priv_stores` ON `stor_id` = `nest_store` WHERE `neaf_approved` = '1' AND `neaf_coupon` IS NOT NULL AND `stor_active` = '1' ORDER BY RAND() LIMIT 12" );
												if ( count( $array_stores1 ) > 0 ) {
													echo "<hr><h2>" . tra( "Recommended stores" ) . "</h2>";
													echo "<div class='row justify-content-center'>";
													foreach ( $array_stores1 as $array_store1 ) {
														store_card( $array_store1[ "stor_id" ] );
													}
													echo "</div>";
												}
												$array_stores1 = query_array_all( "SELECT `stor_id` FROM `priv_stores_views` LEFT JOIN `priv_stores` ON `stor_id` = `stvi_store` WHERE `stor_active` = '1' AND `stvi_user` IN ( SELECT `stvi_user` FROM `priv_stores_views` WHERE `stvi_store` = '" . res( $array_store[ "stor_id" ] ) . "' AND `stvi_user` IS NOT NULL GROUP BY `stvi_user` ) AND `stvi_store` <> '" . res( $array_store[ "stor_id" ] ) . "' " . ( $array_system_site[ "site_networkonly" ] == 1 ? "AND ( SELECT SUM( 1 ) FROM `priv_networks_affiliations` LEFT JOIN `priv_networks_stores` ON `nest_id` = `neaf_network_store` WHERE `neaf_approved` = '1' AND `nest_store` = `stor_id` ) > 0 " : "" ) . "GROUP BY `stvi_store` ORDER BY COUNT( `stvi_id` ) DESC LIMIT 8" );
												if ( count( $array_stores1 ) > 0 ) {
													echo "<hr><h2>" . tra( "Stores viewed by others users that saw this store" ) . "</h2>";
													echo "<div class='row justify-content-center'>";
													foreach ( $array_stores1 as $array_store1 ) {
														store_card( $array_store1[ "stor_id" ] );
													}
													echo "</div>";
												}
											echo "</div>";
										echo "</div>";
									echo "</div>";
								echo "</content>";
								include_once "system_footer.php";
							echo "</main>";
							include_once "system_scripts.php";
						echo "</body>";
					echo "</html>";
				} else {
					header( "location: /" );
				}
			}
		} else {
			header( "location: /" );
		}
	} else {
		header( "location: /" );
	}
	include_once "system_end.php";
?>