diff --git a/app/contacts/contacts.php b/app/contacts/contacts.php
index 2dbc7aff2f..47b82a07d0 100644
--- a/app/contacts/contacts.php
+++ b/app/contacts/contacts.php
@@ -76,13 +76,13 @@ else {
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
- $sql .= " where group_uuid in ('".implode("','", $user_group_uuids)."') ";
+ $sql .= " where group_uuid in ('".implode("','", array_filter($user_group_uuids))."') ";
$sql .= " and domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= " ) \n";
$sql .= " or \n";
$sql .= " contact_uuid not in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
- $sql .= " where user_uuid = '".$_SESSION['user_uuid']."' ";
+ $sql .= " where group_uuid = '".$_SESSION['group_uuid']."' ";
$sql .= " and domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= " ) \n";
$sql .= ") \n";
@@ -105,7 +105,7 @@ else {
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
- $sql .= " where group_uuid in ('".implode("','", $user_group_uuids)."') ";
+ $sql .= " where group_uuid in ('".implode("','", array_filter($user_group_uuids))."') ";
$sql .= " and domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= " ) \n";
$sql .= " or contact_uuid in ( \n";
diff --git a/app/provision/resources/classes/provision.php b/app/provision/resources/classes/provision.php
index 36faf2b511..63a241d5db 100644
--- a/app/provision/resources/classes/provision.php
+++ b/app/provision/resources/classes/provision.php
@@ -164,6 +164,106 @@ include "root.php";
}
}
+ private function contact_append(&$contacts, &$line, $domain_uuid, $user_uuid, $is_group){
+ $sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
+ $sql .= "c.contact_type, c.contact_category, p.phone_label,";
+ $sql .= "p.phone_number, p.phone_extension, p.phone_primary ";
+ $sql .= "from v_contacts as c, v_contact_phones as p ";
+ $sql .= "where c.contact_uuid = p.contact_uuid ";
+ $sql .= "and p.phone_type_voice = '1' ";
+ $sql .= "and c.domain_uuid = '$domain_uuid' ";
+ if ($is_group) {
+ $sql .= "and c.contact_uuid in ( ";
+ $sql .= " select contact_uuid from v_contact_groups ";
+ $sql .= " where group_uuid in ( ";
+ $sql .= " select group_uuid from v_group_users ";
+ $sql .= " where user_uuid = '$user_uuid' ";
+ $sql .= " and domain_uuid = '$domain_uuid' ";
+ $sql .= " )) ";
+ }
+ else {
+ $sql .= "and c.contact_uuid in ( ";
+ $sql .= " select contact_uuid from v_contact_users ";
+ $sql .= " where user_uuid = '$user_uuid' ";
+ $sql .= " and domain_uuid = '$domain_uuid' ";
+ $sql .= ") ";
+ }
+
+ $prep_statement = $this->db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $user_contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ unset($prep_statement, $sql);
+
+ $temp_contacts = array();
+ foreach ($user_contacts as &$row) {
+ $uuid = $row['contact_uuid'];
+ $phone_label = strtolower($row['phone_label']);
+ $contact_category = strtolower($row['contact_category']);
+
+ if(isset($contacts[$uuid])){
+ continue;
+ }
+
+ if(!isset($temp_contacts[$uuid])){
+ $contact = array();
+ $temp_contacts[$uuid] = &$contact;
+ $contact['category'] = $is_group ? 'groups' : 'users';
+ $contact['contact_uuid'] = $row['contact_uuid'];
+ $contact['contact_type'] = $row['contact_type'];
+ $contact['contact_category'] = $row['contact_category'];
+ $contact['contact_organization'] = $row['contact_organization'];
+ $contact['contact_name_given'] = $row['contact_name_given'];
+ $contact['contact_name_family'] = $row['contact_name_family'];
+ $contact['numbers'] = array();
+ }
+
+ $contact = &$temp_contacts[$uuid];
+ $numbers = &$contact['numbers'];
+
+ if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) {
+ $contact['phone_label'] = $phone_label;
+ $contact['phone_number'] = $row['phone_number'];
+ $contact['phone_extension'] = $row['phone_extension'];
+ }
+
+ $numbers[] = array(
+ line_number => $line['line_number'],
+ phone_label => $phone_label,
+ phone_number => $row['phone_number'],
+ phone_extension => $row['phone_extension'],
+ phone_primary => $row['phone_primary'],
+ );
+
+ $contact['phone_number_' . $phone_label] = $row['phone_number'];
+ unset($contact, $numbers, $uuid, $phone_label);
+ }
+
+ foreach($temp_contacts as $contact_uuid=>&$contact){
+ $contacts[$contact_uuid] = $contact;
+ }
+
+ unset($temp_contacts);
+ }
+
+ private function user_uuid_for_line(&$line, $domain_uuid){
+ $sql = "select user_uuid from v_extension_users ";
+ $sql .= "where extension_uuid in ( ";
+ $sql .= " select extension_uuid from v_extensions ";
+ $sql .= " where (extension = '".$line["user_id"]."' or number_alias = '".$line["user_id"]."') ";
+ $sql .= " and domain_uuid = '$domain_uuid' ";
+ $sql .= ") ";
+ $sql .= "and domain_uuid = '$domain_uuid' ";
+
+ $prep_statement = $this->db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $extension_users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ unset($prep_statement, $sql);
+ foreach ($extension_users as &$row) {
+ return $row["user_uuid"];
+ }
+ return false;
+ }
+
public function render() {
//debug
@@ -499,99 +599,19 @@ include "root.php";
//get the list of contact directly assigned to the user
//get the user_uuid to find the contacts assigned to the user and the groups the user is a member of.
if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0) {
- foreach ($device_lines as &$line) {
- //get the user_uuid assigned to the extension_uuid
- if ($_SESSION['provision']['contact_users']['boolean'] == "true" || $_SESSION['provision']['contact_groups']['boolean'] == "true") {
- $sql = "select user_uuid from v_extension_users ";
- $sql .= "where extension_uuid in ( ";
- $sql .= " select extension_uuid from v_extensions ";
- $sql .= " where (extension = '".$line["user_id"]."' or number_alias = '".$line["user_id"]."') ";
- $sql .= " and domain_uuid = '$domain_uuid' ";
- $sql .= ") ";
- $sql .= "and domain_uuid = '$domain_uuid' ";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $extension_users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- unset($prep_statement);
- foreach ($extension_users as &$row) {
- $user_uuid = $row["user_uuid"];
- }
- }
+ if ($_SESSION['provision']['contact_users']['boolean'] == "true" || $_SESSION['provision']['contact_groups']['boolean'] == "true") {
+ foreach ($device_lines as &$line) {
+ $user_uuid = $this->user_uuid_for_line($line, $domain_uuid);
+ if(!$user_uuid) continue;
- //get the contacts assigned to the groups and add to the contacts array
- if ($_SESSION['provision']['contact_groups']['boolean'] == "true") {
- $sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
- $sql .= "c.contact_type, c.contact_category, p.phone_label,";
- $sql .= "p.phone_number, p.phone_extension ";
- $sql .= "from v_contacts as c, v_contact_phones as p ";
- $sql .= "where c.contact_uuid in ( ";
- $sql .= " select contact_uuid from v_contact_groups ";
- $sql .= " where group_uuid in (' ";
- $sql .= " select group_uuid from v_group_users ";
- $sql .= " where user_uuid = '".$user_uuid."' ";
- $sql .= " and domain_uuid = '$domain_uuid' ";
- $sql .= " ) ";
- $sql .= "and domain_uuid = '$domain_uuid' ";
- $sql .= ") ";
- //echo $sql."\n";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $contact_groups = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- unset($prep_statement);
- foreach ($contact_groups as $row) {
- //get the contact_uuid
- $uuid = $row['contact_uuid'];
- //add the contacts to the contact array
- if (!$this->contact_exists($contacts, $uuid)) {
- $contacts[$uuid]['category'] = 'groups';
- $contacts[$uuid]['contact_uuid'] = $row['contact_uuid'];
- $contacts[$uuid]['contact_type'] = $row['contact_type'];
- $contacts[$uuid]['contact_category'] = $row['contact_category'];
- $contacts[$uuid]['contact_organization'] = $row['contact_organization'];
- $contacts[$uuid]['contact_name_given'] = $row['contact_name_given'];
- $contacts[$uuid]['contact_name_family'] = $row['contact_name_family'];
- $contacts[$uuid]['phone_label'] = $row['phone_label'];
- $contacts[$uuid]['phone_number'] = $row['phone_number'];
- $contacts[$uuid]['phone_extension'] = $row['phone_extension'];
- }
+ //get the contacts assigned to the groups and add to the contacts array
+ if ($_SESSION['provision']['contact_groups']['boolean'] == "true") {
+ $this->contact_append($contacts, $line, $domain_uuid, $user_uuid, true);
}
- }
- //get the contacts assigned to the user and add to the contacts array
- if ($_SESSION['provision']['contact_users']['boolean'] == "true") {
- $sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
- $sql .= "c.contact_type, c.contact_category, p.phone_label,";
- $sql .= "p.phone_number, p.phone_extension ";
- $sql .= "from v_contacts as c, v_contact_phones as p ";
- $sql .= "where c.contact_uuid in ( ";
- $sql .= " select contact_uuid from v_contact_users ";
- $sql .= " where user_uuid = '".$user_uuid."' ";
- $sql .= " and domain_uuid = '$domain_uuid' ";
- $sql .= ") ";
- $sql .= "and c.contact_uuid = p.contact_uuid ";
- $sql .= "and p.phone_type_voice = '1' ";
- $sql .= "and c.domain_uuid = '$domain_uuid' ";
- //echo $sql."\n";
- $prep_statement = $this->db->prepare(check_sql($sql));
- $prep_statement->execute();
- $user_contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- unset($prep_statement);
- foreach ($user_contacts as $row) {
- //get the contact_uuid
- $uuid = $row['contact_uuid'];
- //add the contacts to the contact array
- if (!$this->contact_exists($contacts, $uuid)) {
- $contacts[$uuid]['category'] = 'users';
- $contacts[$uuid]['contact_uuid'] = $row['contact_uuid'];
- $contacts[$uuid]['contact_type'] = $row['contact_type'];
- $contacts[$uuid]['contact_category'] = $row['contact_category'];
- $contacts[$uuid]['contact_organization'] = $row['contact_organization'];
- $contacts[$uuid]['contact_name_given'] = $row['contact_name_given'];
- $contacts[$uuid]['contact_name_family'] = $row['contact_name_family'];
- $contacts[$uuid]['phone_label'] = $row['phone_label'];
- $contacts[$uuid]['phone_number'] = $row['phone_number'];
- $contacts[$uuid]['phone_extension'] = $row['phone_extension'];
- }
+ //get the contacts assigned to the user and add to the contacts array
+ if ($_SESSION['provision']['contact_users']['boolean'] == "true") {
+ $this->contact_append($contacts, $line, $domain_uuid, $user_uuid, false);
}
}
}
diff --git a/resources/templates/provision/yealink/t42g/directory.xml b/resources/templates/provision/yealink/t42g/directory.xml
new file mode 100644
index 0000000000..a05b029e18
--- /dev/null
+++ b/resources/templates/provision/yealink/t42g/directory.xml
@@ -0,0 +1,74 @@
+
+{foreach $contacts as $row}
+{if $smarty.get.contacts == "users" && $row.category == "users"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "groups" && $row.category == "groups"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "extensions" && $row.category == "extensions"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+
+{elseif $smarty.get.contacts == "all"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {if $row.category == "extensions"}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+ {else}
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+ {/if}
+
+{/if}
+{/foreach}
+
\ No newline at end of file
diff --git a/resources/templates/provision/yealink/t42g/directory_extensions.xml b/resources/templates/provision/yealink/t42g/directory_extensions.xml
deleted file mode 100644
index 7bd20d7513..0000000000
--- a/resources/templates/provision/yealink/t42g/directory_extensions.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-{assign var=x value=1}
-{foreach $contacts as $row}
-
-{if $row.contact_name_given != ""}
- {$row.contact_name_given} {$row.contact_name_family}
-{else}
- {$row.effective_caller_id_name}
-{/if}
-{if $row.number_alias != ""}
- {$row.number_alias}
-{else}
- {$row.phone_extension}
-{/if}
-
-{assign var=x value=$x+1}
-{/foreach}
-
diff --git a/resources/templates/provision/yealink/t42g/y000000000029.cfg b/resources/templates/provision/yealink/t42g/y000000000029.cfg
index a3ff962818..f1209399da 100644
--- a/resources/templates/provision/yealink/t42g/y000000000029.cfg
+++ b/resources/templates/provision/yealink/t42g/y000000000029.cfg
@@ -557,8 +557,20 @@ dialplan.item.1 =
#remote_phonebook.data.X.url =
#remote_phonebook.data.X.name =
-remote_phonebook.data.1.url = {$yealink_remote_phone_book_url}
-remote_phonebook.data.1.name = Local Extensions
+remote_phonebook.data.1.url = {$yealink_remote_phone_book_url_1}
+remote_phonebook.data.1.name = {$yealink_remote_phone_book_name_1}
+
+remote_phonebook.data.2.url = {$yealink_remote_phone_book_url_2}
+remote_phonebook.data.2.name = {$yealink_remote_phone_book_name_2}
+
+remote_phonebook.data.3.url = {$yealink_remote_phone_book_url_3}
+remote_phonebook.data.3.name = {$yealink_remote_phone_book_name_3}
+
+remote_phonebook.data.4.url = {$yealink_remote_phone_book_url_4}
+remote_phonebook.data.4.name = {$yealink_remote_phone_book_name_4}
+
+remote_phonebook.data.5.url = {$yealink_remote_phone_book_url_5}
+remote_phonebook.data.5.name = {$yealink_remote_phone_book_name_5}
#######################################################################################
## Network Directory ##
diff --git a/resources/templates/provision/yealink/t46g/directory.xml b/resources/templates/provision/yealink/t46g/directory.xml
new file mode 100644
index 0000000000..a05b029e18
--- /dev/null
+++ b/resources/templates/provision/yealink/t46g/directory.xml
@@ -0,0 +1,74 @@
+
+{foreach $contacts as $row}
+{if $smarty.get.contacts == "users" && $row.category == "users"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "groups" && $row.category == "groups"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "extensions" && $row.category == "extensions"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+
+{elseif $smarty.get.contacts == "all"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {if $row.category == "extensions"}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+ {else}
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+ {/if}
+
+{/if}
+{/foreach}
+
\ No newline at end of file
diff --git a/resources/templates/provision/yealink/t46g/directory_extensions.xml b/resources/templates/provision/yealink/t46g/directory_extensions.xml
deleted file mode 100644
index 7bd20d7513..0000000000
--- a/resources/templates/provision/yealink/t46g/directory_extensions.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-{assign var=x value=1}
-{foreach $contacts as $row}
-
-{if $row.contact_name_given != ""}
- {$row.contact_name_given} {$row.contact_name_family}
-{else}
- {$row.effective_caller_id_name}
-{/if}
-{if $row.number_alias != ""}
- {$row.number_alias}
-{else}
- {$row.phone_extension}
-{/if}
-
-{assign var=x value=$x+1}
-{/foreach}
-
diff --git a/resources/templates/provision/yealink/t46g/y000000000028.cfg b/resources/templates/provision/yealink/t46g/y000000000028.cfg
index e32b85a9bc..00851fa87b 100644
--- a/resources/templates/provision/yealink/t46g/y000000000028.cfg
+++ b/resources/templates/provision/yealink/t46g/y000000000028.cfg
@@ -547,8 +547,20 @@ dialplan.item.1 =
#remote_phonebook.data.X.url =
#remote_phonebook.data.X.name =
-remote_phonebook.data.1.url = {$yealink_remote_phone_book_url}
-remote_phonebook.data.1.name = Local Extensions
+remote_phonebook.data.1.url = {$yealink_remote_phone_book_url_1}
+remote_phonebook.data.1.name = {$yealink_remote_phone_book_name_1}
+
+remote_phonebook.data.2.url = {$yealink_remote_phone_book_url_2}
+remote_phonebook.data.2.name = {$yealink_remote_phone_book_name_2}
+
+remote_phonebook.data.3.url = {$yealink_remote_phone_book_url_3}
+remote_phonebook.data.3.name = {$yealink_remote_phone_book_name_3}
+
+remote_phonebook.data.4.url = {$yealink_remote_phone_book_url_4}
+remote_phonebook.data.4.name = {$yealink_remote_phone_book_name_4}
+
+remote_phonebook.data.5.url = {$yealink_remote_phone_book_url_5}
+remote_phonebook.data.5.name = {$yealink_remote_phone_book_name_5}
#######################################################################################
## Network Directory ##
diff --git a/resources/templates/provision/yealink/t48g/directory.xml b/resources/templates/provision/yealink/t48g/directory.xml
new file mode 100644
index 0000000000..a05b029e18
--- /dev/null
+++ b/resources/templates/provision/yealink/t48g/directory.xml
@@ -0,0 +1,74 @@
+
+{foreach $contacts as $row}
+{if $smarty.get.contacts == "users" && $row.category == "users"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "groups" && $row.category == "groups"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "extensions" && $row.category == "extensions"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+
+{elseif $smarty.get.contacts == "all"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {if $row.category == "extensions"}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+ {else}
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+ {/if}
+
+{/if}
+{/foreach}
+
\ No newline at end of file
diff --git a/resources/templates/provision/yealink/t48g/directory_extensions.xml b/resources/templates/provision/yealink/t48g/directory_extensions.xml
deleted file mode 100644
index 7bd20d7513..0000000000
--- a/resources/templates/provision/yealink/t48g/directory_extensions.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-{assign var=x value=1}
-{foreach $contacts as $row}
-
-{if $row.contact_name_given != ""}
- {$row.contact_name_given} {$row.contact_name_family}
-{else}
- {$row.effective_caller_id_name}
-{/if}
-{if $row.number_alias != ""}
- {$row.number_alias}
-{else}
- {$row.phone_extension}
-{/if}
-
-{assign var=x value=$x+1}
-{/foreach}
-
diff --git a/resources/templates/provision/yealink/t48g/y000000000035.cfg b/resources/templates/provision/yealink/t48g/y000000000035.cfg
index 3171e91634..168f3026c9 100644
--- a/resources/templates/provision/yealink/t48g/y000000000035.cfg
+++ b/resources/templates/provision/yealink/t48g/y000000000035.cfg
@@ -548,8 +548,20 @@ dialplan.item.1 =
#remote_phonebook.data.X.url =
#remote_phonebook.data.X.name =
-remote_phonebook.data.1.url = {$yealink_remote_phone_book_url}
-remote_phonebook.data.1.name = Local Extensions
+remote_phonebook.data.1.url = {$yealink_remote_phone_book_url_1}
+remote_phonebook.data.1.name = {$yealink_remote_phone_book_name_1}
+
+remote_phonebook.data.2.url = {$yealink_remote_phone_book_url_2}
+remote_phonebook.data.2.name = {$yealink_remote_phone_book_name_2}
+
+remote_phonebook.data.3.url = {$yealink_remote_phone_book_url_3}
+remote_phonebook.data.3.name = {$yealink_remote_phone_book_name_3}
+
+remote_phonebook.data.4.url = {$yealink_remote_phone_book_url_4}
+remote_phonebook.data.4.name = {$yealink_remote_phone_book_name_4}
+
+remote_phonebook.data.5.url = {$yealink_remote_phone_book_url_5}
+remote_phonebook.data.5.name = {$yealink_remote_phone_book_name_5}
#######################################################################################
## Network Directory ##
diff --git a/resources/templates/provision/yealink/t49g/directory.xml b/resources/templates/provision/yealink/t49g/directory.xml
new file mode 100644
index 0000000000..a05b029e18
--- /dev/null
+++ b/resources/templates/provision/yealink/t49g/directory.xml
@@ -0,0 +1,74 @@
+
+{foreach $contacts as $row}
+{if $smarty.get.contacts == "users" && $row.category == "users"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "groups" && $row.category == "groups"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+
+{elseif $smarty.get.contacts == "extensions" && $row.category == "extensions"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+
+{elseif $smarty.get.contacts == "all"}
+
+ {if $row.contact_name_given != ""}
+ {$row.contact_name_given} {$row.contact_name_family}
+ {else}
+ {$row.effective_caller_id_name}
+ {/if}
+
+ {if $row.category == "extensions"}
+ {if $row.phone_number != ""}
+ {$row.phone_number}
+ {else}
+ {$row.phone_extension}
+ {/if}
+ {else}
+ {foreach $row.numbers as $number}
+ {if $number.phone_number != ""}
+ {$number.phone_number}
+ {else}
+ {$number.phone_extension}
+ {/if}
+ {/foreach}
+ {/if}
+
+{/if}
+{/foreach}
+
\ No newline at end of file
diff --git a/resources/templates/provision/yealink/t49g/directory_extensions.xml b/resources/templates/provision/yealink/t49g/directory_extensions.xml
deleted file mode 100644
index 7bd20d7513..0000000000
--- a/resources/templates/provision/yealink/t49g/directory_extensions.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-{assign var=x value=1}
-{foreach $contacts as $row}
-
-{if $row.contact_name_given != ""}
- {$row.contact_name_given} {$row.contact_name_family}
-{else}
- {$row.effective_caller_id_name}
-{/if}
-{if $row.number_alias != ""}
- {$row.number_alias}
-{else}
- {$row.phone_extension}
-{/if}
-
-{assign var=x value=$x+1}
-{/foreach}
-
diff --git a/resources/templates/provision/yealink/t49g/y000000000051.cfg b/resources/templates/provision/yealink/t49g/y000000000051.cfg
index 0be55727d7..fd7b637bcd 100644
--- a/resources/templates/provision/yealink/t49g/y000000000051.cfg
+++ b/resources/templates/provision/yealink/t49g/y000000000051.cfg
@@ -557,8 +557,20 @@ dialplan.item.1 =
#remote_phonebook.data.X.url =
#remote_phonebook.data.X.name =
-remote_phonebook.data.1.url = {$yealink_remote_phone_book_url}
-remote_phonebook.data.1.name = Local Extensions
+remote_phonebook.data.1.url = {$yealink_remote_phone_book_url_1}
+remote_phonebook.data.1.name = {$yealink_remote_phone_book_name_1}
+
+remote_phonebook.data.2.url = {$yealink_remote_phone_book_url_2}
+remote_phonebook.data.2.name = {$yealink_remote_phone_book_name_2}
+
+remote_phonebook.data.3.url = {$yealink_remote_phone_book_url_3}
+remote_phonebook.data.3.name = {$yealink_remote_phone_book_name_3}
+
+remote_phonebook.data.4.url = {$yealink_remote_phone_book_url_4}
+remote_phonebook.data.4.name = {$yealink_remote_phone_book_name_4}
+
+remote_phonebook.data.5.url = {$yealink_remote_phone_book_url_5}
+remote_phonebook.data.5.name = {$yealink_remote_phone_book_name_5}
#######################################################################################
## Network Directory ##