cidlookup.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* Copyright (C) 2010 Servitux Servicios Informaticos <info@servitux.es>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/asterisk/cidlookup.php
  19. * \brief Script to search companies names based on incoming calls, from caller phone number
  20. * \remarks To use this script, your Asterisk must be compiled with CURL,
  21. * and your dialplan must be something like this:
  22. *
  23. * exten => s,1,Set(CALLERID(name)=${CURL(http://IP-DOLIBARR:80/asterisk/cidlookup.php?phone=${CALLERID(num)})})
  24. *
  25. * Change IP-DOLIBARR to the IP address of your dolibarr server
  26. */
  27. include '../master.inc.php';
  28. $phone = GETPOST('phone');
  29. $notfound = $langs->trans("Unknown");
  30. // Security check
  31. if (empty($conf->clicktodial->enabled))
  32. {
  33. print "Error: Module Click to dial is not enabled.\n";
  34. exit;
  35. }
  36. // Check parameters
  37. if (empty($phone))
  38. {
  39. print "Error: Url must be called with parameter phone=phone to search\n";
  40. exit;
  41. }
  42. $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
  43. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
  44. $sql.= " WHERE s.entity IN (".getEntity('societe').")";
  45. $sql.= " AND (s.phone='".$db->escape($phone)."'";
  46. $sql.= " OR sp.phone='".$db->escape($phone)."'";
  47. $sql.= " OR sp.phone_perso='".$db->escape($phone)."'";
  48. $sql.= " OR sp.phone_mobile='".$db->escape($phone)."')";
  49. $sql.= $db->plimit(1);
  50. dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
  51. $resql = $db->query($sql);
  52. if ($resql)
  53. {
  54. $obj = $db->fetch_object($resql);
  55. if ($obj)
  56. {
  57. $found = $obj->name;
  58. } else {
  59. $found = $notfound;
  60. }
  61. $db->free($resql);
  62. }
  63. else
  64. {
  65. dol_print_error($db,'Error');
  66. $found = 'Error';
  67. }
  68. //Greek to Latin
  69. $greek = array('α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω','ά','έ','ή','ί','ό','ύ','ώ','ϊ','ΐ','Ά','Έ','Ή','Ί','Ό','Ύ','Ώ','Ϊ');
  70. $latin = array('a','b','g','d','e','z','h','th','i','k','l','m','n','ks','o','p','r','s','s','t','u','f','ch','ps','w','A','B','G','D','E','Z','H','TH','I','K','L','M','N','KS','O','P','R','S','T','U','F','CH','PS','W','a','e','h','i','o','u','w','i','i','A','E','H','I','O','U','W','I');
  71. print str_replace($greek, $latin, $found);