<?php
  /**
   * Copyright 2011 Zazavi - http://www.zazavi.com
   * Zazavi is free software released under the terms of the GNU General Public License.
   * You should have received a copy of the license.  If not, see <http://www.gnu.org/licenses/>.
   */
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
	  
  if(!$user->getAcl("Templates")): print $core->msgAlert(_CG_ONLYADMIN, false); return; endif;
?>
<?php switch($core->action): case "edit": ?>
<?php $row = $core->getRowById("email_templates", $content->id);?>
<h1><img src="images/mail-sml.png" alt="" /><?php echo _ET_TITLE1;?></h1>
<p class="info"><span><?php echo $core->langIcon();?></span><?php echo _ET_INFO1. _REQ1 . required(). _REQ2;?></p>
<h2><?php echo _ET_SUBTITLE1 . $row['name'.$core->dblang];?></h2>
<form action="" method="post" id="admin_form" name="admin_form">
  <table cellspacing="0" cellpadding="0" class="formtable">
    <tr>
      <td width="200"><?php echo _ET_TTITLE;?>: <?php echo required();?></td>
      <td><input name="name<?php echo $core->dblang;?>" type="text"  class="inputbox required" value="<?php echo $row['name'.$core->dblang];?>" size="45" title="<?php echo _ET_TTITLE_R;?>"/></td>
    </tr>
    <tr>
      <td><?php echo _ET_SUBJECT;?>: <?php echo required();?></td>
      <td><input name="subject<?php echo $core->dblang;?>" type="text" class="inputbox required" value="<?php echo $row['subject'.$core->dblang];?>" size="45" title="<?php echo _ET_SUBJECT_T;?>"/></td>
    </tr>
    <tr>
      <td colspan="2" class="editor">
      <textarea id="bodycontent" class="tinymce" name="body<?php echo $core->dblang;?>"><?php echo $row['body'.$core->dblang];?></textarea>
      </td>
    </tr>
    <tr>
      <td colspan="2"><p class="info"><textarea name="help<?php echo $core->dblang;?>" cols="80" rows="1"><?php echo $row['help'.$core->dblang];?></textarea></p></td>
    </tr>
    <tr>
      <td colspan="2"><strong><?php echo _ET_VAR_T;?></strong></td>
    </tr>
    <tr>
      <td><input name="submit" type="submit" value="<?php echo _ET_UPDATE;?>"  class="button"/></td>
      <td><a href="loader.php?do=templates" class="button-alt"><?php echo _CANCEL;?></a></td>
    </tr>
  </table>
  <input name="id" type="hidden" value="<?php echo $content->id;?>" />
</form>
<?php echo $core->doForm("processTemplate","controller.php");?>
<?php break;?>
<?php default: ?>
<h1><img src="images/mail-sml.png" alt="" /><?php echo _ET_TITLE2;?></h1>
<p class="info"><span><?php echo $core->langIcon();?></span><?php echo _ET_INFO2;?></p>
<h2><?php echo _ET_SUBTITLE2;?></h2>

<table cellpadding="0" cellspacing="0" class="display">
  <thead>
    <tr>
      <th width="20" class="left">#</th>
      <th class="left"><?php echo _ET_TTITLE;?></th>
      <th width="25" class="right"><?php echo _EDIT;?></th>
    </tr>
  </thead>
  <tbody>
    <?php if(!$member->getEmailTemplates()):?>
    <tr>
      <td colspan="3"><?php echo $core->msgError(_ET_NOTEMPLATE,false);?></td>
    </tr>
    <?php else:?>
    <?php foreach ($member->getEmailTemplates() as $row):?>
    <tr>
      <td><?php echo $row['id'];?>.</td>
      <td><?php echo $row['name'.$core->dblang];?></td>
      <td align="right">
      <a href="loader.php?do=templates&amp;action=edit&amp;id=<?php echo $row['id'];?>"><img src="images/edit.png" alt="" class="tooltip" title="<?php echo _ET_EDIT.': '.$row['name'.$core->dblang];?>"/></a></td>
    </tr>
    <?php endforeach;?>
    <?php unset($row);?>
    <?php endif;?>
  </tbody>
</table>
<?php break;?>
<?php endswitch;?>