dolibarr 21.0.0-alpha
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOTOKENRENEWAL')) {
28 define('NOTOKENRENEWAL', 1); // Disables token renewal
29}
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1');
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1');
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1');
38}
39if (!defined('NOREQUIRESOC')) {
40 define('NOREQUIRESOC', '1');
41}
42
43// Load Dolibarr environment
44require '../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
46
47$htmlname = GETPOST('htmlname', 'aZ09');
48$outjson = (GETPOSTINT('outjson') ? GETPOSTINT('outjson') : 0);
49$action = GETPOST('action', 'aZ09');
50
51$id = GETPOSTINT('id');
52$socid = GETPOSTINT('socid');
53$exclude = GETPOST('exclude', 'intcomma');
54$showsoc = GETPOSTINT('showsoc');
55
56$object = new Contact($db);
57if ($id > 0) {
58 $object->fetch($id);
59}
60
61// Security check
62if ($user->socid > 0) {
63 unset($action);
64 $socid = $user->socid;
65 $object->id = $socid;
66}
67restrictedArea($user, 'societe', $object->id, '&societe');
68
69$permissiontoread = $user->hasRight('societe', 'lire');
70
71
72/*
73 * View
74 */
75
76top_httphead('application/json');
77
78//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
79
80if ($action == 'fetch' && !empty($id) && $permissiontoread) {
81 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
82
83 $outjson = array();
84
85 if ($object->id > 0) {
86 $outref = $object->ref;
87 $outfirstname = $object->firstname;
88 $outlastname = $object->lastname;
89 $outdesc = '';
90
91 $outjson = array('ref' => $outref, 'firstname' => $outfirstname, 'lastname' => $outlastname, 'desc' => $outdesc);
92 }
93
94 echo json_encode($outjson);
95} elseif ($permissiontoread) { // $action can be 'getContacts'
96 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
97
98 if (empty($htmlname)) {
99 return 'Error value for parameter htmlname';
100 }
101
102 // The filter on the company to search for can be:
103 // Into an array with key $htmlname123 (we take first one found). Which page use this ?
104 // Into a var with name $htmlname can be 'elemid', ...
105 $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
106 sort($match);
107
108 $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
109
110 // When used from jQuery, the search term is added as GET param "term".
111 $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
112 if (!$searchkey) {
113 return;
114 }
115
116 if (empty($form) || !is_object($form)) {
117 $form = new Form($db);
118 }
119
120 $limitto = '';
121 $showfunction = 0;
122 $morecss = 'minwidth100';
123 $options_only = 2;
124 $forcecombo = 0;
125 $events = array();
126 $moreparam = '';
127 $htmlid = '';
128 $multiple = 0;
129 $disableifempty = 0;
130
131 $prefix = getDolGlobalString('CONTACT_DONOTSEARCH_ANYWHERE') ? '' : '%'; // Can use index if CONTACT_DONOTSEARCH_ANYWHERE is on
132
133 $nbchar = 0;
134 $filter = '';
135 $listofsearchkey = preg_split('/\s+/', $searchkey);
136 foreach ($listofsearchkey as $searchkey) {
137 $nbchar += strlen($searchkey);
138
139 $filter .= ($filter ? ' AND ' : '');
140 $filter .= '(';
141 $filter .= "(lastname:like:'".$prefix.$searchkey."%') OR (firstname:like:'".$prefix.$searchkey."%')";
142 if ($showsoc) {
143 $filter .= " OR (s.nom:like:'".$prefix.$searchkey."%')";
144 }
145 $filter .= ')';
146 }
147
148 // If CONTACT_USE_SEARCH_TO_SELECT is set, check that nb of chars in $filter is >= to avoid DOS attack
149 if (getDolGlobalInt('CONTACT_USE_SEARCH_TO_SELECT') && $nbchar < getDolGlobalInt('CONTACT_USE_SEARCH_TO_SELECT')) {
150 print json_encode(array());
151 } else {
152 $arrayresult = $form->selectcontacts($socid, array(), $htmlname, 1, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid, $multiple, $disableifempty, $filter);
153
154 print json_encode($arrayresult);
155 }
156}
157
158$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.