<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>

<?php echo $this->partial('_admin_breadcrumb.tpl', 'core', array('parentMenu' => "core_admin_main_manage", 'parentMenuItemName' => 'core_admin_main_manage_tickets', 'lastMenuItemName' => 'Categories')); ?>

<?php if( engine_count($this->navigation) ): ?>
  <div class='tabs'>
    <?php echo $this->navigation()->menu()->setContainer($this->navigation)->render(); ?>
  </div>
<?php endif; ?>

<?php $this->headScript()->appendFile($this->layout()->staticBaseUrl . 'application/modules/Core/externals/scripts/admin/categories.js'); ?>
<script type="application/javascript">
  ajaxurl = en4.core.baseUrl+"admin/core/support/change-order";
</script>

<div class='admin-categories-form'>
  <div>
    <div class="admin-form-cont">
      <h3><?php echo $this->translate("Ticket Categories") ?> </h3>
      <p class="description"><?php echo $this->translate("If you want to allow your users to categorize their tickets, create the categories below. This feature is useful if you want to list all your users' tickets by category. If you have no categories, your users will not be given the option of assigning a category."); ?></p>
      <div class="admin-categories-add-form">
        <h4 class="bold"><?php echo $this->translate("Add New Category"); ?></h4>
        <form id="addcategory" method="post" enctype="multipart/form-data">
          <div class="admin-form-field" id="name-required">
            <div class="admin-form-field-label">
              <label for="tag-name"><?php echo $this->translate("Category Name"); ?></label>
            </div>
            <div class="admin-form-field-element">
              <input name="category_name" autocomplete="off" id="tag-name" type="text"  size="40" >
            </div>
          </div>
          <div class="admin-form-field">
            <div class="admin-form-field-label">
              <label for="parent"><?php echo $this->translate("Parent Category"); ?></label>
            </div>
            <div class="admin-form-field-element">
              <select name="parent" id="parent" class="postform">
                <option value="-1"><?php echo $this->translate("None"); ?></option>
                <?php foreach ($this->categories as $category): ?>
                  <?php if($category->category_id == 0) : ?>
                  <?php continue; ?>
                  <?php endif; ?>
                    <option class="level-0" value="<?php echo $category->category_id; ?>"><?php echo $category->category_name; ?></option>
                  <?php 
                    $subcategory = Engine_Api::_()->getDbtable('categories', 'core')->getSubcategory(array('column_name' => "*", 'category_id' => $category->category_id, 'type' => 'tickets'));
                    foreach ($subcategory as $subCategory):  
                  ?>
                  <option class="level-1" value="<?php echo $subCategory->category_id; ?>">&nbsp;&nbsp;&nbsp;<?php echo $subCategory->category_name; ?></option>
                <?php 
                  endforeach;
                  endforeach; 
                ?>
              </select>
            </div>
          </div>
          <div class="submit admin-form-field">
            <button type="button" id="submitaddcategory" class="upload_image_button button"><?php echo $this->translate("Add New Category"); ?></button>
          </div>
        </form>
        <div class="admin-categories-add-form-overlay" id="add-category-overlay" style="display:none"></div>
      </div>
      <div class="admin-categories-listing">
      	<div id="error-message-category-delete"></div>
        <form id="multimodify_form" method="post" onsubmit="return multiModify();">
          <table class='admin_table admin_table_order' style="width: 100%;">
            <thead>
              <tr>
                <th><input type="checkbox" onclick="selectAll()"  name="checkbox" /></th>
                <th><?php echo $this->translate("Category Name") ?></th>
                <th><?php echo $this->translate("Options") ?></th>
              </tr>
            </thead>
            <tbody>
              <?php foreach ($this->categories as $category): ?>
              <?php if($category->category_id == 0) : ?>
                <?php continue; ?>
              <?php endif; ?>
              <tr id="categoryid-<?php echo $category->category_id; ?>" data-id="<?php echo $category->category_id; ?>">
                <td><input type="checkbox" class="checkbox check-column" name="delete_tag[]" value="<?php echo $category->category_id; ?>" /></td>
                <td><?php echo $category->category_name ?>
                  <div class="hidden" style="display:none" id="inline_<?php echo $category->category_id; ?>">
                    <div class="parent">0</div>
                  </div>
                </td>
                <td>
                  <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'support', 'action' => 'edit-category', 'id' => $category->category_id, 'type' => $category->type), $this->translate('Edit'), array('class' => 'smoothbox')) ?> | <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Delete'), array('class' => 'deleteCat','data-url'=>$category->category_id)); ?>
                </td>
              </tr>
              <?php //Subcategory Work
                $subcategory = Engine_Api::_()->getDbtable('categories', 'core')->getSubcategory(array('column_name' => "*", 'category_id' => $category->category_id, 'type' => 'tickets'));
                foreach ($subcategory as $subCategory):  ?>
                  <tr id="categoryid-<?php echo $subCategory->category_id; ?>" data-id="<?php echo $subCategory->category_id; ?>">
                    <td><input type="checkbox"  class="checkbox check-column" name="delete_tag[]" value="<?php echo $subCategory->category_id; ?>" /></td>
                    <td>-&nbsp;<?php echo $subCategory->category_name ?>
                      <div class="hidden" style="display:none" id="inline_<?php echo $subCategory->category_id; ?>">
                        <div class="parent"><?php echo $subCategory->subcat_id; ?></div>
                      </div>
                    </td>
                    <td>
                      <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'support', 'action' => 'edit-category', 'id' => $subCategory->category_id, 'type' => $subCategory->type), $this->translate('Edit'), array('class' => 'smoothbox')) ?> | <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Delete'), array('class' => 'deleteCat','data-url'=>$subCategory->category_id)) ?>
                    </td>
                  </tr>
                  <?php //SubSubcategory Work
                  $subsubcategory = Engine_Api::_()->getDbtable('categories', 'core')->getSubsubcategory(array('column_name' => "*", 'category_id' => $subCategory->category_id, 'type' => 'tickets'));
                  foreach ($subsubcategory as $subsubCategory): ?>
                    <tr id="categoryid-<?php echo $subsubCategory->category_id; ?>" data-id="<?php echo $subsubCategory->category_id; ?>">
                      <td><input type="checkbox" class="checkbox check-column" name="delete_tag[]" value="<?php echo $subsubCategory->category_id; ?>" /></td>
                      <td>--&nbsp;<?php echo $subsubCategory->category_name ?>
                        <div class="hidden" style="display:none" id="inline_<?php echo $subCategory->category_id; ?>">
                          <div class="parent"><?php echo $subsubCategory->subsubcat_id; ?></div>
                        </div>
                      </td>
                      <td>
                        <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'support', 'action' => 'edit-category', 'id' => $subsubCategory->category_id, 'type' => $subsubCategory->type), $this->translate('Edit'), array('class' => 'smoothbox')) ?> | <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Delete'), array('class' => 'deleteCat','data-url'=>$subsubCategory->category_id)) ?>
                      </td>
                    </tr>
                  <?php endforeach; ?>
                <?php endforeach; ?>
              <?php endforeach; ?>
            </tbody>
          </table>
          <span class='buttons'>
            <button type="button" id="deletecategoryselected" class="upload_image_button button"><?php echo $this->translate("Delete Selected") ?></button>
          </span>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="application/javascript">
  scriptJquery('.core_admin_main_manage').parent().addClass('active');
  scriptJquery('.core_admin_main_manage_tickets').addClass('active');
</script>
