<?php
  /**
   * Coupons
   *
   * @package Wojo Framework
   * @author wojoscripts.com
   * @copyright 2017
   * @version $Id: coupons.tpl.php, v1.00 2017-02-05 10:12:05 gewa Exp $
   */
  if (!defined("_WOJO"))
      die('Direct access to this location is not allowed.');
	  
  if(!Auth::hasPrivileges('manage_coupons')): print Message::msgError(Lang::$word->NOACCESS); return; endif;
?>
<?php switch(Url::segment($this->segments)): case "edit": ?>
<!-- Start edit -->
<div class="row horizontal-gutters align-middle">
  <div class="columns">
    <h2><?php echo Lang::$word->DC_EDIT;?></h2>
  </div>
  <div class="columns shrink"><a data-action="toggle" data-page="coupon" class="wojo small primary icon label sAction"><i class="icon question sign"></i></a>
  </div>
</div>
<form method="post" id="wojo_form" name="wojo_form">
  <div class="wojo segment form">
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->NAME;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo input">
          <input type="text" placeholder="<?php echo Lang::$word->NAME;?>" value="<?php echo $this->data->title;?>" name="title">
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_CODE;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo input">
          <input type="text" placeholder="<?php echo Lang::$word->DC_CODE;?>" value="<?php echo $this->data->code;?>" name="code">
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_VALID;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo fluid calendar left icon input" data-datepicker="true">
          <input name="validuntil" type="text" placeholder="<?php echo Lang::$word->TO;?>" value="<?php echo $this->data->validuntil;?>">
          <i class="icon date"></i>
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_DISC;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo action input">
          <input type="text" placeholder="<?php echo Lang::$word->DC_DISC;?>" value="<?php echo $this->data->discount;?>" name="discount">
          <select class="wojo selection dropdown" name="type">
            <option value="p"<?php if($this->data->type == "p") echo ' selected="selected"';?>><?php echo Lang::$word->DC_TYPE_P;?></option>
            <option value="a"<?php if($this->data->type == "a") echo ' selected="selected"';?>><?php echo Lang::$word->DC_TYPE_A;?></option>
          </select>
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_MIN;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo left right labeled input">
          <div class="wojo label"><?php echo Utility::currencySymbol(App::Core()->currency);?></div>
          <input type="text" placeholder="<?php echo Lang::$word->DC_MIN;?>" value="<?php echo $this->data->minval;?>" name="minval">
          <div class="wojo label">
            <?php echo App::Core()->currency;?>
          </div>
        </div>
      </div>
      <div class="field">
        <label><?php echo Lang::$word->PUBLISHED;?></label>
        <div class="wojo inline fields">
          <div class="wojo checkbox radio field">
            <input name="active" type="radio" value="1" <?php Validator::getChecked($this->data->active, 1); ?>>
            <label><?php echo Lang::$word->YES;?></label>
          </div>
          <div class="wojo checkbox radio field">
            <input name="active" type="radio" value="0" <?php Validator::getChecked($this->data->active, 0); ?>>
            <label><?php echo Lang::$word->NO;?></label>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="content-center">
    <a href="<?php echo Url::url("/admin/coupons");?>" class="wojo basic small button"><?php echo Lang::$word->CANCEL;?></a>
    <button type="button" data-action="processCoupon" name="dosubmit" class="wojo primary button"><?php echo Lang::$word->DC_UPDATE;?></button>
  </div>
  <input type="hidden" name="id" value="<?php echo $this->data->id;?>">
</form>
<?php break;?>
<?php case "new": ?>
<!-- Start new -->
<h2><?php echo Lang::$word->DC_NEW;?></h2>
<form method="post" id="wojo_form" name="wojo_form">
  <div class="wojo segment form">
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->NAME;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo input">
          <input type="text" placeholder="<?php echo Lang::$word->NAME;?>" name="title">
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_CODE;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo input">
          <input type="text" placeholder="<?php echo Lang::$word->DC_CODE;?>" name="code">
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_VALID;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo fluid calendar left icon input" data-datepicker="true">
          <input name="validuntil" type="text" placeholder="<?php echo Lang::$word->TO;?>" value="<?php echo Date::NumberOfDays('+1 month');?>">
          <i class="icon date"></i>
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_DISC;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo action input">
          <input type="text" placeholder="<?php echo Lang::$word->DC_DISC;?>" name="discount">
          <select class="wojo selection dropdown" name="type">
            <option value="p"><?php echo Lang::$word->DC_TYPE_P;?></option>
            <option value="a"><?php echo Lang::$word->DC_TYPE_A;?></option>
          </select>
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->DC_MIN;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo left right labeled input">
          <div class="wojo label"><?php echo Utility::currencySymbol(App::Core()->currency);?></div>
          <input type="text" placeholder="<?php echo Lang::$word->DC_MIN;?>" name="minval">
          <div class="wojo label">
            <?php echo App::Core()->currency;?>
          </div>
        </div>
      </div>
      <div class="field">
        <label><?php echo Lang::$word->PUBLISHED;?></label>
        <div class="wojo inline fields">
          <div class="wojo checkbox radio field">
            <input name="active" type="radio" value="1" checked="checked">
            <label><?php echo Lang::$word->YES;?></label>
          </div>
          <div class="wojo checkbox radio field">
            <input name="active" type="radio" value="0">
            <label><?php echo Lang::$word->NO;?></label>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="content-center">
    <a href="<?php echo Url::url("/admin/coupons");?>" class="wojo button"><?php echo Lang::$word->CANCEL;?></a>
    <button type="button" data-action="processCoupon" name="dosubmit" class="wojo primary button"><?php echo Lang::$word->DC_CREATE;?></button>
  </div>
</form>
<?php break;?>
<?php default: ?>
<div class="row half-gutters align-middle">
  <div class="column mobile-100 phone-100">
    <h2><?php echo Lang::$word->META_M_COUPONS;?></h2>
    <p class="wojo small text"><?php echo Lang::$word->DC_INFO;?></p>
  </div>
  <div class="column shrink mobile-100 phone-100">
    <a href="<?php echo Url::url(Router::$path, "new/");?>" class="wojo small primary basic rounded button"><i class="icon plus alt"></i><?php echo Lang::$word->DC_NEW;?></a>
  </div>
</div>
<?php if(!$this->data):?>
<div class="content-center"><img src="<?php echo ADMINVIEW;?>/images/notfound.png" alt="">
  <p class="wojo small thick caps text"><?php echo Lang::$word->DC_EMPTY;?></p>
</div>
<?php else:?>
<div class="wojo space divider"></div>
<div class="row screen-block-3 tablet-block-2 mobile-block-1 phone-block-1 gutters align-center">
  <?php foreach ($this->data as $row):?>
  <div class="column" id="item_<?php echo $row->id;?>">
    <div class="wojo card">
      <div class="content<?php if($row->active == 0):?> dimmable dimmed<?php endif;?>" id="cpn_<?php echo $row->id;?>"><a href="<?php echo Url::url(Router::$path, "edit/" . $row->id);?>"><img src="<?php echo ADMINVIEW;?>/images/coupon.svg" alt=""></a>
        <h4 class="content-center"><?php echo $row->title;?></h4>
        <?php if($row->active == 0):?>
        <div class="wojo dimmer inverted transition visible active"></div>
        <?php endif;?>
      </div>
      <div class="footer actions">
        <div class="items">
          <a data-set='{"option":[{"trash": "trashCoupon","title": "<?php echo Validator::sanitize($row->title, "spchar");?>","id":<?php echo $row->id;?>}],"action":"trash","parent":"#item_<?php echo $row->id;?>"}' class="wojo icon basic negative tiny button action">
            <i class="icon trash"></i>
          </a>
        </div>
        <div class="items">
          <div class="wojo small checkbox slider is_dimmable" data-set='{"option":[{"quickStatus": 1,"id":<?php echo $row->id;?>,"action":"coupon"}],"parent":"#cpn_<?php echo $row->id;?>"}' >
            <input name="active" type="checkbox" value="1" <?php Validator::getChecked($row->active, 1); ?>>
            <label><?php echo Lang::$word->ACTIVE;?></label>
          </div>
        </div>
      </div>
    </div>
  </div>
  <?php endforeach;?>
</div>
<?php endif;?>
<?php break;?>
<?php endswitch;?>