<?php include('include/auth.php'); 
if (isset($_GET['season'])  && $_GET['season']!='0') {
    $season=$_GET['season'];}
    else {$season='0';}
    if (isset($_GET['acriss'])  && $_GET['acriss']!='0') {
        $acriss=$_GET['acriss'];}
        else {$acriss='0';}   
        if (isset($_GET['day'])  && $_GET['day']!='0') {
            $day=$_GET['day'];}
            else {$day='0';}   
            if (isset($_GET['price'])  && $_GET['price']!='1') {
                $price=$_GET['price'];}
                else {$price='1';} 
                if (isset($_GET['mod'])  && $_GET['mod']!='no') {
                    $mod=$_GET['mod'];}
                    else {$mod='no';} 
                    if($mod=="+"){$mode=1;}elseif($mod=="-"){$mode=2;}
                    if (isset($_GET['diff'])  && $_GET['diff']!='0') {
                        $diff=$_GET['diff'];}
                        else {$diff='0';} 
                        $diff1=$diff."%";
                          
?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');?>

<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>Extended Base Rates</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>Extended Base Rates</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{

?>

                <h3>Filters</h3>
                <div class="row mb-0">

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



                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("season"=>$rowin2['api_ext_season_id'])))?>"
                                <?php if($season==$rowin2['api_ext_season_id']) { echo "selected";} ?>>
                                <?php echo $rowin2['api_ext_seasons_name'];?></option> <?php }?> 
                                
                            </select>
                    </div>
                    <div class="col-md-4"> <label>ACRISS</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("acriss"=>0)))?>"
                                <?php if($acriss=="0") { echo "selected";} ?>>
                               All</option>
                            <?php $sqlin2 = $db2->query("SELECT DISTINCT api_ext_rate_acriss FROM api_ext_rates ") or die(mysql_error()); 
					 while($rowin2 = mysqli_fetch_array($sqlin2)) {?>



                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("acriss"=>$rowin2['api_ext_rate_acriss'])))?>"
                                <?php if($acriss==$rowin2['api_ext_rate_acriss']) { echo "selected";} ?>>
                                <?php echo $rowin2['api_ext_rate_acriss'] ;?></option> <?php }?> 
                               
                            </select>
                    </div>
                    <div class="col-md-4"> <label>Day</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("day"=>0)))?>"
                                <?php if($day=="0") { echo "selected";} ?>>
                               All</option>
                            <?php $sqlin3 = $db2->query("SELECT DISTINCT api_ext_rate_day FROM api_ext_rates ") or die(mysql_error()); 
					 while($rowin3 = mysqli_fetch_array($sqlin3)) {?>



                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("day"=>$rowin3['api_ext_rate_day'])))?>"
                                <?php if($day==$rowin3['api_ext_rate_day']) { echo "selected";} ?>>
                                <?php echo $rowin3['api_ext_rate_day'] ;?></option> <?php }?> 
                               
                            </select>
                    </div>
                     </div>
                     <h3>Mass Price Modification</h3>
                <div class="row mb-0">

                    <div class="col-md-4"> <label>Modifier</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("mod"=>"no")))?>"
                                <?php if($mod=="no") { echo "selected";} ?>>
                                NO</option>
                                <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("mod"=>"+")))?>"
                                <?php if($mod=="+") { echo "selected";} ?>>
                                +</option>
                                <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("mod"=>"-")))?>"
                                <?php if($mod=="-") { echo "selected";} ?>>
                                -</option>
                            </select>
                    </div>
                    <div class="col-md-4"> <label>Difference</label>
                    <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("diff"=>0)))?>"
                                <?php if($diff=="0") { echo "selected";} ?>>
                               0</option>
                             
                            <?php $x = 1;
 
 while($x <= 100) {?>




                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("diff"=>$x)))?>"
                                <?php if($diff==$x) { echo "selected";} ?>>
                                <?php echo $mod." ".$x;?>%</option> <?php $x++; }?> 
                               
                            </select>
                    </div>
                    <div class="col-md-4">
                        <?php if ($mod!="no" && $diff!=0 && $season!=0 && $acriss!=0){?>
                    <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="massrateedit.php?car=<?php echo $acriss;?>&season=<?php echo $season;?>&diff=<?php echo $diff;?>&mod=<?php echo $mode;?>" class="ecommerce-sidebar-link btn btn-primary btn-md font-weight-semibold btn-py-2 px-4" >+ Modify All</a>
						</div>
						
					</div><?php } ?>

 </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">Rates</h2>
                                </header>

                                <div class="card-body">

                                    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                               
                                                <?php if  ($day=='0'){?>  <th>Day</th>         <?php } ?>
                                                <?php if  ($acriss=='0'){?> <th>ACRISS</th>         <?php } ?>
                                                <?php if  ($season=='0'){?> <th>Season</th>         <?php } ?>
                                                <th>Current Rate</th>
                                                <th>New Rate</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            <?php	
											$sql = "SELECT * FROM api_ext_rates LEFT JOIN api_ext_seasons ON api_ext_seasons.api_ext_season_id=api_ext_rates.api_ext_rate_seasid 
                                           
                                            WHERE api_ext_rates.api_ext_rate_seasid!='0' ";
                                                if ($season!='0'){
                                                $sql .=" AND api_ext_rates.api_ext_rate_seasid='$season' ";
                                                }
                                             
                                                if ($acriss!='0'){
                                                    $sql .=" AND api_ext_rates.api_ext_rate_acriss='$acriss' ";
                                                    }
                                                    if ($day!='0'){
                                                        $sql .=" AND api_ext_rates.api_ext_rate_day='$day' ";
                                                        }
                                                        if ($price!='1'){
                                                            $sql .=" AND api_ext_rates.api_ext_rate_price='0.00' ";
                                                            }
											$result = mysqli_query($db2,$sql);
											while($row = mysqli_fetch_array($result)) {
                                                $appr=$row['api_ext_rate_price'];
                                                if ($mod=="no" || $diff==0){ $rate=$row['api_ext_rate_price'];}
                                                else{
                                                    $gfrate=$appr*$diff1;
                                                    $gfrate2=$gfrate/100;
                                                    if($mod=="+"){
                                                        $rate2=$appr+$gfrate2;
                                                    }
                                                    elseif($mod=="-")
                                                    {$rate2=$appr-$gfrate2;}
                                                       $rate=$rate2;
                                                   }        
												?>
                                            <tr>
                                            <form name="form<?php echo $row['api_ext_rate_id'];?>" method="get" action="editextapirate.php">
                                                <td><?php echo $row['api_ext_rate_id'];?></td>
                                           
                                                <?php if  ($day=='0'){?>
                                                <td><?php echo $row['api_ext_rate_day'];?>
                                                </td>
                                                <?php } ?>
                                                <?php if  ($acriss=='0'){?>
                                                <td><?php echo $row['api_ext_rate_acriss'];?>
                                                </td>
                                                <?php } ?>
                                                <?php if  ($season=='0'){?>
                                                <td><?php echo $row['api_ext_seasons_name'];?>
                                                </td>
                                                <?php } ?>
                                                <td><?php echo $row['api_ext_rate_price'];?>
                                                </td>
                                                <td><input class="form-control" style="border: 1px dashed;"name="api_ext_rate_price" id="api_ext_rate_price" value="<?php echo $rate;?>"></td>
                                               
                                              

                                                <td class="actions">
                                                <input type="submit" name="submit"  class="btn btn-success" value="Change" >
                                                <input type="hidden" name="api_ext_rate_id" value="<?php echo $row['api_ext_rate_id'];?>">
                                                <input type="hidden" name="api_ext_rate_day" value="<?php echo $row['api_ext_rate_day'];?>">
                                                <input type="hidden" name="api_ext_rate_acriss" value="<?php echo $row['api_ext_rate_acriss'];?>">
                                                <input type="hidden" name="api_ext_rate_seasid" value="<?php echo $row['api_ext_rate_seasid'];?>">
                                                </td>
                                                </form>
                                            </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({
                    "order": [
                        [1, "asc"]
                    ],
                    "pageLength": 30,
                    "lengthMenu": [[10, 30, 50, -1], [10, 30, 50, "All"]],
                    sDom: '<"text-right mb-md"T><"row"<"col-lg-6"l><"col-lg-6"f>><"table-responsive"t>p',
                    buttons: [{
                            extend: 'print',
                            text: 'Print',
                            exportOptions: {
                    columns: [ 0, 1, 2,3 ]
                }
                        },
                        {
                            extend: 'excel',
                            text: 'Excel',
                            exportOptions: {
                    columns: [ 0, 1, 2,3 ]
                }
                        },
                        {
                            extend: 'pdf',
                            text: 'PDF',
                            exportOptions: {
                    columns: [ 0, 1, 2,3 ]
                },
                            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');?>