2011-08-28 03:39:55 +02:00
|
|
|
|
<?php
|
2010-07-02 00:54:09 +02:00
|
|
|
|
/* Copyright (C) 2010 Servitux Servicios Informaticos <info@servitux.es>
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-07-02 00:54:09 +02:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-07-02 00:54:09 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \file htdocs/asterisk/cidlookup.php
|
2015-05-18 09:11:34 +02:00
|
|
|
|
* \brief Script to search companies names based on incoming calls, from caller phone number
|
2010-07-02 00:54:09 +02:00
|
|
|
|
* \remarks To use this script, your Asterisk must be compiled with CURL,
|
|
|
|
|
|
* and your dialplan must be something like this:
|
|
|
|
|
|
*
|
2015-05-18 09:11:34 +02:00
|
|
|
|
* exten => s,1,Set(CALLERID(name)=${CURL(http://IP-DOLIBARR:80/asterisk/cidlookup.php?phone=${CALLERID(num)})})
|
2010-07-02 00:54:09 +02:00
|
|
|
|
*
|
2015-05-18 09:11:34 +02:00
|
|
|
|
* Change IP-DOLIBARR to the IP address of your dolibarr server
|
2010-07-02 00:54:09 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2010-07-10 01:14:37 +02:00
|
|
|
|
|
2012-08-23 02:04:35 +02:00
|
|
|
|
include '../master.inc.php';
|
2010-07-10 01:14:37 +02:00
|
|
|
|
|
2014-12-30 18:11:55 +01:00
|
|
|
|
$phone = GETPOST('phone');
|
2015-10-10 15:01:39 +02:00
|
|
|
|
$notfound = $langs->trans("Unknown");
|
2018-07-26 19:05:34 +02:00
|
|
|
|
|
2014-12-30 17:59:40 +01:00
|
|
|
|
// Security check
|
2021-02-22 18:38:03 +01:00
|
|
|
|
if (empty($conf->clicktodial->enabled)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
|
print "Error: Module Click to dial is not enabled.\n";
|
|
|
|
|
|
exit;
|
2014-12-30 17:59:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-07-10 01:14:37 +02:00
|
|
|
|
// Check parameters
|
2021-02-22 18:38:03 +01:00
|
|
|
|
if (empty($phone)) {
|
2010-07-10 01:14:37 +02:00
|
|
|
|
print "Error: Url must be called with parameter phone=phone to search\n";
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-09 20:34:38 +01:00
|
|
|
|
$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
|
2020-04-10 10:59:32 +02:00
|
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
|
|
|
|
|
|
$sql .= " WHERE s.entity IN (".getEntity('societe').")";
|
|
|
|
|
|
$sql .= " AND (s.phone='".$db->escape($phone)."'";
|
|
|
|
|
|
$sql .= " OR sp.phone='".$db->escape($phone)."'";
|
|
|
|
|
|
$sql .= " OR sp.phone_perso='".$db->escape($phone)."'";
|
|
|
|
|
|
$sql .= " OR sp.phone_mobile='".$db->escape($phone)."')";
|
|
|
|
|
|
$sql .= $db->plimit(1);
|
2010-07-10 01:14:37 +02:00
|
|
|
|
|
|
|
|
|
|
dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
|
|
|
|
|
|
$resql = $db->query($sql);
|
2021-02-22 18:38:03 +01:00
|
|
|
|
if ($resql) {
|
2012-01-30 10:22:50 +01:00
|
|
|
|
$obj = $db->fetch_object($resql);
|
2021-02-22 18:38:03 +01:00
|
|
|
|
if ($obj) {
|
2012-01-30 10:22:50 +01:00
|
|
|
|
$found = $obj->name;
|
2015-05-13 03:20:06 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
$found = $notfound;
|
2010-07-10 01:14:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
$db->free($resql);
|
2020-05-21 09:35:30 +02:00
|
|
|
|
} else {
|
2019-01-27 11:55:16 +01:00
|
|
|
|
dol_print_error($db, 'Error');
|
2015-05-18 09:11:34 +02:00
|
|
|
|
$found = 'Error';
|
2010-07-10 01:14:37 +02:00
|
|
|
|
}
|
2015-10-05 16:46:02 +02:00
|
|
|
|
//Greek to Latin
|
2020-04-10 10:59:32 +02:00
|
|
|
|
$greek = array('α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Α', 'Β', 'Γ', 'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ', 'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ', 'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω', 'ά', 'έ', 'ή', 'ί', 'ό', 'ύ', 'ώ', 'ϊ', 'ΐ', 'Ά', 'Έ', 'Ή', 'Ί', 'Ό', 'Ύ', 'Ώ', 'Ϊ');
|
2010-07-10 01:14:37 +02:00
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
|
$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');
|
2015-10-05 16:46:02 +02:00
|
|
|
|
|
|
|
|
|
|
print str_replace($greek, $latin, $found);
|