<?php

require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick'])))  {
  ?>
  <script type="text/javascript">
  document.location.href = "login.php";
  </script>
  <?php
  exit();
}
$page_title = 'Посылки';
require_once('conf/head.php');
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
require_once('conf/top.php');
}
?>
<div style="background-color: #000000;">
<div id="main">
<div class="stats">
<center><p class="profile">Посылки</p></center>

      <p><p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p><a href="msg.php" class="menu1"><img src="img/reload.gif" width="12" height="12" /><span class="bonus">Назад</span></a></p>
<p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p>

<?php
$user_id = abs(intval($_SESSION['id']));
$query = "Select message_id from message where delite_ot!='$user_id' and delite_dlya!='$user_id' and ot='$user_id' or dlya='$user_id' and delite_ot!='$user_id' and delite_dlya!='$user_id'";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД2');
$total = mysqli_num_rows($result);
if (!empty($_GET['page'])) {
$cur_page = abs(intval($_GET['page']));
}
else {
  $cur_page = 1;
}
    $result_per_page = 10;
	$skip = (($cur_page - 1) * $result_per_page);
		$num_page = ceil($total / $result_per_page);
	if ($num_page > 0) {
	?><div class="stats"><?php
	  $query = "Select * from message where delite_ot!='$user_id' and delite_dlya!='$user_id' and ot='$user_id' or dlya='$user_id' and delite_ot!='$user_id' and delite_dlya!='$user_id' order by time DESC limit $skip, $result_per_page";
      $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
	  $show = 0;
	  while ($row = mysqli_fetch_array($result)) {
	  
	  /////Шмотка
	    if ($row['type'] == 2 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
	      $show=1;
		  $ot=$row['ot'];
		  $dlya=$row['dlya'];
	      if ($ot == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$dlya' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
		    ?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          <p><img src="img/ico/letterout.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$dlya";?>"><?php echo $row_user['nick'];?></a><?php if ($row['reading'] == '0') { echo '<span class="red">   (не прочитано)</span>';}?><?php echo ''; ?></p>
			<span class="white">Посылка</span>
</p>
<img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		  if ($dlya == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$ot' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
			?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$ot";?>"><?php echo $row_user['nick'];?></a><?php echo ''; ?></p>
                              <a <?php if ($row['reading'] == 0) {?>class="yellow"<?php }?>
			<span class="white">-Посылка</span></p>
<img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
                </p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		}
	  //////////Конец шмотки
	  //////Начало денег
	    if ($row['type'] == 3 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		  $show=1;
		  $ot=$row['ot'];
		  $dlya=$row['dlya'];
	      if ($ot == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$dlya' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
		    ?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          <p><img src="img/ico/letterout.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$dlya";?>"><?php echo $row_user['nick'];?></a><?php if ($row['reading'] == '0') { echo '<span class="red">   (не прочитано)</span>';}?><?php echo ': '; ?></p>
			<span class="white">(<?php echo $row['thing'];?> RUB)</span>
			</p>

<img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
                        </p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		  if ($dlya == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$ot' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
			?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$ot";?>"><?php echo $row_user['nick'];?></a><?php echo ': '; ?></p>
			<p <?php if ($row['reading'] == 0) {?>class="yellow"<?php }?> 
			<span class="white">(<?php echo $row['thing'];?> RUB)</span>
			</p>

                        <img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
                        </p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		}
	  ////////Конец денег
	  ///////Начало хабара
	     if ($row['type'] == 4 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		  $show=1;
		  $ot=$row['ot'];
		  $dlya=$row['dlya'];
	      if ($ot == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$dlya' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
		    ?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          <p><img src="img/ico/letterout.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$dlya";?>"><?php echo $row_user['nick'];?></a><?php if ($row['reading'] == '0') { echo '<span class="red">   (не прочитано)</span>';}?><?php echo ': '; ?></p>
			<span class="white">(<?php echo $row['thing'];?>хабара)</span>
                          </p>

                        <img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		  if ($dlya == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$ot' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
			?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
                        <a href="profile.php?id=<?php echo "$ot";?>"><?php echo $row_user['nick'];?></a><?php echo ': '; ?></p>
			<p <?php if ($row['reading'] == 0) {?>class="yellow"<?php }?> 
			<span class="white">(<?php echo $row['thing'];?>хабара)</span>
                        </p>

                        <img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		}
	  ///////Конец хабара
	  //////Начало Аптечек
	    if ($row['type'] == 5 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		  $show=1;
		  $ot=$row['ot'];
		  $dlya=$row['dlya'];
	      if ($ot == $user_id) {
		    $query_user = "Select nick,avatar from users where id='$dlya' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
		    ?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          <p><img src="img/ico/letterout.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$dlya";?>"><?php echo $row_user['nick'];?></a> <?php if ($row['reading'] == '0') { echo '<span class="red">   (не прочитано)</span>';}?><?php echo ': '; ?></p>
			<span class="white">(<?php echo $row['thing'];?>аптечек)</span>   
        
                         </p>

                        <img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		  if ($dlya == $user_id) {
		    $show=1;
		    $query_user = "Select nick,avatar from users where id='$ot' limit 1";
            $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
		    $row_user = mysqli_fetch_array($result_user);
			?><table width="170" border="0" cellpadding="0" cellspacing="0">
                 <tbody>
                 
                 <td width="54" valign="top"><img src="img/avatars/<?php echo $row_user['avatar']; ?>" width="55" height="55" border="0"/></td>
                 <td width="7777" valign="top">
	          
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
			<a href="profile.php?id=<?php echo "$ot";?>"><?php echo $row_user['nick'];?></a><?php echo ': '; ?></p>
			<p <?php if ($row['reading'] == 0) {?>class="yellow"<?php }?> 
			<span class="white">(<?php echo $row['thing'];?>аптечек)</span>
                        </p>

                    

                        <img src="img/ico/link.png"/><a href="message.php?mes_id=<?php echo $row['message_id'];?>">К диалогу</a>

			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
</td>
                 </tr>
                 </tbody>
                 </table>
			<?php
		  }
		}
		if ($row['type'] == 6 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		$show=1;
		?><p class="white"><img src="img/ico/letterin.png" width="12" height="12"/> Аукцион: <a 
                 <?php if ($row['reading'] == 0) {?>class="white"<?php }?>  
                 href="message.php?mes_id=<?php echo $row['message_id'];?>">вашу ставку перебили</a></p>
			<?php
		}
		/////Шмотка АУКЦИОН
	    if ($row['type'] == 7 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		    $show=1;
		    $ot=$row['ot'];
		    $dlya=$row['dlya'];
			?>
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
			<span class="white">Аукцион:</span>
			<a <?php if ($row['reading'] == 0) {?>class="white"<?php }?> </p>
			<a href="message.php?mes_id=<?php echo $row['message_id'];?>">(Cнаряж:<?php echo $row['text'];?>)</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
			<?php
		}
	  //////////Конец шмотки АУКЦИОН
	  ////Деньги за купленную шмотку
	    if ($row['type'] == 8 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		    $show=1;
		    $ot=$row['ot'];
		    $dlya=$row['dlya'];
			?>
			<p class="white"><img src="img/ico/letterin.png" width="12" height="12"/> Аукцион: <a <?php if ($row['reading'] == 0) {?>class="white"<?php }?>  href="message.php?mes_id=<?php echo $row['message_id'];?>">ваш лот купили</a></p>
			<?php
		}
	  //////////Конец денег за шмотку
	  /////Шмотка АУКЦИОН
	    if ($row['type'] == 9 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		    $show=1;
		    $ot=$row['ot'];
		    $dlya=$row['dlya'];
			?>
			<p>
			<img src="img/ico/letterin.png" width="12" height="12"/> 
			<span class="white">Аукцион:</span>
			<a <?php if ($row['reading'] == 0) {?>class="white"<?php }?> </p>
			<a href="message.php?mes_id=<?php echo $row['message_id'];?>">(Cнаряж:<?php echo $row['text'];?>)</a>
			</p><p class="podmenu" style="border-top:1px dashed #444e4f;"></p>
			<?php
		}
	  //////////Конец шмотки АУКЦИОН
	    if ($row['type'] ==10 and $row['delite_ot'] <> $user_id and $row['delite_dlya'] <> $user_id) {
		    $show=1;
		    $ot=$row['ot'];
		    $dlya=$row['dlya'];
			?>
			<p class="white"><img src="img/ico/letterin.png" width="12" height="12"/> Банк: <a <?php if ($row['reading'] == 0) {?>class="white"<?php }?>  href="message.php?mes_id=<?php echo $row['message_id'];?>">пополнение счёта</a></p>
			<?php
		}
	  }
	  if ($show == 0) {echo 'Писем нет';} 
	  ?>
	  
	  <?php
	  	  /////////////////////////////Навигация
	  ?>

	  <div class="stats"><center><div class="catPages1" align="center" style="clear:both;" id="pagesBlock1">



	  <?php
$phpself= filter($_SERVER['PHP_SELF']);
	  if ($cur_page > 1) {
	    echo '<a class="swchItem" href="' . "$phpself" . '?company_id=' . $clan_id . '&page=1"><<</a></span></b> ';
      }
	  else {
	    echo '<< ';
	  }
	  if ($cur_page > 1) {
	    echo '<a class="swchItem" href="' . "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page-1) . '"><</a></span></b> ';
      }
	  else {
	    echo '<';
	  }
	/////
	  if (($cur_page-3)>0) {
	 $k = ($cur_page-3);
	    ?><a class="swchItem" href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page-3)?>"><?php echo "$k";?></a></span></b><?php
      }
	 if (($cur_page-2)>0) {
	 $k = ($cur_page-2);
	    ?> <a class="swchItem" href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page-2)?>"><?php echo "$k";?></a></span></b> <?php
      }
     if (($cur_page-1)>0) {
	 $k = ($cur_page-1);
	    ?> <a class="swchItem"  href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page-1)?>"><?php echo "$k";?></a></span></b> <?php
      }
	?> <b class="swchItemA"><span><span class="white"><?php echo " $cur_page ";?></span></b><?php
	 if (($cur_page+1)<=$num_page) {
	 $k = ($cur_page+1);
	    ?> <a class="swchItem" href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page+1)?>"><?php echo "$k";?></a></span></b> <?php
      }
	  	 if (($cur_page+2)<=$num_page) {
	 $k = ($cur_page+2);
	    ?> <a class="swchItem" href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page+2)?>"><?php echo "$k";?></a></span></b> <?php
      }
	 if (($cur_page+3)<=$num_page) {
	 $k = ($cur_page+3);
	    ?> <a class="swchItem" href="<?php echo "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page+3)?>"><?php echo "$k";?></a> </span></b><?php
      }
	/////
	if ($cur_page < $num_page) {
	  echo '<a class="swchItem" href="' . "$phpself" . '?company_id=' . $clan_id . '&page=' . ($cur_page+1) . '">></a></span></b> ';
    }
	else {
	  echo '>';
	}
	if ($cur_page < $num_page) {
	  echo ' <a class="swchItem" href="' . "$phpself" . '?company_id=' . $clan_id . '&page=' . $num_page . '">>></a> </span></b>';
    }
	else {
	  echo ' >>';
	}
	  ?></span></b></center>
      
	  <?php
	  ///////////////////Конец навигации
  ?>
  
	  <?php
		} 
	else {
	  ?>
	
	  <p>Посылок нет</p>
	 
	  <?php
	}

	
	
?>

<?php
require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);
?>

</body>
</html>