<?php require_once("../include/class.php");?>
<?php require_once("../include/header.php");?>
<?php require_once("../include/nav_top.php");?>
<?php require_once("../include/sidebar.php");?>
<?php include("table_name.php");?>

<div id="main-content">
  <div class="container-fluid">
  
    <ul class="breadcrumb">
      <li><a href="../<?php echo $name_folder; ?>/list.php"><?php echo ucfirst($name_table) ?></a><span class="divider">&raquo;</span></li>
      <li class="active">List &nbsp;  &nbsp; <a href="add.php"><i class="icon-plus"></i> Add New</a></li>
    </ul>
    
    <div class="row-fluid">
			<div class="span12">
				<div class="widget-block">
					<div class="widget-head">
                   
						<h5>List</h5>
						<div class="widget-control pull-right">
							<a href="../<?php echo $name_folder ?>/list.php" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><b class="caret"></b></a>
							<ul class="dropdown-menu">
								<li><a href="add.php"><i class="icon-plus"></i> Add New</a></li>
                                <li><a href="addcsv.php"><i class="icon-plus"></i> Add file.csv</a></li>
								<!--<li><a href="#"><i class="icon-ok"></i> Bulk Approved</a></li>
								<li><a href="#"><i class="icon-minus-sign"></i> Bulk Remove</a></li>-->
							</ul>
						</div>
					</div>
                     
					<div class="widget-content">
						<div class="widget-box">
                        
                       <?php
                            if($_SESSION['er']=='true')
							{
								?>
                                <div class="alert alert-success fade in">
                                <button data-dismiss="alert" class="close" type="button">×</button>
                                <strong>Save</strong>
                                </div>
                                <?php
							}
							 if($_SESSION['er']=='de_true')
							{
								?>
                                <div class="alert alert-success fade in">
                                <button data-dismiss="alert" class="close" type="button">×</button>
                                <strong>Clear </strong> 
                                </div>
                                <?php
							}
							if($_SESSION['er']=='false')
							{
								?>
                                <div class="alert alert-error fade in">
                                <button data-dismiss="alert" class="close" type="button">×</button>
                                <strong>system crashes</strong>
                                </div>
                                <?php
							}
							
							$secrch = " id > 0";
							//if($_SESSION["admin_cn_type"] == 2){ $secrch = "by_admin = '".$_SESSION["admin_cn_id"]."'";}
							
                            $list = array('table'=>$name_table,'where'=>$secrch,'order'=> "ORDER BY id DESC");				  
							$view = $view_db->view($list);
							$result = $view_db->q_re($view);
							
							$num_rows = mysqli_num_rows($result);
							?>
                        	<div style="padding:15px;color:#F00;">Item number : <?php echo $num_rows;?> list</div>
							<table class="data-tbl-boxy table" style="font-size:12px;border:0px solid #F00;">
							<thead>
							<tr>
								<th width="5%">
									 No.
								</th>
								<th width="15%">
									 phone number
								</th>
                                <th width="11%">
									 Type number
								</th>
                                <th width="10%">
									 sale price
								</th>
                                <th width="7%">
									 system
								</th>
                                <th width="7%">
									 status
								</th>
                                <th width="7%">
									 status price
								</th>
                                <th width="5%">
									status publish 
								</th>
                                <th width="5%">
									 By
									</th>
                                <th width="5%">
									Date
								</th>
								<th width="5%">
									management
								</th>
							</tr>
							</thead>
							<tbody>
                            <?php
							$num=1;
							while($row = $view_db->q_ro($result))
							{
								?>
                                <tr>
                                  <td><?php echo $num; ?>. </td>
                                  <td><?php echo $row['phonenumber']; ?> (<?php echo $row['sum_number']; ?>)</td>
                                  <td>
									  <?php if($row['typenumber'] == 1){?>Prepaid<?php }?>
                                      <?php if($row['typenumber'] == 2){?>Monthly<?php }?>
                                  </td>
                                  <td><?php echo $row['price']; ?> ฿  </td>
                                  <td><?php 
								   $sql_nw = array('table'=>'mobilenetwork','where'=>"id = '".$row['mobilenetwork']."'");
                                   $view_nw = $view_db->view($sql_nw);
                                   $row_nw = $view_db->q($view_nw);
								  ?> 
                                  <img src="../../redbag/mobilenetwork/<?php echo $row_nw['image'] ?>"></td>
                                   <td style="color:#FFF;">
                                    	<?php 
											if($row['status_number'] == 1)//ว่าง
											{
												?>
                                                <img src="../img/v01.jpg" title="blank">blank<?php
											}
											if($row['status_number'] == 2)//ขายแล้ว-ผ่านระบบ
											{
												?><img src="../img/v03.jpg" title="Sold">Sold<?php	
											}
											if($row['status_number'] == 4)//ขายแล้ว-โดยDealer
											{
												?><img src="../img/v03.jpg" title="Sold-ByDealer">Sold-ByDealer<?php	
											}
											if($row['status_number'] == 3)//กำลังถูกจอง
											{
												?><img src="../img/v02.jpg" title="Are booked">Are booked<?php	
											}
										?>
                                    </td>
                                     <td>
                                    	<?php 
											if($row['statusprice'] == 1)
											{
												?> <a href="statusprice.php?id=<?php echo $row['id']?>&s=2" title="publicize">
                                                <i class="dashboard-icons-colors check_sl"></i></a><?php
											}
											else
											{
												?> <a href="statusprice.php?id=<?php echo $row['id']?>&s=1" title="Stop publishing">
                                                <i class="dashboard-icons-colors busy_sl"></i></a><?php	
											}
										?>
                                    </td>
                                     <td>
                                    	<?php 
											if($row['status'] == 1)
											{
												?> <a href="status.php?id=<?php echo $row['id']?>&s=0" title="publicize">
                                                <i class="dashboard-icons-colors check_sl"></i></a><?php
											}
											else
											{
												?> <a href="status.php?id=<?php echo $row['id']?>&s=1" title="Stop publishing">
                                                <i class="dashboard-icons-colors busy_sl"></i></a><?php	
											}
										?>
                                    </td>
                                    <?php
									if($_SESSION["admin_cn_type"] == 3)
									{
									}
									else
									{
										?>
										<td>
										<?php 
                                        $sql_adt = array('table'=>'admin,admin_type','where'=>"admin_type.id = admin.type AND admin.id = '".$row['by_admin']."'");
                                        $view_adt = $view_db->view($sql_adt);
                                        $row_adt = $view_db->q($view_adt);
                                        echo $row_adt['name'] .' / '. $row_adt['username'];
                                        ?></td>
										<?php	
									}
									?>                                    
                                    <td><?php echo $util_class->day_m_th_re($row['up_date']) ?></td> 
                                    <td>
                                    <a href="edit.php?id=<?php echo $row['id']?>" title="Edit<?php echo $num; ?>"><i class="black-icons pencil"></i></a> &nbsp; 
                                    <a onClick="if(!confirm('Confirm the deletion permanent ?')){return false;}" href="delete.php?id=<?php echo $row['id']?>" title="Delete<?php echo $row['name_th']; ?>"><i class="black-icons trashcan"></i></a>
                                    </td>
							</tr>
                                <?php
								$num++;
							}
							?>
							</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
    
    
  </div>
</div>
<?php unset($_SESSION['er']);?>
<?php require_once("../include/footer_js.php");?>
</body>
</html>