<?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["artistid"]) and $_GET["artistid"] != "") {
    $artistid = $_GET["artistid"];
} else if (isset($_POST["artistid"]) and $_POST["artistid"] != "") {
    $artistid = $_POST["artistid"];
}



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['gotoPage'])) {

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



if ($txtSearch != "") {

    $qryopt = " Where ";

    if ($cmbSearchType == "username") {
        $qryopt .= "u.user_name like '" . addslashes($txtSearch) . "%' AND";
    } else if ($cmbSearchType == "dateadded") {
        $dt = $txtSearch;
        $arrdt = explode("/", $dt);
        $day = $arrdt[1];
        $month = $arrdt[0];
        $year = $arrdt[2];
        $dt = $year . "-" . $month . "-" . $day;
        $qryopt .= "f.date_added like '" . addslashes($dt) . "%' AND ";
    } else if ($cmbSearchType == "email") {
        $qryopt .= " u.email like '" . addslashes($txtSearch) . "%' AND ";
    } else if ($cmbSearchType == "feedback") {
        $qryopt .= "f.feedback_content like '" . addslashes($txtSearch) . "%'  AND  ";
    }
}
$qryopt = rtrim($qryopt, " AND");

$sql = " SELECT f.*, u.user_name, a.artist_name ,u.email FROM " . $tableprefix . "artist_feedbacks f
		INNER JOIN " . $tableprefix . "users u ON f.user_id = u.user_id 
		INNER JOIN " . $tableprefix . "artists a ON f.artist_id = a.artist_id 
 		 " . $qryopt . "  order by date_added 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";
?>
<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=='dateadded'){
             $("#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 SELLER_FEEDBACK;?> </div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>

                <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" name="frmFeedbacks">
                     <?php
                                $dateblock = "none";
                                if($cmbSearchType!= "dateadded"){
                                           $txtBlock = "display";
                                           $dateblock = "none";
                                           $txtSearch1 = $txtSearch; 
                                           $disabled1   = "";
                                           $disabled2   = "disabled=disabled";
                                 } else{
                                           $txtBlock = "none";
                                           $dateblock = "display";
                                           $txtSearch2 = $txtSearch;
                                           $disabled1   = "disabled=disabled";
                                           $disabled2   = "";
                                }
                                                           
                         ?>

                    <div align="left">		


                        <input type="hidden" value="<?php echo $artistid; ?>" name="artistid">

                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                            <tr>
                                <td width="55%" align="left" valign="middle" class="">
                                    <select name="cmbSearchType" id="cmbSearchType" class="textarea">
                                        <option value="username"  <?php if ($cmbSearchType == "username" || $cmbSearchType == "") {
                echo("selected");
            } ?>><?php echo USER_NAME;?></option>
                                        <option value="email"  <?php if ($cmbSearchType == "email") {
                echo("selected");
            } ?>><?php echo EMAIL;?></option>
                                        <option value="feedback"  <?php if ($cmbSearchType == "feedback") {
                echo("selected");
            } ?>><?php echo FEEDBACK;?></option>
                                        <option value="dateadded"  <?php if ($cmbSearchType == "dateadded") {
                echo("selected");
            } ?>><?php echo DATE_ADDED;?> <!--(<?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" value="<?php echo(htmlentities(stripslashes($txtSearch1))); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }"  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>
                                    <a onClick="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a></td>

                                </td>

                            </tr>
                        </table>
                    </div>

                </form>	

                <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" name="frmSeller1">
                    

                    <div align="left">

                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                            <tr class="form_header">
                                <th width="4%" align="center" valign="middle">#</th>
                                <th width="17%" align="left" valign="middle"><?php echo FEEDBACK_CONTENT;?></th>
                                <th width="13%" align="left" valign="middle"><?php echo USER_NAME;?></th>
                                <th width="21%" align="left" valign="middle"><?php echo EMAIL;?></th>
                                <th width="11%" align="left" valign="middle"><?php echo SELLER_NAME;?> </th>
                                <th width="18%" align="center" valign="middle"><?php echo DATE_ADDED;?> (<?php echo MM."/".DD."/".YYYY;?>)</th>
                                <th width="16%" align="center" valign="middle" colspan="2"><?php echo PUBLISHED;?></th>
                            </tr>	

                            <?php
                            $i = 1;

                            if (mysql_num_rows($result) > 0) {

                                while ($row = mysql_fetch_array($rs)) {
                                    if ($row["published"] == 'Y') {
                                        $pStatus = YES;
                                    } else {
                                        $pStatus = NO1;
                                    }
                                    $link = "<a class='links' href='viewartistfeedback.php?feedbackid=" . $row["artist_feedback_id"] . "&artistid=" . $row["artist_id"] . "'>";
                                    ?>	

                                    <tr>
                                        <td align="center" valign="middle"><?php echo (($page * $limit) + $i - $limit) ?></td>
                                        <td align="left" valign="middle" title="<?php echo (stripslashes($row["feedback_content"])); ?>"><?php echo $link . stripslashes(substr($row["feedback_content"], 0, 40)) . "...</a>"; ?></td>
                                        <td align="left" valign="middle"><?php echo $link . $row["user_name"] . "</a>"; ?></td>
                                        <td align="left" valign="middle"><?php echo $link . htmlentities($row["email"]) . "</a>"; ?></td>
                                        <td align="left" valign="middle"><?php echo $link . htmlentities($row["artist_name"]) . "</a>"; ?></td>
                                        <td align="center" valign="middle"><?php echo $link . dateFormat($row["date_added"], "Y-m-d", "m/d/Y") . "</a>"; ?></td>
                                        <td colspan="2" align="center" valign="middle"><?php echo $link . ($pStatus) . "</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
                            }

                            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" colspan="5" align="center">&nbsp;</td>
                                <td align="right" valign="middle" class="page_nos">&nbsp;</td>
                                <td align="left" class="btn_gotbl" valign="middle">&nbsp;</td>
                            </tr>
                            <?php
                            if ($page < $numofpages || $page > 1) {
                                ?><tr>
                                    <td colspan="7" align="center">
									
										<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 ?>
												<?php echo GO_TO;?>
											</td>
											<td width="8%" align="right">
											<select class="textarea2" name="gotoPage">
												<?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.frmSeller1.submit();" class="go_button_2"><?php echo GO; ?></a>
											</td>
											<td width="41%" align="center"><?php echo $next ?></td>
											</tr>
										</table>
										
										</td>
                                    </tr><?php
                            }
                            ?>
                            <tr>
                                <td colspan="7" align="center"><input type="button" class="button" name="back" value="<?php echo BACK;?>" onClick="Javascript:history.go(-1)"></td>
                            </tr>

                        </table>



                    </div>

                </form>	

                <!--content area end-->

            </div>

            </form>

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