dolibarr 21.0.0-beta
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28if (!defined('NOTOKENRENEWAL')) {
29 define('NOTOKENRENEWAL', 1); // Disables token renewal
30}
31if (!defined('NOREQUIREMENU')) {
32 define('NOREQUIREMENU', '1');
33}
34if (!defined('NOREQUIREHTML')) {
35 define('NOREQUIREHTML', '1');
36}
37if (!defined('NOREQUIREAJAX')) {
38 define('NOREQUIREAJAX', '1');
39}
40if (!defined('NOREQUIRESOC')) {
41 define('NOREQUIRESOC', '1');
42}
43
44// Load Dolibarr environment
45require '../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
47
56$htmlname = GETPOST('htmlname', 'aZ09');
57$outjson = (GETPOSTINT('outjson') ? GETPOSTINT('outjson') : 0);
58$action = GETPOST('action', 'aZ09');
59
60$id = GETPOSTINT('id');
61$socid = GETPOSTINT('socid');
62$exclude = GETPOST('exclude', 'intcomma');
63$showsoc = GETPOSTINT('showsoc');
64
65$object = new Contact($db);
66if ($id > 0) {
67 $object->fetch($id);
68}
69
70// Security check
71if ($user->socid > 0) {
72 unset($action);
73 $socid = $user->socid;
74 $object->id = $socid;
75}
76restrictedArea($user, 'societe', $object->id, '&societe');
77
78$permissiontoread = $user->hasRight('societe', 'lire');
79
80
81/*
82 * View
83 */
84
85top_httphead('application/json');
86
87//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
88
89if ($action == 'fetch' && !empty($id) && $permissiontoread) {
90 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
91
92 $outjson = array();
93
94 if ($object->id > 0) {
95 $outref = $object->ref;
96 $outfirstname = $object->firstname;
97 $outlastname = $object->lastname;
98 $outdesc = '';
99
100 $outjson = array('ref' => $outref, 'firstname' => $outfirstname, 'lastname' => $outlastname, 'desc' => $outdesc);
101 }
102
103 echo json_encode($outjson);
104} elseif ($permissiontoread) { // $action can be 'getContacts'
105 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
106
107 if (empty($htmlname)) {
108 return 'Error value for parameter htmlname';
109 }
110
111 // The filter on the company to search for can be:
112 // Into an array with key $htmlname123 (we take first one found). Which page use this ?
113 // Into a var with name $htmlname can be 'elemid', ...
114 $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
115 sort($match);
116
117 $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
118
119 // When used from jQuery, the search term is added as GET param "term".
120 $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
121 if (!$searchkey) {
122 return;
123 }
124
125 if (empty($form) || !is_object($form)) {
126 $form = new Form($db);
127 }
128
129 $limitto = '';
130 $showfunction = 0;
131 $morecss = 'minwidth100';
132 $options_only = 2;
133 $forcecombo = 0;
134 $events = array();
135 $moreparam = '';
136 $htmlid = '';
137 $multiple = 0;
138 $disableifempty = 0;
139
140 $prefix = getDolGlobalString('CONTACT_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if CONTACT_DONOTSEARCH_ANYWHERE is on
141
142 $nbchar = 0;
143 $filter = '';
144 $listofsearchkey = preg_split('/\s+/', $searchkey);
145 foreach ($listofsearchkey as $searchkey) {
146 $nbchar += strlen($searchkey);
147
148 $filter .= ($filter ? ' AND ' : '');
149 $filter .= '(';
150 $filter .= "(lastname:like:'".$prefix.$searchkey."%') OR (firstname:like:'".$prefix.$searchkey."%')";
151 if ($showsoc) {
152 $filter .= " OR (s.nom:like:'".$prefix.$searchkey."%')";
153 }
154 $filter .= ')';
155 }
156
157 // If CONTACT_USE_SEARCH_TO_SELECT is set, check that nb of chars in $filter is >= to avoid DOS attack
158 if (getDolGlobalInt('CONTACT_USE_SEARCH_TO_SELECT') && $nbchar < getDolGlobalInt('CONTACT_USE_SEARCH_TO_SELECT')) {
159 print json_encode(array());
160 } else {
161 $arrayresult = $form->selectcontacts($socid, array(), $htmlname, 1, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty, $filter);
162
163 print json_encode($arrayresult);
164 }
165}
166
167$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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 a Dolibarr global constant string value.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.