Mittwoch, 6. März 2013

OTRS Erweiterung: OTRS_QUEUE Variablen in Benachrichtigungen nutzen


Um eine generische Signatur mit unterschiedlichen Queue-basierten Telefonnummern zu verwenden, habe ich eine Erweiterung für OTRS 3.1.13 geschrieben, welche die Tags <OTRS_QUEUE_*> (inklusive Preferences) verfügbar macht.


Nach dem Einspielen des Patches und anschließender Aktivierung der entsprechenden Optionen in der SysConfig können pro Queue zusätzliche, frei wählbare Felder genutzt werden.

diff -Nur Kernel/Config/Files/QueuePref.xml /opt/otrs-3.1.13/Kernel/Config/Files/QueuePref.xml
--- Kernel/Config/Files/QueuePref.xml    1970-01-01 01:00:00.000000000 +0100
+++ /opt/otrs-3.1.13/Kernel/Config/Files/QueuePref.xml    2013-02-19 13:12:45.006970100 +0100
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<otrs_config version="1.0" init="Application">
+    <ConfigItem Name="QueuePreferences###FaxNumber" Required="0" Valid="0">
+        <Description Translatable="1">Parameters of the example queue attribute FaxNumber.</Description>
+        <Group>Ticket</Group>
+        <SubGroup>Frontend::Queue::Preferences</SubGroup>
+        <Setting>
+            <Hash>
+                <Item Key="Module">Kernel::Output::HTML::QueuePreferencesGeneric</Item>
+                <Item Key="Label">FaxNumber</Item>
+                <Item Key="Desc">Define the queue faxnumber</Item>
+                <Item Key="Block">TextArea</Item>
+                <Item Key="Cols">50</Item>
+                <Item Key="Rows">5</Item>
+                <Item Key="PrefKey">FaxNumber</Item>
+            </Hash>
+        </Setting>
+    </ConfigItem>
+    <ConfigItem Name="QueuePreferences###PhoneNumber" Required="0" Valid="0">
+        <Description Translatable="1">Parameters of the example queue attribute PhoneNumber.</Description>
+        <Group>Ticket</Group>
+        <SubGroup>Frontend::Queue::Preferences</SubGroup>
+        <Setting>
+            <Hash>
+                <Item Key="Module">Kernel::Output::HTML::QueuePreferencesGeneric</Item>
+                <Item Key="Label">PhoneNumber</Item>
+                <Item Key="Desc">Define the queue faxnumber</Item>
+                <Item Key="Block">TextArea</Item>
+                <Item Key="Cols">50</Item>
+                <Item Key="Rows">5</Item>
+                <Item Key="PrefKey">PhoneNumber</Item>
+            </Hash>
+        </Setting>
+    </ConfigItem>
+</otrs_config>
+
diff -Nur Kernel/System/TemplateGenerator.pm /opt/otrs-3.1.13/Kernel/System/TemplateGenerator.pm
--- Kernel/System/TemplateGenerator.pm    2012-06-21 13:40:05.000000000 +0200
+++ /opt/otrs-3.1.13/Kernel/System/TemplateGenerator.pm    2013-02-19 13:09:25.758970100 +0100
@@ -1026,7 +1026,12 @@
         }
     }

+    # queueid is in Data if called from actual query
     my %Queue;
+    if ($Param{Data}->{QueueID}) {
+        $Param{QueueID} = $Param{Data}->{QueueID};
+    }
+
     if ( $Param{QueueID} ) {
         %Queue = $Self->{QueueObject}->QueueGet( ID => $Param{QueueID} );
     }
@@ -1088,6 +1093,29 @@
         }
     }

+    # cleanup
+    $Param{Text} =~ s/$Tag.+?$End/-/gi;
+
+    # get queue data and replace it with <OTRS_QUEUE_...
+    $Tag = $Start . 'OTRS_QUEUE_';
+    if ( $Param{QueueID} ) {
+        # html quoting of content
+        if ( $Param{RichText} ) {
+            for ( keys %Queue ) {
+                next if !$Queue{$_};
+                $Queue{$_} = $Self->{HTMLUtilsObject}->ToHTML(
+                    String => $Queue{$_},
+                );
+            }
+        }
+
+        # replace it
+        for ( keys %Queue ) {
+            next if !defined $Queue{$_};
+            $Param{Text} =~ s/$Tag$_$End/$Queue{$_}/gi;
+        }
+    }
+
     # cleanup
     $Param{Text} =~ s/$Tag.+?$End/-/gi;

diff -Nur Kernel/System/Ticket/Article.pm /opt/otrs-3.1.13/Kernel/System/Ticket/Article.pm
--- Kernel/System/Ticket/Article.pm    2012-06-21 13:40:06.000000000 +0200
+++ /opt/otrs-3.1.13/Kernel/System/Ticket/Article.pm    2013-02-19 13:09:22.034970100 +0100
@@ -2614,11 +2614,28 @@
             $Notification{Subject} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
         }
     }
-
+    
     # cleanup
     $Notification{Subject} =~ s/<OTRS_OWNER_.+?>/-/gi;
     $Notification{Body}    =~ s/<OTRS_OWNER_.+?>/-/gi;

+    # get queue data
+    my %QueuePreferences;
+    if ( $Article{QueueID} ) {
+        %QueuePreferences = $Self->{QueueObject}->QueueGet( ID => $Article{QueueID} );
+    }
+
+    for ( keys %QueuePreferences ) {
+        if ( $QueuePreferences{$_} ) {
+            $Notification{Body}    =~ s/<OTRS_QUEUE_$_>/$QueuePreferences{$_}/gi;
+            $Notification{Subject} =~ s/<OTRS_QUEUE_$_>/$QueuePreferences{$_}/gi;
+        }
+    }
+
+    # cleanup
+    $Notification{Subject} =~ s/<OTRS_QUEUE_.+?>/-/gi;
+    $Notification{Body}    =~ s/<OTRS_QUEUE_.+?>/-/gi;
+
     # get responsible data
     my %ResponsiblePreferences = $Self->{UserObject}->GetUserData(
         UserID => $Article{ResponsibleID},


Der vollständige Patch kann auch direkt unter http://www.ciphron.de/download/software/ heruntergeladen werden und mittels patch -p0 < file eingespielt werden.

Keine Kommentare: