<?php
session_start();
	
	if (isset($_POST['k2'])) {
		require_once('wa_polacz.php');
		$id = $_SESSION['id'];
		if ($_POST['k2']==0) {
			$lid = count($_POST['k3']);
			if ($lid==1) {
				$zap = 'DELETE FROM blog_wpis WHERE id_wpis='.$_POST['k3'][0];
				$wynik_pobierz = mysqli_query($db, $zap);
				$zap = 'DELETE FROM blog_komentarz WHERE id_wpisu='.$_POST['k3'][0];
				$wynik_pobierz = mysqli_query($db, $zap);
			} else {
				$zap = "DELETE FROM blog_wpis WHERE id_wpis IN (";
				$zap1 = "DELETE FROM blog_komentarz WHERE id_wpisu IN (";
				$zap2 = '';
				for ($i=0; $i<$lid; $i++) {
					$zap2 = $zap2.$_POST['k3'][$i];
					if ($i<($lid-1)) { $zap2=$zap2.', '; }
				}
				$zap=$zap.$zap2.')';
				$zap1=$zap1.$zap2.')';
				$wynik_pobierz = mysqli_query($db, $zap);
				$wynik_pobierz = mysqli_query($db, $zap1);
			}
			$zap = "SELECT * FROM blog_wpis WHERE id_user=$id ORDER BY id_wpis ASC";
		}
		
		if ($_POST['k2']==1) {
			$zap = "SELECT * FROM blog_wpis WHERE id_user=$id ORDER BY id_wpis ASC";
		}
		if ($_POST['k2']==2) {
			$zap = "SELECT * FROM blog_wpis WHERE id_user=$id ORDER BY id_wpis ASC limit 10";
		}

		$wynik_pobierz = mysqli_query($db, $zap);
		$wynik = array();
		while ($wiersz = mysqli_fetch_row($wynik_pobierz)) 
			{
				$wynik[] = $wiersz;
			}	
	
	$lp = count($wynik);
	for ($i=0; $i<$lp; $i++) {
		echo '<div id="wpis_usun">';
			echo '<input type="checkbox" class="cb'.$wynik[$i][0].'" id="cb_usun">';
			echo '<span style="color: #f44"><b>( '.($i+1).' )</b></span><br />';
			echo '<span style="color: #fb4; text-align: center;"><b>'.$wynik[$i][2].'</b></span><br />';
			echo '<span style="color: #eff">'.$wynik[$i][3].'<br />';
			echo '--------------------------------------------------------------------------<br />';
			echo '<span style="color: #ee4">'.$wynik[$i][4].'</b></span>';
		echo '</div>';
	}
	$wynik_pobierz->free_result();
	unset($_POST['k2']);	
}

?>