<?php
/**
 * The save order record view file of order 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     order
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../../sys/common/view/header.modal.html.php';?>
<?php js::import($jsRoot . 'date.js');?>
<?php js::set('objectType', $objectType);?>
<?php js::set('objectID', $objectID);?>
<?php js::set('history', $history);?>
<form method='post' id='createRecordForm' action='<?php echo inlink('createrecord', "objectType={$objectType}&objectID={$objectID}")?>' class='form'>
  <fieldset class='no-padding-b'>
    <legend><?php echo $lang->action->record->title;?></legend>
    <table class='table table-form'>
      <tr id='widthTR'>
        <th class='w-80px'></th>
        <?php $width = 'w-320px';?>
        <?php if($objectType == 'contract' or $objectType == 'order') $width = 'w-180px';?>
        <?php if($objectType == 'contact')  $width = 'w-240px';?>
        <td class="<?php echo $width;?>"></td>
        <th class='w-60px'></th>
        <td></td>
      </tr>
      <?php if($objectType != 'contact'):?>
      <tr>
        <th><?php echo $lang->action->record->contact;?></th>
        <td>
          <div class='required required-wrapper'></div>
          <div class='input-group'>
            <select id='contact' name='contact' class='form-control chosen'>
              <option></option>
              <?php foreach($contacts as $contact):?>
              <?php
              $phone  = $contact->phone;
              $mobile = $contact->mobile;
              $phone  = empty($phone) ? $mobile : (empty($mobile) ? $phone : $phone . $lang->slash . $mobile);
              $optionPinyin = zget($pinyinContacts, $contact->realname, '');
              ?>
              <option value='<?php echo $contact->id;?>' data-phone='<?php echo $phone;?>' data-qq='<?php echo $contact->qq;?>' data-email='<?php echo $contact->email;?>' data-keys='<?php echo $optionPinyin;?>'><?php echo $contact->realname;?></option>
              <?php endforeach;?>
            </select>
            <?php echo html::input('realname', '', "class='form-control' style='display:none'");?>
            <?php if($objectType == 'customer'):?>
            <?php $style = $isCustomer ? '' : "style='min-width: 60px'";?>
            <span class='input-group-addon' <?php echo $style;?>>
              <?php echo html::checkbox('createContact', array(1 => $lang->action->createContact), '');?>
              <?php if($isCustomer) echo html::checkbox('objectType', array('order' => $lang->action->record->order, 'contract' => $lang->action->record->contract), '');?>
            </span>
            <?php endif;?>
          </div>
        </td>
        <th><?php echo $lang->action->record->date;?></th>
        <td><?php echo html::input('date', date('Y-m-d H:i:s'), "class='form-control form-datetime'");?></td>
      </tr>
      <tr id='phoneTR' class='hide'>
        <th><?php echo $lang->contact->contactInfo;?></th>
        <td id='phoneTD' colspan='3'></td>
      </tr>
      <tr class='new-contact hide'>
        <th>
          <?php echo $lang->contact->position;?>
        </th>
        <td id='titleTD'>
          <?php echo html::input('title', '', "class='title-input form-control'");?>
        </td>
        <th>
          <?php echo $lang->contact->gender;?>
        </th>
        <td>
          <?php unset($lang->genderList['u']); echo html::radio('gender', $lang->genderList, '');?>
        </td>
      </tr>
      <tr class='new-contact hide'>
        <th>
          <?php echo $lang->contact->mobile;?>
        </th>
        <td>
          <?php echo html::input('mobile', '', "class='form-control'");?>
        </td>
        <th>
          <?php echo $lang->contact->email;?>
        </th>
        <td>
          <?php echo html::input('email', '', "class='form-control'");?>
        </td>
      </tr>
      <tr class='new-contact hide'>
        <th>
          <?php echo $lang->contact->weixin;?>
        </th>
        <td>
          <?php echo html::input('weixin', '', "class='form-control'");?>
        </td>
        <th>
          <?php echo $lang->contact->qq;?>
        </th>
        <td>
          <?php echo html::input('qq', '', "class='form-control'");?>
        </td>
      </tr>
      <?php elseif(!empty($customers)):?>
      <tr>
        <th><?php echo $lang->action->record->customer;?></th>
        <td><?php echo html::select('customer', $customers, '', "class='form-control'");?></td>
        <th><?php echo $lang->action->record->date;?></th>
        <td><?php echo html::input('date', date('Y-m-d H:i:s'), "class='form-control form-datetime'");?></td>
      </tr>
      <?php endif;?>
      <?php if($isCustomer):?>
      <tr style='display:none'>
        <th><?php echo $lang->action->record->contract;?></th>
        <td colspan='3'><?php echo html::select('contract', $contracts, '', "class='form-control chosen'");?></td>
      </tr>
      <tr style='display:none'>
        <th><?php echo $lang->action->record->order;?></th>
        <td colspan='3'><?php echo html::select('order', $orders, '', "class='form-control'");?></td>
      </tr>
      <?php endif;?>
      <tr>
        <th><?php echo $lang->action->record->comment;?></th>
        <td colspan='3'>
          <div class='required required-wrapper'></div>
          <?php echo html::textarea('comment', '', "class='form-control' rows='3'");?>
        </td>
      </tr>
      <?php if(commonModel::hasPriv('file', 'upload')):?>
      <tr>
        <th>
          <?php echo $lang->action->record->file;?>
          <span class='text-danger'><?php echo '(' . $config->file->maxSize / 1024 / 1024 . 'M)';?>
        </th>
        <td colspan='3'><?php echo $this->fetch('file', 'buildForm');?></td>
      </tr>
      <?php endif;?>
    </table>
  </fieldset>
  <fieldset class='no-padding-b no-margin-b'>
    <legend><?php echo $lang->action->record->next;?></legend>
    <table class='table table-form table-condensed'>
      <tr>
        <?php $colspan = 2;?>
        <?php if($objectType != 'contact' && $objectType != 'leads'):?>
        <?php $colspan = 3;?>
        <th class='w-80px'><?php echo $lang->action->record->contact;?></th>
        <td class='w-150px'><?php echo html::select('nextContact', array('ditto' => $lang->action->record->sameContact) + $contactPairs, '', "class='form-control chosen'");?></td>
        <?php endif;?>
        <th class='w-80px'><?php echo $lang->action->record->contactedBy;?></th>
        <td class='w-180px'><?php echo html::select('contactedBy', $users, $this->app->user->account, "class='form-control chosen'");?></td>
        <td></td>
        <td class='w-20px'></td>
      </tr>
      <tr>
        <th><?php echo $lang->action->date;?></th>
        <td><?php echo html::input('nextDate', '', "class='form-control form-date'");?></td>
        <td colspan='<?php echo $colspan;?>'><?php echo html::radio('delta', $lang->action->nextContactList , '', "onclick='computeNextDate(this.value)'");?></td>
      </tr>
      <tr class='next-contact-count hide'>
        <th></th>
        <td colspan='<?php echo $colspan + 1;?>'><div class='text-warning'></div></td>
      </tr>
      <tr>
        <th><?php echo $lang->action->record->desc;?></th>
        <td colspan='<?php echo $colspan + 1;?>'><?php echo html::textarea('desc', '', "rows='3' class='form-control'");?></td>
        <td></td>
      </tr>
    </table>
  </fieldset>
  <div class='form-actions text-center space'>
    <?php if($objectType == 'contact') echo html::hidden('contact', $objectID);?>
    <?php if($objectType == 'contact' && empty($customers)) echo html::hidden('date', date(DT_DATETIME1));?>
    <?php echo html::submitButton() . html::hidden('customer', $customer);?>
    <div id='duplicateError' class='hide'></div>
  </div>

  <?php if($history):?>
  <div id='actionBox'></div>
  <?php endif;?>
</form>
<div class='errorMessage hide'>
  <div class='alert alert-danger alert-dismissable'>
    <button aria-hidden='true' data-dismiss='alert' class='close' type='button'>×</button>
    <button type='button' class='btn btn-default' id='continueSubmit'><?php echo $lang->continueSave;?></button>
  </div>
</div>
<?php include '../../../sys/common/view/footer.modal.html.php';?>
