<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../head.php";

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
?>
<html>

  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
    <div class="wrapper">
		<?php include "../header.php";?>
      
		<?php include "../menu.php";?>
      

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            DATA IKLAN
            <small>Data IKLAN</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">IKLAN</a></li>
            <li class="active">Data Iklan</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">List Iklan</h3><br><br>
				  <a href="add.php" class="btn btn-sm btn-info btn-flat pull-left">Iklan Baru</a> <br><br>
				  
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>Iklan</th>
                        <th>Category</th>
						<th>Product</th>
						<th>DM</th>
						<th>Biaya Bln Ini</th>
						<th>Biaya Hari Ini</th>
						<th>Bonus Bln Ini</th>
						<th>Bonus Hari Ini</th>
						<th></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						$idd = $_SESSION['idm'];
						$leader = mysql_result(mysql_query("select leader from admins where pk = $idd"),0);
						if($leader == "N"){
							$cek = mysql_query("Select * from  iklan where sales = $idd and status = 'Y' order by dateadded desc");
						}else{
							$leaderall = mysql_result(mysql_query("select status from leader where leader = $idd"),0);
							if ($leaderall =="ALL"){
								$cek = mysql_query("Select * from  iklan where status = 'Y' order by dateadded desc");
							}else{
								$cek = mysql_query("Select * from  iklan where sales in (select anak from leader where leader = $idd) and status = 'Y' order by dateadded desc");
							}
							
						}
						while ($r=mysql_fetch_array($cek)){	
							$cust = $r['id'];
							$cat = mysql_result(mysql_query("select category from iklancat where pk = $r[category]"),0);
							$sales = mysql_result(mysql_query("select userid from admins where pk = $r[sales]"),0);
							$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
							$harini = date("Y-m-d");
							$dt = strtotime('today GMT');
							$tglawal = date('Y-m-d', strtotime('first day of this month', $dt));
							$tglakhir = date('Y-m-d', strtotime('last day of this month', $dt));
							$biaya2 = mysql_result(mysql_query("select sum(cost) from iklanhasil where (tanggal >= '$tglawal' and tanggal <= '$tglakhir') and iklan = $r[id]"),0);
							$biaya = format_rupiah($biaya2);
							$biayahariini = format_rupiah(mysql_result(mysql_query("select sum(cost) from iklanhasil where (tanggal = '$hariini') and iklan = $r[id]"),0));
							$namacs = mysql_result(mysql_query("select userid from admins where pk = $r[cs]"),0);
							echo "<tr>
									<td><a href = 'evaluasi.php?id=$cust'>$namacs # $sales # $r[nama]</a></td>
									<td>$cat</td>
									<td>$produk</td>
									<td>$sales</td>
									<td>$biaya</td>
									<td>$biayahariini</td>
									<td>$bonus</td>
									<td>$bonushariini</td>";
									if ($idd ==$r['sales']){
										echo"
										<td><a href='edit.php?id=$cust'><span class='label label-success'>Edit</span></a><a href='aksicust.php?id=$cust&module=cust&act=delete'><span class='label label-danger'>Delete</span></a>  </td>";
									}else{
										echo"
										<td></td>";
									}
									
							echo"
								  </tr>";
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Iklan</th>
                        <th>Category</th>
						<th>Product</th>
						<th>DM	</th>
                        <th>Biaya Bln Ini</th>
						<th>Biaya Hari Ini</th>
						<th>Bonus Bln Ini</th>
						<th>Bonus Hari Ini</th>
                      </tr>
                    </tfoot>
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
		<?php include "../footer.php";?>
		

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">

        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">

          </div><!-- /.tab-pane -->

        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../dist/js/demo.js"></script>
    <!-- page script -->
    <script>
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>