<?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_settings", "parentMenuItemName" => "core_admin_main_emailsettings", 'lastMenuItemName' => 'Manage Email Templates')); ?>

<h2 class="page_heading"><?php echo $this->translate('Email Settings') ?></h2>
<div class='tabs'>
  <?php echo $this->navigation()->menu()->setContainer($this->navigation)->render(); ?>
</div>

<p>
  <?php echo $this->translate("This page list all templates which you have created by you using this page. Below, you can create a new Email Template by clicking on “Create New Template link. You can manage below Email Template by using various links for them in the “Options” section below."); ?>
</p>

<div>
  <?php echo $this->htmlLink(array('controller' => 'mail', 'module' => 'core', 'action' => 'create', 'reset' => true), $this->translate("Create New Template"), array('class' => 'admin_link_btn mb-2')) ?>
</div>

<script type="text/javascript">

  function multiDelete() {
    return confirm("<?php echo $this->translate("Are you sure you want to delete the selected templates ?") ?>");
  }

  function selectAll() {
    var i;
    var multidelete_form = document.getElementById('multidelete_form');
    var inputs = multidelete_form.elements;
    for (i = 1; i < inputs.length - 1; i++) {
      inputs[i].checked = inputs[0].checked;
    }
  }
</script>
<?php $user_admin = Zend_Registry::isRegistered('user_admin') ? Zend_Registry::get('user_admin') : null; ?>
<?php if (!empty($user_admin) && is_countable($this->paginator) && engine_count($this->paginator)): ?>
  <div class="mb-2">
    <?php echo $this->translate(array('%s Email Template found.', '%s Email Templates  found', $this->paginator->getTotalItemCount()), $this->locale()->toNumber($this->paginator->getTotalItemCount())) ?>
  </div>
  <form id="multidelete_form" action="<?php echo $this->url(); ?>" onSubmit="return multiDelete()" method="POST">
    <table class='admin_table admin_responsive_table' width="100%">
      <thead>
        <tr>
          <th class='admin_table_short' style="width:5%;"><input onclick="selectAll()" type='checkbox' class='checkbox' />
          </th>
          <th class='admin_table_short' style="width:5%;"><?php echo $this->translate('Id') ?></th>
          <th class='admin_table_short' style="width:40%;"><?php echo $this->translate('Title') ?></th>
          <th class="text-center" style="width:15%;"><?php echo $this->translate('Status') ?></th>
          <th style="width:35%;"><?php echo $this->translate('Options') ?></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($this->paginator as $item): ?>
          <tr>
            <td><input type='checkbox' class='checkbox' name='delete_<?php echo $item->emailtemplate_id; ?>' value="<?php echo $item->emailtemplate_id ?>" /></td>
            <td data-label="<?php echo $this->translate('Id') ?>"><?php echo $item->emailtemplate_id; ?></td>
            <td data-label="<?php echo $this->translate('Title') ?>"><?php echo $item->title; ?></td>
            <td data-label="<?php echo $this->translate('Status') ?>" class="admin_table_centered">
              <?php echo ($item->is_active ? $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'enabled', 'template_id' => $item->emailtemplate_id), $this->htmlImage($this->layout()->staticBaseUrl . 'application/modules/Core/externals/images/admin/check.png', '', array('title' => $this->translate('Enabled'))), array()) : $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'enabled', 'template_id' => $item->emailtemplate_id), $this->htmlImage('application/modules/Core/externals/images/admin/uncheck.png', '', array('title' => $this->translate('Disabled'))))) ?>
            </td>
            <td class="admin_table_options">
              <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'create', 'template_id' => $item->emailtemplate_id), $this->translate("Edit")) ?>
              |
              <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'delete-emailtemplate', 'template_id' => $item->emailtemplate_id), $this->translate("Delete"), array('class' => 'smoothbox')) ?>
              |
              <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'create', 'duplicate' => $item->emailtemplate_id), $this->translate("Duplicate")) ?>
              |
              <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'core', 'controller' => 'mail', 'action' => 'testmail', 'template_id' => $item->emailtemplate_id), $this->translate("Send Test Mail"), array('class' => 'smoothbox')) ?>
            </td>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
    <div class='buttons'>
      <button type='submit'><?php echo $this->translate("Delete Selected") ?></button>
    </div>
  </form>
  <div>
    <?php echo $this->paginationControl($this->paginator, null, null); ?>
  </div>
<?php else: ?>
  <div class="tip">
    <span>
      <?php echo $this->translate("There are no templates created yet.") ?>
    </span>
  </div>
<?php endif; ?>
<style>
  .text-center {
    text-align: center;
  }
</style>
<script type="application/javascript">
  scriptJquery('.core_admin_main_settings').parent().addClass('active');
  scriptJquery('.core_admin_main_emailsettings').addClass('active');
</script>