Using FOP2 Phonebook with LDAP server
-
FOP2 has its own phonebook/contacts and scripts to tie that with the switchboard itself. Code is there for users to modify if they so like/need.
The dial box will query the visual_phonebook table that the contacts app uses, but it can be modified, as I expalined originally, as it is a standard php script. You are free to modify it to query whatever you want instead of FOP2 tables.In any case, that feature is not on the roadmap, you can purchase development time if you want us to work on this particular integration, or just look at doing it yourself, it is just one php script (vphonebook.php) that is used for querying contacts from the dial box.
-
-
-
Hi,
Ideallly you should work directly by modifying the vphonebook.php script and adding your custom query to it, replacing or not the ones provided. Return format is a json array like:[ {"name":"","value":"John <1234567>"}, {"name":"","value":"Peter <7654321>"} ] -
-
I have wrote a little script to query on LDAP and formating the result in a json array but not working when adding it in vphonebook.php
<?php // ---------------------------- VARIABLES ---------------------------- $ldapURL = 'LDAP_URL'; $ldapPort = 389; // Port par defaut = 389 $ldapVersionProtocole = 3; // Version par defaut = 2 $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM'; $ldapMotDePasse = 'PASSWD'; // ---------------------------- CONNEXION ---------------------------- $ldap = ldap_connect($ldapURL, $ldapPort); if (false === $ldap) die('Echec de la connexion'); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole); $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse); if (false === $retour) die('Echec de l\'authentification (ou de la connexion)'); // ---------------------------- RECHERCHE ---------------------------- $dn = "OU=PERSON,DC=DOMAIN,DC=COM"; $recherche = "UID=*$texto*"; $requete = ldap_search($ldap, $dn, $recherche); if (false === $requete) die('La recherche a echoue'); // ---------------------------- RESULTAT ---------------------------- $resultats = ldap_get_entries($ldap, $requete); $myArray = array(); for ($i=0; $i<$resultats["count"]; $i++) { $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}"; } // ---------------------------- FORMATAGE ---------------------------- //print_r($myArray); $results = json_encode($myArray,JSON_UNESCAPED_UNICODE); $results = str_replace('\"', '"', $results); $results = str_replace('"{', '{', $results); $results = str_replace('}"', '}', $results); // ---------------------------- FERMETURE ---------------------------- ldap_close($ldap); return $results; ?> -
-
Thank Nicolas for your help.
Finally as I only use ldap for my search my vphonebook.php look like<?php $texto = $_REQUEST['term']; // ---------------------------- VARIABLES ---------------------------- $ldapURL = 'LDAP_URL'; $ldapPort = 389; // Port par defaut = 389 $ldapVersionProtocole = 3; // Version par defaut = 2 $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM'; $ldapMotDePasse = 'PASSWD'; // ---------------------------- CONNEXION ---------------------------- $ldap = ldap_connect($ldapURL, $ldapPort); if (false === $ldap) die('Echec de la connexion'); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole); $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse); if (false === $retour) die('Echec de l\'authentification (ou de la connexion)'); // ---------------------------- RECHERCHE ---------------------------- $dn = "OU=PERSON,DC=DOMAIN,DC=COM"; $recherche = "UID=*$texto*"; $requete = ldap_search($ldap, $dn, $recherche); if (false === $requete) die('La recherche a echoue'); // ---------------------------- RESULTAT ---------------------------- $resultats = ldap_get_entries($ldap, $requete); $myArray = array(); for ($i=0; $i<$resultats["count"]; $i++) { $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}"; } // ---------------------------- FORMATAGE ---------------------------- //print_r($myArray); $results = json_encode($myArray,JSON_UNESCAPED_UNICODE); $results = str_replace('\"', '"', $results); $results = str_replace('"{', '{', $results); $results = str_replace('}"', '}', $results); // ---------------------------- FERMETURE ---------------------------- ldap_close($ldap); echo $results; ?> -
Here is the full fixed code:
<?php $texto = $_REQUEST['term']; // ---------------------------- VARIABLES ---------------------------- $ldapURL = 'LDAP_URL'; $ldapPort = 389; // Port par defaut = 389 $ldapVersionProtocole = 3; // Version par defaut = 2 $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM'; $ldapMotDePasse = 'PASSWD'; // ---------------------------- CONNEXION ---------------------------- $ldap = ldap_connect($ldapURL, $ldapPort); if (false === $ldap) die('Echec de la connexion'); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole); $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse); if (false === $retour) die('Echec de l\'authentification (ou de la connexion)'); // ---------------------------- RECHERCHE ---------------------------- $dn = "OU=PERSON,DC=DOMAIN,DC=COM"; $recherche = "UID=*$texto*"; $requete = ldap_search($ldap, $dn, $recherche); if (false === $requete) die('La recherche a echoue'); // ---------------------------- RESULTAT ---------------------------- $resultats = ldap_get_entries($ldap, $requete); $myArray = array(); for ($i=0; $i<$resultats["count"]; $i++) { $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}"; } // ---------------------------- FORMATAGE ---------------------------- //print_r($myArray); $results = json_encode($myArray,JSON_UNESCAPED_UNICODE); $results = str_replace('\"', '"', $results); $results = str_replace('"{', '{', $results); $results = str_replace('}"', '}', $results); // ---------------------------- FERMETURE ---------------------------- ldap_close($ldap); echo $results; ?> -
Yes! Thanks for pointing my fault. As I'm not using this query in a function, I forgot changing return $results; to echo $results;
I firstly trying to add this code inside the original in a function with no luck. Then I have blank vphonebook.php and fill it with this code only but still not working. Finally Nicolas help me to fix the problem.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
