<?php
/**
 * The create view of todo 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      Chunsheng Wang <chunsheng@cnezsoft.com>
 * @package     todo
 * @version     $Id: edit.html.php 4728 2013-05-03 06:14:34Z chencongzhi520@gmail.com $
 * @link        http://www.zdoo.com
 */
?>
<?php if(helper::isAjaxRequest()):?>
<?php include '../../../sys/common/view/header.modal.html.php';?>
<?php else:?>
<?php include '../../../sys/my/view/header.html.php';?>
<?php endif;?>
<?php include '../../common/view/datepicker.html.php';?>
<?php include '../../common/view/editor.html.php';?>
<?php js::set('moduleList', $config->todo->moduleList)?>
<?php js::set('objectsMethod', $config->todo->getUserObjectsMethod)?>
<?php js::set('idvalue', $todo->idvalue);?>
<?php js::set('defaultType', $todo->type);?>
<?php js::set('nameBoxLabel', array('custom' => $lang->todo->name, 'idvalue' => $lang->todo->idvalue));?>
<form method='post' id='ajaxForm' action='<?php echo inlink('edit', 'id=' . $todo->id);?>'>
  <table class='table table-form'>
    <tr>
      <th class="w-80px"><?php echo $lang->todo->date;?></th>
      <td colspan='3'>
        <div class='input-group has-icon-right'>
          <?php $disabled = $todo->date == '00000000' || $todo->cycle == '1' ? "disabled='disabled'" : ''?>
          <?php echo html::input('date', $todo->date == '00000000' ? '' : $todo->date, "class='form-control form-date date-picker-down' $disabled");?>
          <?php if(!$todo->cycle):?>
          <span class='input-group-addon'><label class='checkbox-inline'><input type='checkbox' <?php echo $todo->date == '00000000' ? 'checked' : ''?> id='switchDate'> <?php echo $lang->todo->periods['future'];?></label></span>
          <?php endif;?>
        </div>
      </td>
    </tr>
    <?php if($todo->cycle):?>
    <?php $todo->config = json_decode($todo->config);?>
    <tr>
      <th><?php echo $lang->todo->cycleConfig;?></th>
      <td colspan='3'>
        <ul class="nav nav-tabs">
          <li <?php if($todo->config->type == 'day')   echo "class='active'"?>><a class='config-type' data-tab data-type='day' href="#day"><?php echo $lang->todo->cycleDay;?></a></li>
          <li <?php if($todo->config->type == 'week')  echo "class='active'"?>><a class='config-type' data-tab data-type='week' href="#week"><?php echo $lang->todo->cycleWeek;?></a></li>
          <li <?php if($todo->config->type == 'month') echo "class='active'"?>><a class='config-type' data-tab data-type='month' href="#month"><?php echo $lang->todo->cycleMonth;?></a></li>
        </ul>
        <div class="tab-content">
          <div class="tab-pane <?php if($todo->config->type == 'day') echo 'active'?>" id="day">
            <div>
              <?php echo html::radio('config[dayType]', $this->lang->todo->dayTypeList, isset($todo->config->specifiedDate) ? 'specified' : 'every', "class='config-dayType' onchange='changeDayType(this)'");?>
            </div>
            <div class='input-group every w-310px'>
              <span class='input-group-addon'><?php echo $lang->todo->every;?></span>
              <?php echo html::input('config[day]', isset($todo->config->day) ? $todo->config->day : '', "class='form-control' id='everyInput'")?>
              <span class='input-group-addon'><?php echo $lang->todo->cycleDay;?></span>
              <span class='input-group-addon'>
                <div class='checkbox-primary w-100px'>
                  <input type='checkbox' name='config[skipNoWork]' id='skipNoWork' value='1' <?php if(isset($todo->config->skipNoWork) && $todo->config->skipNoWork == 1) echo 'checked';?> />
                  <label for='config[skipNoWork]'><?php echo $this->lang->todo->skipNoWork;?></label>
                </div>
              </span>
            </div>
            <div class='input-group specify hidden'>
              <span class='input-group-addon'><?php echo $lang->todo->specify;?></span>
              <?php echo html::select('config[specify][month]', $lang->datepicker->monthNames, isset($todo->config->specify->month) ? $todo->config->specify->month : 0, "class='form-control w-80px' onchange='setDays(this.value);'");?>
              <?php echo html::select('config[specify][day]', $lang->todo->specifiedDay, isset($todo->config->specify->day) ? $todo->config->specify->day : 1, "class='form-control w-60px' id='specifiedDay'");?>
              <span class='input-group-addon'><?php echo $lang->todo->day;?></span>
              <span class='input-group-addon'>
                <div class='checkbox-primary w-50px'>
                <input type='checkbox' name='config[cycleYear]' id='cycleYear' value='1' <?php if(isset($todo->config->cycleYear)) echo 'checked';?> />
                  <label for='config[cycleYear]'><?php echo $lang->todo->everyYear;?></label>
                </div>
              </span>
            </div>
          </div>
          <div class="tab-pane <?php if($todo->config->type == 'week') echo 'active'?>" id="week">
            <?php echo html::checkbox('config[week]', $lang->todo->dayNames, isset($todo->config->week) ? $todo->config->week : '')?>
          </div>
          <div class="tab-pane <?php if($todo->config->type == 'month') echo 'active'?>" id="month">
            <?php
            $days = array();
            for($i = 1; $i <= 10; $i ++) $days[$i] = $i;
            echo "<p class='box1-10'>" . html::checkbox('config[month]', $days, isset($todo->config->month) ? $todo->config->month : '') . '</p>';
            $days = array();
            for($i = 11; $i <= 20; $i ++) $days[$i] = $i;
            echo "<p class='box11-20'>" . html::checkbox('config[month]', $days, isset($todo->config->month) ? $todo->config->month : '') . '</p>';
            $days = array();
            for($i = 21; $i <= 31; $i ++) $days[$i] = $i;
            echo "<p class='box21-31'>" . html::checkbox('config[month]', $days, isset($todo->config->month) ? $todo->config->month : '') . '</p>';
            ?>
          </div>
        </div>
        <?php echo html::hidden('config[type]', $todo->config->type, "id='configType'")?>
        <div class='input-group' style='width:250px; padding-top:5px;'>
        <?php printf($lang->todo->beforeDays, html::input('config[beforeDays]', $todo->config->beforeDays, "class='form-control'"));?>
        </div>
      </td>
    </tr>
    <tr>
      <th><?php echo $lang->todo->deadline;?></th>
      <td colspan='3'>
        <?php echo html::input("config[end]", $todo->config->end, "class='form-control form-date'");?>
      </td>
    </tr>
    <?php endif;?>
    <tr>
      <th><?php echo $lang->todo->type;?></th>
      <td colspan='3'>
        <?php echo $lang->todo->typeList[$todo->type];?>
      </td>
    </tr>
    <tr>
      <th><?php echo $lang->todo->pri;?></th>
      <td colspan='3'>
        <?php echo html::select('pri', $lang->todo->priList, $todo->pri, "class='form-control'");?>
      </td>
    </tr>
    <tr>
      <th id='nameBoxLabel'><?php echo $lang->todo->name;?></th>
      <td colspan='3'>
        <?php $readType = in_array($todo->type, array('custom', 'cycle')) ? '' : 'readonly';?>
        <?php echo html::input('name', $todo->name, "class='form-control' $readType");?>
      </td>
    </tr>
    <tr>
      <th><?php echo $lang->todo->desc;?></th>
      <td colspan='3'>
        <?php echo html::textarea('desc', $todo->desc, "rows='8' class='form-control'");?>
      </td>
    </tr>
    <tr>
      <th><?php echo $lang->todo->status;?></th>
      <td colspan='3'>
        <?php echo html::select('status', $lang->todo->statusList, $todo->status, "class='form-control'");?>
      </td>
    </tr>
    <tr>
      <th><?php echo $lang->todo->beginAndEnd;?></th>
      <td>
        <?php echo html::select('begin', $times, $todo->begin, 'onchange=selectNext(); class="form-control" data-drop_direction="up"')?>
      </td>
      <td>
        <?php echo html::select('end', $times, $todo->end, 'class="form-control" data-drop_direction="up"');?>
      </td>
      <td>
        <div class='checkbox-primary dateSwitcher'>
          <input type='checkbox' id='dateSwitcher' onclick='switchDateFeature(this);' <?php if($todo->begin == 2400) echo 'checked';?> >
          <label for='dateSwitcher'><?php echo $lang->todo->lblDisableDate;?></label>
        </div>
      </td>
    </tr>
    <tr>
      <th></th>
      <td colspan='3'>
        <div class='checkbox-primary'>
          <input type='checkbox' name='private' id='private' value='1' <?php if($todo->private) echo 'checked';?> />
          <label for='private'><?php echo $lang->todo->private;?></label>
        </div>
      </td>
    </tr>
    <tr>
      <th></th>
      <td colspan='3'>
        <?php echo html::submitButton();?>
      </td>
    </tr>
  </table>
</form>
<script>switchDateFeature(document.getElementById('dateSwitcher'));</script>
<?php if(helper::isAjaxRequest()):?>
<?php include '../../../sys/common/view/footer.modal.html.php';?>
<?php else:?>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
<?php endif;?>
