<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if (isset($_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"] != "") {
    $adminname = $_SESSION["sess_adminname"];
} else {
    header("Location:login.php");
    exit;
}


if (isset($_GET["txtSearch"]) and $_GET["txtSearch"] != "") {
    $txtSearch = $_GET["txtSearch"];
    $cmbSearchType = $_GET["cmbSearchType"];
} else if (isset($_POST["txtSearch"]) and $_POST["txtSearch"] != "") {
    $txtSearch = $_POST["txtSearch"];
    $cmbSearchType = $_POST["cmbSearchType"];
}


if (isset($_GET["msg"]) and $_GET["msg"] != "") {
    $msg = $_GET["msg"];
    switch ($msg) {
        case "deleted": $message = FEEDBACK_DEL_SUCC."!";
            break;
        default:
            ;
    } // switch
}

if (isset($_POST['gotoPage'])) {

    header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage']);
}

$qryopt = "";

$qryopt.="WHERE o.vpayment_status='C' ";
if ($txtSearch != "") {
    if ($cmbSearchType == "artistname") {
        $qryopt .= "  AND   s.artist_name like '" . addslashes($txtSearch) . "%'";
    } else if ($cmbSearchType == "datepaid") {
        $dt = $txtSearch;
        $arrdt = explode("/", $dt);
        $day = $arrdt[1];
        $month = $arrdt[0];
        $year = $arrdt[2];
        $dt = $year . "-" . $month . "-" . $day;
        $qryopt .= "  AND  sp.payment_date like '" . addslashes($dt) . "%'";
    } else if ($cmbSearchType == "orderid") {
        $qryopt .= "  AND  sp.order_id like '" . addslashes($txtSearch) . "%'";
    }
}

$sql = " SELECT sp.*,s.artist_name FROM " . $tableprefix . "artist_payments sp
                INNER JOIN  " . $tableprefix . "artists s
            ON sp.artist_id = s.artist_id
            INNER JOIN  " . $tableprefix . "orders o ON o.order_id = sp.order_id
" . $qryopt . "   order by sp.artist_payment_id DESC   ";
//echo $sql;
if (!(isset($pagenum))) {
    $pagenum = 1;
}

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page']) ? trim($_GET['page']) : 1;


if (empty($page)) {
    $page = 1;
}

$result = mysql_query($sql) or die(mysql_error());

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string = " LIMIT $limitvalue, $limit";

$sql = $sql . $query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);

include "../includes/htmltop.php";
?>
<link rel="stylesheet" href="<?php echo SITE_URL; ?>/style/jquery-ui.css">
<script src="<?php echo SITE_URL; ?>/js/jquery-ui.js"></script>
<script language="JavaScript" type="text/JavaScript">
     $(document).ready(function () {
        $("#datepicker").datepicker({
                dateFormat: 'mm/dd/yy',
                maxDate: '0'
       
         });
      
    $("#cmbSearchType").on("change",function(){
        if(this.value=='datepaid'){
             $("#textSelector").hide();
             $("#dateSelector").show();
             $("#txtSearch").attr("disabled","disabled");
             $("#datepicker").removeAttr("disabled");
            
        }else{
             $("#textSelector").show();
             $("#dateSelector").hide();
             $("#datepicker").attr("disabled","disabled");
             $("#txtSearch").removeAttr("disabled");
             
        }
        
        
    });
});
    function clickSearch()
    {
        document.frmFeedbacks.submit();
    }
    function changeStatus(id){
        var frm = document.frmFeedbacks;
        if(Confirm("<?php echo ARE_YOU_SURE;?>?")){
            document.frmFeedbacks.submit();
        }
    }
</script>


<body>

<center>

    <div align="left" id="layout">




        <!--header area start -->
<?php
include_once("../includes/topheader_admin.php")
?>

        <!--header area end -->




        <div align="left" class="main_body">
            <!--main body start -->



<?php
include_once("../includes/admintopmenu.php")
?>		


            <div align="left" class="content_area">

                <!--content area start -->

                <div align="left" class="page_title"><?php echo PAYMENTS;?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>

                <div align="left">			

                    <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" name="frmFeedbacks">
                        <?php
                                $dateblock = "none";
                                if($cmbSearchType!= "datepaid"){
                                           $txtBlock = "display";
                                           $dateblock = "none";
                                           $txtSearch1 = $txtSearch; 
                                           $disabled1   = "";
                                           $disabled2   = "disabled=disabled";
                                 } else{
                                           $txtBlock = "none";
                                           $dateblock = "display";
                                           $txtSearch2 = $txtSearch;
                                           $disabled1   = "disabled=disabled";
                                           $disabled2   = "";
                                }
                                                           
                             ?>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                            <tr>
                                <td width="100%" align=left valign="baseline" class=''><?php echo SEARCH;?>
                                    <select name="cmbSearchType"  id="cmbSearchType" class="textarea">
                                        <option value="artistname"  <?php if ($cmbSearchType == "artistname" || $cmbSearchType == "") {
    echo("selected");
} ?>><?php echo SELLER_NAME;?></option>
                                        <option value="orderid"  <?php if ($cmbSearchType == "orderid") {
    echo("selected");
} ?>><?php echo ORDER;?> #</option>
                                        <option value="datepaid"  <?php if ($cmbSearchType == "datepaid") {
    echo("selected");
} ?>><?php echo DATE_PAID;?> <!--(<?php echo MM."/".DD."/".YYYY;?>)--></option>

                                    </select> &nbsp;
                                     <span id="textSelector" style="display:<?php echo $txtBlock; ?>"  >
                                        <input type="text" <?php echo $disabled1; ?> name="txtSearch" id="txtSearch" size="20" maxlength="50" onKeyPress="if(window.event.keyCode == '13'){ return false; }" value="<?php echo(htmlentities($txtSearch1)); ?>"   class="textarea">
                                   </span>
                                    <span id="dateSelector" style="display:<?php echo $dateblock; ?>" >
                                        <input type="text" <?php echo $disabled2; ?> name="txtSearch" id="datepicker" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch2)); ?>"   class="textarea">
                                    </span>
                                    &nbsp;
                                    <a href="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
                                </td>
                            </tr>
                        </table>

                    </form>

                </div>

                <div align="left">
                    <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" name="frmFeedbacks1">

                        <table  width="100%" cellpadding="0" cellspacing="0" class="manage_table">
                             
                              <tr align="left"><td  colspan="8" class="specialmessage"><?php echo ADMIN_COMMISION_AMOUNT;?></td></tr> 
                              
                            <tr align="left"><td  colspan="8" class="specialmessage"><?php echo AMOUNT_PAYABLE_NOTE;?></td></tr>  
                            <tr align="left"><td  colspan="8" class="specialmessage">&nbsp;</td></tr>  
                            
                            <tr class="page_title2" align="left">
                                <th width="3%" align="center" height="30"><strong>#</strong></th>
                                <th width="15%" align="left"><?php echo SELLER_NAME;?></th>
                                <th width="8%"><?php echo ORDER;?> #</th>
                                <th width="14%" align="left"><?php echo SELLER_ORDER_TOTAL;?></th>
                                <th width="14%" align="left"><?php echo PRO_TOTAL;?></th>
                                <th width="18%" align="left"><?php echo COMMISSION_AMOUNT;?></th>
                                <th width="14%" align="left"><?php echo AMOUNT_PAYABLE;?></th>
                                <th width="20%" align="left"><?php echo PAYMENT_STATUS;?> </th>
                            </tr>
                            <?php
                            if (mysql_num_rows($result) > 0) {
                                $i = 1;

                                while ($row = mysql_fetch_array($rs)) {
                                    $link = "<a href='viewpayment.php?paymentid=" . $row["artist_payment_id"] . "' class='links'>";
                                    $txtPaymentDate = (isNotNull($row["payment_date"] and ($row["payment_date"] != "0000-00-00")) ? dateFormat($row["payment_date"], "Y-m-d", "m/d/Y") : "");

                                    $currencycode = getSellerCurrencySybol($row['artist_id']);
                                    $currencySymbol = getCurrencySybol($currencycode);


                                    if ($row['payment_status'] == 'P') {
                                        $Paymentstatus = NOT_YET_SETTLE;
                                    } else {
                                        $Paymentstatus = PAID;
                                    }
                                    ?>
                                    <tr align="left">
                                        <td><?php echo (($page * $limit) + $i - $limit) ?></td> 
                                        <td><?php echo $link . (substr($row["artist_name"], 0, 40)) . "</a>"; ?></td>
                                        <td><?php echo $link . htmlentities($row["order_id"]) . "</a>"; ?></td>
                                        <td><?php echo $adminCurrency['currency_symbol']; ?> &nbsp; <?php echo $link . htmlentities(number_format($row["seller_order_total_amount"], 2, '.', '')) . "</a>"; ?></td>
                                        <td><?php echo $adminCurrency['currency_symbol']; ?> &nbsp; <?php echo $link . htmlentities(number_format($row["total_amount"], 2, '.', '')) . "</a>"; ?></td>
                                        <td><?php echo $adminCurrency['currency_symbol']; ?> &nbsp; <?php echo $link . htmlentities(number_format($row["admin_commision_amount"], 2, '.', '')) . "</a>"; ?> &nbsp; (<?php echo $row["commission_percentage"] ?>%) </td>
                                        <td><?php echo $adminCurrency['currency_symbol']; ?> &nbsp; <?php echo $link . htmlentities(number_format($row["amount_paid"], 2, '.', '')) . "</a>"; ?></td>
                                        <td><?php echo $link . $Paymentstatus . "</a>"; ?></td>
                                    </tr>
        <?php
        $i++;
    }
} else {
    ?>					
                                <tr>
                                    <td align="center" valign="middle" colspan="8"  class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
                                </tr>					
                                <?php
                            }
                            ?>





                            <?php
                            if ($page > 1) {
                                $pageprev = $page - 1;

                                $previous_page = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PREV."</a>";
                            }


                            if ($page < $numofpages) {
                                $pagenext = ($page + 1);

                                $next = "<a href=" . $_SERVER['PHP_SELF'] . "?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";
                            }
                            ?>


                            <tr>
                                <td class="page_nos"  align="center" colspan="4">&nbsp;</td>
                                <td align="right" valign="middle" class="page_nos" colspan="2">&nbsp;</td>
                                <td align="left" valign="middle" class="btn_gotbl" colspan="2">&nbsp;</td>
                            </tr>							  <?php
                            if ($page < $numofpages || $page > 1) {
                                ?>
                                <tr>
                                    <td class="page_nos"  align="center" colspan="8">
									<table width="100%" border="0" cellspacing="10" cellpadding="0">
										<tr align="left" valign="middle">
											<td width="21%" align="right"><?php echo $previous_page ?></td>
											<td width="23%" align="right">
												<?php echo PAGE."(".S.")";?> <?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;
												<?php echo GO_TO;?>
											</td>
											<td width="8%" align="right">
												<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px; ">
													<?php
													for ($i = 1; $i <= $numofpages; $i++) {
													if ($i == $_GET['page']) {
													$page_selected = "selected";
													} else {
													$page_selected = "";
													}
													?>									
													<option value="<?php echo $i ?>" <?php echo $page_selected ?>><?php echo $i ?></option>
													<?php
													}
													?>									
												</select>
											</td>
											<td width="7%">
												<a onClick="Javascript:document.frmFeedbacks1.submit();" class="go_button_2"><?php echo GO; ?></a>
											</td>
											<td width="41%" align="center"><?php echo $next ?></td>
										</tr>
									</table>
								  </td>
                                </tr>
    <?php
}
?>
                        </table>
                    </form>



                </div>


                <!--content area end-->

            </div>


            <div align="left" class="clear_float"><img src="<?php echo $imagefolder; ?>/clear.gif" alt="" width="1" height="1" /></div>
            <!--main body end -->
        </div>


                                        <?php
                                        include "../includes/footer.php";
                                        ?>