';
}
diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php
index 3b74180f237..eed18bbf8bd 100644
--- a/htdocs/product/class/html.formproduct.class.php
+++ b/htdocs/product/class/html.formproduct.class.php
@@ -206,7 +206,7 @@ class FormProduct
/**
* Return list of warehouses
*
- * @param string|int $selected Id of preselected warehouse ('' for no value, 'ifone'=select value if one value otherwise no value)
+ * @param string|int $selected Id of preselected warehouse ('' or '-1' for no value, 'ifone'=select value if one value otherwise no value, '-2' to use the default value from setup)
* @param string $htmlname Name of html select html
* @param string $filterstatus warehouse status filter, following comma separated filter options can be used
* 'warehouseopen' = select products from open warehouses,
@@ -250,10 +250,10 @@ class FormProduct
if (strpos($htmlname, 'search_') !== 0) {
if (empty($user->fk_warehouse) || $user->fk_warehouse == -1) {
- if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) $selected = $conf->global->MAIN_DEFAULT_WAREHOUSE;
+ if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) $selected = $conf->global->MAIN_DEFAULT_WAREHOUSE;
}
else {
- if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) $selected = $user->fk_warehouse;
+ if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) $selected = $user->fk_warehouse;
}
}
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index ef3da905990..2826d2fe4e3 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -300,9 +300,9 @@ if (empty($reshook))
$multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha'));
$multicurrency_code = GETPOST("multicurrency_code", 'alpha');
- $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, $_POST["multicurrency_price_base_type"], $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type);
+ $ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, GETPOST("multicurrency_price_base_type"), $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type);
} else {
- $ret = $object->update_buyprice($quantity, $newprice, $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type);
+ $ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type);
}
if ($ret < 0)
{
@@ -655,7 +655,7 @@ if ($id > 0 || $ref)
}
$currencies = json_encode($currencies);
- print <<
-SCRIPT;
+END;
} else {
// Price qty min
print '
';
// Description
@@ -690,7 +690,7 @@ if ($action == 'create')
// Ref
print '
| ';
print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).' | ';
diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php
index 509c1419a00..08e839ecee1 100644
--- a/htdocs/societe/class/api_thirdparties.class.php
+++ b/htdocs/societe/class/api_thirdparties.class.php
@@ -2,6 +2,7 @@
/* Copyright (C) 2015 Jean-François Ferry
* Copyright (C) 2018 Pierre Chéné
* Copyright (C) 2019 Cedric Ancelin
+ * Copyright (C) 2020 Frédéric France
*
* 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
@@ -68,7 +69,7 @@ class Thirdparties extends DolibarrApi
* Return an array with thirdparty informations
*
* @param int $id Id of third party to load
- * @return array|mixed data without useless information
+ * @return Object Cleaned Societe object
*
* @throws RestException
*/
@@ -83,7 +84,7 @@ class Thirdparties extends DolibarrApi
* Return an array with thirdparty informations
*
* @param string $email Email of third party to load
- * @return array|mixed data without useless information
+ * @return Object Cleaned Societe object
*
* @url GET email/{email}
*
@@ -100,7 +101,7 @@ class Thirdparties extends DolibarrApi
* Return an array with thirdparty informations
*
* @param string $barcode Barcode of third party to load
- * @return array|mixed data without useless information
+ * @return Object Cleaned Societe object
*
* @url GET barcode/{barcode}
*
@@ -154,9 +155,9 @@ class Thirdparties extends DolibarrApi
$sql .= " AND t.fk_stcomm = st.id";
if ($mode == 1) $sql .= " AND t.client IN (1, 3)";
- if ($mode == 2) $sql .= " AND t.client IN (2, 3)";
- if ($mode == 3) $sql .= " AND t.client IN (0)";
- if ($mode == 4) $sql .= " AND t.fournisseur IN (1)";
+ elseif ($mode == 2) $sql .= " AND t.client IN (2, 3)";
+ elseif ($mode == 3) $sql .= " AND t.client IN (0)";
+ elseif ($mode == 4) $sql .= " AND t.fournisseur IN (1)";
// Select thirdparties of given category
if ($category > 0) {
@@ -188,8 +189,7 @@ class Thirdparties extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
- if ($page < 0)
- {
+ if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@@ -249,7 +249,7 @@ class Thirdparties extends DolibarrApi
*
* @param int $id Id of thirdparty to update
* @param array $request_data Datas
- * @return int
+ * @return Object|boolean
*/
public function put($id, $request_data = null)
{
@@ -271,8 +271,9 @@ class Thirdparties extends DolibarrApi
$this->company->$field = $value;
}
- if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
+ if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) {
return $this->get($id);
+ }
return false;
}
@@ -1840,7 +1841,7 @@ class Thirdparties extends DolibarrApi
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
* @param string $email Email of third party (Warning, this can return several records)
* @param string $ref_alias Name_alias of third party (Warning, this can return several records)
- * @return array|mixed data without useless information
+ * @return Object cleaned Societe object
*
* @throws RestException
*/
@@ -1850,8 +1851,11 @@ class Thirdparties extends DolibarrApi
if (!DolibarrApiAccess::$user->rights->societe->lire) {
throw new RestException(401);
}
-
- $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
+ if ($rowid == 0) {
+ $result = $this->company->initAsSpecimen();
+ } else {
+ $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
+ }
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 5bca91b0700..e67f28c4dab 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -1660,7 +1660,7 @@ class Societe extends CommonObject
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->model_pdf = $obj->model_pdf;
- $this->modelpdf = $obj->model_pdf;
+ $this->modelpdf = $obj->model_pdf; // deprecated
$this->default_lang = $obj->default_lang;
$this->logo = $obj->logo;
$this->logo_squarred = $obj->logo_squarred;
@@ -3765,6 +3765,7 @@ class Societe extends CommonObject
// Initialize parameters
$this->id = 0;
+ $this->entity = 1;
$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog');
$this->nom = $this->name; // For backward compatibility
$this->ref_ext = 'Ref ext';
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index a703816ce71..066d68b8902 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -495,7 +495,7 @@ if (empty($reshook))
// Actions to send emails
$triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
$autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
- $trackid = 'spr'.$object->id;
+ $trackid = 'spro'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Actions to build doc
@@ -1952,7 +1952,7 @@ if ($action == 'create')
$defaulttopic = 'SendAskRef';
$diroutput = $conf->supplier_proposal->dir_output;
$autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
- $trackid = 'spr'.$object->id;
+ $trackid = 'spro'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
}
diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php
index 863ec318798..e189d149bf7 100644
--- a/htdocs/supplier_proposal/class/supplier_proposal.class.php
+++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php
@@ -1699,13 +1699,13 @@ class SupplierProposal extends CommonObject
$resql = $this->db->query($sql);
if ($resql)
{
- $modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED : $this->modelpdf;
+ $modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED : (empty($this->modelpdf) ? '' : $this->modelpdf);
$triggerName = 'PROPOSAL_SUPPLIER_CLOSE_REFUSED';
if ($status == 2)
{
$triggerName = 'PROPOSAL_SUPPLIER_CLOSE_SIGNED';
- $modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL : $this->modelpdf;
+ $modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL : (empty($this->modelpdf) ? '' : $this->modelpdf);
if (!empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) // TODO This option was not tested correctly. Error if product ref does not exists
{
diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php
index 55e00f68c70..39855b866cb 100644
--- a/htdocs/theme/eldy/global.inc.php
+++ b/htdocs/theme/eldy/global.inc.php
@@ -331,15 +331,15 @@ span.timesheetalreadyrecorded input {
border-bottom: solid 1px rgba(0,0,0,0.4);
margin-right: 1px !important;
}
-td.weekend {
- background-color: #eee;
-}
td.onholidaymorning, td.onholidayafternoon {
background-color: #fdf6f2;
}
td.onholidayallday {
background-color: #f4eede;
}
+td.weekend { /* must be after td.onholidayallday */
+ background-color: #eee;
+}
/*
td.leftborder, td.hide0 {
border-left: 1px solid #ccc;
@@ -1272,11 +1272,11 @@ table[summary="list_of_modules"] .fa-cog {
.minwidth500imp { min-width: 250px !important; }
}
-.widthcentpercentminusx {
- width: calc(100% - 50px) !important;
+select.widthcentpercentminusx, input.widthcentpercentminusx {
+ width: calc(100% - 52px) !important;
display: inline-block;
}
-.widthcentpercentminusxx {
+select.widthcentpercentminusxx, input.widthcentpercentminusxx {
width: calc(100% - 70px) !important;
display: inline-block;
}
diff --git a/htdocs/ticket/class/api_tickets.class.php b/htdocs/ticket/class/api_tickets.class.php
index bce4d03fd92..5ba67060552 100644
--- a/htdocs/ticket/class/api_tickets.class.php
+++ b/htdocs/ticket/class/api_tickets.class.php
@@ -29,542 +29,544 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
*/
class Tickets extends DolibarrApi
{
- /**
- * @var array $FIELDS Mandatory fields, checked when create and update object
- */
- public static $FIELDS = array(
- 'subject',
- 'message'
- );
+ /**
+ * @var array $FIELDS Mandatory fields, checked when create and update object
+ */
+ public static $FIELDS = array(
+ 'subject',
+ 'message'
+ );
- /**
- * @var array $FIELDS_MESSAGES Mandatory fields, checked when create and update object
- */
- public static $FIELDS_MESSAGES = array(
- 'track_id',
- 'message'
- );
+ /**
+ * @var array $FIELDS_MESSAGES Mandatory fields, checked when create and update object
+ */
+ public static $FIELDS_MESSAGES = array(
+ 'track_id',
+ 'message'
+ );
- /**
- * @var Ticket $ticket {@type Ticket}
- */
- public $ticket;
+ /**
+ * @var Ticket $ticket {@type Ticket}
+ */
+ public $ticket;
- /**
- * Constructor
- */
- public function __construct()
- {
- global $db;
- $this->db = $db;
- $this->ticket = new Ticket($this->db);
- }
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ global $db;
+ $this->db = $db;
+ $this->ticket = new Ticket($this->db);
+ }
- /**
- * Get properties of a Ticket object.
- *
- * Return an array with ticket informations
- *
- * @param int $id ID of ticket
- * @return array|mixed Data without useless information
- *
- * @throws RestException 401
- * @throws RestException 403
- * @throws RestException 404
- */
- public function get($id)
- {
- return $this->getCommon($id, '', '');
- }
+ /**
+ * Get properties of a Ticket object.
+ *
+ * Return an array with ticket informations
+ *
+ * @param int $id ID of ticket
+ * @return array|mixed Data without useless information
+ *
+ * @throws RestException 401
+ * @throws RestException 403
+ * @throws RestException 404
+ */
+ public function get($id)
+ {
+ return $this->getCommon($id, '', '');
+ }
- /**
- * Get properties of a Ticket object from track id
- *
- * Return an array with ticket informations
- *
- * @param string $track_id Tracking ID of ticket
- * @return array|mixed Data without useless information
- *
- * @url GET track_id/{track_id}
- *
- * @throws RestException 401
- * @throws RestException 403
- * @throws RestException 404
- */
- public function getByTrackId($track_id)
- {
- return $this->getCommon(0, $track_id, '');
- }
+ /**
+ * Get properties of a Ticket object from track id
+ *
+ * Return an array with ticket informations
+ *
+ * @param string $track_id Tracking ID of ticket
+ * @return array|mixed Data without useless information
+ *
+ * @url GET track_id/{track_id}
+ *
+ * @throws RestException 401
+ * @throws RestException 403
+ * @throws RestException 404
+ */
+ public function getByTrackId($track_id)
+ {
+ return $this->getCommon(0, $track_id, '');
+ }
- /**
- * Get properties of a Ticket object from ref
- *
- * Return an array with ticket informations
- *
- * @param string $ref Reference for ticket
- * @return array|mixed Data without useless information
- *
- * @url GET ref/{ref}
- *
- * @throws RestException 401
- * @throws RestException 403
- * @throws RestException 404
- */
- public function getByRef($ref)
- {
- try {
- return $this->getCommon(0, '', $ref);
- } catch (Exception $e)
- {
- throw $e;
- }
- }
+ /**
+ * Get properties of a Ticket object from ref
+ *
+ * Return an array with ticket informations
+ *
+ * @param string $ref Reference for ticket
+ * @return array|mixed Data without useless information
+ *
+ * @url GET ref/{ref}
+ *
+ * @throws RestException 401
+ * @throws RestException 403
+ * @throws RestException 404
+ */
+ public function getByRef($ref)
+ {
+ try {
+ return $this->getCommon(0, '', $ref);
+ } catch (Exception $e)
+ {
+ throw $e;
+ }
+ }
- /**
- * Get properties of a Ticket object
- * Return an array with ticket informations
- *
- * @param int $id ID of ticket
- * @param string $track_id Tracking ID of ticket
- * @param string $ref Reference for ticket
- * @return array|mixed Data without useless information
- */
- private function getCommon($id = 0, $track_id = '', $ref = '')
- {
- if (!DolibarrApiAccess::$user->rights->ticket->read) {
- throw new RestException(403);
- }
+ /**
+ * Get properties of a Ticket object
+ * Return an array with ticket informations
+ *
+ * @param int $id ID of ticket
+ * @param string $track_id Tracking ID of ticket
+ * @param string $ref Reference for ticket
+ * @return array|mixed Data without useless information
+ */
+ private function getCommon($id = 0, $track_id = '', $ref = '')
+ {
+ if (!DolibarrApiAccess::$user->rights->ticket->read) {
+ throw new RestException(403);
+ }
- // Check parameters
- if (!$id && !$track_id && !$ref) {
- throw new RestException(401, 'Wrong parameters');
- }
-
- $result = $this->ticket->fetch($id, $ref, $track_id);
- if (!$result) {
- throw new RestException(404, 'Ticket not found');
- }
-
- // String for user assigned
- if ($this->ticket->fk_user_assign > 0) {
- $userStatic = new User($this->db);
- $userStatic->fetch($this->ticket->fk_user_assign);
- $this->ticket->fk_user_assign_string = $userStatic->firstname.' '.$userStatic->lastname;
- }
-
- // Messages of ticket
- $messages = array();
- $this->ticket->loadCacheMsgsTicket();
- if (is_array($this->ticket->cache_msgs_ticket) && count($this->ticket->cache_msgs_ticket) > 0) {
- $num = count($this->ticket->cache_msgs_ticket);
- $i = 0;
- while ($i < $num) {
- if ($this->ticket->cache_msgs_ticket[$i]['fk_user_author'] > 0) {
- $user_action = new User($this->db);
- $user_action->fetch($this->ticket->cache_msgs_ticket[$i]['fk_user_author']);
- }
-
- // Now define messages
- $messages[] = array(
- 'id' => $this->ticket->cache_msgs_ticket[$i]['id'],
- 'fk_user_action' => $this->ticket->cache_msgs_ticket[$i]['fk_user_author'],
- 'fk_user_action_socid' => $user_action->socid,
- 'fk_user_action_string' => dolGetFirstLastname($user_action->firstname, $user_action->lastname),
- 'message' => $this->ticket->cache_msgs_ticket[$i]['message'],
- 'datec' => $this->ticket->cache_msgs_ticket[$i]['datec'],
- 'private' => $this->ticket->cache_msgs_ticket[$i]['private']
- );
- $i++;
- }
- $this->ticket->messages = $messages;
- }
-
- // History
- $history = array();
- $this->ticket->loadCacheLogsTicket();
- if (is_array($this->ticket->cache_logs_ticket) && count($this->ticket->cache_logs_ticket) > 0) {
- $num = count($this->ticket->cache_logs_ticket);
- $i = 0;
- while ($i < $num) {
- if ($this->ticket->cache_logs_ticket[$i]['fk_user_create'] > 0) {
- $user_action = new User($this->db);
- $user_action->fetch($this->ticket->cache_logs_ticket[$i]['fk_user_create']);
- }
-
- // Now define messages
- $history[] = array(
- 'id' => $this->ticket->cache_logs_ticket[$i]['id'],
- 'fk_user_author' => $this->ticket->cache_msgs_ticket[$i]['fk_user_author'],
- 'fk_user_action' => $this->ticket->cache_logs_ticket[$i]['fk_user_create'],
- 'fk_user_action_string' => dolGetFirstLastname($user_action->firstname, $user_action->lastname),
- 'message' => $this->ticket->cache_logs_ticket[$i]['message'],
- 'datec' => $this->ticket->cache_logs_ticket[$i]['datec'],
- );
- $i++;
- }
- $this->ticket->history = $history;
- }
-
-
- if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
- return $this->_cleanObjectDatas($this->ticket);
- }
-
- /**
- * List tickets
- *
- * Get a list of tickets
- *
- * @param int $socid Filter list with thirdparty ID
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Limit for list
- * @param int $page Page number
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101') and (t.fk_statut:=:1)"
- *
- * @return array Array of ticket objects
- *
- */
- public function index($socid = 0, $sortfield = "t.rowid", $sortorder = "ASC", $limit = 100, $page = 0, $sqlfilters = '')
- {
- global $db, $conf;
-
- $obj_ret = array();
-
- if (!$socid && DolibarrApiAccess::$user->socid) {
- $socid = DolibarrApiAccess::$user->socid;
- }
-
- // If the internal user must only see his customers, force searching by him
- if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
- $search_sale = DolibarrApiAccess::$user->id;
- }
-
- $sql = "SELECT t.rowid";
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
- $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
- }
- $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
-
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
- $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
- }
-
- $sql .= ' WHERE t.entity IN ('.getEntity('ticket', 1).')';
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
- $sql .= " AND t.fk_soc = sc.fk_soc";
- }
- if ($socid > 0) {
- $sql .= " AND t.fk_soc = ".$socid;
- }
- if ($search_sale > 0) {
- $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
- }
-
- // Insert sale filter
- if ($search_sale > 0) {
- $sql .= " AND sc.fk_user = ".$search_sale;
- }
- // 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);
- $i = 0;
- while ($i < $num) {
- $obj = $this->db->fetch_object($result);
- $ticket_static = new Ticket($this->db);
- if ($ticket_static->fetch($obj->rowid)) {
- if ($ticket_static->fk_user_assign > 0) {
- $userStatic = new User($this->db);
- $userStatic->fetch($ticket_static->fk_user_assign);
- $ticket_static->fk_user_assign_string = $userStatic->firstname.' '.$userStatic->lastname;
- }
- $obj_ret[] = $this->_cleanObjectDatas($ticket_static);
- }
- $i++;
- }
+ // Check parameters
+ if (($id < 0) && !$track_id && !$ref) {
+ throw new RestException(401, 'Wrong parameters');
+ }
+ if ($id == 0) {
+ $result = $this->ticket->initAsSpecimen();
} else {
- throw new RestException(503, 'Error when retrieve ticket list');
+ $result = $this->ticket->fetch($id, $ref, $track_id);
}
- if (!count($obj_ret)) {
- throw new RestException(404, 'No ticket found');
- }
- return $obj_ret;
- }
+ if (!$result) {
+ throw new RestException(404, 'Ticket not found');
+ }
- /**
- * Create ticket object
- *
- * @param array $request_data Request datas
- * @return int ID of ticket
- */
- public function post($request_data = null)
- {
- $ticketstatic = new Ticket($this->db);
- if (!DolibarrApiAccess::$user->rights->ticket->write) {
- throw new RestException(401);
- }
- // Check mandatory fields
- $result = $this->_validate($request_data);
+ // String for user assigned
+ if ($this->ticket->fk_user_assign > 0) {
+ $userStatic = new User($this->db);
+ $userStatic->fetch($this->ticket->fk_user_assign);
+ $this->ticket->fk_user_assign_string = $userStatic->firstname.' '.$userStatic->lastname;
+ }
- foreach ($request_data as $field => $value) {
- $this->ticket->$field = $value;
- }
- if (empty($this->ticket->ref)) {
- $this->ticket->ref = $ticketstatic->getDefaultRef();
- }
- if (empty($this->ticket->track_id)) {
- $this->ticket->track_id = generate_random_id(16);
- }
+ // Messages of ticket
+ $messages = array();
+ $this->ticket->loadCacheMsgsTicket();
+ if (is_array($this->ticket->cache_msgs_ticket) && count($this->ticket->cache_msgs_ticket) > 0) {
+ $num = count($this->ticket->cache_msgs_ticket);
+ $i = 0;
+ while ($i < $num) {
+ if ($this->ticket->cache_msgs_ticket[$i]['fk_user_author'] > 0) {
+ $user_action = new User($this->db);
+ $user_action->fetch($this->ticket->cache_msgs_ticket[$i]['fk_user_author']);
+ }
- if ($this->ticket->create(DolibarrApiAccess::$user) < 0) {
- throw new RestException(500, "Error creating ticket", array_merge(array($this->ticket->error), $this->ticket->errors));
- }
+ // Now define messages
+ $messages[] = array(
+ 'id' => $this->ticket->cache_msgs_ticket[$i]['id'],
+ 'fk_user_action' => $this->ticket->cache_msgs_ticket[$i]['fk_user_author'],
+ 'fk_user_action_socid' => $user_action->socid,
+ 'fk_user_action_string' => dolGetFirstLastname($user_action->firstname, $user_action->lastname),
+ 'message' => $this->ticket->cache_msgs_ticket[$i]['message'],
+ 'datec' => $this->ticket->cache_msgs_ticket[$i]['datec'],
+ 'private' => $this->ticket->cache_msgs_ticket[$i]['private']
+ );
+ $i++;
+ }
+ $this->ticket->messages = $messages;
+ }
- return $this->ticket->id;
- }
+ // History
+ $history = array();
+ $this->ticket->loadCacheLogsTicket();
+ if (is_array($this->ticket->cache_logs_ticket) && count($this->ticket->cache_logs_ticket) > 0) {
+ $num = count($this->ticket->cache_logs_ticket);
+ $i = 0;
+ while ($i < $num) {
+ if ($this->ticket->cache_logs_ticket[$i]['fk_user_create'] > 0) {
+ $user_action = new User($this->db);
+ $user_action->fetch($this->ticket->cache_logs_ticket[$i]['fk_user_create']);
+ }
- /**
- * Create ticket object
- *
- * @param array $request_data Request datas
- * @return int ID of ticket
- *
- */
- public function postNewMessage($request_data = null)
- {
- $ticketstatic = new Ticket($this->db);
- if (!DolibarrApiAccess::$user->rights->ticket->write) {
- throw new RestException(401);
- }
- // Check mandatory fields
- $result = $this->_validateMessage($request_data);
+ // Now define messages
+ $history[] = array(
+ 'id' => $this->ticket->cache_logs_ticket[$i]['id'],
+ 'fk_user_author' => $this->ticket->cache_msgs_ticket[$i]['fk_user_author'],
+ 'fk_user_action' => $this->ticket->cache_logs_ticket[$i]['fk_user_create'],
+ 'fk_user_action_string' => dolGetFirstLastname($user_action->firstname, $user_action->lastname),
+ 'message' => $this->ticket->cache_logs_ticket[$i]['message'],
+ 'datec' => $this->ticket->cache_logs_ticket[$i]['datec'],
+ );
+ $i++;
+ }
+ $this->ticket->history = $history;
+ }
- foreach ($request_data as $field => $value) {
- $this->ticket->$field = $value;
- }
- $ticketMessageText = $this->ticket->message;
- $result = $this->ticket->fetch('', '', $this->ticket->track_id);
- if (!$result) {
- throw new RestException(404, 'Ticket not found');
- }
- $this->ticket->message = $ticketMessageText;
- if (!$this->ticket->createTicketMessage(DolibarrApiAccess::$user)) {
- throw new RestException(500);
- }
- return $this->ticket->id;
- }
+ if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+ return $this->_cleanObjectDatas($this->ticket);
+ }
- /**
- * Update ticket
- *
- * @param int $id Id of ticket to update
- * @param array $request_data Datas
- * @return int
- *
- */
- public function put($id, $request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->ticket->write) {
- throw new RestException(401);
- }
+ /**
+ * List tickets
+ *
+ * Get a list of tickets
+ *
+ * @param int $socid Filter list with thirdparty ID
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
+ * @param int $limit Limit for list
+ * @param int $page Page number
+ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101') and (t.fk_statut:=:1)"
+ *
+ * @return array Array of ticket objects
+ *
+ */
+ public function index($socid = 0, $sortfield = "t.rowid", $sortorder = "ASC", $limit = 100, $page = 0, $sqlfilters = '')
+ {
+ global $db, $conf;
- $result = $this->ticket->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Ticket not found');
- }
+ $obj_ret = array();
- if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ if (!$socid && DolibarrApiAccess::$user->socid) {
+ $socid = DolibarrApiAccess::$user->socid;
+ }
- foreach ($request_data as $field => $value) {
- $this->ticket->$field = $value;
- }
+ // If the internal user must only see his customers, force searching by him
+ if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
+ $search_sale = DolibarrApiAccess::$user->id;
+ }
- if ($this->ticket->update($id, DolibarrApiAccess::$user)) {
- return $this->get($id);
- }
+ $sql = "SELECT t.rowid";
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
+ $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+ }
+ $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
- return false;
- }
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
+ $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+ }
- /**
- * Delete ticket
- *
- * @param int $id Ticket ID
- * @return array
- *
- */
- public function delete($id)
- {
- if (!DolibarrApiAccess::$user->rights->ticket->delete) {
- throw new RestException(401);
- }
- $result = $this->ticket->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Ticket not found');
- }
+ $sql .= ' WHERE t.entity IN ('.getEntity('ticket', 1).')';
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
+ $sql .= " AND t.fk_soc = sc.fk_soc";
+ }
+ if ($socid > 0) {
+ $sql .= " AND t.fk_soc = ".$socid;
+ }
+ if ($search_sale > 0) {
+ $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
+ }
- if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ // Insert sale filter
+ if ($search_sale > 0) {
+ $sql .= " AND sc.fk_user = ".$search_sale;
+ }
+ // 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).")";
+ }
- if (!$this->ticket->delete($id)) {
- throw new RestException(500);
- }
+ $sql .= $this->db->order($sortfield, $sortorder);
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'Ticket deleted'
- )
- );
- }
+ if ($limit) {
+ if ($page < 0) {
+ $page = 0;
+ }
+ $offset = $limit * $page;
- /**
- * Validate fields before create or update object
- *
- * @param array $data Data to validate
- * @return array
- *
- * @throws RestException
- */
- private function _validate($data)
- {
- $ticket = array();
- foreach (Tickets::$FIELDS as $field) {
- if (!isset($data[$field])) {
- throw new RestException(400, "$field field missing");
- }
- $ticket[$field] = $data[$field];
- }
- return $ticket;
- }
+ $sql .= $this->db->plimit($limit, $offset);
+ }
- /**
- * Validate fields before create or update object message
- *
- * @param array $data Data to validate
- * @return array
- *
- * @throws RestException
- */
- private function _validateMessage($data)
- {
- $ticket = array();
- foreach (Tickets::$FIELDS_MESSAGES as $field) {
- if (!isset($data[$field])) {
- throw new RestException(400, "$field field missing");
- }
- $ticket[$field] = $data[$field];
- }
- return $ticket;
- }
+ $result = $this->db->query($sql);
+ if ($result) {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+ while ($i < $num) {
+ $obj = $this->db->fetch_object($result);
+ $ticket_static = new Ticket($this->db);
+ if ($ticket_static->fetch($obj->rowid)) {
+ if ($ticket_static->fk_user_assign > 0) {
+ $userStatic = new User($this->db);
+ $userStatic->fetch($ticket_static->fk_user_assign);
+ $ticket_static->fk_user_assign_string = $userStatic->firstname.' '.$userStatic->lastname;
+ }
+ $obj_ret[] = $this->_cleanObjectDatas($ticket_static);
+ }
+ $i++;
+ }
+ } else {
+ throw new RestException(503, 'Error when retrieve ticket list');
+ }
+ if (!count($obj_ret)) {
+ throw new RestException(404, 'No ticket found');
+ }
+ return $obj_ret;
+ }
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
- /**
- * Clean sensible object datas
- *
- * @param Object $object Object to clean
- * @return Object Object with cleaned properties
- *
- * @todo use an array for properties to clean
- *
- */
- protected function _cleanObjectDatas($object)
- {
- // phpcs:enable
- $object = parent::_cleanObjectDatas($object);
+ /**
+ * Create ticket object
+ *
+ * @param array $request_data Request datas
+ * @return int ID of ticket
+ */
+ public function post($request_data = null)
+ {
+ $ticketstatic = new Ticket($this->db);
+ if (!DolibarrApiAccess::$user->rights->ticket->write) {
+ throw new RestException(401);
+ }
+ // Check mandatory fields
+ $result = $this->_validate($request_data);
- // Other attributes to clean
- $attr2clean = array(
- "contact",
- "contact_id",
- "ref_previous",
- "ref_next",
- "ref_ext",
- "table_element_line",
- "statut",
- "country",
- "country_id",
- "country_code",
- "barcode_type",
- "barcode_type_code",
- "barcode_type_label",
- "barcode_type_coder",
- "mode_reglement_id",
- "cond_reglement_id",
- "cond_reglement",
- "fk_delivery_address",
- "shipping_method_id",
- "modelpdf",
- "fk_account",
- "note_public",
- "note_private",
- "note",
- "total_ht",
- "total_tva",
- "total_localtax1",
- "total_localtax2",
- "total_ttc",
- "fk_incoterms",
- "label_incoterms",
- "location_incoterms",
- "name",
- "lastname",
- "firstname",
- "civility_id",
- "canvas",
- "cache_msgs_ticket",
- "cache_logs_ticket",
- "cache_types_tickets",
- "cache_category_tickets",
- "regeximgext",
- "statuts_short",
- "statuts"
- );
- foreach ($attr2clean as $toclean) {
- unset($object->$toclean);
- }
+ foreach ($request_data as $field => $value) {
+ $this->ticket->$field = $value;
+ }
+ if (empty($this->ticket->ref)) {
+ $this->ticket->ref = $ticketstatic->getDefaultRef();
+ }
+ if (empty($this->ticket->track_id)) {
+ $this->ticket->track_id = generate_random_id(16);
+ }
- // If object has lines, remove $db property
- if (isset($object->lines) && count($object->lines) > 0) {
- $nboflines = count($object->lines);
- for ($i = 0; $i < $nboflines; $i++) {
- $this->_cleanObjectDatas($object->lines[$i]);
- }
- }
+ if ($this->ticket->create(DolibarrApiAccess::$user) < 0) {
+ throw new RestException(500, "Error creating ticket", array_merge(array($this->ticket->error), $this->ticket->errors));
+ }
- // If object has linked objects, remove $db property
- if (isset($object->linkedObjects) && count($object->linkedObjects) > 0) {
- foreach ($object->linkedObjects as $type_object => $linked_object) {
- foreach ($linked_object as $object2clean) {
- $this->_cleanObjectDatas($object2clean);
- }
- }
- }
- return $object;
- }
+ return $this->ticket->id;
+ }
+
+ /**
+ * Create ticket object
+ *
+ * @param array $request_data Request datas
+ * @return int ID of ticket
+ *
+ */
+ public function postNewMessage($request_data = null)
+ {
+ $ticketstatic = new Ticket($this->db);
+ if (!DolibarrApiAccess::$user->rights->ticket->write) {
+ throw new RestException(401);
+ }
+ // Check mandatory fields
+ $result = $this->_validateMessage($request_data);
+
+ foreach ($request_data as $field => $value) {
+ $this->ticket->$field = $value;
+ }
+ $ticketMessageText = $this->ticket->message;
+ $result = $this->ticket->fetch('', '', $this->ticket->track_id);
+ if (!$result) {
+ throw new RestException(404, 'Ticket not found');
+ }
+ $this->ticket->message = $ticketMessageText;
+ if (!$this->ticket->createTicketMessage(DolibarrApiAccess::$user)) {
+ throw new RestException(500);
+ }
+ return $this->ticket->id;
+ }
+
+ /**
+ * Update ticket
+ *
+ * @param int $id Id of ticket to update
+ * @param array $request_data Datas
+ * @return int
+ *
+ */
+ public function put($id, $request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->ticket->write) {
+ throw new RestException(401);
+ }
+
+ $result = $this->ticket->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Ticket not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ foreach ($request_data as $field => $value) {
+ $this->ticket->$field = $value;
+ }
+
+ if ($this->ticket->update($id, DolibarrApiAccess::$user)) {
+ return $this->get($id);
+ }
+
+ return false;
+ }
+
+ /**
+ * Delete ticket
+ *
+ * @param int $id Ticket ID
+ * @return array
+ *
+ */
+ public function delete($id)
+ {
+ if (!DolibarrApiAccess::$user->rights->ticket->delete) {
+ throw new RestException(401);
+ }
+ $result = $this->ticket->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Ticket not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('ticket', $this->ticket->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ if (!$this->ticket->delete($id)) {
+ throw new RestException(500);
+ }
+
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Ticket deleted'
+ )
+ );
+ }
+
+ /**
+ * Validate fields before create or update object
+ *
+ * @param array $data Data to validate
+ * @return array
+ *
+ * @throws RestException
+ */
+ private function _validate($data)
+ {
+ $ticket = array();
+ foreach (Tickets::$FIELDS as $field) {
+ if (!isset($data[$field])) {
+ throw new RestException(400, "$field field missing");
+ }
+ $ticket[$field] = $data[$field];
+ }
+ return $ticket;
+ }
+
+ /**
+ * Validate fields before create or update object message
+ *
+ * @param array $data Data to validate
+ * @return array
+ *
+ * @throws RestException
+ */
+ private function _validateMessage($data)
+ {
+ $ticket = array();
+ foreach (Tickets::$FIELDS_MESSAGES as $field) {
+ if (!isset($data[$field])) {
+ throw new RestException(400, "$field field missing");
+ }
+ $ticket[$field] = $data[$field];
+ }
+ return $ticket;
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
+ /**
+ * Clean sensible object datas
+ *
+ * @param Object $object Object to clean
+ * @return Object Object with cleaned properties
+ *
+ * @todo use an array for properties to clean
+ *
+ */
+ protected function _cleanObjectDatas($object)
+ {
+ // phpcs:enable
+ $object = parent::_cleanObjectDatas($object);
+
+ // Other attributes to clean
+ $attr2clean = array(
+ "contact",
+ "contact_id",
+ "ref_previous",
+ "ref_next",
+ "ref_ext",
+ "table_element_line",
+ "statut",
+ "country",
+ "country_id",
+ "country_code",
+ "barcode_type",
+ "barcode_type_code",
+ "barcode_type_label",
+ "barcode_type_coder",
+ "mode_reglement_id",
+ "cond_reglement_id",
+ "cond_reglement",
+ "fk_delivery_address",
+ "shipping_method_id",
+ "modelpdf",
+ "fk_account",
+ "note_public",
+ "note_private",
+ "note",
+ "total_ht",
+ "total_tva",
+ "total_localtax1",
+ "total_localtax2",
+ "total_ttc",
+ "fk_incoterms",
+ "label_incoterms",
+ "location_incoterms",
+ "name",
+ "lastname",
+ "firstname",
+ "civility_id",
+ "canvas",
+ "cache_msgs_ticket",
+ "cache_logs_ticket",
+ "cache_types_tickets",
+ "cache_category_tickets",
+ "regeximgext",
+ "statuts_short",
+ "statuts"
+ );
+ foreach ($attr2clean as $toclean) {
+ unset($object->$toclean);
+ }
+
+ // If object has lines, remove $db property
+ if (isset($object->lines) && count($object->lines) > 0) {
+ $nboflines = count($object->lines);
+ for ($i = 0; $i < $nboflines; $i++) {
+ $this->_cleanObjectDatas($object->lines[$i]);
+ }
+ }
+
+ // If object has linked objects, remove $db property
+ if (isset($object->linkedObjects) && count($object->linkedObjects) > 0) {
+ foreach ($object->linkedObjects as $type_object => $linked_object) {
+ foreach ($linked_object as $object2clean) {
+ $this->_cleanObjectDatas($object2clean);
+ }
+ }
+ }
+ return $object;
+ }
}
diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php
index 0b7ce39a83c..e5818fa7762 100644
--- a/htdocs/ticket/class/ticket.class.php
+++ b/htdocs/ticket/class/ticket.class.php
@@ -108,7 +108,7 @@ class Ticket extends CommonObject
/**
* @var int Ticket statut
- * @deprecated
+ * @deprecated
*/
public $fk_statut;
@@ -197,6 +197,9 @@ class Ticket extends CommonObject
*/
public $notify_tiers_at_create;
+ /**
+ * @var string msgid
+ */
public $email_msgid;
public $lines;
@@ -1076,7 +1079,7 @@ class Ticket extends CommonObject
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
- * @return void
+ * @return int
*/
public function initAsSpecimen()
{
@@ -1101,6 +1104,7 @@ class Ticket extends CommonObject
$this->date_read = '';
$this->date_close = '';
$this->tms = '';
+ return 1;
}
/**
diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php
index 3d82c9b6cf2..32cf9eccfe3 100644
--- a/htdocs/ticket/list.php
+++ b/htdocs/ticket/list.php
@@ -584,7 +584,7 @@ if ($mode == 'mine') {
$topicmail = "SendTicketRef";
$modelmail = "ticket";
$objecttmp = new Ticket($db);
-$trackid = 'tick'.$object->id;
+$trackid = 'tic'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($search_all)
diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php
index 2f2c1ee0a86..b1f0b7d4785 100644
--- a/htdocs/user/bank.php
+++ b/htdocs/user/bank.php
@@ -76,6 +76,8 @@ if (!$bankid)
}
if (empty($account->userid)) $account->userid = $object->id;
+$permissiontoaddbankaccount = (!empty($user->rights->salaries->write) || !empty($user->rights->hrm->employee->write) || !empty($user->rights->user->creer));
+
/*
* Actions
@@ -172,8 +174,7 @@ if ($action == 'update' && !$cancel)
$result = $account->update($user);
- if (!$result)
- {
+ if (!$result) {
setEventMessages($account->error, $account->errors, 'errors');
$action = 'edit'; // Force chargement page edition
} else {
@@ -183,32 +184,28 @@ if ($action == 'update' && !$cancel)
}
// update personal email
-if ($action == 'setpersonal_email')
-{
- $object->personal_email = GETPOST('personal_email');
+if ($action == 'setpersonal_email') {
+ $object->personal_email = (string) GETPOST('personal_email', 'alphanohtml');
$result = $object->update($user);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
}
// update personal mobile
-if ($action == 'setpersonal_mobile')
-{
- $object->personal_mobile = GETPOST('personal_mobile');
+if ($action == 'setpersonal_mobile') {
+ $object->personal_mobile = (string) GETPOST('personal_mobile', 'alphanohtml');
$result = $object->update($user);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
}
// update default_c_exp_tax_cat
-if ($action == 'setdefault_c_exp_tax_cat')
-{
+if ($action == 'setdefault_c_exp_tax_cat') {
$object->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat', 'int');
$result = $object->update($user);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
}
// update default range
-if ($action == 'setdefault_range')
-{
+if ($action == 'setdefault_range') {
$object->default_range = GETPOST('default_range', 'int');
$result = $object->update($user);
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
@@ -505,7 +502,13 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco
$morehtmlright = '';
if ($account->id == 0) {
- $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=create');
+ if ($permissiontoaddbankaccount) {
+ $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=create');
+ } else {
+ $morehtmlright = dolGetButtonTitle($langs->trans('Add'), 'NotEnoughPermission', 'fa fa-plus-circle', '', '', -2);
+ }
+ } else {
+ $morehtmlright = dolGetButtonTitle($langs->trans('Add'), 'AlreadyOneBankAccount', 'fa fa-plus-circle', '', '', -2);
}
print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank_account');
@@ -571,8 +574,8 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco
// Edit/Delete
print '';
- if ($user->rights->hrm->employee->write || $user->rights->user->creer) {
- print 'id.'&bankid='.$account->id.'&action=edit">';
+ if ($permissiontoaddbankaccount) {
+ print 'id.'&bankid='.$account->id.'&action=edit">';
print img_picto($langs->trans("Modify"), 'edit');
print '';
}
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index b7b3fdc689e..6a928e0bfee 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -690,12 +690,6 @@ llxHeader('', $langs->trans("UserCard"));
if ($action == 'create' || $action == 'adduserldap')
{
- /* ************************************************************************** */
- /* */
- /* Affichage fiche en mode creation */
- /* */
- /* ************************************************************************** */
-
print load_fiche_titre($langs->trans("NewUser"), '', 'user');
print ''.$langs->trans("CreateInternalUserDesc")." \n";
@@ -704,11 +698,7 @@ if ($action == 'create' || $action == 'adduserldap')
if (!empty($conf->ldap->enabled) && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr'))
{
- /*
- * Affiche formulaire d'ajout d'un compte depuis LDAP
- * si on est en synchro LDAP vers Dolibarr
- */
-
+ // Show form to add an account from LDAP if sync LDAP -> Dolibarr is set
$ldap = new Ldap();
$result = $ldap->connect_bind();
if ($result >= 0)
@@ -1272,12 +1262,7 @@ if ($action == 'create' || $action == 'adduserldap')
print "";
} else {
- /* ************************************************************************** */
- /* */
- /* View and edition */
- /* */
- /* ************************************************************************** */
-
+ // View and edit mode
if ($id > 0)
{
$object->fetch($id, '', '', 1);
@@ -1576,10 +1561,12 @@ if ($action == 'create' || $action == 'adduserldap')
if (!empty($conf->stock->enabled) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
- $warehousestatic = new Entrepot($db);
- $warehousestatic->fetch($object->fk_warehouse);
print ' | | '.$langs->trans("DefaultWarehouse").' | ';
- print $warehousestatic->getNomUrl(1);
+ if ($object->fk_warehouse > 0) {
+ $warehousestatic = new Entrepot($db);
+ $warehousestatic->fetch($object->fk_warehouse);
+ print $warehousestatic->getNomUrl(1);
+ }
print ' | ';
}
diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php
index d04c735eeed..9a89ad8e81c 100644
--- a/htdocs/user/class/api_users.class.php
+++ b/htdocs/user/class/api_users.class.php
@@ -153,13 +153,16 @@ class Users extends DolibarrApi
//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
//throw new RestException(401);
//}
-
- $result = $this->useraccount->fetch($id);
+ if ($id == 0) {
+ $result = $this->useraccount->initAsSpecimen();
+ } else {
+ $result = $this->useraccount->fetch($id);
+ }
if (!$result) {
throw new RestException(404, 'User not found');
}
- if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
+ if ($id > 0 && !DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
@@ -286,11 +289,11 @@ class Users extends DolibarrApi
//}
// check mandatory fields
/*if (!isset($request_data["login"]))
- throw new RestException(400, "login field missing");
- if (!isset($request_data["password"]))
- throw new RestException(400, "password field missing");
- if (!isset($request_data["lastname"]))
- throw new RestException(400, "lastname field missing");*/
+ throw new RestException(400, "login field missing");
+ if (!isset($request_data["password"]))
+ throw new RestException(400, "password field missing");
+ if (!isset($request_data["lastname"]))
+ throw new RestException(400, "lastname field missing");*/
//assign field values
foreach ($request_data as $field => $value) {
$this->useraccount->$field = $value;
@@ -327,9 +330,10 @@ class Users extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- foreach ($request_data as $field => $value)
- {
- if ($field == 'id') continue;
+ foreach ($request_data as $field => $value) {
+ if ($field == 'id') {
+ continue;
+ }
// The status must be updated using setstatus() because it
// is not handled by the update() method.
if ($field == 'statut') {
@@ -461,7 +465,9 @@ class Users extends DolibarrApi
$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t";
$sql .= ' WHERE t.entity IN ('.getEntity('user').')';
- if ($group_ids) $sql .= " AND t.rowid IN (".$group_ids.")";
+ if ($group_ids) {
+ $sql .= " AND t.rowid IN (".$group_ids.")";
+ }
// Add sql filters
if ($sqlfilters) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
@@ -483,13 +489,11 @@ class Users extends DolibarrApi
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$i = 0;
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
- while ($i < $min)
- {
+ while ($i < $min) {
$obj = $this->db->fetch_object($result);
$group_static = new UserGroup($this->db);
if ($group_static->fetch($obj->rowid)) {
@@ -562,8 +566,8 @@ class Users extends DolibarrApi
/**
* Clean sensible object datas
*
- * @param Object $object Object to clean
- * @return Object Object with cleaned properties
+ * @param Object $object Object to clean
+ * @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
@@ -681,8 +685,9 @@ class Users extends DolibarrApi
{
$account = array();
foreach (Users::$FIELDS as $field) {
- if (!isset($data[$field]))
+ if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
+ }
$account[$field] = $data[$field];
}
return $account;
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 197194245e4..31c884e9f2c 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -87,13 +87,19 @@ class User extends CommonObject
*/
public $personal_email;
-
/**
* @var array array of socialnetworks
*/
public $socialnetworks;
- public $job; // job position
+ /**
+ * @var string job position
+ */
+ public $job;
+
+ /**
+ * @var string user signature
+ */
public $signature;
/**
@@ -113,12 +119,40 @@ class User extends CommonObject
public $state_id; // The state/department
public $state_code;
public $state;
+
+ /**
+ * @var string office phone
+ */
public $office_phone;
+
+ /**
+ * @var string office fax
+ */
public $office_fax;
+
+ /**
+ * @var string phone mobile
+ */
public $user_mobile;
+
+ /**
+ * @var string personal phone mobile
+ */
public $personal_mobile;
+
+ /**
+ * @var int 1 if admin 0 if standard user
+ */
public $admin;
+
+ /**
+ * @var string user login
+ */
public $login;
+
+ /**
+ * @var string user apikey
+ */
public $api_key;
/**
@@ -141,6 +175,11 @@ class User extends CommonObject
*/
public $pass_indatabase_crypted;
+ /**
+ * @var string Temporary password
+ */
+ public $pass_temp;
+
/**
* Date creation record (datec)
*
@@ -155,9 +194,14 @@ class User extends CommonObject
*/
public $datem;
- //! If this is defined, it is an external user
+ /**
+ * @var int If this is defined, it is an external user
+ */
public $socid;
- //! If this is defined, it is a user created from a contact
+
+ /**
+ * @var int If this is defined, it is a user created from a contact
+ */
public $contact_id;
/**
@@ -170,27 +214,71 @@ class User extends CommonObject
*/
public $fk_user;
+ /**
+ * @var int User ID of expense validator
+ */
public $fk_user_expense_validator;
+
+ /**
+ * @var int User ID of holidays validator
+ */
public $fk_user_holiday_validator;
+ /**
+ * @string clicktodial url
+ */
public $clicktodial_url;
+
+ /**
+ * @var string clicktodial login
+ */
public $clicktodial_login;
+
+ /**
+ * @var string clicktodial password
+ */
public $clicktodial_password;
+
+ /**
+ * @var string clicktodial poste
+ */
public $clicktodial_poste;
public $datelastlogin;
public $datepreviouslogin;
public $datestartvalidity;
public $dateendvalidity;
+
+ /**
+ * @var string photo filename
+ */
public $photo;
public $lang;
- public $rights; // Array of permissions user->rights->permx
- public $all_permissions_are_loaded; // All permission are loaded
- public $nb_rights; // Number of rights granted to the user
- private $_tab_loaded = array(); // Cache array of already loaded permissions
+ /**
+ * @var stdClass Class of permissions user->rights->permx
+ */
+ public $rights;
- public $conf; // To store personal config
+ /**
+ * @var int All permissions are loaded
+ */
+ public $all_permissions_are_loaded;
+
+ /**
+ * @var int Number of rights granted to the user
+ */
+ public $nb_rights;
+
+ /**
+ * @var array Cache array of already loaded permissions
+ */
+ private $_tab_loaded = array();
+
+ /**
+ * @var stdClass To store personal config
+ */
+ public $conf;
public $default_values; // To store default values for user
public $lastsearch_values_tmp; // To store current search criterias for user
public $lastsearch_values; // To store last saved search criterias for user
@@ -208,7 +296,10 @@ class User extends CommonObject
public $salaryextra; // Monthly salary extra - Denormalized value from llx_user_employment
public $weeklyhours; // Weekly hours - Denormalized value from llx_user_employment
- public $color; // Define background color for user in agenda
+ /**
+ * @var string Define background color for user in agenda
+ */
+ public $color;
public $dateemployment; // Define date of employment by company
public $dateemploymentend; // Define date of employment end by company
@@ -317,7 +408,8 @@ class User extends CommonObject
} else {
$sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
}
- } else {// The fetch was forced on an entity
+ } else {
+ // The fetch was forced on an entity
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
} else {
@@ -337,21 +429,19 @@ class User extends CommonObject
$sql .= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$obj = $this->db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
- $this->ref_ext = $obj->ref_ext;
+ $this->ref_ext = $obj->ref_ext;
- $this->ldap_sid = $obj->ldap_sid;
- $this->lastname = $obj->lastname;
+ $this->ldap_sid = $obj->ldap_sid;
+ $this->lastname = $obj->lastname;
$this->firstname = $obj->firstname;
- $this->employee = $obj->employee;
+ $this->employee = $obj->employee;
$this->login = $obj->login;
$this->gender = $obj->gender;
@@ -422,7 +512,9 @@ class User extends CommonObject
// Protection when module multicompany was set, admin was set to first entity and then, the module was disabled,
// in such case, this admin user must be admin for ALL entities.
- if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) $this->entity = 0;
+ if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) {
+ $this->entity = 0;
+ }
// Retrieve all extrafield
// fetch optionals attributes and labels
@@ -442,23 +534,22 @@ class User extends CommonObject
}
// To get back the global configuration unique to the user
- if ($loadpersonalconf)
- {
+ if ($loadpersonalconf) {
// Load user->conf for user
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
$sql .= " WHERE fk_user = ".$this->id;
$sql .= " AND entity = ".$conf->entity;
//dol_syslog(get_class($this).'::fetch load personalized conf', LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$p = (!empty($obj->param) ? $obj->param : '');
- if (!empty($p)) $this->conf->$p = $obj->value;
+ if (!empty($p)) {
+ $this->conf->$p = $obj->value;
+ }
$i++;
}
$this->db->free($resql);
@@ -469,8 +560,7 @@ class User extends CommonObject
$result = $this->loadDefaultValues();
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $this->db->lasterror();
return -3;
}
@@ -494,20 +584,16 @@ class User extends CommonObject
$sql .= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity
$sql .= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined)
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
- if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
+ if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) {
// $obj->page is relative URL with or without params
// $obj->type can be 'filters', 'sortorder', 'createform', ...
// $obj->param is key or param
$pagewithoutquerystring = $obj->page;
$pagequeries = '';
$reg = array();
- if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
- {
+ if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param
$pagewithoutquerystring = $reg[1];
$pagequeries = $reg[2];
}
@@ -517,10 +603,8 @@ class User extends CommonObject
}
// Sort by key, so _noquery_ is last
if (!empty($this->default_values)) {
- foreach ($this->default_values as $a => $b)
- {
- foreach ($b as $c => $d)
- {
+ foreach ($this->default_values as $a => $b) {
+ foreach ($b as $c => $d) {
krsort($this->default_values[$a][$c]);
}
}
@@ -557,50 +641,56 @@ class User extends CommonObject
$this->db->begin();
- if (!empty($rid))
- {
+ if (!empty($rid)) {
+ $module = $perms = $subperms = '';
+
// Si on a demande ajout d'un droit en particulier, on recupere
// les caracteristiques (module, perms et subperms) de ce droit.
$sql = "SELECT module, perms, subperms";
$sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
- $sql .= " WHERE id = '".$this->db->escape($rid)."'";
- $sql .= " AND entity = ".$entity;
+ $sql .= " WHERE id = ".((int) $rid);
+ $sql .= " AND entity = ".((int) $entity);
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
+ }
} else {
$error++;
dol_print_error($this->db);
}
// Where pour la liste des droits a ajouter
- $whereforadd = "id=".$this->db->escape($rid);
+ $whereforadd = "id=".((int) $rid);
// Ajout des droits induits
- if (!empty($subperms)) $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))";
- elseif (!empty($perms)) $whereforadd .= " OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
+ if (!empty($subperms)) {
+ $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
+ } elseif (!empty($perms)) {
+ $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
+ }
} else {
// On a pas demande un droit en particulier mais une liste de droits
// sur la base d'un nom de module de de perms
// Where pour la liste des droits a ajouter
- if (!empty($allmodule))
- {
- if ($allmodule == 'allmodules')
- {
+ if (!empty($allmodule)) {
+ if ($allmodule == 'allmodules') {
$whereforadd = 'allmodules';
} else {
$whereforadd = "module='".$this->db->escape($allmodule)."'";
- if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
+ if (!empty($allperms)) {
+ $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
+ }
}
}
}
// Ajout des droits trouves grace au critere whereforadd
- if (!empty($whereforadd))
- {
+ if (!empty($whereforadd)) {
//print "$module-$perms-$subperms";
$sql = "SELECT id";
$sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
@@ -610,19 +700,21 @@ class User extends CommonObject
}
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($result);
$nid = $obj->id;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id." AND fk_id=".$nid." AND entity = ".$entity;
- if (!$this->db->query($sql)) $error++;
+ if (!$this->db->query($sql)) {
+ $error++;
+ }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (entity, fk_user, fk_id) VALUES (".$entity.", ".$this->id.", ".$nid.")";
- if (!$this->db->query($sql)) $error++;
+ if (!$this->db->query($sql)) {
+ $error++;
+ }
$i++;
}
@@ -632,14 +724,15 @@ class User extends CommonObject
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
$langs->load("other");
$this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
// Call trigger
$result = $this->call_trigger('USER_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -675,6 +768,8 @@ class User extends CommonObject
$this->db->begin();
if (!empty($rid)) {
+ $module = $perms = $subperms = '';
+
// Si on a demande supression d'un droit en particulier, on recupere
// les caracteristiques module, perms et subperms de ce droit.
$sql = "SELECT module, perms, subperms";
@@ -685,19 +780,26 @@ class User extends CommonObject
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
+ }
} else {
$error++;
dol_print_error($this->db);
}
// Where pour la liste des droits a supprimer
- $wherefordel = "id=".$this->db->escape($rid);
+ $wherefordel = "id=".((int) $rid);
// Suppression des droits induits
- if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)";
- if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='$module')";
+ if ($subperms == 'lire' || $subperms == 'read') {
+ $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
+ }
+ if ($perms == 'lire' || $perms == 'read') {
+ $wherefordel .= " OR (module='".$this->db->escape($module)."')";
+ }
} else {
// On a demande suppression d'un droit sur la base d'un nom de module ou perms
// Where pour la liste des droits a supprimer
@@ -714,8 +816,7 @@ class User extends CommonObject
}
// Suppression des droits selon critere defini dans wherefordel
- if (!empty($wherefordel))
- {
+ if (!empty($wherefordel)) {
//print "$module-$perms-$subperms";
$sql = "SELECT id";
$sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
@@ -725,8 +826,7 @@ class User extends CommonObject
}
// avoid admin can remove his own important rights
- if ($this->admin == 1)
- {
+ if ($this->admin == 1) {
$sql .= " AND id NOT IN (251, 252, 253, 254, 255, 256)"; // other users rights
$sql .= " AND id NOT IN (341, 342, 343, 344)"; // own rights
$sql .= " AND id NOT IN (351, 352, 353, 354)"; // groups rights
@@ -734,19 +834,19 @@ class User extends CommonObject
}
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($result);
$nid = $obj->id;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights";
$sql .= " WHERE fk_user = ".$this->id." AND fk_id=".$nid;
$sql .= " AND entity = ".$entity;
- if (!$this->db->query($sql)) $error++;
+ if (!$this->db->query($sql)) {
+ $error++;
+ }
$i++;
}
@@ -756,14 +856,15 @@ class User extends CommonObject
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
$langs->load("other");
$this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
// Call trigger
$result = $this->call_trigger('USER_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
@@ -786,7 +887,7 @@ class User extends CommonObject
public function clearrights()
{
dol_syslog(get_class($this)."::clearrights reset user->rights");
- $this->rights = '';
+ $this->rights = null;
$this->nb_rights = 0;
$this->all_permissions_are_loaded = 0;
$this->_tab_loaded = array();
@@ -805,16 +906,13 @@ class User extends CommonObject
{
global $conf;
- if (empty($forcereload))
- {
- if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag])
- {
+ if (empty($forcereload)) {
+ if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
// Rights for this module are already loaded, so we leave
return;
}
- if (!empty($this->all_permissions_are_loaded))
- {
+ if (!empty($this->all_permissions_are_loaded)) {
// We already loaded all rights for this user, so we leave
return;
}
@@ -827,43 +925,52 @@ class User extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
$sql .= ", ".MAIN_DB_PREFIX."rights_def as r";
$sql .= " WHERE r.id = ur.fk_id";
- if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY))
- {
+ if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
$sql .= " AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "").$conf->entity.")";
} else {
$sql .= " AND ur.entity = ".$conf->entity;
}
$sql .= " AND ur.fk_user= ".$this->id;
$sql .= " AND r.perms IS NOT NULL";
- if ($moduletag) $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
+ if ($moduletag) {
+ $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
- if ($perms)
- {
- if (!isset($this->rights) || !is_object($this->rights)) $this->rights = new stdClass(); // For avoid error
- if ($module)
- {
- if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass();
- if ($subperms)
- {
- if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass();
- if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
- $this->rights->$module->$perms->$subperms = 1;
- } else {
- if (empty($this->rights->$module->$perms)) $this->nb_rights++;
- $this->rights->$module->$perms = 1;
+ if (!empty($perms)) {
+ if (!isset($this->rights) || !is_object($this->rights)) {
+ $this->rights = new stdClass(); // For avoid error
+ }
+ if (!empty($module)) {
+ if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
+ $this->rights->$module = new stdClass();
+ }
+ if (!empty($subperms)) {
+ if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
+ $this->rights->$module->$perms = new stdClass();
+ }
+ if (empty($this->rights->$module->$perms->$subperms)) {
+ $this->nb_rights++;
+ }
+ $this->rights->$module->$perms->$subperms = 1;
+ } else {
+ if (empty($this->rights->$module->$perms)) {
+ $this->nb_rights++;
+ }
+ $this->rights->$module->$perms = 1;
+ }
}
}
}
@@ -878,8 +985,7 @@ class User extends CommonObject
$sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu,";
$sql .= " ".MAIN_DB_PREFIX."rights_def as r";
$sql .= " WHERE r.id = gr.fk_id";
- if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY))
- {
+ if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= " AND gu.entity IN (0,".$conf->entity.")";
} else {
@@ -893,34 +999,48 @@ class User extends CommonObject
$sql .= " AND gr.fk_usergroup = gu.fk_usergroup";
$sql .= " AND gu.fk_user = ".$this->id;
$sql .= " AND r.perms IS NOT NULL";
- if ($moduletag) $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
+ if ($moduletag) {
+ $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
- if ($perms)
- {
- if (!isset($this->rights) || !is_object($this->rights)) $this->rights = new stdClass(); // For avoid error
- if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass();
- if ($subperms)
- {
- if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass();
- if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
- $this->rights->$module->$perms->$subperms = 1;
- } else {
- if (empty($this->rights->$module->$perms)) $this->nb_rights++;
- // if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group
- if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = 1;
+ if (!empty($perms)) {
+ if (!isset($this->rights) || !is_object($this->rights)) {
+ $this->rights = new stdClass(); // For avoid error
+ }
+ if (!empty($module)) {
+ if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
+ $this->rights->$module = new stdClass();
+ }
+ if (!empty($subperms)) {
+ if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
+ $this->rights->$module->$perms = new stdClass();
+ }
+ if (empty($this->rights->$module->$perms->$subperms)) {
+ $this->nb_rights++;
+ }
+ $this->rights->$module->$perms->$subperms = 1;
+ } else {
+ if (empty($this->rights->$module->$perms)) {
+ $this->nb_rights++;
+ }
+ // if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group
+ if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
+ $this->rights->$module->$perms = 1;
+ }
+ }
+ }
}
}
$i++;
@@ -929,11 +1049,14 @@ class User extends CommonObject
}
// For backward compatibility
- if (isset($this->rights->propale) && !isset($this->rights->propal)) $this->rights->propal = $this->rights->propale;
- if (isset($this->rights->propal) && !isset($this->rights->propale)) $this->rights->propale = $this->rights->propal;
+ if (isset($this->rights->propale) && !isset($this->rights->propal)) {
+ $this->rights->propal = $this->rights->propale;
+ }
+ if (isset($this->rights->propal) && !isset($this->rights->propale)) {
+ $this->rights->propale = $this->rights->propal;
+ }
- if (!$moduletag)
- {
+ if (!$moduletag) {
// Si module etait non defini, alors on a tout charge, on peut donc considerer
// que les droits sont en cache (car tous charges) pour cet instance de user
$this->all_permissions_are_loaded = 1;
@@ -956,8 +1079,11 @@ class User extends CommonObject
$error = 0;
// Check parameters
- if ($this->statut == $status) return 0;
- else $this->statut = $status;
+ if ($this->statut == $status) {
+ return 0;
+ } else {
+ $this->statut = $status;
+ }
$this->db->begin();
@@ -968,16 +1094,16 @@ class User extends CommonObject
$result = $this->db->query($sql);
dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
- if ($result)
- {
+ if ($result) {
// Call trigger
$result = $this->call_trigger('USER_ENABLEDISABLE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if ($error)
- {
+ if ($error) {
$this->db->rollback();
return -$error;
} else {
@@ -1056,68 +1182,57 @@ class User extends CommonObject
// Remove rights
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id;
- if (!$error && !$this->db->query($sql))
- {
+ if (!$error && !$this->db->query($sql)) {
$error++;
$this->error = $this->db->lasterror();
}
// Remove group
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user WHERE fk_user = ".$this->id;
- if (!$error && !$this->db->query($sql))
- {
+ if (!$error && !$this->db->query($sql)) {
$error++;
$this->error = $this->db->lasterror();
}
// Remove params
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param WHERE fk_user = ".$this->id;
- if (!$error && !$this->db->query($sql))
- {
+ if (!$error && !$this->db->query($sql)) {
$error++;
$this->error = $this->db->lasterror();
}
// If contact, remove link
- if ($this->contact_id > 0)
- {
+ if ($this->contact_id > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id;
- if (!$error && !$this->db->query($sql))
- {
+ if (!$error && !$this->db->query($sql)) {
$error++;
$this->error = $this->db->lasterror();
}
}
// Remove extrafields
- if (!$error)
- {
+ if (!$error) {
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
// Remove user
- if (!$error)
- {
+ if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->id;
- dol_syslog(get_class($this)."::delete", LOG_DEBUG);
- if (!$this->db->query($sql))
- {
- $error++;
- $this->error = $this->db->lasterror();
- }
+ dol_syslog(get_class($this)."::delete", LOG_DEBUG);
+ if (!$this->db->query($sql)) {
+ $error++;
+ $this->error = $this->db->lasterror();
+ }
}
- if (!$error)
- {
+ if (!$error) {
// Call trigger
$result = $this->call_trigger('USER_DELETE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->db->rollback();
return -1;
@@ -1147,7 +1262,9 @@ class User extends CommonObject
// Clean parameters
$this->setUpperOrLowerCase();
$this->login = trim($this->login);
- if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value
+ if (!isset($this->entity)) {
+ $this->entity = $conf->entity; // If not defined, we use default value
+ }
dol_syslog(get_class($this)."::create login=".$this->login.", user=".(is_object($user) ? $user->id : ''), LOG_DEBUG);
@@ -1174,13 +1291,11 @@ class User extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$this->db->free($resql);
- if ($num)
- {
+ if ($num) {
$this->error = 'ErrorLoginAlreadyExists';
dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
$this->db->rollback();
@@ -1191,20 +1306,17 @@ class User extends CommonObject
$result = $this->db->query($sql);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
- if ($result)
- {
+ if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user");
// Set default rights
- if ($this->set_default_rights() < 0)
- {
+ if ($this->set_default_rights() < 0) {
$this->error = 'ErrorFailedToSetDefaultRightOfUser';
$this->db->rollback();
return -5;
}
- if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE))
- {
+ if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$langs->load("stocks");
$entrepot = new Entrepot($this->db);
@@ -1220,22 +1332,21 @@ class User extends CommonObject
// Update minor fields
$result = $this->update($user, 1, 1);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->db->rollback();
return -4;
}
- if (!$notrigger)
- {
+ if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('USER_CREATE', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $this->id;
} else {
@@ -1301,22 +1412,24 @@ class User extends CommonObject
// Create user and set $this->id. Trigger is disabled because executed later.
$result = $this->create($user, 1);
- if ($result > 0)
- {
+ if ($result > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET fk_socpeople=".$contact->id;
- if ($contact->socid) $sql .= ", fk_soc=".$contact->socid;
+ if ($contact->socid) {
+ $sql .= ", fk_soc=".$contact->socid;
+ }
$sql .= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG);
- if ($resql)
- {
+ if ($resql) {
$this->context['createfromcontact'] = 'createfromcontact';
// Call trigger
$result = $this->call_trigger('USER_CREATE', $user);
- if ($result < 0) { $error++; $this->db->rollback(); return -1; }
+ if ($result < 0) {
+ $error++; $this->db->rollback(); return -1;
+ }
// End call triggers
$this->db->commit();
@@ -1377,33 +1490,31 @@ class User extends CommonObject
// Create and set $this->id
$result = $this->create($user);
- if ($result > 0)
- {
+ if ($result > 0) {
if (!empty($this->pass)) { // If a clear password was received (this situation should not happen anymore now), we use it to save it into database
$newpass = $this->setPassword($user, $this->pass);
- if (is_numeric($newpass) && $newpass < 0) $result = -2;
+ if (is_numeric($newpass) && $newpass < 0) {
+ $result = -2;
+ }
} elseif (!empty($this->pass_crypted)) { // If a crypted password is already known, we save it directly into database because the previous create did not save it.
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET pass_crypted = '".$this->db->escape($this->pass_crypted)."'";
$sql .= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$result = -1;
}
}
- if ($result > 0 && $member->fk_soc) // If member is linked to a thirdparty
- {
+ if ($result > 0 && $member->fk_soc) { // If member is linked to a thirdparty
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET fk_soc=".$member->fk_soc;
$sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->db->commit();
return $this->id;
} else {
@@ -1415,8 +1526,7 @@ class User extends CommonObject
}
}
- if ($result > 0)
- {
+ if ($result > 0) {
$this->db->commit();
return $this->id;
} else {
@@ -1461,7 +1571,9 @@ class User extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
$result = $this->db->query($sql);
- if (!$result) return -1;
+ if (!$result) {
+ return -1;
+ }
$i++;
}
@@ -1527,14 +1639,12 @@ class User extends CommonObject
$this->fk_warehouse = trim(empty($this->fk_warehouse) ? '' : $this->fk_warehouse);
// Check parameters
- if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email))
- {
+ if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
$langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail", $this->email);
return -1;
}
- if (empty($this->login))
- {
+ if (empty($this->login)) {
$langs->load("errors");
$this->error = $langs->trans("ErrorFieldRequired", 'Login');
return -1;
@@ -1551,7 +1661,9 @@ class User extends CommonObject
$sql .= ", api_key = ".($this->api_key ? "'".$this->db->escape($this->api_key)."'" : "null");
$sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
$sql .= ", birth=".(strval($this->birth) != '' ? "'".$this->db->idate($this->birth)."'" : 'null');
- if (!empty($user->admin)) $sql .= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user
+ if (!empty($user->admin)) {
+ $sql .= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user
+ }
$sql .= ", address = '".$this->db->escape($this->address)."'";
$sql .= ", zip = '".$this->db->escape($this->zip)."'";
$sql .= ", town = '".$this->db->escape($this->town)."'";
@@ -1579,10 +1691,18 @@ class User extends CommonObject
$sql .= ", fk_user = ".($this->fk_user > 0 ? "'".$this->db->escape($this->fk_user)."'" : "null");
$sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null");
$sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null");
- if (isset($this->thm) || $this->thm != '') $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null");
- if (isset($this->tjm) || $this->tjm != '') $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null");
- if (isset($this->salary) || $this->salary != '') $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null");
- if (isset($this->salaryextra) || $this->salaryextra != '') $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".$this->db->escape($this->salaryextra)."'" : "null");
+ if (isset($this->thm) || $this->thm != '') {
+ $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null");
+ }
+ if (isset($this->tjm) || $this->tjm != '') {
+ $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null");
+ }
+ if (isset($this->salary) || $this->salary != '') {
+ $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null");
+ }
+ if (isset($this->salaryextra) || $this->salaryextra != '') {
+ $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".$this->db->escape($this->salaryextra)."'" : "null");
+ }
$sql .= ", weeklyhours= ".($this->weeklyhours != '' ? "'".$this->db->escape($this->weeklyhours)."'" : "null");
$sql .= ", entity = '".$this->db->escape($this->entity)."'";
$sql .= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null');
@@ -1593,39 +1713,39 @@ class User extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nbrowsaffected += $this->db->affected_rows($resql);
// Update password
- if (!empty($this->pass))
- {
- if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
- {
+ if (!empty($this->pass)) {
+ if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
// Si mot de passe saisi et different de celui en base
$result = $this->setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass);
- if (!$nbrowsaffected) $nbrowsaffected++;
+ if (!$nbrowsaffected) {
+ $nbrowsaffected++;
+ }
}
}
// If user is linked to a member, remove old link to this member
- if ($this->fk_member > 0)
- {
+ if ($this->fk_member > 0) {
dol_syslog(get_class($this)."::update remove link with member. We will recreate it later", LOG_DEBUG);
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member;
$resql = $this->db->query($sql);
- if (!$resql) { $this->error = $this->db->error(); $this->db->rollback(); return -5; }
+ if (!$resql) {
+ $this->error = $this->db->error(); $this->db->rollback(); return -5;
+ }
}
// Set link to user
dol_syslog(get_class($this)."::update set link with member", LOG_DEBUG);
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member =".($this->fk_member > 0 ? $this->fk_member : 'null')." where rowid = ".$this->id;
$resql = $this->db->query($sql);
- if (!$resql) { $this->error = $this->db->error(); $this->db->rollback(); return -5; }
+ if (!$resql) {
+ $this->error = $this->db->error(); $this->db->rollback(); return -5;
+ }
- if ($nbrowsaffected) // If something has changed in data
- {
- if ($this->fk_member > 0 && !$nosyncmember)
- {
+ if ($nbrowsaffected) { // If something has changed in data
+ if ($this->fk_member > 0 && !$nosyncmember) {
dol_syslog(get_class($this)."::update user is linked with a member. We try to update member too.", LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
@@ -1635,8 +1755,7 @@ class User extends CommonObject
$adh = new Adherent($this->db);
$result = $adh->fetch($this->fk_member);
- if ($result > 0)
- {
+ if ($result > 0) {
$adh->firstname = $this->firstname;
$adh->lastname = $this->lastname;
$adh->login = $this->login;
@@ -1664,23 +1783,20 @@ class User extends CommonObject
$adh->user_login = $this->login;
$result = $adh->update($user, 0, 1, 0);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $adh->error;
$this->errors = $adh->errors;
dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR);
$error++;
}
- } elseif ($result < 0)
- {
+ } elseif ($result < 0) {
$this->error = $adh->error;
$this->errors = $adh->errors;
$error++;
}
}
- if ($this->contact_id > 0 && !$nosynccontact)
- {
+ if ($this->contact_id > 0 && !$nosynccontact) {
dol_syslog(get_class($this)."::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
@@ -1689,8 +1805,7 @@ class User extends CommonObject
$tmpobj = new Contact($this->db);
$result = $tmpobj->fetch($this->contact_id);
- if ($result >= 0)
- {
+ if ($result >= 0) {
$tmpobj->firstname = $this->firstname;
$tmpobj->lastname = $this->lastname;
$tmpobj->login = $this->login;
@@ -1719,8 +1834,7 @@ class User extends CommonObject
$tmpobj->user_login = $this->login;
$result = $tmpobj->update($tmpobj->id, $user, 0, 'update', 1);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $tmpobj->error;
$this->errors = $tmpobj->errors;
dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR);
@@ -1737,25 +1851,23 @@ class User extends CommonObject
$action = 'update';
// Actions on extra fields
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('USER_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return $nbrowsaffected;
} else {
@@ -1790,8 +1902,7 @@ class User extends CommonObject
dol_syslog(get_class($this)."::update_last_login_date user->id=".$this->id." ".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->datepreviouslogin = $this->datelastlogin;
$this->datelastlogin = $now;
return 1;
@@ -1822,8 +1933,7 @@ class User extends CommonObject
dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG);
// If new password not provided, we generate one
- if (!$password)
- {
+ if (!$password) {
$password = getRandomPassword(false);
}
@@ -1831,17 +1941,17 @@ class User extends CommonObject
$password_crypted = dol_hash($password);
// Mise a jour
- if (!$changelater)
- {
- if (!is_object($this->oldcopy)) $this->oldcopy = clone $this;
+ if (!$changelater) {
+ if (!is_object($this->oldcopy)) {
+ $this->oldcopy = clone $this;
+ }
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."',";
$sql .= " pass_temp = null";
- if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
- {
+ if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
$sql .= ", pass = null";
} else {
$sql .= ", pass = '".$this->db->escape($password)."'";
@@ -1850,16 +1960,13 @@ class User extends CommonObject
dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->affected_rows($result))
- {
+ if ($result) {
+ if ($this->db->affected_rows($result)) {
$this->pass = $password;
$this->pass_indatabase = $password;
$this->pass_indatabase_crypted = $password_crypted;
- if ($this->fk_member && !$nosyncmember)
- {
+ if ($this->fk_member && !$nosyncmember) {
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
// This user is linked with a member, so we also update members informations
@@ -1867,11 +1974,9 @@ class User extends CommonObject
$adh = new Adherent($this->db);
$result = $adh->fetch($this->fk_member);
- if ($result >= 0)
- {
+ if ($result >= 0) {
$result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $adh->error;
dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
$error++;
@@ -1884,11 +1989,12 @@ class User extends CommonObject
dol_syslog(get_class($this)."::setPassword notrigger=".$notrigger." error=".$error, LOG_DEBUG);
- if (!$error && !$notrigger)
- {
+ if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('USER_NEW_PASSWORD', $user);
- if ($result < 0) { $error++; $this->db->rollback(); return -1; }
+ if ($result < 0) {
+ $error++; $this->db->rollback(); return -1;
+ }
// End call triggers
}
@@ -1912,8 +2018,7 @@ class User extends CommonObject
dol_syslog(get_class($this)."::setPassword", LOG_DEBUG); // No log
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
return $password;
} else {
dol_print_error($this->db);
@@ -1948,8 +2053,7 @@ class User extends CommonObject
$outputlangs = new Translate("", $conf);
if (isset($this->conf->MAIN_LANG_DEFAULT)
- && $this->conf->MAIN_LANG_DEFAULT != 'auto')
- { // If user has defined its own language (rare because in most cases, auto is used)
+ && $this->conf->MAIN_LANG_DEFAULT != 'auto') { // If user has defined its own language (rare because in most cases, auto is used)
$outputlangs->getDefaultLang($this->conf->MAIN_LANG_DEFAULT);
}
@@ -1963,7 +2067,9 @@ class User extends CommonObject
$outputlangs->loadLangs(array("main", "errors", "users", "other"));
$appli = constant('DOL_APPLICATION_TITLE');
- if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli = $conf->global->MAIN_APPLICATION_TITLE;
+ if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
+ $appli = $conf->global->MAIN_APPLICATION_TITLE;
+ }
$subject = $outputlangs->transnoentitiesnoconv("SubjectNewPassword", $appli);
@@ -1971,8 +2077,7 @@ class User extends CommonObject
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
- if (!$changelater)
- {
+ if (!$changelater) {
$url = $urlwithroot.'/';
$mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived").".\n";
$mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs")." :\n\n";
@@ -2019,8 +2124,7 @@ class User extends CommonObject
$trackid
);
- if ($mailfile->sendfile())
- {
+ if ($mailfile->sendfile()) {
return 1;
} else {
$langs->trans("errors");
@@ -2054,10 +2158,8 @@ class User extends CommonObject
$sql .= " WHERE u.fk_user = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
- if ($this->db->num_rows($resql))
- {
+ if ($resql) {
+ if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->clicktodial_url = $obj->url;
@@ -2103,8 +2205,7 @@ class User extends CommonObject
dol_syslog(get_class($this).'::update_clicktodial', LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$this->db->commit();
return 1;
} else {
@@ -2144,21 +2245,20 @@ class User extends CommonObject
$sql .= " VALUES (".$entity.",".$this->id.",".$group.")";
$result = $this->db->query($sql);
- if ($result)
- {
- if (!$error && !$notrigger)
- {
+ if ($result) {
+ if (!$error && !$notrigger) {
$this->newgroupid = $group; // deprecated. Remove this.
$this->context = array('audit'=>$langs->trans("UserSetInGroup"), 'newgroupid'=>$group);
// Call trigger
$result = $this->call_trigger('USER_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -2197,21 +2297,20 @@ class User extends CommonObject
$sql .= " AND entity = ".$entity;
$result = $this->db->query($sql);
- if ($result)
- {
- if (!$error && !$notrigger)
- {
+ if ($result) {
+ if (!$error && !$notrigger) {
$this->oldgroupid = $group; // deprecated. Remove this.
$this->context = array('audit'=>$langs->trans("UserRemovedFromGroup"), 'oldgroupid'=>$group);
// Call trigger
$result = $this->call_trigger('USER_MODIFY', $user);
- if ($result < 0) { $error++; }
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -2267,14 +2366,17 @@ class User extends CommonObject
global $dolibarr_main_authentication, $dolibarr_main_demo;
global $menumanager;
- if (!$user->rights->user->user->lire && $user->id != $this->id) $option = 'nolink';
+ if (!$user->rights->user->user->lire && $user->id != $this->id) {
+ $option = 'nolink';
+ }
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0;
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
+ $withpictoimg = 0;
+ }
$result = ''; $label = '';
- if (!empty($this->photo))
- {
+ if (!empty($this->photo)) {
$label .= '';
$label .= Form::showphoto('userphoto', $this, 0, 60, 0, 'photowithmargin photologintooltip', 'small', 0, 1); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed
$label .= ' ';
@@ -2285,28 +2387,37 @@ class User extends CommonObject
$label .= img_picto('', $this->picto).' '.$langs->trans("User").'';
$label .= ' '.$this->getLibStatut(4);
$label .= ' '.$langs->trans('Name').': '.$this->getFullName($langs, '');
- if (!empty($this->login)) $label .= ' '.$langs->trans('Login').': '.$this->login;
- if (!empty($this->job)) $label .= ' '.$langs->trans("Job").': '.$this->job;
+ if (!empty($this->login)) {
+ $label .= ' '.$langs->trans('Login').': '.$this->login;
+ }
+ if (!empty($this->job)) {
+ $label .= ' '.$langs->trans("Job").': '.$this->job;
+ }
$label .= ' '.$langs->trans("Email").': '.$this->email;
- if (!empty($this->phone)) $label .= ' '.$langs->trans("Phone").': '.$this->phone;
- if (!empty($this->admin))
+ if (!empty($this->phone)) {
+ $label .= ' '.$langs->trans("Phone").': '.$this->phone;
+ }
+ if (!empty($this->admin)) {
$label .= ' '.$langs->trans("Administrator").': '.yn($this->admin);
- if (!empty($this->socid)) // Add thirdparty for external users
- {
+ }
+ if (!empty($this->socid)) { // Add thirdparty for external users
$thirdpartystatic = new Societe($db);
$thirdpartystatic->fetch($this->socid);
- if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company
+ if (empty($hidethirdpartylogo)) {
+ $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company
+ }
$company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')';
}
$type = ($this->socid ? $langs->trans("External").$company : $langs->trans("Internal"));
$label .= ' '.$langs->trans("Type").': '.$type;
$label .= '';
- if ($infologin > 0)
- {
+ if ($infologin > 0) {
$label .= ' ';
$label .= ' '.$langs->trans("Session").'';
$label .= ' '.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"];
- if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label .= ' '.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')';
+ if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
+ $label .= ' '.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')';
+ }
$label .= ' '.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)');
$label .= ' '.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin, "dayhour", 'tzuser');
$label .= ' '.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser');
@@ -2317,28 +2428,37 @@ class User extends CommonObject
$label .= ' '.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.$_SERVER['HTTP_USER_AGENT'].')';
$label .= ' '.$langs->trans("Layout").': '.$conf->browser->layout;
$label .= ' '.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight'];
- if ($conf->browser->layout == 'phone') $label .= ' '.$langs->trans("Phone").': '.$langs->trans("Yes");
- if (!empty($_SESSION["disablemodules"])) $label .= ' '.$langs->trans("DisabledModules").': '.join(', ', explode(',', $_SESSION["disablemodules"]));
+ if ($conf->browser->layout == 'phone') {
+ $label .= ' '.$langs->trans("Phone").': '.$langs->trans("Yes");
+ }
+ if (!empty($_SESSION["disablemodules"])) {
+ $label .= ' '.$langs->trans("DisabledModules").': '.join(', ', explode(',', $_SESSION["disablemodules"]));
+ }
+ }
+ if ($infologin < 0) {
+ $label = '';
}
- if ($infologin < 0) $label = '';
$url = DOL_URL_ROOT.'/user/card.php?id='.$this->id;
- if ($option == 'leave') $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id;
+ if ($option == 'leave') {
+ $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id;
+ }
- if ($option != 'nolink')
- {
+ if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
- if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
- if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
+ $add_save_lastsearch_values = 1;
+ }
+ if ($add_save_lastsearch_values) {
+ $url .= '&save_lastsearch_values=1';
+ }
}
$linkstart = 'global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$langs->load("users");
$label = $langs->trans("ShowUser");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
@@ -2359,22 +2479,33 @@ class User extends CommonObject
//if ($withpictoimg == -1) $result.='';
$result .= (($option == 'nolink') ? '' : $linkstart);
- if ($withpictoimg)
- {
- $paddafterimage = '';
- if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"';
+ if ($withpictoimg) {
+ $paddafterimage = '';
+ if (abs($withpictoimg) == 1) {
+ $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"';
+ }
// Only picto
- if ($withpictoimg > 0) $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'';
+ if ($withpictoimg > 0) {
+ $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'';
+ }
// Picto must be a photo
- else $picto = ''.Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1).'';
+ else {
+ $picto = ''.Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1).'';
+ }
$result .= $picto;
}
- if ($withpictoimg > -2 && $withpictoimg != 2)
- {
- if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= '';
- if ($mode == 'login') $result .= dol_trunc($this->login, $maxlen);
- else $result .= $this->getFullName($langs, '', ($mode == 'firstelselast' ? 3 : ($mode == 'firstname' ? 2 : -1)), $maxlen);
- if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= '';
+ if ($withpictoimg > -2 && $withpictoimg != 2) {
+ if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $result .= '';
+ }
+ if ($mode == 'login') {
+ $result .= dol_trunc($this->login, $maxlen);
+ } else {
+ $result .= $this->getFullName($langs, '', ($mode == 'firstelselast' ? 3 : ($mode == 'firstname' ? 2 : -1)), $maxlen);
+ }
+ if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+ $result .= '';
+ }
}
$result .= (($option == 'nolink') ? '' : $linkend);
//if ($withpictoimg == -1) $result.=' ';
@@ -2385,8 +2516,11 @@ class User extends CommonObject
$hookmanager->initHooks(array('userdao'));
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook > 0) $result = $hookmanager->resPrint;
- else $result .= $hookmanager->resPrint;
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
return $result;
}
@@ -2408,22 +2542,24 @@ class User extends CommonObject
$linkend = '';
//Check user's rights to see an other user
- if ((!$user->rights->user->user->lire && $this->id != $user->id)) $option = 'nolink';
+ if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
+ $option = 'nolink';
+ }
- if ($option == 'xxx')
- {
+ if ($option == 'xxx') {
$linkstart = '';
$linkend = '';
}
- if ($option == 'nolink')
- {
+ if ($option == 'nolink') {
$linkstart = '';
$linkend = '';
}
$result .= $linkstart;
- if ($withpicto) $result .= img_object($langs->trans("ShowUser"), 'user', 'class="paddingright"');
+ if ($withpicto) {
+ $result .= img_object($langs->trans("ShowUser"), 'user', 'class="paddingright"');
+ }
$result .= $this->login;
$result .= $linkend;
return $result;
@@ -2453,8 +2589,7 @@ class User extends CommonObject
// phpcs:enable
global $langs;
- if (empty($this->labelStatus) || empty($this->labelStatusShort))
- {
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Enabled');
@@ -2464,7 +2599,9 @@ class User extends CommonObject
}
$statusType = 'status5';
- if ($status == self::STATUS_ENABLED) $statusType = 'status4';
+ if ($status == self::STATUS_ENABLED) {
+ $statusType = 'status4';
+ }
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
@@ -2486,9 +2623,13 @@ class User extends CommonObject
// phpcs:enable
global $conf;
$dn = '';
- if ($mode == 0) $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN;
- elseif ($mode == 1) $dn = $conf->global->LDAP_USER_DN;
- elseif ($mode == 2) $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS];
+ if ($mode == 0) {
+ $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN;
+ } elseif ($mode == 1) {
+ $dn = $conf->global->LDAP_USER_DN;
+ } elseif ($mode == 2) {
+ $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS];
+ }
return $dn;
}
@@ -2531,63 +2672,77 @@ class User extends CommonObject
);
// Champs
- foreach ($ldapkey as $constname => $varname)
- {
- if (!empty($this->$varname) && !empty($conf->global->$constname))
- {
+ foreach ($ldapkey as $constname => $varname) {
+ if (!empty($this->$varname) && !empty($conf->global->$constname)) {
$info[$conf->global->$constname] = $this->$varname;
// Check if it is the LDAP key and if its value has been changed
- if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname)
- {
- if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified = true; // For check if LDAP key has been modified
+ if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
+ if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
+ $keymodified = true; // For check if LDAP key has been modified
+ }
}
}
}
- if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
- if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
- if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
- if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 2);
- if ($this->socid > 0)
- {
+ if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
+ $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
+ }
+ if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
+ $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
+ }
+ if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
+ $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
+ }
+ if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
+ $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 2);
+ }
+ if ($this->socid > 0) {
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
- if ($soc->client == 1) $info["businessCategory"] = "Customers";
- if ($soc->client == 2) $info["businessCategory"] = "Prospects";
- if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
+ if ($soc->client == 1) {
+ $info["businessCategory"] = "Customers";
+ }
+ if ($soc->client == 2) {
+ $info["businessCategory"] = "Prospects";
+ }
+ if ($soc->fournisseur == 1) {
+ $info["businessCategory"] = "Suppliers";
+ }
}
// When password is modified
- if (!empty($this->pass))
- {
- if (!empty($conf->global->LDAP_FIELD_PASSWORD)) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
- if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption)
+ if (!empty($this->pass)) {
+ if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
+ $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
+ }
+ if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
+ $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption)
+ }
}
// Set LDAP password if possible
- elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
- {
- if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
- {
+ elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') { // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
+ if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
// Just for the default MD5 !
- if (empty($conf->global->MAIN_SECURITY_HASH_ALGO))
- {
+ if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
$info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase_crypted, 5); // Create OpenLDAP MD5 password from Dolibarr MD5 password
}
}
}
// Use $this->pass_indatabase value if exists
- elseif (!empty($this->pass_indatabase))
- {
- if (!empty($conf->global->LDAP_FIELD_PASSWORD)) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
- if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption
+ elseif (!empty($this->pass_indatabase)) {
+ if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
+ $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
+ }
+ if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
+ $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption
+ }
}
}
- if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
- {
+ if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') {
$info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
$info['uidnumber'] = $this->id;
@@ -2600,18 +2755,23 @@ class User extends CommonObject
$info["phpgwContactCatId"] = 0;
$info["phpgwContactAccess"] = "public";
- if (dol_strlen($this->egroupware_id) == 0)
- {
+ if (dol_strlen($this->egroupware_id) == 0) {
$this->egroupware_id = 1;
}
$info["phpgwContactOwner"] = $this->egroupware_id;
- if ($this->email) $info["rfc822Mailbox"] = $this->email;
- if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+ if ($this->email) {
+ $info["rfc822Mailbox"] = $this->email;
+ }
+ if ($this->phone_mobile) {
+ $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+ }
}
- if (!empty($conf->global->LDAP_FIELD_USERID))$info[$conf->global->LDAP_FIELD_USERID] = $this->id;
+ if (!empty($conf->global->LDAP_FIELD_USERID)) {
+ $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
+ }
if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) {
$usergroup = new UserGroup($this->db);
$groupslist = $usergroup->listGroupsForUser($this->id);
@@ -2623,7 +2783,9 @@ class User extends CommonObject
}
}
}
- if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname";
+ if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
+ $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname";
+ }
return $info;
}
@@ -2634,7 +2796,7 @@ class User extends CommonObject
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
- * @return void
+ * @return int
*/
public function initAsSpecimen()
{
@@ -2677,6 +2839,7 @@ class User extends CommonObject
$this->statut = 1;
$this->entity = 1;
+ return 1;
}
/**
@@ -2693,10 +2856,8 @@ class User extends CommonObject
$sql .= " WHERE u.rowid = ".$id;
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@@ -2727,8 +2888,7 @@ class User extends CommonObject
$sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$nb = $obj->nb;
@@ -2754,19 +2914,23 @@ class User extends CommonObject
$sql = "SELECT count(rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."user";
- if ($option == 'superadmin')
- {
+ if ($option == 'superadmin') {
$sql .= " WHERE entity = 0";
- if ($admin >= 0) $sql .= " AND admin = ".$admin;
+ if ($admin >= 0) {
+ $sql .= " AND admin = ".$admin;
+ }
} else {
$sql .= " WHERE entity IN (".getEntity('user', 0).")";
- if ($limitTo == 'active') $sql .= " AND statut = 1";
- if ($admin >= 0) $sql .= " AND admin = ".$admin;
+ if ($limitTo == 'active') {
+ $sql .= " AND statut = 1";
+ }
+ if ($admin >= 0) {
+ $sql .= " AND admin = ".$admin;
+ }
}
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$nb = $obj->nb;
@@ -2833,11 +2997,9 @@ class User extends CommonObject
dol_syslog(get_class($this)."::get_children sql=".$sql, LOG_DEBUG);
$res = $this->db->query($sql);
- if ($res)
- {
+ if ($res) {
$users = array();
- while ($rec = $this->db->fetch_array($res))
- {
+ while ($rec = $this->db->fetch_array($res)) {
$user = new User($this->db);
$user->fetch($rec['rowid']);
$users[] = $user;
@@ -2869,10 +3031,8 @@ class User extends CommonObject
dol_syslog(get_class($this)."::loadParentOf", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$this->parentof[$obj->id_son] = $obj->id_parent;
}
return 1;
@@ -2921,15 +3081,15 @@ class User extends CommonObject
} else {
$sql .= " WHERE u.entity IN (".getEntity('user').")";
}
- if ($filter) $sql .= " AND ".$filter;
+ if ($filter) {
+ $sql .= " AND ".$filter;
+ }
dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$this->users[$obj->rowid]['rowid'] = $obj->rowid;
$this->users[$obj->rowid]['id'] = $obj->rowid;
$this->users[$obj->rowid]['fk_user'] = $obj->fk_user;
@@ -2952,29 +3112,24 @@ class User extends CommonObject
// We add the fullpath property to each elements of first level (no parent exists)
dol_syslog(get_class($this)."::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
- foreach ($this->users as $key => $val)
- {
+ foreach ($this->users as $key => $val) {
$result = $this->build_path_from_id_user($key, 0); // Process a branch from the root user key (this user has no parent)
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = 'ErrorLoopInHierarchy';
return -1;
}
}
// Exclude leaf including $deleteafterid from tree
- if ($deleteafterid)
- {
+ if ($deleteafterid) {
//print "Look to discard user ".$deleteafterid."\n";
$keyfilter1 = '^'.$deleteafterid.'$';
$keyfilter2 = '_'.$deleteafterid.'$';
$keyfilter3 = '^'.$deleteafterid.'_';
$keyfilter4 = '_'.$deleteafterid.'_';
- foreach ($this->users as $key => $val)
- {
+ foreach ($this->users as $key => $val) {
if (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath'])
- || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath']))
- {
+ || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath'])) {
unset($this->users[$key]);
}
}
@@ -3000,8 +3155,7 @@ class User extends CommonObject
{
$childids = array();
- if (isset($this->cache_childids[$this->id]))
- {
+ if (isset($this->cache_childids[$this->id])) {
$childids = $this->cache_childids[$this->id];
} else {
// Init this->users
@@ -3010,15 +3164,18 @@ class User extends CommonObject
$idtoscan = $this->id;
dol_syslog("Build childid for id = ".$idtoscan);
- foreach ($this->users as $id => $val)
- {
+ foreach ($this->users as $id => $val) {
//var_dump($val['fullpath']);
- if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) $childids[$val['id']] = $val['id'];
+ if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) {
+ $childids[$val['id']] = $val['id'];
+ }
}
}
$this->cache_childids[$this->id] = $childids;
- if ($addcurrentuser) $childids[$this->id] = $this->id;
+ if ($addcurrentuser) {
+ $childids[$this->id] = $this->id;
+ }
return $childids;
}
@@ -3037,8 +3194,7 @@ class User extends CommonObject
// phpcs:enable
//dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG);
- if (!empty($this->users[$id_user]['fullpath']))
- {
+ if (!empty($this->users[$id_user]['fullpath'])) {
// Already defined
dol_syslog(get_class($this)."::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
return 0;
@@ -3050,10 +3206,8 @@ class User extends CommonObject
$i = 0; $cursor_user = $id_user;
$useridfound = array($id_user);
- while (!empty($this->parentof[$cursor_user]))
- {
- if (in_array($this->parentof[$cursor_user], $useridfound))
- {
+ while (!empty($this->parentof[$cursor_user])) {
+ if (in_array($this->parentof[$cursor_user], $useridfound)) {
dol_syslog("The hierarchy of user has a recursive loop", LOG_WARNING);
return -1; // Should not happen. Protection against looping hierarchy
}
@@ -3106,10 +3260,8 @@ class User extends CommonObject
$sql .= " AND u.entity IN (".getEntity('user').")";
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$this->nb["users"] = $obj->nb;
}
$this->db->free($resql);
@@ -3139,10 +3291,8 @@ class User extends CommonObject
$langs->load("user");
// Positionne le modele sur le nom du modele a utiliser
- if (!dol_strlen($modele))
- {
- if (!empty($conf->global->USER_ADDON_PDF))
- {
+ if (!dol_strlen($modele)) {
+ if (!empty($conf->global->USER_ADDON_PDF)) {
$modele = $conf->global->USER_ADDON_PDF;
} else {
$modele = 'bluesky';
@@ -3167,23 +3317,26 @@ class User extends CommonObject
// phpcs:enable
$user_property = '';
- if (empty($rowid)) return '';
+ if (empty($rowid)) {
+ return '';
+ }
$sql = "SELECT rowid, email, user_mobile, civility, lastname, firstname";
$sql .= " FROM ".MAIN_DB_PREFIX."user";
$sql .= " WHERE rowid = ".((int) $rowid);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nump = $this->db->num_rows($resql);
- if ($nump)
- {
+ if ($nump) {
$obj = $this->db->fetch_object($resql);
- if ($mode == 'email') $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
- elseif ($mode == 'mobile') $user_property = $obj->user_mobile;
+ if ($mode == 'email') {
+ $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
+ } elseif ($mode == 'mobile') {
+ $user_property = $obj->user_mobile;
+ }
}
return $user_property;
} else {
@@ -3210,10 +3363,8 @@ class User extends CommonObject
$sql = "SELECT t.rowid";
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t ';
- if ($entityfilter)
- {
- if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
- {
+ if ($entityfilter) {
+ if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql .= " WHERE t.entity IS NOT NULL"; // Show all users
} else {
@@ -3248,19 +3399,18 @@ class User extends CommonObject
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
}
$sql .= $this->db->order($sortfield, $sortorder);
- if ($limit) $sql .= $this->db->plimit($limit + 1, $offset);
+ if ($limit) {
+ $sql .= $this->db->plimit($limit + 1, $offset);
+ }
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->users = array();
$num = $this->db->num_rows($resql);
- if ($num)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($num) {
+ while ($obj = $this->db->fetch_object($resql)) {
$line = new self($this->db);
$result = $line->fetch($obj->rowid);
if ($result > 0 && !empty($line->id)) {
@@ -3297,8 +3447,7 @@ class User extends CommonObject
*/
public function findUserIdByEmail($email)
{
- if ($this->findUserIdByEmailCache[$email])
- {
+ if ($this->findUserIdByEmailCache[$email]) {
return $this->findUserIdByEmailCache[$email];
}
@@ -3309,25 +3458,21 @@ class User extends CommonObject
$sql = 'SELECT rowid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'user';
- if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR))
- {
+ if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
$sql .= ' WHERE email LIKE "%'.$email.'%"';
- }
- else {
+ } else {
$sql .= ' WHERE email = "'.$email.'"';
}
$sql .= ' LIMIT 1';
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
return -1;
}
$obj = $this->db->fetch_object($resql);
- if (!$obj)
- {
+ if (!$obj) {
return -1;
}
diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php
index 2998658d7fc..882d33bd562 100644
--- a/htdocs/user/class/usergroup.class.php
+++ b/htdocs/user/class/usergroup.class.php
@@ -307,33 +307,33 @@ class UserGroup extends CommonObject
if (!empty($rid))
{
+ $module = $perms = $subperms = '';
+
// Si on a demande ajout d'un droit en particulier, on recupere
// les caracteristiques (module, perms et subperms) de ce droit.
$sql = "SELECT module, perms, subperms";
$sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
- $sql .= " WHERE id = '".$this->db->escape($rid)."'";
- $sql .= " AND entity = ".$entity;
+ $sql .= " WHERE id = ".((int) $rid);
+ $sql .= " AND entity = ".((int) $entity);
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
+ }
} else {
$error++;
dol_print_error($this->db);
}
// Where pour la liste des droits a ajouter
- $whereforadd = "id=".$this->db->escape($rid);
- // Ajout des droits induits
- if ($subperms) $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))";
- elseif ($perms) $whereforadd .= " OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
-
- // Pour compatibilite, si lowid = 0, on est en mode ajout de tout
- // TODO A virer quand sera gere par l'appelant
- //if (substr($rid,-1,1) == 0) $whereforadd="module='$module'";
+ $whereforadd = "id=".((int) $rid);
+ // Find also rights that are herited to add them too
+ if ($subperms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
+ elseif ($perms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
} else {
// Where pour la liste des droits a ajouter
if (!empty($allmodule))
@@ -348,7 +348,7 @@ class UserGroup extends CommonObject
}
}
- // Ajout des droits de la liste whereforadd
+ // Add permission of the list $whereforadd
if (!empty($whereforadd))
{
//print "$module-$perms-$subperms";
@@ -425,6 +425,8 @@ class UserGroup extends CommonObject
if (!empty($rid))
{
+ $module = $perms = $subperms = '';
+
// Si on a demande supression d'un droit en particulier, on recupere
// les caracteristiques module, perms et subperms de ce droit.
$sql = "SELECT module, perms, subperms";
@@ -435,9 +437,11 @@ class UserGroup extends CommonObject
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
+ }
} else {
$error++;
dol_print_error($this->db);
@@ -446,14 +450,14 @@ class UserGroup extends CommonObject
// Where pour la liste des droits a supprimer
$wherefordel = "id=".$this->db->escape($rid);
// Suppression des droits induits
- if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)";
- if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='$module')";
+ if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
+ if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."')";
// Pour compatibilite, si lowid = 0, on est en mode suppression de tout
// TODO A virer quand sera gere par l'appelant
//if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
} else {
- // Where pour la liste des droits a supprimer
+ // Add permission of the list $wherefordel
if (!empty($allmodule))
{
if ($allmodule == 'allmodules')
@@ -461,7 +465,7 @@ class UserGroup extends CommonObject
$wherefordel = 'allmodules';
} else {
$wherefordel = "module='".$this->db->escape($allmodule)."'";
- if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
+ if (!empty($allperms)) $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
}
}
}
@@ -484,8 +488,12 @@ class UserGroup extends CommonObject
$i = 0;
while ($i < $num)
{
+ $nid = 0;
+
$obj = $this->db->fetch_object($result);
- $nid = $obj->id;
+ if ($obj) {
+ $nid = $obj->id;
+ }
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights";
$sql .= " WHERE fk_usergroup = $this->id AND fk_id=".$nid;
@@ -565,22 +573,24 @@ class UserGroup extends CommonObject
{
$obj = $this->db->fetch_object($resql);
- $module = $obj->module;
- $perms = $obj->perms;
- $subperms = $obj->subperms;
+ if ($obj) {
+ $module = $obj->module;
+ $perms = $obj->perms;
+ $subperms = $obj->subperms;
- if ($perms)
- {
- if (!isset($this->rights)) $this->rights = new stdClass(); // For avoid error
- if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass();
- if ($subperms)
+ if ($perms)
{
- if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass();
- if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
- $this->rights->$module->$perms->$subperms = 1;
- } else {
- if (empty($this->rights->$module->$perms)) $this->nb_rights++;
- $this->rights->$module->$perms = 1;
+ if (!isset($this->rights)) $this->rights = new stdClass(); // For avoid error
+ if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass();
+ if ($subperms)
+ {
+ if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass();
+ if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
+ $this->rights->$module->$perms->$subperms = 1;
+ } else {
+ if (empty($this->rights->$module->$perms)) $this->nb_rights++;
+ $this->rights->$module->$perms = 1;
+ }
}
}
diff --git a/htdocs/zapier/class/api_zapier.class.php b/htdocs/zapier/class/api_zapier.class.php
index 6118aa71241..bb3e42f5f05 100644
--- a/htdocs/zapier/class/api_zapier.class.php
+++ b/htdocs/zapier/class/api_zapier.class.php
@@ -93,14 +93,13 @@ class ZapierApi extends DolibarrApi
* Get list of possibles choices for module
*
* Return an array with hook informations
- * @param integer $id ID
*
- * @return array|mixed data
+ * @return array data
*
* @url GET /getmoduleschoices/
* @throws RestException
*/
- public function getModulesChoices($id)
+ public function getModulesChoices()
{
if (!DolibarrApiAccess::$user->rights->zapier->read) {
throw new RestException(401);
@@ -110,6 +109,7 @@ class ZapierApi extends DolibarrApi
'orders' => 'Orders',
'thirdparties' => 'Thirparties',
'contacts' => 'Contacts',
+ 'users' => 'Users',
);
// $result = $this->hook->fetch($id);
// if (! $result ) {
@@ -244,6 +244,7 @@ class ZapierApi extends DolibarrApi
$fields = array(
'url',
);
+ dol_syslog("API Zapier create hook receive : " . print_r($request_data, true), LOG_DEBUG);
$result = $this->validate($request_data, $fields);
foreach ($request_data as $field => $value) {
diff --git a/htdocs/zapier/class/hook.class.php b/htdocs/zapier/class/hook.class.php
index e7ce317096d..8e6d3fa725f 100644
--- a/htdocs/zapier/class/hook.class.php
+++ b/htdocs/zapier/class/hook.class.php
@@ -126,7 +126,7 @@ class Hook extends CommonObject
),
'module' => array(
'type' => 'varchar(128)',
- 'label' => 'Url',
+ 'label' => 'Module',
'enabled' => 1,
'visible' => 1,
'position' => 30,
@@ -137,7 +137,7 @@ class Hook extends CommonObject
),
'action' => array(
'type' => 'varchar(128)',
- 'label' => 'Url',
+ 'label' => 'Action',
'enabled' => 1,
'visible' => 1,
'position' => 30,
diff --git a/htdocs/zapier/hook_card.php b/htdocs/zapier/hook_card.php
index ab081f1cf58..548b79de866 100644
--- a/htdocs/zapier/hook_card.php
+++ b/htdocs/zapier/hook_card.php
@@ -101,12 +101,6 @@ if (empty($reshook)) {
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
-
- // Actions to send emails
- $triggersendname = 'MYOBJECT_SENTBYMAIL';
- $autocopy = 'MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
- $trackid = 'myobject'.$object->id;
- include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
}
@@ -391,19 +385,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '';
}
-
- //Select mail models is same action as presend
- /*
- if (GETPOST('modelselected')) $action = 'presend';
-
- // Presend form
- $modelmail='inventory';
- $defaulttopic='InformationMessage';
- $diroutput = $conf->product->dir_output.'/inventory';
- $trackid = 'stockinv'.$object->id;
-
- include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
- */
}
// End of page
diff --git a/htdocs/zapier/hook_list.php b/htdocs/zapier/hook_list.php
index 8450ec3e0d8..59432aea44b 100644
--- a/htdocs/zapier/hook_list.php
+++ b/htdocs/zapier/hook_list.php
@@ -354,7 +354,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sort
$topicmail = "SendHookRef";
$modelmail = "hook";
$objecttmp = new Hook($db);
-$trackid = 'xxxx'.$object->id;
+$trackid = 'zapier'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($sall) {
diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php
index 4326f536f92..52c00978c54 100644
--- a/test/phpunit/CodingPhpTest.php
+++ b/test/phpunit/CodingPhpTest.php
@@ -255,7 +255,7 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
//if ($reg[0] != 'db') $ok=false;
}
//print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
- $this->assertTrue($ok, 'Found a $this->db->idate to forge a sql request without quotes around this date field '.$file['relativename'].' :: '.$val[0]);
+ $this->assertTrue($ok, 'Found a $this->db->idate to forge a sql request without quotes around this date field '.$file['relativename']);
//exit;
@@ -274,7 +274,7 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
//if ($reg[0] != 'db') $ok=false;
}
//print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
- $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].': '.$val[0].' - Bad.');
+ $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].' - Bad.');
//exit;
// Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request.
diff --git a/test/phpunit/FactureRecTest.php b/test/phpunit/FactureRecTest.php
index 3778989945a..0250b659e47 100644
--- a/test/phpunit/FactureRecTest.php
+++ b/test/phpunit/FactureRecTest.php
@@ -183,22 +183,18 @@ class FactureRecTest extends PHPUnit\Framework\TestCase
{
$retAr=array();
- if (get_class($oA) !== get_class($oB))
- {
+ if (get_class($oA) !== get_class($oB)) {
$retAr[]="Supplied objects are not of same class.";
} else {
$oVarsA=get_object_vars($oA);
$oVarsB=get_object_vars($oB);
$aKeys=array_keys($oVarsA);
- foreach ($aKeys as $sKey)
- {
+ foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) continue;
- if (! $ignoretype && $oVarsA[$sKey] !== $oVarsB[$sKey])
- {
+ if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
- if ($ignoretype && $oVarsA[$sKey] != $oVarsB[$sKey])
- {
+ if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
}
diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php
index 17cc4176a87..26396ae2c30 100644
--- a/test/phpunit/FactureTest.php
+++ b/test/phpunit/FactureTest.php
@@ -241,7 +241,7 @@ class FactureTest extends PHPUnit\Framework\TestCase
'ref','statut','paye','specimen','ref','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement',
'cond_reglement_doc','situation_cycle_ref','situation_counter','situation_final','multicurrency_total_ht','multicurrency_total_tva',
'multicurrency_total_ttc','fk_multicurrency','multicurrency_code','multicurrency_tx',
- 'retained_warranty' ,'retained_warranty_date_limit', 'retained_warranty_fk_cond_reglement', 'specimen'
+ 'retained_warranty' ,'retained_warranty_date_limit', 'retained_warranty_fk_cond_reglement', 'specimen', 'trackid'
)
);
$this->assertEquals($arraywithdiff, array()); // Actual, Expected
@@ -362,22 +362,18 @@ class FactureTest extends PHPUnit\Framework\TestCase
{
$retAr=array();
- if (get_class($oA) !== get_class($oB))
- {
+ if (get_class($oA) !== get_class($oB)) {
$retAr[]="Supplied objects are not of same class.";
} else {
$oVarsA=get_object_vars($oA);
$oVarsB=get_object_vars($oB);
$aKeys=array_keys($oVarsA);
- foreach ($aKeys as $sKey)
- {
+ foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) continue;
- if (! $ignoretype && $oVarsA[$sKey] !== $oVarsB[$sKey])
- {
+ if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
- if ($ignoretype && $oVarsA[$sKey] != $oVarsB[$sKey])
- {
+ if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
}
diff --git a/test/phpunit/Functions2LibTest.php b/test/phpunit/Functions2LibTest.php
index 21fa1f29257..be050b83b4f 100644
--- a/test/phpunit/Functions2LibTest.php
+++ b/test/phpunit/Functions2LibTest.php
@@ -148,6 +148,13 @@ class Functions2LibTest extends PHPUnit\Framework\TestCase
*/
public function testIsValidMailDomain()
{
+ $mail = 'bidon@unvalid.unvalid';
+ $result = isValidMailDomain($mail);
+ $this->assertEquals(0, $result, 'Email isValidMailDomain('.$mail.') should return 0 (not valid) but returned '.$result);
+
+ $mail = 'bidon@dolibarr.org';
+ $result = isValidMailDomain($mail);
+ $this->assertEquals(1, $result, 'Email isValidMailDomain('.$mail.') should return 1 (valid) but returned '.$result);
}
/**
diff --git a/test/phpunit/LangTest.php b/test/phpunit/LangTest.php
index c064a03e2f8..8b614d77948 100644
--- a/test/phpunit/LangTest.php
+++ b/test/phpunit/LangTest.php
@@ -191,9 +191,9 @@ class LangTest extends PHPUnit\Framework\TestCase
print 'Check lang file '.$file."\n";
$filecontent=file_get_contents(DOL_DOCUMENT_ROOT.'/langs/'.$code.'/'.$file);
- $result=strpos($filecontent, '%');
- print __METHOD__." Result for checking we don't have bad percent char = ".$result."\n";
- $this->assertTrue($result===false, 'Found a bad percent char % instead of % into file '.$code.'/'.$file);
+ $result=strpos($filecontent, '%'); // A special % char we don't want. We want the common one.
+ //print __METHOD__." Result for checking we don't have bad percent char = ".$result."\n";
+ $this->assertTrue($result === false, 'Found a bad percent char % instead of % into file '.$code.'/'.$file);
}
}
diff --git a/test/phpunit/UserGroupTest.php b/test/phpunit/UserGroupTest.php
index 7e3cdd24b3a..3ec92449f08 100644
--- a/test/phpunit/UserGroupTest.php
+++ b/test/phpunit/UserGroupTest.php
@@ -257,15 +257,10 @@ class UserGroupTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
- /*$result=$localobject->setstatus(0);
- print __METHOD__." id=".$localobject->id." result=".$result."\n";
- $this->assertLessThan($result, 0);
- */
+ $result = $localobject->generateDocument('templatenamethadoesnotexist', $langs);
+ print __METHOD__." result=".$result."\n";
+ $this->assertEquals(-1, $result, 'Calling generateDocument with a not existing template should return 0');
- /*$localobject->info($localobject->id);
- print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
- $this->assertNotEquals($localobject->date_creation, '');
- */
return $localobject->id;
}
diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php
index d5c1be0b4d2..a8486451c47 100644
--- a/test/phpunit/UserTest.php
+++ b/test/phpunit/UserTest.php
@@ -200,7 +200,7 @@ class UserTest extends PHPUnit\Framework\TestCase
$newlocalobject=new User($this->savdb);
$newlocalobject->initAsSpecimen();
$this->changeProperties($newlocalobject);
- $this->assertEquals($this->objCompare($localobject, $newlocalobject, true, array('id','socid','societe_id','specimen','note','ref','pass','pass_indatabase','pass_indatabase_crypted','datec','datem','datelastlogin','datepreviouslogin')), array()); // Actual, Expected
+ $this->assertEquals($this->objCompare($localobject, $newlocalobject, true, array('id','socid','societe_id','specimen','note','ref','pass','pass_indatabase','pass_indatabase_crypted','pass_temp','datec','datem','datelastlogin','datepreviouslogin','trackid')), array()); // Actual, Expected
return $localobject;
}
@@ -340,12 +340,11 @@ class UserTest extends PHPUnit\Framework\TestCase
$oVarsB=get_object_vars($oB);
$aKeys=array_keys($oVarsA);
foreach ($aKeys as $sKey) {
- if (in_array($sKey, $fieldstoignorearray))
- continue;
- if (! $ignoretype && $oVarsA[$sKey] !== $oVarsB[$sKey]) {
+ if (in_array($sKey, $fieldstoignorearray)) continue;
+ if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
- if ($ignoretype && $oVarsA[$sKey] != $oVarsB[$sKey]) {
+ if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]);
}
}
|