dolibarr/htdocs/asterisk/cidlookup.php

71 lines
2.0 KiB
PHP
Raw Normal View History

<?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
* 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
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-07-02 00:54:09 +02:00
*/
/**
* \file htdocs/asterisk/cidlookup.php
* \brief Script to search companies names based on incoming calls
* \remarks To use this script, your Asterisk must be compiled with CURL,
* and your dialplan must be something like this:
*
* exten => s,1,Set(CALLERID(name)=${CURL(http://IP-DOLIBARR:80/asterisk/cidlookup.php?phone=${CALLERID(num)})})
*
* Change IP-DOLIBARR to the IP address of your dolibarr
* server
*
*/
$phone = $_GET['phone'];
include '../master.inc.php';
// Check parameters
if (empty($phone))
{
print "Error: Url must be called with parameter phone=phone to search\n";
exit;
}
$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
2011-02-05 16:17:00 +01:00
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
2013-03-09 16:19:15 +01:00
$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);
dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
2012-01-30 10:22:50 +01:00
$obj = $db->fetch_object($resql);
if ($obj)
{
2012-01-30 10:22:50 +01:00
$found = $obj->name;
}
$db->free($resql);
}
else
{
dol_print_error($db,'Error');
}
2010-07-02 00:54:09 +02:00
echo $found;
?>