<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php js::set('mode', $mode);?>
<?php js::set('status', $status);?>
<?php js::set('category', $category);?>
<?php js::set('store', $store);?>
<li id='bysearchTab'><?php echo html::a('javascript:;', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div id='menuActions'>
  <?php if(false && !empty($config->psi->turnon)):?>
  <?php if(commonModel::hasPriv('product', 'exportTemplate') or commonModel::hasPriv('product', 'import')):?>
  <div class='btn-group'>
    <button class='btn btn-primary dropdown-toggle' data-toggle='dropdown'><?php echo $lang->importIcon . $lang->import;?></button>
    <ul class='dropdown-menu' role='menu'>
      <?php commonModel::printLink('product', 'import', '', $lang->product->import, "data-toggle='modal'", '', '', 'li');?>
      <?php commonModel::printLink('product', 'exportTemplate', '', $lang->product->exportTemplate, '', '', '', 'li');?>
    </ul>
  </div>
  <?php endif;?>
  <?php commonModel::printLink('product', 'exportProduct', '', $lang->exportIcon . $lang->export, "class='btn btn-primary export' data-toggle='modal'");?>
  <?php endif;?>
  <?php commonModel::printLink('product', 'create', '', '<i class="icon-plus"></i> ' . $lang->product->create, "class='btn btn-primary' data-toggle='modal' data-width='800'");?>
  <?php commonModel::printLink('product', 'batchCreate', '', "<i class='icon-plus'></i> " . $lang->product->batchCreate, "class='btn btn-primary'");?>
</div>
<div class='main-row'>
  <div class='side-col'>
    <?php if(!empty($config->psi->turnon)):?>
    <?php $treeBrowsePriv  = commonModel::hasPriv('tree', 'browse');?>
    <?php $storeBrowsePriv = commonModel::hasPriv('store', 'browse');?>
    <?php if($treeBrowsePriv || $storeBrowsePriv):?>
    <div class='panel panel-block'>
      <div class='tabs'>
        <ul class='nav nav-tabs'>
          <?php if($treeBrowsePriv):?>
          <li <?php if(!$store) echo "class='active'"?>>
            <a href="#categoryList" data-toggle="tab"><strong><?php echo $lang->product->category;?></strong></a>
          </li>
          <?php endif;?>
          <?php if($storeBrowsePriv):?>
          <li <?php if($store) echo "class='active'"?>>
            <a href="#storeList" data-toggle="tab"><strong><?php echo $lang->store->common;?></strong></a>
          </li>
          <?php endif;?>
        </ul>
      </div>
      <div class='tab-content'>
        <?php if($treeBrowsePriv):?>
        <div <?php echo $store ? "class='tab-pane'" : "class='tab-pane active'"?> id="categoryList">
          <div class='panel-body'>
            <div id='treeMenuBox'>
              <?php echo $categoryMenu;?>
              <?php commonModel::printLink('tree', 'browse', 'type=product&startModule=&root=&from=product', $lang->product->setCategory, "class='btn btn-primary'");?>
            </div>
          </div>
        </div>
        <?php endif;?>
        <?php if($storeBrowsePriv):?>
        <div <?php echo !$store ? "class='tab-pane'" : "class='tab-pane active'"?> id="storeList">
          <div class='panel-body'>
            <div id='treeMenuBox'>
              <ul class='tree treeview'>
                <?php echo $storeMenu;?>
              </ul>
              <?php commonModel::printLink('store', 'browse', '', $lang->store->manage, "class='btn btn-primary'");?>
            </div>
          </div>
        </div>
        <?php endif;?>
      </div>
    </div>
    <?php endif;?>
    <?php else:?>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->product->category;?></strong>
      </div>
      <div class='panel-body'>
        <div id='treeMenuBox'><?php echo $treeMenu;?></div>
        <?php commonModel::printLink('tree', 'browse', 'type=product&startModule=&root=&from=product', $lang->product->setCategory, "class='btn btn-primary'");?>
      </div>
    </div>
    <?php endif;?>
  </div>
  <div class='main-col'>
    <div class='panel main-table' data-ride='table'>
      <table class='table has-sort-head' id='productList'>
        <thead>
          <tr class='text-center'>
            <?php $vars = "mode={$mode}&status={$status}&category={$category}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
            <th class='w-60px'> <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->product->id);?></th>
            <th><?php commonModel::printOrderLink('name', $orderBy, $vars, $lang->product->name);?></th>
            <th class='w-100px'><?php commonModel::printOrderLink('category', $orderBy, $vars, $lang->product->category);?></th>
            <th class='w-100px'><?php commonModel::printOrderLink('code', $orderBy, $vars, $lang->product->code);?></th>
            <th class='w-120px'><?php commonModel::printOrderLink('subject', $orderBy, $vars, $lang->product->subject);?></th>
            <th class='w-70px'><?php commonModel::printOrderLink('model', $orderBy, $vars, $lang->product->model);?></th>
            <th class='w-70px'><?php commonModel::printOrderLink('unit', $orderBy, $vars, $lang->product->unit);?></th>
            <th class='w-70px'><?php commonModel::printOrderLink('amount', $orderBy, $vars, $lang->product->amount);?></th>
            <th class='w-60px'><?php commonModel::printOrderLink('type', $orderBy, $vars, $lang->product->type);?></th>
            <th class='w-70px'> <?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->product->status);?></th>
            <th class='w-80px'><?php echo $lang->actions;?></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($products as $product):?>
          <tr class='text-center' data-url="<?php echo $this->createLink('product', 'view', "productID={$product->id}");?>">
            <td><?php echo $product->id;?></td>
            <td class='text-left'><?php echo $product->name;?></td>
            <td><?php echo zget($categories, $product->category, '');?></td>
            <td><?php echo $product->code;?></td>
            <td><?php echo zget($subjects, $product->subject, '');?></td>
            <td><?php echo zget($lang->product->models, $product->model);?></td>
            <td><?php echo zget($lang->product->units, $product->unit);?></td>
            <td><?php echo $product->amount;?></td>
            <td><?php echo $lang->product->typeList[$product->type];?></td>
            <td><?php echo zget($lang->product->statusList, $product->status);?></td>
            <td class='actions'>
              <?php
              $canEdit   = commonModel::hasPriv('product', 'edit');
              $canField  = commonModel::hasPriv('product', 'adminField');
              $canAction = commonModel::hasPriv('product', 'adminAction');
              $canCopy   = commonModel::hasPriv('product', 'copy');
              $canDelete = commonModel::hasPriv('product', 'delete');

              commonModel::printLink('product', 'edit',        "productID=$product->id", $lang->edit, "data-toggle='modal' data-width='800'");

              if($canField or $canAction or $canCopy or $canDelete)
              {
                  echo "<div class='dropdown'>";
                  echo html::a('javascript:', $lang->more . "<span class='caret'></span>", "data-toggle='dropdown'");
                  echo "<ul class='dropdown-menu pull-right'>";
                  if($canField)  echo '<li>' . html::a(inlink('adminField',  "productID=$product->id"), $lang->product->adminfield) . '</li>';
                  if($canAction) echo '<li>' . html::a(inlink('adminAction', "productID=$product->id"), $lang->product->adminaction) . '</li>';
                  if($canCopy)   echo '<li>' . html::a(inlink('copy',        "productID=$product->id"), $lang->copy, "data-toggle='modal'") . '</li>';
                  if($canDelete) echo '<li>' . html::a(inlink('delete',      "productID=$product->id"), $lang->delete, "class='reloadDeleter'") . '</li>';
                  echo '</ul></div>';
              }
              ?>
            </td>
          </tr>
          <?php endforeach;?>
        </tbody>
      </table>
      <div class='table-footer'><?php $pager->show();?></div>
    </div>
  </div>
</div>
<?php include '../../../common/view/footer.html.php';?>
