<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 10">
<meta name=Originator content="Microsoft Word 10">
<link rel=File-List href="cid:filelist.xml@01C508FB.2A1C7A10">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:DoNotRelyOnCSS/>
</o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:DocumentKind>DocumentEmail</w:DocumentKind>
<w:EnvelopeVis/>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;
        mso-font-charset:0;
        mso-generic-font-family:swiss;
        mso-font-pitch:variable;
        mso-font-signature:536871559 0 0 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {mso-style-parent:"";
        margin:0in;
        margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:12.0pt;
        font-family:"Times New Roman";
        mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;
        text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;
        text-underline:single;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        mso-style-noshow:yes;
        mso-ansi-font-size:10.0pt;
        mso-bidi-font-size:10.0pt;
        font-family:Arial;
        mso-ascii-font-family:Arial;
        mso-hansi-font-family:Arial;
        mso-bidi-font-family:Arial;
        color:windowtext;}
span.SpellE
        {mso-style-name:"";
        mso-spl-e:yes;}
span.GramE
        {mso-style-name:"";
        mso-gram-e:yes;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;
        mso-header-margin:.5in;
        mso-footer-margin:.5in;
        mso-paper-source:0;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
        {mso-style-name:"Table Normal";
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-parent:"";
        mso-padding-alt:0in 5.4pt 0in 5.4pt;
        mso-para-margin:0in;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman";}
</style>
<![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoNormal><font size=1 color=black face=Verdana><span
style='font-size:8.5pt;font-family:Verdana;color:black'>This is my first
attempt to write software of any sort. What I am trying to is to use a .<span
class=SpellE>php</span> page to query asterisk Manager and get the <span
class=SpellE>ExtensionState</span> for each particular extension. Then
when it has the answer it outputs an XML file for use as the directory on a
Cisco 7960 phone. What I am thinking is that when the user hits the
directory button to <span class=SpellE>veiw</span> the directory that is at
this URL it will show the directory, but based on <span class=SpellE>teh</span>
<span class=SpellE>extenstion</span> status it will show whether that person in
available or not. It should work pretty <span class=GramE>good</span> as
a <span class=SpellE>blf</span>, you just have to request the directory again
to get an updated status of everyone that you are monitoring.<br>
<br>
The problem I am having is that the only status that I can seem to get from <span
class=SpellE>ExtensionState</span> is -1. No matter what I do. I
don't know why this is happening and I have fiddled with the context how the
extension is listed, however I still <span class=SpellE>jsut</span> get -1 as a
response.<br>
<br>
It is my understanding that these are the possible <span class=GramE>status's</span>:<br>
<br>
-1 Channel is unavailable or does not exit<br>
0 Channel is down and available <br>
1 Channel is down, but reserved <br>
2 Channel is off hook <br>
3 Digits (or equivalent) have been dialed <br>
4 Line is ringing <br>
5 Remote end is ringing <br>
6 Line is up <br>
7 Line is busy<br>
<br>
Here is my <span class=SpellE>php</span> code that logs into the manager <span
class=SpellE><span class=GramE>api</span></span> and then runs through an array
of my extensions and names and returns the XML file with name field updated
with the status:<br>
<br>
I put some comments in with //'s so that you can get an idea as to what I was
thinking here. Most of this code I copied and pasted from php.net
and other places on asterisk lists.<br>
<br>
<span class=GramE><?<span class=SpellE>php</span></span><br>
<span class=GramE>header(</span>"Content-type: text/xml"); <br>
header("Connection: close"); <br>
header("Expires: -1");<br>
<br>
<span class=GramE>print(</span>"<<span class=SpellE>CiscoIPPhoneDirectory</span>>\n");<br>
<br>
//SET THE ARRAY WITH MY EXTENSIONS AND NAMES<br>
$<span class=SpellE>exten</span> = array('Name1' => '201','Name2' =>
'202','Name3' => '203','Name4' => '204');<br>
<br>
//RUN THROUGHT THE ARRAY TO GET THE STATUS OF EACH EXTENSION<br>
<span class=SpellE><span class=GramE>foreach</span></span><span class=GramE>(</span>$<span
class=SpellE>exten</span> as $name => $phone)<br>
{<br>
$<span class=SpellE>fp</span> = <span class=SpellE><span class=GramE>fsockopen</span></span><span
class=GramE>(</span>"127.0.0.1", 5038, $<span class=SpellE>errno</span>,
$<span class=SpellE>errstr</span>, 30); //OPEN THE CONNECTION TO THE MANAGER<br>
$out = "Action: Login\r\n";<br>
$<span class=GramE>out .=</span> "<span class=SpellE>UserName</span>:
user\r\n";<br>
$<span class=GramE>out .=</span> "Secret: password\r\n\r\n";<br>
<span class=SpellE><span class=GramE>fwrite</span></span><span class=GramE>(</span>$<span
class=SpellE>fp</span>, $out);<br>
$in = "Action: <span class=SpellE>ExtensionState</span>\r\n";<br>
$<span class=GramE>in .=</span> "<span class=SpellE>Exten</span>:
$phone\r\n"; //HERE WHERE I AM ENTERING THE EXTENSION TO MONITOR<br>
$<span class=GramE>in .=</span> "Context: intern\r\n";<br>
$<span class=GramE>in .=</span> "<span class=SpellE>ActionID</span>:
$phone\r\n\r\n"; //I JUST USED THE EXTENSION AS THE ACTION ID, I DON'T
KNOW TO USE IT ANYWAY<br>
$<span class=GramE>in .=</span> "Action: Logoff\r\n\r\n";<br>
<span class=SpellE><span class=GramE>fwrite</span></span><span class=GramE>(</span>$<span
class=SpellE>fp,$in</span>);<br>
$<span class=SpellE>fo</span> = <span class=SpellE><span class=GramE>fgets</span></span><span
class=GramE>(</span>$<span class=SpellE>fp</span>, 1024);//HERE IS WHERE I GET
TEH ACTUAL RESPONSE FROM ASTERISK<br>
$<span class=SpellE>fq</span> = <span class=SpellE><span class=GramE>strstr</span></span><span
class=GramE>(</span>$<span class=SpellE>fo</span>, "Status:");//HERE
IS WHERE I PARSE IT OUT THE "STATUS:" PART<br>
$<span class=SpellE>fr</span> = <span class=SpellE><span class=GramE>substr</span></span><span
class=GramE>(</span>$<span class=SpellE>fq</span>, 8, 9);//THESE ARE THE TWO
DIGITS AFTER "STATUS:"<br>
$<span class=SpellE>fs</span> = <span class=GramE>trim(</span>$<span
class=SpellE>fr</span>);//HERE I TRIM OFF THE WHITE SPACE IF THE NUMBER IS NOT
NEGATIVE<br>
<span class=GramE>switch(</span>$<span class=SpellE>fs</span>)//HERE I RUN A
SWITCH FUNCTION AND EACH CASE CORRESPONDES TO THE VALUE FROM THE STATUS AND
PRINTS THE XML ACCORDINGLY<br>
{<br>
<span class=GramE>case</span> -1:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Unavailable"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");
<br>
break;<br>
<span class=GramE>case</span> 0:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name"); <br>
print("</Name>\n"); <br>
<br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");
<br>
break;<br>
<span class=GramE>case</span> 1:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Not Available"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 2:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Off Hook"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<br>
<span class=GramE>case</span> 3:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Dialing"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 4:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Ringing"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 5:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is On a Call"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 6:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is On a Call"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 7:<br>
<span class=GramE>print(</span>"\t<<span
class=SpellE>DirectoryEntry</span>>\n"); <br>
<br>
print("\t\t<Name>"); <br>
print("$name is Busy"); <br>
print("</Name>\n"); <br>
<br>
print("\t\t<Telephone>"); <br>
print("$phone"); <br>
print("</Telephone>\n"); <br>
<br>
print("\t</<span class=SpellE>DirectoryEntry</span>>\n");<br>
<span class=GramE>break</span>;<br>
}<br>
}<br>
<span class=SpellE><span class=GramE>fclose</span></span><span class=GramE>(</span>$<span
class=SpellE>fp</span>);<br>
<span class=GramE>print(</span>"</<span class=SpellE>CiscoIPPhoneDirectory</span>>\n");<br>
?><br>
<br>
Any input you may have would be fabulous. <span class=GramE>please</span>
forgive my <span class=SpellE>php</span> skills, it is everything I have
learned in about one day. <br>
<br>
Thanks!<br>
<br>
Dax Ewbank</span></font><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p></o:p></span></font></p>
</div>
</body>
</html>