<div class="row-fluid">
  <div class="span2">
    <ul class="nav nav-tabs nav-stacked" style="min-height:800px;background:#f5f5f5;">
      <li class="<?php if($nav_status=='index') echo 'active'; ?>"><a href="<?php echo site_url('sendmail/index');?>">待发送邮件</a></li>
      <li class="<?php if($nav_status=='sent_mail') echo 'active'; ?>"><a href="<?php echo site_url('sendmail/index/1');?>">已发送邮件</a></li>
      <li class="<?php if($nav_status=='loglist') echo 'active'; ?>"><a href="<?php echo site_url('sendmail/log_list');?>">投递失败邮件</a></li>
      <li><a href="<?php echo site_url('sendmail/send_mail');?>" target="_blank">触发邮件发送</a></li>
    </ul>
  </div>
  <div class="span10">
    <table class="table table-striped">
  <thead>
    <tr>
      <th>时间</th>
      <th>发件人</th>
      <th>收件人</th>
      <th>标题</th>
      <th>内容</th>
      <th>错误信息</th>
      <th>设置</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($log as $key => $l) { ?>
    <tr>
      <td><?php echo $l->M_AddTime; ?></td>
      <td><?php echo $l->M_ReplyToName.':<br>'.$l->M_ReplyToEmail; ?></td>
      <td><?php echo $l->M_ToName.':<br>'.$l->M_ToEmail; ?></td>
      <td><?php echo $l->M_SN.':'.$l->M_Title; ?></td>
      <td><?php $text=get_text_short($l->M_Body,40,'...'); echo $text['content']; ?></td>
      <td><a href="#errorModal" class="error-btn" data-toggle="modal">详细<em class="hide"><?php echo $l->log_content;?></em></a></td>
      <td><a class="unsend" href="<?php echo site_url('sendmail/set_unsend').'/'.$l->M_SN; ?>">重新投递</a></td>
    </tr>
    <?php } ?>
  </tbody>
</table>
  </div>
</div>

<!-- 错误信息Modal -->
<div id="errorModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">投递错误信息</h3>
  </div>
  <div class="modal-body error-infos"></div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
  </div>
</div>

<script type="text/javascript">
//设置邮件状态，重新投递该邮件
$(".unsend").click(function(event){
  event.preventDefault();
  var $a=$(this);
  var url=$a.attr('href');
  $.post(url,'',function(text){
    $('.modal').modal('hide');
    if (text==1) {
      $a.text('');
      $.modaldialog.success("设置成功,稍后会重新投递该邮件！");
    }else{
      $.modaldialog.error("设置失败，请稍后再试！");
    }
  });
});

$(".error-btn").click(function(){
  var content=$(this).children('em').html();
  $(".error-infos").html(content);
});
</script>