<?php include('include/auth.php'); 
if (isset($_GET['pid'])  && $_GET['pid']!='0') {
    $pid=$_GET['pid'];}
    else {$pid='0';}
?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');?>
<style>
    .green{color:green;}
    .red{color:red;}
</style>
<body>
    <section class="body">

        <!-- start: header -->
        <header class="header">
            <div class="logo-container">
                <a href="index.php" class="logo">
                    <img src="img/logo-light.png" width="75" height="35" alt="Web Voyage" />
                </a>
                <div class="d-md-none toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html"
                    data-fire-event="sidebar-left-opened">
                    <i class="fas fa-bars" aria-label="Toggle sidebar"></i>
                </div>
            </div>

            <!-- start: search & user box -->
            <div class="header-right">
                <?php include('include/search.php');?>


                <span class="separator"></span>
                <?php include('include/notifications.php');?>


                <span class="separator"></span>
                <?php include('include/userbox.php');?>

            </div>
            <!-- end: search & user box -->
        </header>
        <!-- end: header -->

        <div class="inner-wrapper">
            <!-- start: sidebar -->
            <?php include('include/nav.php');?>
            <!-- end: sidebar -->

            <section role="main" class="content-body">
                <header class="page-header">
                    <h2>API Extended Partner Seasons</h2>

                    <div class="right-wrapper text-right">
                        <ol class="breadcrumbs">
                            <li>
                                <a href="index.php">
                                    <i class="fas fa-home"></i>
                                </a>
                            </li>
                            <li><span>WV Admin</span></li>
                            <li><span>API Extended Partner Seasons</span></li>
                        </ol>

                        <a class="sidebar-right-toggle" data-open="sidebar-right"><i
                                class="fas fa-chevron-left"></i></a>
                    </div>
                </header>
                <?php if($userrole==2){echo "Δεν έχετε Διακαιώματα για αυτή την λειτουργία";}
				else {

?>
                               <div class="row justify-content-center justify-content-sm-between">
						<div class="col-sm-auto text-center mb-4 mb-sm-0 mt-2 mt-sm-0">
							<a href="newapextpartseasondiff.php" class="ecommerce-sidebar-link btn btn-primary btn-md font-weight-semibold btn-py-2 px-4" >+ Add Partner Season</a>
						</div>
                </div>
                <h3>Filters</h3>
                <div class="row mb-0">

                    <div class="col-md-4"> <label>Partner</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("pid"=>0)))?>"
                                <?php if($pid==0) { echo "selected";} ?>>
                                All</option>
                            <?php $sqlin2 = $db2->query("SELECT * FROM api_partner ") or die(mysql_error()); 
					 while($rowin2 = mysqli_fetch_array($sqlin2)) {?>



                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("pid"=>$rowin2['api_partner_id'])))?>"
                                <?php if($pid==$rowin2['api_partner_id']) { echo "selected";} ?>>
                                <?php echo $rowin2['api_partner_name'];?></option> <?php }?> 
                                
                            </select>
                    </div>
					</div>   
                    <div class="row">
                        <div class="col">
                            <section class="card">
                                <header class="card-header">
                                    <div class="card-actions">
                                        <a href="#" class="card-action card-action-toggle" data-card-toggle></a>
                                        <a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
                                    </div>

                                    <h2 class="card-title">Seasons</h2>
                                </header>

                                <div class="card-body">

                                    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
                                        <thead>
                                        <th>ID</th>
                                     <th>Partner</th>
                                       
                                         <th>Start</th>
                                     
                                       
                                        <th>End</th>
                                        
                                        <th>Adjustment</th>
                                        <th>Actions </th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                        <?php 
			$sql = "SELECT * FROM  api_gen_ext_seasons LEFT JOIN api_partner ON api_partner.api_partner_id=api_gen_ext_seasons.api_gen_ext_season_partner ";
            if ($pid!='0'){
                $sql .=" WHERE api_gen_ext_seasons.api_gen_ext_season_partner='$pid' ";
                }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    // output data of each row
   while($row = mysqli_fetch_array($result)) {
	  if ($row["api_gen_ext_season_mod"]=="+"){$color="green";} elseif ($row["api_gen_ext_season_mod"]=="-"){$color="red";}
     ?>
                                            <tr>
                                            <td><?php echo $row["api_gen_ext_season_id"]; ?></td>
                                        <td class="text-center"><?php echo $row["api_partner_name"]; ?></td>
                                        <td  class="text-center"><?php echo date('d/m/Y H:i', $row["api_gen_ext_season_start"]); ?></td>
                                          
                                             
                                              <td  class="text-center"><?php echo date('d/m/Y H:i', $row["api_gen_ext_season_end"]); ?></td>
                                              
                                              <td  class="text-center"><?php if ($row["api_gen_ext_season_mod"]!=null) {echo "<span class='$color'>".$row['api_gen_ext_season_mod'].$row['api_gen_ext_season_diff']."%</span>";} else {echo "None";} ?></td>
                                            
                                     
                                           <td class="actions">
                                                    <a href="editapextpartseasondiff.php?id=<?php echo $row["api_gen_ext_season_id"];?>"
                                                    class="on-default edit-row"><i class="fas fa-pencil-alt"></i></a>
                                                    <a href="deleteapextpartseasondiff.php?id=<?php echo $row["api_gen_ext_season_id"];?>"
                                                    class="on-default edit-row"><i class="fas fa-trash-alt"></i></a>

   </td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                </div>

                            </section>

                        </div>
                    </div>
                    <?php } }?>
                    <!-- end: page -->
            </section>
        </div>

        <?php include('include/aside.php');?>

    </section>


    <!-- Vendor -->
    <script src="vendor/jquery/jquery.js"></script>
    <script src="vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
    <script src="vendor/popper/umd/popper.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.js"></script>
    <script src="vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="vendor/common/common.js"></script>
    <script src="vendor/nanoscroller/nanoscroller.js"></script>
    <script src="vendor/magnific-popup/jquery.magnific-popup.js"></script>
    <script src="vendor/jquery-placeholder/jquery.placeholder.js"></script>

    <!-- Specific Page Vendor -->
    <script src="vendor/select2/js/select2.js"></script>
    <script src="vendor/datatables/media/js/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables/media/js/dataTables.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/dataTables.buttons.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.html5.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.print.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/JSZip-2.5.0/jszip.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/pdfmake.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/vfs_fonts.js"></script>


    <!--(remove-empty-lines-end)-->

    <!-- Theme Base, Components and Settings -->
    <script src="js/theme.js"></script>

    <!-- Theme Custom -->
    <script src="js/custom.js"></script>

    <!-- Theme Initialization Files -->
    <script src="js/theme.init.js"></script>

    <!-- Examples -->
    <script src="js/examples/examples.datatables.default.js"></script>

    <script>
        (function ($) {

            'use strict';

            var datatableInit = function () {
                var $table = $('#datatable-tabletools');


                var table = $table.dataTable({
                    
                    "pageLength": 12,
                    sDom: '<"text-right mb-md"T><"row"<"col-lg-6"l><"col-lg-6"f>><"table-responsive"t>p',
                    buttons: [{
                            extend: 'print',
                            text: 'Print'
                        },
                        {
                            extend: 'excel',
                            text: 'Excel'
                        },
                        {
                            extend: 'pdf',
                            text: 'PDF',
                            customize: function (doc) {
                                var colCount = new Array();
                                $('#datatable-tabletools').find('tbody tr:first-child td').each(
                                    function () {
                                        if ($(this).attr('colspan')) {
                                            for (var i = 1; i <= $(this).attr(
                                                'colspan'); $i++) {
                                                colCount.push('*');
                                            }
                                        } else {
                                            colCount.push('*');
                                        }
                                    });
                                doc.content[1].table.widths = colCount;
                            }
                        }
                    ]
                });

                $('<div />').addClass('dt-buttons mb-2 pb-1 text-right').prependTo(
                    '#datatable-tabletools_wrapper');

                $table.DataTable().buttons().container().prependTo('#datatable-tabletools_wrapper .dt-buttons');

                $('#datatable-tabletools_wrapper').find('.btn-secondary').removeClass('btn-secondary').addClass(
                    'btn-default');
            };

            $(function () {
                datatableInit();
            });

        }).apply(this, [jQuery]);
    </script>
</body>

</html>
<?php include('include/footer.php');?>