Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. [php]
  2. <?php
  3. // File: gs_phonebook.php
  4. // Description: Generating a XML Phonebook from FreePBX MySQL DB
  5. // Modification: Use 'users' table instead of devices allowing exclusion of some devices
  6. // Populated both first and last name fields, changed output filename
  7.  
  8. //!!Enable for Debug only!!
  9. // error_reporting(E_ALL);
  10. // ini_set("display_errors", 'ON');
  11.  
  12. // Database settings
  13. $DBhost = "localhost"; //** Insert your host here
  14. $DBuser = "root"; //** Insert your DB user here
  15. $DBpass = ""; //** Insert your password here
  16. $DBdatabase = "asterisk"; //** change only when installed Free PBX in a non-common way!
  17.  
  18. // Connect to the Database and get all users
  19. $DBlink = mysql_connect($DBhost, $DBuser, $DBpass) or die("Could not connect to host.");
  20. mysql_select_db($DBdatabase, $DBlink) or die("Could not find database.");
  21. $DBquery = "SELECT extension, name FROM users ORDER BY name ASC";
  22. $QUERYresult = mysql_query($DBquery, $DBlink) or die("Data not found.");
  23.  
  24. //Setup XMLWriter
  25. $writer = new XMLWriter();
  26. $writer->openURI('/tftpboot/phonebook.xml'); //** If your TFTP server is using another root directory as /tfptboot, chang the path here!
  27. $writer->setIndent(4);
  28.  
  29. //Begin output
  30. $writer->startDocument('1.0');
  31. $writer->startElement('AddressBook');
  32.  
  33. //Add extensions / contacts from devices to the xml phonebook
  34. while ($contact=mysql_fetch_array($QUERYresult)){
  35. list($fn,$ln) = explode(' ',$contact['name'],2); //** Seperate first name by space. Last name = remainder of field
  36. //!!Enable for Debug only!!
  37. // print $fn . $ln . $contact['extension'] . '<br>';
  38. $writer->startElement('Contact');
  39. $writer->writeElement('LastName',$ln);
  40. $writer->writeElement('FirstName',$fn);
  41. $writer->startElement('Phone');
  42. $writer->writeElement('phonenumber',$contact['extension']);
  43. $writer->writeElement('accountindex','0');
  44. $writer->endElement();
  45. $writer->endElement();
  46. }
  47.  
  48. $writer->endElement();
  49. $writer->endDocument();
  50. $writer->flush();
  51. ?>
  52. [/php]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement