Pre-defined messages

From ISPWiki
Jump to: navigation, search

Before sending a message, BILLmanager generates an XML document containing information about a client, his services, server, etc.

An HTML reply can be based on EJS and XSLT depending on if "<xsl:stylesheet" is specified in the message template or not. If it is present, the XSLT will be used, otherwise - EJS.

You can use the "Test" icon in the "Message templates" module to check pre-defined messages. There you can also view contents of the XML document.

EJS

This technology uses the node.js platform. The XML-document is converted into json to generate an HTML message:

<doc>
 <hostname>example.com</hostname>
 <user>
   <realname>John Doe</realname>
   <email>john@example.com</email>
 </user>
 <item>
   <id>1</id>
   <name>shared hosting #1</name>
 </item>
 <item>
   <id>2</id>
   <name>shared hosting #2</name>
 </item>
</doc>

will be converted into json:

{
  'hostname': 'example.com',
  'user': {
    'realname': 'John Doe',
    'email': 'john@example.com'
  },
  'item': [
    {
      'id': 1,
      'name': 'shared hosting #1'
    },
    {
      'id': 2,
      'name': 'shared hosting #2'
    }
  ]
}

The script node /usr/local/mgr5/etc/scripts/template_ejs.js -t /path/to/template/file will start. The json-document will be sent to STDIN, and then contents of the HTML message will be sent to STDOUT.

The following is an example of the Shared hosting activation letter:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style type="text/css">
      b { color: #333; }
      .sP {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sA {color:blue;}
      .sH2 {font-family:Arial,Helvetica,sans-serif; font-size:13px; font-weight:bold;}
      .sP {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sLI {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sUL {margin-top: 0px; padding-left: 30px;}
      #subject {
        font-family:Arial,Helvetica,sans-serif; font-size:15px; margin-top:6px; margin-left:10px; margin-right:10px; margin-bottom:5px;
      }
      #content {margin: 8px 9px;}
    </style>
  </head>
  <body bgcolor="#ffffff">
    <div>
    <table width="90%" align="center" cellpadding="0" cellspacing="0" border="0">
    <!-- Subject -->
    <tr><td bgcolor="#e5e5e5">
    <div id="subject"><b>Shared hosting activation</b></div>
    </td></tr>
    <!-- Text -->
    <tr><td>
      <div id="content">
        <p class="sP">Dear, <%= user.realname %>!</p>
        <p class="sP">We want to inform you that the Shared hosting service has been activated on your account.
        You can print this message for your convenience.</p>
        <h2 class="sH2">Hosting service information</h2>
        <ul class="sUL">
            <li class="sLI"><b>Tariff plan: </b
            > <%= pricelist.name_ru && pricelist.name_ru !=  ? pricelist.name_ru : pricelist.name  %></li>
            <li class="sLI"><b>Activation date: </b> <%= item.opendate %></li>
            <li class="sLI"><b>Domain name: </b> <%= item.domain %></li>
            <li class="sLI"><b>Server IP address: </b> <%= item.ip %></li>
        </ul>
        <p class="sP"><br/>Kind regards,<br/>"<%= project.name >"</p>
      </div>
    </td></tr>
    </table>
    </div>
  </body>
</html>

XSLT

XSLT - is a language for transforming XML documents into other XML documents. libxml is used,

The following is an example of the shared hosting activation letter:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:mgr="http://ispsystem.com/xslplugin">
<xsl:output method='xml' indent='yes' encoding='UTF-8' omit-xml-declaration='yes'/>
<xsl:variable name="subject">Shared hosting activation</xsl:variable>
<xsl:variable name="content">
    <p class="sP">Dear, <xsl:value-of select='/doc/user/realname'/>!</p>
    <p class="sP">We want to inform you that a Shared hosting service has been activated on your account. 
    You can print this letter for your convenience.</p>
    <h2 class="sH2">Hosting service information</h2>
    <ul class="sUL">
        <li class="sLI"><b>Tariff plan: </b> 
        <xsl:choose><xsl:when test="/doc/pricelist/name_en !="><xsl:value-of select="/doc/pricelist/name_en"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="/doc/pricelist/name"/></xsl:otherwise></xsl:choose></li>
        <li class="sLI"><b>Activation date: </b> <xsl:value-of select='/doc/item/opendate'/></li>
        <li class="sLI"><b>Domain name: </b> <xsl:value-of select='/doc/item/domain'/></li>
        <li class="sLI"><b>Server IP: </b> <xsl:value-of select='/doc/item/ip'/></li>
    </ul>
    <p class="sP"><br/>Best regards<br/> "<xsl:value-of select="/doc/project/name"/>"</p>
</xsl:variable>
<xsl:template match='/doc'>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style type="text/css">
      b { color: #333; }
      .sP {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sA {color:blue;}
      .sH2 {font-family:Arial,Helvetica,sans-serif; font-size:13px; font-weight:bold;}
      .sP {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sLI {font-family:Arial,Helvetica,sans-serif; font-size:12px;}
      .sUL {margin-top: 0px; padding-left: 30px;}
      #subject {
        font-family:Arial,Helvetica,sans-serif; font-size:15px; margin-top:6px; margin-left:10px; margin-right:10px; margin-bottom:5px;
      }
      #content {margin: 8px 9px;}
    </style>
  </head>
  <body bgcolor="#ffffff">
    <div>
    <table width="90%" align="center" cellpadding="0" cellspacing="0" border="0">
    <!-- Subject -->
    <tr><td bgcolor="#e5e5e5">
    <div id="subject"><b><xsl:value-of select='$subject'/></b></div>
    </td></tr>
    <!-- Text -->
    <tr><td>
      <div id="content">
        <xsl:copy-of select="$content"/>
      </div>
    </td></tr>
    </table>
    </div>
  </body>
</html>
</xsl:template>
</xsl:stylesheet>