<?php 
/**
 * The browse view file of customer 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     customer 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->getAppRoot() . 'common/view/header.html.php';?>
<?php js::set('mode', $mode);?>
<?php $extendFields = $this->customer->getFlowExtendFields();?>
<li id='bysearchTab'><?php echo html::a('#', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div id='menuActions'>
  <?php if(commonModel::hasPriv('customer', 'export')):?>
  <div class='btn-group universal'>
    <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('customer', 'export', "mode=$mode&type=all", $lang->exportAll, "class='iframe' data-width='700'");?></li>
      <li><?php commonModel::printLink('customer', 'export', "mode=$mode&type=thisPage", $lang->exportThisPage, "class='iframe' data-width='700'");?></li>
    </ul>
  </div>
  <?php endif;?>
  <?php commonModel::printLink('customer', 'create', '', '<i class="icon-plus"></i> ' . $lang->customer->create, 'class="btn btn-primary"');?>
</div>
<div class='panel main-table' data-ride='table'>
  <?php $canBatchAssign = ($customers && commonModel::hasPriv('customer', 'batchAssign'));?>
  <?php if($canBatchAssign):?>
  <form id='browseForm' method='post' action='<?php echo inlink('batchAssign');?>'>
  <?php endif;?>
    <table class='table has-sort-head'>
      <thead>
        <tr class='text-center'>
          <?php $vars = "mode={$mode}&param=&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
          <th class='text-left w-100px'>
            <?php if($canBatchAssign):?>
            <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
            <?php endif;?>
            <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->customer->id);?>
          </th>
          <th><?php commonModel::printOrderLink('name', $orderBy, $vars, $lang->customer->name);?></th>
          <th class='w-70px universal'> <?php commonModel::printOrderLink('assignedTo', $orderBy, $vars, $lang->customer->assignedTo);?></th>
          <th class='w-70px universal'> <?php commonModel::printOrderLink('level',  $orderBy, $vars, $lang->customer->level);?></th>
          <th class='w-80px'><?php commonModel::printOrderLink('size', $orderBy, $vars, $lang->customer->size);?></th>
          <th class='w-80px'> <?php commonModel::printOrderLink('stage', $orderBy, $vars, $lang->customer->stageName);?></th>
          <th class='w-160px text-left singleApp'><?php commonModel::printOrderLink('area',     $orderBy, $vars, $lang->customer->area);?></th>
          <th class='w-150px text-left singleApp'><?php commonModel::printOrderLink('industry', $orderBy, $vars, $lang->customer->industry);?></th>
          <th class='w-70px universal'> <?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->customer->status);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->customer->createdDate);?></th>
          <th class='w-100px universal'><?php commonModel::printOrderLink('contactedDate', $orderBy, $vars, $lang->customer->contactedDate);?></th>
          <th class='w-110px universal'><?php commonModel::printOrderLink('nextDate', $orderBy, $vars, $lang->customer->nextDate);?></th>
          <?php foreach($extendFields as $extendField) echo "<th class='" . ($extendField->width != 'auto' ? "w-{$extendField->width}px" : '')  . "'>{$extendField->name}</th>";?>
          <th class='w-<?php echo $lang->customer->actionWidth;?>px'><?php echo $lang->actions;?></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($customers as $customer):?>
        <tr class='text-center' data-customer="<?php echo $customer->id;?>">
          <td class='text-left'>
            <?php if($canBatchAssign):?>
            <div class='checkbox-primary'><input type='checkbox' name='customerIDList[]' value="<?php echo $customer->id;?>" id="customerIDList<?php echo $customer->id;?>">
              <label for="customerIDList<?php echo $customer->id;?>"></label>
            </div>
            <?php endif;?>
            <?php echo $customer->id;?>
          </td>
          <td class='text-left c-name'><?php if(!commonModel::printLink('customer', 'view', "customerID={$customer->id}", $customer->name)) echo $customer->name;?></td>
          <td class='universal'><?php if(isset($users[$customer->assignedTo])) echo $users[$customer->assignedTo];?></td>
          <td class='universal'><?php echo isset($lang->customer->levelNameList[$customer->level]) ? $lang->customer->levelNameList[$customer->level] : '';?></td>
          <td><?php echo $lang->customer->sizeNameList[$customer->size];?></td>
          <td><?php echo zget($lang->customer->stages, $customer->stage);?></td>
          <td class='text-left singleApp'><?php echo zget($areas, $customer->area);?></td>
          <td class='text-left singleApp'><?php echo zget($industries, $customer->industry);?></td>
          <td class='<?php echo "customer-{$customer->status}";?> universal'><?php if($customer->status) echo $lang->customer->statusList[$customer->status];?></td>
          <td><?php echo formatTime($customer->createdDate, DT_DATE1);?></td>
          <td class='universal'><?php echo formatTime($customer->contactedDate, DT_DATE1);?></td>
          <td class='universal'><?php echo formatTime($customer->nextDate, DT_DATE1); ?></td>
          <?php foreach($extendFields as $extendField) echo "<td>" . $this->loadModel('flow')->getFieldValue($extendField, $customer) . "</td>";?>
          <td class='actions'>
            <?php echo $this->customer->buildOperateMenu($customer, 'browse')?>
          </td>
        </tr>
        <?php endforeach;?>
      </tbody>
    </table>
    <div class='table-footer'>
      <?php if($canBatchAssign):?>
      <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
      <div class='table-actions btn-toolbar'>
        <div class="btn-group dropup no-margin search-box-float">
          <button data-toggle="dropdown" type="button" class="btn"><?php echo $lang->customer->assign;?> <span class="caret"></span></button>
          <?php echo html::hidden('assignedTo');?>
          <?php $actionLink = inlink('batchAssign');?>
          <?php $withSearch = count($validUsers) > 10;?>
          <div class="dropdown-menu search-list<?php if($withSearch) echo ' search-box-sink';?>" data-ride="searchList">
            <?php if($withSearch):?>
            <?php $usersPinYin = commonModel::convert2Pinyin($validUsers);?>
            <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 endif;?>
            <div class="list-group">
              <?php
              foreach($validUsers as $key => $value)
              {
                  if(empty($key) or $key == 'closed') continue;
                  $searchKey = $withSearch ? ('data-key="' . zget($usersPinYin, $value, '') . " @$key\"") : "data-key='@$key'";
                  echo html::a("javascript:$(\"#assignedTo\").val(\"$key\");setFormAction(\"$actionLink\");", $value, $searchKey);
              }
              ?>
            </div>
          </div>
        </div>
      </div>
      <div class='table-statistic'></div>
      <?php endif;?>
      <?php $pager->show();?>
    </div>
  </form>
</div>
<?php include $app->getAppRoot() . 'common/view/footer.html.php';?>
