<!-- Category Section 1: ម៉ូដសំអាងការ (Beauty/Makeup) — portrait, no frame, no text below -->
<div id="bar_title_khmer" style="position: relative; background: url(images/line.png) no-repeat bottom left; font-family: 'Koulen', sans-serif; font-size: 22px; color: #f808ea; width: 930px; height: auto; min-height: 40px; line-height: 1.5; margin-top: 10px; margin-bottom: 5px;">
	ម៉ូដសំអាងការ
</div>
<div class="clear" style="height: 0px;"></div>
<?php
// Query EXCLUSIVELY from tbl_clothes for ម៉ូដសំអាងការ
$b_cc_ids = array();
$q_bc = mysql_query("SELECT id FROM tbl_cate_clothes WHERE name_kh LIKE '%សំអាង%' OR name_kh LIKE '%ស្បែក%' OR name LIKE '%Beauty%' OR id=7 OR par_id=7");
if ($q_bc) {
	while ($r = mysql_fetch_array($q_bc)) {
		$b_cc_ids[] = $r['id'];
	}
}

$sql_c3 = null;
if (!empty($b_cc_ids)) {
	$sql_c3 = mysql_query("SELECT * FROM tbl_clothes WHERE (cid IN (" . implode(',', $b_cc_ids) . ") OR mcid IN (" . implode(',', $b_cc_ids) . ")) ORDER BY id DESC LIMIT 0,4");
}

if ($sql_c3 && mysql_num_rows($sql_c3) > 0) {
	while ($row = mysql_fetch_array($sql_c3)) {
		$code_title = !empty($row['code_id']) ? "កូដ: " . $row['code_id'] : "ម៉ូដសំអាងការ";
		if (!empty($row['price']) && $row['price'] > 0) {
			$code_title .= " - $" . number_format($row['price'], 2);
		}
		$b_img = !empty($row['image']) && file_exists("images/clothes/" . $row['image']) 
			? "images/clothes/" . $row['image'] 
			: (!empty($row['image']) && file_exists("images/clothes/b/" . $row['image']) 
				? "images/clothes/b/" . $row['image'] 
				: "images/photo/p3.jpg");
		$b_link = "?p=clothes&s_id=" . $row['s_id'] . "&id_detail=" . $row['id'] . "&sub=" . $row['mcid'] . "&cc_id=" . $row['cid'] . "&action=cl_detail#txt";
?>
	<a href="<?php echo $b_link; ?>" title="<?php echo htmlspecialchars($code_title); ?>" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="<?php echo $b_img; ?>" alt="<?php echo htmlspecialchars($code_title); ?>" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php 
	}
} else {
	for ($b_i = 1; $b_i <= 4; $b_i++) {
?>
	<a href="?p=clothes#txt" title="ម៉ូដសំអាងការ" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="images/photo/p3.jpg" alt="ម៉ូដសំអាងការ" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php
	}
}
?>
<div class="clear" style="height: 15px;"></div>

<!-- Category Section 2: ពិភពម៉ូដសក់ — portrait, no frame, no text below -->
<div id="bar_title_khmer" style="position: relative; background: url(images/line.png) no-repeat bottom left; font-family: 'Koulen', sans-serif; font-size: 22px; color: #f808ea; width: 930px; height: auto; min-height: 40px; line-height: 1.5; margin-top: 10px; margin-bottom: 5px;">
	ពិភពម៉ូដសក់
</div>
<div class="clear" style="height: 0px;"></div>
<?php
// Query category 'ពិភពម៉ូដសក់' / 'Hair' strictly
$hair_cc_ids = array();
$q_hc = mysql_query("SELECT id FROM tbl_cate_clothes WHERE name_kh LIKE '%សក់%' OR name LIKE '%Hair%' OR name LIKE '%hair%'");
if ($q_hc) {
	while ($r = mysql_fetch_array($q_hc)) {
		$hair_cc_ids[] = $r['id'];
	}
}

$sql_c1 = null;
if (!empty($hair_cc_ids)) {
	$sql_c1 = mysql_query("SELECT * FROM tbl_clothes WHERE (cid IN (" . implode(',', $hair_cc_ids) . ") OR mcid IN (" . implode(',', $hair_cc_ids) . ")) ORDER BY id DESC LIMIT 0,4");
}

if ($sql_c1 && mysql_num_rows($sql_c1) > 0) {
	while ($row = mysql_fetch_array($sql_c1)) {
		$code_title = !empty($row['code_id']) ? "កូដ: " . $row['code_id'] : "ពិភពម៉ូដសក់";
		if (!empty($row['price']) && $row['price'] > 0) {
			$code_title .= " - $" . number_format($row['price'], 2);
		}
		$c_img = !empty($row['image']) && file_exists("images/clothes/" . $row['image']) 
			? "images/clothes/" . $row['image'] 
			: (!empty($row['image']) && file_exists("images/clothes/b/" . $row['image']) 
				? "images/clothes/b/" . $row['image'] 
				: "images/photo/p1.jpg");
?>
	<a href="?p=clothes&s_id=<?php echo $row['s_id']; ?>&id_detail=<?php echo $row['id']; ?>&sub=<?php echo $row['mcid']; ?>&cc_id=<?php echo $row['cid']; ?>&action=cl_detail#txt" title="<?php echo htmlspecialchars($code_title); ?>" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="<?php echo $c_img; ?>" alt="<?php echo htmlspecialchars($code_title); ?>" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php 
	}
} else {
	for ($h_i = 1; $h_i <= 4; $h_i++) {
?>
	<a href="?p=clothes#txt" title="ពិភពម៉ូដសក់" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="images/photo/p1.jpg" alt="ពិភពម៉ូដសក់" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php
	}
}
?>
<div class="clear" style="height: 15px;"></div>

<!-- Category Section 3: ម៉ូដសម្លៀកបំពាក់ប៉ាក់និងហូលផាម៉ួង — portrait, no frame, no text below -->
<div id="bar_title_khmer" style="position: relative; background: url(images/line.png) no-repeat bottom left; font-family: 'Koulen', sans-serif; font-size: 22px; color: #f808ea; width: 930px; height: auto; min-height: 40px; line-height: 1.5; margin-top: 10px; margin-bottom: 5px;">
	ម៉ូដសម្លៀកបំពាក់ប៉ាក់និងហូលផាម៉ួង
</div>
<div class="clear" style="height: 0px;"></div>
<?php
// Query category 'ម៉ូដសម្លៀកបំពាក់' / 'Dresses' / 'Women Clothes' strictly
$dress_cc_ids = array();
$q_dc = mysql_query("SELECT id FROM tbl_cate_clothes WHERE name_kh LIKE '%សម្លៀកបំពាក់%' OR name_kh LIKE '%ហូល%' OR name_kh LIKE '%ប៉ាក់%' OR name LIKE '%Women Clothes%' OR name LIKE '%Dress%' OR id IN (1,8,9,11,12,13)");
if ($q_dc) {
	while ($r = mysql_fetch_array($q_dc)) {
		$dress_cc_ids[] = $r['id'];
	}
}

$sql_c2 = null;
if (!empty($dress_cc_ids)) {
	$sql_c2 = mysql_query("SELECT * FROM tbl_clothes WHERE (cid IN (" . implode(',', $dress_cc_ids) . ") OR mcid IN (" . implode(',', $dress_cc_ids) . ")) ORDER BY id DESC LIMIT 0,4");
}

if ($sql_c2 && mysql_num_rows($sql_c2) > 0) {
	while ($row = mysql_fetch_array($sql_c2)) {
		$code_title = !empty($row['code_id']) ? "កូដ: " . $row['code_id'] : "ម៉ូតសំលៀកបំពាក់";
		if (!empty($row['price']) && $row['price'] > 0) {
			$code_title .= " - $" . number_format($row['price'], 2);
		}
		$c_img = !empty($row['image']) && file_exists("images/clothes/" . $row['image']) 
			? "images/clothes/" . $row['image'] 
			: (!empty($row['image']) && file_exists("images/clothes/b/" . $row['image']) 
				? "images/clothes/b/" . $row['image'] 
				: "images/photo/p2.jpg");
?>
	<a href="?p=clothes&s_id=<?php echo $row['s_id']; ?>&id_detail=<?php echo $row['id']; ?>&sub=<?php echo $row['mcid']; ?>&cc_id=<?php echo $row['cid']; ?>&action=cl_detail#txt" title="<?php echo htmlspecialchars($code_title); ?>" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="<?php echo $c_img; ?>" alt="<?php echo htmlspecialchars($code_title); ?>" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php 
	}
} else {
	for ($d_i = 1; $d_i <= 4; $d_i++) {
?>
	<a href="?p=clothes#txt" title="ម៉ូដសម្លៀកបំពាក់ប៉ាក់និងហូលផាម៉ួង" style="text-decoration: none;">
		<div style="position: relative; float: left; margin-top: 10px; margin-right: 12px; margin-left: 15px; width: 210px;">
			<div style="width: 210px; height: 280px; overflow: hidden; box-shadow: 0 10px 22px -3px rgba(0,0,0,0.45), 0 4px 8px -2px rgba(0,0,0,0.25); transition: transform 0.25s ease, box-shadow 0.25s ease;">
				<img src="images/photo/p2.jpg" alt="ម៉ូដសម្លៀកបំពាក់ប៉ាក់និងហូលផាម៉ួង" style="width: 100%; height: 100%; object-fit: cover; display: block; border: none;" />
			</div>
		</div>
	</a>
<?php
	}
}
?>
<div class="clear" style="height: 15px;"></div>

<!-- Category Section 4: ព័ត៌មាន — ORIGINAL STYLE (landscape with gold frame) -->
<div id="bar_title_khmer" style="position: relative; background: url(images/line.png) no-repeat bottom left; font-family: 'Koulen', sans-serif; font-size: 22px; color: #f808ea; width: 930px; height: auto; min-height: 40px; line-height: 1.5; margin-top: 10px; margin-bottom: 5px;">
	ព័ត៌មាន
</div>
<div class="clear" style="height: 0px;"></div>
<?php
$sql_c4 = mysql_query("SELECT * FROM tbl_all ORDER BY id DESC LIMIT 0,8");
if ($sql_c4 && mysql_num_rows($sql_c4) > 0) {
	while ($row = mysql_fetch_array($sql_c4)) {
		$str = $row['title'];
		$sp1 = (mb_strlen($str, 'UTF-8') > 45) ? mb_substr($str, 0, 45, 'UTF-8') . '...' : $str;
		$a_img = !empty($row['image']) && file_exists("images/all/" . $row['image']) ? "images/all/" . $row['image'] : "images/photo/p4.jpg";
?>
	<a href="?p=all&a_id=<?php echo $row['id']; ?>&act=show#txt" title="<?php echo htmlspecialchars($row['title']); ?>" style="text-decoration: none;">
		<div id="box_photo">
			<div id="bg_photo">
				<div id="photo_img" style="background: url('<?php echo $a_img; ?>') no-repeat center center; background-size: cover;"></div>
			</div>
			<div class="clear" style="height: 5px;"></div>
			<?php echo htmlspecialchars($sp1); ?>
		</div>
	</a>
<?php 
	}
} 
?>
<div class="clear" style="height: 15px;"></div>
