dolibarr 21.0.0-beta
cidlookup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010 Servitux Servicios Informaticos <info@servitux.es>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30if (!defined('NOTOKENRENEWAL')) {
31 define('NOTOKENRENEWAL', '1'); // Disables token renewal
32}
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39if (!defined('NOREQUIREAJAX')) {
40 define('NOREQUIREAJAX', '1');
41}
42if (!defined('NOLOGIN')) {
43 define('NOLOGIN', '1');
44}
45if (!defined('NOIPCHECK')) {
46 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
47}
48
49// So log file will have a suffix
50if (!defined('USESUFFIXINLOG')) {
51 define('USESUFFIXINLOG', '_cidlookup');
52}
53
54include '../../main.inc.php';
59$phone = GETPOST('phone');
60$securitykey = GETPOST('securitykey');
61
62$notfound = $langs->trans("Unknown");
63
64// Security check
65if (empty($conf->clicktodial->enabled)) {
66 print "Error: Module Click to dial is not enabled.\n";
67 exit;
68}
69
70
71/*
72 * View
73 */
74
75if (empty($securitykey)) {
76 echo 'Securitykey is required. Check setup of clicktodial module.';
77 exit;
78}
79if ($securitykey != getDolGlobalString('CLICKTODIAL_KEY_FOR_CIDLOOKUP')) {
80 echo 'Securitykey is wrong.';
81 exit;
82}
83
84// Check parameters
85if (empty($phone)) {
86 print "Error: Url must be called with parameter phone=phone to search\n";
87 exit;
88}
89
90
91$sql = "SELECT s.nom as name FROM ".MAIN_DB_PREFIX."societe as s";
92$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
93$sql .= " WHERE s.entity IN (".getEntity('societe').")";
94$sql .= " AND (s.phone='".$db->escape($phone)."'";
95$sql .= " OR sp.phone='".$db->escape($phone)."'";
96$sql .= " OR sp.phone_perso='".$db->escape($phone)."'";
97$sql .= " OR sp.phone_mobile='".$db->escape($phone)."')";
98$sql .= $db->plimit(1);
99
100dol_syslog('cidlookup search information with phone '.$phone, LOG_DEBUG);
101$resql = $db->query($sql);
102if ($resql) {
103 $obj = $db->fetch_object($resql);
104 if ($obj) {
105 $found = $obj->name;
106 } else {
107 $found = $notfound;
108 }
109 $db->free($resql);
110} else {
111 dol_print_error($db, 'Error');
112 $found = 'Error';
113}
114//Greek to Latin
115$greek = array('α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'ς', 'σ', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Α', 'Β', 'Γ', 'Δ', 'Ε', 'Ζ', 'Η', 'Θ', 'Ι', 'Κ', 'Λ', 'Μ', 'Ν', 'Ξ', 'Ο', 'Π', 'Ρ', 'Σ', 'Τ', 'Υ', 'Φ', 'Χ', 'Ψ', 'Ω', 'ά', 'έ', 'ή', 'ί', 'ό', 'ύ', 'ώ', 'ϊ', 'ΐ', 'Ά', 'Έ', 'Ή', 'Ί', 'Ό', 'Ύ', 'Ώ', 'Ϊ');
116
117$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');
118
119print str_replace($greek, $latin, $found);
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79