/htdocs/api/class/api_setup.class.php
PHP | 2067 lines | 1207 code | 284 blank | 576 comment | 273 complexity | df37d93384711ac04d6bf5fc9ffbdf96 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
Large files files are truncated, but you can click here to view the full file
- <?php
- /* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
- * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2017 Neil Orley <neil.orley@oeris.fr>
- * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2018-2021 Thibault FOUCART <support@ptibogxiv.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
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- use Luracast\Restler\RestException;
- require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/cstate.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
- /**
- * API class for dictionaries
- *
- * @access protected
- * @class DolibarrApiAccess {@requires user,external}
- */
- class Setup extends DolibarrApi
- {
- private $translations = null;
- /**
- * Constructor
- */
- public function __construct()
- {
- global $db;
- $this->db = $db;
- }
- /**
- * Get the list of ordering methods.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Payment type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'OrderByWWW')"
- *
- * @url GET dictionary/ordering_methods
- *
- * @return array [List of ordering methods]
- *
- * @throws RestException 400
- */
- public function getOrderingMethods($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->rights->commande->lire) {
- throw new RestException(401);
- }
- $sql = "SELECT rowid, code, libelle as label, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of ordering origins.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Payment type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'OrderByWWW')"
- *
- * @url GET dictionary/ordering_origins
- *
- * @return array [List of ordering reasons]
- *
- * @throws RestException 400
- */
- public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->rights->commande->lire) {
- throw new RestException(401);
- }
- $sql = "SELECT rowid, code, label, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_input_reason as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of payments types.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Payment type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'CHQ')"
- *
- * @url GET dictionary/payment_types
- *
- * @return array [List of payment types]
- *
- * @throws RestException 400
- */
- public function getPaymentTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
- throw new RestException(401);
- }
- $sql = "SELECT id, code, type, libelle as label, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
- $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")";
- $sql .= " AND t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of states/provinces.
- *
- * The names of the states will be translated to the given language if
- * the $lang parameter is provided. The value of $lang must be a language
- * code supported by Dolibarr, for example 'en_US' or 'fr_FR'.
- * The returned list is sorted by state ID.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $filter To filter the countries by name
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of countries
- *
- * @url GET dictionary/states
- *
- * @throws RestException
- */
- public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $sqlfilters = '')
- {
- $list = array();
- // Note: The filter is not applied in the SQL request because it must
- // be applied to the translated names, not to the names in database.
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
- $sql .= " WHERE 1 = 1";
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $obj = $this->db->fetch_object($result);
- $state = new Cstate($this->db);
- if ($state->fetch($obj->rowid) > 0) {
- if (empty($filter) || stripos($state->label, $filter) !== false) {
- $list[] = $this->_cleanObjectDatas($state);
- }
- }
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of states');
- }
- return $list;
- }
- /**
- * Get state by ID.
- *
- * @param int $id ID of state
- * @return array Array of cleaned object properties
- *
- * @url GET dictionary/states/{id}
- *
- * @throws RestException
- */
- public function getStateByID($id)
- {
- return $this->_fetchCstate($id, '');
- }
- /**
- * Get state by Code.
- *
- * @param string $code Code of state
- * @return array Array of cleaned object properties
- *
- * @url GET dictionary/states/byCode/{code}
- *
- * @throws RestException
- */
- public function getStateByCode($code)
- {
- return $this->_fetchCstate('', $code);
- }
- /**
- * Get the list of countries.
- *
- * The names of the countries will be translated to the given language if
- * the $lang parameter is provided. The value of $lang must be a language
- * code supported by Dolibarr, for example 'en_US' or 'fr_FR'.
- * The returned list is sorted by country ID.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $filter To filter the countries by name
- * @param string $lang Code of the language the label of the countries must be translated to
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of countries
- *
- * @url GET dictionary/countries
- *
- * @throws RestException
- */
- public function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
- {
- $list = array();
- // Note: The filter is not applied in the SQL request because it must
- // be applied to the translated names, not to the names in database.
- $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
- $sql .= " WHERE 1 = 1";
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $obj = $this->db->fetch_object($result);
- $country = new Ccountry($this->db);
- if ($country->fetch($obj->rowid) > 0) {
- // Translate the name of the country if needed
- // and then apply the filter if there is one.
- $this->translateLabel($country, $lang, 'Country');
- if (empty($filter) || stripos($country->label, $filter) !== false) {
- $list[] = $this->_cleanObjectDatas($country);
- }
- }
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of countries');
- }
- return $list;
- }
- /**
- * Get country by ID.
- *
- * @param int $id ID of country
- * @param string $lang Code of the language the name of the
- * country must be translated to
- * @return array Array of cleaned object properties
- *
- * @url GET dictionary/countries/{id}
- *
- * @throws RestException
- */
- public function getCountryByID($id, $lang = '')
- {
- return $this->_fetchCcountry($id, '', '', $lang);
- }
- /**
- * Get country by Code.
- *
- * @param string $code Code of country (2 characters)
- * @param string $lang Code of the language the name of the
- * country must be translated to
- * @return array Array of cleaned object properties
- *
- * @url GET dictionary/countries/byCode/{code}
- *
- * @throws RestException
- */
- public function getCountryByCode($code, $lang = '')
- {
- return $this->_fetchCcountry('', $code, '', $lang);
- }
- /**
- * Get country by Iso.
- *
- * @param string $iso ISO of country (3 characters)
- * @param string $lang Code of the language the name of the
- * country must be translated to
- * @return array Array of cleaned object properties
- *
- * @url GET dictionary/countries/byISO/{iso}
- *
- * @throws RestException
- */
- public function getCountryByISO($iso, $lang = '')
- {
- return $this->_fetchCcountry('', '', $iso, $lang);
- }
- /**
- * Get state.
- *
- * @param int $id ID of state
- * @param string $code Code of state
- * @return array Array of cleaned object properties
- *
- * @throws RestException
- */
- private function _fetchCstate($id, $code = '')
- {
- $state = new Cstate($this->db);
- $result = $state->fetch($id, $code);
- if ($result < 0) {
- throw new RestException(503, 'Error when retrieving state : '.$state->error);
- } elseif ($result == 0) {
- throw new RestException(404, 'State not found');
- }
- return $this->_cleanObjectDatas($state);
- }
- /**
- * Get country.
- *
- * @param int $id ID of country
- * @param string $code Code of country (2 characters)
- * @param string $iso ISO of country (3 characters)
- * @param string $lang Code of the language the name of the
- * country must be translated to
- * @return array Array of cleaned object properties
- *
- * @throws RestException
- */
- private function _fetchCcountry($id, $code = '', $iso = '', $lang = '')
- {
- $country = new Ccountry($this->db);
- $result = $country->fetch($id, $code, $iso);
- if ($result < 0) {
- throw new RestException(503, 'Error when retrieving country : '.$country->error);
- } elseif ($result == 0) {
- throw new RestException(404, 'Country not found');
- }
- $this->translateLabel($country, $lang, 'Country');
- return $this->_cleanObjectDatas($country);
- }
- /**
- * Get the list of delivery times.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Delivery times is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter with.
- *
- * @url GET dictionary/availability
- *
- * @return array [List of availability]
- *
- * @throws RestException 400
- */
- public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->rights->commande->lire) {
- throw new RestException(401);
- }
- $sql = "SELECT rowid, code, label";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
- /**
- * Clean sensible object datas
- *
- * @param Object $object Object to clean
- * @return Object Object with cleaned properties
- */
- protected function _cleanObjectDatas($object)
- {
- // phpcs:enable
- $object = parent::_cleanObjectDatas($object);
- unset($object->error);
- unset($object->errors);
- return $object;
- }
- /**
- * Translate the name of the object to the given language.
- *
- * @param object $object Object with label to translate
- * @param string $lang Code of the language the name of the object must be translated to
- * @param string $prefix Prefix for translation key
- *
- * @return void
- */
- private function translateLabel($object, $lang, $prefix = 'Country')
- {
- if (!empty($lang)) {
- // Load the translations if this is a new language.
- if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
- global $conf;
- $this->translations = new Translate('', $conf);
- $this->translations->setDefaultLang($lang);
- $this->translations->load('dict');
- }
- if ($object->code) {
- $key = $prefix.$object->code;
- $translation = $this->translations->trans($key);
- if ($translation != $key) {
- $object->label = html_entity_decode($translation);
- }
- }
- }
- }
- /**
- * Get the list of events types.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $type To filter on type of event
- * @param string $module To filter on module events
- * @param int $active Event's type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of events types
- *
- * @url GET dictionary/event_types
- *
- * @throws RestException
- */
- public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT id, code, type, libelle as label, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
- $sql .= " WHERE t.active = ".((int) $active);
- if ($type) {
- $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
- }
- if ($module) {
- $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of Expense Report types.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $module To filter on module
- * @param int $active Event's type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of expense report types
- *
- * @url GET dictionary/expensereport_types
- *
- * @throws RestException
- */
- public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT id, code, label, accountancy_code, active, module, position";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
- $sql .= " WHERE t.active = ".((int) $active);
- if ($module) {
- $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of expense report types : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of contacts types.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $type To filter on type of contact
- * @param string $module To filter on module contacts
- * @param int $active Contact's type is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of Contacts types
- *
- * @url GET dictionary/contact_types
- *
- * @throws RestException
- */
- public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
- $sql .= " WHERE t.active = ".((int) $active);
- if ($type) {
- $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
- }
- if ($module) {
- $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of contacts types : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of civilities.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $module To filter on module events
- * @param int $active Civility is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of civility types
- *
- * @url GET dictionary/civilities
- *
- * @throws RestException
- */
- public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid, code, label, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
- $sql .= " WHERE t.active = ".((int) $active);
- if ($module) {
- $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of civility : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of currencies.
- *
- * @param int $multicurrency Multicurrency rates (0: no multicurrency, 1: last rate, 2: all rates) {@min 0} {@max 2}
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Payment term is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of currencies
- *
- * @url GET dictionary/currencies
- *
- * @throws RestException
- */
- public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT t.code_iso, t.label, t.unicode";
- if (!empty($multicurrency)) {
- $sql .= " , cr.date_sync, cr.rate ";
- }
- $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
- if (!empty($multicurrency)) {
- $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
- $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
- }
- $sql .= " WHERE t.active = ".((int) $active);
- if (!empty($multicurrency)) {
- $sql .= " AND m.entity IN (".getEntity('multicurrency').")";
- if (!empty($multicurrency) && $multicurrency != 2) {
- $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
- }
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of extra fields.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param string $type Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...)
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'SO-%')"
- * @return array List of extra fields
- *
- * @url GET extrafields
- *
- * @throws RestException
- */
- public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->admin) {
- throw new RestException(401, 'Only an admin user can get list of extrafields');
- }
- if ($type == 'thirdparty') {
- $type = 'societe';
- }
- if ($type == 'contact') {
- $type = 'socpeople';
- }
- $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
- $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
- $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
- if (!empty($type)) {
- $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- $resql = $this->db->query($sql);
- if ($resql) {
- if ($this->db->num_rows($resql)) {
- while ($tab = $this->db->fetch_object($resql)) {
- // New usage
- $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
- $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
- $list[$tab->elementtype][$tab->name]['size'] = $tab->size;
- $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
- $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
- $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
- $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
- $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
- $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
- $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
- $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
- $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
- $list[$tab->elementtype][$tab->name]['list'] = $tab->list;
- }
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
- }
- if (!count($list)) {
- throw new RestException(404, 'No extrafield found');
- }
- return $list;
- }
- /**
- * Get the list of towns.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $zipcode To filter on zipcode
- * @param string $town To filter on city name
- * @param int $active Payment term is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of towns
- *
- * @url GET dictionary/towns
- *
- * @throws RestException
- */
- public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
- $sql .= " AND t.active = ".((int) $active);
- if ($zipcode) {
- $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
- }
- if ($town) {
- $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of payments terms.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Payment term is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter. Syntax example "(t.code:=:'CHQ')"
- *
- * @url GET dictionary/payment_terms
- *
- * @return array List of payment terms
- *
- * @throws RestException 400
- */
- public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
- throw new RestException(401);
- }
- $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
- $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
- $sql .= " AND t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of shipping methods.
- *
- * @param int $limit Number of items per page
- * @param int $page Page number {@min 0}
- * @param int $active Shipping methodsm is active or not {@min 0} {@max 1}
- * @param string $sqlfilters SQL criteria to filter. Syntax example "(t.code:=:'CHQ')"
- *
- * @url GET dictionary/shipping_methods
- *
- * @return array List of shipping methods
- *
- * @throws RestException 400
- */
- public function getShippingModes($limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
- $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
- $sql .= " AND t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- //$sql.= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(400, $this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of measuring units.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Measuring unit is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of measuring unit
- *
- * @url GET dictionary/units
- *
- * @throws RestException
- */
- public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of measuring units: '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of legal form of business.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param string $country To filter on country
- * @param int $active Lega form is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of legal form
- *
- * @url GET dictionary/legal_form
- *
- * @throws RestException
- */
- public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = '', $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t";
- $sql .= " WHERE t.active = ".((int) $active);
- if ($country) {
- $sql .= " AND t.fk_pays = '".$this->db->escape($country)."'";
- }
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of legal form: '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of staff.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Staff is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of staff
- *
- * @url GET dictionary/staff
- *
- * @throws RestException
- */
- public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of staff: '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of social networks.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Social network is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of social networks
- *
- * @url GET dictionary/socialnetworks
- *
- * @throws RestException
- */
- public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- global $conf;
- if (empty($conf->socialnetworks->enabled)) {
- throw new RestException(400, 'API not available: this dictionary is not enabled by setup');
- }
- $list = array();
- //TODO link with multicurrency module
- $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t";
- $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
- $sql .= " AND t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of social networks: '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of tickets categories.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Payment term is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of ticket categories
- *
- * @url GET dictionary/ticket_categories
- *
- * @throws RestException
- */
- public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid, code, pos, label, use_default, description";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
- $sql .= " WHERE t.active = ".((int) $active);
- // Add sql filters
- if ($sqlfilters) {
- if (!DolibarrApi::_checkFilters($sqlfilters)) {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
- $sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0) {
- $page = 0;
- }
- $offset = $limit * $page;
- $sql .= $this->db->plimit($limit, $offset);
- }
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- for ($i = 0; $i < $min; $i++) {
- $list[] = $this->db->fetch_object($result);
- }
- } else {
- throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
- }
- return $list;
- }
- /**
- * Get the list of tickets severity.
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Number of items per page
- * @param int $page Page number (starting from zero)
- * @param int $active Payment term is active or not {@min 0} {@max 1}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
- * @return array List of ticket severities
- *
- * @url GET dictionary/ticket_severities
- *
- * @throws RestException
- */
- public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
- {
- $list = array();
- $sql = "SELECT rowid, code, pos, label, use_default, c…
Large files files are truncated, but you can click here to view the full file