<?php
/**
 * The contact List block file of contact 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      Xiying Guan <guanxiying@xirangit.com>
 * @package     common
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<style>
.contact-list-item + .contact-list-item {border-top: 1px solid #E7EAF2; margin-top: 5px; padding-top: 6px;}
.contact-list-item > .heading {height: 30px; position: relative; margin-right: 30px;}
.contact-list-item > .heading > .btn-expand {position: absolute; right: -30px; top: 0; z-index: 10}
.contact-list-item > .heading > .btn-expand.collapsed > .icon-angle-up:before {content: '\e939'}
.contact-list-item .contact-name,
.contact-list-item .contact-title,
.contact-list-item .contact-mobile {float: left; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; line-height: 28px; padding-left: 5px; height: 28px;}
.contact-list-item .contact-name {width: 40%;}
.contact-list-item .contact-name .label {position: relative; top: -2px;}
.contact-list-item .contact-title {width: 22%; padding-left: 10px;}
.contact-list-item > .content {position: relative; top: -30px; padding-left: 120px; background: #fff; display: none}
.contact-list-item.expanded > .content {display: block}
.contact-list-item .contact-vcard {width: 120px; height: 120px; position: absolute; left: 0; top: 0;}
.contact-list-item .contact-infos {min-height: 120px; margin-bottom: -30px;}
.contact-info-item {position: relative; padding-left: 31%; line-height: 24px;}
.contact-info-item > .info-title {position: absolute; left: 0; top: 0; width: 70px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; text-align: right; padding-right: 10px}
.contact-info-item > .info-content {text-overflow: ellipsis; white-space: nowrap; overflow: hidden; height: 24px}
</style>
<div class='panel panel-block universal'>
  <div class='panel-heading'>
    <strong class='title'><?php echo $lang->contact->common;?></strong>
  </div>
  <?php if(isset($customer)):?>
  <div class='panel-actions'>
    <?php echo html::a($this->createLink('crm.customer', 'linkContact', "customerID=$customer->id"), '<i class="icon icon-plus"></i> ' . $lang->contact->create, "class='btn btn-primary'");?>
  </div>
  <?php endif;?>
  <div class='panel-body contact-list' id='contactsList'>
    <?php $isFirstContact = true;?>
    <?php foreach($contacts as $contact):?>
    <div class='contact-list-item<?php if($isFirstContact) echo ' expanded';?>' id='contact-info-<?php echo $contact->id?>'>
      <div class='heading'>
        <div class='contact-name'>
          <?php echo html::a($this->createLink('crm.contact', 'view', "contactID=$contact->id"), $contact->realname, "class='text-fore text-md'");?>
          <?php if($contact->gender == 'f'):?>
          &nbsp; <small class='text-red'><?php echo $lang->contact->lady;?></small>
          <?php elseif($contact->gender == 'm'):?>
          &nbsp; <small class='text-primary'><?php echo $lang->contact->gentleman;?></small>
          <?php endif;?>
        </div>
        <div class='contact-mobile text-md'><?php echo  $contact->mobile;?></div>
        <a href='#contact-info-<?php echo $contact->id?>' class='btn btn-link btn-expand<?php if(!$isFirstContact) echo ' collapsed';?>'><i class='icon icon-angle-up'></i></a>
      </div>
      <div class='content'>
        <?php echo html::image(helper::createLink('crm.contact', 'vcard', "contactID={$contact->id}"), "class='contact-vcard'");?>
        <div class='contact-infos'>
          <div class='contact-info-item'>
            <div class='info-title text-gray'><?php echo $lang->contact->realname;?></div>
            <div class='info-content'><?php echo html::a($this->createLink('crm.contact', 'view', "contactID=$contact->id"), $contact->realname, "class='text-fore text-md'"); ?>
              <?php if($contact->maker):?>
              &nbsp; <span class='label label-pale'><?php echo $lang->resume->maker?></span>
              <?php endif;?>
            </div>
          </div>
          <?php if($contact->title):?>
          <div class='contact-info-item'>
            <div class='info-title text-gray'><?php echo $lang->resume->title;?></div>
            <div class='info-content'>
              <?php
              $positions = array_filter(explode(',', $contact->position));
              foreach($positions as $index => $position)
              {
                  if($position == 'other')
                  {
                      $title = $contact->title;
                  }
                  else
                  {
                      $title = zget($lang->contact->positionList, $position);
                  }
                  if($index != 1)
                  {
                      $title = ',' . $title;
                  }
                  echo $title;
              }
              ?>
            </div>
          </div>
          <?php endif; ?>
          <?php if(!empty($contact->gender) && isset($lang->genderList[$contact->gender])): ?>
          <div class='contact-info-item'>
            <div class='info-title text-gray'><?php echo $lang->contact->gender;?></div>
            <div class='info-content'><?php echo $lang->genderList[$contact->gender]; ?></div>
          </div>
          <?php endif; ?>
          <?php foreach($config->contact->contactWayList as $item):?>
          <?php if(!empty($contact->{$item})):?>
          <div class='contact-info-item'>
            <div class='info-title text-gray'><?php echo $lang->contact->{$item};?></div>
            <div class='info-content'>
              <?php
              if($item == 'qq')
              {
                  $site = isset($config->company->name) ? $config->company->name : '';
                  echo html::a("http://wpa.qq.com/msgrd?v=3&uin={$contact->$item}&site={$site}&menu=yes", $contact->$item, "target='_blank'");
              }
              else if($item == 'email')
              {
                  echo html::mailto($contact->{$item}, $contact->{$item});
              }
              else if($item != 'qq' and $item != 'email')
              {
                  echo $contact->{$item};
              }
              ?>
            </div>
          </div>
          <?php endif;?>
          <?php endforeach;?>
        </div>
      </div>
    </div>
    <?php $isFirstContact = false;?>
    <?php endforeach;?>
  </div>
</div>
<script>
$(function()
{
    $('#contactsList').on('click', '.btn-expand', function(e)
    {
        var $btn = $(this).toggleClass('collapsed');
        var collapsed = $btn.hasClass('collapsed');
        var id = $btn.attr('href');
        $btn.closest('.contact-list-item').toggleClass('expanded', !collapsed);
        if (!collapsed)
        {
            $('#contactsList .contact-list-item').not(id).removeClass('expanded').find('.btn-expand').addClass('collapsed');
        }
        e.preventDefault();
    });
});
</script>
<?php if(isset($pageJS)) js::execute($pageJS);?>
