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

<xsl:import href="ack_text"/>

<xsl:variable name="level_none">0</xsl:variable>
<xsl:variable name="level_debug">1</xsl:variable>
<xsl:variable name="level_info">2</xsl:variable>
<xsl:variable name="level_notice">3</xsl:variable>
<xsl:variable name="level_warn">4</xsl:variable>
<xsl:variable name="level_error">5</xsl:variable>
<xsl:variable name="level_critical">6</xsl:variable>
<xsl:variable name="level_fatal">7</xsl:variable>

  <xsl:template match="syntax_error">
<xsl:text>
***Error: Syntax error in object
</xsl:text>
  <xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="syntax_ok">
***Info: Syntax check passed
  </xsl:template>

  <xsl:template match="invalid_source">
***Error: Source [<xsl:value-of select="source/text()"/>] not recognised.
  </xsl:template>


  <xsl:template match="attr">
<xsl:text>
</xsl:text>
<xsl:value-of select="text()"/>: <xsl:value-of select="value"/>
<xsl:if test="count(syntax_error)>0">
<xsl:text></xsl:text>
***Error: <xsl:value-of select="syntax_error"/>
</xsl:if>
  </xsl:template>


  <xsl:template match="object_syntax_error">
<xsl:text>
</xsl:text>***Error: <xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="object_syntax_warn">
<xsl:text>
</xsl:text>***Warning: <xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="input_analyse">
<xsl:apply-templates select="bad_credentials"/>
  </xsl:template>

  <xsl:template match="bad_credentials">
***Error: The following PGP credentials were not correct:
<xsl:apply-templates select="list"/>
<xsl:text>
</xsl:text>
  </xsl:template>


  <xsl:template match="unparsable_input">
<xsl:value-of select="text()"/>
<xsl:text>
</xsl:text>
  </xsl:template>


<!-- Follows PGP key info, its big, ends with key_info case -->

<!--   <xsl:template match="ok">
key-cert operation OK
  </xsl:template> -->
  <xsl:template match="multiple_keys">
***Error: The supplied object has multiple keys
  </xsl:template>
  <xsl:template match="no_key">
***Error: The supplied object has no key 
  </xsl:template>
  <xsl:template match="key_exists">
***Error: The supplied key already exists
  </xsl:template>
  <xsl:template match="secret_key">
***Error: The supplied key is a secret key
  </xsl:template>
  <xsl:template match="ids_dont_match">
***Error: The supplied key and its ID don't match 
  </xsl:template>
  <xsl:template match="internal">
***Error: There was an internal error
  </xsl:template>
  <xsl:template match="unexistent_key">
***Error: Key doesn't exist
  </xsl:template>
  <xsl:template match="not_removed">
***Error: The key was not removed
  </xsl:template>
  <xsl:template match="unknown_error">
***Error: Unknown key-cert error
  </xsl:template>
  <xsl:template match="key_info"><xsl:apply-templates/></xsl:template>


  <xsl:template match="non_existent_object">
***Error: This object does not exist in the database.<xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="unknown_country">
***Error: Country not recognised: <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="unknown_nic_suffix">
***Error: Unknown nic handle referenced: <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="object_exists">
***Error: Object exists: <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="versions_dont_match">
***Error: This does not exactly match the object stored in the database.
<xsl:text>
</xsl:text>
  </xsl:template>

  <xsl:template match="versions_match">
***Warning: Submited object identical to database object.
  </xsl:template>

  <xsl:template match="operation_failed">
***Error: Operation failed (<xsl:value-of select="operation/text()"/>)
  </xsl:template>



  <xsl:template match="notification_header">From: <xsl:value-of select="from/text()"/>
To: <xsl:value-of select="to/text()"/>
Subject: <xsl:if test="count(../obj[@result='ERR'])>0">FAILED: </xsl:if><xsl:if
test="count(../obj[@result='ERR'])=0">SUCCESS: </xsl:if><xsl:value-of select="subject/text()"/>
Reply-To: ripe-dbm@ripe.net
<xsl:text>

</xsl:text>
  </xsl:template>

  <xsl:template match="mail_origin_of_request">
>  From:       <xsl:value-of select="from/text()"/>       
>  Subject:    <xsl:value-of select="subject/text()"/>    
>  Date:       <xsl:value-of select="date/text()"/>       
>  Reply-To:   <xsl:value-of select="reply_to/text()"/>   
>  Message-ID: <xsl:value-of select="msgid/text()"/>      
<xsl:text>

</xsl:text>
  </xsl:template>

  <xsl:template match="ip_origin_of_request">
 - From-Host: <xsl:value-of select="ip/text()"/>
 - Date/Time: <xsl:value-of select="../process_time/p_time/text()"/>
  </xsl:template>

  <xsl:template match="operation_ok">
Operation OK (<xsl:value-of select="operation/text()"/>)
  </xsl:template>


  <xsl:template match="object">
<xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="mntner">
Maintainer: <xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="enforced_new_exists">
***Error: Enforced new keyword specified, but the object already exists in the database
  </xsl:template>

  <xsl:template match="invalid_keyword_combination">
***Warning: Invalid keyword combination found: <xsl:value-of select="text()"/>
***Warning: All keywords were ignored
  </xsl:template>

  <xsl:template match="invalid_keyword">
***Warning: Invalid keyword(s) found: <xsl:value-of select="text()"/>
***Warning: All keywords were ignored
  </xsl:template>

  <xsl:template match="object_still_referenced">
***Error: Object still referenced
  </xsl:template>

  <xsl:template match="object_not_referenced">
***Error: Object not referenced
  </xsl:template>

  <xsl:template match="object_not_found">
***Error: The object '<xsl:value-of select="object/text()"/>' was not found in the database
  </xsl:template>


  <xsl:template match="mail_from">
There is a MAIL-FROM in the object. <xsl:if test="only_mfrom">The maintainer has no other types of auth.</xsl:if>
<xsl:if test="ok">Operation OK.</xsl:if>
  </xsl:template>

  <xsl:template match="no_mail_from">
No MAIL-FROM in the object.
  </xsl:template>



  <xsl:template match="manual_creation">
Manual creation of the object.
  </xsl:template>

  <xsl:template match="automatic_creation">
Automatic creation</xsl:template>

  <xsl:template match="unknown_refered_object">
***Error: Refered object <xsl:value-of select="refered_object/text()"/> doesn't exist.</xsl:template>

  <xsl:template match="known_refered_object">
Refered object <xsl:value-of select="refered_object/text()"/> exists.
  </xsl:template>

  <xsl:template match="unknown_auto_nic">
***Error: Unknown AUTO- nic handle referenced: <xsl:value-of select="nic/text()"/>
  </xsl:template>

  <xsl:template match="changed_date_missing">
<xsl:if test="$level_notice>$level">
***Warning: Date '<xsl:value-of select="date/text()"/>' added to changed: attribute '<xsl:value-of select="value/text()"/>'
</xsl:if>
</xsl:template>

  <xsl:template match="multiple_changed_date_missing">
***Error: More than one changed: attribute without date
  </xsl:template>

  <xsl:template match="changed_date_order">
***Error: The dates in the changed: attributes should be in accending order
          '<xsl:value-of select="value/text()"/>' was found after '<xsl:value-of select="previous/text()"/>'
  </xsl:template>

  <xsl:template match="changed_date_syntax">
***Error: <xsl:value-of select="message/text()"/>
  </xsl:template>

  <xsl:template match="postprocessed_object"></xsl:template>

  <xsl:template match="changed_date_syntax">
***Error: <xsl:value-of select="message/text()"/>
  </xsl:template>

  <xsl:template match="key_add_error">
***Error: Unable to add key: <xsl:value-of select="error/text()"/>
  </xsl:template>

  <xsl:template match="key_modify_error">
***Error: Unable to modify key: <xsl:value-of select="error/text()"/>
<!-- ***Error: Unable to modify key: <xsl:if test="error/text()='KM_KEY_EXISTS'">Key exists</xsl:if> -->
  </xsl:template>

  <xsl:template match="key_remove_error">
***Error: Unable to remove key: <xsl:value-of select="error/text()"/>
  </xsl:template>

  <xsl:template match="incorrect_generated">
***Warning: Supplied attribute '<xsl:value-of select="text()"/>' has been replaced with generated value</xsl:template>


  <xsl:template match="pgp_error">
***Error: PGP reported:
<xsl:value-of select="error/text()"/>
  </xsl:template>

  <xsl:template match="pgp_ok">
No PGP error on object
  </xsl:template>

  <xsl:template match="non_existent_maintainer">
  
***Error: The maintainer '<xsl:value-of select="text()"/>' was not found in the database
  </xsl:template>

  <xsl:template match="non_existent_irt">
  
***Error: The irt '<xsl:value-of select="text()"/>' was not found in the database
  </xsl:template>

  <xsl:template match="non_existent_origin">

***Error: The origin AS object does not exist
  </xsl:template>

  <xsl:template match="non_existent_parent">

***Error: There is no parent object
  </xsl:template>

  <xsl:template match="multiple_parents">

***Error: The following multiple overlapping parents were found:
<xsl:apply-templates/>
***Info: All but one of these parent networks must be
         deleted before the child can be created.
         If you are not the maintainer of the invalid parent(s), 
         please contact the maintainer.
  </xsl:template>

  <xsl:template match="status_check_failed">

***Error: <xsl:value-of select="reason/text()"/>
  </xsl:template>
  
  <xsl:template match="rip_update_error">
  <xsl:text>
</xsl:text><xsl:value-of select="error/text()"/>
  </xsl:template>


<!-- AU module -->

  <xsl:template match="auth_info">

***Info: Authorisation for <xsl:value-of select="parent_text/text()"/> [<xsl:value-of select="type/text()"/>] <xsl:if test="substring(key/text(), 1, 5)='AUTO-'"><xsl:value-of select="../../../@id"/></xsl:if><xsl:if test="substring(key/text(), 1, 5)!='AUTO-'"><xsl:value-of select="key/text()"/></xsl:if> <xsl:text>
  </xsl:text>
  <xsl:apply-templates select="no_maintainer | attribute_checked"/>
  <xsl:apply-templates select="mnt_auth_ok"/>
  <xsl:apply-templates select="mnt_auth_fail"/>
  <xsl:if test="count(mnt_auth_ok/*) = 0 and count(mnt_auth_fail/*) = 0">
         no valid maintainer found</xsl:if>
  </xsl:template>

  <xsl:template match="attribute_checked">       using <xsl:value-of select="text()"/>:</xsl:template>
  <xsl:template match="no_maintainer">       no maintainer found  <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="mnt_auth_fail">
<xsl:text>
  </xsl:text>       not authenticated by: <xsl:apply-templates/></xsl:template>
  <xsl:template match="mnt_auth_ok">
<xsl:text>
  </xsl:text>       authenticated by: <xsl:apply-templates/> </xsl:template>

  <xsl:template match="irt_auth_info">

***Info: Authorisation for  [<xsl:value-of select="type/text()"/>] <xsl:value-of select="key/text()"/> <xsl:text>
  </xsl:text>
  <xsl:apply-templates select="no_irt | attribute_checked"/>
  <xsl:apply-templates select="irt_auth_ok"/>
  <xsl:apply-templates select="irt_auth_fail"/>
  <xsl:if test="count(irt_auth_ok/*) = 0 and count(irt_auth_fail/*) = 0">
         no valid irt found</xsl:if>
  </xsl:template>

  <xsl:template match="attribute_checked">       using <xsl:value-of select="text()"/>:</xsl:template>
  <xsl:template match="no_irt">       no irt found  <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="irt_auth_fail">
<xsl:text>
  </xsl:text>       not authenticated by: <xsl:apply-templates/></xsl:template>
  <xsl:template match="irt_auth_ok">
<xsl:text>
  </xsl:text>       authenticated by: <xsl:apply-templates/> </xsl:template>


<!-- 
  <xsl:template match="auth_result">
  <xsl:if test="(../../../@operation!='Forward')>0">
  <xsl:if test="(../../../@result='ERR')>0">
  <xsl:if test="ok">
***Info: Authorisation passed</xsl:if>
  </xsl:if>
  <xsl:if test="fail">
***Error: Authorisation failed</xsl:if>

  </xsl:if>
  
  </xsl:template>
-->


  <xsl:template match="auth_result">
  <xsl:if test="(../../../@operation!='Forward')>0">
  <xsl:if test="(../../../@result='ERR')>0">
  <xsl:if test="ok">
    <xsl:if test="../../../irt_auth_result/ok or not(../../../irt_auth_result)">
<!--    <xsl:if test="(../../../irt_auth_result/fail!=NULL)>0"> -->
***Info: Authorisation passed</xsl:if>
    <xsl:if test="../../../irt_auth_result/fail">
***Error: Authorisation failed</xsl:if>
    </xsl:if>
  </xsl:if>
  <xsl:if test="fail">
***Error: Authorisation failed</xsl:if>

  </xsl:if>
  
  </xsl:template>

<!-- lists -->
  <xsl:template match="list">
<xsl:value-of select="text()"/><xsl:if test="not(position()=last())">, </xsl:if></xsl:template>


  <xsl:template match="list_line">
<xsl:text>          </xsl:text><xsl:value-of select="text()"/><xsl:if test="not(position()=last())">, </xsl:if><xsl:text>
</xsl:text>

</xsl:template>

<!-- root node -->
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="obj">

---
<xsl:if test="(@result='ERR')>0"> 
<xsl:if test="(@operation!='Syntax Error')>0"><xsl:value-of select="@operation"/></xsl:if>
<xsl:if test="(@operation='Syntax Error')>0">Update</xsl:if> FAILED:</xsl:if>

<xsl:if test="(@result='OK')>0">
<xsl:if test="(@operation!='Forward')>0">
<xsl:value-of select="@operation"/> <xsl:if test="(@operation!='No Operation')>0"><xsl:text> </xsl:text>SUCCEEDED</xsl:if></xsl:if>
<xsl:if test="(@operation='Forward')>0">No Operation</xsl:if>
<xsl:text>:</xsl:text></xsl:if>

<xsl:text> [</xsl:text><xsl:value-of select="class/@class"/><xsl:text>] </xsl:text>
<xsl:value-of select="@id"/>
    <xsl:apply-templates select="*[name()='composite']">
      <xsl:with-param name="level" select="$level"/>
      <xsl:with-param name="summary" select="1"/>
    </xsl:apply-templates>


    <xsl:apply-templates select="*[name()='syntax_error' or name()='syntax_warn' or (name()='syntax_ok' and (../@result='ERR')>0)]">
      <xsl:with-param name="level" select="$level"/>
    </xsl:apply-templates>

<xsl:if test="(@operation!='Forward')>0">
    <xsl:apply-templates select="*[(name()!='composite' and (name()!='attr' or (../@result='ERR')>0) and name()!='syntax_ok' and name()!='syntax_error' and name()!='syntax_warn')]">
      <xsl:with-param name="level" select="$level"/>
    </xsl:apply-templates>

    <xsl:apply-templates select="*[name()='composite']">
      <xsl:with-param name="level" select="$level"/>
      <xsl:with-param name="summary" select="0"/>
    </xsl:apply-templates>
</xsl:if>
<xsl:if test="(@operation='Forward')>0">

***Info: <xsl:value-of select="class/@class"/>: objects cannot be created automatically
         The object has been forwarded to the RIPE
         Database Administration for authorisation.
         You will receive further notification when 
         this request is processesed.
         No further action from your part is required.
</xsl:if>

  </xsl:template>

  <xsl:template match="report">
      <xsl:apply-templates select="notification_header" />
      <xsl:apply-templates select="input_analyse" />
      <xsl:apply-templates select="mail_origin_of_request" />
      <xsl:apply-templates select="ip_origin_of_request" />


  <xsl:choose>
    <xsl:when test="internal_error">
      <xsl:call-template name="internal_error" />
    </xsl:when>
    <xsl:when test="help_request">
      <xsl:call-template name="DB_help" />
    </xsl:when>
    <xsl:otherwise>
SUMMARY OF UPDATE:

Number of objects found:                   <xsl:value-of select="count(obj)"/>
Number of objects processed successfully:  <xsl:value-of select="count(obj[@result='OK'])"/>
  Create:         <xsl:value-of select="count(obj[@result='OK' and @operation='Create'])"/>
  Modify:         <xsl:value-of select="count(obj[@result='OK' and @operation='Modify'])"/>
  Delete:         <xsl:value-of select="count(obj[@result='OK' and @operation='Delete'])"/>
  No Operation:   <xsl:value-of select="count(obj[@result='OK' and @operation='No Operation'])+count(obj[@result='OK' and @operation='Forward'])"/>
Number of objects processed with errors:   <xsl:value-of select="count(obj[@result='ERR'])"/>
  Create:         <xsl:value-of select="count(obj[@result='ERR' and @operation='Create'])"/>
  Modify:         <xsl:value-of select="count(obj[@result='ERR' and @operation='Modify'])"/>
  Delete:         <xsl:value-of select="count(obj[@result='ERR' and @operation='Delete'])"/>
  Syntax Errors:  <xsl:value-of select="count(obj[@result='ERR' and @operation='Syntax Error'])"/>


DETAILED EXPLANATION:

      <xsl:apply-templates select="invalid_keyword_combination">
        <xsl:with-param name="level" select="@level"/>
      </xsl:apply-templates>

      <xsl:apply-templates select="invalid_keyword">
        <xsl:with-param name="level" select="@level"/>
      </xsl:apply-templates>

    <xsl:if test="count(obj[@result='ERR'])>0">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following object(s) were found to have ERRORS:
      <xsl:apply-templates select="obj[@result='ERR']">
        <xsl:with-param name="level" select="@level"/>
      </xsl:apply-templates>
    </xsl:if>
    <xsl:if test="count(obj[@result='OK'])>0">
    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following object(s) were processed SUCCESSFULLY:
      <xsl:apply-templates select="obj[@result='OK']">
        <xsl:with-param name="level" select="@level"/>
      </xsl:apply-templates>
    </xsl:if>
    <xsl:if test="count(unparsable_input)>0">
    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following paragraph(s) do not look like objects
and were NOT PROCESSED:

<xsl:apply-templates select="unparsable_input"/>
    </xsl:if>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    </xsl:otherwise>
  </xsl:choose>

<xsl:call-template name="contact" />
  </xsl:template>

<!-- level stuff
  <xsl:template match="level">
    <xsl:element name="level"><xsl:attribute name="level"><xsl:value-of select="@level"/></xsl:attribute><xsl:apply-templates/></xsl:element>
  </xsl:template>
-->

<!-- composite/summary -->
  <xsl:template match="composite">
    <xsl:if test="(@operation!='Forward')>0">

      <xsl:if test="$summary=1">
      <xsl:apply-templates select="summary"/>
      </xsl:if>
      <xsl:if test="$summary=0">
      <xsl:apply-templates select="*[name()!='summary']"/>
      <xsl:if test="summary/auth_result/@override">
         Authorisation override used
      </xsl:if>
      </xsl:if>
    </xsl:if>

  </xsl:template>




<!--
  <xsl:template match="summary">
      <xsl:apply-templates/>
  </xsl:template>
  -->
</xsl:stylesheet>
