cidlookup.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/public/clicktodial/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, and your dialplan must be something like this:
  21. *
  22. * exten => s,1,Set(CALLERID(name)=${CURL(http://IP-DOLIBARR:80/asterisk/cidlookup.php?phone=${CALLERID(num)}&securitykey=SECURITYKEY)})
  23. *
  24. * Change IP-DOLIBARR to the IP address of your dolibarr server
  25. * Change SECURITYKEY to the value defined into your setup of module ClickToDial
  26. */
  27. if (!defined('NOTOKENRENEWAL')) {
  28. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  29. }
  30. if (!defined('NOREQUIREMENU')) {
  31. define('NOREQUIREMENU', '1');
  32. }
  33. if (!defined('NOREQUIREHTML')) {
  34. define('NOREQUIREHTML', '1');
  35. }
  36. if (!defined('NOREQUIREAJAX')) {
  37. define('NOREQUIREAJAX', '1');
  38. }
  39. if (!defined('NOLOGIN')) {
  40. define('NOLOGIN', '1');
  41. }
  42. if (!defined('NOIPCHECK')) {
  43. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  44. }
  45. // So log file will have a suffix
  46. if (!defined('USESUFFIXINLOG')) {
  47. define('USESUFFIXINLOG', '_cidlookup');
  48. }
  49. include '../../main.inc.php';
  50. $phone = GETPOST('phone');
  51. $securitykey = GETPOST('securitykey');
  52. $notfound = $langs->trans("Unknown");
  53. // Security check
  54. if (empty($conf->clicktodial->enabled)) {
  55. print "Error: Module Click to dial is not enabled.\n";
  56. exit;
  57. }
  58. /*
  59. * View
  60. */
  61. if (empty($securitykey)) {
  62. echo 'Securitykey is required. Check setup of clicktodial module.';
  63. exit;
  64. }
  65. if ($securitykey != getDolGlobalString('CLICKTODIAL_KEY_FOR_CIDLOOKUP')) {
  66. echo 'Securitykey is wrong.';
  67. exit;
  68. }
  69. // Check parameters
  70. if (empty($phone)) {
  71. print "Error: Url must be called with parameter phone=phone to search\n";
  72. exit;
  73. }
  74. $sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
  75. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
  76. $sql .= " WHERE s.entity IN (".getEntity('societe').")";
  77. $sql .= " AND (s.phone='".$db->escape($phone)."'";
  78. $sql .= " OR sp.phone='".$db->escape($phone)."'";
  79. $sql .= " OR sp.phone_perso='".$db->escape($phone)."'";
  80. $sql .= " OR sp.phone_mobile='".$db->escape($phone)."')";
  81. $sql .= $db->plimit(1);
  82. dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
  83. $resql = $db->query($sql);
  84. if ($resql) {
  85. $obj = $db->fetch_object($resql);
  86. if ($obj) {
  87. $found = $obj->name;
  88. } else {
  89. $found = $notfound;
  90. }
  91. $db->free($resql);
  92. } else {
  93. dol_print_error($db, 'Error');
  94. $found = 'Error';
  95. }
  96. //Greek to Latin
  97. $greek = array('α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Α', 'Β', 'Γ', 'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ', 'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ', 'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω', 'ά', 'έ', 'ή', 'ί', 'ό', 'ύ', 'ώ', 'ϊ', 'ΐ', 'Ά', 'Έ', 'Ή', 'Ί', 'Ό', 'Ύ', 'Ώ', 'Ϊ');
  98. $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');
  99. print str_replace($greek, $latin, $found);