<?php
use home\assets\MainAsset;
use yii\helpers\Url;
use common\models\User;
use yii\widgets\ActiveForm;
use yii\helpers\StringHelper;
use home\models\Message;

$this->title = '收件箱';
?>

<!--container-->
<div class="container manage-project fix">

    <div class="manage-left">
        <ul>
            <li><a href="<?= Url::to(['message/inbox']) ?>">消息通知</a>
            <ul>
                <li><a href="<?= Url::to(['message/inbox']) ?>">收件箱</a></li>
                <li><a href="<?= Url::to(['message/outbox']) ?>">发件箱</a></li>
            </ul>
            </li>
            <li><a href="<?= Url::to(['announcement/index']) ?>">系统通知</a>
            <ul>
                <li><a href="<?= Url::to(['announcement/index']) ?>">通知列表</a></li>
            </ul>
            </li>
        </ul>
    </div>

    <div class="manage-right">

        <div class="tab-column tab-manage">
            <?php if (Message::readAccess('home/message/short-message')) :?>
            <div class="tab-right">
                <button title="发送短消息" type="button" data-url='<?= Url::to([$this->context->id . '/short-message']) ?>' data-width='800' data-height='500' data-title='发送短消息' class="btn btn-default btn-task open-dialog">
                    <i class="icon-envelope"></i>
                </button>
            </div>
            <?php endif; ?>
            <?php if (Message::readAccess('home/message/notice')) :?>
            <div class="tab-right">
                <button title="发送通知公告" type="button" data-url='<?= Url::to([$this->context->id . '/notice']) ?>' data-width='800' data-height='500' data-title='发送通知公告' class="btn btn-default btn-task open-dialog">
                    <i class="icon-volume-up"></i>
                </button>
            </div>
            <?php endif; ?>
            <p class="caption">消息列表</p>
        </div>

        <?= \home\widgets\Alert::widget(); ?>
        <?= $this->render('_search', ['model' => $model, 'get' => $get, 'action' => '/message/inbox']) ?>
		<?php $mainForm = ActiveForm::begin([ 'id' => 'main-form', 'action' => '']); ?>

		<table class="table task-table">
			<tr>
				<th width="40"><label style="font-weight:lighter" ><input type="checkbox" name="select_all" class="box-select-all" style="position:relative;top:2px;" /> 全选</label></th>
				<th width="35%">标题</th>
                <th width="70">发件人</th>
                <th width="90">发送时间</th>
                <th width="90">阅读时间</th>
				<th width="100" align="center">操作</th>
			</tr>
			<?php if (empty($models)) : ?>
				<tr><td colspan="7" class="tac red">没有任何数据...</td></tr>
			<?php else : ?>
                <?php foreach ($models as $key => $model) : ?>
                    <tr>
                        <td><input type="checkbox" name="delete[]" class="box-delete" value="<?= $model->message_id ?>" /></td>
                        <td class='theleft-min' title="<?= $model->message->title ?>"><?= StringHelper::truncate($model->message->title, 24) ?></td>
                        <td><?= $model->fromName->realname; ?></td>
                        <td><?= date('Y-m-d H:i',$model->message->create_time) ?></td>
                        <td><?= !empty($model->is_read) ? date('Y-m-d H:i',$model->read_time) : '<font color="red">未读</font>' ?></td>
                        <td align="center" >
                            <?php if (empty($model->message->is_reply)) : ?>
                                <a href="javascript:;" class="open-only-see-dialog"  data-url="<?= Url::to([$this->context->id.'/only-see', 'id' => $model->message_id, 'link_id' => $model->link_id]) ?>"  data-height='400' data-width='850' data-title='查看信息通知' >查看</a>
                            <?php else : ?>
                                <a href="javascript:;" class="open-dialog"  data-url="<?= Url::to([$this->context->id.'/look-reply', 'id' => $model->message_id, 'link_id' => $model->link_id]) ?>"  data-height='500' data-width='850' data-title='查看信息通知' >查看</a>
                            <?php endif; ?>

                            <?php if (!empty($model->is_read)) : ?>
                                <a href="<?= Url::to([$this->context->id . '/inbox-delete', 'id' => $model->message_id ]) ?>" class="link-delete" >删除</a>
                            <?php endif; ?> 
                        </td>
                    </tr>
                <?php endforeach; ?>
			<?php endif; ?>
		</table>

		<div class="tab-column tab-manage">
            <button title="删除" type="button" class="btn btn-default btn-task batch-delete" data-url="<?= Url::to([$this->context->id.'/inbox-delete']) ?>" >
              <i class="icon-trash"></i>
            </button>
        </div>

		<?php ActiveForm::end(); ?>
        
        <!--分页标签-->
      	<div class="pages">
            <?php if ($pages->totalCount != 0) : ?><span class="pagetotal">共<em><?= $pages->totalCount ?></em>条记录<em><?= $pages->page + 1 ?>/<?= $pages->pageCount ?></em>页 </span><?php endif; ?>
            <?= \yii\widgets\LinkPager::widget(['pagination' => $pages, 'prevPageLabel' => '上一页','nextPageLabel' => '下一页', 'firstPageLabel' => '首页', 'lastPageLabel' => '末页']); ?>
        </div>
        <!--分页标签-->
    </div>
	<!--manage-right-->
</div>
<!--container-->

