<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/ui/minified/jquery.ui.mouse.min.js"></script>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/ui/minified/jquery.ui.draggable.min.js"></script>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/ui/minified/jquery.ui.resizable.min.js"></script>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/ui/minified/jquery.ui.dialog.min.js"></script>
<script type="text/javascript" src="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide-with-html.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/highslide.css" />
<link type="text/css" href="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/themes/base/jquery.ui.dialog.css" rel="stylesheet" />
<link type="text/css" href="<?php echo GLOBAL_ADMIN_JS_PATH; ?>jquery/themes/base/jquery.ui.resizable.css" rel="stylesheet" />
<script type="text/javascript">
    hs.graphicsDir = '<?php echo GLOBAL_ADMIN_JS_PATH; ?>highslide/graphics/';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
</script>
<script type="text/javascript">
    function verify()
    {
        SendGridBindRequest('<?= $inquiryObj->urlwithpara ?>','gridbody','D','chkgrow');
    }
    function popreply1(id)
    {
        var response;
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=contactusmsg&view=newslatter&action=email&ajax=Y&id="+id,
            async: false,
            success: function(data){
                response=data;
            }
        });
        $('#dialog-modal').html(response);
        $('#dialog-modal').dialog({
            autoOpen: false,
            height: 295,
            width: 615,
            modal: true
        });
        $('#dialog-modal').dialog('open');
    }
    function excelreport()
    {
        var chkelements = document.getElementsByName('chkgrow');
        var ids = "";
        var countChecked = 0;
        for(var i = 0; i < chkelements.length; i++)
        {
            if(chkelements.item(i).checked == true)
            {
                countChecked++;
                if(ids != "")
                    ids += ",";
                ids += chkelements.item(i).value;
            }
        }
        var totalpagerecords = document.getElementById('ptrecords').value;
        document.getElementById('totalrecords').value = totalpagerecords;
        document.getElementById('chkids').value = ids;
        document.forms["exportform"].submit();
    }
function updateread(id)
    {
        var p='';
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=contactusmsg&view=newslatter&action=updatereaddata&ajax=Y&id="+id,
            async: false,
            success: function(data){
                p=data;
                document.getElementById('gtr-'+p).className = 'grid-list-inner-table-text';
                    document.getElementById('star1-'+p).style.display='none';
            }
        });
    }
</script>
<div id="dialog-modal" title="Reply Form"></div>
<div class="web-booking-main" id="gridbody">
    <div class="breadcrumbs"><a href="index.php">Home </a>&nbsp;>&nbsp; <span class="current">Manage Newsletter Leads</span></div>
    <div class="clear"></div>
    <?= $messagebox; ?><?= $sendmailstatus; ?>
    <?php echo $headerpanel; ?>
    <?php echo $pagingTop; ?>

    <div class="grid-list-subtitle-bg" style="margin-top:10px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <?php if ($paramMain['Delete'] == 'Y') { ?>
                    <td width="2%" align="left" valign="top" class="grid-td-left"><input name="chkall" id="chkall" type="checkbox" onclick="checkall('chkgrow')"  /></td>                      
                <?php } else { ?>
                    <td width="3%" align="left" valign="top" class="grid-td-left">&nbsp;</td>
                <?php } ?>
                <td width="15%" align="left" valign="middle" class="grid-td-top"><a href="javascript:;" onclick="SendGridBindRequest('<?= $inquiryObj->urlwithoutsort ?>&orderby=var_email&sorting=Y','gridbody','ST')">Email<?= $setsortimgvar_email ?></a></td>
                <td width="10%" align="center" valign="middle" class="grid-td-top">Admin Message</td>
                <td width="10%" align="center" valign="top" class="grid-td-top">Reply</td>
                <td width="10%" align="center" valign="top" class="grid-td-top">Reply Sent</td>
                <td width="15%" align="center" valign="top" class="grid-td-top" ><a href="javascript:;" onclick="SendGridBindRequest('<?= $inquiryObj->urlwithoutsort ?>&orderby=dt_createdate&sorting=Y','gridbody','ST')">Date<?= $setsortimgdt_createdate ?></a></td>
            </tr>
        </table>
    </div>
    <div class="information-white-bg" id="dvpersonalinformation" >
        <div class="clear"></div>
        <div class="grid-list-inner-table-text">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <?php
                if ($numofrows > 0) {
                    $rowcount = 0;
                    while ($row = $configObj->glDbObj->fetch_array($result)) {
                        $clsname = ($row['chr_read'] == 'N') ? "grid-list-inner-table-text-active" : "grid-list-inner-table-text"; // For read unread class

                        $starimg = ($row['chr_star'] == 'Y') ? "gstar.png" : "gstar-disable.png"; // Displaying the stat and unstart image
                        $tickimg = ($row['chr_publish'] == 'Y') ? "tick.png" : "tick_cross.png"; // Displaying the stat and unstart image
                        $sql_con_rep = "SELECT fk_contactdetail,GROUP_CONCAT(var_adminreply,'<br/>$$$$$') as add_rep,GROUP_CONCAT(DATE_FORMAT(dtcreateddate, '" . DEFAULT_DATEFORMAT . "'),'$$$$$') as add_rep_date,GROUP_CONCAT(time(dtcreateddate),'<br/>$$$$$') as add_rep_time FROM " . DB_PREFIX . "newsletter_reply where fk_contactdetail='" . $row['int_glcode'] . "' group by fk_contactdetail order by dtcreateddate desc";
                        $row_add_rep = $configObj->glDbObj->get_sql_row($sql_con_rep);
                        $arr_admin = explode('<br/>$$$$$,', $row_add_rep['add_rep']);
                        $arr_admin_date = explode('$$$$$,', $row_add_rep['add_rep_date']);
                        $arr_admin_time = explode('<br/>$$$$$,', $row_add_rep['add_rep_time']);

                        if ($row['chr_read'] == 'N') {
                            $style = 'display:inline;';
                        } else {
                            $style = 'display:none;';
                        }

                        $star = "<span id='star1-" . $row['int_glcode'] . "' style='" . $style . "'><img width='10px' id='imgStar-" . $row['int_glcode'] . "' style='padding-bottom:5px;' height='10px' title='New News letter leads Added'  src='html/images/star_red.png'></span>";
                        ?>
                        <tr id="gtr-<?= $row['int_glcode'] ?>"  style="background-color: transparent;"  class="<?= $clsname ?>" onmouseover="this.style.backgroundColor='#f6f6f6'" onmouseout="this.style.backgroundColor='transparent'" >
                        <?php if ($paramMain['Delete'] == 'Y') { ?>
                                <td width="2%" align="left" valign="middle" class="grid-td-left"><input name="chkgrow" id="chkgrow" type="checkbox" value="<?php echo $row['int_glcode'] ?>" /></td>
                        <?php } else { ?>
                                <td width="2%" align="left" valign="middle" class="grid-td-left">&nbsp;</td>
                        <?php } ?>
                            <td width="15%" align="left" valign="middle" class="grid-td-top"><?php echo $row['var_email']; ?>&nbsp;<?php echo $star ?></td>
                            <td width="10%" align="center" valign="middle" class="grid-td-top">
        <?php if ($row['chr_replysent'] == 'Y') {  ?>
                             <a href="javascript:;" onclick="return hs.htmlExpand(this,{ headingText:'Reply From Admin To User'})"><span onclick="updateread('<?= $row['int_glcode'] ?>');">View</span> <!--<img alt="reply" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/message-icon.png" />--> 
                                </a> 
                                <?php } ?>
                                <div class="highslide-maincontent">
                                <?php
                                for ($i = count($arr_admin) - 1; $i >= 0; $i--) {

                                    if ($i != (count($arr_admin) - 1)) {
                                        echo "<strong>" . $arr_admin_date[$i] . ' ' . $arr_admin_time[$i] . "</strong><br/><br/>";
                                        echo $arr_admin[$i] . "<br/><hr>";
                                    } else {
                                        echo "<strong>" . substr($arr_admin_date[$i], 0, count($arr_admin_date[$i]) - 6) . ' ' . substr($arr_admin_time[$i], 0, count($arr_admin_time[$i]) - 6) . "</strong><br/><br/>";
                                        echo substr($arr_admin[$i], 0, count($arr_admin[$i]) - 6) . "<br/><hr>";
                                    }
                                }
                                ?>
                                </div>
                            </td>

                            <td width="10%" align="center" valign="middle" class="grid-td-top" ><a style="cursor:pointer;" onclick="popreply1('<?php echo $row['int_glcode'] ?>')">
                                    <img alt="reply" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/message-reply.png" />
                                </a></td>

                            <td width="10%" align="center" valign="middle" class="grid-td-top" >
                                    <? if ($row['chr_replysent'] == "Y") { ?>
                                    <img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>tick-icon.jpg" id="reply<?= $row['int_glcode'] ?>" />
        <?php } else { ?>
                                    <img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>cross.png" id="reply<?= $row['int_glcode'] ?>" />
        <?php } ?>
                            </td>
                            <td width="15%" align="center" valign="top" class="grid-td-top" >
        <?=$row['Date'] . ' ' . $row['Time']; ?>
                            </td>
                        </tr>
                <?php
                                $rowcount++;
                            }
                        } else { ?>
                    <tr style="background-color: transparent;"  class="<?= $clsname ?>" onmouseover="this.style.backgroundColor='#f6f6f6'" onmouseout="this.style.backgroundColor='transparent'">
                        <td height="25" align="center" valign="middle" colspan="6" class="form_titles">
                            No new leads, Please <a target="_blank" href="http://www.netclues.ky/seo-search-engine-optimization-cayman-islands.php"> <strong>Click Here</strong> </a> to find out how to get more leads.</td>
                    </tr>
                    <?php } ?>
                <input type="hidden" name="ptrecords" id="ptrecords" value="<?= $rowcount ?>">
            </table>
        </div>
    </div>
    <div class="clear"></div>

<?php echo $pagingBottom; ?>
<?php if ($numofrows > 0) { ?>
<?php if ($paramMain['Delete'] == 'Y') { ?>
    <div style="width:90px; float: left;" class="add-new-user-button"><a href="javascript:" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image47','','<?= GLOBAL_ADMIN_IMAGES_PATH ?>delete-button-hover.jpg',0)"><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>delete-button.jpg" alt="Delete" name="Image47" width="80" height="25" border="0" id="Image47" onclick="return verify();" /></a>
    </div>
<?php } ?>
<?php } ?>
    <form name="exportform" id="exportform" action="index.php?module=contactusmsg&view=newslatter&action=export"  method="post">
        <input type="hidden" name="totalrecords" id="totalrecords" value="">
        <input type="hidden" name="chkids" id="chkids" value="">
<?php if ($numofrows > 0) { ?>
            <div class="add-new-user-button"><a href="javascript:" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image48','','<?= GLOBAL_ADMIN_IMAGES_PATH ?>export-button-hover.gif',0)"><img src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>export-button.gif" alt="Delete" name="Image48" width="81" height="25" border="0" id="Image48" onclick="return excelreport();" /></a></div>
    <?php } ?>
    </form>
</div>