<script type="text/javascript">
function viewMessage(ID) {
  document.location.href = "index.php?md=Affiliate_Merchants_Views_Communications&action=view&mid="+ID+"&<?php echo SID?>";
}
function editMessage(ID) {
  document.location.href = "index.php?md=Affiliate_Merchants_Views_BroadcastMessage&action=edit&mid="+ID+"&<?php echo SID?>";
}
function replyMessage(ID,emailsubject) {
  document.location.href = "index.php?md=Affiliate_Merchants_Views_BroadcastMessage&br_sheet=news&userid="+ID+"&emailsubject="+emailsubject+"&<?php echo SID?>";
}
function deleteMessage(ID) {
  if(confirm("<?php echo L_G_CONFIRMDELETEMESSAGE?>"))
    document.location.href = "index.php?md=Affiliate_Merchants_Views_Communications&mid="+ID+"&action=delete"+"&<?php echo SID?>";
}
function activateMessage(ID) {
  document.location.href = "index.php?md=Affiliate_Merchants_Views_Communications&action=activate&mid="+ID+"&<?php echo SID?>";
}
function deactivateMessage(ID) {
  document.location.href = "index.php?md=Affiliate_Merchants_Views_Communications&action=deactivate&mid="+ID+"&<?php echo SID?>";
}
</script>



    <table class="tblist mt10" border=0 cellspacing=0 cellpadding=1 width="780">
    <tr class=header>
<?php
    //QUnit_Templates::printHeader(L_G_ID, 'm.messageid');
    QUnit_Templates::printHeader(L_G_CREATED, 'm.dateinserted');
    QUnit_Templates::printHeader(L_G_TITLE, 'm.title');
    QUnit_Templates::printHeader(L_G_MESSAGE_TEXT, 'm.rtext');
    if($this->a_Auth->getSetting('Aff_display_news') == '1') {
        QUnit_Templates::printHeader(L_G_HISTORYTYPE, 'm.rtype');
    }
    QUnit_Templates::printHeader(L_G_SENDFROM, 'mu.fromuserid');
    QUnit_Templates::printHeader(L_G_RECIPIENT, 'users_count');
    QUnit_Templates::printHeader(L_G_EMAIL, 'mu.email');
    QUnit_Templates::printHeader(L_G_ACTIONS);
?>
    </tr>
<?php
    $nodata = true;
    while($data=$this->a_list_data->getNextRecord()) {
        $nodata = false;
?>
    <tr class=listresult onMouseover="this.className='listresultMouseOver'" onMouseOut="this.className='listresult';">
      <td class=listresult nowrap><?php echo $data['dateinserted']?></td>
      <td class=listresult nowrap><?php echo cut_str($data['title'],5); ?></td>
      <td class=listresult nowrap>
      <?php
      $text = $data['rtext'];
      print cut_str($text,5);
      ?>

      </td>
      <?php if($this->a_Auth->getSetting('Aff_display_news') == '1') { ?>
        <td class=listresult nowrap>
        <?php if($data['rtype'] == MESSAGETYPE_EMAIL) print L_G_EMAIL;
           else if($data['rtype'] == MESSAGETYPE_NEWS) print L_G_NEWS;
           else print L_G_UNKNOWN_TYPE;
        ?>

        </td>
      <?php } ?>
      <td class=listresult nowrap>
        <?php print $this->a_message_users[$data['messageid']][$data['messagetouserid']]['fromuser']; ?>

      </td>
      <td class=listresult nowrap>
        <?php
          if($data['showtoall'] == '1') print L_G_ALL;
          else if($data['users_count'] > 1) print L_G_MULTIPLE;
          else if($data['users_count'] > 0) print $this->a_message_users[$data['messageid']][$data['messagetouserid']]['name'];
        ?>

      </td>
      <td class=listresult nowrap>
        <?php
          if($data['showtoall'] == '1') print L_G_ALL;
          else if($data['users_count'] > 1) print L_G_MULTIPLE;
          else if($data['users_count'] > 0) print $this->a_message_users[$data['messageid']][$data['messagetouserid']]['email'];
        ?>

      </td>
      <td class=listresult>
<?php          $actions = array();
            $i = 0;
            if($this->a_action_permission['view']) {
                if($this->a_message_users[$data['messageid']][$data['messagetouserid']]['userid']!=1) {
                    $ico = $this->a_message_users[$data['messageid']][$data['messagetouserid']]['rstatus']=='1'?'page.gif':'page_hui.gif';
                } else {
                    $ico = $this->a_message_users[$data['messageid']][$data['messagetouserid']]['rstatus']=='1'?'page_waterblue.gif':'page_hui.gif';
                }

                $actions[$i++] = array('id'     => 'view',
                                       'img'    => $ico,
                                       'desc'   => L_G_VIEW,
                                       'action' => "viewMessage('".$data['messageid']."');" );
            }
            //如果是发送给管理员的就不显示编辑按钮，显示为回复按钮
            if($data['rtype'] == MESSAGETYPE_NEWS && $this->a_action_permission['edit']
                && $this->a_message_users[$data['messageid']][$data['messagetouserid']]['userid']!=1) {
                $actions[$i] = array('id'     => 'edit',
                                     'img'    => 'edit.gif',
                                     'desc'   => L_G_EDIT,
                                     'action' => "editMessage('".$data['messageid']."');" );
            }
            if($this->a_message_users[$data['messageid']][$data['messagetouserid']]['userid']==1) {
                $actions[$i] = array('id'     => 'reply',
                                     'img'    => 'email_go.png',
                                     'desc'   => L_G_REPLY,
                                     'action' => "replyMessage('".$this->a_message_users[$data['messageid']][$data['messagetouserid']]['fromuserid']."',"._q(urlencode('Re: '.$data['title'])).");" );
            }

            if($this->a_message_users[$data['messageid']][$data['messagetouserid']]['userid']!=1) {
                $i++;
                if($data['rtype'] == MESSAGETYPE_NEWS && $data['active'] != '1' && $this->a_action_permission['edit']) {
                    $actions[$i] = array('id'     => 'activate',
                                         'img'    => 'sphore_active.png',
                                         'desc'   => L_G_ACTIVATE,
                                         'action' => "activateMessage('".$data['messageid']."');" );
                }

                $i++;
                if($data['rtype'] == MESSAGETYPE_NEWS && $data['active'] == '1' && $this->a_action_permission['edit']) {
                    $actions[$i] = array('id'     => 'deactivate',
                                         'img'    => 'sphore_declined.png',
                                         'desc'   => L_G_DEACTIVATE,
                                         'action' => "deactivateMessage('".$data['messageid']."');" );
                }
            }else { $i += 2; }


            $i++;
            if($this->a_action_permission['delete']) {
                $actions[$i++] = array('id'     => 'delete',
                                       'img'    => 'delete.png',
                                       'desc'   => L_G_DELETE,
                                       'action' => "deleteMessage('".$data['messageid']."');" );
            }
            $this->a_this->initTemporaryTE();
            $this->a_this->temporaryAssign('a_actions', $actions);
            $this->a_this->temporaryAssign('a_action_count', $i);
?>
            <?php echo $this->a_this->temporaryFetch('actions_icon'); ?>
      </td>
    </tr>
<?php
    }
?>

    <tr>
      <td class=listheader colspan=8 align=center>
        <?php QUnit_Templates::printPaging($this->a_list_page, $this->a_list_pages, $this->a_allcount) ?>
      </td>
    </tr>

<?php  if ($nodata) { ?>
    <tr><td colspan="9" align="center"><b><?php echo L_G_NORECORDSFOUND; ?></b></td></tr>
<?php  } ?>

  </table>
  </form>

