<?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 (isset($_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"] != "") {
    $artistid = $_SESSION["sess_artistid"];
} 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($_POST['message_to_seller_ids'])) {


    $message_to_seller_ids = $_POST['message_to_seller_ids'];

    $message_to_seller_ids = implode(',', $message_to_seller_ids);

    $deleteQ = "DELETE FROM " . $tableprefix . "message_to_seller WHERE message_to_seller_id IN(" . $message_to_seller_ids . ")";

    mysql_query($deleteQ) or die(mysql_error());
    header("Location:messages.php?msg=".MSG_MSG_DEL_SUC);
    exit;
}
if (isset($_GET['msg'])) {
    $message = $_GET['msg'];
}

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

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



$qryopt = "";
$txtSearch = trim($txtSearch);
if ($txtSearch != "") {
    if ($cmbSearchType == "name") {
        $qryopt .= "  AND  name like '%" . addslashes($txtSearch) . "%'";
    } else if ($cmbSearchType == "dateadded") {
        $dt = $txtSearch;
        $arrdt = explode("/", $dt);
        $day = $arrdt[1];
        $month = $arrdt[0];
        $year = $arrdt[2];
        $dt = $year . $month . $day;
        $qryopt .= "  AND  date_format(created_on,'%Y%m%d') = '" . $dt . "' ";
    } else if ($cmbSearchType == "subject") {
        $qryopt .= "  AND  subject like '%" . addslashes($txtSearch) . "%'";
    } else if ($cmbSearchType == "message") {
        $qryopt .= "  AND  message like '%" . addslashes($txtSearch) . "%'";
    }
}

$sql = "SELECT *
		FROM " . $tableprefix . "message_to_seller
                WHERE artist_id = " . $_SESSION["sess_artistid"] . $qryopt . " 
                ORDER BY message_to_seller_id DESC";


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";
?>

<script>
    function clickSearch()
    {
        document.frmMyProducts.submit();
    }

    function checkAllOrders()
    {
        $(".jqMessageToSeller").attr("checked", $("#checkAllBox").is(":checked"));
    }

    function deleteMessages()
    {
        if($(".jqMessageToSeller:checked").length > 0)
        {
            if(confirm('<?php echo MSG_DEL_SEL_MSG;?>'))
            {
                return true;
            }
        }
        else
        {
            alert('<?php echo MSG_SEL_MSG_DEL;?>');
        }
        return false;
    }


</script>

<body>

<center>

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




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

        <!--header area end -->




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



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


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

                <!--content area start -->

                <div align="left" class="page_title"><?php echo TEXT_MY_MSG;?></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="frmMyProducts">

                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                            <tr>
                                <td width="90%" align="left" valign="middle"><?php echo TEXT_SEARCH;?>
                                    <select name="cmbSearchType" class="textarea">
                                        <option value="name"  <?php if ($cmbSearchType == "name" || $cmbSearchType == "") {
                echo("selected");
            } ?>><?php echo TEXT_NAME;?></option>
                                        <option value="email"  <?php if ($cmbSearchType == "email") {
                echo("selected");
            } ?>><?php echo TEXT_EMAIL;?></option>
                                        <option value="subject"  <?php if ($cmbSearchType == "subject") {
                echo("selected");
            } ?>><?php echo TEXT_SUBJECT;?></option>
                                        <option value="message"  <?php if ($cmbSearchType == "message") {
                echo("selected");
            } ?>><?php echo TEXT_MSG;?></option>
                                        <option value="dateadded"  <?php if ($cmbSearchType == "dateadded") {
                echo("selected");
            } ?>><?php echo TEXT_DATE_ADDED;?><?php echo TEXT_MM_DD_YY;?></option>
                                    </select> &nbsp;
                                    <input type="text" name="txtSearch"  class="textarea" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>">
                                    &nbsp;<a href="javascript:clickSearch();" class="go_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
                                </td>


                            </tr>
                        </table>


                    </form>

                </div>

                <div align="left">					


                    <table border="0" width="100%" cellpadding="0" cellspacing="0" class="manage_table">
                        <form action="" method="post" name="frmMyProducts1">
                            <tr  class="form_header">
                                <th width="4%" align="left">#</th>
                                <th width="17%" align="left"><?php echo TEXT_FROM;?></th>
                                <th width="11%" align="left"><?php echo TEXT_EMAIL;?></th>
                                <th width="11%" align="left"><?php echo TEXT_SUBJECT;?></th>
                                <th align="left"><?php echo TEXT_MSG;?></th>
                                <th width="13%" align="left"><?php echo TEXT_DATE_ADDED;?></th>
                                <th width="10%"><input type="checkbox" id="checkAllBox" value="1" onClick="checkAllOrders();"><?php echo TEXT_SELECT_ALL;?>&nbsp;/</th>
                                <th width="12%"><input type="image" src="../images/btn_del.gif" onClick="return deleteMessages();"/></th>
                            </tr>


<?php
if (mysql_num_rows($result) > 0) {
    $i = 1;
    while ($row = mysql_fetch_array($rs)) {
        $link = "<a class=links href='readmessage.php?message_to_seller_id=" . $row["message_to_seller_id"] . "&page=" . $_GET['page'] . "'>";
        ?>
                                    <tr <?php echo $row["read"] == 'N' ? 'style="font-weight: bold"' : ''; ?>> 
                                        <td><?php echo (($page * $limit) + $i - $limit) ?></td>
                                        <td align="left"><?php echo $link . stripslashes($row["name"]) . "</a>"; ?></td>
                                        <td align="left"><?php echo $link . stripslashes($row["email"]) . "</a>"; ?></td>
                                        <td align="left"><?php echo $link . stripslashes($row["subject"]) . "</a>"; ?></td>
                                        <td align="left"><?php echo $link . stripslashes(substr($row["message"], 0, 20)) . "</a>"; ?></td>

                                        <td align=""><?php echo $link . dateFormat($row["created_on"], "Y-m-d", "m/d/Y") . "</a>"; ?></td>
                                        <td align="">
                                            <input type="checkbox" class="jqMessageToSeller" name="message_to_seller_ids[]" value="<?php echo $row["message_to_seller_id"]; ?>">
                                        </td>

                                    </tr>
        <?php
        $i++;
    }
    ?>	

                                <input type="hidden" name="checkCount" value="<?php echo $i - 1 ?>">
    <?php
} else {
    ?>					
                                <tr>
                                    <td align="center" valign="middle" colspan="8"  class="text_information"><?php echo TEXT_NO_MSG;?></td>
                                </tr>					
                                <?php
                            }

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

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


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

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

                            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">
													Page(s) <?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;Goto
												</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.frmMyProducts1.submit();" class="go_button_2">Go</a>
												</td>
												<td width="41%" align="center"><?php echo $next ?></td>
											</tr>
										</table>
									</td>
                                </tr>
                                            <?php
                                        }
                                        ?>
                        </form>
                        <tr>
                            <td colspan="8">

                            </td>
                        </tr>
                    </table>

                </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";
?>