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