<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template name="translateBR">
    <xsl:param name="data"/>

    <xsl:variable name="br">
      <xsl:text>&lt;br /&gt;</xsl:text>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="contains($data, $br)">
        <xsl:value-of select="substring-before($data, $br)"/>
        <br/>
        <xsl:call-template name="translateBR">
          <xsl:with-param name="data">
            <xsl:value-of select="substring-after($data, $br)"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$data"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

  <xsl:attribute-set name="row-column-span-style">
    <xsl:attribute name="rowspan">3</xsl:attribute>
    <xsl:attribute name="colspan">3</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="row-span-style">
    <xsl:attribute name="rowspan">3</xsl:attribute>
  </xsl:attribute-set>

  <xsl:template match="/">

    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

    <html>
      <head>
        <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
      </head>
      <body>
        <table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">
          <xsl:for-each select="/Document/JobSession">
            <xsl:variable name='errorStyle'>
              <xsl:text>background-color: #fb9895;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 17px 15px;font-family: Tahoma;</xsl:text>
            </xsl:variable>
            <xsl:variable name='warningStyle'>
              <xsl:text>background-color: #ffd96c;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 17px 15px;font-family: Tahoma;</xsl:text>
            </xsl:variable>
            <xsl:variable name='successStyle'>
              <xsl:text>background-color: #00B050;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 17px 15px;font-family: Tahoma;</xsl:text>
            </xsl:variable>
            <tr>
              <td style="border:none; padding: 0px;font-family: Tahoma;font-size: 12px;">
                <table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">
                  <tr style="height:70px">
                    <td style="padding: 0px;font-family: Tahoma;font-size: 12px;">
                      <xsl:attribute name="style">
                        <xsl:text>width: 80%;border: none;</xsl:text>
                        <xsl:choose>
                          <xsl:when test="./Status = 'InProgress'">
                            <xsl:choose>
                              <xsl:when test="count(./TaskSession[Status = 'Error']) > 0">
                                <xsl:value-of select="$errorStyle"/>
                              </xsl:when>
                              <xsl:when test="count(./TaskSession[Status = 'Warning']) > 0">
                                <xsl:value-of select="$warningStyle"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:value-of select="$successStyle"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:when>
                          <xsl:when test="./Status = 'Success'">
                            <xsl:value-of select="$successStyle"/>
                          </xsl:when>
                          <xsl:when test="./Status = 'Warning'">
                            <xsl:value-of select="$warningStyle"/>
                          </xsl:when>
                          <xsl:when test="./Status = 'Error'">
                            <xsl:value-of select="$errorStyle"/>
                          </xsl:when>
                        </xsl:choose>
                      </xsl:attribute>

                      <xsl:value-of select="./JobType" />
                      <xsl:text> job: </xsl:text>
                      <xsl:value-of select="./JobName" />
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="./JobMode" />

                      <div class="jobDescription" style="margin-top: 5px;font-size: 12px;">
                        <xsl:value-of select="./JobDescription" />
                      </div>
                    </td>
                    <td>
                      <xsl:attribute name="style">
                        <xsl:text>border: none;padding: 0px;font-family: Tahoma;font-size: 12px;</xsl:text>
                        <xsl:choose>
                          <xsl:when test="./Status = 'InProgress'">
                            <xsl:choose>
                              <xsl:when test="count(./TaskSession[Status = 'Error']) > 0">
                                <xsl:value-of select="$errorStyle"/>
                              </xsl:when>
                              <xsl:when test="count(./TaskSession[Status = 'Warning']) > 0">
                                <xsl:value-of select="$warningStyle"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:value-of select="$successStyle"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:when>
                          <xsl:when test="./Status = 'Success'">
                            <xsl:value-of select="$successStyle"/>
                          </xsl:when>
                          <xsl:when test="./Status = 'Warning'">
                            <xsl:value-of select="$warningStyle"/>
                          </xsl:when>
                          <xsl:when test="./Status = 'Error'">
                            <xsl:value-of select="$errorStyle"/>
                          </xsl:when>
                        </xsl:choose>
                      </xsl:attribute>
                      <xsl:value-of select="./Status" />

                      <div class="jobDescription" style="margin-top: 5px;font-size: 12px;">
                        <xsl:value-of select="./ProcessedObject" />
                        of
                        <xsl:value-of select="./TotalObjects" />
                        <xsl:choose>
	                      <xsl:when test="./EDbJobType = '2'">
		                    objects processed
	                      </xsl:when>
						  <xsl:when test="./EDbJobType = '24'">
                            files processed
                          </xsl:when>
                          <xsl:when test="./EDbJobType = '28'">
                            backups processed
                          </xsl:when>
                          <xsl:when test="./EDbJobType = '4000'">
                            PCs processed
                          </xsl:when>
                          <xsl:when test="./EDbJobType = '12002'">
                            hosts processed
                          </xsl:when>
						  <xsl:when test="./EDbJobType = '12003'">
							hosts processed
						  </xsl:when>
						  <xsl:otherwise>
                            VMs processed
                          </xsl:otherwise>
                        </xsl:choose>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="border: none; padding: 0px;font-family: Tahoma;font-size: 12px;">
                      <table width="100%" cellspacing="0" cellpadding="0" class="inner" border="0" style='margin: 0px;border-collapse: collapse;'>

                        <tr style="height: 17px;">
                          <td colspan="9" class="sessionDetails"
                              style='border-style: solid; border-color:#a7a9ac; border-width: 1px 1px 0 1px;height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365; font-family: Tahoma;'>
                            <span>
                              <xsl:value-of select="./CreationTime" />
                            </span>
                          </td>
                        </tr>

                        <tr style="height: 17px;">
                          <td nowrap="" style="width: 1%;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Success</b>
                          </td>
                          <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./SuccessfulObjects" />
                          </td>

                          <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Start time</b>
                          </td>
                          <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./StartTime" />
                          </td>
                          <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:choose>
                              <xsl:when test="./EDbJobType = '51'">
                                <b>Processed</b>
                              </xsl:when>
                              <xsl:otherwise>
                                <b>Total size</b>
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>

                          <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./TotalSize" />
                          </td>

                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <b>Backup size</b>
                              </td>
                              <td nowrap="" style="width:85px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <xsl:value-of select="./BackupSize" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                          <td xsl:use-attribute-sets="row-span-style" style="border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;vertical-align: top;">
                            <xsl:choose>
                              <xsl:when test="./EDbJobType = '24' or ./EDbJobType = '28'">
                                <xsl:attribute name="colspan">3</xsl:attribute>
                              </xsl:when>
                            </xsl:choose>
                            <span class="small_label" style="font-size: 10px;">
                              <xsl:choose>
                                <xsl:when test="string(./Details) = ''">
                                  <xsl:text>&#160;</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                  <xsl:for-each select="./Details">
                                    <xsl:call-template name="translateBR">
                                      <xsl:with-param name="data">
                                        <xsl:value-of select="." />
                                      </xsl:with-param>
                                    </xsl:call-template>
                                  </xsl:for-each>
                                </xsl:otherwise>
                              </xsl:choose>
                            </span>
                          </td>
                        </tr>

                        <tr style="height: 17px;">
                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Warning</b>
                          </td>

                          <td style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./WarningObjects" />
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>End time</b>
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./EndTime" />
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:choose>
                              <xsl:when test="./EDbJobType = '51'">
                                <b>Read</b>
                              </xsl:when>
                              <xsl:otherwise>
                                <b>Data read</b>
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./DataRead" />
                          </td>

                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <b>Dedupe</b>
                              </td>

                              <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <xsl:value-of select="./Dedupe" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                        </tr>

                        <tr style="height: 17px;">
                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Error</b>
                          </td>

                          <td style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./FailedObjects" />
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Duration</b>
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./Duration" />
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <b>Transferred</b>
                          </td>

                          <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                            <xsl:value-of select="./DataTransferred" />
                          </td>

                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <b>Compression</b>
                              </td>
                              <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                                <xsl:value-of select="./Compression" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                        </tr>

                        <tr style="height: 17px;">
                          <td colspan="9" nowrap="" style="height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365; font-family: Tahoma;border: 1px solid #a7a9ac;" >
                            Details
                          </td>
                        </tr>

                        <tr class="processObjectsHeader" style="height: 23px">
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Name</b>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Status</b>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Start time</b>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>End time</b>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <xsl:choose>
                              <xsl:when test="./EDbJobType = '51'">
                                <b>Processed</b>
                              </xsl:when>
                              <xsl:otherwise>
                                <b>Size</b>
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Read</b>
                          </td>
                          <td nowrap="" style="width:1%;background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Transferred</b>
                          </td>
                          <td nowrap="" style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Duration</b>
                          </td>
                          <td style="background-color: #e3e3e3;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;border-top: none;font-family: Tahoma;font-size: 12px;">
                            <b>Details</b>
                          </td>
                        </tr>

                        <xsl:for-each select="./TaskSession">
                          <tr style="height: 17px;">
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./ObjectName" />
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <span>
                                <xsl:variable name="successStyleColor">
                                  <xsl:text>color: #00B050;</xsl:text>
                                </xsl:variable>
                                <xsl:variable name="warningStyleColor">
                                  <xsl:text>color: #FFC000;</xsl:text>
                                </xsl:variable>
                                <xsl:variable name="errorStyleColor">
                                  <xsl:text>color: #FF0000;</xsl:text>
                                </xsl:variable>
                                <xsl:attribute name="style">
                                  <xsl:choose>
                                    <xsl:when test="./Status = 'Success'">
                                      <xsl:value-of select="$successStyleColor"/>
                                    </xsl:when>
                                    <xsl:when test="./Status = 'Warning'">
                                      <xsl:value-of select="$warningStyleColor"/>
                                    </xsl:when>
                                    <xsl:when test="./Status = 'Error'">
                                      <xsl:value-of select="$errorStyleColor"/>
                                    </xsl:when>
                                  </xsl:choose>
                                </xsl:attribute>
                                <xsl:value-of select="./Status" />
                              </span>
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./StartTime" />
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./EndTime" />
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:choose>
                                <xsl:when test="../EDbJobType = '51'">
                                  <xsl:value-of select="./Processed" />
                                </xsl:when>
                                <xsl:otherwise>
                                  <xsl:value-of select="./Size" />
                                </xsl:otherwise>
                              </xsl:choose>
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./Read" />
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./Transferred" />
                            </td>
                            <td nowrap="" style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <xsl:value-of select="./Duration" />
                            </td>
                            <td style="padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;">
                              <span class='small_label' style='font-size: 10px;'>
                                <xsl:choose>
                                  <xsl:when test="string(./Details) = ''">
                                    <xsl:text>&#160;</xsl:text>
                                  </xsl:when>
                                  <xsl:otherwise>
                                    <xsl:for-each select="./Details">
                                      <xsl:call-template name="translateBR">
                                        <xsl:with-param name="data">
                                          <xsl:value-of select="." />
                                        </xsl:with-param>
                                      </xsl:call-template>
                                    </xsl:for-each>
                                  </xsl:otherwise>
                                </xsl:choose>
                              </span>
                            </td>
                          </tr>
                        </xsl:for-each>

                      </table>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>

            <tr>
              <td>&#160;</td>
            </tr>
          </xsl:for-each>

          <xsl:choose>
            <xsl:when test="/Document/WriteSignature = 'true'">
              <tr>
                <td style="font-size:12px;color:#626365;padding: 2px 3px 2px 3px;vertical-align: top;font-family: Tahoma;">
                  Veeam Backup &amp; Replication <xsl:value-of select="/Document/Shell_App_Version" />
                </td>
              </tr>
            </xsl:when>
          </xsl:choose>

          <xsl:choose>
            <xsl:when test="/Document/CustomSignature = 'true'">
              <tr>
                <td style="font-size:12px;color:#626365;padding: 2px 3px 2px 3px;vertical-align: top;font-family: Tahoma;">
                  <xsl:value-of select="/Document/CustomSignatureText" />
                </td>
              </tr>
            </xsl:when>
          </xsl:choose>
        </table>
      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>
