<?php
  /**
   * Products Edit
   *
   * @package Wojo Framework
   * @author wojoscripts.com
   * @copyright 2016
   * @version $Id: _products_edit.tpl.php, v1.00 2016-01-08 10:12:05 gewa Exp $
   */
  if (!defined("_WOJO"))
      die('Direct access to this location is not allowed.');
?>
<div class="row horizontal-gutters align-middle">
  <div class="columns">
    <h2><?php echo Lang::$word->PRD_EDIT;?></h2>
  </div>
  <div class="columns shrink"><a data-action="toggle" data-page="product" 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->row->title;?>" name="title">
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_SLUG;?></label>
        <div class="wojo input">
          <input type="text" placeholder="<?php echo Lang::$word->PRD_SLUG;?>" value="<?php echo $this->row->slug;?>" name="slug">
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_PRICE;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo right labeled input">
          <span class="wojo label"><?php echo Utility::currencySymbol();?></span>
          <input type="text" placeholder="<?php echo Lang::$word->PRD_PRICE;?>" value="<?php echo $this->row->price;?>" name="price">
          <div class="wojo transparent label"><span class="wojo small text"><?php echo App::Core()->currency;?></span></div>
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_SPRICE;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo right labeled input">
          <span class="wojo label"><?php echo Utility::currencySymbol();?></span>
          <input type="text" placeholder="<?php echo Lang::$word->PRD_SPRICE;?>" value="<?php echo $this->row->sprice;?>" name="sprice">
          <div class="wojo transparent label"><span class="wojo small text"><?php echo App::Core()->currency;?></span></div>
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field">
        <label><?php echo Lang::$word->PRD_TYPE;?></label>
        <div class="wojo inline fields">
          <div class="wojo small checkbox radio field">
            <input name="type" type="radio" value="normal" <?php Validator::getChecked($this->row->type, "normal"); ?>>
            <label><?php echo Lang::$word->PRD_DEFAULT;?></label>
          </div>
          <div class="wojo small checkbox radio field">
            <input name="type" type="radio" value="affiliate" <?php Validator::getChecked($this->row->type, "affiliate"); ?>>
            <label><?php echo Lang::$word->PRD_AFFILIATE;?></label>
          </div>
          <div class="wojo small checkbox radio field">
            <input name="type" type="radio" value="cdkey" <?php Validator::getChecked($this->row->type, "cdkey"); ?>>
            <label><?php echo Lang::$word->PRD_CDKEY;?></label>
          </div>
        </div>
      </div>
    </div>
    <div id="affiliate" class="<?php echo ($this->row->type == "affiliate") ? '' : ' hide-all';?>">
      <div class="wojo fields">
        <div class="field">
          <label><?php echo Lang::$word->PRD_AFFURL;?>
            <i class="icon asterisk"></i></label>
          <input type="text" placeholder="<?php echo Lang::$word->PRD_AFFURL;?>" value="<?php echo $this->row->affiliate;?>" name="affiliate">
        </div>
      </div>
    </div>
    <div id="cdkey" class="<?php echo ($this->row->type == "cdkey") ? '' : ' hide-all';?>">
      <div class="wojo fields">
        <div class="field five wide">
          <label><?php echo Lang::$word->PRD_CDKEYS;?>
            <i class="icon asterisk"></i></label>
          <textarea name="cdkeys"><?php echo ($this->cdkeys) ? Utility::toTextArea($this->cdkeys, "cdkey") : null;?></textarea>
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field">
        <div class="wojo primary attached segment">
          <h6 class="wojo secondary text"><?php echo Lang::$word->PRD_MLEVEL;?></h6>
          <div class="wojo divided horizontal list">
            <?php if($this->membership_list):?>
            <?php foreach($this->membership_list as $mrow):?>
            <?php $is_checked = in_array($mrow->id, explode(",", $this->row->membership_id)) ? ' checked="checked"' : null;?>
            <div class="item">
              <div class="content middle aligned">
                <div class="wojo small checkbox">
                  <input type="checkbox" name="memberships[]" value="<?php echo $mrow->id;?>"<?php echo $is_checked;?>>
                  <label><?php echo $mrow->title;?></label>
                </div>
              </div>
            </div>
            <?php endforeach;?>
            <?php endif;?>
          </div>
        </div>
      </div>
    </div>
    <div class="wojo fitted divider"></div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->CATEGORIES;?></label>
        <div class="wojo secondary attached segment">
          <div class="scrollbox_y" style="height:370px;">
            <div class="wojo relaxed divided list">
              <?php echo $this->droplist;?>
            </div>
          </div>
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->FILES;?></label>
        <div class="wojo secondary attached segment">
          <?php if($this->files):?>
          <div class="wojo small icon input" id="filter">
            <input type="text" placeholder="Filter">
            <i class="find icon"></i>
          </div>
          <div class="wojo divider"></div>
          <div class="scrollbox_y" style="height:300px;">
            <div id="fsearch" class="wojo relaxed divided list">
              <?php foreach($this->files as $file):?>
              <?php $is_checked = in_array($file->id, explode(",", $this->row->files)) ? ' checked="checked"' : null;?>
              <?php $is_active = in_array($file->id, explode(",", $this->row->files)) ? ' highlite' : null;?>
              <div class="item<?php echo $is_active;?>">
                <div class="right floated content"><small class="size"><?php echo File::getSize($file->filesize);?> - <?php echo $file->extension;?></small></div>
                <div class="wojo mime basic rounded image" style="background-color:<?php echo Product::fileStyle($file->extension);?>"><?php echo Product::fileIcon($file->extension, "");?></div>
                <div class="content middle aligned">
                  <div class="wojo small checkbox">
                    <input type="checkbox" name="files[]" value="<?php echo $file->id;?>"<?php echo $is_checked;?>>
                    <label><?php echo $file->alias;?></label>
                  </div>
                </div>
              </div>
              <?php endforeach;?>
            </div>
          </div>
          <?php endif;?>
        </div>
      </div>
    </div>
    <a class="wojo left floating tiny icon button" data-trigger="#uImages" data-type="slideDown" data-velocity="true"><i class="icon chevron down"></i></a>
    <div class="hide-all" id="uImages">
      <div class="wojo basic attached segment">
        <h6 class="wojo secondary text"><?php echo Lang::$word->CF_TITLE;?></h6>
        <?php echo $this->custom_fields;?></div>
      <div class="wojo fields">
        <div class="field">
          <h6 class="wojo secondary text"><?php echo Lang::$word->IMAGES;?></h6>
          <label class="input">
            <input type="file" name="images" id="images" data-buttonClass="secondary" data-buttonText="<?php echo Lang::$word->MULTIPLE;?>" data-fields='{"qAction":1, "page":"processImages","id":<?php echo $this->row->id;?>}' class="filefield" multiple>
          </label>
          <div class="wojo boxed segment">
            <div class="scrollbox_y" style="height:300px;">
              <div class="row phone-block-1 mobile-block-2 tablet-block-3 screen-block-4 gutters content-center" id="sortable">
                <?php if($this->images):?>
                <?php foreach ($this->images as $i => $irow):?>
                <div class="column" id="item_<?php echo $irow->id;?>" data-id="<?php echo $irow->id;?>">
                  <div class="wojo basic attached segment"><img src="<?php echo Product::hasThumb($irow->name, $this->row->id);?>" alt="" class="wojo boxed image">
                    <a data-set='{"option":[{"delete":"deleteImage", "id":<?php echo $irow->id;?>}], "parent":"#item_<?php echo $irow->id;?>", "url":"/controller.php", "complete":"remove"}' class="wojo top right small basic icon attached label qAction"><i class="icon trash negative"></i></a>
                  </div>
                </div>
                <?php endforeach;?>
                <?php endif;?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_EXPIRY;?>
          <i class="icon asterisk"></i></label>
        <div class="wojo action input">
          <input type="text" placeholder="<?php echo Lang::$word->PRD_EXPIRY;?>" value="<?php echo (substr_count($this->row->expiry,'D') == 1) ? substr($this->row->expiry, 1) : $this->row->expiry;?>" name="expiry">
          <select name="expiry_type" class="wojo dropdown">
            <option value="days"<?php echo (substr_count($this->row->expiry,'D') == 1) ? ' selected="selected"' : null;?>><?php echo Lang::$word->PRD_EXP_DAYS;?></option>
            <option value="downloads"<?php echo (substr_count($this->row->expiry,'D') == 1) ? null : ' selected="selected"';?>><?php echo Lang::$word->PRD_EXP_DOWN;?></option>
          </select>
        </div>
      </div>
      <div class="field five wide">
        <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->row->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->row->active, 0); ?>>
            <label><?php echo Lang::$word->NO;?></label>
          </div>
        </div>
      </div>
    </div>
    <div class="wojo fitted divider"></div>
    <div class="wojo fields">
      <div class="field">
        <label><?php echo Lang::$word->PRD_BODY;?></label>
        <textarea class="bodypost" name="body"><?php echo Url::out_url($this->row->body);?></textarea>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field">
        <label><?php echo Lang::$word->PRD_PBODY;?></label>
        <textarea class="bodypost" name="pbody"><?php echo Url::out_url($this->row->pbody);?></textarea>
      </div>
    </div>
    <div class="wojo fitted divider"></div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_IMG;?></label>
        <input type="file" data-buttonText="<?php echo Lang::$word->BROWSE;?>" name="thumb" id="thumb" class="filefield">
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_IMG;?></label>
        <img src="<?php echo Product::hasThumb($this->row->thumb, $this->row->id);?>" alt="" class="wojo small basic image">
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_AUDIO;?></label>
        <input type="file" data-buttonText="<?php echo Lang::$word->BROWSE;?>" name="audio" id="audio" class="filefield">
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_AUDIO;?></label>
        <?php if($this->row->audio):?>
        <audio controls>
          <source src="<?php echo UPLOADURL;?>/data/<?php echo $this->row->id;?>/<?php echo $this->row->audio;?>">
        </audio>
        <?php endif;?>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_YTUBE;?></label>
        <div class="wojo left icon input">
          <i class="icon youtube alt"></i>
          <input type="text" placeholder="<?php echo Lang::$word->PRD_YTUBE;?>" value="<?php echo $this->row->youtube;?>" name="youtube">
        </div>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->PRD_TAGS;?></label>
        <div class="wojo left icon input">
          <i class="icon tags"></i>
          <input type="text" placeholder="<?php echo Lang::$word->PRD_TAGS;?>" value="<?php echo $this->row->tags;?>" name="tags">
        </div>
      </div>
    </div>
    <div class="wojo fields">
      <div class="field five wide">
        <label><?php echo Lang::$word->METAKEYS;?></label>
        <textarea class="small" placeholder="<?php echo Lang::$word->METAKEYS;?>" name="keywords"><?php echo $this->row->keywords;?></textarea>
      </div>
      <div class="field five wide">
        <label><?php echo Lang::$word->METADESC;?></label>
        <textarea class="small" placeholder="<?php echo Lang::$word->METADESC;?>" name="description"><?php echo $this->row->description;?></textarea>
      </div>
    </div>
  </div>
  <div class="content-center">
    <a href="<?php echo Url::url("/admin/products");?>" class="wojo small basic button"><?php echo Lang::$word->CANCEL;?></a>
    <button type="button" data-action="processItem" name="dosubmit" class="wojo primary button"><?php echo Lang::$word->PRD_UPDATE;?></button>
  </div>
  <input type="hidden" name="id" value="<?php echo $this->row->id;?>">
</form>

<?php 
//$cdkeys = Db::run()->select(Product::cdTable, array("cdkey"), array("product_id" => 12))->results();

	
	//Debug::pre(Utility::toTextArea ($cdkeys, "cdkey"));
	
	?>
