dolibarr 21.0.0-beta
company.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.'/societe/class/societe.class.php';
55$htmlname = GETPOST('htmlname', 'aZ09');
56$filter = GETPOST('filter', 'alpha');
57$outjson = (GETPOSTINT('outjson') ? GETPOSTINT('outjson') : 0);
58$action = GETPOST('action', 'aZ09');
59$id = GETPOSTINT('id');
60$excludeids = GETPOST('excludeids', 'intcomma');
61$showtype = GETPOSTINT('showtype');
62$showcode = GETPOSTINT('showcode');
63
64$object = new Societe($db);
65if ($id > 0) {
66 $object->fetch($id);
67}
68
69// Security check
70if ($user->socid > 0) {
71 unset($action);
72 $socid = $user->socid;
73 $object->id = $socid;
74}
75restrictedArea($user, 'societe', $object->id, '&societe');
76
77
78/*
79 * View
80 */
81
82top_httphead('application/json');
83
84//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
85
86if (!empty($action) && $action == 'fetch' && !empty($id) && $user->hasRight('societe', 'lire')) {
87 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
88
89 $outjson = array();
90
91 if ($object->id > 0) {
92 $outref = $object->ref;
93 $outname = $object->name;
94 $outdesc = '';
95 $outtype = $object->type;
96
97 $outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
98 }
99
100 echo json_encode($outjson);
101} else {
102 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
103
104 if (empty($htmlname)) {
105 return;
106 }
107
108 // The filter on the company to search for can be:
109 // Into an array with key $htmlname123 (we take first one found). Which page use this ?
110 // Into a var with name $htmlname can be 'prodid', 'productid', ...
111 $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
112 sort($match);
113
114 $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
115
116 // When used from jQuery, the search term is added as GET param $htmlname.
117 $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
118 if (!$searchkey) {
119 return;
120 }
121
122 if (empty($form) || !is_object($form)) {
123 $form = new Form($db);
124 }
125
126 if (!empty($excludeids)) {
127 $excludeids = explode(',', $excludeids);
128 } else {
129 $excludeids = array();
130 }
131
132 // FIXME
133 // If SOCIETE_USE_SEARCH_TO_SELECT is set, check that nb of chars in $filter is >= to avoid DOS attack
134
135
136 $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids, $showcode);
137
138 if ($outjson) {
139 print json_encode($arrayresult);
140 }
141}
142
143$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.