dolibarr 18.0.6
cidlookup.php
Go to the documentation of this file.
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
29if (!defined('NOTOKENRENEWAL')) {
30 define('NOTOKENRENEWAL', '1'); // Disables token renewal
31}
32if (!defined('NOREQUIREMENU')) {
33 define('NOREQUIREMENU', '1');
34}
35if (!defined('NOREQUIREHTML')) {
36 define('NOREQUIREHTML', '1');
37}
38if (!defined('NOREQUIREAJAX')) {
39 define('NOREQUIREAJAX', '1');
40}
41if (!defined('NOLOGIN')) {
42 define('NOLOGIN', '1');
43}
44if (!defined('NOIPCHECK')) {
45 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
46}
47
48// So log file will have a suffix
49if (!defined('USESUFFIXINLOG')) {
50 define('USESUFFIXINLOG', '_cidlookup');
51}
52
53include '../../main.inc.php';
54
55$phone = GETPOST('phone');
56$securitykey = GETPOST('securitykey');
57
58$notfound = $langs->trans("Unknown");
59
60// Security check
61if (empty($conf->clicktodial->enabled)) {
62 print "Error: Module Click to dial is not enabled.\n";
63 exit;
64}
65
66
67/*
68 * View
69 */
70
71if (empty($securitykey)) {
72 echo 'Securitykey is required. Check setup of clicktodial module.';
73 exit;
74}
75if ($securitykey != getDolGlobalString('CLICKTODIAL_KEY_FOR_CIDLOOKUP')) {
76 echo 'Securitykey is wrong.';
77 exit;
78}
79
80// Check parameters
81if (empty($phone)) {
82 print "Error: Url must be called with parameter phone=phone to search\n";
83 exit;
84}
85
86
87$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
88$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
89$sql .= " WHERE s.entity IN (".getEntity('societe').")";
90$sql .= " AND (s.phone='".$db->escape($phone)."'";
91$sql .= " OR sp.phone='".$db->escape($phone)."'";
92$sql .= " OR sp.phone_perso='".$db->escape($phone)."'";
93$sql .= " OR sp.phone_mobile='".$db->escape($phone)."')";
94$sql .= $db->plimit(1);
95
96dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
97$resql = $db->query($sql);
98if ($resql) {
99 $obj = $db->fetch_object($resql);
100 if ($obj) {
101 $found = $obj->name;
102 } else {
103 $found = $notfound;
104 }
105 $db->free($resql);
106} else {
107 dol_print_error($db, 'Error');
108 $found = 'Error';
109}
110//Greek to Latin
111$greek = array('α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Α', 'Β', 'Γ', 'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ', 'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ', 'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω', 'ά', 'έ', 'ή', 'ί', 'ό', 'ύ', 'ώ', 'ϊ', 'ΐ', 'Ά', 'Έ', 'Ή', 'Ί', 'Ό', 'Ύ', 'Ώ', 'Ϊ');
112
113$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');
114
115print str_replace($greek, $latin, $found);
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.