<?php
/**
 * The operate view file of flow module of ZDOO.
 *
 * @copyright   Copyright 2009-2016 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     商业软件，非开源软件
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     flow 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php
if($editor)
{
    $webRoot      = $config->webRoot;
    $jsRoot       = $webRoot . "js/";
    $themeRoot    = $webRoot . "theme/";
    include '../../../sys/common/view/kindeditor.html.php';
}
?>
<style>
.preview-content td.child > .table tr > td {padding-left: 0px;}
</style>
<div class='preview-content'>
  <table class='table table-form'>
    <?php $hasChildFields = false;?>
    <?php foreach($fields as $field):?>
    <?php if(!$field->show) continue;?>
    <?php $readonly = $field->readonly;?>
    <?php $value    = ($field->readonly or $action->action == 'browse' or $action->action == 'view') ? $lang->workflowaction->previewData : $field->defaultValue;?>
  
    <?php /* Print files. */ ?>
    <?php if($field->field == 'file'):?>
    <tr>
      <th class='w-100px'><?php echo $lang->files;?></th>
      <td>
        <?php if($readonly) echo $this->fetch('file', 'printFiles', array('files' => $data->files, 'fieldset' => 'false'));?>
        <?php if(!$readonly) echo $this->fetch('file', 'buildForm');?>
      </td>
      <td class='w-160px'></td>
    </tr>
  
    <?php /* Print sub tables. */ ?>
    <?php elseif(isset($childFields[$field->field])):?>
    <?php $hasChildFields = true;?>
    <tr>
      <th><?php echo $field->name;?></th>
      <td colspan='2' class='child'>
        <table class='table table-form table-child' data-child='<?php echo $field->field;?>'>
          <?php for($i = 0; $i < 3; $i++):?>
          <tr>
            <?php foreach($childFields[$field->field] as $childField):?>
            <?php $childValue = ($childField->readonly or $action->action == 'browse' or $action->action == 'view') ? $lang->workflowaction->previewData : $childField->defaultValue;?>
            <?php if(!$childField->show) continue;?>
            <?php if($childField->field == 'file') continue;?>
            <td>
              <?php
              if(!$readonly && !$childField->readonly)
              {
                  echo $this->flow->buildControl($childField, $childValue, "preview_{$field->field}", $field->field, false, true);
              }
              ?>
            </td>
            <?php endforeach;?>
            <?php if(!$readonly):?>
            <td class='w-100px'>
              <a href='javascript:;' class='btn btn-default addItem'><i class='icon-plus'></i></a>
              <a href='javascript:;' class='btn btn-default delItem'><i class='icon-remove'></i></a>
            </td>
            <?php endif;?>
            <td></td>
          </tr>
          <?php endfor;?>
        </table>
      </td>
    </tr>
    
    <?php /* Print other fields. */ ?>
    <?php else:?>
    <tr>
      <th class='w-100px'><?php echo $field->name;?></th>
      <td>
        <?php if(!$readonly) echo $this->flow->buildControl($field, $value, "preview_{$field->field}", '', false, true);?>
      </td>
      <td class='w-160px'></td>
    </tr>
    <?php endif;?>
  
    <?php endforeach;?>
    <tr>
      <th class='w-100px'><?php echo $lang->workflowaction->toList;?></th>
      <td>
        <div class='input-group'>
          <?php echo html::select('toList[]', $users, $action->toList, "class='form-control chosen' data-placeholder='{$lang->chooseUserToMail}' multiple");?>
          <?php echo $this->fetch('usercontact', 'buildContactList');?>
        </div>
      </td>
      <td class='text-important w-160px'><?php echo $lang->flow->tips->notice;?></td>
    </tr>
    <tr>
      <th></th>
      <td colspan='2' class='form-actions'>
        <?php echo html::submitButton();?>
        <?php echo html::commonButton($lang->goback);?>
      </td>
    </tr>
  </table>
</div>
<script>
$('.preview-content a').attr('href', 'javascript:;').removeAttr('onclick');
</script>
