<?php

include("../includes/site_config.php");

include('../session_handler.inc');

//include('../functions.php');

include('../includes/functions.php');

include('../message.php');

include('../error.php');


/*
if ($Sess_UserType != "A") {

    exit;

}
*/
$Name = $_REQUEST['Name'];

$LANG_ID = $_REQUEST['LANG_ID'];

$Type = $_REQUEST['Type'];

$Body = $_REQUEST['Body'];

$act = $_REQUEST['act'];



$mailtemplate =& MTemplateManager::getInstance();

$m_template = $mailtemplate->Get($Name);



if($act == 'save') {

    restrict_demo();

    $res = $m_template->Save($Body,$Type,$LANG_ID);

    if ($res===null ) {

        error_page(join("<br>",$m_template->error),GENERAL_USER_ERROR);

    } else {

         echo "<script> location.href='$CONST_LINK_ROOT/admin/admin_mailtemplates.php'; </script>";
//header("Location: $CONST_LINK_ROOT/admin/admin_mailtemplates.php");

        exit;

    }

}

# retrieve the template

$area = 'member';



?>

<?php include("include/header.php"); ?>
<div class="borderpage"><div class="borderpage2">
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">

        <tr>

      <td align="right">

      </td>

    </tr>

    <tr>

    <td class="pageheader">

      <?= ADM_MAILTEMPLATES_EDIT_SECTION_NAME?>

    </td>

    </tr>

    <tr>

      <td><table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">

        <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/admin_mailtemplates_edit.php<?php print("?PHPSESSID=".session_id()); ?>" enctype="multipart/form-data">

          <input type="hidden" name="act" value="save">

          <input type="hidden" name="Name" value="<?=$Name?>">

          <input type="hidden" name="LANG_ID" value="<?=$LANG_ID?>">

          <tr>

            <td align="center">

    	    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">

                <tr>

                  <td colspan="2" class="tdhead">&nbsp;</td>

                </tr>

                <tr class="tdodd">

                  <td>

                    <?=ADM_MAILTEMPLATES_DESCRIPTION?>

                  </td>

                  <td height="25"> <?= $m_template->comments?></td>

                </tr>

                <tr class="tdodd">

                  <td>

                    <?=ADM_MAILTEMPLATES_VARIABLES?>

                  </td>

                  <td height="25"> <?= join(", ",$m_template->config)?></td>

                </tr>

                <tr class="tdodd">

                  <td>

                    <?=ADM_MAILTEMPLATES_TYPE?>

                  </td>

                  <td height="25">

                  <select name="Type" class="input">

                    <option value="text/html" <? if ($m_template->type == "text/html"){?>selected<?}?>>Text/Html

                    <option value="text/plain" <? if ($m_template->type == "text/plain"){?>selected<?}?>>Text/Plain

                  </select>

                  </td>

                </tr>

                <tr class="tdeven">

                  <td>

                    <?=ADM_MAILTEMPLATES_MESSAGE?>

                  </td>

                  <td> <textarea style="width=500 px;" name="Body" cols="80" rows="15" wrap="soft" class="inputl"><?=$m_template->value[$LANG_ID]?></textarea></td>

                </tr>

                <tr>

                  <td colspan="2" align="center" class="tdfoot"> <input name="submit" type="submit" class="button" value="<?=GENERAL_SAVE?>">

                    <input name="button" type="button" class="button" onclick="window.location = '<?=$CONST_LINK_ROOT?>/admin/admin_mailtemplates.php'" value="<?=GENERAL_CANCEL?>">

                  </td>

                </tr>

              </table></td>

          </tr>

        </form>

      </table></td>

    </tr>

</table></div></div>

<?php include("include/footer.php"); ?>

