<?php include 'sets.php';?>
<?php
$superuser="0";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Webadmin <?php echo $domain ?></title>
<?php include 'codes.php';?>
</head>
<body>

<?php include 'navbar.php';?>
    
<div class="container">
<div class="frame">
<div class="frametitles flist">
<?php
$itemid = $mysqli->real_escape_string(stripslashes($_REQUEST['itemid']));
$catid = $mysqli->real_escape_string(stripslashes($_REQUEST['catid']));

if ($itemid) {
$result = $mysqli->query("SELECT insert_id FROM categories WHERE type=4 AND priority=3 GROUP BY lang_id LIMIT 1");
$row = $result->fetch_array(); 
$catid=$row['insert_id'];
} else {
$itemid=0;
$catid = $mysqli->real_escape_string(stripslashes($_REQUEST['catid']));
}

$result1 = $mysqli->query("SELECT * FROM categories WHERE type=4 AND insert_id='$catid'");
$row = $result1->fetch_array(); 
$catid=$row['insert_id'];
$category=$row['name'];

$result2 = $mysqli->query("SELECT * FROM members WHERE category_id='$catid'");
$rows = mysqli_num_rows($result2);
?>
<a href="list-members.php?catid=<?php echo $catid?>"><?php echo $category ?></a> (<?php echo $rows ?>)
<div class="floatright"><a href="add-member.php"><img src="img/add.png" alt="<?php echo $adminadditem ?>" title="<?php echo $adminadditem ?>"></a></div>
</div>
<div class="framein">

<?php
include ('pagination.php'); 

if ($itemid!=0) {
$result = $mysqli->query("SELECT * FROM members WHERE category_id='$catid' AND item_id='$itemid' ORDER BY id desc LIMIT $start,$nritems");
} else {
$result = $mysqli->query("SELECT * FROM members WHERE category_id='$catid' ORDER BY id desc LIMIT $start,$nritems");	
}
while($row = $result->fetch_array()) {
$count++;
$id=$row['id'];
$category_id=$row['category_id'];
$name=$row['name'];
$email=$row['email'];
$password=$row['password'];
$profession=$row['profession'];
$company=$row['company'];
$address=$row['address'];
$region=$row['region'];
$postcode=$row['postcode'];
$city=$row['city'];
$country=$row['country'];
$tel=$row['tel'];
$fax=$row['fax'];
$taxnr=$row['taxnr'];
$taxoffice=$row['taxoffice'];
$comments=$row['comments'];
$rate=$row['rate'];
$publish=$row['publish'];
$active=$row['active'];
$date=$row['date'];

$address="$address $region $postcode $city";
$address = trim($address);
?>
<div class="framerow<?php if ($publish=='no') { echo " notpublished"; }?>">
  <table>
    <tr> 
      <td>
        <a href="edit-member.php?id=<?php echo $id?>" class="titles"><?php echo $name ?></a>
        <hr>
        <table>
        <?php if ($email) { ?>
          <tr>
            <td width="30"><span class="icon fa-envelope <?php if ($active==1) { echo " color2"; }?>"></span></td>
            <td>
            <a href="mailto:<?php echo $email ?>?subject=<?php echo $firma?> Newsletter" class="links" title="email"><?php echo $email ?></a>
            &nbsp; &nbsp;
           <?php if ($password) { ?>
             <span class="icon fa-lock stylepass"></span> &nbsp; <span class="stylepass"><?php echo $password ?></span>
             <?php } ?> 
            </td>
          </tr>
          <?php } ?>
          <?php if ($profession) { ?>
          <tr>
            <td width="30"><span class="icon fa-briefcase"></span></td>
            <td><?php echo $profession ?> <strong><?php echo $company ?></strong></td>
          </tr>
          <?php } ?>
              <?php if ($address) { ?>
                <tr> 
                  <td width="30"><span class="icon fa-home"></span></td>
                  <td> 
                    <?php echo $address ?> 
                  </td>
                </tr>
                <?php } ?>
                <?php if ($country) { ?>
                <tr class="color2">
                  <td width="30"><span class="icon fa-map-marker"></span></td>
                  <td><strong><?php echo $country ?></strong> <?php if ($destination!=$country) { echo $destination; } ?> </td>
                </tr>
                <?php } ?>
         <?php if ($tel OR $fax) { ?> 
          <tr>
            <td width="30"><span class="icon fa-phone"></span></td>
            <td>
			<?php echo $tel ?> 
             <?php if ($fax) { ?>
            &nbsp; &nbsp; <span class="icon fa-fax"></span> <?php echo $fax ?>
             <?php } ?>
            </td>
          </tr>
          <?php } ?>
                <?php if ($taxnr OR $taxoffice) { ?>
                <tr>
                  <td width="30"><span class="icon fa-folder"></span></td>
                  <td><?php echo $taxnr ?> <?php echo $taxoffice ?></td>
                </tr>
                <?php } ?>
                <?php if ($comments) { ?>
                <tr>
                  <td width="30"><span class="icon fa-comment"></span></td>
                  <td><?php echo $comments ?></td>
                </tr>
                <?php } ?>
          <tr>
            <td width="30">
        <?php if ($rate>0) { ?>
		<span class="color1"><?php echo $rate ?></span>
        <?php } ?>          
            </td>
            <td>
<?php if ($itemid>0) { ?>
<?php
$resulti = $mysqli->query("SELECT name FROM items WHERE insert_id=$itemid AND lang_id=$lang");
$row = $resulti->fetch_array();
$item=$row['name']; 
?>              
<a href="edit-item.php?id=<?php echo $itemid?>" class="color1"><span class="icon fa-tag"></span> <?php echo $item ?></a>
<?php } ?>
            </td>
          </tr>
          </table>
      </td>
      <td width="100" valign="top">
            <strong><?php echo $date?></strong>
          </td>
      <td class="divdetails">
   <?php if ($publish=='no') { ?>
     <span class="icon icstyle1 fa-eye-slash" title="<?php echo $adminpublish ?> &raquo; <?php echo $adminno ?>"></span> &nbsp;
     <?php } ?>   
      </td>
      <td class="divoption"><a href="edit-member.php?id=<?php echo $id?>" class="linkoption" title="<?php echo $adminedit ?>"><span class="icon fa-edit"></span> <?php echo $adminedit ?></a></td>
      <td class="divoption">
<?php
if  (isset($_POST['deleterow'])) {
$mysqli->query("DELETE FROM members WHERE id='{$_REQUEST['id']}'");
$mysqli->query("ALTER TABLE members AUTO_INCREMENT = 1");
?>
        <meta http-equiv="refresh" content="0;URL=list-members.php?catid=<?php echo $category_id ?>">
        <?php } ?>
          <form name="formdelete" method="post">
          <input type="hidden" name="id" value="<?php echo $id ?>">
          <button type="submit" name="deleterow" class="linkoption linkdelete" title="<?php echo $admindelete ?>"><span class="icon fa-trash-o"></span> <?php echo $admindelete ?></button>
          </form>
          </td>
      </tr>
  </table>
</div>
<hr>
<?php } ?>

<?php
if ($itemid!=0) {
$resultm = $mysqli->query("SELECT * FROM members WHERE category_id='$catid' AND item_id='$itemid' AND rate>0");
} else {
$resultm = $mysqli->query("SELECT * FROM members WHERE category_id='$catid' AND rate>0");	
}
$rowsm = mysqli_num_rows($resultm);
while($row = $resultm->fetch_array()) {
$rate=$row['rate'];
$totalrate = $totalrate+$rate;
$averagerate=substr($totalrate/$rowsm, 0, 4);
}?>
<?php if ($rowsm>0 && $catid==3) { ?>    
 &nbsp; <span class="icon fa-check-square price"></span> &nbsp; &nbsp; <span class="price"><?php echo $averagerate ?></span>    
<hr>
<?php } ?>

<div class="floatleft">
<a href="mailto:<?php echo $sitemail ?>?Bcc=<?php 
$result3 = $mysqli->query("SELECT email FROM members WHERE category_id='$catid' AND active=1 AND email!='' ORDER BY id desc LIMIT $start,$nritems");
while($row = $result3->fetch_array()) {
$email=$row['email'];?><?php echo $email ?>,<?php }?>&subject=<?php echo $firma ?>" class="icstyle1 color1" title="email"><span class="icon fa-envelope"></span></a>
</div>

<div class="floatright">               
<?php
if  (isset($_POST['deletespam'])) {
$mysqli->query("DELETE FROM members WHERE name IS NULL OR comments LIKE ('%http%')");
$mysqli->query("ALTER TABLE members AUTO_INCREMENT = 1");
}?>
<form name="forma" method="post" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<?php echo $id ?>">
<button type="submit" name="deletespam" class="buttonicon colorgrey" title="<?php echo $admindelete ?>"><span class="icon fa-trash-o"></span> <?php echo $admindelete ?> spam</button>
 </form>
</div>

<div class="divpaginate">
<?php include 'paginate.php';?>
</div>

</div>
</div>
</div>

<?php include 'menudown.php';?>

</body>
</html>