My Collab Lab

mycollablab.org

XML Phone Directory

April 15, 2017 Voice

I had a colleuge ask about running a small ASP web site on a Linux Distro. My first question was why, and echoed my concern of spending more time troubleshooting than to just rewrite the app. With that I went ahead and rewrote the ap to PHP. Its a like for like app so just moving what feaures were there. The origional app provided an XML file that contained a contained the phone directory and then a couple of scripts that parsed that directory for the phone to display. Obviuosly the first additon to start looking at would be an editable site that would allow the user to edit the XML without messing with the XML itself. We’ll see.

XML Directory entries


<?xml version="1.0"?>
<CiscoIPPhoneDirectory>
	<DirectoryEntry>
		<Name>Doe, John</Name>
		<Telephone>5551234567</Telephone>
	</DirectoryEntry>
	<DirectoryEntry>
		<Name>Smith, Jane</Name>
		<Telephone>5551234567</Telephone>
	</DirectoryEntry>
	<DirectoryEntry>
		<Name>williams, bob</Name>
		<Telephone>1000</Telephone>
	</DirectoryEntry>
</CiscoIPPhoneDirectory>

php code for phoneb>

);
$host_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$host_url = preg_replace('/\?.*/','',$host_url);
echo '<?xml version="1.0"?>';

function searchXML($first_name,$last_name, $array) {
    $search_directory = array();
    foreach ( $array as $dir_entry ) {

       if ( preg_match('/, '.strtolower($first_name).'.*$/',strtolower($dir_entry['Name'])) &&
        preg_match('/^'.strtolower($last_name).'.*/',strtolower($dir_entry['Name'])) ) {
           $search_directory[] = array(  "Name"=>$dir_entry['Name']
                                           ,"Telephone"=>$dir_entry['Telephone']);
       }
    }
   return $search_directory;
}

if ( ! isset($_GET['f']) && ! isset($_GET['l'])  ) {

echo<<<XML
<CiscoIPPhoneInput>
<Title>Directory Search</Title>
<Prompt>Enter search parameters...</Prompt>
<URL>http://172.20.10.142/phonedirectory/directory.php</URL>
<InputItem>
<DisplayName>First Name</DisplayName>
<QueryStringParam>f</QueryStringParam>
<InputFlags>U</InputFlags>
<DefaultValue></DefaultValue>
</InputItem>
<InputItem>
<DisplayName>Last Name</DisplayName>
<QueryStringParam>l</QueryStringParam>
<InputFlags>U</InputFlags>
<DefaultValue></DefaultValue>
</InputItem>
<SoftKeyItem>
<Position>1</Position>
<Name>Search</Name>
<URL>SoftKey:Submit</URL>
</SoftKeyItem>
<SoftKeyItem>
<Position>2</Position>
<Name>&lt;&lt;</Name>
<URL>SoftKey:&lt;&lt;</URL>
</SoftKeyItem>
<SoftKeyItem>
<Position>3</Position>
<Name>Cancel</Name>
<URL>SoftKey:Cancel</URL>
</SoftKeyItem>
</CiscoIPPhoneInput>

XML;

} else {

    $directory = json_decode(json_encode((array)simplexml_load_string(file_get_contents('./directory.xml'))),1);

    if ( isset($_GET['f']) ) {
        $f = $_GET['f'];
    } else {
        $f = "";
    }
    if ( isset($_GET['l']) ) {
        $l = $_GET['l'];
    } else {
        $l = "";
    }

    $results = searchXML($f,$l,$directory['DirectoryEntry']);

    echo "\n<CiscoIPPhoneDirectory>\n";

    $result_count = sizeof($results);
    if (  $result_count == 0 ) {
        echo "<Prompt>No Records Found</Prompt>";
    } else {
        if  ( isset($_GET['page']) ){
            $page = $_GET['page'];
        } else {
            $page = 1;
        }

        echo "<Title>Search Results</Title>\n<Prompt>Page ".$page." of ".ceil( $result_count / 32 )."</Prompt>\n";

        $i = ($page * 32) - 31;
        while ( $i <= (32 * $page) && $i <= $result_count ){
            echo "<DirectoryEntry>\n";
            echo "\t<Name>".$results[$i - 1]['Name']."</Name>\n";
            echo "\t<Telephone>".$results[$i - 1]['Telephone']."</Telephone>\n";
            echo "</DirectoryEntry>\n";

            $i++;

        }
    } 
    echo "<SoftKeyItem>\n\t<Name>Dial</Name>\n\t<URL>SoftKey:Dial</URL>\n\t<Position>1</Position>\n</SoftKeyItem>\n";
        echo "<SoftKeyItem>\n\t<Name>Prev</Name>\n\t";
        if ( $page > 1 ){
            echo "<URL>".$host_url."?f=".$f."&amp;l=".$l."&amp;page=".( $page - 1 )."</URL>\n";
        }
        echo "\t<Position>2</Position>\n</SoftKeyItem>";

        echo "<SoftKeyItem>\n\t<Name>Next</Name>\n\t";
        if ( $page < ceil($result_count / 32 ) ){
            echo "<URL>".$host_url."?f=".$f."&amp;l=".$l."&amp;page=".( $page + 1 )."</URL>\n";
        }
        echo "\t<Position>3</Position>\n</SoftKeyItem>";

    echo "<SoftKeyItem>\n\t<Name>Exit</Name>\n\t<URL>SoftKey:Exit</URL>\n\t<Position>4</Position>\n</SoftKeyItem>\n";
    echo "</CiscoIPPhoneDirectory>";
}

?>


apicucmdirectoryphonexml

Quote Bot

Google Speech to Text API


Jon Snipes
LinkedIn

My career progressed from head butcher to Collaboration CCIE. There isn’t much technically that carries over between professions, but 8 years of direct customer service experience and squeezing margin out of processes provided a solid base and direction for the rest of my career. My focus today is deep into collaboration messaging, voice and video with the expertise to develop processes and programmatic solutions to complex business problems.

Principal Architect at Cloverhound
CCIE Collaboration 51786
Cisco Webex Expert
2018-2021 Cisco Champion

Categories
  • Cloud (4)
  • Contact Center (1)
  • Development (1)
  • PHP (10)
  • Python (3)
  • Uncategorized (1)
  • Video (2)
  • Voice (12)
  • Voicemail (5)
  • Webex (7)
Recent Posts
  • Azure OAuth2.0 User Authentication December 4, 2021
  • Pass-through Gateway Routing and Dial Peer Groups December 4, 2021
  • Get Started Coding with Python: System Setup and Running Scripts December 4, 2021
  • Exporting CUCM to an Offline Local DB with Python December 4, 2021
  • Connecting to UCCX INFORMIX DB with Python on Linux December 4, 2021
Proudly powered by WordPress | Theme: Doo by ThemeVS.