<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.tooltip');
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');
JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');

$doc=JFactory::getDocument();
if (!class_exists('JHtmlMpusers')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_marketplace/helpers/html/mpusers.php';
}
$script = 'function showmore(element) {
    element.closest(".seller-mess").find(".hidden-more").show();
    element.hide();
}
function showless(element) {
    element.closest(".seller-mess").find(".show-less").show();
    element.closest(".hidden-more").hide();
}';
$doc->addScriptDeclaration($script);
$style='
.hidden-more {
    display: none;
}

.icon-messages {
    background-image: url("components/com_marketplace/assets/images/sprite-icon.png");
    background-repeat: no-repeat;
    background-position: -39px -208px !important;
    vertical-align: middle;
    width: 20px;
    height: 20px;
    margin-right: 0px!important;
}

#j-main-container table>thead>tr>th>a {
    text-decoration: none;
    color: #FFFFFF;
    vertical-align: top;
}

#articleList table tbody tr td {
    work-break: break-all;
}

.wk_show_link,
.wk_show_link:hover {
    display: block;
    text-decoration: none;
    font-style: italic;
    color: #F44321;
}
';
$doc->addStyleDeclaration($style);
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<div id="j-sidebar-container" class="span2">
    <?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
    <div id="j-main-container">
        <form action="<?php echo 'index.php?option=com_marketplace&view=messages'; ?>" method="post" name="adminForm" id="adminForm">
        <?php
        echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));
        ?>
            <table class="table table-striped table-bordered" id="articleList">
                <thead>
                    <tr bgcolor="#6994C4" style="color:#FFFFFF;vertical-align:top">
                        <th width="1%" class="">
                            <?php echo JHtml::_('grid.checkall'); ?>
                        </th>
                        <th width="13%">
                        <?php
                            echo JHtml::_(
                                'searchtools.sort',
                                'CUSTOMER_NAME',
                                'u.username',
                                $listDirn,
                                $listOrder
                            );
                        ?>
                        </th>
                        <th width="20%">
                        <?php
                            echo JHtml::_(
                                'searchtools.sort',
                                'SUBJECT_ASKADMIN',
                                'a.subject',
                                $listDirn,
                                $listOrder
                            );
                        ?>
                        </th>
                        <th width="30%">
                        <?php
                            echo JText::_('MESSAGE_ASKADMIN');
                        ?>
                        </th>
                        <th width="10%">
                        <?php
                            echo JHtml::_(
                                'searchtools.sort',
                                'TIMEDATE_ASKADMIN',
                                'a.time',
                                $listDirn,
                                $listOrder
                            );
                        ?>
                        </th>
                        <th width="5%">
                        <?php
                            echo JHtml::_(
                                'searchtools.sort',
                                'ID',
                                'a.id',
                                $listDirn,
                                $listOrder
                            );
                        ?>
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="10">
                        <?php
                            echo $this->pagination->getListFooter();
                        ?>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                <?php
                if (count($this->items)) {
                    foreach ($this->items as $i => $item) {
                        $checked = JHTML::_('grid.id', $i, $item->id);
                        ?>
                    <tr class="row<?php echo $i % 2; ?>">
                        <td>
                            <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                        </td>
                        <td class="">
                                <a href="index.php?option=com_marketplace&view=marketplace&layout=edit_seller&seller_id=<?php
                                    echo $item->seller_id;
                                ?>">
                                <?php echo $item->username;
                            ?></a>
                        </td>
                        <td style="word-break: break-all;">
                            <?php echo $item->subject; ?>
                        </td>
                        <td style="word-break: break-all;" class="seller-mess">
                        <?php
                        if (strlen($item->message)>250) {
                            $str1 = substr($item->message, 0, 250);
                            $str2 = substr(
                                $item->message, 250, strlen($item->message)
                            );
                            $hidden_str = '<span class="hidden-more">'.$str2.
                                '<a class="wk_show_link"'.
                                'href="javascript:void(0);" onclick="showless'.
                                '(jQuery(this));"> '.JText::_('SHOW_LESS').
                                '</a>'.'</span>';
                            $show_more=$str1.
                                '<a class="wk_show_link show-less" href="javascript:void(0);" '.
                                'onclick="showmore(jQuery(this));"> '.JText::_(
                                    'SHOW_MORE'
                                ).'</a>';
                            echo $show_more.$hidden_str;
                        } else {
                            echo $item->message;
                        }
                        ?>
                        </td>
                        <td>
                            <?php echo $item->time; ?>
                        </td>
                        <td>
                            <?php echo $item->id; ?>
                        </td>
                    </tr>
                <?php
                    }
                } else {
                    echo "<tr ><td colspan='9'><div class='alert alert-info'>".
                    "<strong>Info!</strong>".JText::_('NO_RECORD_FOUND')."</div></td></tr>";
                }
                ?>
                </tbody>
            </table>
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="boxchecked" value="0" />
            <?php echo JHTML::_('form.token'); ?>
        </form>
    </div>
</div>
