<?php 
/**
 * The browse view file of leads module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Tingting Dai <daitingting@xirangit.com>
 * @package     leads 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('mode', $mode);?>
<?php js::set('origin', $origin);?>
<li id='bysearchTab'><?php echo html::a('#', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div id='menuActions'>
  <?php commonModel::printLink('contact', 'import', '', $lang->importIcon . $lang->import, "class='btn btn-secondary' data-toggle='modal'");?>
  <?php if(commonModel::hasPriv('contact', 'export')):?>
  <div class='btn-group'>
    <button data-toggle='dropdown' class='btn btn-secondary dropdown-toggle' type='button'><?php echo $lang->exportIcon . $lang->export;?> <span class='caret'></span></button>
    <ul id='exportActionMenu' class='dropdown-menu'>
      <li><?php commonModel::printLink('contact', 'export', 'type=leads&mode=all', $lang->exportAll, "class='iframe' data-width='700'");?></li>
      <li><?php commonModel::printLink('contact', 'export', 'type=leads&mode=thisPage', $lang->exportThisPage, "class='iframe' data-width='700'");?></li>
      <li><?php commonModel::printLink('contact', 'exportTemplate', 'type=leads', $lang->exportTemplate, "class='iframe' data-width='700'");?></li>
    </ul>
  </div>
  <?php endif;?>
  <?php commonModel::printLink('leads', 'apply', '', "<i class='icon-pencil'> </i>" . $lang->contact->apply, "class='jsoner btn btn-primary'");?>
  <?php commonModel::printLink('leads', 'create', '', "<i class='icon-plus'></i> {$lang->leads->create}", "class='btn btn-primary'")?>
</div>
<?php 
$canBatchAssign  = commonModel::hasPriv('leads', 'batchAssign');
$canBatchIgnore  = commonModel::hasPriv('leads', 'batchIgnore');
$canBatchAction  = $contacts && ($canBatchAssign || $canBatchIgnore);
?>
<div class='panel main-table' data-ride='table'>
  <?php if($canBatchAction):?>
  <form id='ajaxForm' method='post'>
  <?php endif;?>
    <table class='table has-sort-head' id='contactList'>
      <thead>
        <tr class='text-center'>
          <?php $vars = "mode={$mode}&status={$status}&origin={$origin}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
          <th class='w-80px text-left'>
            <?php if($canBatchAction):?>
            <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
            <?php endif;?>
            <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->contact->id);?>
          </th>
          <th class='w-80px text-left'><?php commonModel::printOrderLink('realname', $orderBy, $vars, $lang->contact->realname);?></th>
          <?php if($mode == 'next'):?>
          <th class='w-80px text-left'><?php commonModel::printOrderLink('nextDate', $orderBy, $vars, $lang->contact->nextDate);?></th>
          <?php endif;?>
          <th><?php commonModel::printOrderLink('company', $orderBy, $vars, $lang->contact->company);?></th>
          <th class='w-60px'> <?php commonModel::printOrderLink('gender', $orderBy, $vars, $lang->contact->gender);?></th>
          <th class='w-160px'><?php commonModel::printOrderLink('phone', $orderBy, $vars, $lang->contact->phone . $lang->slash . $lang->contact->mobile);?></th>
          <th class='w-160px'><?php commonModel::printOrderLink('email', $orderBy, $vars, $lang->contact->email);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('qq', $orderBy, $vars, $lang->contact->qq);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('weixin', $orderBy, $vars, $lang->contact->weixin);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('origin', $orderBy, $vars, $lang->contact->origin);?></th>
          <th class='w-<?php echo $lang->leads->actionWidth;?>px'><?php echo $lang->actions;?></th>
        </tr>
      </thead>
      <tbody>
      <?php foreach($contacts as $contact):?>
      <tr class='text-center'>
        <td class='text-left'>
          <?php if($canBatchAction):?>
          <div class='checkbox-primary'>
            <input type='checkbox' name='contactIDList[]' value="<?php echo $contact->id;?>">
            <label for="contactIDList<?php echo $contact->id;?>"></label>
          </div>
          <?php endif;?>
          <?php echo $contact->id;?>
        </td>
        <td class='text-left c-name' title='<?php echo $contact->realname;?>'><?php echo html::a(inlink('view', "contactID={$contact->id}&mode={$mode}&status={$status}"), $contact->realname);?></td>
        <?php if($mode == 'next'):?>
        <td title='<?php echo formatTime($contact->nextDate);?>'><?php echo formatTime($contact->nextDate, DT_DATE1);?></td>
        <?php endif;?>
        <td class='text-left c-name' title='<?php echo $contact->company;?>'><?php echo $contact->company;?></td>
        <td><?php echo isset($lang->genderList->{$contact->gender}) ? $lang->genderList->{$contact->gender} : '';?></td>
        <?php $phoneAndMobile =  $contact->phone . (($contact->phone && $contact->mobile) ? $lang->slash : '') . $contact->mobile;?>
        <td class='text-left c-name' title='<?php echo $phoneAndMobile;?>' ><?php echo $phoneAndMobile;?></td>
        <td title='<?php echo $contact->email;?>'><?php echo html::mailto($contact->email, $contact->email)?></td>
        <td title='<?php echo $contact->qq;?>'><?php echo empty($contact->qq) ? '' : html::a("tencent://Message/?Uin={$contact->qq}&websiteName=ZDOO&Menu=yes", $contact->qq, "target='_blank'")?></td>
        <td title='<?php echo $contact->weixin;?>'><?php echo empty($contact->weixin) ? '' : $contact->weixin;?></td>
        <td class='text-left' title='<?php echo $contact->origin;?>'><?php echo $contact->origin;?></td>
        <td class='actions'>
          <?php
          commonModel::printLink('leads', 'assign', "contactID=$contact->id", $lang->contact->assign, "data-toggle='modal'");
          commonModel::printLink('action', 'createRecord', "objectType=contact&objectID={$contact->id}", $lang->contact->record, "data-toggle='modal' data-width='800'");
          commonModel::printLink('address', 'browse', "objectType=contact&objectID=$contact->id", $lang->contact->address, "data-toggle='modal'");
          commonModel::printLink('leads', 'edit', "contactID={$contact->id}&mode={$mode}&status={$status}", $lang->edit);
          commonModel::printLink('leads', 'transform', "contactID=$contact->id", $lang->confirm, "data-toggle='modal'");
          if($contact->status != 'ignore') commonModel::printLink('leads', 'ignore', "contactID=$contact->id", $lang->ignore, "data-toggle='modal'");
          if($contact->status == 'ignore') commonModel::printLink('leads', 'delete', "contactID=$contact->id", $lang->delete, "class='deleter'");
          ?>
        </td>
      </tr>
      <?php endforeach;?>
      </tbody>
    </table>

    <div class='table-footer'>
      <?php if($canBatchAction):?>
      <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll;?></label></div>
      <div class='table-statistic'></div>
      <div class='table-actions btn-toolbar'>
        <?php
        if($canBatchIgnore && $mode != 'ignoredBy' && $mode != 'all')
        {
            $ignoreLink = $this->createLink('leads', 'batchIgnore');
            echo html::a('javascript:;', $lang->ignore, "onclick=\"setFormAction('$ignoreLink')\" class='btn'");
        }
        ?>

        <?php if($canBatchAssign):?>
        <?php $assignToLink = $this->createLink('leads', 'batchAssign');?>
        <div class='btn-group dropup no-margin'>
          <button data-toggle='dropdown' type='button' class='btn dropdown-toggle'> <?php echo $lang->contact->assignedTo;?> <span class='caret'></span></button>
          <?php echo html::select('assignedTo', $users, '', "class='hidden'");?>
          <?php $withSearch = count($users) > 10;?>
          <?php if($withSearch):?>
          <div class="dropdown-menu search-list search-box-sink" data-ride="searchList">
            <div class="input-control search-box has-icon-left has-icon-right search-example">
              <input id="userSearchBox" type="search" autocomplete="off" class="form-control search-input">
              <label for="userSearchBox" class="input-control-icon-left search-icon"><i class="icon icon-search"></i></label>
              <a class="input-control-icon-right search-clear-btn"><i class="icon icon-close icon-sm"></i></a>
            </div>
          <?php $usersPinYin = commonModel::convert2Pinyin($users);?>
          <?php else:?>
          <div class="dropdown-menu search-list">
          <?php endif;?>
            <div class="list-group">
              <?php
              foreach($users as $key => $value)
              {
                  if(empty($key)) continue;
                  $searchKey = $withSearch ? ('data-key="' . zget($usersPinYin, $value, '') . " @$key\"") : "data-key='@$key'";
                  echo html::a("javascript:$(\".table-actions #assignedTo\").val(\"$key\");setFormAction(\"$assignToLink\")", $value, '', $searchKey);
              }
              ?>
            </div>
          </div>
        </div>
        <?php endif;?>
      </div>
      <?php endif;?>

      <?php $pager->show();?>
    </div>

  <?php if($canBatchAction):?>
  </form>
  <?php endif;?>
</div>
<?php include '../../common/view/footer.html.php';?>
