Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [php]
- <?php
- // File: gs_phonebook.php
- // Description: Generating a XML Phonebook from FreePBX MySQL DB
- // Modification: Use 'users' table instead of devices allowing exclusion of some devices
- // Populated both first and last name fields, changed output filename
- //!!Enable for Debug only!!
- // error_reporting(E_ALL);
- // ini_set("display_errors", 'ON');
- // Database settings
- $DBhost = "localhost"; //** Insert your host here
- $DBuser = "root"; //** Insert your DB user here
- $DBpass = ""; //** Insert your password here
- $DBdatabase = "asterisk"; //** change only when installed Free PBX in a non-common way!
- // Connect to the Database and get all users
- $DBlink = mysql_connect($DBhost, $DBuser, $DBpass) or die("Could not connect to host.");
- mysql_select_db($DBdatabase, $DBlink) or die("Could not find database.");
- $DBquery = "SELECT extension, name FROM users ORDER BY name ASC";
- $QUERYresult = mysql_query($DBquery, $DBlink) or die("Data not found.");
- //Setup XMLWriter
- $writer = new XMLWriter();
- $writer->openURI('/tftpboot/phonebook.xml'); //** If your TFTP server is using another root directory as /tfptboot, chang the path here!
- $writer->setIndent(4);
- //Begin output
- $writer->startDocument('1.0');
- $writer->startElement('AddressBook');
- //Add extensions / contacts from devices to the xml phonebook
- while ($contact=mysql_fetch_array($QUERYresult)){
- list($fn,$ln) = explode(' ',$contact['name'],2); //** Seperate first name by space. Last name = remainder of field
- //!!Enable for Debug only!!
- // print $fn . $ln . $contact['extension'] . '<br>';
- $writer->startElement('Contact');
- $writer->writeElement('LastName',$ln);
- $writer->writeElement('FirstName',$fn);
- $writer->startElement('Phone');
- $writer->writeElement('phonenumber',$contact['extension']);
- $writer->writeElement('accountindex','0');
- $writer->endElement();
- $writer->endElement();
- }
- $writer->endElement();
- $writer->endDocument();
- $writer->flush();
- ?>
- [/php]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement