Cisco Phone 7940 7960 Directory Button Script

Here’s my version of the script.It creates a CiscoIPPhoneDirectory XML structure. I assigned it to the “services” button, and it comes up as a nice menu;

<?php

// Edit this line below with your freepbx mysql server, username and password 
// for the database with extensions

$link = mysql_connect("localhost","freepbxuser", "");

// Our SQL Query to get name and extension columns
$sGetUsers = "SELECT name, extension from asterisk.users ORDER BY name";
$sGetUsersR = mysql_query($sGetUsers) or die("Could not load users:
$sGetUsers
" . mysql_error());

// Init the variables we need
$aUsers = array();
$line = "";

// Step through the results of our SQL query, reverse the name and add 
// a comma "John Doe" is now "Doe, John"

// The If statement is NOT needed if you dont have special extensions 
// you dont want displayed

while ($line = mysql_fetch_array($sGetUsersR, MYSQL_ASSOC))
{
        extract($line);
        // $newname = explode(" ", $name);
        // $aUsers[$extension] = "$newname[1], $newname[0]";
        $aUsers[$extension] = "$name";
}

print("<CiscoIPPhoneDirectory>");
print("\n\t<Title>Company Directory</Title>");
        //print("\t<Prompt>Prompt</Prompt>\n");
        // asort preserves our key/index
        asort($aUsers);

        // Step trhough the array we built from our SQL and write our XML tagging
        foreach($aUsers as $ext => $name)
        {
                print("\n\t<DirectoryEntry>\n");

                print("\t\t<Name>");
                print($name);
                print("</Name>\n");

                print("\t\t<Telephone>");
                print($ext);
                print("</Telephone>");

                print("\n\t</DirectoryEntry>");
        }

print("\n</CiscoIPPhoneDirectory>\n");

?>

Dan