dolibarr 18.0.6
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', 1); // Disables token renewal
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38if (!defined('NOREQUIRESOC')) {
39 define('NOREQUIRESOC', '1');
40}
41
42// Load Dolibarr environment
43require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
45
46$htmlname = GETPOST('htmlname', 'aZ09');
47$filter = GETPOST('filter', 'alpha');
48$outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
49$action = GETPOST('action', 'aZ09');
50$id = GETPOST('id', 'int');
51$excludeids = GETPOST('excludeids', 'intcomma');
52$showtype = GETPOSTINT('showtype', 'alpha');
53$showcode = GETPOSTINT('showcode', 'alpha');
54
55$object = new Societe($db);
56if ($id > 0) {
57 $object->fetch($id);
58}
59
60// Security check
61if ($user->socid > 0) {
62 unset($action);
63 $socid = $user->socid;
64 $object->id = $socid;
65}
66restrictedArea($user, 'societe', $object->id, '&societe');
67
68
69/*
70 * View
71 */
72
73top_httphead('application/json');
74
75//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
76//print_r($_GET);
77
78if (!empty($action) && $action == 'fetch' && !empty($id)) {
79 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
80
81 $outjson = array();
82
83 if ($object->id > 0) {
84 $outref = $object->ref;
85 $outname = $object->name;
86 $outdesc = '';
87 $outtype = $object->type;
88
89 $outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
90 }
91
92 echo json_encode($outjson);
93} else {
94 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
95
96 if (empty($htmlname)) {
97 return;
98 }
99
100 // Filter on the company to search can be:
101 // Into an array with key $htmlname123 (we take first one found). Which page use this ?
102 // Into a var with name $htmlname can be 'prodid', 'productid', ...
103 $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
104 sort($match);
105
106 $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
107
108 // When used from jQuery, the search term is added as GET param "term".
109 $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ?GETPOST($htmlname, 'alpha') : ''));
110 if (!$searchkey) {
111 return;
112 }
113
114 if (empty($form) || !is_object($form)) {
115 $form = new Form($db);
116 }
117
118 if (!empty($excludeids)) {
119 $excludeids = explode(',', $excludeids);
120 } else {
121 $excludeids = array();
122 }
123
124 $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids, $showcode);
125
126 if ($outjson) {
127 print json_encode($arrayresult);
128 }
129}
130
131$db->close();
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 value of a param into GET or POST supervariable.
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.