dolibarr  16.0.1
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 
25 if (!defined('NOTOKENRENEWAL')) {
26  define('NOTOKENRENEWAL', 1); // Disables token renewal
27 }
28 if (!defined('NOREQUIREMENU')) {
29  define('NOREQUIREMENU', '1');
30 }
31 if (!defined('NOREQUIREHTML')) {
32  define('NOREQUIREHTML', '1');
33 }
34 if (!defined('NOREQUIREAJAX')) {
35  define('NOREQUIREAJAX', '1');
36 }
37 if (!defined('NOREQUIRESOC')) {
38  define('NOREQUIRESOC', '1');
39 }
40 if (!defined('NOCSRFCHECK')) {
41  define('NOCSRFCHECK', '1');
42 }
43 
44 require '../../main.inc.php';
45 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
46 
47 $htmlname = GETPOST('htmlname', 'aZ09');
48 $filter = GETPOST('filter', 'alpha');
49 $outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
50 $action = GETPOST('action', 'aZ09');
51 $id = GETPOST('id', 'int');
52 $excludeids = GETPOST('excludeids', 'intcomma');
53 $showtype = GETPOSTINT('showtype');
54 $showcode = GETPOSTINT('showcode');
55 
56 $object = new Societe($db);
57 if ($id > 0) {
58  $object->fetch($id);
59 }
60 
61 // Security check
62 if ($user->socid > 0) {
63  unset($action);
64  $socid = $user->socid;
65  $object->id = $socid;
66 }
67 restrictedArea($user, 'societe', $object->id, '&societe');
68 
69 
70 /*
71  * View
72  */
73 
74 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
75 //print_r($_GET);
76 
77 if (!empty($action) && $action == 'fetch' && !empty($id)) {
78  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
79 
80  $outjson = array();
81 
82  if ($object->id > 0) {
83  $outref = $object->ref;
84  $outname = $object->name;
85  $outdesc = '';
86  $outtype = $object->type;
87 
88  $outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
89  }
90 
91  echo json_encode($outjson);
92 } else {
93  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
94 
95  $langs->load("companies");
96 
97  top_httphead();
98 
99  if (empty($htmlname)) {
100  return;
101  }
102 
103  // Filter on the company to search can be:
104  // Into an array with key $htmlname123 (we take first one found). Which page use this ?
105  // Into a var with name $htmlname can be 'prodid', 'productid', ...
106  $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
107  sort($match);
108 
109  $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
110 
111  // When used from jQuery, the search term is added as GET param "term".
112  $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ?GETPOST($htmlname, 'alpha') : ''));
113  if (!$searchkey) {
114  return;
115  }
116 
117  if (empty($form) || !is_object($form)) {
118  $form = new Form($db);
119  }
120 
121  if (!empty($excludeids)) {
122  $excludeids = explode(',', $excludeids);
123  } else {
124  $excludeids = array();
125  }
126 
127  $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids, $showcode);
128 
129  $db->close();
130 
131  if ($outjson) {
132  print json_encode($arrayresult);
133  }
134 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1403
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.
restrictedArea($user, $features, $objectid=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.