<link rel="stylesheet" href="/js/jquery-ui/smoothness/jquery-ui-1.8.21.custom.css" type="text/css" />
<script type="text/javascript" src="/js/jquery-ui/jquery-ui-1.8.21.custom.min.js"></script>

<script>
  $(function() {
      $( "#t_expires" ).datepicker({
        showButtonPanel: true
      });
  });
  function upload_task_attach(text){
      $("#t_attach").val(text);
      $("#upload_status0").text(text);
  }
</script>

<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">
          <form action="<?php echo site_url('welcome/update_task') ?>" class=""  name="form_update_task" id="form_update_task" method="post">
            <div class="control-group">
            <label class="control-label">Task name</label>
              <div class="controls">
              <input type="text" class="span12" id="t_title" name="t_title" placeholder="Task name" value="<?php echo isset($task)?$task->t_title:false; ?>" />
              </div>
            </div>
            
            <div class="control-group">
            <label class="control-label">Task description</label>
            <div class="controls">
              <textarea rows="8" class="span12" id="t_content" name="t_content" ><?php echo isset($task)?$task->t_content:false; ?></textarea>
              </div>
            </div>
            <input type="hidden" name="t_attach" id="t_attach" value="<?php echo isset($task)?$task->t_attach:false; ?>">
            </form>
            <div class="control-group">
            <label class="control-label">Estimated time of completion</label>
            <div class="controls">
                <div class="span3"><input form="form_update_task" class="span12" size="16" id="t_expires" name="t_expires" type="text" value="<?php echo isset($task)?date('m/d/Y',strtotime($task->t_expires)):false; ?>" /></div>
                <div class="span2" style="position:relative">
                  <form action="<?php echo site_url('welcome/upload_task_attach') ?>" 
                    method="post" 
                    target="ifm1"
                    class="form-horizontal"
                    enctype="multipart/form-data" style="position:absolute;z-index:10;">
                    <input class="span12" style="filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;cursor: pointer;" type="file" name="task_attach" id="task_attach" onChange="this.form.submit()" />
                  </form>
                  <span class="text-info span12" style="position: absolute;top: 4px;"> Add Attachment + </span>
                </div>
                <div class="span3" id="upload_status0" style="padding-top: 4px;"><?php echo isset($task)?"<a target='_blank' href='/author/document/task_attach/{$task->t_attach}' >{$task->t_attach}</a>":false; ?></div>
              </div>
            </div><br>

            <div class="btn-group pull-right">
               <input form="form_update_task" type="hidden" name="t_a_id" value="<?php echo isset($task)?$task->t_a_id:false; ?>" />
               <input form="form_update_task" type="hidden" name="t_id" value="<?php echo isset($task)?$task->t_id:false; ?>" />
               <a class="btn btn-danger" href="<?php echo site_url('welcome/delete_task/'.$task->t_id); ?>">Delete task</a>
               <button type="button" class="btn btn-primary" onclick="submitForm('form_update_task');">Submit task.</button>
            </div>
          
      </div>
      <div id="upload_status1">
         <iframe class="ifm1 hide" name="ifm1"></iframe>
      </div>
      <div class="span3 well" style="min-height:800px;">
           <?php if(!empty($task->t_a_id)){ ?>
            <a name="sms"></a>
            <legend class="muted">Short message</legend> 
            <form action="<?php echo site_url('welcome/send_to_admin'); ?>" class="form-horizontal"  name="form_sms" id="form_sms" method="post">
                  <textarea rows="3" class="span12" id="m_content" name="m_content" placeholder="Short message" ></textarea>
                  <input type="hidden" id="t_id" name="t_id" value="<?php echo isset($task)?$task->t_id:false; ?>" >
            <p> </p>
                  <a class="btn <?php if($task->t_a_id!=$admin_info_user) echo 'hide'; ?>" href="javascript:void(0);" onclick="submitForm('form_sms');">Send</a>
            </form>
            <p> </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;"><?php echo $content['content']; ?></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;"><?php echo $content['content']; ?></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 }}} ?>

            <!--短消息历史记录start-->
            <?php if(!empty($sms_list)){ ?>
            <?php $avatars['me']=get_author_photo($task->t_a_id); if(isset($other_sender))$avatars['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 $avatars['other'];?>" 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 echo $avatars['me'];?>" 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 } ?>
            <!--短消息历史记录end-->

           <?php } ?>
        
  </div>
    </div>
  </div>

</div>


