25if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL', 1);
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38if (!defined(
'NOHEADERNOFOOTER')) {
39 define(
'NOHEADERNOFOOTER',
'1');
42include
'../../main.inc.php';
43include_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
52$objectid =
GETPOST(
'objectid',
'aZ09');
54$objecttype =
GETPOST(
'objecttype',
'aZ09arobase');
55$objectkey =
GETPOST(
'objectkey',
'restricthtml');
56$search =
GETPOST(
'search',
'restricthtml');
59$value =
GETPOST(
'value',
'alphanohtml');
61$offset = (($page - 1) * $limit);
63if (is_numeric($objectid)) {
64 $objectid = (int) $objectid;
66 $element_ref = $objectid;
70$object = fetchObjectByElement($objectid, $objecttype, $element_ref);
72 httponly_accessforbidden(
'Failed to get object with fetchObjectByElement(id=' . $objectid .
', objecttype=' . $objecttype .
')');
78$usesublevelpermission = ($module != $element ? $element :
'');
79if ($usesublevelpermission && !$user->hasRight($module, $element)) {
80 $usesublevelpermission =
'';
102 $data[
'results'][] = [
110 $extrafields->fetch_name_optionals_label($element);
111 $options = $extrafields->attributes[$element][
'param'][$objectkey][
'options'];
112 if (is_array($options)) {
115 $tmpparamoptions = array_keys($options);
116 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
118 $InfoFieldList = explode(
":", $paramoptions[0], 5);
130 if (! empty($InfoFieldList[4])) {
132 $parenthesisopen = 0;
133 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
134 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
137 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
142 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
143 $tmpafter = substr($InfoFieldList[4], $pos + 1);
145 $InfoFieldList[4] = $tmpbefore;
146 if ($tmpafter !==
'') {
147 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
152 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
153 $InfoFieldList[4] =
'(' . $reg[1] .
':' . $reg[2] .
':' . $reg[3] .
')';
161 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2] .
' as rowid');
163 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
164 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
165 $keyList .=
', ' . $parentField;
167 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
168 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
169 $keyList =
'main.' . $InfoFieldList[2] .
' as rowid';
171 $keyList = $InfoFieldList[2] .
' as rowid';
175 $filter_categorie =
false;
176 if (count($InfoFieldList) > 5) {
177 if ($InfoFieldList[0] ==
'categorie') {
178 $filter_categorie =
true;
182 if (!$filter_categorie) {
183 $fields_label = isset($InfoFieldList[1]) ? explode(
'|', $InfoFieldList[1]) : array();
184 if (!empty($fields_label)) {
186 $keyList .= implode(
', ', $fields_label);
190 $sql =
"SELECT " . $keyList;
191 $sql .=
' FROM ' . $db->prefix() . $InfoFieldList[0];
194 if (!empty($InfoFieldList[4])) {
196 if (strpos($InfoFieldList[4],
'$ENTITY$') !==
false) {
197 $InfoFieldList[4] = str_replace(
'$ENTITY$', (
string) $conf->entity, $InfoFieldList[4]);
201 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
202 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
206 if (strpos($InfoFieldList[4],
'$MODE$') !==
false) {
207 $InfoFieldList[4] = str_replace(
'$MODE$', preg_replace(
'/[^a-z0-9_]/i',
'', (
string) $mode), $InfoFieldList[4]);
211 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
212 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
214 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
220 preg_match_all(
'/\$(.*?)\$/', $InfoFieldList[4], $tags);
221 foreach ($tags[0] as $keytag => $valuetag) {
222 $property = preg_replace(
'/[^a-z0-9_]/',
'', strtolower($tags[1][$keytag]));
223 if (strpos($InfoFieldList[4], $valuetag) !==
false && property_exists($object, $property) && !empty(
$object->$property)) {
224 $InfoFieldList[4] = str_replace($valuetag, (
string)
$object->$property, $InfoFieldList[4]);
226 $InfoFieldList[4] = str_replace($valuetag,
'0', $InfoFieldList[4]);
233 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
234 $sql .=
' as main, ' . $db->sanitize($db->prefix() . $InfoFieldList[0]) .
'_extrafields as extra';
235 $sqlwhere .=
" WHERE extra.fk_object = main." . $db->sanitize($InfoFieldList[2]);
241 $sqlwhere .=
' WHERE 1=1';
245 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
246 $sqlwhere .=
' AND entity = ' . ((int) $conf->entity);
256 $orderfields = explode(
'|', $InfoFieldList[1]);
257 $keyList = $InfoFieldList[1];
258 if (count($orderfields)) {
259 $keyList = implode(
', ', $orderfields);
261 $sql .= $db->order($keyList);
262 $sql .= $db->plimit($limit, $offset);
266 $resql = $db->query($sql);
269 $num = $db->num_rows($resql);
273 $obj = $db->fetch_object($resql);
277 $fields_label = explode(
'|', $InfoFieldList[1]);
278 if (count($fields_label) > 1) {
280 foreach ($fields_label as $field_toshow) {
281 $labeltoshow .= $obj->$field_toshow .
' ';
284 $labeltoshow = $obj->{$InfoFieldList[1]};
287 if ($value == $obj->rowid) {
289 foreach ($fields_label as $field_toshow) {
290 $translabel = $langs->trans($obj->$field_toshow);
291 $labeltoshow = $translabel .
' ';
295 $data[
'results'][] = [
297 'text' => $labeltoshow,
301 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
302 $labeltoshow = $translabel;
304 if (empty($labeltoshow)) {
305 $labeltoshow =
'(not defined)';
318 $data[
'results'][] = [
320 'text' => $labeltoshow,
328 dol_syslog(
'Error in request ' . $db->lasterror() .
'. Check setup of extra parameters.', LOG_ERR);
331 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
332 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
337if ($page > 1 && $i < 9) {
338 $data[
'pagination'] = [
342print json_encode($data);
if(! $sortfield) if(! $sortorder) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
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.