<script>
    function deal_task(){
      var url= $("#form_refuse_task").attr('action');
      var data=$("#form_refuse_task").serialize();
      $.post(url,data,function(responseText){
          var responseText=eval("("+responseText+")");//转换为json对象 
          for (var key in responseText) {
              if (responseText[key].name == 'ok') {
                 alert('已通过该投稿申请！');
              }else if(responseText[key].name == 'no'){
                  alert('已拒绝该投稿申请！');
              }
          }
          $('#myModal').modal('hide');
      });
      $(".wait-task").remove();
    }
    function show_msg(a,type){
    if (type=='data-short') {
        var contenttype='data-long';
        var flag=' >> ';
    }else{
        var contenttype='data-short';
        var flag=' << ';
    }
    var content=$(a).parent('p').attr(type);
    $(a).parent('p').html(content+'<a href="javascript:void(0);" onclick="show_msg(this,'+"'"+contenttype+"'"+');"> '+flag+' </a>');
}
</script>
<style>
.nav-list{border-right: none !important;}
</style>
<div class="row-fluid">
  <div class="span2 well" style="min-height:700px;">
    <?php echo $nav_view; ?>
  </div>
  <div class="span10">
    <div class="row-fluid">
        <div class="span9">
            <legend>投稿详情</legend>
            <form action=""  name="form_refuse_task" id="form_refuse_task" method="post">
                <input type="hidden" id="is_id" name="is_id" value="<?php echo!empty($information) ? $information->is_id : false; ?>" >
                <input type="hidden" id="t_id" name="t_id" value="<?php echo isset($task) ? $task->t_id : false; ?>" >
                <input type="hidden" id="t_a_id" name="t_a_id" value="<?php echo $task->t_a_id; ?>">
                <input type="hidden" id="refuse_msg" name="refuse_msg" >
            </form>
            <address>
              <strong class="muted">投稿名称：</strong>
              <?php echo $task->t_title; ?>
            </address>
            <address>
              <strong class="muted">投稿作者：</strong>
              <?php echo get_author_name($task->t_a_id); ?>
            </address>
            <address>
              <strong class="muted">预计完成日期：</strong>
              <?php echo date('Y-m-d', strtotime($task->t_expires)); ?>
            </address>
            <address>
              <strong class="muted">投稿描述:</strong><br>
              <p><?php echo $task->t_content; ?></p>
            </address>
            <?php if(!empty($task->t_attach)){ ?>
              <div class="row-fluid">附件:<a target="_blank" href="<?php echo ('/author/document/task_attach/'.$task->t_attach); ?>"><?php echo $task->t_attach; ?></a> </div>
            <?php } ?>
            <legend style="padding-top:20px;"></legend>
            <div class="btn-group pull-right" >
                <a href="#myModal" role="button" class="btn btn-danger wait-task" data-toggle="modal">不通过投稿申请</a>
                <button class="btn btn-success wait-task" onclick="$('#form_refuse_task').attr('action','<?php echo site_url('author/change_wait_tast_status/edit'); ?>');deal_task();">通过投稿申请</button>
            </div>
        </div>

        <div class="span3 well" style="min-height:1024px;">
          <?php if (!empty($task->t_a_id)) { ?>
            <a name="sms"></a>
            <legend>短消息</legend> 
            <form action="<?php echo site_url('author/send_to_author'); ?>" class="form-horizontal"  name="form_sms" id="form_sms" method="post">
              <textarea rows="3" class="input-block-level" id="m_content" name="m_content" placeholder="短消息" ></textarea>
              <input type="hidden" id="t_id" name="t_id" value="<?php echo isset($task) ? $task->t_id : false; ?>" >
              <p> </p>
              <a class="btn pull-left" href="javascript:void(0);" onclick="submitForm('form_sms');">发送</a>
            </form>
            <p>&nbsp;</p>
            <?php
            if (!empty($sms_list)) {
                foreach ($sms_list as $k=>$sms) {
                    if ($k>2) break;
                    $content=get_text_short(htmlspecialchars($sms->m_content),50);
                    if ($sms->m_sender == $task->t_a_id) {
                        ?>
                        <blockquote>
                            <p style="word-break: break-all; word-wrap:break-word;" data-long="<?php echo htmlspecialchars($sms->m_content); ?>" data-short="<?php echo $content['content']; ?>">
                                <?php echo $content['content']; ?> 
                                <?php if($content['length']){ ?> 
                                    <a href="javascript:void(0);" onclick="show_msg(this,'data-long');"> >> </a> 
                                <?php } ?>
                            </p>
                            <small><?php echo get_author_name($sms->m_sender); ?> <?php echo date('m/d/Y H:i:s', strtotime($sms->m_datetime)); ?></small>
                        </blockquote><div class="clearfix"></div>
                    <?php } else { ?>
                        <?php if(!isset($other_sender)) $other_sender=$sms->m_sender; ?>
                        <blockquote class="pull-right">
                            <p style="word-break: break-all; word-wrap:break-word;" data-long="<?php echo htmlspecialchars($sms->m_content); ?>" data-short="<?php echo $content['content']; ?>">
                                <?php echo $content['content']; ?> 
                                <?php if($content['length']){ ?> 
                                    <a href="javascript:void(0);" onclick="show_msg(this,'data-long');"> >> </a> 
                                <?php } ?>
                            </p>
                            <small><?php echo get_author_name($sms->m_sender); ?> <?php echo date('m/d/Y H:i:s', strtotime($sms->m_datetime)); ?></small>
                        </blockquote><div class="clearfix"></div>
                        <?php
                    }
                }
            }?>
            <?php if(count($sms_list)>3){ ?>
            <?php $avatar['me']=get_author_photo();if(isset($other_sender))$avatar['other']=get_author_photo($other_sender); ?>
            <a data-toggle="modal" href="#sms-modal" id="sms-modal-trigger" class="btn btn-block" data-backdrop="static">更多消息..</a>
            <div id="sms-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                <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" id="sms-modal-body" style="height:450px;">
                  <?php if (!empty($sms_list)) { krsort($sms_list); foreach ($sms_list as $sms) { ?>
                    <?php if($sms->m_sender == $task->t_a_id){ ?>

                    <div class="media">
                      <a class="pull-left" href="#">
                        <img class="media-object" src="<?php echo $avatar['me'];?>" width="45" height="45">
                      </a>
                      <div class="media-body">
                        <div class="media">
                          <small><?php echo get_author_name($sms->m_sender); ?>　<?php echo date('Y-m-d H:i:s', strtotime($sms->m_datetime)); ?></small>
                          <p style="word-break: break-all; word-wrap:break-word;"><?php echo htmlspecialchars($sms->m_content); ?></p>
                        </div>
                      </div>
                    </div>
                    
                  <?php }else{ ?>
                    <div class="media">
                      <a class="pull-right" href="#">
                        <img class="media-object" src="<?php if(!isset($avatar['other']))$avatar['other']=get_author_photo($sms->m_sender);  echo $avatar['other'];?>" width="45" height="45">
                      </a>
                      <div class="media-body">
                        <div class="media">
                          <small class="pull-right"><?php echo get_author_name($sms->m_sender); ?>　<?php echo date('Y-m-d H:i:s', strtotime($sms->m_datetime)); ?></small>
                          <p class="pull-right" style="word-break: break-all; word-wrap:break-word; clear:both;"><?php echo htmlspecialchars($sms->m_content); ?></p>
                        </div>
                      </div>
                    </div>
                  <?php } } } ?>
                </div>
                <div class="modal-footer"></div>
            </div>
            <script type="text/javascript">
              $("#sms-modal-trigger").click(function(){
                setTimeout(function(){
                    $("#sms-modal-body").scrollTop(102400);
                },500);
              });
            </script>
            <?php } ?>
          <?php } ?>
          </div>
    </div>
  </div>
</div>

<!-- Modal -->
<div id="myModal" 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">
    <label class="control-label">不通过的理由</label>
    <textarea rows="4" class="input-xlarge" id="refuse_m_content" name="refuse_m_content" style="width:510px;">refuse</textarea>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
    <button class="btn btn-primary" onclick="$('#refuse_msg').val($('#refuse_m_content').val());$('#form_refuse_task').attr('action','<?php echo site_url('author/change_wait_tast_status/refuse'); ?>');deal_task();">确定</button>
  </div>
</div>