From 25a69a7dd0ca196cfd753a2f060629c4f4dcea57 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 16 Dec 2013 15:41:13 -0600
Subject: [PATCH] names: Add option for original name

And define getInitials() function for %{ticket.name.initials}
---
 include/class.user.php                       | 11 +++++++++++
 include/staff/templates/user-lookup.tmpl.php |  2 +-
 include/staff/templates/user.tmpl.php        |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/class.user.php b/include/class.user.php
index 0998f2348..125220bce 100644
--- a/include/class.user.php
+++ b/include/class.user.php
@@ -270,6 +270,7 @@ class PersonsName {
         'short' => array("First L.", 'getShort'),
         'shortformal' => array("F. Last", 'getShortFormal'),
         'complete' => array("Mr. First M. Last Sr.", 'getComplete'),
+        'original' => array('-- As Entered --', 'getOriginal'),
     );
 
     function __construct($name) {
@@ -342,6 +343,16 @@ class PersonsName {
         return $this->name;
     }
 
+    function getInitials() {
+        $names = array($this->parts['first']);
+        $names = array_merge($names, explode(' ', $this->parts['middle']));
+        $names[] = $this->parts['last'];
+        $initials = '';
+        foreach (array_filter($names) as $n)
+            $initials .= mb_substr($n,0,1);
+        return mb_convert_case($initials, MB_CASE_UPPER);
+    }
+
     function asVar() {
         return $this->__toString();
     }
diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php
index c2d8951a5..baeaebc6e 100644
--- a/include/staff/templates/user-lookup.tmpl.php
+++ b/include/staff/templates/user-lookup.tmpl.php
@@ -16,7 +16,7 @@ if ($info['error']) {
     <i class="icon-user icon-4x pull-left icon-border"></i>
     <a class="action-button pull-right" style="overflow:inherit"
         id="unselect-user"  href="#"><i class="icon-remove"></i> Add New User</a>
-    <div><strong id="user-name"><?php echo $user ? Format::htmlchars($user->getName()) : ''; ?></strong></div>
+    <div><strong id="user-name"><?php echo $user ? Format::htmlchars($user->getName()->getOriginal()) : ''; ?></strong></div>
     <div>&lt;<span id="user-email"><?php echo $user ? $user->getEmail() : ''; ?></span>&gt;</div>
 <?php if ($user) { ?>
     <table style="margin-top: 1em;">
diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php
index 2615cabbd..e2f2fd3cd 100644
--- a/include/staff/templates/user.tmpl.php
+++ b/include/staff/templates/user.tmpl.php
@@ -20,7 +20,7 @@ if ($info['error']) {
     <?php
     } ?>
     <div><b><a href="#" id="edituser"><i class="icon-edit"></i>&nbsp;<?php
-    echo Format::htmlchars($user->getName()); ?></a></b></div>
+    echo Format::htmlchars($user->getName()->getOriginal()); ?></a></b></div>
     <div>&lt;<?php echo $user->getEmail(); ?>&gt;</div>
     <table style="margin-top: 1em;">
 <?php foreach ($user->getDynamicData() as $entry) {
-- 
GitLab