Cisco Phone 7940 7960 Directory Button Script

Sorry its a 7945 and I am using firmware I found here - http://shyju.wordpress.com/tag/cisco-7945-sip/

The sample menu was very useful thanks but although I can make a similar menu when I go into it it shows the raw php code.

Did you chmod +x the file and chown it to asterisk:asterisk

thanks for the script, just to inform any user who is uploading the php file to pbx server, make sure your url doesn’t get redirected to https. if you’re able to parse the database with this file, but unable to get Cisco 79xx to read it, turn rewrite off in httpd file on the web server and restart web service to complete the change.

Sorry for bumping an old thread back up, but I was able to get this working, with a couple of changes, on the 7941 and 7965. However, the displayed directory shows the employee name on one line, then the extension on the second line. I have looked for a solution and changed the PHP code multiple times to get both the name and extension on the same line but have yet to find a solution. Anyone able to point me in the correct direction?

Is it a matter of formatting or something more complex? Maybe include the code you have thus far?

Here is the code. It is the same basic code that was publish by the OP.

<?php header("Content-type: text/xml"); header("Connection: close"); header("Expires: -1"); echo " Cisco IP Telephony Directory Staff Directory";

// Edit this line below with your freepbx mysql server, username and password
// for the database with extensions
$link = mysql_connect(“localhost”,“username”, “password”);

// 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);
if($extension < 800)
{
$newname = explode(" ", $name);
$aUsers[$extension] = “$newname[0] $newname[1]”;
}
}

// 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)
{
echo
"
$name $ext
\n";
}

echo “
”;
// We’re done!
?>

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

Were you ever able to find a solution to this? I’m having the same issue. I have the URL to my directory XML file in the <directoryURL>, but I still only see Missed calls, Received Calls & Placed calls. Nothing else. I’m using the SIP45.8-5-4S firmware. The Services button takes me to my services XML, but directories isn’t…

Anyone get this working? I have 7961, directory only shows the standard items, Missed, Received and placed calls. I have entered the url as mentioned above:

http://192.168.30.10/phonebook/phonebook.php

Still no joy. I can see the directory fine using a browser to the same URL.

Any Help Appreciated

Feed the output of the PHP script thgough “xmllint” and make sure there are no errors. The 7961 should be logging any errors internally, so you might need to look through the phone’s logs to make sure it’s working correctly.