<?php
session_start();
require '../lib/dbclass.php';

if (!$_SESSION['challenge_startdate']) {
    $_SESSION['challenge_startdate'] = date('Y-01-01');
}

if (!$_SESSION['challenge_enddate']) {
    $_SESSION['challenge_enddate'] = date('Y-m-d');
}

$where = 'tbl_transaction.status=0 and tbl_transaction.sponsorship=0 and tbl_transaction.Amount>0 ';
$where1 .= 'tbl_transaction.status=0 and tbl_transaction.Amount>0 ';

if ($_POST) {
    $_SESSION['volunteersettlement']        = 0;
    $_SESSION['usernames']                  = $_POST['usernames'];
    $_SESSION['searchname']                 = $_POST['searchname'];
    $_SESSION['searchtransname']            = $_POST['searchtransname'];
    $_SESSION['searchTransactionType_drop'] = $_POST['searchTransactionType_drop'];
    $_SESSION['searchuser_drop']            = $_POST['searchuser_drop'];
    $_SESSION['searchclub_drop']            = $_POST['searchclub_drop'];
    $_SESSION['searchward_drop']            = $_POST['searchward_drop'];
    $_SESSION['searchpaymode_drop']         = $_POST['searchpaymode_drop'];
    $_SESSION['searchchallenge_drop']       = $_POST['searchchallenge_drop'];

    $_SESSION['challenge_startdate'] = $_POST['challenge_startdate'];
    $_SESSION['challenge_enddate']   = $_POST['challenge_enddate'];
    $_SESSION['searchpan_drop']      = $_POST['searchpan_drop'];

    $_SESSION['searchase_drop'] = $_POST['searchase_drop'];
    $_SESSION['searchdis_drop'] = $_POST['searchdis_drop'];

    if ($_POST['unpaid'] == 'on') {
        $_SESSION['unpaid'] = 1;
    } else {
        $_SESSION['unpaid'] = 0;
    }

    if ($_POST['volunteersettlement'] == 'on') {
        $_SESSION['volunteersettlement'] = 1;

        $_SESSION['searchname']                 = '';
        $_SESSION['searchTransactionType_drop'] = 0;
        $_SESSION['searchase_drop']             = 0;
        $_SESSION['searchdis_drop']             = 0;
        $_SESSION['searchpan_drop']             = 0;

        $_SESSION['searchclub_drop']    = 0;
        $_SESSION['searchward_drop']    = 0;
        $_SESSION['searchpaymode_drop'] = 0;
        $_SESSION['unpaid']             = 0;
    }

    if ($_POST['searchchallenge_drop'] == '') {
        $_SESSION['challengeid']          = 1;
        $searchchallenge_drop             = 0;
        $_SESSION['searchchallenge_drop'] = 0;
    } else {
        $_SESSION['challengeid'] = $_SESSION['searchchallenge_drop'];
        $searchchallenge_drop    = $_SESSION['searchchallenge_drop'];
    }

    if ($_POST['reset'] != 'Reset') {
        if ($_SESSION['volunteersettlement'] == 0) {
            if ($_SESSION['searchTransactionType_drop'] == 0) {
                if ($_SESSION['searchchallenge_drop'] == 0) {
                    $message = 'Select Challenge/Transaction Type';

                    $encodedMessage = urlencode($message);

                    $url = "challengereport.php?message={$encodedMessage}";

                    // Redirect to the new URL
                    echo "<script>window.location.href='{$url}';</script>";
                }
            }

            if ($_SESSION['searchchallenge_drop'] > 0) {
                if ($_SESSION['searchTransactionType_drop'] == 0) {
                    $message = 'Select Transaction Type';

                    $encodedMessage = urlencode($message);

                    $url = "challengereport.php?message={$encodedMessage}";

                    // Redirect to the new URL
                    echo "<script>window.location.href='{$url}';</script>";
                }
            }

            if ($_SESSION['searchTransactionType_drop'] < 3) {
                if ($_SESSION['searchchallenge_drop'] == 0) {
                    $message = 'Select Challenge';

                    $encodedMessage = urlencode($message);

                    $url = "challengereport.php?message={$encodedMessage}";

                    // Redirect to the new URL
                    echo "<script>window.location.href='{$url}';</script>";
                }
            }
        }
    }
}
$chlngid = $_SESSION['searchchallenge_drop'];

if ($_POST['reset'] == 'Reset') {
    $_SESSION['challenge_startdate']        = date('Y-01-01');
    $_SESSION['challenge_enddate']          = date('Y-m-d');
    $_SESSION['unpaid']                     = 0;
    $_SESSION['searchname']                 = '';
    $_SESSION['searchtransname']            = '';
    $_SESSION['searchTransactionType_drop'] = 0;
    $_SESSION['searchuser_drop']            = 0;
    $_SESSION['searchclub_drop']            = 0;
    $_SESSION['searchward_drop']            = 0;
    $_SESSION['searchpaymode_drop']         = 0;
    $searchname                             = '';
    $searchtransname                        = '';
    $searchTransactionType_drop             = 0;
    $searchuser_drop                        = 0;
    $searchclub_drop                        = 0;
    $searchward_drop                        = 0;
    $searchpaymode_drop                     = 0;
    $searchchallenge_drop                   = 0;
    $_SESSION['where']                      = '';
    $_SESSION['where1']                     = '';
    $_SESSION['challengeid']                = 0;
    $_SESSION['searchpan_drop']             = 0;
    $_SESSION['searchdis_drop']             = 0;
    $_SESSION['searchase_drop']             = 0;
    $_SESSION['volunteersettlement']        = 0;
    $_SESSION['searchchallenge_drop']       = 0;
    $searchpan_drop                         = 0;
    $searchase_drop                         = 0;
    $searchdis_drop                         = 0;
}

if ($_SESSION['searchname']) {
    $searchname = $_SESSION['searchname'];
    $where  .= " and tbl_customer.name like '%$searchname%'";
    $where1 .= " and tbl_customer.name like '%$searchname%'";
}

if ($_SESSION['searchtransname']) {
    $searchtransname = $_SESSION['searchtransname'];
    $where  .= " and tbl_transaction.Transid like '%$searchtransname%'";
    $where1 .= " and tbl_transaction.Transid like '%$searchtransname%'";
}

if ($_SESSION['challenge_startdate'] > '2000-01-01' && $_SESSION['challenge_enddate'] > '2000-01-01') {
    $challenge_startdate = $_SESSION['challenge_startdate'];
    $challenge_enddate   = $_SESSION['challenge_enddate'];

    $where  .= " and  DATE_FORMAT(tbl_transaction.dateadded, '%Y-%m-%d')  between '$challenge_startdate' and '$challenge_enddate' ";
    $where1 .= "and   DATE_FORMAT(tbl_transaction.dateadded, '%Y-%m-%d') between '$challenge_startdate' and '$challenge_enddate'";
}

if ($_SESSION['searchpan_drop'] > 0) {
    $searchpan_drop = $_SESSION['searchpan_drop'];
    $where  .= " and tbl_customer.Panchayat=$searchpan_drop";
    $where1 .= " and tbl_customer.Panchayat=$searchpan_drop";
}

if ($_SESSION['searchase_drop'] > 0) {
    $searchase_drop = $_SESSION['searchase_drop'];
    $where  .= " and tbl_customer.Assembly=$searchase_drop";
    $where1 .= " and tbl_customer.Assembly=$searchase_drop";
}

if ($_SESSION['searchdis_drop'] > 0) {
    $searchdis_drop = $_SESSION['searchdis_drop'];
    $where  .= " and tbl_customer.District=$searchdis_drop";
    $where1 .= " and tbl_customer.District=$searchdis_drop";
}

if ($_SESSION['searchTransactionType_drop'] > 0) {
    $searchTransactionType_drop = $_SESSION['searchTransactionType_drop'];
}

if ($_SESSION['searchpaymode_drop'] > 0) {
    $searchpaymode_drop = $_SESSION['searchpaymode_drop'];

    if ($searchpaymode_drop == 1) {
        $where  .= " and tbl_transaction.Transid=''";
        $where1 .= " and tbl_transaction.Transid=''";
    }

    if ($searchpaymode_drop == 2) {
        $where  .= " and tbl_transaction.Transid!=''";
        $where1 .= " and tbl_transaction.Transid!=''";
    }
}

if ($_SESSION['searchuser_drop'] > 0) {
    $searchuser_drop = $_SESSION['searchuser_drop'];
    $where  .= " and tbl_transaction.volunteer=$searchuser_drop";
    $where1 .= " and tbl_transaction.volunteer=$searchuser_drop";
}

if ($_SESSION['searchclub_drop'] > 0) {
    $searchclub_drop = $_SESSION['searchclub_drop'];
    $where  .= " and tbl_transaction.clubid=$searchclub_drop";
    $where1 .= " and tbl_transaction.clubid=$searchclub_drop";
}

if ($_SESSION['searchward_drop'] > 0) {
    $searchward_drop = $_SESSION['searchward_drop'];
    $where  .= " and tbl_customer.Ward=$searchward_drop and tbl_transaction.clubid=0 ";
    $where1 .= " and tbl_customer.Ward=$searchward_drop and tbl_transaction.clubid=0 ";
}

if ($_SESSION['searchchallenge_drop'] > 0) {
    $searchchallenge_drop = $_SESSION['searchchallenge_drop'];
}

if ($_SESSION['unpaid'] > 0) {
    $where  .= ' and tbl_transaction.Received=0';
    $where1 .= ' and tbl_transaction.Received=0';
} else {
    //$where.=" and tbl_transaction.Received>0";
    //$where1.=" and tbl_transaction.Received>0";
}
$_SESSION['where']  = $where;
$_SESSION['where1'] = $where1;

$trantype = 'tbl_transaction.status=0';
//$chlngid=0;
$data = [];

if ($_SESSION['volunteersettlement'] == 1) {
    $_SESSION['wherenew'] = '';
    $searchtransname      = $_SESSION['searchtransname'];

    if ($searchtransname != '') {
        $wherenews = "and ca_receipt.transid='$searchtransname'";
    } else {
        $wherenews = 'and ca_receipt.id>0';
    }

    if ($searchuser_drop > 0) {
        $wherenew = "DATE_FORMAT(ca_receipt.send_date, '%Y-%m-%d')  between '$challenge_startdate' and '$challenge_enddate' and ca_receipt.userid=$searchuser_drop $wherenews  ";
        $data     = findQuery("SELECT ca_receipt.*,tbl_user.name,ca_receipt.amount Received  FROM `ca_receipt` inner join tbl_user on tbl_user.id=ca_receipt.userid
     where $wherenew order by ca_receipt.id desc");
    } else {
        $wherenew = "DATE_FORMAT(ca_receipt.send_date, '%Y-%m-%d')  between '$challenge_startdate' and '$challenge_enddate' $wherenews";

        $data = findQuery("SELECT ca_receipt.*,tbl_user.name  FROM `ca_receipt` inner join tbl_user on tbl_user.id=ca_receipt.userid where $wherenew  order by ca_receipt.id desc
     ");
    }

    $_SESSION['wherenew'] = $wherenew;
} elseif ($searchTransactionType_drop == 1) {
    $trantype .= ' and tbl_transaction.sponsorship=0';



    $data = findQuery("SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    
    ,tbl_transaction.dateadded ordrddate,
     tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where $where and tbl_transaction.challengeid=$chlngid and  tbl_transaction.volunteer>0 
    
    union all
    
    SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    ,tbl_transaction.dateadded ordrddate,
      tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where $where and tbl_transaction.challengeid=$chlngid and  tbl_transaction.volunteer=0 and tbl_transaction.Received>0
    
     ");

    function array_msort($array, $cols)
    {
        $colarr = [];

        foreach ($cols as $col => $order) {
            $colarr[$col] = [];

            foreach ($array as $k => $row) {
                $colarr[$col]['_' . $k] = strtolower($row[$col]);
            }
        }
        $eval = 'array_multisort(';

        foreach ($cols as $col => $order) {
            $eval .= '$colarr[\'' . $col . '\'],' . $order . ',';
        }
        $eval = substr($eval, 0, -1) . ');';
        eval($eval);
        $ret = [];

        foreach ($colarr as $col => $arr) {
            foreach ($arr as $k => $v) {
                $k = substr($k, 1);

                if (!isset($ret[$k])) {
                    $ret[$k] = $array[$k];
                }
                $ret[$k][$col] = $array[$k][$col];
            }
        }

        return $ret;
    }
    $data = array_msort($data, ['id' => SORT_DESC]);

    $data = array_values($data);
} elseif ($searchTransactionType_drop == 2) {
    $trantype .= ' and tbl_transaction.sponsorship=1';

    $data = findQuery("SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    ,tbl_transaction.dateadded ordrddate
    ,
      tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where tbl_transaction.status=0 and tbl_transaction.sponsorship=1 and tbl_transaction.challengeid=$chlngid and $where1 
    and  tbl_transaction.volunteer=0 and tbl_transaction.Received>0
    
    
    union all
    
    SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    ,tbl_transaction.dateadded ordrddate
    ,
      tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where tbl_transaction.status=0 and tbl_transaction.sponsorship=1 and tbl_transaction.challengeid=$chlngid 
    and $where1 and  tbl_transaction.volunteer>0 
    
");

    function array_msort($array, $cols)
    {
        $colarr = [];

        foreach ($cols as $col => $order) {
            $colarr[$col] = [];

            foreach ($array as $k => $row) {
                $colarr[$col]['_' . $k] = strtolower($row[$col]);
            }
        }
        $eval = 'array_multisort(';

        foreach ($cols as $col => $order) {
            $eval .= '$colarr[\'' . $col . '\'],' . $order . ',';
        }
        $eval = substr($eval, 0, -1) . ');';
        eval($eval);
        $ret = [];

        foreach ($colarr as $col => $arr) {
            foreach ($arr as $k => $v) {
                $k = substr($k, 1);

                if (!isset($ret[$k])) {
                    $ret[$k] = $array[$k];
                }
                $ret[$k][$col] = $array[$k][$col];
            }
        }

        return $ret;
    }
    $data = array_msort($data, ['id' => SORT_DESC]);

    $data = array_values($data);
} elseif ($searchTransactionType_drop == 3) {
    $trantype .= ' and tbl_transaction.donation=1';

    $data = findQuery("SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    ,tbl_transaction.dateadded ordrddate
    ,
      tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where tbl_transaction.status=0 and tbl_transaction.donation=1 and $where1 and  
    tbl_transaction.volunteer=0 and tbl_transaction.Received>0
    
    
    union all
    
    
    SELECT 
    tbl_transaction.id,
    tbl_transaction.orderforothers,
    tbl_customer.id cuid,
    tbl_customer.name,
     tbl_customer.Mobile
    ,tbl_ward.ward_name
    ,tbl_panchayat.panchayat_name
    ,tbl_assembly.name assembly
    ,
    tbl_district.district_name
    ,tbl_transaction.Received
    ,tbl_transaction.Amount
    ,tbl_transaction.Transid
    ,tbl_transaction.dateadded ordrddate
    ,
      tbl_transaction.clubid
     from tbl_transaction
     inner join tbl_customer on tbl_customer.id=tbl_transaction.customerid inner join tbl_ward on tbl_ward.id=tbl_customer.Ward inner join tbl_panchayat on tbl_panchayat.id=tbl_customer.Panchayat
    inner join tbl_assembly on tbl_assembly.id=tbl_customer.Assembly 
    inner join tbl_district on tbl_district.id=tbl_customer.District where tbl_transaction.status=0 and tbl_transaction.donation=1 and $where1 and  
    tbl_transaction.volunteer>0
    
    
");

    function array_msort($array, $cols)
    {
        $colarr = [];

        foreach ($cols as $col => $order) {
            $colarr[$col] = [];

            foreach ($array as $k => $row) {
                $colarr[$col]['_' . $k] = strtolower($row[$col]);
            }
        }
        $eval = 'array_multisort(';

        foreach ($cols as $col => $order) {
            $eval .= '$colarr[\'' . $col . '\'],' . $order . ',';
        }
        $eval = substr($eval, 0, -1) . ');';
        eval($eval);
        $ret = [];

        foreach ($colarr as $col => $arr) {
            foreach ($arr as $k => $v) {
                $k = substr($k, 1);

                if (!isset($ret[$k])) {
                    $ret[$k] = $array[$k];
                }
                $ret[$k][$col] = $array[$k][$col];
            }
        }

        return $ret;
    }
    $data = array_msort($data, ['id' => SORT_DESC]);

    $data = array_values($data);
}
?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Language" content="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CH CENTER TIRUR</title>
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
    <meta name="description" content="CH CENTER TIRUR">

    <link rel="icon" type="image/x-icon" href="../assets/images/Shade logo.png">
    <link href="..\assets\css\main.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/daterangepicker.css">

</head>

<body>
    <div class="app-container app-theme-white body-tabs-shadow fixed-sidebar fixed-header">
        <div class="app-header header-shadow">
            <div class="app-header__logo">
                <div class="logo-sr">
                    <img width="55px" src="../assets/images/Shade logo.png" alt="">
                </div>
                <div class="header__pane ml-auto">
                    <div>
                        <button type="button" class="hamburger close-sidebar-btn hamburger--elastic"
                            data-class="closed-sidebar">
                            <span class="hamburger-box">
                                <span class="hamburger-inner"></span>
                            </span>
                        </button>
                    </div>
                </div>
            </div>





            <div class="app-header__mobile-menu">
                <div>
                    <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                        <span class="hamburger-box">
                            <span class="hamburger-inner"></span>
                        </span>
                    </button>
                </div>
            </div>
            <div class="app-header__menu">
                <span>
                    <button type="button"
                        class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                        <span class="btn-icon-wrapper">
                            <i class="fa fa-ellipsis-v fa-w-6"></i>
                        </span>
                    </button>
                </span>
            </div>
            <div class="app-header__content">

                <div class="app-header-right">
                    <div class="header-btn-lg pr-0">
                        <div class="widget-content p-0">
                            <div class="widget-content-wrapper">

                                <div class="widget-content-left  ml-3 header-user-info">
                                    <!--<div class="widget-heading">
                                      <?php
// $data1 = findQuery("select * from tbl_user where status=0");
?>
                                    </div>
                                    <div class="widget-subheading">
                                        Admin
                                    </div>-->
                                </div>

                                <div class="d-inline-block dropdown ml-3 p-0">
                                    <button style="width: 40px;" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false"
                                        class="btn-shadow dropdown-toggle btn btn-info" fdprocessedid="rwibbh">


                                        <img style="width: 100%;" src="../assets/images/Shade logo.png" alt="">
                                    </button>
                                    <div tabindex="-1" role="menu" aria-hidden="true"
                                        class="dropdown-menu dropdown-menu-right">
                                        <ul class="nav flex-column">
                                            <li class="nav-item">
                                                <a href="logout.php" class="nav-link">
                                                    <i class="nav-link-icon lnr-inbox"></i>
                                                    <span> Logout</span>
                                                </a>
                                            </li>

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

        <div class="app-main">
            <div class="app-sidebar sidebar-shadow">
                <div class="app-header__logo">

                    <div class="header__pane ml-auto">
                        <div>
                            <button type="button" class="hamburger close-sidebar-btn hamburger--elastic "
                                id="toggleButton-header">
                                <span class="hamburger-box">
                                    <span class="hamburger-inner"></span>
                                </span>
                            </button>

                        </div>
                    </div>
                </div>
                <div class="app-header__mobile-menu">
                    <div>
                        <img src="../../assets/images/Shade logo.png" alt="">
                        <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                            <span class="hamburger-box">
                                <span class="hamburger-inner"></span>
                            </span>
                        </button>
                    </div>
                </div>
                <div class="app-header__menu">
                    <span>
                        <button type="button"
                            class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                            <span class="btn-icon-wrapper">
                                <i class="fa fa-ellipsis-v fa-w-6"></i>
                            </span>
                        </button>
                    </span>
                </div>
                <div class="scrollbar-sidebar ps ps--active-y">
                    <div class="app-sidebar__inner">
                        <ul class="vertical-nav-menu metismenu">

                            
                            
                            <li>
                                <a href="../Assembly_Management/assembly_management.php">

                                    <i class="fa fa-sitemap" aria-hidden="true"></i> </i>Assembly Management
                                </a>
                            </li>
                            <li>
                                <a href="../Panchayat/panchayat_management.php">

                                    <i class="fa fa-industry" aria-hidden="true"></i> </i>Panchayat Management
                                </a>
                            </li>
                            <li>
                                <a href="../Ward/ward_management.php">

                                    <i class="fa fa-home" aria-hidden="true"></i>Ward management
                                </a>
                            </li>
                            <li>
                                <a href="../Club/club_management.php">

                                    <i class="fa fa-sign-language" aria-hidden="true"></i></i>Organisation
                                </a>
                            </li>
                            
                            <li>
                                <a href="../SPNRProduct/spnr_product_management.php">

                                    <i class="fa fa-shopping-basket" aria-hidden="true"></i>Sponsor Product Management
                                </a>
                            </li>
                            <li>
                                <a href="../Challenge/challenge_management.php">

                                    <i class="fa fa-shopping-bag" aria-hidden="true"></i></i>Challenge Management
                                </a>
                            </li>
                            <li>
                                <a href="../User/user_management.php">

                                    <i class="fa fa-users" aria-hidden="true"></i>User Management
                                </a>
                            </li>
                              <li>
                                <a href="../ChallengeReport/challengereport.php">

                                    <i class="fa fa-users" aria-hidden="true"></i>Challenge Report
                                </a>
                            </li>


                        </ul>
                    </div>
                    <div class="ps__rail-x" style="left: 0px; bottom: 0px;">
                        <div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
                    </div>
                    <div class="ps__rail-y" style="top: 0px; height: 643px; right: 0px;">
                        <div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 610px;"></div>
                    </div>
                </div>
            </div>

            <div class="app-main__outer w-100">
                <div class="app-main__inner">

                    <div class="app-page-title app-page-title-simple">
                        <div class="page-title-wrapper d-flex justify-content-between">
                            <div class="page-title-heading">
                                <div>
                                    <div class="page-title-head center-elem mb-3">
                                        <span class="d-inline-block">
                                            <i class="lnr-apartment opacity-6"></i>
                                        </span>
                                        <span class="d-inline-block">Challenge Report</span>

                                    </div>


                                </div>
                            </div>

                            <nav class="" aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="challengereport.php">Challenge Report</a></li>

                                </ol>
                            </nav>






                        </div>
                        
                        
                        
                       <div class="row">
							<div class="col-md-6 col-xl-4">
								<div class="card mb-3 widget-content">
									<div class="widget-content-outer">
										<div class="widget-content-wrapper">
											<div class="widget-content-left">
											    	<?php if ($searchTransactionType_drop == 1) { ?>
												<div class="widget-heading">Total Participants</div>
													  <?php } else { ?>
												<div class="widget-heading">Total Participants</div> 
													   <?php } ?>
												<div class="widget-subheading"></div>
											</div>
											<div class="widget-content-right">
												<div class="widget-numbers text-info">
													<?php
             $count = 0;

if ($chlngid > 0 && $searchTransactionType_drop > 0) {
    if ($searchTransactionType_drop == 2) {
        $count = count($data);
    } elseif ($searchTransactionType_drop == 1) {
        $count = count($data);
    } else {
        $count = count($data);
    }
}
echo $count;
?>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="col-md-6 col-xl-4">
								<div class="card mb-3 widget-content">
									<div class="widget-content-outer">
										<div class="widget-content-wrapper">
											<div class="widget-content-left">
												<div class="widget-heading">Amount Received </div>
												<div class="widget-subheading"></div>
											</div>
											<div class="widget-content-right">
												<div class="widget-numbers text-success">
													<?php
$count = 0;

if ($searchTransactionType_drop == 3) {
    $totalReceived = 0;

    foreach ($data as $entry) {
        $totalReceived += $entry['Received'];
    }
    $count = $totalReceived;
} elseif ($chlngid > 0 && $searchTransactionType_drop > 0) {
    $totalReceived = 0;

    foreach ($data as $entry) {
        $totalReceived += $entry['Received'];
    }
    $count = $totalReceived;
}
echo $count;
?>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="col-md-6 col-xl-4">
								<div class="card mb-3 widget-content">
									<div class="widget-content-outer">
										<div class="widget-content-wrapper">
											<div class="widget-content-left">
												<div class="widget-heading">Amount Pending</div>
												<div class="widget-subheading"></div>
											</div>
											<div class="widget-content-right">
												<div class="widget-numbers text-danger">
													<?php
$count = 0;

if ($chlngid > 0 && $searchTransactionType_drop > 0) {
    $totalReceived = 0;
    $totalAmount   = 0;

    foreach ($data as $entry) {
        $totalReceived += $entry['Received'];
        $totalAmount   += $entry['Amount'];
    }
    $count = $totalAmount - $totalReceived;
}
echo $count;
?>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>



<div class="row ">
                            <div class="col-md-12">
                                <div class="main-card mb-3 card">
                                    <div class="card-body">
                                        <h5 class="card-title">Search</h5>
                                        <form class="" novalidate="true" action="<?php echo siteurl . 'ChallengeReport/challengereport.php'; ?>" method="post">
    <div class="form-row">
        
        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Challenge</label>
            <?php $challenge = get_option('tbl_challenge', 'challenge_name', 'id!=0 and status=0'); ?>
            <select name="searchchallenge_drop" id="searchchallenge_drop" class="mb-2 form-control select2">
                <?php echo array_options($challenge, $searchchallenge_drop); ?>
            </select>
        </div>
        
        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Transaction Type</label>
            <?php $assembly = [0 => 'Select', 1 => 'Challenge', 'Sponsor', 'Donation']; ?>
            <select name="searchTransactionType_drop" id="searchTransactionType_drop" class="mb-2 form-control select2">
                <?php echo array_options($assembly, $searchTransactionType_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Paymode</label>
            <?php $paymode = [0 => 'Select', 1 => 'By Cash', 'Online']; ?>
            <select name="searchpaymode_drop" id="searchpaymode_drop" class="mb-2 form-control select2">
                <?php echo array_options($paymode, $searchpaymode_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Volunteer</label>
            <?php $user = get_option('tbl_user', 'name', 'id!=0'); ?>
            <select name="searchuser_drop" id="searchuser_drop" class="mb-2 form-control select2">
                <?php echo array_options($user, $searchuser_drop); ?>
            </select>
        </div>
    </div>

    <div class="form-row">
        
        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">District</label>
            <?php $dis = get_option('tbl_district', 'district_name', 'id!=0 and status=0'); ?>
            <select name="searchdis_drop" id="searchdis_drop" class="mb-2 form-control select2">
                <?php echo array_options($dis, $searchdis_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Assembly</label>
            
           <?php
           $assembly_id = $_SESSION['searchdis_drop'];

if ($assembly_id > 0) {
    $ase = get_option('tbl_assembly', 'name', 'status=0 and district=' . $assembly_id);
} else {
    $ase = get_option('tbl_assembly', 'name', 'status=0 and district=-1');
}
?>
            <select name="searchase_drop" id="searchase_drop" class="mb-2 form-control select2">
                <?php echo array_options($ase, $searchase_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Panchayat</label>
            
            <?php
$pan_id = $_SESSION['searchase_drop'];

if ($pan_id > 0) {
    $ase1 = get_option('tbl_panchayat', 'panchayat_name', 'status=0 and assembly_id=' . $pan_id);
} else {
    $ase1 = get_option('tbl_panchayat', 'panchayat_name', 'status=0 and assembly_id=-1');
}
?>
          
            <select name="searchpan_drop" id="searchpan_drop" class="mb-2 form-control select2">
                 <?php echo array_options($ase1, $searchpan_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Ward</label>
            
             <?php
$wrd_id = $_SESSION['searchpan_drop'];

if ($wrd_id > 0) {
    $ase11 = get_option('tbl_ward', 'ward_name', 'status=0 and panchayat_id=' . $wrd_id);
} else {
    $ase11 = get_option('tbl_ward', 'ward_name', 'status=0 and panchayat_id=-1');
}
?>
          
            <select name="searchward_drop" id="searchward_drop" class="mb-2 form-control select2">
                <?php echo array_options($ase11, $searchward_drop); ?>
            </select>
        </div>
    </div>

    <div class="form-row">
        
        <div class="col-12 col-sm-6 col-md-3 mb-3">
            <label for="validationCustom01">Organisation</label>
            <?php $club = get_option('tbl_club', 'club_name', 'id!=0 and status=0'); ?>
            <select name="searchclub_drop" id="searchclub_drop" class="mb-2 form-control select2">
                <?php echo array_options($club, $searchclub_drop); ?>
            </select>
        </div>

        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <label for="validationCustom01">Name</label>
            <input type="text" class="form-control" id="searchname" name="searchname" fdprocessedid="6j5eqm" value="<?php echo $searchname; ?>">
        </div>

        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <label for="validationCustom01">Transaction ID</label>
            <input type="text" class="form-control" id="searchtransname" name="searchtransname" fdprocessedid="6j5eqm" value="<?php echo $searchtransname; ?>">
        </div>

        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <label for="validationCustom01">Start Date</label>
            <input type="date" class="form-control" id="challenge_startdate" name="challenge_startdate" placeholder="Enter challenge start date" value="<?php echo $_SESSION['challenge_startdate']; ?>" required="true">
        </div>

        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <label for="validationCustom01">End Date</label>
            <input type="date" class="form-control" id="challenge_enddate" name="challenge_enddate" placeholder="Enter challenge end date" value="<?php echo $_SESSION['challenge_enddate']; ?>" required="true">
        </div>
    </div>

    <div class="form-row">
        
        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <br>
            <input type="checkbox" id="volunteersettlement" name="volunteersettlement" <?php if ($_SESSION['volunteersettlement'] == 1) {
                echo 'checked="checked"';
            } ?> onchange="setFries(this);">
            <label for="validationCustom01">Show Volunteer Settlement Details</label>
        </div>

        <div class="col-12 col-sm-6 col-md-4 mb-2">
            <br>
            <input type="checkbox" id="unpaid" name="unpaid" <?php if ($_SESSION['unpaid'] == 1) {
                echo 'checked="checked"';
            } ?>>
            <label for="validationCustom01">Show unpaid</label>
        </div>
    </div>

    <div class="d-flex justify-content-end">
        <button class="btn btn-outline-dark mx-3" name="reset" type="submit" value="Reset">Reset</button>
        <button class="btn btn-success" type="submit" fdprocessedid="xryn1r">Search</button>
        <input type="hidden" name="usernames" value="<?php echo $_SESSION['usernames']; ?>">
        &nbsp &nbsp
        
        <?php if ($_SESSION['usernames'] == 'online') { ?>
            <button class="btn btn-success">
                <a class="text-white" href="addpayment.php">Add Payment</a>
            </button>
        <?php } ?>
    </div>
</form>


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




                        <div class="row">
                            <div class="col-md-12">
                                <div class="main-card mb-3 card" >
                                    <div class="card-header d-flex justify-content-center">Report
                                        <div class="btn-actions-pane-right">
                                            <div role="group" class="btn-group-sm btn-group">

                                                <div class="app-header-left py-1">
                                                    <div class="search-wrapper">
                                                        <div class="input-holder">
                                                            <!--<input type="text" class="search-input"
                                                                placeholder="Type to search" id="searchInput-header"
                                                                onkeyup="searchTable()">
                                                            <button class="search-icon"><span></span></button>-->
                                                        </div>
                                                       <button id="search-close-new" class="close"></button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        </button>
                                        
                                        
                                    </div>
                                    <div class="table-responsive">
                                        <table
                                            class="align-middle mb-0 table table-borderless table-striped table-hover">
                                            <thead>
                                                
                                                <?php if ($_SESSION['volunteersettlement'] == 1) { ?>
                                                      <th class="text-left">Si.No</th>
                                                    <th class="text-left">Name</th>
                                                     <th class="text-left">Date</th>
													  <th class="text-left">Amount</th>
													   <th class="text-left">Transaction ID</th>
												<?php } else { ?>
                                                     
                                                     <tr>
                                                    <th class="text-left">Si.No</th>
                                                    <th class="text-left">Name</th>
                                                    <th class="text-left">Mobile</th>
                                                    
                                                    <th class="text-left">Date</th>
                                                    <th class="text-left">Assembly</th>
                                                    <th class="text-left">Panchayat</th>
                                                    <th class="text-left">Ward</th>
                                                    <th class="text-left">Organisation</th>
                                                    <?php if ($searchTransactionType_drop == 1) { ?>
													  <th class="text-left">Product</th>
													  <th class="text-left">Qty</th>
													  
													<?php } elseif ($searchTransactionType_drop == 2) { ?>
													  <th class="text-left">Product & Qty</th>
													 
													<?php } ?>
                                                    <th class="text-left">Amount</th>
                                                    <th class="text-left">Received</th>
                                                    <th class="text-left">Transaction ID</th>
                                                    <th class="text-left">Action</th>


                                                </tr>
                                                
                                                <?php } ?>
                                            </thead>
                                            <tbody id="tabledata-new">
                                                <?php
                                                // Define the number of records per page
                                                $recordsPerPage = 50;

// Calculate the total number of pages
$totalPages = ceil(count($data) / $recordsPerPage);

// Determine the current page number
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
    $currentPage = $_GET['page'];
} else {
    $currentPage = 1;
}

// Calculate the starting record for the current page
$start = ($currentPage - 1) * $recordsPerPage;

// Slice the data array to display only the records for the current page
$paginatedData = array_slice($data, $start, $recordsPerPage);
$name          = '';

// Display the paginated data
foreach ($paginatedData as $index => $row) {
    if ($_SESSION['volunteersettlement'] == 0) {
        $clubbid   = $row['clubid'];
        $dataaclub = findQuery("SELECT * FROM tbl_club WHERE id=$clubbid");
        $id        = $row['id'];
        $cuid      = $row['cuid'];

        if ($row['orderforothers'] == 1) {
            $dataaddrs     = findQuery("SELECT * FROM tbl_transaction WHERE id=$id");
            $address       = $dataaddrs[0]['address'];
            $row['Mobile'] = $dataaddrs[0]['mobile'];
            $row['name']   = $dataaddrs[0]['name'];
        } else {
            $dataaddrs = findQuery("SELECT * FROM tbl_customer WHERE id=$cuid");
            $address   = $dataaddrs[0]['Address'];

            if ($address == '') {
                $address = 'NA';
            }
        }

        if ($searchTransactionType_drop == 1) {
            $Ordrdqty1 = 0;
            $dataprod  = findQuery("SELECT tbl_transactiondetails.item,tbl_transactiondetails.qty,tbl_transactiondetails.rate FROM `tbl_transaction`
													inner join tbl_transactiondetails on tbl_transaction.id=tbl_transactiondetails.hdrid where tbl_transactiondetails.hdrid=$id order by tbl_transactiondetails.item");
            $product = '';

            if ($dataprod) {
                $datae = findQuery("select * from  `tbl_challenge` where id=$chlngid");

                if ($datae) {
                    $prod1 = 0;
                    $prod2 = 0;
                    $prod3 = 0;

                    $qty1 = 0;
                    $qty2 = 0;
                    $qty3 = 0;

                    $product1  = '';
                    $product2  = '';
                    $product3  = '';
                    $Ordrdqty1 = 0;
                    $Ordrdqty2 = 0;
                    $Ordrdqty3 = 0;

                    if ($dataprod[0]['item']) {
                        if ($dataprod[0]['item'] == 1) {
                            $prod1 = 1;
                            $qty1  = $dataprod[0]['qty'];
                        } elseif ($dataprod[0]['item'] == 2) {
                            $prod2 = 2;
                            $qty2  = $dataprod[0]['qty'];
                        } else {
                            $prod3 = 3;
                            $qty3  = $dataprod[0]['qty'];
                        }
                    }

                    if ($dataprod[1]['item']) {
                        if ($dataprod[1]['item'] == 1) {
                            $prod1 = 1;
                            $qty1  = $dataprod[1]['qty'];
                        } elseif ($dataprod[1]['item'] == 2) {
                            $prod2 = 2;
                            $qty2  = $dataprod[1]['qty'];
                        } else {
                            $prod3 = 3;
                            $qty3  = $dataprod[1]['qty'];
                        }
                    }

                    if ($dataprod[2]['item']) {
                        if ($dataprod[2]['item'] == 1) {
                            $prod1 = 1;
                            $qty1  = $dataprod[2]['qty'];
                        } elseif ($dataprod[2]['item'] == 2) {
                            $prod2 = 2;
                            $qty2  = $dataprod[2]['qty'];
                        } else {
                            $prod3 = 3;
                            $qty3  = $dataprod[2]['qty'];
                        }
                    }

                    if ($prod1 == 1) {
                        $product1  = $datae[0]['product_name1'];
                        $Ordrdqty1 = $qty1;
                    }

                    if ($prod2 == 2) {
                        $product2  = $datae[0]['product_name2'];
                        $Ordrdqty2 = $qty2;
                    }

                    if ($prod3 == 3) {
                        $product3  = $datae[0]['product_name3'];
                        $Ordrdqty3 = $qty3;
                    }
                }
            }
        } else {
            $dataprod = findQuery(
                "SELECT tbl_product.product_name,tbl_transactiondetails.qty,tbl_transactiondetails.rate FROM `tbl_transaction` inner join tbl_transactiondetails on tbl_transaction.id=tbl_transactiondetails.hdrid inner join tbl_product on tbl_product.id=tbl_transactiondetails.item where tbl_transactiondetails.hdrid=$id"
            );
            $product = '';

            if ($dataprod) {
                for ($iq = 0; $iq < count($dataprod); $iq++) {
                    $product .= $dataprod[$iq]['product_name'] . ' (' . $dataprod[$iq]['qty'] . ') ,';
                    $product = rtrim($product, ',');
                }
            }
        }
    } ?>
												
												<?php if ($_SESSION['volunteersettlement'] == 1) { ?>
												    <tr>
														<td class="text-left text-muted"><?php echo $index + $start + 1; ?>.</td>
														
															<td class="text-left"><?php echo $row['name']; ?></td>
														
																<td class="text-left"><?php echo date('d-m-Y', strtotime($row['send_date'])); ?></td>
																	<td class="text-left"><?php echo $row['amount']; ?></td>
																	<td class="text-left"><?php echo $row['transid'] ? $row['transid'] : 'NA'; ?></td>
														
													</tr>
														<?php $name = $row['ward_name'];
												} else { ?>
												   <tr>
														<td class="text-left text-muted"><?php echo $index + $start + 1; ?>.</td>
															<td class="text-left"><?php echo $row['name']; ?></td>
														<td class="text-left"><?php echo $row['Mobile']; ?></td>
														
														
														<td class="text-left"><?php echo date('d-m-Y', strtotime($row['ordrddate'])); ?></td>
														<td class="text-left"><?php echo $row['assembly']; ?></td>
														<td class="text-left"><?php echo $row['panchayat_name']; ?></td>
														<td class="text-left"><?php echo $row['ward_name']; ?></td>
														<td class="text-left"><?php echo $dataaclub[0]['club_name'] ? $dataaclub[0]['club_name'] : 'NA'; ?></td>
														
														<?php if ($searchTransactionType_drop == 1) { ?>
													  <td class="text-left"><?php echo $product1; ?></td>
													   <td class="text-left"><?php echo $Ordrdqty1; ?></td>
													    
													<?php } elseif ($searchTransactionType_drop == 2) { ?>
													  <td class="text-left"><?php echo $product; ?></td>
													  <?php } ?>
														
														
														<td class="text-left"><?php echo $row['Amount']; ?></td>
														<td class="text-left"><?php echo $row['Received']; ?></td>
														<td class="text-left"><?php echo $row['Transid'] ? $row['Transid'] : 'NA'; ?></td>
														
														<?php if ($row['Received'] == 0) { ?>
														
														<td class="text-left">
															
														
														
														<!--	<a class="mb-4 mr-2 badge badge-danger" href="block.php?blockid=<?php echo $row['id']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')">Delete</i></a> -->
                                                            
                                                           
                                                        <a class="mb-4 mr-2 badge badge-success" href="receipt.php?blockid=<?php echo $row[
												            'id'
												        ]; ?>" title="click for receipt" onclick="return confirm('Sure To Receive Full Amount ?')">Receive</i></a>
                                                            
                                                        <a class="mb-2 mr-2 badge badge-warning" href="add_user.php?blockid=<?php echo $row['id']; ?>" title="click for edit">Edit</a>
                                                            

														</td>
												<?php } else { ?>
														
														<td class="text-left">
															
														<a class="mb-2 mr-2 badge badge-warning" href="add_user.php?blockid=<?php echo $row['id']; ?>" title="click for edit">Edit</a>
                                                            
                                                        <button type="button" class="btn btn-success">Paid</button>
                                                            

														</td>
												<?php } ?>
													</tr> 
														<?php }
												}
?>
                                            </tbody>
                                            
                                        </table>
<div class="d-flex justify-content-end">
<?php if ($totalPages > 0) {
    if ($searchTransactionType_drop == 1) { ?>
<button class="mb-2 mr-2 btn btn-success" fdprocessedid="07uj0u"><a
                                                class="text-white" href="Challengeexport.php">Export</a>
                                        </button>
 <?php } elseif ($searchTransactionType_drop == 2) { ?>
<button class="mb-2 mr-2 btn btn-success" fdprocessedid="07uj0u"><a
                                                class="text-white" href="Sponsorexport.php">Export</a>
                                        </button>
 <?php } elseif ($searchTransactionType_drop == 3) { ?>
<button class="mb-2 mr-2 btn btn-success" fdprocessedid="07uj0u"><a
                                                class="text-white" href="Donationexport.php">Export</a>
                                        </button>
 <?php } elseif ($_POST['volunteersettlement'] == 'on') { ?>
<button class="mb-2 mr-2 btn btn-success" fdprocessedid="07uj0u"><a
                                                class="text-white" href="volunteersettlement.php">Export</a>
                                        </button>
 <?php }
 } ?>
                                    </div>
                                    </div>
                                    
                                    
                                </div>
                                <?php if ($totalPages > 0) { ?>                           
                              <ul class="pagination pagination-sm d-flex justify-content-end">
    <!-- Previous page link -->
    <?php if ($currentPage > 1) { ?>
        <li class="page-item"><a href="?page=<?php echo $currentPage - 1; ?>" class="page-link" aria-label="Previous"><span aria-hidden="true">«</span><span class="sr-only">Previous</span></a></li>
    <?php } else { ?>
        <li class="page-item disabled"><span class="page-link" aria-label="Previous"><span aria-hidden="true">«</span><span class="sr-only">Previous</span></span></li>
    <?php } ?>

    <!-- Page numbers -->
    <li class="page-item <?php echo $currentPage == 1 ? 'active' : ''; ?>"><a href="?page=1" class="page-link">1</a></li>

    <?php
     // Define the range of neighboring pages to show
     $neighboringPages = 2;

                                    // Show ellipsis if there are more than 5 pages after the current page
                                    if ($totalPages - $currentPage - $neighboringPages > 1) { ?>
        <li class="page-item disabled"></li>
    <?php }

                                    // Loop through the pages
                                    for ($i = max(2, $currentPage - $neighboringPages); $i <= min($currentPage + $neighboringPages, $totalPages); $i++) { ?>
        <?php if ($i != 1 && $i != $totalPages) { ?>
            <li class="page-item <?php echo $i == $currentPage ? 'active' : ''; ?>"><a href="?page=<?php echo $i; ?>" class="page-link"><?php echo $i; ?></a></li>
        <?php } ?>
    <?php }

                                    // Show ellipsis if there are more than 5 pages after the current page
                                    if ($totalPages - $currentPage - $neighboringPages > 1) { ?>
        <li class="page-item disabled"><span class="page-link">...</span></li>
    <?php }
                                    ?>

    <!-- End of pagination -->
    <?php if ($totalPages != 1) { ?>
        <li class="page-item"><a href="?page=<?php echo $totalPages; ?>" class="page-link"><?php echo $totalPages; ?></a></li>
    <?php } ?>

    <!-- Next page link -->
    <?php if ($currentPage < $totalPages) { ?>
        <li class="page-item"><a href="?page=<?php echo $currentPage + 1; ?>" class="page-link" aria-label="Next"><span aria-hidden="true">»</span><span class="sr-only">Next</span></a></li>
    <?php } else { ?>
        <li class="page-item disabled"><span class="page-link" aria-label="Next"><span aria-hidden="true">»</span><span class="sr-only">Next</span></span></li>
    <?php } ?>
</ul>
<?php } ?>

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

                <div class="app-wrapper-footer">
                    <div class="app-footer">
                        <div class="app-footer__inner d-flex justify-content-center">
                            <li style="list-style-type: none;">Developed by <a
                                    href="https://workmateinfotech.com/">Workmate Infotech Pvt Ltd</a> </li>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
        
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
            style="display: none;" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-file-import">

                        <form id="uploadForm" role="form" method="post" action="<?php echo siteurl . 'Panchayat/import/save.php'; ?>" enctype="multipart/form-data">
							<div class="card">
								<h3>Import Files</h3>
								<div class="drop_box">
									<header>
										<h4>Select File here</h4>
									</header>
									<p>Please choose file for importing</p>
								
		                            
		                           <input class="mb-3" style="margin-left: 100px;" type="file" name="csv_file[]" accept=".xlsx,.xls" required>
										
									<button type="submit" name="upload" class="btn btn-primary">- Import-</button>
								</div>
							</div>
							<!-- Add any other form fields or buttons here if needed -->
						</form>
						
						
						

						<script>
							document.getElementById('fileInput').addEventListener('change', function() {
								document.getElementById('uploadForm').submit();
							});
						</script>


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


        <!-- Modal HTML -->
        <div class="yes-or-n0-modal">
            <div id="myModalyesorno" class="modal fade">
                <div class="modal-dialog modal-confirm">
                    <div class="modal-content">
                        <div class="modal-header bg-white flex-column">
                            <div class="icon-box">
                                <i class="fa fa-exclamation-circle" aria-hidden="true"></i>
                            </div>
                            <h4 class="modal-title w-100">Sure to block?</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                        <div class="modal-body">
                            <p>Do you really want to block these record? </p>
                        </div>
                        <div class="modal-footer bg-white justify-content-center">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-danger">Delete</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="success_modal_new">
            <div class="modal fade show" id="statusSuccessModal" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false">
                <div class="modal-dialog modal-dialog-centered modal-sm" role="document">
                    <div class="modal-content">
                        <div class="modal-body text-center p-lg-4">
                            <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
                                <circle class="path circle" fill="none" stroke="#198754" stroke-width="6" stroke-miterlimit="10" cx="65.1" cy="65.1" r="62.1" />
                                <polyline class="path check" fill="none" stroke="#198754" stroke-width="6" stroke-linecap="round" stroke-miterlimit="10" points="100.2,40.2 51.5,88.8 29.8,67.5 " />
                            </svg>
                            <h4 class="text-success mt-3">Oh Yeah!</h4>
                            <p class="mt-3">
                            <div id="messagesuccess"></div>
                            </p>
                            <button type="button" class="btn btn-sm  btn-success" data-dismiss="modal">Ok</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="success_modal_new">
            <div class="modal fade show" id="statusErrorsModal" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false">
                <div class="modal-dialog modal-dialog-centered modal-sm" role="document">
                    <div class="modal-content">
                        <div class="modal-body text-center p-lg-4">
                            <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
                                <circle class="path circle" fill="none" stroke="#db3646" stroke-width="6" stroke-miterlimit="10" cx="65.1" cy="65.1" r="62.1" />
                                <line class="path line" fill="none" stroke="#db3646" stroke-width="6" stroke-linecap="round" stroke-miterlimit="10" x1="34.4" y1="37.9" x2="95.8" y2="92.3" />
                                <line class="path line" fill="none" stroke="#db3646" stroke-width="6" stroke-linecap="round" stroke-miterlimit="10" x1="95.8" y1="38" X2="34.4" y2="92.2" />
                            </svg>
                            <h4 class="text-danger mt-3">Oh No!</h4>
                            <p class="mt-3">
                            <div id="messagefailed"></div>
                            </p>
                            <button type="button" class="btn btn-sm mt-3 btn-danger" data-dismiss="modal">Ok</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script src="../assets/scripts/jquery.min.js"></script>
		<script src="../assets/scripts/moment.min.js"></script>
		<script src="../assets/scripts/daterangepicker.min.js"></script>
		<script src="../assets/scripts/custome.js"></script>
		<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="../assets/scripts/main.js"></script>
		<script src="https://use.fontawesome.com/f9637666d8.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>


		<script>
			$(document).ready(function() {
				// Check if the URL has a parameter indicating invalid login
				const urlParams = new URLSearchParams(window.location.search);
				const message = urlParams.get('message');

				if (message == 'Blocked successfully!') {
					$('#statusSuccessModal').modal('show');
					$('#messagesuccess').text(message);
				}
				else if (message == 'Something went wrong, please try again.') {
					$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				else if (message == 'Imported Successfullly') {
						$('#statusSuccessModal').modal('show');
					$('#messagesuccess').text(message);
				}
 else if (message == 'Reference exist cannot block') {
						$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				
			
				else if (message == 'Added successfully!') {
							$('#statusSuccessModal').modal('show');
					$('#messagesuccess').text(message);
				}
				
				else if (message == 'Wrong Amount Entered!') {
						$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				
				else if (message == 'Select Challenge/Transaction Type') {
						$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				
				else if (message == 'Select Transaction Type') {
						$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				
				else if (message == 'Select Challenge') {
						$('#statusErrorsModal').modal('show');
					$('#messagefailed').text(message);
				}
				
				else if (message == 'Edited successfully!') {
						$('#statusSuccessModal').modal('show');
					$('#messagesuccess').text(message);
				}
				
				// Event listener for modal close event
				$('#statusSuccessModal').on('hidden.bs.modal', function() {
					// Remove the message parameter from the URL
					window.history.replaceState({}, document.title, window.location.pathname);
				});
				$('#statusErrorsModal').on('hidden.bs.modal', function() {
					// Remove the message parameter from the URL
					window.history.replaceState({}, document.title, window.location.pathname);
				});
			});
		</script>
    </div>

	<script>
	
	window.onload = function() {
  setFries();
};

function setFries(){
    
    
     var opt2= document.getElementById("searchname");
   
    var opt3 = document.getElementById("unpaid");
     var opt4 = document.getElementById("searchTransactionType_drop");
      var opt5 = document.getElementById("searchclub_drop");
       var opt6 = document.getElementById("searchward_drop");
        var opt7 = document.getElementById("searchpaymode_drop");
        var opt8 = document.getElementById("searchchallenge_drop");
     var opt9 = document.getElementById("searchpan_drop");
      var opt10 = document.getElementById("searchase_drop");
       var opt11 = document.getElementById("searchdis_drop");
  


      
// Get the checkbox element by its ID
const checkbox = document.getElementById('volunteersettlement');

// Check if the checkbox is checked
if (checkbox.checked) {
    opt3.disabled = true;
    opt3.checked = false;
      opt2.disabled = true;
      opt4.disabled = true;
      opt5.disabled = true;
      opt6.disabled = true;
      opt7.disabled = true;
      opt8.disabled = true;
       opt9.disabled = true;
       opt10.disabled = true;
       opt11.disabled = true;
      
} else {
    opt3.disabled = false;
      opt2.disabled = false;
      opt4.disabled = false;
      opt5.disabled = false;
      opt6.disabled = false;
      opt7.disabled = false;
      opt8.disabled = false;
       opt9.disabled = false;
       opt10.disabled = false;
       opt11.disabled = false;
      
}


  
    
     if(x=="true"){
         
         alert();
     
      
    
     }
     
    
}
	</script>
	
<script>
$(document).ready(function() {
    $('#volunteersettlement').change(function() {
        if ($(this).is(':checked')) {
            // Reset dropdowns to '0' or 'Select' for all select2 elements
            $('#searchchallenge_drop').val('0').trigger('change');
            $('#searchTransactionType_drop').val('0').trigger('change');
            $('#searchpaymode_drop').val('0').trigger('change');
            $('#searchuser_drop').val('0').trigger('change');
            $('#searchdis_drop').val('0').trigger('change');
            $('#searchase_drop').val('0').trigger('change');
            $('#searchpan_drop').val('0').trigger('change');
            $('#searchward_drop').val('0').trigger('change');
            $('#searchclub_drop').val('0').trigger('change');
        }
    });
});



$(document).ready(function() {
    // When the district dropdown changes
    $('#searchdis_drop').change(function() {
        var district_id = $(this).val();  // Get the selected district ID

        if (district_id != '0') {  // Check if a valid district is selected
            // Make an AJAX request to get the assemblies for the selected district
            var url = "<?php echo siteurl ?>ChallengeReport/get_assemblies.php";  // Ensure the PHP siteurl works

            var data = { district_id: district_id };

            $.ajax({
                type: 'GET',
                url: url,
                data: data,
                beforeSend: function (xhr) {
                    if (xhr && xhr.overrideMimeType) {
                        xhr.overrideMimeType('application/json;charset=utf-8');
                    }
                    // Optional: Show a loading state
                    $('#searchase_drop').html('<option>Loading...</option>');
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);  // Debug the response

                    // Check if the data is an array
                    if (Array.isArray(data)) {
                        // Clear the current assembly options
                        $('#searchase_drop').empty();

                        // Add a default 'Select' option
                        $('#searchase_drop').append('<option value="0">Select</option>');

                        // Loop through the response and add options to the "Assembly" dropdown
                        $.each(data, function(index, assembly) {
                            $('#searchase_drop').append('<option value="' + assembly.id + '">' + assembly.name + '</option>');
                        });

                        // Trigger select2 to refresh the dropdown (if you're using select2)
                        $('#searchase_drop').trigger('change');
                    } else {
                        alert('Unexpected response format.');
                    }
                },
                error: function() {
                    alert('No Data Found');
                }
            });
        } else {
            // If no district is selected, clear the assembly dropdown and reset it
            $('#searchase_drop').empty().append('<option value="0">Select</option>');
            $('#searchase_drop').trigger('change');
        }
    });
});


$(document).ready(function() {
    // When the district dropdown changes
    $('#searchase_drop').change(function() {
        var district_id = $(this).val();  // Get the selected district ID

        if (district_id != '0') {  // Check if a valid district is selected
            // Make an AJAX request to get the assemblies for the selected district
            var url = "<?php echo siteurl ?>ChallengeReport/get_panchayat.php";  // Ensure the PHP siteurl works

            var data = { district_id: district_id };

            $.ajax({
                type: 'GET',
                url: url,
                data: data,
                beforeSend: function (xhr) {
                    if (xhr && xhr.overrideMimeType) {
                        xhr.overrideMimeType('application/json;charset=utf-8');
                    }
                    // Optional: Show a loading state
                    $('#searchpan_drop').html('<option>Loading...</option>');
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);  // Debug the response

                    // Check if the data is an array
                    if (Array.isArray(data)) {
                        // Clear the current assembly options
                        $('#searchpan_drop').empty();

                        // Add a default 'Select' option
                        $('#searchpan_drop').append('<option value="0">Select</option>');

                        // Loop through the response and add options to the "Assembly" dropdown
                        $.each(data, function(index, assembly) {
                            $('#searchpan_drop').append('<option value="' + assembly.id + '">' + assembly.name + '</option>');
                        });

                        // Trigger select2 to refresh the dropdown (if you're using select2)
                        $('#searchpan_drop').trigger('change');
                    } else {
                        alert('Unexpected response format.');
                    }
                },
                error: function() {
                    alert('No Data Found');
                }
            });
        } else {
            // If no district is selected, clear the assembly dropdown and reset it
            $('#searchpan_drop').empty().append('<option value="0">Select</option>');
            $('#searchpan_drop').trigger('change');
        }
    });
});


$(document).ready(function() {
    // When the district dropdown changes
    $('#searchpan_drop').change(function() {
        var district_id = $(this).val();  // Get the selected district ID

        if (district_id != '0') {  // Check if a valid district is selected
            // Make an AJAX request to get the assemblies for the selected district
            var url = "<?php echo siteurl ?>ChallengeReport/get_ward.php";  // Ensure the PHP siteurl works

            var data = { district_id: district_id };

            $.ajax({
                type: 'GET',
                url: url,
                data: data,
                beforeSend: function (xhr) {
                    if (xhr && xhr.overrideMimeType) {
                        xhr.overrideMimeType('application/json;charset=utf-8');
                    }
                    // Optional: Show a loading state
                    $('#searchward_drop').html('<option>Loading...</option>');
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);  // Debug the response

                    // Check if the data is an array
                    if (Array.isArray(data)) {
                        // Clear the current assembly options
                        $('#searchward_drop').empty();

                        // Add a default 'Select' option
                        $('#searchward_drop').append('<option value="0">Select</option>');

                        // Loop through the response and add options to the "Assembly" dropdown
                        $.each(data, function(index, assembly) {
                            $('#searchward_drop').append('<option value="' + assembly.id + '">' + assembly.name + '</option>');
                        });

                        // Trigger select2 to refresh the dropdown (if you're using select2)
                        $('#searchward_drop').trigger('change');
                    } else {
                        alert('Unexpected response format.');
                    }
                },
                error: function() {
                    alert('No Data Found');
                }
            });
        } else {
            // If no district is selected, clear the assembly dropdown and reset it
            $('#searchward_drop').empty().append('<option value="0">Select</option>');
            $('#searchward_drop').trigger('change');
        }
    });
});


</script>
</body>
<style>
       .table th,
        .table td { 
            font-size: 10px;
            padding: 0.25rem;

      }
      /* Ensure select2 dropdowns take up full width of their parent container */
.select2-container {
    width: 100% !important;
}

/* Optional: Set a minimum width to prevent small dropdowns */
.select2-container--default .select2-selection--single {
    min-width: 200px; /* Adjust to fit your needs */
}

/* Ensure the dropdown list doesn't shrink */
.select2-dropdown {
    min-width: 200px !important; /* Adjust to fit your needs */
}

</style>
</html>