dolibarr/htdocs/core/ajax/selectobject.php

105 lines
3.2 KiB
PHP
Raw Normal View History

2017-10-25 22:02:07 +02:00
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-10-25 22:02:07 +02:00
*/
/**
* \file htdocs/core/ajax/selectobject.php
* \brief File to return Ajax response on a selection list request
*/
2021-02-23 22:03:23 +01:00
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
2017-10-25 22:02:07 +02:00
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
2017-10-25 22:02:07 +02:00
require '../../main.inc.php';
2023-03-27 11:52:56 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
2017-10-25 22:02:07 +02:00
$objectdesc = GETPOST('objectdesc', 'alpha');
$htmlname = GETPOST('htmlname', 'aZ09');
$outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
$id = GETPOST('id', 'int');
2023-03-27 11:52:56 +02:00
$filter = GETPOST('filter', 'alphanohtml'); // Universal Syntax filter
2017-10-25 22:02:07 +02:00
2021-02-23 22:03:23 +01:00
if (empty($htmlname)) {
2023-03-27 11:52:56 +02:00
httponly_accessforbidden('Bad value for param htmlname');
2021-02-23 22:03:23 +01:00
}
2017-10-25 22:02:07 +02:00
$InfoFieldList = explode(":", $objectdesc);
$classname = $InfoFieldList[0];
$classpath = $InfoFieldList[1];
2021-02-23 22:03:23 +01:00
if (!empty($classpath)) {
2017-10-25 22:02:07 +02:00
dol_include_once($classpath);
2021-02-23 22:03:23 +01:00
if ($classname && class_exists($classname)) {
2017-10-25 22:02:07 +02:00
$objecttmp = new $classname($db);
}
}
2021-02-23 22:03:23 +01:00
if (!is_object($objecttmp)) {
2023-03-27 11:52:56 +02:00
httponly_accessforbidden('Bad value for param objectdesc');
2017-10-25 22:02:07 +02:00
}
2023-03-27 11:52:56 +02:00
/*
// Load object according to $id and $element
$object = fetchObjectByElement($id, $element);
$module = $object->module;
$element = $object->element;
$usesublevelpermission = ($module != $element ? $element : '');
if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly
$usesublevelpermission = '';
}
*/
2017-10-25 22:02:07 +02:00
// When used from jQuery, the search term is added as GET param "term".
$searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
2017-10-25 22:02:07 +02:00
// Add a security test to avoid to get content of all tables
restrictedArea($user, $objecttmp->element, $id);
2017-10-25 22:02:07 +02:00
2023-03-27 11:52:56 +02:00
/*
* View
*/
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
//print_r($_GET);
//$langs->load("companies");
$form = new Form($db);
top_httphead($outjson ? 'application/json' : 'text/html');
2022-12-07 15:54:25 +01:00
$arrayresult = $form->selectForFormsList($objecttmp, $htmlname, '', 0, $searchkey, '', '', '', 0, 1, 0, '', $filter);
2017-10-25 22:02:07 +02:00
$db->close();
2021-02-23 22:03:23 +01:00
if ($outjson) {
print json_encode($arrayresult);
}