<?php
  /**
   * Page Manager
   *
   * @package Wojo Framework
   * @author wojoscripts.com
   * @copyright 2017
   * @version $Id: faq.tpl.php, v1.00 2017-05-08 10:12:05 gewa Exp $
   */
  if (!defined("_WOJO"))
      die('Direct access to this location is not allowed.');
	  
  if(!Auth::hasPrivileges('manage_faq')): print Message::msgError(Lang::$word->NOACCESS); return; endif;
?>
<?php switch(Url::segment($this->segments)): case "edit": ?>
<!-- Start edit -->
<h2><?php echo Lang::$word->FAQ_EDIT;?></h2>
<form method="post" id="wojo_form" name="wojo_form">
  <div class="wojo segment form">
    <div class="wojo fields align-middle">
      <div class="field four wide labeled">
        <label class="content-right mobile-content-left"><?php echo Lang::$word->FAQ_QUESTION;?>
          <i class="icon asterisk"></i></label>
      </div>
      <div class="field">
        <input type="text" placeholder="<?php echo Lang::$word->FAQ_QUESTION;?>" name="question" value="<?php echo $this->data->question;?>">
      </div>
    </div>
    <div class="wojo fields align-middle">
      <div class="field four wide labeled">
        <label class="content-right mobile-content-left"><?php echo Lang::$word->FAQ_ANSWER;?>
          <i class="icon asterisk"></i></label>
      </div>
      <div class="field">
        <textarea name="answer" placeholder="<?php echo Lang::$word->FAQ_ANSWER;?>"><?php echo $this->data->answer;?></textarea>
      </div>
    </div>
  </div>
  <div class="content-center">
    <a href="<?php echo Url::url("/admin/faq");?>" class="wojo basic small button"><?php echo Lang::$word->CANCEL;?></a>
    <button type="button" data-action="processFaq" name="dosubmit" class="wojo primary button"><?php echo Lang::$word->FAQ_UPDATE;?></button>
  </div>
  <input type="hidden" name="id" value="<?php echo $this->data->id;?>">
</form>
<?php break;?>
<?php case "new": ?>
<!-- Start new -->
<div class="row horizontal-gutters align-middle">
  <div class="columns">
    <h2><?php echo Lang::$word->PAG_NEW;?></h2>
  </div>
  <div class="columns shrink"><a data-action="toggle" data-page="page" 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 align-middle">
      <div class="field four wide labeled">
        <label class="content-right mobile-content-left"><?php echo Lang::$word->FAQ_QUESTION;?>
          <i class="icon asterisk"></i></label>
      </div>
      <div class="field">
        <input type="text" placeholder="<?php echo Lang::$word->FAQ_QUESTION;?>" name="question">
      </div>
    </div>
    <div class="wojo fields align-middle">
      <div class="field four wide labeled">
        <label class="content-right mobile-content-left"><?php echo Lang::$word->FAQ_ANSWER;?>
          <i class="icon asterisk"></i></label>
      </div>
      <div class="field">
        <textarea name="answer" placeholder="<?php echo Lang::$word->FAQ_ANSWER;?>"></textarea>
      </div>
    </div>
  </div>
  <div class="content-center">
    <a href="<?php echo Url::url("/admin/faq");?>" class="wojo basic small button"><?php echo Lang::$word->CANCEL;?></a>
    <button type="button" data-action="processFaq" name="dosubmit" class="wojo primary button"><?php echo Lang::$word->FAQ_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_FAQ;?></h2>
    <p class="wojo small text">
      <?php echo Lang::$word->FAQ_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->FAQ_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->FAQ_EMPTY;?></p>
</div>
<?php else:?>
<div class="wojo space divider"></div>
<div class="masonry" id="sortable">
  <?php foreach ($this->data as $row):?>
  <div class="item" id="item_<?php echo $row->id;?>" data-id="<?php echo $row->id;?>">
    <div class="wojo soft shadow attached card">
      <div class="header">
        <h4 class="wojo truncate">
          <?php echo $row->question;?>
        </h4>
      </div>
      <div class="content wojo small text"><?php echo Validator::truncate($row->answer, 100);?></div>
      <div class="footer actions">
        <div class="items">
          <a href="<?php echo Url::url(Router::$path, "edit/" . $row->id);?>" class="positive">
            <i class="icon note"></i>
            <?php echo Lang::$word->EDIT;?></a>
        </div>
        <div class="items">
          <a data-set='{"option":[{"trash": "trashFaq","title": "<?php echo Validator::sanitize($row->question, "spchar");?>","id": "<?php echo $row->id;?>"}],"action":"trash","subtext":"<?php echo Lang::$word->DELCONFIRM3;?>","parent":"#item_<?php echo $row->id;?>"}' class="action"><i class="icon trash"></i>
            <?php echo Lang::$word->TRASH;?></a>
        </div>
      </div>
    </div>
  </div>
  <?php endforeach;?>
</div>
<script src="<?php echo SITEURL;?>/assets/sortable.js"></script>
<script type="text/javascript"> 
// <![CDATA[
$(document).ready(function() {
    $("#sortable").sortables({
        ghostClass: "ghost",
        //handle: ".label",
        animation: 600,
        onUpdate: function(e) {
            var order = this.toArray();
            $.ajax({
                type: 'post',
                url: "<?php echo ADMINVIEW . '/helper.php';?>",
                dataType: 'json',
                data: {
					qAction: 1,
                    page: "sortFaq",
                    sortlist: order
                }
            });
        }
    });
});
// ]]>
</script>
<?php endif;?>
<?php break;?>
<?php endswitch;?>