<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Phonebook extensions mismatch]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">first, thank you for this amazing product. We have bought the full license for unlimited buttons/extensions, and we love FOP2.</p>
<p dir="auto">FOP2 works great, but we have a weird behavior with phonebook entries in the web frontend.<br />
I've integrated FOP2 phonebook with the CID Superfecta module in Freepbx 12.0.54, and it works.<br />
Extensions display the correct CID.<br />
The FOP web frontend display also correct CID when external calls incoming, but when internal extensions call another extension, the web frontend displays the first entry in the phonebook that match the last 2 numbers of extensions.</p>
<p dir="auto">I.E. John Smith with ext 52 is visualized as Marc Brown mobile +39 123 4578<strong>52</strong></p>
<p dir="auto">All the phones are in the local LAN net.<br />
The Chrome plugin works well.</p>
<p dir="auto">Thank you for your help.</p>
<p dir="auto">Regards</p>
<p dir="auto">Marco</p>
]]></description><link>http://localhost:4567/topic/1975/phonebook-extensions-mismatch</link><generator>RSS for Node</generator><lastBuildDate>Tue, 27 Oct 2026 16:35:36 GMT</lastBuildDate><atom:link href="http://localhost:4567/topic/1975.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Apr 2015 08:02:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Phonebook extensions mismatch on Sun, 29 Sep 2019 00:11:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
Part of your analysis is not correct. The query does not find the number <em>anywhere</em> but just the final bit. The like search has the % (wildcard) at the begining only, then the significant digits as retrieved in the callerid.<br />
I made a quick test with the same data you posted as an example:</p>
<pre><code>MariaDB [asterisk]&gt; select id,phone1,phone2,firstname from visual_phonebook;
+----+----------+----------+-----------+
| id | phone1   | phone2   | firstname |
+----+----------+----------+-----------+
|  1 | 650      | 12345678 | User A    |
|  2 | 12650348 |          | User B    |
+----+----------+----------+-----------+
2 rows in set (0.00 sec)

</code></pre>
<p dir="auto">Then I run the query to match based on callerid '650':</p>
<pre><code>MariaDB [asterisk]&gt; SELECT id,phone1,phone2,concat(firstname,' ',lastname) AS name,company,picture FROM visual_phonebook WHERE (phone1 LIKE '%650' OR phone2 LIKE '%650') AND context='' ORDER BY LENGTH(CONCAT(phone1,phone2)) LIMIT 1;
+----+--------+----------+---------+---------+---------------+
| id | phone1 | phone2   | name    | company | picture       |
+----+--------+----------+---------+---------+---------------+
|  1 | 650    | 12345678 | User A  |         | 1-picture.png |
+----+--------+----------+---------+---------+---------------+
1 row in set (0.00 sec)

</code></pre>
<p dir="auto">As you see, the User A record is retrieved. Not sure why you were getting the incorrect contact, only the LAST part of the number is matched.</p>
<p dir="auto">Regarding normalization of entered numbers in the phonebook, what can I say, people might type spaces, parenthesis, dashes, dots, words, whatever...  Its a bit complicated to do that kind of normalization. In general, whenever phone number lists are involved, users should use 'computer friendly' numbers to get consistent results.</p>
<p dir="auto">So, a quick way to compare numbers would be to strip any non digit character from it, but MySQL lacks that function, however there are some examples posted on StackOverflow, like this one:</p>
<pre><code>DROP FUNCTION IF EXISTS STRIP_NON_DIGIT;
DELIMITER $$
CREATE FUNCTION STRIP_NON_DIGIT(input VARCHAR(255))
   RETURNS VARCHAR(255)
BEGIN
   DECLARE output   VARCHAR(255) DEFAULT '';
   DECLARE iterator INT          DEFAULT 1;
   WHILE iterator &lt; (LENGTH(input) + 1) DO
      IF SUBSTRING(input, iterator, 1) IN ( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ) THEN
         SET output = CONCAT(output, SUBSTRING(input, iterator, 1));
      END IF;
      SET iterator = iterator + 1;
   END WHILE;
   RETURN output;
END
$$
</code></pre>
<p dir="auto">With that function created on MySQL asterisk database, then you can modify the query in vphonebook.php a bit:</p>
<pre><code>SELECT id,phone1,phone2,concat(firstname,' ',lastname) AS name,company,picture FROM visual_phonebook WHERE (STRIP_NON_DIGIT(phone1) LIKE '%650' OR STRIP_NON_DIGIT(phone2) LIKE '%650') AND context='' ORDER BY LENGTH(CONCAT(phone1,phone2)) LIMIT 1;
</code></pre>
<p dir="auto">The thing is that I am not much comfortable having users needing to add a Function in MySQL/MariaDB by default... maybe I am just picky and its not a problem at all. What do you think?</p>
]]></description><link>http://localhost:4567/post/8622</link><guid isPermaLink="true">http://localhost:4567/post/8622</guid><dc:creator><![CDATA[nicolas]]></dc:creator><pubDate>Sun, 29 Sep 2019 00:11:55 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Thu, 23 May 2019 00:12:11 GMT]]></title><description><![CDATA[<p dir="auto">This is still an issue in FOP2  Version: 2.31.23.</p>
<p dir="auto">My above workaround still works, but it would be nice to see a fix coded into the program itself.</p>
]]></description><link>http://localhost:4567/post/8621</link><guid isPermaLink="true">http://localhost:4567/post/8621</guid><dc:creator><![CDATA[OZPHB]]></dc:creator><pubDate>Thu, 23 May 2019 00:12:11 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Wed, 06 Sep 2017 13:08:42 GMT]]></title><description><![CDATA[<p dir="auto">I took a long time to get around to this, but I have had a play, and I think I know what is going on. I have set up a workaround, but I also think I know what is needed for a proper fix.</p>
<p dir="auto"><strong>THE PROBLEM</strong><br />
When a user dialled from an extension (3 digits) the lookup would often incorrectly return a name and picture associated with a different address book entry. This happened when the 3 digit extension number appeared anywhere within the longer phone number.  For example, calling extension 650, would select entry for user with phone number 12346501</p>
<p dir="auto">The issue is that the logic of this select statement did not work:</p>
<pre><code>$res = $db-&gt;consulta("SELECT concat(firstname,' ',lastname) AS name,company,picture FROM visual_phonebook WHERE (phone1 LIKE '%%%s'OR phone2 LIKE '%%%s') AND context='%s' ORDER BY LENGTH(CONCAT(phone1,phone2)) LIMIT 1",$clid_significant,$clid_significant,$context);
</code></pre>
<p dir="auto">The problem is that the LIKE statement was finding all records containing the callerid phone number ANYWHERE within it.  So, when the calling extension is 650, it matched on ALL of 1236504, 1234650, 650, 16501245.  The ORDER BY statement was then supposed to select the shortest match (which should have been the extension).  However, because there are two phone fields, an attempt was made to identify the record with the shortest match by concatenating both numbers in the record, and comparing that length with the concatenated numbers of the other matching records.<br />
The LIMIT 1 statement then picked the first record.</p>
<p dir="auto">This does not work because there is no certainty that the total length of both phone number fields will be shorter for the correct entry.</p>
<p dir="auto">Consider this mini-database:<br />
Calling Extension is 650.<br />
User A  	Phone1:  	650  		Phone2: 12345678<br />
User B 	Phone1:  	12650348 	Phone2:  nul</p>
<p dir="auto">Both of these records are selected by the above statement. They are then compared by adding the two phone fields, and picking the shortest COMBINED length:<br />
User A:  3+8=11<br />
User B: 8+0=8</p>
<p dir="auto">User B record is shorter, so it is selected.  The correct record is User A.</p>
<p dir="auto"><strong>MY WORKAROUND</strong><br />
In Australia, all phone numbers are 10 digits (including area code) – even mobile numbers.<br />
So, I have set the comparison to EQUALS (rather than LIKE) so that I only get one valid match. I have removed the LENGTH comparison altogether.</p>
<pre><code>$res = $db-&gt;consulta("SELECT concat(firstname,' ',lastname) AS name,company,picture FROM visual_phonebook WHERE (phone1 = '%s' OR phone2 = '%s') AND context='%s' LIMIT 1",$clid_significant,$clid_significant,$context);
</code></pre>
<p dir="auto">This works, except that if the visual phone book entry does not include the area code, or includes spaces, the record is not found.</p>
<p dir="auto"><strong>FIX REQUIRED</strong><br />
•	We need to be able to strip the spaces out of the visual phonebook phone number entries when comparing;<br />
•	We need to be able to perform a routine on the visual phonebook phone number entries to only compare the significant digits – in the same way that the script does with the caller id number:</p>
<pre><code>	$significant    = 10;
	$startoffset    = 0;
	if($largo &gt; $significant) {
        $startoffset=$largo-$significant;
    }

    $clid_significant = substr( $decodedClidnum, $startoffset );
</code></pre>
<p dir="auto">When comparing the CLID with the visual phone book entries after stripping spaces and looking at the same significant digits, the EQUALS comparison operator will then work as desired.</p>
<p dir="auto">I am not sufficiently expert to figure out how to do this bit.  Hopefully what I have said helps, and the proper fix will be simple for you <img src="http://localhost:4567/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=9c14fadbfa0" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>http://localhost:4567/post/8620</link><guid isPermaLink="true">http://localhost:4567/post/8620</guid><dc:creator><![CDATA[OZPHB]]></dc:creator><pubDate>Wed, 06 Sep 2017 13:08:42 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Thu, 18 May 2017 01:08:25 GMT]]></title><description><![CDATA[<p dir="auto">Experiment with the SQL query that is used in /var/www/html/fop2/checkdir.php and see if it needs modification:</p>
<p dir="auto">SELECT concat(firstname,' ',lastname) AS name,company,picture FROM visual_phonebook WHERE (phone1 LIKE '%215' OR phone2 LIKE '%215') AND context='' ORDER BY LENGTH(CONCAT(phone1,phone2)) LIMIT 1</p>
<p dir="auto">And see what record you get.. perhaps you have a phone2 field set on your extension (short) but not on your customer, and that makes the order by clause show the customer instead of extension entry? play a bit with it and see, then you can alter checkdir.php to use the correct query.</p>
]]></description><link>http://localhost:4567/post/8619</link><guid isPermaLink="true">http://localhost:4567/post/8619</guid><dc:creator><![CDATA[nicolas]]></dc:creator><pubDate>Thu, 18 May 2017 01:08:25 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Wed, 17 May 2017 03:18:36 GMT]]></title><description><![CDATA[<p dir="auto">Hi Nikolas,<br />
I found this thread because I am experiencing similar issues.</p>
<blockquote>
<p dir="auto">Forgot to add, you can also add your own extensions in the phonebook, so they will match instead of the other customers. If you have an entry with a phone 52 it will have precedence over 3928237352</p>
</blockquote>
<p dir="auto">This does not appear to be the case.  My extensions are 3 digits long.  When there is an address book entry for that extension, say, 215, and there is another address book entry for someone else , say 55334215, the second (longer) entry is matched, not the shorter (more precisely matching) entry.</p>
<p dir="auto">Running FOP2 version 2.31.05 on FreePBX 13.0.191.11.  Any thoughts?</p>
]]></description><link>http://localhost:4567/post/8618</link><guid isPermaLink="true">http://localhost:4567/post/8618</guid><dc:creator><![CDATA[OZPHB]]></dc:creator><pubDate>Wed, 17 May 2017 03:18:36 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Thu, 30 Apr 2015 17:59:09 GMT]]></title><description><![CDATA[<p dir="auto">Forgot to add, you can also add your own extensions in the phonebook, so they will match instead of the other customers. If you have an entry with a phone 52 it will have precedence over 3928237352</p>
<p dir="auto">Best regards,</p>
]]></description><link>http://localhost:4567/post/8617</link><guid isPermaLink="true">http://localhost:4567/post/8617</guid><dc:creator><![CDATA[nicolas]]></dc:creator><pubDate>Thu, 30 Apr 2015 17:59:09 GMT</pubDate></item><item><title><![CDATA[Reply to Phonebook extensions mismatch on Thu, 30 Apr 2015 17:39:28 GMT]]></title><description><![CDATA[<p dir="auto">Edit /var/www/html/fop2/checkdir.php and look for this</p>
<pre><code>if($largo &gt; $significant) {
    $startoffset=$largo-$significant;
}
</code></pre>
<p dir="auto">Before that you can add another if condition, assuming your extensions are 2 digits, you can set it like this</p>
<pre><code>if($largo &gt; 2) {

if($largo &gt; $significant) {
    $startoffset=$largo-$significant;
}
</code></pre>
<p dir="auto">And then put the closing curly bracket just before the Header line:</p>
<pre><code>}
Header( "X-JSON: { \"clidnum\": \"$clidnum\", \"clidname\": \"$clidname\", \"picture\": \"$picture\", \"queue\": \"$fromqueue\", \"url\": \"$url\" }");

</code></pre>
<p dir="auto">That should prevent callerid numbers less than 3 digits long from looking up for matches in the DB.</p>
]]></description><link>http://localhost:4567/post/8616</link><guid isPermaLink="true">http://localhost:4567/post/8616</guid><dc:creator><![CDATA[nicolas]]></dc:creator><pubDate>Thu, 30 Apr 2015 17:39:28 GMT</pubDate></item></channel></rss>