Grandstream Phonebook

Discussion in 'IP Phones' started by alfil2k, Aug 6, 2010.

  1. alfil2k

    Joined:
    Aug 17, 2009
    Messages:
    25
    Likes Received:
    0
    Hi guys,

    I modified a original grandstream phonebook script from Guillermo Salas to add syncronize the address book form elastix and the extension directory. This is code:

    Code:
    <?php
    
    // File: gs_phonebook.php
    // version: 1.0
    // Date: 07-17-2006
    // Author: Shane Steinbeck http://www.steinbeckconsulting.com
    // Description: Realtime XML phonebook from MySQL database for Grandstream GXP-2000 firmware 1.1.1.17
    // Modified by Guillermo Salas <gsalas@mantareys.com> to use the FreePBX database to show the name and
    // extension number.
    
    header("Content-type: text/xml");
    
    /*
    * Aqui nos conectamos a la base de datos de Mysql para traernos  la lista de extensiones
    *
    */
    
    $host = "localhost";
    $user = "root";
    $pass = "eLaStIx.2oo7";
    $database = "asterisk";
    
    $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
    mysql_select_db($database, $linkID) or die("Could not find database.");
    
    $query = "SELECT user, description FROM devices ORDER BY description ASC";
    $resultID = mysql_query($query, $linkID) or die("Data not found.");
    
    
    /*
    * Aqui nos conectamos a la base de datos sqlite3 para traernos la lista de Contactos
    * de la web de elastix
    */
    
    
    $db = new PDO('sqlite:/var/www/db/address_book.db') or die("Could not connect to host.");
    
    $results = $db->query('SELECT * FROM contact')or die("Data not found");
    
    
    /*
    * Aqui comenzamos a crear el xml con los cantactos de ambas listas
    *
    */
    
    $xml_output = "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<AddressBook>\n";
    // parseamos el array de la lista de extension
    for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
    $xml_output .= "\t<Contact>\n";
    $xml_output .= "\t\t<LastName>" . $row['description'] . "</LastName>\n";
    $xml_output .= "\t\t<FirstName></FirstName>\n";
    $xml_output .= "\t\t\t<Phone>\n\t\t\t\t<phonenumber>" . $row['user'] . "</phonenumber>\n";
    $xml_output .= "\t\t\t\t<accountindex>0</accountindex>\n";
    
    $xml_output .=  "\t\t\t</Phone>\n";
    $xml_output .= "\t</Contact>\n";
    }
    // parseamos el array de la lista de contactos de elastix
    while ($row = $results->Fetch()) {
            $xml_output .= "\t<Contact>\n";
            $xml_output .= "\t\t<LastName>" . $row['last_name'] . "</LastName>\n";
            $xml_output .= "\t\t<FirstName>" . $row['name'] . "</FirstName>\n";
            $xml_output .= "\t\t\t<Phone>\n\t\t\t\t<phonenumber>" . $row['telefono'] . "</phonenumber>\n";
            $xml_output .= "\t\t\t\t<accountindex>0</accountindex>\n";
            $xml_output .=  "\t\t\t</Phone>\n";
            $xml_output .= "\t</Contact>\n";
    }
    $xml_output .= "</AddressBook>";
    
    /***************************************************************************************
    
        * Author: Mike
        * Date: 10/03/2006
        * This snipplet will save your xml file to the server for easier updating of your phone.
        * To facilitate automatic updates, add a cron job to run this file at your desired interval (i.e. hourly).
    */
    
    
    $filename = "/tftpboot/gs_phonebook.xml";
    
    $fp = fopen($filename, 'w');
    fwrite($fp, $xml_output);
    fclose($fp);
    
    
    /**************************************************************************************/
    
    echo $xml_output;
    ?>
    
    May be is usefull for somebody.

    Bye.
     
  2. Aerion

    Joined:
    Aug 18, 2012
    Messages:
    50
    Likes Received:
    0
    This is an absolutely wonderful script. Worked like a charm the first time. Great contribution. Thanks!
     

Share This Page