<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. &nbsp;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. &nbsp;Then
when it has the answer it outputs an XML file for use as the directory on a
Cisco 7960 phone. &nbsp;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. &nbsp;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. &nbsp;No matter what I do. &nbsp;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. &nbsp;&nbsp;Most of this code I copied and pasted from php.net
and other places on asterisk lists.<br>
<br>
<span class=GramE>&lt;?<span class=SpellE>php</span></span><br>
<span class=GramE>header(</span>&quot;Content-type: text/xml&quot;); <br>
header(&quot;Connection: close&quot;); <br>
header(&quot;Expires: -1&quot;);<br>
<br>
<span class=GramE>print(</span>&quot;&lt;<span class=SpellE>CiscoIPPhoneDirectory</span>&gt;\n&quot;);<br>
<br>
//SET THE ARRAY WITH MY EXTENSIONS AND NAMES<br>
$<span class=SpellE>exten</span> = array('Name1' =&gt; '201','Name2' =&gt;
'202','Name3' =&gt; '203','Name4' =&gt; '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 =&gt; $phone)<br>
{<br>
$<span class=SpellE>fp</span> = <span class=SpellE><span class=GramE>fsockopen</span></span><span
class=GramE>(</span>&quot;127.0.0.1&quot;, 5038, $<span class=SpellE>errno</span>,
$<span class=SpellE>errstr</span>, 30); //OPEN THE CONNECTION TO THE MANAGER<br>
$out = &quot;Action: Login\r\n&quot;;<br>
$<span class=GramE>out .=</span> &quot;<span class=SpellE>UserName</span>:
user\r\n&quot;;<br>
$<span class=GramE>out .=</span> &quot;Secret: password\r\n\r\n&quot;;<br>
<span class=SpellE><span class=GramE>fwrite</span></span><span class=GramE>(</span>$<span
class=SpellE>fp</span>, $out);<br>
$in = &quot;Action: <span class=SpellE>ExtensionState</span>\r\n&quot;;<br>
$<span class=GramE>in .=</span> &quot;<span class=SpellE>Exten</span>:
$phone\r\n&quot;; //HERE WHERE I AM ENTERING THE EXTENSION TO MONITOR<br>
$<span class=GramE>in .=</span> &quot;Context: intern\r\n&quot;;<br>
$<span class=GramE>in .=</span> &quot;<span class=SpellE>ActionID</span>:
$phone\r\n\r\n&quot;; //I JUST USED THE EXTENSION AS THE ACTION ID, I DON'T
KNOW TO USE IT ANYWAY<br>
$<span class=GramE>in .=</span> &quot;Action: Logoff\r\n\r\n&quot;;<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>, &quot;Status:&quot;);//HERE
IS WHERE I PARSE IT OUT THE &quot;STATUS:&quot; 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 &quot;STATUS:&quot;<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>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Unavailable&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);
<br>
&nbsp;&nbsp;&nbsp;break;<br>
<span class=GramE>case</span> 0:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);
<br>
&nbsp;&nbsp;&nbsp;break;<br>
<span class=GramE>case</span> 1:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Not Available&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 2:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Off Hook&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<br>
<span class=GramE>case</span> 3:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Dialing&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 4:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Ringing&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 5:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is On a Call&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 6:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is On a Call&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>break</span>;<br>
<span class=GramE>case</span> 7:<br>
&nbsp;&nbsp;&nbsp;<span class=GramE>print(</span>&quot;\t&lt;<span
class=SpellE>DirectoryEntry</span>&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Name&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$name is Busy&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Name&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t\t&lt;Telephone&gt;&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;$phone&quot;); <br>
&nbsp;&nbsp;&nbsp;print(&quot;&lt;/Telephone&gt;\n&quot;); <br>
<br>
&nbsp;&nbsp;&nbsp;print(&quot;\t&lt;/<span class=SpellE>DirectoryEntry</span>&gt;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;<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>&quot;&lt;/<span class=SpellE>CiscoIPPhoneDirectory</span>&gt;\n&quot;);<br>
?&gt;<br>
<br>
Any input you may have would be fabulous. &nbsp;<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>