*
* 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
@@ -31,12 +31,12 @@
class RiskAssessmentDocument extends DigiriskDocuments
{
/**
- * @var string Module name.
+ * @var string Module name
*/
public $module = 'digiriskdolibarr';
/**
- * @var string Element type of object.
+ * @var string Element type of object
*/
public $element = 'riskassessmentdocument';
@@ -46,9 +46,9 @@ class RiskAssessmentDocument extends DigiriskDocuments
public string $picto = 'fontawesome_fa-file-alt_fas_#d35968';
/**
- * Constructor.
+ * Constructor
*
- * @param DoliDb $db Database handler.
+ * @param DoliDb $db Database handler
*/
public function __construct(DoliDB $db)
{
@@ -115,102 +115,59 @@ public function load_dashboard(): array
{
global $langs;
- $arrayLastGenerateDate = $this->getLastGenerateDate();
- $arrayNextGenerateDate = $this->getNextGenerateDate();
- $arrayNbDaysBeforeNextGenerateDate = $this->getNbDaysBeforeNextGenerateDate();
-
- if (empty($arrayNbDaysBeforeNextGenerateDate['nbdaysbeforenextgeneratedate'])) {
- $arrayNbDaysAfterNextGenerateDate = $this->getNbDaysAfterNextGenerateDate();
- $arrayNbDaysBeforeNextGenerateDate = ['nbdaysbeforenextgeneratedate' => 'N/A'];
- } else {
- $arrayNbDaysAfterNextGenerateDate = ['nbdaysafternextgeneratedate' => 'N/A'];
- }
+ $arrayGetGenerationDateInfos = $this->getGenerationDateInfos();
$array['widgets'] = [
'riskassessmentdocument' => [
- 'label' => [$langs->transnoentities('LastGenerateDate') ?? '', $langs->transnoentities('NextGenerateDate') ?? '', $langs->transnoentities('NbDaysBeforeNextGenerateDate') ?? '', $langs->transnoentities('NbDaysAfterNextGenerateDate') ?? ''],
- 'content' => [$arrayLastGenerateDate['lastgeneratedate'] ?? 0, $arrayNextGenerateDate['nextgeneratedate'] ?? 0, $arrayNbDaysBeforeNextGenerateDate['nbdaysbeforenextgeneratedate'] ?? 0, $arrayNbDaysAfterNextGenerateDate['nbdaysafternextgeneratedate'] ?? 0],
- 'picto' => 'fas fa-info-circle',
- 'widgetName' => $langs->transnoentities('RiskAssessmentDocument')
+ 'title' => $langs->transnoentities('RiskAssessmentDocument'),
+ 'picto' => 'fas fa-book',
+ 'pictoColor' => '#0D8AFF',
+ 'label' => [$langs->transnoentities('NextGenerateDate') ?? '', $langs->transnoentities('LastGenerateDate') ?? '', $langs->transnoentities('DelayGenerateDate') ?? ''],
+ 'content' => [$arrayGetGenerationDateInfos['nextgeneratedate'], $arrayGetGenerationDateInfos['lastgeneratedate'], $arrayGetGenerationDateInfos['delaygeneratedate']],
+ 'picto' => 'fas fa-info-circle',
+ 'moreContent' => ['', $arrayGetGenerationDateInfos['moreContent'] ?? ''],
+ 'widgetName' => $langs->transnoentities('RiskAssessmentDocument')
]
];
return $array;
}
- /**
- * Get last riskassessmentdocument generate date.
- *
- * @return array
- * @throws Exception
- */
- public function getLastGenerateDate()
- {
- // Last riskassessmentdocument generate date
- $filter = array('customsql' => "t.type='riskassessmentdocument'");
- $riskassessmentdocumentarray = $this->fetchAll('desc', 't.rowid', 1, 0, $filter, 'AND');
- if ( ! empty($riskassessmentdocumentarray) && $riskassessmentdocumentarray > 0 && is_array($riskassessmentdocumentarray)) {
- $riskassessmentdocument = array_shift($riskassessmentdocumentarray);
- $array['lastgeneratedate'] = dol_print_date($riskassessmentdocument->date_creation, 'day');
- } else {
- $array['lastgeneratedate'] = 'N/A';
- }
- return $array;
- }
-
- /**
- * Get next riskassessmentdocument generate date.
- *
- * @return array
- * @throws Exception
- */
- public function getNextGenerateDate()
- {
- // Next riskassessmentdocument generate date
- $filter = array('customsql' => "t.type='riskassessmentdocument'");
- $riskassessmentdocumentarray = $this->fetchAll('desc', 't.rowid', 1, 0, $filter, 'AND');
- if ( ! empty($riskassessmentdocumentarray) && $riskassessmentdocumentarray > 0 && is_array($riskassessmentdocumentarray)) {
- $riskassessmentdocument = array_shift($riskassessmentdocumentarray);
- $array['nextgeneratedate'] = dol_print_date(dol_time_plus_duree($riskassessmentdocument->date_creation, '1', 'y'), 'day');
- } else {
- $array['nextgeneratedate'] = 'N/A';
- }
- return $array;
- }
+ /**
+ * Get generation date infos
+ *
+ * @param array $moreParam More param (Object/user/etc)
+ *
+ * @return array
+ * @throws Exception
+ */
+ public function getGenerationDateInfos(array $moreParam = []): array
+ {
+ global $langs;
- /**
- * Get number days before next riskassessmentdocument generate date.
- *
- * @return array
- * @throws Exception
- */
- public function getNbDaysBeforeNextGenerateDate()
- {
- // Number days before next riskassessmentdocument generate date
- $arrayNextGenerateDate = $this->getNextGenerateDate();
- if ($arrayNextGenerateDate['nextgeneratedate'] > 0) {
- $array['nbdaysbeforenextgeneratedate'] = num_between_day(dol_now(), dol_stringtotime($arrayNextGenerateDate['nextgeneratedate']), 1);
- } else {
- $array['nbdaysbeforenextgeneratedate'] = 'N/A';
- }
- return $array;
- }
+ $filter = ['customsql' => 't.type = "' . $this->element . '"' . ($moreParam['filter'] ?? '')];
+ $riskAssessmentDocuments = $this->fetchAll('desc', 't.rowid', 1, 0, $filter);
+ if (!empty($riskAssessmentDocuments) && is_array($riskAssessmentDocuments)) {
+ $riskAssessmentDocument = array_shift($riskAssessmentDocuments);
+ $now = dol_now();
+ $nextGenerateTimeStamp = dol_time_plus_duree($riskAssessmentDocument->date_creation, '1', 'y');
+ $nextGenerateDate = dol_print_date($nextGenerateTimeStamp, 'day');
+ $lastGenerateDate = dol_print_date($riskAssessmentDocument->date_creation, 'day');
+ $nbDaysAfterNextGenerateDate = num_between_day($now, $nextGenerateTimeStamp, 1);
+ $nbDaysBeforeNextGenerateDate = num_between_day($nextGenerateTimeStamp, $now, 1);
+
+ $array['nextgeneratedate'] = img_picto('', 'fontawesome_fa-calendar_far_#263C5C80', 'class="pictofixedwidth"') . $nextGenerateDate;
+ $array['nextgeneratedate'] .= ' ' . (!empty($nbDaysAfterNextGenerateDate) ? $nbDaysAfterNextGenerateDate . ' ' . $langs->transnoentities('Days') : '');
+ $array['lastgeneratedate'] = img_picto('', 'fontawesome_fa-calendar_far_#263C5C80', 'class="pictofixedwidth"') . $lastGenerateDate;
+ $array['delaygeneratedate'] = !empty($nbDaysBeforeNextGenerateDate) ? $nbDaysBeforeNextGenerateDate . ' ' . $langs->transnoentities('Days') : $langs->transnoentities('NoDelay');
+ } else {
+ $array['nextgeneratedate'] = 'N/A';
+ $array['lastgeneratedate'] = 'N/A';
+ $array['delaygeneratedate'] = 'N/A';
+ }
- /**
- * Get number days after next riskassessmentdocument generate date.
- *
- * @return array
- * @throws Exception
- */
- public function getNbDaysAfterNextGenerateDate()
- {
- // Number days after next riskassessmentdocument generate date
- $arrayNextGenerateDate = $this->getNextGenerateDate();
- if ($arrayNextGenerateDate['nextgeneratedate'] > 0) {
- $array['nbdaysafternextgeneratedate'] = num_between_day(dol_stringtotime($arrayNextGenerateDate['nextgeneratedate']), dol_now(), 1);
- } else {
- $array['nbdaysafternextgeneratedate'] = 'N/A';
- }
- return $array;
- }
+ $array['moreContent'] = $this->showUrlOfLastGeneratedDocument($this->module, $this->element, 'odt', 'fontawesome_fa-file-word_far_#0D8AFF', $moreParam['entity'] ?? 1);
+ $array['moreContent'] .= $this->showUrlOfLastGeneratedDocument($this->module, $this->element, 'pdf', 'fontawesome_fa-file-pdf_far_#FB4B54', $moreParam['entity'] ?? 1);
+ return $array;
+ }
}
diff --git a/class/digiriskelement.class.php b/class/digiriskelement.class.php
index b1bfa04bd..633a0503a 100644
--- a/class/digiriskelement.class.php
+++ b/class/digiriskelement.class.php
@@ -136,7 +136,7 @@ public function create(User $user, bool $notrigger = false): int
{
global $conf;
if (empty($this->ref)) {
- $type = 'DIGIRISKDOLIBARR_' . strtoupper($this->element_type) . '_ADDON';
+ $type = 'DIGIRISKDOLIBARR_' . dol_strtoupper($this->element_type) . '_ADDON';
$objectMod = $conf->global->$type;
$numberingModules = [
'digiriskelement/' . $this->element_type => $objectMod
@@ -367,6 +367,30 @@ public function getMultiEntityTrashList()
}
}
+ /**
+ * Return SQL filter for trash exclusion
+ *
+ * @return string
+ * @throws Exception
+ */
+ public function getTrashExclusionSqlFilter(): string
+ {
+ $filter = '';
+ $digiriskElementTrashs = $this->getMultiEntityTrashList();
+ if (!empty($digiriskElementTrashs) && is_array($digiriskElementTrashs)) {
+ $filter = '(';
+ foreach (array_keys($digiriskElementTrashs) as $digiriskElementTrash) {
+ $filter .= $digiriskElementTrash . ', ';
+ }
+ if (preg_match('/, /', $filter)) {
+ $filter = rtrim($filter, ', ');
+ }
+ $filter .= ')';
+ }
+
+ return $filter;
+ }
+
/**
* Return list of parent ids for an element
*
@@ -400,7 +424,7 @@ public function getActiveDigiriskElements(int $multiEntityManagement = 0, array
$this->ismultientitymanaged = 0;
}
- $digiriskElements = $this->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . self::STATUS_VALIDATED . $moreParams['filter']]);
+ $digiriskElements = $this->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . self::STATUS_VALIDATED . ($moreParams['filter'] ?? '')]);
$trashList = $this->getMultiEntityTrashList();
if (is_array($trashList) && !empty($trashList)) {
foreach($trashList as $trashElementID) {
@@ -539,10 +563,22 @@ public function getTriggerDescription(SaturneObject $object): string
*/
public function load_dashboard(): array
{
- $getDigiriskElementListsByDepth = $this->getDigiriskElementListsByDepth();
- $getRisksByDigiriskElement = $this->getRisksByDigiriskElement();
+ global $langs;
+
+ $confName = strtoupper($this->module) . '_DASHBOARD_CONFIG';
+ $dashboardConfig = json_decode(getDolUserString($confName));
+ $array = ['graphs' => [], 'disabledGraphs' => []];
- $array['graphs'] = [$getDigiriskElementListsByDepth, $getRisksByDigiriskElement];
+ if (empty($dashboardConfig->graphs->DigiriskElementsRepartitionByDepth->hide)) {
+ $array['graphs'][] = $this->getDigiriskElementListsByDepth();
+ } else {
+ $array['disabledGraphs']['DigiriskElementsRepartitionByDepth'] = $langs->transnoentities('DigiriskElementsRepartitionByDepth');
+ }
+ if (empty($dashboardConfig->graphs->RisksRepartitionByDigiriskElement->hide)) {
+ $array['graphs'][] = $this->getRisksByDigiriskElement();
+ } else {
+ $array['disabledGraphs']['RisksRepartitionByDigiriskElement'] = $langs->transnoentities('RisksRepartitionByDigiriskElement');
+ }
return $array;
}
@@ -561,6 +597,7 @@ public function getRisksByDigiriskElement(string $riskType = 'risk'): array
// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDigiriskElement');
+ $array['name'] = 'RisksRepartitionByDigiriskElement';
$array['picto'] = $this->picto;
// Graph parameters
@@ -613,6 +650,7 @@ public function getDigiriskElementListsByDepth(): array
// Graph Title parameters
$array['title'] = $langs->transnoentities('DigiriskElementsRepartitionByDepth', getDolGlobalInt('DIGIRISKDOLIBARR_DIGIRISKELEMENT_DEPTH_GRAPH'));
+ $array['name'] = 'DigiriskElementsRepartitionByDepth';
$array['picto'] = $this->picto;
// Graph parameters
diff --git a/class/digiriskresources.class.php b/class/digiriskresources.class.php
index e71f9c868..8cc3ea958 100644
--- a/class/digiriskresources.class.php
+++ b/class/digiriskresources.class.php
@@ -301,7 +301,7 @@ public function fetchDigiriskResources()
$allLinks = array();
if (!empty ($links) && $links > 0) {
foreach ($links as $link) {
- if ($allLinks[$link->ref]->ref == $link->ref) {
+ if (isset($allLinks[$link->ref]) && $allLinks[$link->ref]->ref == $link->ref) {
array_push($allLinks[$link->ref]->id, $link->element_id);
} else {
$allLinks[$link->ref] = new stdClass();
@@ -329,9 +329,11 @@ public function load_dashboard(): array
$array['widgets'] = [
'society' => [
+ 'title' => $langs->transnoentities('Society'),
+ 'picto' => 'fas fa-building',
+ 'pictoColor' => '#FB4B54',
'label' => [$langs->transnoentities('SiretNumber') ?? ''],
'content' => [$arraySiretNumber['siretnumber'] ?? 0],
- 'picto' => 'fas fa-building',
'widgetName' => $langs->transnoentities('Society')
]
];
diff --git a/class/evaluator.class.php b/class/evaluator.class.php
index 1ce18b023..2bb75a0a5 100644
--- a/class/evaluator.class.php
+++ b/class/evaluator.class.php
@@ -142,10 +142,12 @@ public function load_dashboard(): array
$array['widgets'] = [
'evaluator' => [
+ 'title' => $langs->transnoentities('Employees'),
+ 'picto' => 'fas fa-user',
+ 'pictoColor' => '#32E592',
'label' => [$langs->transnoentities('NbEmployeesInvolved') ?? '', $langs->transnoentities('NbEmployees') ?? ''],
'content' => [$arrayNbEmployeesInvolved['nbemployeesinvolved'] ?? 0, $arrayNbEmployees['nbemployees'] ?? 0],
'tooltip' => [$langs->transnoentities('NbEmployeesInvolvedTooltip'), (($conf->global->DIGIRISKDOLIBARR_NB_EMPLOYEES > 0 && $conf->global->DIGIRISKDOLIBARR_MANUAL_INPUT_NB_EMPLOYEES) ? $langs->transnoentities('NbEmployeesConfTooltip') : $langs->transnoentities('NbEmployeesTooltip'))],
- 'picto' => 'fas fa-user-check',
'widgetName' => $langs->transnoentities('Evaluator')
]
];
@@ -156,12 +158,13 @@ public function load_dashboard(): array
/**
* Get number employees involved.
*
- * @return array
+ * @param array $moreParam More param (Object/user/etc)
+ * @return array
* @throws Exception
*/
- public function getNbEmployeesInvolved() {
+ public function getNbEmployeesInvolved(array $moreParam = []) {
// Number employees involved
- $allevaluators = $this->fetchAll('','', 0, 0, array(), 'AND', 'fk_user');
+ $allevaluators = $this->fetchAll('','', 0, 0, ['customsql' => ($moreParam['filter'] ?? '')], 'AND', 'fk_user');
if (is_array($allevaluators) && !empty($allevaluators)) {
$array['nbemployeesinvolved'] = count($allevaluators);
} else {
@@ -170,29 +173,29 @@ public function getNbEmployeesInvolved() {
return $array;
}
- /**
- * Get number employees.
- *
- * @return array
- * @throws Exception
- */
- public function getNbEmployees() {
- global $conf;
-
- // Number employees
- if ($conf->global->DIGIRISKDOLIBARR_NB_EMPLOYEES > 0 && $conf->global->DIGIRISKDOLIBARR_MANUAL_INPUT_NB_EMPLOYEES) {
- $array['nbemployees'] = $conf->global->DIGIRISKDOLIBARR_NB_EMPLOYEES;
- } else {
- $user = new User($this->db);
- $allusers = $user->get_full_tree(0, 'u.employee = 1');
- if (!empty($allusers) && is_array($allusers)) {
- $array['nbemployees'] = count($allusers);
- } else {
- $array['nbemployees'] = 'N/A';
- }
- }
- return $array;
- }
+ /**
+ * Get number employees
+ *
+ * @param array $moreParam More param (Object/user/etc)
+ * @return array
+ * @throws Exception
+ */
+ public function getNbEmployees(array $moreParam = []): array
+ {
+ global $user;
+
+ if (getDolGlobalInt('DIGIRISKDOLIBARR_NB_EMPLOYEES') > 0 && getDolGlobalInt('DIGIRISKDOLIBARR_MANUAL_INPUT_NB_EMPLOYEES')) {
+ $array['nbemployees'] = getDolGlobalInt('DIGIRISKDOLIBARR_NB_EMPLOYEES');
+ } else {
+ $users = $user->get_full_tree(0, 'u.employee = 1' . ($moreParam['filter'] ?? ''));
+ if (!empty($users) && is_array($users)) {
+ $array['nbemployees'] = count($users);
+ } else {
+ $array['nbemployees'] = 0;
+ }
+ }
+ return $array;
+ }
/**
* Write information of trigger description
diff --git a/class/firepermit.class.php b/class/firepermit.class.php
index da31e6473..ed78e83e5 100644
--- a/class/firepermit.class.php
+++ b/class/firepermit.class.php
@@ -306,6 +306,12 @@ public function LibStatut($status, $mode = 0): string
$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('ValidatePendingSignature');
$this->labelStatus[self::STATUS_LOCKED] = $langs->trans('Locked');
$this->labelStatus[self::STATUS_ARCHIVED] = $langs->trans('Archived');
+
+ $this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('InProgress');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatePendingSignature');
+ $this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked');
+ $this->labelStatusShort[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived');
}
$statusType = 'status' . $status;
diff --git a/class/preventionplan.class.php b/class/preventionplan.class.php
index e300c48cf..f0c6d9d5d 100644
--- a/class/preventionplan.class.php
+++ b/class/preventionplan.class.php
@@ -307,6 +307,12 @@ public function LibStatut($status, $mode = 0): string
$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('ValidatePendingSignature');
$this->labelStatus[self::STATUS_LOCKED] = $langs->trans('Locked');
$this->labelStatus[self::STATUS_ARCHIVED] = $langs->trans('Archived');
+
+ $this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted');
+ $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
+ $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
+ $this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked');
+ $this->labelStatusShort[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived');
}
$statusType = 'status' . $status;
diff --git a/class/riskanalysis/risk.class.php b/class/riskanalysis/risk.class.php
index 33b8d4b17..f054e7812 100644
--- a/class/riskanalysis/risk.class.php
+++ b/class/riskanalysis/risk.class.php
@@ -87,7 +87,7 @@ class Risk extends SaturneObject
'import_key' => ['type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => '1', 'position' => 70, 'notnull' => -1, 'visible' => 0],
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 0],
'category' => ['type' => 'varchar(255)', 'label' => 'RiskCategory', 'enabled' => '1', 'position' => 21, 'notnull' => 0, 'visible' => 1],
- 'description' => ['type' => 'text', 'label' => 'Description', 'enabled' => '1', 'position' => 23, 'notnull' => 0, 'visible' => -1],
+ 'description' => ['type' => 'text', 'label' => 'Description', 'enabled' => '$conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION', 'position' => 23, 'notnull' => 0, 'visible' => -1],
'type' => ['type' => 'varchar(255)', 'label' => 'Type', 'enabled' => '1', 'position' => 24, 'notnull' => 1, 'visible' => 0, 'default' => '(PROV)'],
'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => '1', 'position' => 110, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid'],
'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 120, 'notnull' => -1, 'visible' => 0],
@@ -140,12 +140,12 @@ public function __construct(DoliDB $db)
'label' => $langs->transnoentities('RedRisk'),
'color' => '#e05353',
'start' => 51,
- 'end' => 80
+ 'end' => 79
],
4 => [
'label' => $langs->transnoentities('BlackRisk'),
'color' => '#2b2b2b',
- 'start' => 81,
+ 'start' => 80,
'end' => 100
]
];
@@ -192,7 +192,8 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
$objects = $object->getActiveDigiriskElements();
if ($get_shared_data) {
- $risk->ismultientitymanaged = 0;
+ $activeDigiriskElements = $object->getActiveDigiriskElements($get_shared_data);
+ $risk->ismultientitymanaged = 0;
$riskAssessment->ismultientitymanaged = 0;
}
$riskList = $risk->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . self::STATUS_VALIDATED . $moreParams['filterRisk']]);
@@ -305,11 +306,13 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
$digiriskElementOfEntity->fetchObjectLinked(null, '', $digiriskElementOfEntity->id, 'digiriskdolibarr_digiriskelement', 'AND', 1, 'sourcetype', 0);
if (!empty($digiriskElementOfEntity->linkedObjectsIds['digiriskdolibarr_risk'])) {
foreach ($digiriskElementOfEntity->linkedObjectsIds['digiriskdolibarr_risk'] as $sharedRiskId) {
- $sharedRisk = $riskList[$sharedRiskId];
- if (is_object($sharedRisk)) {
- $sharedRisk->appliedOn = $digiriskElementOfEntity->id;
- $risks[] = $sharedRisk;
- }
+ $sharedRisk = $riskList[$sharedRiskId];
+ $sharedParentActive = array_search($sharedRisk->fk_element, array_column($activeDigiriskElements, 'id'));
+ if (is_object($sharedRisk) && $sharedParentActive > 0) {
+ $clonedRisk = clone $sharedRisk;
+ $clonedRisk->appliedOn = $digiriskElementOfEntity->id;
+ $risks[] = $clonedRisk;
+ }
}
}
}
@@ -320,10 +323,12 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
$parentElement->fetchObjectLinked(null, '', $parent_id, 'digiriskdolibarr_digiriskelement', 'AND', 1, 'sourcetype', 0);
if (!empty($parentElement->linkedObjectsIds['digiriskdolibarr_risk'])) {
foreach ($parentElement->linkedObjectsIds['digiriskdolibarr_risk'] as $sharedRiskId) {
- $sharedRisk = $riskList[$sharedRiskId];
- if (is_object($sharedRisk)) {
- $sharedRisk->appliedOn = $parent_id;
- $risks[] = $sharedRisk;
+ $sharedRisk = $riskList[$sharedRiskId];
+ $sharedParentActive = array_search($sharedRisk->fk_element, array_column($activeDigiriskElements, 'id'));
+ if (is_object($sharedRisk) && $sharedParentActive > 0) {
+ $clonedRisk = clone $sharedRisk;
+ $clonedRisk->appliedOn = $parent_id;
+ $risks[] = $clonedRisk;
}
}
}
@@ -490,6 +495,100 @@ public function getFirePermitDangerCategoryName($object)
return -1;
}
+ /**
+ * check if risk not exists for a digirisk element
+ *
+ * @param int $limit Limit
+ * @return array|int Int <0 if KO, array of pages if OK
+ * @throws Exception
+ */
+ public function checkNotExistsDigiriskElementForRisk(int $limit = 0)
+ {
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $digiriskElement = new DigiriskElement($this->db);
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+ $sql .= ' WHERE !EXISTS';
+ $sql .= ' ( SELECT ';
+ $sql .= $digiriskElement->getFieldList('d');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d';
+ $sql .= ' WHERE d.rowid = t.fk_element )';
+
+ $records = [];
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new $this($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error ' . $this->db->lasterror();
+ dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
+ return -1;
+ }
+ }
+
+ /**
+ * check if risk assessment not exists for a risk
+ *
+ * @param int $limit Limit
+ * @return array|int Int <0 if KO, array of pages if OK
+ * @throws Exception
+ */
+ public function checkNotExistsRiskAssessmentForRisk(int $limit = 0)
+ {
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $riskAssessment = new RiskAssessment($this->db);
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+ $sql .= ' WHERE !EXISTS';
+ $sql .= ' (SELECT ';
+ $sql .= $riskAssessment->getFieldList('ra');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $riskAssessment->table_element . ' as ra';
+ $sql .= ' WHERE ra.fk_risk = t.rowid)';
+
+ $records = [];
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new $this($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error ' . $this->db->lasterror();
+ dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
+ return -1;
+ }
+ }
+
/**
* Get children tasks
*
@@ -534,7 +633,7 @@ public function getRelatedTasks($risk)
*/
public function getTasksWithFkRisk()
{
- $sql = "SELECT * FROM " . MAIN_DB_PREFIX . 'projet_task_extrafields' . ' WHERE fk_risk > 0';
+ $sql = "SELECT * FROM " . MAIN_DB_PREFIX . 'projet_task_extrafields' . ' WHERE fk_risk > 0 ORDER BY fk_object ASC';
$tasksList = saturne_fetch_all_object_type('SaturneTask', '', '', 0, 0, [], 'AND', false, false);
$resql = $this->db->query($sql);
@@ -545,7 +644,7 @@ public function getTasksWithFkRisk()
$records = array();
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
- $records[$obj->fk_risk][$obj->rowid] = $tasksList[$obj->fk_object];
+ $records[$obj->fk_risk][$obj->rowid] = $tasksList[$obj->fk_object] ?? null;
$i++;
}
$this->db->free($resql);
@@ -567,15 +666,51 @@ public function getTasksWithFkRisk()
*/
public function load_dashboard(): array
{
- $dangerCategories = $this->getDangerCategories();
+ global $langs;
+
+ $confName = dol_strtoupper($this->module) . '_DASHBOARD_CONFIG';
+ $dashboardConfig = json_decode(getDolUserString($confName));
+ $array = ['graphs' => [], 'lists' => [], 'disabledGraphs' => []];
+
+ $riskType = !empty($dashboardConfig->filters->riskType) ? $dashboardConfig->filters->riskType : 'risk';
- $getRisksByCotation = $this->getRisksByCotation();
- $getRisksByDangerCategoriesAndCriticality = $this->getRisksByDangerCategoriesAndCriticality($dangerCategories);
- $getRisksByDangerCategories = $this->getRisksByDangerCategories($dangerCategories);
- $getRiskListsByDangerCategories = $this->getRiskListsByDangerCategories($dangerCategories);
+ $digiriskElement = new DigiriskElement($this->db);
- $array['graphs'] = [$getRisksByCotation, $getRisksByDangerCategoriesAndCriticality, $getRisksByDangerCategories];
- $array['lists'] = [$getRiskListsByDangerCategories];
+ $filter = 'AND t.fk_element NOT IN ' . $digiriskElement->getTrashExclusionSqlFilter();
+
+ $dangerCategories = $this->getDangerCategories();
+ $riskByDangerCategoriesAndRiskAssessments = $this->getRiskByDangerCategoriesAndRiskAssessments($dangerCategories, $filter, $riskType);
+ $moreParam['filter'] = $filter;
+
+ $array['graphsFilters'] = [
+ 'riskType' => [
+ 'title' => $langs->transnoentities('DisplayRiskOfType'),
+ 'type' => 'selectarray',
+ 'filter' => 'riskType',
+ 'values' => ['risk' => $langs->transnoentities('Risk'), 'riskenvironmental' => $langs->transnoentities('Riskenvironmental')],
+ 'currentValue' => $riskType
+ ]];
+
+ if (empty($dashboardConfig->graphs->RisksRepartitionByDangerCategoriesAndCriticality->hide)) {
+ $array['graphs'][] = $this->getRisksByDangerCategoriesAndCriticality($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
+ } else {
+ $array['disabledGraphs']['RisksRepartitionByDangerCategoriesAndCriticality'] = $langs->transnoentities('RisksRepartitionByDangerCategoriesAndCriticality');
+ }
+ if (empty($dashboardConfig->graphs->RisksRepartitionByDangerCategories->hide)) {
+ $array['graphs'][] = $this->getRisksByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
+ } else {
+ $array['disabledGraphs']['RisksRepartitionByDangerCategories'] = $langs->transnoentities('RisksRepartitionByDangerCategories');
+ }
+ if (empty($dashboardConfig->graphs->RisksRepartitionByCotation->hide)) {
+ $array['graphs'][] = $this->getRisksByCotation($moreParam);
+ } else {
+ $array['disabledGraphs']['RisksRepartitionByCotation'] = $langs->transnoentities('RisksRepartitionByCotation');
+ }
+ if (empty($dashboardConfig->graphs->RiskListsByDangerCategories->hide)) {
+ $array['lists'][] = $this->getRiskListsByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments, $filter, $riskType);
+ } else {
+ $array['disabledGraphs']['RiskListsByDangerCategories'] = $langs->transnoentities('RiskListsByDangerCategories');
+ }
return $array;
}
@@ -583,17 +718,20 @@ public function load_dashboard(): array
/**
* Get risks by cotation
*
+ * @param array $moreParam More param (Object/user/etc)
* @return array
* @throws Exception
*/
- public function getRisksByCotation(): array
+ public function getRisksByCotation(array $moreParam = []): array
{
global $conf, $langs;
- $riskAssessment = new RiskAssessment($this->db);
+ $riskAssessment = new RiskAssessment($this->db);
+ $digiriskElement = new DigiriskElement($this->db);
// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartition');
+ $array['name'] = 'RisksRepartition';
$array['picto'] = $this->picto;
// Graph parameters
@@ -604,8 +742,11 @@ public function getRisksByCotation(): array
$array['dataset'] = 1;
$array['labels'] = $this->cotations;
- $riskAssessmentList = $riskAssessment->fetchAll('', '', 0, 0, ['customsql' => 'status = 1']);
- $array['data'] = $riskAssessment->getRiskAssessmentCategoriesNumber($riskAssessmentList);
+ $join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as r ON r.rowid = t.fk_risk';
+ $join .= ' LEFT JOIN ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d ON d.rowid = r.fk_element';
+
+ $riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . str_replace('t.fk_element NOT IN', 'r.fk_element NOT IN', $moreParam['filter'])], 'AND', false, $moreParam['multiEntityManagement'] ?? true, false, $join);
+ $array['data'] = $riskAssessment->getRiskAssessmentCategoriesNumber($riskAssessments);
return $array;
}
@@ -613,18 +754,17 @@ public function getRisksByCotation(): array
/**
* Get risks by danger categories and criticality
*
- * @param array $dangerCategories Danger categories datas
- * @param string $type Risk type (risk, riskenvironmental or ...)
- *
+ * @param array $dangerCategories Danger categories datas
+ * @param array $riskByDangerCategoriesAndRiskAssessments Risk by danger categories and risk assessments
* @return array
- * @throws Exception
*/
- public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories, string $type = 'risk'): array
+ public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories, array $riskByDangerCategoriesAndRiskAssessments): array
{
- global $conf, $langs;
+ global $langs;
// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDangerCategoriesAndCriticality');
+ $array['name'] = 'RisksRepartitionByDangerCategoriesAndCriticality';
$array['picto'] = $this->picto;
// Graph parameters
@@ -636,14 +776,10 @@ public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories
$array['moreCSS'] = 'grid-2';
$array['labels'] = $this->cotations;
- $join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as r ON r.rowid = t.fk_risk';
foreach ($dangerCategories as $dangerCategory) {
$array['data'][$dangerCategory['position']][0] = $dangerCategory['name'];
-
- $risks = $this->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '" AND t.category = ' . $dangerCategory['position']]);
for ($i = 1; $i <= 4; $i++) {
- $riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . ' AND r.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND r.fk_element = ' . GETPOST('id') : '') . ' AND r.type = "' . $type . '" AND r.category = ' . $dangerCategory['position'] . ' AND t.cotation >= ' . $this->cotations[$i]['start'] . ' AND t.cotation <= ' . $this->cotations[$i]['end']], 'AND', false, true, false, $join);
- $array['data'][$dangerCategory['position']]['y_combined_' . $array['labels'][$i]['label']] = ((is_array($risks) && !empty($risks) && is_array($riskAssessments) && !empty($riskAssessments)) ? count($riskAssessments) / count($risks) : 0);
+ $array['data'][$dangerCategory['position']]['y_combined_' . $array['labels'][$i]['label']] = !empty($riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['risk']) ? $riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['riskAssessments'][$i] / $riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['risk'] : 0;
}
}
@@ -653,18 +789,19 @@ public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories
/**
* Get risks by danger categories
*
- * @param array $dangerCategories Danger categories datas
- * @param string $type Risk type (risk, riskenvironmental or ...)
- *
+ * @param array $dangerCategories Danger categories datas
+ * @param array $riskByDangerCategoriesAndRiskAssessments Risk by danger categories and risk assessments
+ *
* @return array
* @throws Exception
*/
- public function getRisksByDangerCategories(array $dangerCategories, string $type = 'risk'): array
+ public function getRisksByDangerCategories(array $dangerCategories, array $riskByDangerCategoriesAndRiskAssessments): array
{
- global $conf, $langs;
+ global $langs;
// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDangerCategories');
+ $array['name'] = 'RisksRepartitionByDangerCategories';
$array['picto'] = $this->picto;
// Graph parameters
@@ -683,10 +820,8 @@ public function getRisksByDangerCategories(array $dangerCategories, string $type
];
foreach ($dangerCategories as $dangerCategory) {
- $risks = $this->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '" AND t.category = ' . $dangerCategory['position']]);
-
$array['data'][$dangerCategory['position']][] = $dangerCategory['name'];
- $array['data'][$dangerCategory['position']][] = (is_array($risks) && !empty($risks) ? count($risks) : 0);
+ $array['data'][$dangerCategory['position']][] = $riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['risk'];
}
return $array;
@@ -695,49 +830,50 @@ public function getRisksByDangerCategories(array $dangerCategories, string $type
/**
* Get list of risks by danger categories
*
- * @param array $dangerCategories Danger categories datas
- * @param string $type Risk type (risk, riskenvironmental or ...)
+ * @param array $dangerCategories Danger categories datas
+ * @param array $riskByDangerCategoriesAndRiskAssessments Risk by danger categories and risk assessments
+ * @param string $filter SQL Filter
+ * @param string $type Risk type (risk, riskenvironmental or ...)
*
* @return array
* @throws Exception
*/
- public function getRiskListsByDangerCategories(array $dangerCategories, string $type = 'risk') : array
+ public function getRiskListsByDangerCategories(array $dangerCategories, array $riskByDangerCategoriesAndRiskAssessments, string $filter = '', string $type = 'risk') : array
{
+ //$riskByDangerCategoriesAndRiskAssessments
global $conf, $langs;
+ $digiriskElement = new DigiriskElement($this->db);
+
// Graph Title parameters
$array['title'] = $langs->transnoentities('RiskListsByDangerCategories');
+ $array['name'] = 'RiskListsByDangerCategories';
$array['picto'] = $this->picto;
// Graph parameters
$array['width'] = '100%';
$array['type'] = 'list';
- $totalRisks = $this->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '"']);
+ $totalRisks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '"' . (!empty($filter) ? ' AND ' . $filter : '')], 'AND', false, true, false, ' LEFT JOIN ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d ON d.rowid = t.fk_element');
$array['labels']['Ref'] = $langs->transnoentities('DangerCategories');
$array['labels']['numberOfRisks'] = $langs->transnoentities('NumberOfRisks') . ' : ' . '' . (is_array($totalRisks) && !empty($totalRisks) ? count($totalRisks) : 0) . ' ';
$array['labels']['percentage'] = $langs->transnoentities('Percentage');
$arrayRiskLists = [];
- $join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as r ON r.rowid = t.fk_risk';
if (is_array($totalRisks) && !empty($totalRisks)) {
foreach ($dangerCategories as $dangerCategory) {
$arrayRiskLists[$dangerCategory['position']]['Ref']['value'] = $dangerCategory['name'];
- $risks = $this->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '" AND t.category = ' . $dangerCategory['position']]);
- $arrayRiskLists[$dangerCategory['position']]['numberOfRisks']['value'] = is_array($risks) && !empty($risks) ? count($risks) : 0;
+ $arrayRiskLists[$dangerCategory['position']]['numberOfRisks']['value'] = $riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['risk'];
$arrayRiskLists[$dangerCategory['position']]['numberOfRisks']['morecss'] = 'risk-evaluation-cotation';
$arrayRiskLists[$dangerCategory['position']]['numberOfRisks']['moreAttr'] = 'style="line-height: 0; border-radius: 0; background-color: #A1467EAA; color: #FFF;"';
- $arrayRiskLists[$dangerCategory['position']]['percentage']['value'] = is_array($risks) && !empty($risks) ? price2num((count($risks) / count($totalRisks)) * 100, 2) . ' %' : 0;
+ $arrayRiskLists[$dangerCategory['position']]['percentage']['value'] = price2num(($riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['risk'] / count($totalRisks)) * 100, 2) . ' %';
for ($i = 1; $i <= 4; $i++) {
$array['labels'][$i] = $this->cotations[$i]['label'];
-
- $riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . ' AND r.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND r.fk_element = ' . GETPOST('id') : '') . ' AND r.type = "' . $type . '" AND r.category = ' . $dangerCategory['position'] . ' AND t.cotation >= ' . $this->cotations[$i]['start'] . ' AND t.cotation <= ' . $this->cotations[$i]['end']], 'AND', false, true, false, $join);
-
- $arrayRiskLists[$dangerCategory['position']][$i]['value'] = is_array($riskAssessments) && !empty($riskAssessments) ? count($riskAssessments) : 0;
+ $arrayRiskLists[$dangerCategory['position']][$i]['value'] = $riskByDangerCategoriesAndRiskAssessments[$dangerCategory['name']]['riskAssessments'][$i];
$arrayRiskLists[$dangerCategory['position']][$i]['morecss'] = 'risk-evaluation-cotation';
$arrayRiskLists[$dangerCategory['position']][$i]['moreAttr'] = 'data-scale = ' . $i . ' style="line-height: 0; border-radius: 0;"';
}
@@ -749,6 +885,36 @@ public function getRiskListsByDangerCategories(array $dangerCategories, string $
return $array;
}
+ /**
+ * Get risk by danger categories and risk assessments
+ *
+ * @param array $dangerCategories Danger categories datas
+ * @param string $filter SQL Filter
+ * @param string $type Risk type (risk, riskenvironmental or ...)
+ *
+ * @return array
+ * @throws Exception
+ */
+ public function getRiskByDangerCategoriesAndRiskAssessments(array $dangerCategories, string $filter = '', string $type = 'risk') : array
+ {
+ global $conf;
+
+ $array = [];
+ $digiriskElement = new DigiriskElement($this->db);
+
+ foreach ($dangerCategories as $dangerCategory) {
+ $risks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 't.status = ' . self::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND t.fk_element = ' . GETPOST('id') : '') . ' AND t.type = "' . $type . '" AND t.category = ' . $dangerCategory['position'] . $filter], 'AND', false, true, false, ' LEFT JOIN ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d ON d.rowid = t.fk_element');
+ $array[$dangerCategory['name']]['risk'] = !empty($risks) && is_array($risks) ? count($risks) : 0;
+ for ($i = 1; $i <= 4; $i++) {
+ $join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as r ON r.rowid = t.fk_risk';
+ $join .= ' LEFT JOIN ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d ON d.rowid = r.fk_element';
+ $riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . ' AND r.entity = ' . $conf->entity . (GETPOSTISSET('id') ? ' AND r.fk_element = ' . GETPOST('id') : '') . ' AND r.type = "' . $type . '" AND r.category = ' . $dangerCategory['position'] . ' AND t.cotation >= ' . $this->cotations[$i]['start'] . ' AND t.cotation <= ' . $this->cotations[$i]['end'] . str_replace('t.fk_element NOT IN', 'r.fk_element NOT IN', $filter)], 'AND', false, true, false, $join);
+ $array[$dangerCategory['name']]['riskAssessments'][$i] = !empty($riskAssessments) && is_array($riskAssessments) ? count($riskAssessments) : 0;
+ }
+ }
+ return $array;
+ }
+
/**
* Write information of trigger description
*
diff --git a/class/riskanalysis/riskassessment.class.php b/class/riskanalysis/riskassessment.class.php
index ba8a091bc..d05ce61c1 100644
--- a/class/riskanalysis/riskassessment.class.php
+++ b/class/riskanalysis/riskassessment.class.php
@@ -92,7 +92,7 @@ class RiskAssessment extends SaturneObject
'date_riskassessment' => array('type' => 'datetime', 'label' => 'RiskAssessmentDate', 'enabled' => '1', 'position' => 141, 'notnull' => -1, 'visible' => 0,),
'comment' => array('type' => 'text', 'label' => 'Comment', 'enabled' => '1', 'position' => 150, 'notnull' => 0, 'visible' => 0,),
'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => '1', 'position' => 160, 'notnull' => 0, 'visible' => 0,),
- 'has_tasks' => array('type' => 'integer', 'label' => 'Tasks', 'enabled' => '1', 'position' => 170, 'notnull' => 0, 'visible' => -1,),
+ 'has_tasks' => array('type' => 'integer', 'label' => 'Tasks', 'enabled' => '$conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT', 'position' => 170, 'notnull' => 0, 'visible' => -1,),
'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => '1', 'position' => 180, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid',),
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 190, 'notnull' => -1, 'visible' => 0,),
'fk_risk' => array('type' => 'integer', 'label' => 'ParentRisk', 'enabled' => '1', 'position' => 200, 'notnull' => 1, 'visible' => 0,),
@@ -192,6 +192,53 @@ public function updatePreviousRiskAssessmentStatus(User $user, int $riskID)
}
}
+ /**
+ * check if risk assessment not exists for a risk
+ *
+ * @param int $limit Limit
+ * @return array|int Int <0 if KO, array of pages if OK
+ * @throws Exception
+ */
+ public function checkNotExistsRiskForRiskAssessment(int $limit = 0)
+ {
+ dol_syslog(__METHOD__, LOG_DEBUG);
+
+ $risk = new Risk($this->db);
+
+ $sql = 'SELECT ';
+ $sql .= $this->getFieldList('t');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
+ $sql .= ' WHERE !EXISTS';
+ $sql .= ' ( SELECT ';
+ $sql .= $risk->getFieldList('r');
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $risk->table_element . ' as r';
+ $sql .= ' WHERE r.rowid = t.fk_risk )';
+
+ $records = [];
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < ($limit ? min($limit, $num) : $num)) {
+ $obj = $this->db->fetch_object($resql);
+
+ $record = new $this($this->db);
+ $record->setVarsFromFetchObj($obj);
+
+ $records[$record->id] = $record;
+
+ $i++;
+ }
+ $this->db->free($resql);
+
+ return $records;
+ } else {
+ $this->errors[] = 'Error ' . $this->db->lasterror();
+ dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
+ return -1;
+ }
+ }
+
/**
* Return scale level for risk assessment
*
diff --git a/class/ticketdashboard.class.php b/class/ticketdashboard.class.php
index e16723195..5c250c6ad 100644
--- a/class/ticketdashboard.class.php
+++ b/class/ticketdashboard.class.php
@@ -40,6 +40,11 @@ class TicketDashboard extends DigiriskDolibarrDashboard
*/
public DoliDB $db;
+ /**
+ * @var string Module name
+ */
+ public $module = 'digiriskdolibarr';
+
/**
* @var string SQL FROM
*/
@@ -70,7 +75,7 @@ public function __construct(DoliDB $db, ?string $moreJoin = '', ?string $moreWhe
if (dol_strlen($moreJoin) > 0) {
$this->join .= $moreJoin;
}
- $this->where = 't.fk_statut >= 0';
+ $this->where = 't.fk_statut > 0';
$this->where .= ' AND t.entity IN (' . getEntity('ticket') . ')';
if (dol_strlen($moreWhere) > 0) {
$this->where .= $moreWhere;
@@ -267,19 +272,36 @@ public function getNbTicketByDigiriskElementAndTicketTags(int $dateStart, int $d
*/
public function load_dashboard(array $moreParams = []): array
{
- $getTicketsByMonth = $this->getTicketsByMonth();
+ global $langs;
+
+ $confName = dol_strtoupper($this->module) . '_DASHBOARD_CONFIG';
+ $dashboardConfig = json_decode(getDolUserString($confName));
+ $array = ['graphs' => [], 'lists' => [], 'disabledGraphs' => []];
$category = new Categorie($this->db);
$category->fetch(getDolGlobalInt('DIGIRISKDOLIBARR_TICKET_MAIN_CATEGORY'));
$mainCategories = $category->get_filles();
- $getTicketsByMainTagAndByDigiriskElement = $this->getTicketsByMainTagAndByDigiriskElement($mainCategories);
- $getTicketsByMainSubTagAndByDigiriskElement = $this->getTicketsByMainSubTagAndByDigiriskElement($mainCategories);
-
- $getTicketsByYear = $this->getTicketsByYear();
-
- $array['graphs'] = [$getTicketsByMonth, $getTicketsByMainTagAndByDigiriskElement, $getTicketsByMainSubTagAndByDigiriskElement];
- $array['lists'] = [$getTicketsByYear];
+ if (empty($dashboardConfig->graphs->NumberOfTicketsByMonth->hide)) {
+ $array['graphs'][] = $this->getTicketsByMonth();
+ } else {
+ $array['disabledGraphs']['NumberOfTicketsByMonth'] = $langs->transnoentities('NumberOfTicketsByMonth');
+ }
+ if (empty($dashboardConfig->graphs->NumberOfTicketsByMainTagAndByDigiriskElement->hide)) {
+ $array['graphs'][] = $this->getTicketsByMainTagAndByDigiriskElement($mainCategories);
+ } else {
+ $array['disabledGraphs']['NumberOfTicketsByMainTagAndByDigiriskElement'] = $langs->transnoentities('NumberOfTicketsByMainTagAndByDigiriskElement');
+ }
+ if (empty($dashboardConfig->graphs->NumberOfTicketsByMainSubTagAndByDigiriskElement->hide)) {
+ $array['graphs'][] = $this->getTicketsByMainSubTagAndByDigiriskElement($mainCategories);
+ } else {
+ $array['disabledGraphs']['NumberOfTicketsByMainSubTagAndByDigiriskElement'] = $langs->transnoentities('NumberOfTicketsByMainSubTagAndByDigiriskElement');
+ }
+ if (empty($dashboardConfig->graphs->NumberOfTicketsByYear->hide)) {
+ $array['lists'][] = $this->getTicketsByYear();
+ } else {
+ $array['disabledGraphs']['NumberOfTicketsByYear'] = $langs->transnoentities('NumberOfTicketsByYear');
+ }
return $array;
}
@@ -295,6 +317,7 @@ public function getTicketsByMonth(): array
// Graph Title parameters
$array['title'] = $langs->transnoentities('NumberOfTicketsByMonth');
+ $array['name'] = 'NumberOfTicketsByMonth';
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
// Graph parameters
@@ -352,6 +375,7 @@ public function getTicketsByMainTagAndByDigiriskElement($mainCategories): array
// Graph Title parameters
$array['title'] = $langs->transnoentities('NumberOfTicketsByMainTagAndByDigiriskElement');
+ $array['name'] = 'NumberOfTicketsByMainTagAndByDigiriskElement';
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
// Graph parameters
@@ -398,6 +422,7 @@ public function getTicketsByMainSubTagAndByDigiriskElement($mainCategories): arr
// Graph Title parameters
$array['title'] = $langs->transnoentities('NumberOfTicketsByMainSubTagAndByDigiriskElement');
+ $array['name'] = 'NumberOfTicketsByMainSubTagAndByDigiriskElement';
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
// Graph parameters
@@ -449,6 +474,7 @@ public function getTicketsByYear(): array
// Graph Title parameters
$array['title'] = $langs->transnoentities('NumberOfTicketsByYear');
+ $array['name'] = 'NumberOfTicketsByYear';
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
// Graph parameters
@@ -461,7 +487,7 @@ public function getTicketsByYear(): array
foreach ($tickets as $key => $ticket) {
$arrayTicketByYear[$key]['Ref']['value'] = $ticket['year'];
$arrayTicketByYear[$key]['Tickets']['value'] = $ticket['nb'];
- $arrayTicketByYear[$key]['Percentage']['value'] = price2num($ticket['avg'] ?: 0, 2) . ' %';
+ $arrayTicketByYear[$key]['Percentage']['value'] = price2num($ticket['avg'] ?? 0, 2) . ' %';
}
}
diff --git a/class/ticketstatsdashboard.class.php b/class/ticketstatsdashboard.class.php
new file mode 100644
index 000000000..bd5401729
--- /dev/null
+++ b/class/ticketstatsdashboard.class.php
@@ -0,0 +1,350 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file class/ticketstatsdashboard.class.php
+ * \ingroup digiriskdolibarr
+ * \brief Class file for manage TicketDashboard
+ */
+
+// load Dolibarr librairies
+require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
+
+/**
+ * Class to manage stats for tickets
+ */
+class TicketStatsDashboard extends DigiriskDolibarrDashboard
+{
+ /**
+ * @var DoliDB Database handler
+ */
+ public DoliDB $db;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ public function __construct(DoliDB $db)
+ {
+ parent::__construct($db);
+ }
+
+ /**
+ * Load dashboard info ticket
+ *
+ * @param array $moreParams Parameters for load dashboard info
+ * @return array
+ * @throws Exception
+ */
+ public function load_dashboard(array $moreParams = []): array
+ {
+ $tickets = $this->getAllTickets();
+
+ $runningTickets = $this->getRunningTickets($tickets);
+ $ticketStats = $this->getTicketStats($tickets);
+
+ $getTicketRepartitionPerUserAndMeanAnswerTime = $this->getTicketRepartitionPerUserAndMeanAnswerTime($tickets);
+ $getTopSocietyWithMostTickets = $this->getTopSocietyWithMostTickets($tickets);
+
+ $array['widgets'] = array_merge($runningTickets, $ticketStats);
+ $array['graphs'] = [$getTicketRepartitionPerUserAndMeanAnswerTime, $getTopSocietyWithMostTickets];
+
+ return $array;
+ }
+
+ /**
+ * Get all tickets from database for current entity order by datec DESC
+ * fetch all comments for each ticket if exists
+ * add them to ticket object as comms property (array of comments)
+ *
+ * @return array $tickets All tickets with comments if exists or empty array
+ * @throws Exception If an error occurs while fetching tickets
+ */
+ public function getAllTickets(): array
+ {
+ try {
+ $actionComm = new ActionComm($this->db);
+ $tickets = saturne_fetch_all_object_type('Ticket', 'DESC', 't.datec');
+ if (!empty($tickets) && is_array($tickets)) {
+ foreach ($tickets as $ticketID => $ticket) {
+ $ticket->comms = [];
+ $actionComms = $actionComm->getActions(0, $ticketID, 'ticket', 'AND a.code LIKE "TICKET_MSG%"', 'a.datec');
+ if (!empty($actionComms) && is_array($actionComms)) {
+ $ticket->comms = $actionComms;
+ } elseif (is_string($actionComms)) {
+ dol_syslog(__METHOD__ . 'Error while fetching comments for ticket ID {$ticketID}: ' . $actionComms, LOG_ERR);
+ }
+ }
+ }
+ } catch (Exception $e) {
+ dol_syslog(__METHOD__ . 'Error while fetching tickets: ' . $e->getMessage(), LOG_ERR);
+ throw $e;
+ }
+
+ return $tickets;
+ }
+
+ /**
+ * Get running tickets
+ *
+ * @param array $tickets All tickets from database for current entity order by datec DESC with comments if exists or empty array
+ * @return array Widget of running tickets with the oldest ticket and oldest message ticket
+ */
+ public function getRunningTickets(array $tickets): array
+ {
+ global $form, $langs;
+
+ // Widget title parameters
+ $array['title'] = $langs->transnoentities('RunningTicket');
+ $array['widgetName'] = 'RunningTicket';
+ $array['picto'] = 'fas fa-ticket-alt';
+ $array['pictoColor'] = '#0D8AFF';
+
+ // Widget labels parameters
+ $array['label'] = [
+ $langs->transnoentities('NbOfOpenedTicket'),
+ $form->textwithpicto($langs->transnoentities('OldestTicket'), $langs->transnoentities('OldestTicketDescription')),
+ $form->textwithpicto($langs->transnoentities('OldestMessageTicket'), $langs->transnoentities('OldestMessageTicketDescription'))
+ ];
+
+ // Initialize variables
+ $openTickets = 0;
+ $oldestTicket = null;
+ $oldestMessageTicket = null;
+ $now = dol_now();
+
+ // Get number of open tickets, oldest ticket and oldest message ticket
+ if (!empty($tickets)) {
+ foreach ($tickets as $ticket) {
+ if (!in_array($ticket->fk_statut, [Ticket::STATUS_CANCELED, Ticket::STATUS_CLOSED])) {
+ $openTickets++;
+
+ if (empty($oldestTicket) || $ticket->datec < $oldestTicket->datec) {
+ $oldestTicket = $ticket;
+ }
+
+ $lastComm = !empty($ticket->comms) ? current($ticket->comms) : null;
+ if (!empty($lastComm) && (empty($oldestMessageTicket) || $lastComm->datec < $oldestMessageTicket->datec)) {
+ $oldestMessageTicket = $lastComm;
+ }
+ }
+ }
+ }
+
+ // Widget content parameters
+ $array['content'] = [
+ $openTickets,
+ !empty($oldestTicket) ? dol_print_date($oldestTicket->datec, 'day') : $langs->transnoentities('NoData'),
+ !empty($oldestMessageTicket) ? dol_print_date($oldestMessageTicket->datec, 'day') : $langs->transnoentities('NoData')
+ ];
+
+ $array['moreContent'] = [
+ '',
+ !empty($oldestTicket) ? ' (' . convertSecondToTime(roundUpToNextMultiple($now - $oldestTicket->datec, 60)) . ')' . $oldestTicket->getNomUrl(2, '', 0, 'paddingleft') : '',
+ !empty($oldestMessageTicket) ? ' (' . convertSecondToTime(roundUpToNextMultiple($now - $oldestMessageTicket->datec, 60)) . ')' . $tickets[$oldestMessageTicket->fk_element]->getNomUrl(2, '', 0, 'paddingleft') : ''
+ ];
+
+ return ['runningTickets' => $array];
+ }
+
+ /**
+ * Get ticket stats
+ *
+ * @param array $tickets All tickets from database for current entity order by datec DESC with comments if exists or empty array
+ * @return array Widget of ticket stats with number of ticket per user, mean answer time and number of exchange per ticket
+ */
+ function getTicketStats(array $tickets): array
+ {
+ global $langs;
+
+ // Widget title parameters
+ $array['title'] = $langs->transnoentities('TicketStatistics');
+ $array['widgetName'] = 'TicketStatistics';
+ $array['picto'] = 'fas fa-chart-pie';
+ $array['pictoColor'] = '#32E592';
+
+ // Widget labels parameters
+ $array['label'] = [
+ $langs->transnoentities('MeanAnswerTime'),
+ $langs->transnoentities('NbTicketPerUser'),
+ $langs->transnoentities('NbExchangePerTicket')
+ ];
+
+ // Initialize variables
+ $timePerTicket = [];
+ $users = [];
+ $nbTicketAssigned = 0;
+ $nbExchanges = 0;
+
+ if (!empty($tickets)) {
+ foreach ($tickets as $ticket) {
+ if (!empty($ticket->date_close)) {
+ $timePerTicket[] = $ticket->date_close - $ticket->datec;
+ }
+ if (!empty($ticket->fk_user_assign)) {
+ $nbTicketAssigned++;
+ if (!in_array($ticket->fk_user_assign, $users)) {
+ $users[] = $ticket->fk_user_assign;
+ }
+ }
+ $nbExchanges += count($ticket->comms);
+ }
+ }
+
+ // Widget content parameters
+ $array['content'] = [
+ count($timePerTicket) ? convertSecondToTime(array_sum($timePerTicket) / count($timePerTicket)) : $langs->transnoentities('NoData'),
+ count($users) ? intdiv($nbTicketAssigned, count($users)) : 0,
+ $tickets ? ceil($nbExchanges / count($tickets)) : 0
+ ];
+
+ return ['ticketStats' => $array];
+ }
+
+ /**
+ * Get ticket repartition per user with number of ticket and mean answer time
+ *
+ * @param array $tickets All tickets from database for current entity order by datec DESC with comments if exists or empty array
+ * @return array Graph of ticket repartition per user with number of ticket and mean answer time
+ */
+ function getTicketRepartitionPerUserAndMeanAnswerTime(array $tickets): array
+ {
+ global $langs;
+
+ // Graph title parameters
+ $array['title'] = $langs->transnoentities('TicketRepartitionPerUserAndMeanAnswerTime');
+ $array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
+
+ // Graph parameters
+ $array['width'] = '100%';
+ $array['height'] = 300;
+ $array['type'] = 'bar';
+ $array['showlegend'] = 1;
+ $array['dataset'] = 3;
+ $array['moreCSS'] = 'grid-2';
+
+ $array['labels'] = [
+ ['label' => $langs->transnoentities('NbOfTickets')],
+ ['label' => $langs->transnoentities('MeanAnswerTime')]
+ ];
+
+ // Initialize technical objects
+ $userTmp = new User($this->db);
+
+ // Initialize variables
+ $nbTicketPerUser = [];
+
+ if (!empty($tickets)) {
+ foreach ($tickets as $ticket) {
+ if ($ticket->fk_user_assign == null) {
+ continue;
+ }
+
+ $userTmp->fetch($ticket->fk_user_assign);
+ $userFullName = $userTmp->getFullName($langs);
+ if (!isset($nbTicketPerUser[$userFullName])) {
+ $nbTicketPerUser[$userFullName]['nbTicket'] = 0;
+ }
+ $nbTicketPerUser[$userFullName]['nbTicket']++;
+ if (!empty($ticket->date_close)) {
+ $nbTicketPerUser[$userFullName]['meanAnswerTime'][$ticket->id] = $ticket->date_close - $ticket->datec;
+ }
+ }
+
+ if (!empty($nbTicketPerUser)) {
+ uasort($nbTicketPerUser, function($a, $b) {
+ return $b['nbTicket'] - $a['nbTicket'];
+ });
+
+ foreach ($nbTicketPerUser as $userName => $ticketData) {
+ $meanAnswerTimePerUser = 0;
+ if (isset($ticketData['meanAnswerTime'])) {
+ $meanAnswerTimePerUser = array_sum($ticketData['meanAnswerTime']) / count($ticketData['meanAnswerTime']);
+ $meanAnswerTimePerUser = round($meanAnswerTimePerUser / 86400);
+ }
+ $array['data'][] = [$userName, $ticketData['nbTicket'], $meanAnswerTimePerUser];
+ }
+ }
+ }
+
+ return $array;
+ }
+
+ /**
+ * Get top society with most tickets
+ *
+ * @param array $tickets All tickets from database for current entity order by datec DESC with comments if exists or empty array
+ * @return array Graph of top society with most tickets
+ */
+ function getTopSocietyWithMostTickets(array $tickets): array
+ {
+ global $langs;
+
+ // Graph title parameters
+ $array['title'] = $langs->transnoentities('TopSocietyWithMostTickets', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
+ $array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';
+
+ // Graph parameters
+ $array['width'] = '100%';
+ $array['height'] = 300;
+ $array['type'] = 'bar';
+ $array['showlegend'] = 1;
+ $array['dataset'] = 2;
+ $array['moreCSS'] = 'grid-2';
+
+ $array['labels'] = [
+ [
+ 'label' => $langs->transnoentities('NbOfTickets'),
+ 'color' => '#A1467E'
+ ]
+ ];
+
+ // Initialize technical objects
+ $society = new Societe($this->db);
+
+ // Initialize variables
+ $nbTicketPerSociety = [];
+
+ if (!empty($tickets)) {
+ foreach ($tickets as $ticket) {
+ if ($ticket->fk_soc == null) {
+ continue;
+ }
+
+ $society->fetch($ticket->fk_soc);
+ if (!isset($nbTicketPerSociety[$society->name])) {
+ $nbTicketPerSociety[$society->name]['nbTicket'] = 0;
+ }
+ $nbTicketPerSociety[$society->name]['nbTicket']++;
+ }
+
+ if (!empty($nbTicketPerSociety)) {
+ uasort($nbTicketPerSociety, function($a, $b) {
+ return $b['nbTicket'] - $a['nbTicket'];
+ });
+
+ $nbTicketPerSociety = array_slice($nbTicketPerSociety, 0, getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5), true);
+ foreach ($nbTicketPerSociety as $socName => $ticketData) {
+ $array['data'][] = [$socName, $ticketData['nbTicket']];
+ }
+ }
+ }
+
+ return $array;
+ }
+}
diff --git a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/accidentinvestigationdocument/doc_accidentinvestigationdocument_odt.modules.php b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/accidentinvestigationdocument/doc_accidentinvestigationdocument_odt.modules.php
index 0677b21fb..82de373d5 100644
--- a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/accidentinvestigationdocument/doc_accidentinvestigationdocument_odt.modules.php
+++ b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/accidentinvestigationdocument/doc_accidentinvestigationdocument_odt.modules.php
@@ -215,17 +215,24 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$tmpArray['attendants_number'] = '0 ';
}
- $tmpArray['victim_lastname'] = dol_strtoupper($victim->lastname);
- $tmpArray['victim_firstname'] = ucfirst($victim->firstname);
$tmpArray['seniority_in_position'] = $object->seniority_in_position;
- if ($victim->dateemployment > 0) {
- $daysEmployee = dol_time_plus_duree($now, -$victim->dateemployment, 's');
- $daysEmployee = round($daysEmployee / 60 / 60 / 24);
- $tmpArray['victim_date_employment'] = dol_print_date($victim->dateemployment, 'day', 'tzuser') . ' - ' . $daysEmployee . ' ' . ($daysEmployee <= 1 ? $outputLangs->trans('Day') : $outputLangs->trans('Days'));
- } else {
- $tmpArray['victim_date_employment'] = '';
- }
+ if ($victim->id > 0) {
+ $tmpArray['victim_lastname'] = dol_strtoupper($victim->lastname);
+ $tmpArray['victim_firstname'] = ucfirst($victim->firstname);
+ if ($victim->dateemployment > 0) {
+ $daysEmployee = dol_time_plus_duree($now, -$victim->dateemployment, 's');
+ $daysEmployee = round($daysEmployee / 60 / 60 / 24);
+ $tmpArray['victim_date_employment'] = dol_print_date($victim->dateemployment, 'day', 'tzuser') . ' - ' . $daysEmployee . ' ' . ($daysEmployee <= 1 ? $outputLangs->trans('Day') : $outputLangs->trans('Days'));
+ } else {
+ $tmpArray['victim_date_employment'] = '';
+ }
+ } else {
+ $tmpArray['victim_lastname'] = '';
+ $tmpArray['victim_firstname'] = '';
+ $tmpArray['victim_date_employment'] = '';
+ }
+
$tmpArray['accident_date'] = dol_print_date($accident->accident_date, 'day');
$tmpArray['accident_hour'] = dol_print_date($accident->accident_date, 'hour');
$tmpArray['accident_day'] = dol_print_date($accident->accident_date, '%A');
diff --git a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/digiriskelementdocument/modules_digiriskelementdocument.php b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/digiriskelementdocument/modules_digiriskelementdocument.php
index 5577f3650..f56fabef8 100644
--- a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/digiriskelementdocument/modules_digiriskelementdocument.php
+++ b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/digiriskelementdocument/modules_digiriskelementdocument.php
@@ -32,8 +32,9 @@
require_once __DIR__ . '/../../../../../class/riskanalysis/risk.class.php';
require_once __DIR__ . '/../../../../../class/evaluator.class.php';
require_once __DIR__ . '/../../../../../class/accident.class.php';
+require_once __DIR__ . '/../../../../../class/digiriskresources.class.php';
-// Load saturne libraries
+// Load Saturne libraries
require_once __DIR__ . '/../../../../../../saturne/core/modules/saturne/modules_saturne.php';
/**
@@ -306,6 +307,32 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$tmpArray['photo'] = DOL_DOCUMENT_ROOT . $noPhoto;
}
+ $resources = new DigiriskResources($this->db);
+ $userTmp = new User($this->db);
+
+ // Get QRCode to public interface
+ if (isModEnabled('multicompany')) {
+ $qrCodePath = DOL_DATA_ROOT . '/digiriskdolibarr/multicompany/ticketqrcode/';
+ } else {
+ $qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . '/ticketqrcode/';
+ }
+ $QRCodeList = dol_dir_list($qrCodePath);
+ if (is_array($QRCodeList) && !empty($QRCodeList)) {
+ $QRCode = array_shift($QRCodeList);
+ $QRCodeImagePath = $QRCode['fullname'];
+ } else {
+ $QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
+ }
+
+ $allLinks = $resources->fetchDigiriskResources();
+ $responsibleResources = $allLinks['Responsible'];
+ $userTmp->fetch($responsibleResources->id[0]);
+
+ // @todo The keyword "signature" is needed because we want the image to be cropped to fit in the table
+ $tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
+ $tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
+ $tmpArray['securityResponsible'] = (!empty($userTmp) ? dol_strtoupper($userTmp->lastname) . ' ' . ucfirst($userTmp->firstname) : '');
+
if (isset($moreParam['tmparray']) && is_array($moreParam['tmparray'])) {
$moreParam['tmparray'] = array_merge($moreParam['tmparray'], $tmpArray);
} else {
diff --git a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/ticketdocument/doc_ticketdocument_odt.modules.php b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/ticketdocument/doc_ticketdocument_odt.modules.php
index 10a865cd2..559cd0a10 100644
--- a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/ticketdocument/doc_ticketdocument_odt.modules.php
+++ b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/ticketdocument/doc_ticketdocument_odt.modules.php
@@ -108,7 +108,7 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$tmpArray['type'] = $outputLangs->transnoentities('Action' . $actionComm->type_code);
$tmpArray['title'] = $actionComm->label;
$tmpArray['event_content'] = dol_htmlentitiesbr_decode($actionComm->note);
- $tmpArray['date'] = dol_print_date($actionComm->datec, 'dayreduceformat');
+ $tmpArray['date'] = dol_print_date($actionComm->datec, 'dayhourreduceformat');
$this->setTmpArrayVars($tmpArray, $listLines, $outputLangs);
}
diff --git a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/workunitdocument/doc_workunitdocument_odt.modules.php b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/workunitdocument/doc_workunitdocument_odt.modules.php
index 7b9adcc40..cb8da90f8 100644
--- a/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/workunitdocument/doc_workunitdocument_odt.modules.php
+++ b/core/modules/digiriskdolibarr/digiriskdolibarrdocuments/workunitdocument/doc_workunitdocument_odt.modules.php
@@ -28,7 +28,6 @@
// Load DigiriskDolibarr libraries
require_once __DIR__ . '/../digiriskelementdocument/modules_digiriskelementdocument.php';
-require_once __DIR__ . '/../../../../../class/digiriskresources.class.php';
/**
* Class to build documents using ODF templates generator
@@ -65,52 +64,4 @@ public function info(Translate $langs): string
{
return parent::info($langs);
}
-
- /**
- * Function to build a document on disk
- *
- * @param SaturneDocuments $objectDocument Object source to build document
- * @param Translate $outputLangs Lang object to use for output
- * @param string $srcTemplatePath Full path of source filename for generator using a template file
- * @param int $hideDetails Do not show line details
- * @param int $hideDesc Do not show desc
- * @param int $hideRef Do not show ref
- * @param array $moreParam More param (Object/user/etc)
- * @return int 1 if OK, <=0 if KO
- * @throws Exception
- */
- public function write_file(SaturneDocuments $objectDocument, Translate $outputLangs, string $srcTemplatePath, int $hideDetails = 0, int $hideDesc = 0, int $hideRef = 0, array $moreParam): int
- {
- global $conf;
-
- $resources = new DigiriskResources($this->db);
- $userTmp = new User($this->db);
-
- // Get QRCode to public interface
- if (isModEnabled('multicompany')) {
- $qrCodePath = DOL_DATA_ROOT . '/digiriskdolibarr/multicompany/ticketqrcode/';
- } else {
- $qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . '/ticketqrcode/';
- }
- $QRCodeList = dol_dir_list($qrCodePath);
- if (is_array($QRCodeList) && !empty($QRCodeList)) {
- $QRCode = array_shift($QRCodeList);
- $QRCodeImagePath = $QRCode['fullname'];
- } else {
- $QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
- }
-
- $allLinks = $resources->fetchDigiriskResources();
- $responsibleResources = $allLinks['Responsible'];
- $userTmp->fetch($responsibleResources->id[0]);
-
- // @todo The keyword "signature" is needed because we want the image to be cropped to fit in the table
- $tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
- $tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
- $tmpArray['securityResponsible'] = (!empty($userTmp) ? dol_strtoupper($userTmp->lastname) . ' ' . ucfirst($userTmp->firstname) : '');
-
- $moreParam['tmparray'] = $tmpArray;
-
- return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam);
- }
}
diff --git a/core/modules/modDigiriskDolibarr.class.php b/core/modules/modDigiriskDolibarr.class.php
index ede0ae826..367154523 100644
--- a/core/modules/modDigiriskDolibarr.class.php
+++ b/core/modules/modDigiriskDolibarr.class.php
@@ -364,7 +364,7 @@ public function __construct($db)
$this->errors[] = $langs->trans('activateModuleDependNotSatisfied', 'Digirisk', 'Saturne');
}
- $langs->load("digiriskdolibarr@digiriskdolibarr");
+ $langs->loadLangs(['digiriskdolibarr@digiriskdolibarr', 'categories']);
// Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
@@ -380,7 +380,7 @@ public function __construct($db)
$this->descriptionlong = "Digirisk";
$this->editor_name = 'Evarisk';
$this->editor_url = 'https://evarisk.com';
- $this->version = '10.2.1';
+ $this->version = '20.0.0';
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
$this->picto = 'digiriskdolibarr_color@digiriskdolibarr';
@@ -478,7 +478,7 @@ public function __construct($db)
$this->hidden = false;
$this->depends = ['modSaturne', 'modECM', 'modProjet', 'modSociete', 'modTicket', 'modCategorie', 'modFckeditor', 'modApi', 'modExport', 'modImport'];
- $this->requiredby = [];
+ $this->requiredby = ['modDigiBoard'];
$this->conflictwith = [];
$this->langfiles = ["digiriskdolibarr@digiriskdolibarr"];
$this->phpmin = [7, 4]; // Minimum version of PHP required by module
@@ -755,7 +755,7 @@ public function __construct($db)
$i++ => ['DIGIRISKDOLIBARR_TICKET_PARENT_CATEGORY', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TICKET_MAIN_CATEGORY', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TICKET_PARENT_CATEGORY_LABEL', 'chaine', $langs->trans('Registre'), '', 0, 'current'],
- $i++ => ['DIGIRISKDOLIBARR_TICKET_CHILD_CATEGORY_LABEL', 'chaine', $langs->trans('Pertinence'), '', 0, 'current'],
+ $i++ => ['DIGIRISKDOLIBARR_TICKET_CHILD_CATEGORY_LABEL', 'chaine', $langs->trans('Rubriques'), '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TICKET_PROJECT', 'integer', 0, '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_TICKET_SUCCESS_MESSAGE', 'chaine', $langs->trans('YouMustNotifyYourHierarchy'), '', 0, 'current'],
$i++ => ['DIGIRISKDOLIBARR_SHOW_MULTI_ENTITY_SELECTOR_ON_TICKET_PUBLIC_INTERFACE', 'integer', 0, '', 0, 'current'],
@@ -901,6 +901,7 @@ public function __construct($db)
$this->tabs[] = ['data' => 'thirdparty:+schedules:'. $pictoDigirisk .$langs->trans('Schedules').':digiriskdolibarr@digiriskdolibarr:1:/custom/saturne/view/saturne_schedules.php?id=__ID__&element_type=societe&module_name=societe']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'user:+participation:'. $pictoDigirisk .$langs->trans('GP/UTParticipation').':digiriskdolibarr@digiriskdolibarr:1:/custom/digiriskdolibarr/view/digiriskelement/digiriskelement_evaluator.php?fromid=__ID__']; // To add a new tab identified by code tabname1
$this->tabs[] = ['data' => 'user:+accidents:'. $pictoDigirisk .$langs->trans('Accidents').':digiriskdolibarr@digiriskdolibarr:1:/custom/digiriskdolibarr/view/accident/accident_list.php?fromiduser=__ID__']; // To add a new tab identified by code tabname1
+ $this->tabs[] = ['data' => 'categories_ticket:+config:' . $pictoDigirisk .$langs->trans('WHSRegister') . ':digiriskdolibarr@digiriskdolibarr:1:/custom/digiriskdolibarr/view/ticket/category_config.php?id=__ID__&type=ticket'];
// Dictionaries
$this->dictionaries = [
@@ -1398,7 +1399,7 @@ public function __construct($db)
'prefix' => ' ',
'mainmenu' => 'digiriskdolibarr',
'leftmenu' => 'digiriskstandard',
- 'url' => '/digiriskdolibarr/view/digiriskstandard/digiriskstandard_card.php',
+ 'url' => '/digiriskdolibarr/view/digiriskstandard/digiriskstandard_card.php?type=risk',
'langs' => 'digiriskdolibarr@digiriskdolibarr', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position' => 100 + $r,
'enabled' => '$conf->digiriskdolibarr->enabled', // Define condition to show or hide menu entry. Use '$conf->digiriskdolibarr->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
@@ -1459,7 +1460,7 @@ public function __construct($db)
'prefix' => ' ',
'mainmenu' => 'digiriskdolibarr',
'leftmenu' => 'digiriskstandard_riskenvironmental',
- 'url' => '/digiriskdolibarr/view/digiriskstandard/digiriskstandard_card.php',
+ 'url' => '/digiriskdolibarr/view/digiriskstandard/digiriskstandard_card.php?type=riskenvironmental',
'langs' => 'digiriskdolibarr@digiriskdolibarr',
'position' => 100 + $r,
'enabled' => '$conf->digiriskdolibarr->enabled',
@@ -1693,7 +1694,7 @@ public function __construct($db)
'prefix' => $pictoDigirisk,
'mainmenu' => 'ticket',
'leftmenu' => 'ticketstats',
- 'url' => '/digiriskdolibarr/view/ticket/ticketstats.php',
+ 'url' => '/digiriskdolibarr/view/ticket/ticket_management_dashboard.php',
'langs' => 'digiriskdolibarr@digiriskdolibarr', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position' => 100 + $r,
'enabled' => '$conf->digiriskdolibarr->enabled && $conf->ticket->enabled', // Define condition to show or hide menu entry. Use '$conf->digiriskdolibarr->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
@@ -1803,7 +1804,7 @@ public function __construct($db)
$this->export_entities_array[$r] = [];
$keyforclass = ucfirst($key);
- $keyforclassfile = '/' . $this->rights_class . '/class/' . $objectMetaData['classPath'] . '/' . $key . '.class.php';
+ $keyforclassfile = '/' . $this->rights_class . '/class/' . (isset($objectMetaData['classPath']) ? $objectMetaData['classPath'] . '/' : '') . $key . '.class.php';
$keyforelement = $key;
$keyforalias = 't';
@@ -2106,6 +2107,28 @@ public function init($options = '')
dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_THIRDPARTY_SET', 3, 'integer', 0, '', $conf->entity);
}
+ if (getDolGlobalInt('DIGIRISKDOLIBARR_THIRDPARTY_SET') == 3) {
+ $poisonCenters = [
+ 'ANGERS' => ['phone' => '02 41 48 21 21'],
+ 'BORDEAUX' => ['phone' => '05 56 96 40 80'],
+ 'LILLE' => ['phone' => '08 00 59 59 59'],
+ 'LYON' => ['phone' => '04 72 11 69 11'],
+ 'MARSEILLE' => ['phone' => '04 91 75 25 25'],
+ 'NANCY' => ['phone' => '03 83 22 50 50'],
+ 'PARIS' => ['phone' => '01 40 05 48 48'],
+ 'TOULOUSE' => ['phone' => '05 61 77 74 47']
+ ];
+
+ foreach ($poisonCenters as $city => $poisonCenter) {
+ $societe->name = $langs->trans('PoisonControlCenter') . ' ' . $city . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->client = 0;
+ $societe->phone = $poisonCenter['phone'];
+ $societe->url = '';
+ $poisonControlCenterID = $societe->create($user);
+ }
+
+ dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_THIRDPARTY_SET', 4, 'integer', 0, '', $conf->entity);
+ }
if (getDolGlobalInt('DIGIRISKDOLIBARR_CONTACTS_SET') == 0) {
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
@@ -2136,118 +2159,105 @@ public function init($options = '')
dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_CONTACTS_SET', 1, 'integer', 0, '', $conf->entity);
}
- if ( $conf->global->DIGIRISKDOLIBARR_THIRDPARTY_UPDATED == 0 ) {
- require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
- require_once __DIR__ . '/../../class/digiriskresources.class.php';
-
- $societe = new Societe($this->db);
- $resources = new DigiriskResources($this->db);
- $labour_inspectorID = $resources->fetchDigiriskResource('LabourInspectorSociety');
- $societe->fetch($labour_inspectorID);
- $societe->name = $langs->trans('LabourInspectorName') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $policeID = $resources->fetchDigiriskResource('Police');
- $societe->fetch($policeID);
- $societe->name = $langs->trans('Police') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $samuID = $resources->fetchDigiriskResource('SAMU');
- $societe->fetch($samuID);
- $societe->name = $langs->trans('SAMU') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $pompiersID = $resources->fetchDigiriskResource('Pompiers');
- $societe->fetch($pompiersID);
- $societe->name = $langs->trans('Pompiers') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $emergencyID = $resources->fetchDigiriskResource('AllEmergencies');
- $societe->fetch($emergencyID);
- $societe->name = $langs->trans('AllEmergencies') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $rights_defenderID = $resources->fetchDigiriskResource('RightsDefender');
- $societe->fetch($rights_defenderID);
- $societe->name = $langs->transnoentities('RightsDefender') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- $poison_control_centerID = $resources->fetchDigiriskResource('PoisonControlCenter');
- $societe->fetch($poison_control_centerID);
- $societe->name = $langs->trans('PoisonControlCenter') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
- $societe->update(0, $user);
-
- dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_THIRDPARTY_UPDATED', 1, 'integer', 0, '', $conf->entity);
- }
+ if (getDolGlobalInt('DIGIRISKDOLIBARR_THIRDPARTY_UPDATED') == 0) {
+ $labourInspectorID = $resources->fetchDigiriskResource('LabourInspectorSociety');
+ $societe->fetch($labourInspectorID);
+ $societe->name = $langs->trans('LabourInspectorName') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $policeID = $resources->fetchDigiriskResource('Police');
+ $societe->fetch($policeID);
+ $societe->name = $langs->trans('Police') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $samuID = $resources->fetchDigiriskResource('SAMU');
+ $societe->fetch($samuID);
+ $societe->name = $langs->trans('SAMU') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $pompiersID = $resources->fetchDigiriskResource('Pompiers');
+ $societe->fetch($pompiersID);
+ $societe->name = $langs->trans('Pompiers') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $emergencyID = $resources->fetchDigiriskResource('AllEmergencies');
+ $societe->fetch($emergencyID);
+ $societe->name = $langs->trans('AllEmergencies') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $rightsDefenderID = $resources->fetchDigiriskResource('RightsDefender');
+ $societe->fetch($rightsDefenderID);
+ $societe->name = $langs->transnoentities('RightsDefender') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ $poisonControlCenterID = $resources->fetchDigiriskResource('PoisonControlCenter');
+ $societe->fetch($poisonControlCenterID);
+ $societe->name = $langs->trans('PoisonControlCenter') . ' - ' . $conf->global->MAIN_INFO_SOCIETE_NOM;
+ $societe->update(0, $user);
+
+ dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_THIRDPARTY_UPDATED', 1, 'integer', 0, '', $conf->entity);
+ }
+ if (getDolGlobalInt('DIGIRISKDOLIBARR_THIRDPARTY_UPDATED') == 1) {
+ $rightsDefenderID = $resources->fetchDigiriskResource('RightsDefender');
+ $societe->fetch($rightsDefenderID);
+ $societe->phone = '09 69 39 00 00';
+ $societe->url = 'https://www.defenseurdesdroits.fr/';
+ $societe->update(0, $user);
+
+ dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_THIRDPARTY_UPDATED', 2, 'integer', 0, '', $conf->entity);
+ }
- // Create extrafields during init
- include_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
- require_once __DIR__ . '/../../lib/digiriskdolibarr_function.lib.php';
-
- $extra_fields = new ExtraFields($this->db);
-
- $extra_fields->update('fk_risk', $langs->transnoentities("RiskLinked"), 'sellist', '', 'projet_task', 0, 0, 1010, 'a:1:{s:7:"options";a:1:{s:50:"digiriskdolibarr_risk:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->addExtraField('fk_risk', $langs->transnoentities("RiskLinked"), 'sellist', 1010, '', 'projet_task', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:50:"digiriskdolibarr_risk:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->update('fk_preventionplan', $langs->transnoentities("PreventionPlanLinked"), 'sellist', '', 'projet_task', 0, 0, 1020, 'a:1:{s:7:"options";a:1:{s:60:"digiriskdolibarr_preventionplan:ref:rowid::entity = $ENTITY$";N;}}', '', '', '', 1);
- $extra_fields->addExtraField('fk_preventionplan', $langs->transnoentities("PreventionPlanLinked"), 'sellist', 1020, '', 'projet_task', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:60:"digiriskdolibarr_preventionplan:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->update('fk_firepermit', $langs->transnoentities("FirePermitLinked"), 'sellist', '', 'projet_task', 0, 0, 1030, 'a:1:{s:7:"options";a:1:{s:56:"digiriskdolibarr_firepermit:ref:rowid::entity = $ENTITY$";N;}}', '', '', '', 1);
- $extra_fields->addExtraField('fk_firepermit', $langs->transnoentities("FirePermitLinked"), 'sellist', 1030, '', 'projet_task', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:56:"digiriskdolibarr_firepermit:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->update('fk_accident', $langs->transnoentities("AccidentLinked"), 'sellist', '', 'projet_task', 0, 0, 1040, 'a:1:{s:7:"options";a:1:{s:54:"digiriskdolibarr_accident:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->addExtraField('fk_accident', $langs->transnoentities("AccidentLinked"), 'sellist', 1040, '', 'projet_task', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:54:"digiriskdolibarr_accident:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->update('fk_accidentinvestigation', $langs->transnoentities("AccidentInvestigationLinked"), 'sellist', '', 'projet_task', 0, 0, 1050, 'a:1:{s:7:"options";a:1:{s:68:"digiriskdolibarr_accident_investigation:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
- $extra_fields->addExtraField('fk_accidentinvestigation', $langs->transnoentities("AccidentInvestigationLinked"), 'sellist', 1050, '', 'projet_task', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:68:"digiriskdolibarr_accident_investigation:ref:rowid::entity = $ENTITY$";N;}}', '', '', 1);
-
- if (!$conf->global->DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS_BACKWARD_COMPATIBILITY && (dolibarr_get_const($this->db, 'DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS', 0) || dolibarr_get_const($this->db, 'DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS', $conf->entity))) {
- if ($conf->multicompany->enabled) {
- $current_entity = $conf->entity;
- $object = new ActionsMulticompany($this->db);
-
- $entities = $object->getEntitiesList(false, false, true, true);
- foreach ($entities as $sub_entity => $entity_name) {
- $conf->setEntityValues($this->db, $sub_entity);
-
- extrafield_soft_delete('digiriskdolibarr_ticket_firstname', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_lastname', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_phone', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_service', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_location', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_date', 'ticket', $extra_fields);
- }
- $conf->setEntityValues($this->db, $current_entity);
- } else {
- extrafield_soft_delete('digiriskdolibarr_ticket_firstname', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_lastname', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_phone', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_service', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_location', 'ticket', $extra_fields);
- extrafield_soft_delete('digiriskdolibarr_ticket_date', 'ticket', $extra_fields);
- }
+ // Create extrafields during init
+ require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
- $extra_fields->addExtraField('digiriskdolibarr_ticket_lastname', $langs->transnoentities("LastName"), 'varchar', 2000, 255, 'ticket', 0, 0, '', '', 1, '', 1, '', '', 0);
- $extra_fields->addExtraField('digiriskdolibarr_ticket_firstname', $langs->transnoentities("FirstName"), 'varchar', 2100, 255, 'ticket', 0, 0, '', '', 1, '', 1, '', '', 0);
- $extra_fields->addExtraField('digiriskdolibarr_ticket_phone', $langs->transnoentities("Phone"), 'phone', 2200, '', 'ticket', 0, 0, '', '', 1, '', 1, '', '', 0);
- $extra_fields->addExtraField('digiriskdolibarr_ticket_service', $langs->transnoentities("GP/UT"), 'sellist', 2300, '255', 'ticket', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:61:"digiriskdolibarr_digiriskelement:ref:rowid::entity = $ENTITY$";N;}}', 1, '', 4, '','',0);
- $extra_fields->addExtraField('digiriskdolibarr_ticket_location', $langs->transnoentities("Location"), 'varchar', 2400, 255, 'ticket', 0, 0, '', '', 1, '', 1, '', '', 0);
- $extra_fields->addExtraField('digiriskdolibarr_ticket_date', $langs->transnoentities("Date"), 'datetime', 2500, '', 'ticket', 0, 0, '', '', 1, '', 1, '', '', 0);
- dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS', 1, 'integer', 0, '', 0);
- dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_TICKET_EXTRAFIELDS_BACKWARD_COMPATIBILITY', 1, 'integer', 0, '', 0);
- }
+ $extraFields = new ExtraFields($this->db);
- //Used for data import from Digirisk Wordpress
- $extra_fields->update('wp_digi_id', $langs->trans("WPDigiID"), 'int', 100, 'digiriskdolibarr_digiriskelement', 0, 0, 1020, '', '', '', 0);
- $extra_fields->addExtraField('wp_digi_id', $langs->trans("WPDigiID"), 'int', 100, '', 'digiriskdolibarr_digiriskelement', 0, 0, '', '', '', '', 0);
- $extra_fields->addExtraField('entity', $langs->trans("Entity"), 'int', 100, '', 'digiriskdolibarr_digiriskelement', 0, 0, '', '', '', '', 0);
+ $commonExtraFieldsValue = [
+ 'alwayseditable' => 1, 'list' => 1, 'help' => '', 'entity' => 0, 'langfile' => 'digiriskdolibarr@digiriskdolibarr', 'enabled' => "isModEnabled('digiriskdolibarr') && isModEnabled('project')", 'moreparams' => ['css' => 'minwidth100 maxwidth300']
+ ];
- $extra_fields->addExtraField('professional_qualification', $langs->trans("ProfessionalQualification"), 'varchar', 990, 255, 'user', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:0:"";N;}}', 1, '', 1, '', '', 0, 'digiriskdolibarr');
- $extra_fields->addExtraField('contract_type', $langs->trans("ContractType"), 'select', 1000, '', 'user', 0, 0, '', 'a:1:{s:7:"options";a:5:{i:1;s:3:"CDI";i:2;s:3:"CDD";i:3;s:18:"Apprentice/Student";i:4;s:7:"Interim";i:5;s:5:"Other";}}', 1, '', 1, '', '', 0, 'digiriskdolibarr');
+ $extraFieldsArrays = [
+ 'fk_risk' => ['Label' => 'Risk', 'type' => 'link', 'elementtype' => ['projet_task'], 'position' => $this->numero . 10, 'params' => ['Risk:digiriskdolibarr/class/riskanalysis/risk.class.php:1:(entity:IN:__SHARED_ENTITIES__)' => NULL], ],
+ 'fk_preventionplan' => ['Label' => 'PreventionPlan', 'type' => 'link', 'elementtype' => ['projet_task'], 'position' => $this->numero . 20, 'params' => ['PreventionPlan:digiriskdolibarr/class/preventionplan.class.php:1:(entity:IN:__SHARED_ENTITIES__)' => NULL], ],
+ 'fk_firepermit' => ['Label' => 'FirePermit', 'type' => 'link', 'elementtype' => ['projet_task'], 'position' => $this->numero . 30, 'params' => ['FirePermit:digiriskdolibarr/class/firepermit.class.php:1:(entity:IN:__SHARED_ENTITIES__)' => NULL], ],
+ 'fk_accident' => ['Label' => 'Accident', 'type' => 'link', 'elementtype' => ['projet_task'], 'position' => $this->numero . 40, 'params' => ['Accident:digiriskdolibarr/class/accident.class.php:1:(entity:IN:__SHARED_ENTITIES__)' => NULL], ],
+ 'fk_accidentinvestigation' => ['Label' => 'AccidentInvestigation', 'type' => 'link', 'elementtype' => ['projet_task'], 'position' => $this->numero . 50, 'params' => ['AccidentInvestigation:digiriskdolibarr/class/accidentinvestigation.class.php:1:(entity:IN:__SHARED_ENTITIES__)' => NULL]],
- if ($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2 == 0) {
- dolibarr_set_const($this->db, 'MAIN_EXTRAFIELDS_USE_SELECT2', 1, 'integer', 0, '', $conf->entity);
- }
+ 'wp_digi_id' => ['Label' => 'WPDigiID', 'type' => 'int', 'length' => 100, 'elementtype' => ['digiriskdolibarr_digiriskelement'], 'position' => $this->numero . 10, 'list' => 0, 'enabled' => "isModEnabled('digiriskdolibarr')"],
+ 'entity' => ['Label' => 'Entity', 'type' => 'int', 'length' => 100, 'elementtype' => ['digiriskdolibarr_digiriskelement'], 'position' => $this->numero . 20, 'list' => 0, 'enabled' => "isModEnabled('digiriskdolibarr')"],
- if ($conf->global->CATEGORIE_RECURSIV_ADD == 0) {
- dolibarr_set_const($this->db, 'CATEGORIE_RECURSIV_ADD', 1, 'integer', 0, '', $conf->entity);
- }
+ 'professional_qualification' => ['Label' => 'ProfessionalQualification', 'type' => 'varchar', 'length' => 255, 'elementtype' => ['user'], 'position' => $this->numero . 10, 'enabled' => "isModEnabled('digiriskdolibarr') && isModEnabled('user')"],
+ 'contract_type' => ['Label' => 'ContractType', 'type' => 'select', 'elementtype' => ['user'], 'position' => $this->numero . 20, 'params' => [1 => 'CDI', 2 => 'CDD', 3 => 'Apprentice/Student', 4 => 'Interim', 5 => 'Other'], 'enabled' => "isModEnabled('digiriskdolibarr') && isModEnabled('user')"]
+ ];
+
+ if (getDolGlobalInt('DIGIRISKDOLIBARR_EXTRAFIELDS_BACKWARD_COMPATIBILITY') == 0) {
+ if (isModEnabled('multicompany')) {
+ require_once __DIR__ . '/../../../multicompany/class/actions_multicompany.class.php';
+
+ $currentEntity = $conf->entity;
+ $actionsMulticompany = new ActionsMulticompany($this->db);
+ $entities = $actionsMulticompany->getEntitiesList(false, false, true, true);
+ foreach ($entities as $subEntity => $entity_name) {
+ $conf->setEntityValues($this->db, $subEntity);
+ foreach ($extraFieldsArrays as $key => $extraField) {
+ foreach ($extraField['elementtype'] as $extraFieldElementType) {
+ $extraFields->delete($key, $extraFieldElementType);
+ }
+ }
+ $conf->setEntityValues($this->db, $currentEntity);
+ }
+ } else {
+ foreach ($extraFieldsArrays as $key => $extraField) {
+ foreach ($extraField['elementtype'] as $extraFieldElementType) {
+ $extraFields->delete($key, $extraFieldElementType);
+ }
+ }
+ }
+
+ dolibarr_set_const($this->db, 'DIGIRISKDOLIBARR_EXTRAFIELDS_BACKWARD_COMPATIBILITY', 1, 'integer', 0, '', $conf->entity);
+ }
+
+ saturne_manage_extrafields($extraFieldsArrays, $commonExtraFieldsValue);
//DigiriskElement favorite medias backward compatibility
if ($conf->global->DIGIRISKDOLIBARR_DIGIRISKELEMENT_MEDIAS_BACKWARD_COMPATIBILITY == 0) {
diff --git a/core/tpl/riskanalysis/risk/digiriskdolibarr_inheritedrisklist_view.tpl.php b/core/tpl/riskanalysis/risk/digiriskdolibarr_inheritedrisklist_view.tpl.php
index a4dc6c16d..92527c277 100644
--- a/core/tpl/riskanalysis/risk/digiriskdolibarr_inheritedrisklist_view.tpl.php
+++ b/core/tpl/riskanalysis/risk/digiriskdolibarr_inheritedrisklist_view.tpl.php
@@ -328,26 +328,6 @@
$arrayfields = dol_sort_array($arrayfields, 'position');
- $menuConf = 'MAIN_SELECTEDFIELDS_' . $varpage;
-
- if (dol_strlen($user->conf->$menuConf) < 1 || preg_match('/t./', $user->conf->$menuConf)) {
- $user->conf->$menuConf = 'r.fk_element,r.ref,r.category,evaluation.cotation,';
- }
-
- if ( ! preg_match('/r.description/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = $user->conf->$menuConf . 'r.description,';
- } elseif ( ! $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = preg_replace('/r.description,/', '', $user->conf->$menuConf);
- $arrayfields['r.description']['enabled'] = 0;
- }
-
- if ( ! preg_match('/evaluation.has_tasks/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf .= $user->conf->$menuConf . 'evaluation.has_tasks,';
- } elseif ( ! $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf = preg_replace('/evaluation.has_tasks,/', '', $user->conf->$menuConf);
- $arrayfields['evaluation.has_tasks']['enabled'] = 0;
- }
-
$selectedfields = $form->multiSelectArrayWithCheckbox('inherited_risklist_selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
diff --git a/core/tpl/riskanalysis/risk/digiriskdolibarr_risk_actions.tpl.php b/core/tpl/riskanalysis/risk/digiriskdolibarr_risk_actions.tpl.php
index 99d1e91df..fb75ee434 100644
--- a/core/tpl/riskanalysis/risk/digiriskdolibarr_risk_actions.tpl.php
+++ b/core/tpl/riskanalysis/risk/digiriskdolibarr_risk_actions.tpl.php
@@ -92,12 +92,8 @@
if ($result2 > 0) {
$tasktitle = $data['task'];
- $dateStart = $data['dateStart'];
- $hourStart = $data['hourStart'];
- $minStart = $data['minStart'];
- $dateEnd = $data['dateEnd'];
- $hourEnd = $data['hourEnd'];
- $minEnd = $data['minEnd'];
+ $dateStart = dol_stringtotime($data['dateStart']);
+ $dateEnd = dol_stringtotime($data['dateEnd']);
$budget = $data['budget'];
if ( ! empty($tasktitle) && $tasktitle !== 'undefined') {
$extrafields->fetch_name_optionals_label($task->table_element);
@@ -107,16 +103,12 @@
$task->fk_project = $riskType == 'risk' ? $conf->global->DIGIRISKDOLIBARR_DU_PROJECT : $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT;
$task->date_c = dol_now();
if (!empty($dateStart)) {
- $task->date_start = strtotime(preg_replace('/\//', '-', $dateStart));
- $task->date_start = dol_time_plus_duree($task->date_start, $hourStart, 'h');
- $task->date_start = dol_time_plus_duree($task->date_start, $minStart, 'i');
+ $task->date_start = $dateStart;
} else {
$task->date_start = dol_now('tzuser');
}
if (!empty($dateEnd)) {
- $task->date_end = strtotime(preg_replace('/\//', '-', $dateEnd));
- $task->date_end = dol_time_plus_duree($task->date_end, $hourEnd, 'h');
- $task->date_end = dol_time_plus_duree($task->date_end, $minEnd, 'i');
+ $task->date_end = $dateEnd;
}
$task->budget_amount = $budget;
$task->array_options['options_fk_risk'] = $risk->id;
@@ -355,18 +347,7 @@
}
$entity = ($conf->entity > 1) ? '/' . $conf->entity : '';
- $result = $evaluation->update($user);
-
- if ($result > 0) {
- // Update evaluation OK
- $urltogo = str_replace('__ID__', $result, $backtopage);
- $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $id, $urltogo); // New method to autoselect project after a New on another form object creation
- header("Location: " . $urltogo);
- } else {
- // Update evaluation KO
- if ( ! empty($evaluation->errors)) setEventMessages(null, $evaluation->errors, 'errors');
- else setEventMessages($evaluation->error, null, 'errors');
- }
+ $evaluation->update($user);
}
if ( ! $error && $action == "deleteEvaluation" && $permissiontodelete) {
@@ -400,12 +381,8 @@
$riskID = $data['riskToAssign'];
$tasktitle = $data['tasktitle'];
- $dateStart = $data['dateStart'];
- $hourStart = $data['hourStart'];
- $minStart = $data['minStart'];
- $dateEnd = $data['dateEnd'];
- $hourEnd = $data['hourEnd'];
- $minEnd = $data['minEnd'];
+ $dateStart = dol_stringtotime($data['dateStart']);
+ $dateEnd = dol_stringtotime($data['dateEnd']);
$budget = $data['budget'];
$extrafields->fetch_name_optionals_label($task->table_element);
@@ -415,16 +392,12 @@
$task->fk_project = $riskType == 'risk' ? $conf->global->DIGIRISKDOLIBARR_DU_PROJECT : $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT;
$task->datec = dol_now();
if (!empty($dateStart)) {
- $task->date_start = strtotime(preg_replace('/\//', '-', $dateStart));
- $task->date_start = dol_time_plus_duree($task->date_start, $hourStart, 'h');
- $task->date_start = dol_time_plus_duree($task->date_start, $minStart, 'i');
+ $task->date_start = $dateStart;
} else {
$task->date_start = dol_now('tzuser');
}
if (!empty($dateEnd)) {
- $task->date_end = strtotime(preg_replace('/\//', '-', $dateEnd));
- $task->date_end = dol_time_plus_duree($task->date_end, $hourEnd, 'h');
- $task->date_end = dol_time_plus_duree($task->date_end, $minEnd, 'i');
+ $task->date_end = $dateEnd;
}
$task->budget_amount = $budget;
$task->fk_task_parent = 0;
@@ -451,12 +424,8 @@
$riskAssessmentTaskID = $data['riskAssessmentTaskID'];
$tasktitle = $data['tasktitle'];
- $dateStart = $data['dateStart'];
- $hourStart = $data['hourStart'];
- $minStart = $data['minStart'];
- $dateEnd = $data['dateEnd'];
- $hourEnd = $data['hourEnd'];
- $minEnd = $data['minEnd'];
+ $dateStart = dol_stringtotime($data['dateStart']);
+ $dateEnd = dol_stringtotime($data['dateEnd']);
$budget = $data['budget'];
$taskProgress = $data['taskProgress'];
@@ -465,18 +434,14 @@
$task->label = $tasktitle;
if (!empty($dateStart)) {
- $task->date_start = strtotime(preg_replace('/\//', '-', $dateStart));
- $task->date_start = dol_time_plus_duree($task->date_start, $hourStart, 'h');
- $task->date_start = dol_time_plus_duree($task->date_start, $minStart, 'i');
+ $task->date_start = $dateStart;
} else {
$task->date_start = dol_now('tzuser');
}
if (!empty($dateEnd)) {
- $task->date_end = strtotime(preg_replace('/\//', '-', $dateEnd));
- $task->date_end = dol_time_plus_duree($task->date_end, $hourEnd, 'h');
- $task->date_end = dol_time_plus_duree($task->date_end, $minEnd, 'i');
+ $task->date_end = $dateEnd;
}
- $task->budget_amount = is_int($budget) ? $budget : ($task->budget ?? 0);
+ $task->budget_amount = is_numeric($budget) ? $budget : ($task->budget ?? 0);
if ($taskProgress == 1) {
$task->progress = 100;
diff --git a/core/tpl/riskanalysis/risk/digiriskdolibarr_risklist_view.tpl.php b/core/tpl/riskanalysis/risk/digiriskdolibarr_risklist_view.tpl.php
index 11a22b516..da138fc58 100644
--- a/core/tpl/riskanalysis/risk/digiriskdolibarr_risklist_view.tpl.php
+++ b/core/tpl/riskanalysis/risk/digiriskdolibarr_risklist_view.tpl.php
@@ -459,9 +459,10 @@
$sql .= " FROM " . MAIN_DB_PREFIX . $evaluation->table_element . " as evaluation";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $risk->table_element . " as r on (evaluation.fk_risk = r.rowid)";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $digiriskelement->table_element . " as e on (r.fk_element = e.rowid)";
- if (is_array($extrafields->attributes[$evaluation->table_element]['label']) && count($extrafields->attributes[$evaluation->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $evaluation->table_element . "_extrafields as ef on (evaluation.rowid = ef.fk_object)";
+ if (isset($extrafields->attributes[$evaluation->table_element]) &&
+ is_array($extrafields->attributes[$evaluation->table_element]['label']) && count($extrafields->attributes[$evaluation->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $evaluation->table_element . "_extrafields as ef on (evaluation.rowid = ef.fk_object)";
if ($sortfield == 'evaluation.has_tasks') $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet_task_extrafields as taskextrafields ON (taskextrafields.fk_risk = r.rowid)';
- if (!empty($conf->categorie->enabled) && getDolGlobalInt('DIGIRISKDOLIBARR_CATEGORY_ON_RISK') > 0) $sql .= Categorie::getFilterJoinQuery('risk', "r.rowid");
+ if (!empty($conf->categorie->enabled) && getDolGlobalInt('DIGIRISKDOLIBARR_CATEGORY_ON_RISK') > 0) $sql .= Categorie::getFilterJoinQuery('risk', "r.rowid");
if ($evaluation->ismultientitymanaged == 1) $sql .= " WHERE evaluation.entity IN (" . getEntity($evaluation->element) . ")";
else $sql .= " WHERE 1 = 1";
$sql .= " AND evaluation.status = 1";
@@ -593,441 +594,240 @@
} else {
$newcardbutton = '
';
} ?>
-
- global->DIGIRISKDOLIBARR_TASK_MANAGEMENT == 0 && $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION == 0 && $conf->global->DIGIRISKDOLIBARR_MULTIPLE_RISKASSESSMENT_METHOD == 0 ) : ?>
-
-
-
-
-
-
-
-
-
-
-
-
trans('PhotoWellSaved') ?>
-
-
-
-
-
-
-
-
trans('PhotoNotSaved') ?>
-
-
-
-
-
-
-
trans('Risk'); ?>*
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
trans('RiskAssessment'); ?>
-
-
-
-
-
-
trans('RiskAssessment'); ?>*
-
- '0-47', 48 => '48-50', 51 => '51-80', 100 => '81-100');
- if ( ! empty($defaultCotation)) :
- foreach ($defaultCotation as $cotation => $shownCotation) :
- $evaluation->cotation = $cotation; ?>
-
-
-
-
-
- type . '_variable'];
- ?>
-
-
-
-
trans('SelectEvaluation') ?>*
-
-
-
-
-
-
trans('CalculatedEvaluation'); ?>*
-
-
-
-
-
-
- global->DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE) : ?>
-
- trans('Date'); ?>
- selectDate('', 'RiskAssessmentDate0', 0, 0, 0, '', 1, 1); ?>
-
-
- categorie->enabled) && getDolGlobalInt('DIGIRISKDOLIBARR_CATEGORY_ON_RISK') > 0) {
- print '
'.$langs->trans("Categories") . ' ';
- $categoryArborescence = $form->select_all_categories('risk', '', 'parent', 64, 0, 1);
- print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, GETPOST('categories', 'array'), '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400');
- print '
';
- print "
";
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
trans('PhotoWellSaved') ?>
-
-
-
-
-
-
-
-
trans('PhotoNotSaved') ?>
-
-
-
-
-
-
-
trans('Risk'); ?>*
-
-
-
-
-
-
-
-
-
-
-
-
-
- global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) : ?>
-
- trans('Description'); ?>
- ' . ('') . '' . "\n"; ?>
-
-
-
- categorie->enabled) && getDolGlobalInt('DIGIRISKDOLIBARR_CATEGORY_ON_RISK') > 0) {
- print '
'.$langs->trans("Categories") . ' ';
- $categoryArborescence = $form->select_all_categories('risk', '', 'parent', 64, 0, 1);
- print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, GETPOST('categories', 'array'), '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400');
- print '
';
- print "
";
- } ?>
-
-
trans('RiskAssessment'); ?>
-
-
-
-
-
-
trans('RiskAssessment'); ?>*
-
- '0-47', 48 => '48-50', 51 => '51-80', 100 => '81-100');
- if ( ! empty($defaultCotation)) :
- foreach ($defaultCotation as $cotation => $shownCotation) :
- $evaluation->cotation = $cotation; ?>
-
-
-
-
-
- type . '_variable'];
- ?>
-
-
-
-
trans('SelectEvaluation') ?>*
-
-
-
-
-
-
trans('CalculatedEvaluation'); ?>*
-
-
-
-
-
-
- global->DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE) : ?>
-
- trans('Date'); ?>
- selectDate('', 'RiskAssessmentDate', 0, 0, 0, '', 1, 1); ?>
-
-
-
+
+
trans('CalculatedEvaluation'); ?>*
+
+
+
+
+
+
+ global->DIGIRISKDOLIBARR_SHOW_RISKASSESSMENT_DATE) : ?>
+
+ trans('Date'); ?>
+ selectDate('', 'RiskAssessmentDate0', 0, 0, 0, '', 1, 1); ?>
+
+
+
-
- global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) : ?>
-
-
trans('Task'); ?>
-
trans('Label'); ?>
-
-
- trans('DateStart'); ?>
- selectDate(dol_now('tzuser'), 'RiskassessmentTaskDateStartModalRisk', 1, 1, 0, '', 1, 1); ?>
-
-
- trans('Deadline'); ?>
- selectDate(-1,'RiskassessmentTaskDateEndModalRisk', 1, 1, 0, '', 1, 1); ?>
-
-
-
trans('Budget'); ?>
-
-
-
-
-
-
-
-
-
-
+ global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) : ?>
+
+
+
trans('Task'); ?>
+
trans('Label'); ?>
+
+
+ trans('DateStart'); ?>
+ '; ?>
+
+
+ trans('Deadline'); ?>
+ '; ?>
+
+
+
trans('Budget'); ?>
+
+
+
+
+
+
+
+
+
trans('DigiriskElement' . ucfirst($riskType) . 'sList');
print '';
-print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $risk->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
+print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $risk->picto, 0, $newcardbutton ?? '', '', $limit, 0, 0, 1);
$corruptedRisks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 't.category NOT BETWEEN 0 AND ' . count($dangerCategories) . ' AND t.type = "' . $riskType . '"']);
@@ -1066,26 +866,6 @@ class="risk-evaluation-cotation cotation">
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
-$menuConf = 'MAIN_SELECTEDFIELDS_' . $varpage;
-
-if (dol_strlen($user->conf->$menuConf) < 1 || preg_match('/t./', $user->conf->$menuConf)) {
- $user->conf->$menuConf = ($contextpage == 'risklist' ? 'r.fk_element,' : '') . 'r.ref,r.category,evaluation.cotation,';
-}
-
-if ( ! preg_match('/r.description/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = $user->conf->$menuConf . 'r.description,';
-} elseif ( ! $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = preg_replace('/r.description,/', '', $user->conf->$menuConf);
- $arrayfields['r.description']['enabled'] = 0;
-}
-
-if ( ! preg_match('/evaluation.has_tasks/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf .= $user->conf->$menuConf . 'evaluation.has_tasks,';
-} elseif ( ! $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf = preg_replace('/evaluation.has_tasks,/', '', $user->conf->$menuConf);
- $arrayfields['evaluation.has_tasks']['enabled'] = 0;
-}
-
$selectedfields = $form->multiSelectArrayWithCheckbox('risklist_selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
@@ -1102,15 +882,15 @@ class="risk-evaluation-cotation cotation">
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
if ( ! empty($arrayfields['r.' . $key]['checked'])) {
print '';
- if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
+ if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
elseif (strpos($val['type'], 'integer:') === 0) {
print $risk->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
} elseif ($key == 'fk_element') {
- print $digiriskelement->selectDigiriskElementList($search['fk_element'], 'search_fk_element', ['customsql' => 'rowid NOT IN (' . implode(',', $deletedElements) . ')'], 1, 0, [], 0, 0, 'minwidth100 maxwidth300', 0, false, 1);
+ print $digiriskelement->selectDigiriskElementList($search['fk_element'] ?? '', 'search_fk_element', ['customsql' => 'rowid NOT IN (' . implode(',', $deletedElements) . ')'], 1, 0, [], 0, 0, 'minwidth100 maxwidth300', 0, false, 1);
} elseif ($key == 'category') { ?>
- ';
+ ';
print ' ';
}
}
@@ -1195,7 +975,7 @@ class="risk-evaluation-cotation cotation">
// contenu
$i = 0;
-$totalarray = array();
+$totalarray = array('nbfield' => 0);
while ($i < ($limit ? min($num, $limit) : $num)) {
$obj = $db->fetch_object($resql);
diff --git a/core/tpl/riskanalysis/risk/digiriskdolibarr_sharedrisklist_view.tpl.php b/core/tpl/riskanalysis/risk/digiriskdolibarr_sharedrisklist_view.tpl.php
index e7925f20f..db5b01e3b 100644
--- a/core/tpl/riskanalysis/risk/digiriskdolibarr_sharedrisklist_view.tpl.php
+++ b/core/tpl/riskanalysis/risk/digiriskdolibarr_sharedrisklist_view.tpl.php
@@ -120,6 +120,7 @@
}
$sql .= " AND el.sourcetype = 'digiriskdolibarr_risk'";
$sql .= ' AND r.type = "' . $riskType . '"';
+ $sql .= ' AND e.rowid IN (' . implode(',', array_keys($alldigiriskelement)) . ')';
foreach ($search as $key => $val) {
if ($key == 'status' && $search[$key] == -1) continue;
@@ -211,7 +212,8 @@
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $risk->table_element . " as r on (evaluation.fk_risk = r.rowid)";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . 'element_element' . " as el on (r.rowid = el.fk_source)";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $digiriskelement->table_element . " as e on (r.fk_element = e.rowid)";
- if (is_array($extrafields->attributes[$evaluation->table_element]['label']) && count($extrafields->attributes[$evaluation->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $evaluation->table_element . "_extrafields as ef on (evaluation.rowid = ef.fk_object)";
+ if (isset($extrafields->attributes[$evaluation->table_element]) &&
+ is_array($extrafields->attributes[$evaluation->table_element]['label']) && count($extrafields->attributes[$evaluation->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $evaluation->table_element . "_extrafields as ef on (evaluation.rowid = ef.fk_object)";
//if ($evaluation->ismultientitymanaged == 1) $sql .= " WHERE evaluation.entity IN (" . getEntity($evaluation->element) . ")";
else $sql .= " WHERE 1 = 1";
$sql .= " AND evaluation.status = 1";
@@ -234,6 +236,7 @@
}
$sql .= " AND el.sourcetype = 'digiriskdolibarr_risk'";
$sql .= ' AND r.type = "' . $riskType . '"';
+ $sql .= ' AND e.rowid IN (' . implode(',', array_keys($alldigiriskelement)) . ')';
foreach ($search as $key => $val) {
if ($key == 'status' && $search[$key] == -1) continue;
@@ -368,26 +371,6 @@
$arrayfields = dol_sort_array($arrayfields, 'position');
-$menuConf = 'MAIN_SELECTEDFIELDS_' . $varpage;
-
-if (dol_strlen($user->conf->$menuConf) < 1 || preg_match('/t./', $user->conf->$menuConf)) {
- $user->conf->$menuConf = 'r.entity,r.fk_element,r.applied_on,r.ref,r.category,evaluation.cotation,';
-}
-
-if ( ! preg_match('/r.description/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = $user->conf->$menuConf . 'r.description,';
-} elseif ( ! $conf->global->DIGIRISKDOLIBARR_RISK_DESCRIPTION) {
- $user->conf->$menuConf = preg_replace('/r.description,/', '', $user->conf->$menuConf);
- $arrayfields['r.description']['enabled'] = 0;
-}
-
-if ( ! preg_match('/evaluation.has_tasks/', $user->conf->$menuConf) && $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf .= $user->conf->$menuConf . 'evaluation.has_tasks,';
-} elseif ( ! $conf->global->DIGIRISKDOLIBARR_TASK_MANAGEMENT) {
- $user->conf->$menuConf = preg_replace('/evaluation.has_tasks,/', '', $user->conf->$menuConf);
- $arrayfields['evaluation.has_tasks']['enabled'] = 0;
-}
-
$selectedfields = $form->multiSelectArrayWithCheckbox('shared_risklist_selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
@@ -408,19 +391,19 @@
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
if ( ! empty($arrayfields['r.' . $key]['checked'])) {
print '';
- if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
- elseif (strpos($val['type'], 'integer:') === 0) {
+ if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
+ elseif (strpos($val['type'] ?? '', 'integer:') === 0) {
print $risk->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
} elseif ($key == 'entity') {
- print select_entity_list($search['entity'], 'search_entity', 'e.rowid NOT IN (' . $conf->entity . ')');
+ print select_entity_list($search['entity'] ?? '', 'search_entity', 'e.rowid NOT IN (' . $conf->entity . ')');
} elseif ($key == 'fk_element') {
- print $digiriskelement->selectDigiriskElementList($search['fk_element'], 'search_fk_element_sharedrisk', ['customsql' => 'entity NOT IN (' . $conf->entity . ') AND rowid NOT IN (' . implode(',', $deletedElements) . ')'], 1, 0, array(), 0, 0, 'minwidth100 maxwidth300', 0, false, 1, $contextpage, false);
+ print $digiriskelement->selectDigiriskElementList($search['fk_element'] ?? '', 'search_fk_element_sharedrisk', ['customsql' => 'entity NOT IN (' . $conf->entity . ') AND rowid NOT IN (' . implode(',', $deletedElements) . ')'], 1, 0, array(), 0, 0, 'minwidth100 maxwidth300', 0, false, 1, $contextpage, false);
} elseif ($key == 'applied_on') {
// print $digiriskelement->select_digiriskelement_list($search['search_applied_on_sharedrisk'], 'search_applied_on_sharedrisk', '', 1, 0, array(), 0, 0, 'minwidth100', 0, false, 1, $contextpage);
} elseif ($key == 'category') { ?>
-
-
+
+
- ';
+ ';
print '
';
}
}
@@ -479,7 +462,7 @@
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
if ( ! empty($arrayfields['r.' . $key]['checked'])) {
- print getTitleFieldOfList($arrayfields['r.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 'r.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : ''), $arrayfields['r.' . $key]['disablesort']) . "\n";
+ print getTitleFieldOfList($arrayfields['r.' . $key]['label'] ?? '', 0, $_SERVER['PHP_SELF'], 'r.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : ''), $arrayfields['r.' . $key]['disablesort'] ?? '') . "\n";
}
}
@@ -507,7 +490,7 @@
// contenu
$i = 0;
-$totalarray = array();
+$totalarray = ['nbfield' => 0];
unset($risk->fields['applied_on']);
while ($i < ($limit ? min($num, $limit) : $num)) {
diff --git a/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view.tpl.php b/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view.tpl.php
index c0efb7a22..b89ff2593 100644
--- a/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view.tpl.php
+++ b/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view.tpl.php
@@ -213,28 +213,6 @@
-
-
-
-
-
- trans('NoRiskAssessment'); ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
method = $lastRiskAssessment->method ?: "standard" ;
?>
@@ -335,10 +313,10 @@ class="risk-evaluation-cotation cotation">
-
@@ -379,7 +357,7 @@ class="risk-evaluation-cotation cotation">
-
+
diff --git a/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view_edit_modal.tpl.php b/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view_edit_modal.tpl.php
index 41b7740c9..97aa5d2ed 100644
--- a/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view_edit_modal.tpl.php
+++ b/core/tpl/riskanalysis/riskassessment/digiriskdolibarr_riskassessment_view_edit_modal.tpl.php
@@ -149,7 +149,7 @@ class="risk-evaluation-cotation cotationcotation ==
-
+
@@ -121,18 +109,6 @@
0 ? $langs->trans('NoTaskLinked') : $langs->trans('NoTaskShared'); ?>
-
-
-
-
-
-
-
-
-
-
-
-
@@ -148,18 +124,6 @@
trans('NoTaskLinked'); ?>
-
-
-
-
-
-
-
-
-
-
-
-
@@ -194,11 +158,11 @@
trans('DateStart'); ?>
- selectDate(dol_now('tzuser'), 'RiskassessmentTaskDateStart' . $risk->id, 1, 1, 0, '', 1, 1); ?>
+ id . '" name="RiskassessmentTaskDateStart' . $risk->id . '">'; ?>
trans('Deadline'); ?>
- selectDate(-1,'RiskassessmentTaskDateEnd'. $risk->id, 1, 1, 0, '', 1, 1); ?>
+ id . '" name="RiskassessmentTaskDateEnd' . $risk->id . '">'; ?>
trans('Budget'); ?>
@@ -323,9 +287,19 @@
- 0) : ?>
-
- id]; ?>
+ 0) :
+ foreach ($related_tasks as $related_task) :
+ if ($conf->global->DIGIRISKDOLIBARR_SHOW_TASK_CALCULATED_PROGRESS) {
+ $tmparray = $related_task->getSummaryOfTimeSpent();
+ if ($tmparray['total_duration'] > 0 && !empty($related_task->planned_workload)) {
+ $task_progress = round($tmparray['total_duration'] / $related_task->planned_workload * 100, 2);
+ } else {
+ $task_progress = 0;
+ }
+ } else {
+ $task_progress = $related_task->progress;
+ }
+ $allTimeSpentArray = $timeSpentSortedByTasks[$related_task->id] ?? []; ?>
';
- //User Victim -- Victime de l'accident
- print '';
- print $form->textwithpicto($langs->trans("UserVictim"), $langs->trans("GaugeCounter"), 1, 'info');
- print ' ';
- print '';
- print $userVictim->getNomUrl(1);
- print ' ';
-
//Accident type -- Type de l'accident
print '';
print $form->textwithpicto($langs->trans("AccidentType"), $langs->trans("GaugeCounter"), 1, 'info');
diff --git a/view/accident/accident_list.php b/view/accident/accident_list.php
index 6237124c0..46dad4988 100644
--- a/view/accident/accident_list.php
+++ b/view/accident/accident_list.php
@@ -90,7 +90,7 @@
// List of fields to search into when doing a "search in all"
$fieldstosearchall = [];
foreach ($accident->fields as $key => $val) {
- if ($val['searchall']) {
+ if (!empty($val['searchall'])) {
$fieldstosearchall['t.' . $key] = $val['label'];
}
}
@@ -100,10 +100,11 @@
foreach ($accident->fields as $key => $val) {
// If $val['visible']==0, then we never show the field
- if ( ! empty($val['visible'])) $arrayfields['t.' . $key] = array('label' => $val['label'], 'checked' => (($val['visible'] < 0) ? 0 : 1), 'enabled' => ($val['enabled'] && ($val['visible'] != 3)), 'position' => $val['position']);
+ if (!empty($val['visible'])) $arrayfields['t.' . $key] = ['label' => $val['label'], 'checked' => (($val['visible'] < 0) ? 0 : 1), 'enabled' => ($val['enabled'] && ($val['visible'] != 3)), 'position' => $val['position']];
}
-// Load accident object
+$id = GETPOST('id', 'int'); // get if for actions_fetchobject.inc.php
+// Load accident object, why ?
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
//Permission for accident
@@ -284,7 +285,8 @@
$sql = preg_replace('/,\s*$/', '', $sql);
$sql .= " FROM " . MAIN_DB_PREFIX . $accident->table_element . " as t";
-if (is_array($extrafields->attributes[$accident->table_element]['label']) && count($extrafields->attributes[$accident->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $accident->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
+if (isset($extrafields->attributes[$accident->table_element]['label']) &&
+ is_array($extrafields->attributes[$accident->table_element]['label']) && count($extrafields->attributes[$accident->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $accident->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
if ($accident->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (" . getEntity($accident->element) . ")";
else $sql .= " WHERE 1 = 1";
$sql .= ' AND status != ' . $accident::STATUS_DELETED;
@@ -378,10 +380,10 @@
if ( ! empty($arrayfields['t.' . $key]['checked'])) {
print ' ';
- if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
+ if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key] ?? '', $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
elseif (strpos($val['type'], 'integer:') === 0) {
- print $accident->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
- } elseif ( ! preg_match('/^(date|timestamp)/', $val['type'])) print ' ';
+ print $accident->showInputField($val, $key, $search[$key] ?? '', '', '', 'search_', 'maxwidth150', 1);
+ } elseif ( ! preg_match('/^(date|timestamp)/', $val['type'])) print ' ';
print ' ';
}
if ($key == 'Custom') {
@@ -458,7 +460,7 @@
// contenu
$i = 0;
$kCounter = 0;
-$totalarray = [];
+$totalarray = ['nbfield' => 0];
while ($i < ($limit ? min($num, $limit) : $num)) {
$obj = $db->fetch_object($resql);
@@ -470,7 +472,11 @@
$accident->setVarsFromFetchObj($obj);
$userVictim = $accident->getUserVictim();
- $json = json_decode($accident->json, false, 512, JSON_UNESCAPED_UNICODE)->Accident;
+ if (isset($accident->json)) {
+ $json = json_decode($accident->json, false, 512, JSON_UNESCAPED_UNICODE)->Accident;
+ } else {
+ $json = [];
+ }
// Show here line of result
print '';
@@ -508,7 +514,7 @@
$arrayAccident[] = $accident->accident_location;
break;
}
- $arrayAccident[] = $userVictim->id;
+ $arrayAccident[] = $userVictim->id > 0 ? $userVictim->id : '';
$accidentLesions = $accidentLesion->fetchAll('', '', 0, 0, ['customsql' => 't.fk_accident = ' . $accident->id]);
$arrayAccident[] = (is_array($accidentLesions) && !empty($accidentLesions)) ? count($accidentLesions) : '';
@@ -608,7 +614,7 @@
}
$db->free($resql);
-$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
+$parameters = ['arrayfields' => $arrayfields, 'sql' => $sql];
$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $risk); // Note that $action and $risk may have been modified by hook
print $hookmanager->resPrint;
diff --git a/view/accidentinvestigation/accidentinvestigation_card.php b/view/accidentinvestigation/accidentinvestigation_card.php
index 740a4cdb8..fe861f04a 100644
--- a/view/accidentinvestigation/accidentinvestigation_card.php
+++ b/view/accidentinvestigation/accidentinvestigation_card.php
@@ -333,8 +333,8 @@
require_once DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
- print '' . $langs->trans("UserVictim") . ' ';
- print '' . $victim->getNomUrl(1) . ' ';
+ print '' . $langs->trans("UserVictim") . ' ';
+ print '' . ($victim->id > 0 ? $victim->getNomUrl(1) : '') . ' ';
print ' ' . $langs->trans("CausalityTree") . ' ';
print '';
$pathPhotos = $conf->digiriskdolibarr->multidir_output[$conf->entity] . '/accidentinvestigation/'. $object->ref . '/causality_tree/';
diff --git a/view/digiriskelement/risk_list.php b/view/digiriskelement/risk_list.php
index 20f80dae0..4e09f0e6d 100644
--- a/view/digiriskelement/risk_list.php
+++ b/view/digiriskelement/risk_list.php
@@ -80,6 +80,8 @@
$search_category_array = GETPOST('search_category_risk_list', 'array');
}
+$onPhone = $conf->browser->layout == 'phone';
+
// Initialize technical objects
$object = new DigiriskStandard($db);
$risk = new Risk($db);
@@ -108,7 +110,7 @@
// Default sort order (if not yet defined by previous GETPOST)
if ( ! $sortfield) $sortfield = $conf->global->DIGIRISKDOLIBARR_SORT_LISTINGS_BY_COTATION ? "evaluation.cotation" : "r." . key($risk->fields);; // Set here default search field. By default 1st field in definition.
if ( ! $sortorder) $sortorder = $conf->global->DIGIRISKDOLIBARR_SORT_LISTINGS_BY_COTATION ? "DESC" : "ASC" ;
-if ( ! $evalsortfield) $evalsortfield = "evaluation." . key($evaluation->fields);
+if (!isset($evalsortfield) || !$evalsortfield) $evalsortfield = "evaluation." . key($evaluation->fields);
$offset = $limit * $page;
$pageprev = $page - 1;
@@ -127,7 +129,7 @@
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array();
foreach ($risk->fields as $key => $val) {
- if ($val['searchall']) $fieldstosearchall['r.' . $key] = $val['label'];
+ if (!empty($val['searchall'])) $fieldstosearchall['r.' . $key] = $val['label'];
}
// Definition of fields for list
diff --git a/view/digiriskstandard/digiriskstandard_auditreportdocument.php b/view/digiriskstandard/digiriskstandard_auditreportdocument.php
index 1f2cf8c14..c7dd2b1ae 100644
--- a/view/digiriskstandard/digiriskstandard_auditreportdocument.php
+++ b/view/digiriskstandard/digiriskstandard_auditreportdocument.php
@@ -130,10 +130,10 @@
print ' ';
// DateRange -- Plage de date
-$dateStart = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? dol_mktime(0, 0, 0, getDolGlobalInt('SOCIETE_FISCAL_MONTH_START'), 1, strftime("%Y", dol_now())) : dol_now();
+$currentDate = dol_now();
print '' . $langs->trans("DateRange") . ' ';
-print '' . $langs->trans('From') . $form->selectDate($dateStart, 'datestart');
-print $langs->trans('At') . $form->selectDate(dol_time_plus_duree($dateStart, 1, 'y'), 'dateend');
+print ' ' . $langs->trans('From') . $form->selectDate(dol_time_plus_duree($currentDate, -1, 'd'), 'datestart');
+print $langs->trans('At') . $form->selectDate($currentDate, 'dateend');
print $langs->trans('UseDateRange');
print ' ';
print ' ';
diff --git a/view/digirisktools.php b/view/digirisktools.php
index 9c6a23420..47ead4d8a 100644
--- a/view/digirisktools.php
+++ b/view/digirisktools.php
@@ -84,6 +84,7 @@
$dangerCategories = $risk->getDangerCategories();
$risk->type = 'riskenvironmental';
$environmentalCategories = $risk->getDangerCategories();
+$risk->type = 'risk';
// Security check - Protection if external user
$permissiontoread = $user->rights->digiriskdolibarr->adminpage->read;
@@ -218,19 +219,22 @@
//Risk
foreach ($digiriskExportArray['risks'] as $digiriskExportRisk) {
- $risk->ref = $refRiskMod->getNextValue($risk);
- $risk->category = $risk->getDangerCategoryPositionByName($digiriskExportRisk['danger_category']['name']);
- $risk->fk_element = $digiriskElement->fetch_id_from_wp_digi_id($digiriskExportRisk['parent_id']);
- $risk->fk_projet = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
-
- if ( ! $error) {
+ $risk->ref = $refRiskMod->getNextValue($risk);
+ $risk->status = Risk::STATUS_VALIDATED;
+ $risk->category = $risk->getDangerCategoryPositionByName($digiriskExportRisk['danger_category']['name']);
+ $risk->fk_element = $digiriskElement->fetch_id_from_wp_digi_id($digiriskExportRisk['parent_id']);
+ $risk->fk_projet = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
+ $risk->date_creation = $digiriskExportRisk['evaluation']['date']['raw'];
+
+ if (!$error) {
$result = $risk->create($user, true);
if ($result > 0) {
$riskAssessment->ref = $refRiskAssessmentMod->getNextValue($riskAssessment);
$riskAssessment->date_riskassessment = $digiriskExportRisk['evaluation']['date']['raw'];
- $riskAssessment->cotation = $digiriskExportRisk['current_equivalence'];
- $riskAssessment->status = 1;
- $riskAssessment->fk_risk = $risk->id;
+ $riskAssessment->date_creation = $digiriskExportRisk['evaluation']['date']['raw'];
+ $riskAssessment->cotation = $digiriskExportRisk['current_equivalence'];
+ $riskAssessment->status = RiskAssessment::STATUS_VALIDATED;
+ $riskAssessment->fk_risk = $risk->id;
if ($digiriskExportRisk['evaluation_method']['name'] == 'Evarisk') {
$riskassessment_variables = array_values($digiriskExportRisk['evaluation']['variables']);
@@ -416,18 +420,21 @@
//Risk
foreach ($digiriskExportArray['risks'] as $digiriskExportRisk) {
- $risk->ref = $refRiskMod->getNextValue($risk);
- $risk->category = $risk->getDangerCategoryPositionByName($digiriskExportRisk['danger_category']['name']);
- $risk->fk_element = $digiriskElement->fetch_id_from_wp_digi_id($digiriskExportRisk['parent_id']);
- $risk->fk_projet = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
-
- if ( ! $error) {
+ $risk->ref = $refRiskMod->getNextValue($risk);
+ $risk->status = Risk::STATUS_VALIDATED;
+ $risk->category = $risk->getDangerCategoryPositionByName($digiriskExportRisk['danger_category']['name']);
+ $risk->fk_element = $digiriskElement->fetch_id_from_wp_digi_id($digiriskExportRisk['parent_id']);
+ $risk->fk_projet = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
+ $risk->date_creation = $digiriskExportRisk['evaluation']['date']['raw'];
+
+ if (!$error) {
$result = $risk->create($user, true);
if ($result > 0) {
$riskAssessment->ref = $refRiskAssessmentMod->getNextValue($riskAssessment);
- $riskAssessment->date_riskassessment = $digiriskExportRisk['evaluation']['date']['raw'];
+ $riskAssessment->date_riskassessment = $digiriskExportRisk['evaluation']['date']['raw'];
+ $riskAssessment->date_creation = $digiriskExportRisk['evaluation']['date']['raw'];
$riskAssessment->cotation = $digiriskExportRisk['current_equivalence'];
- $riskAssessment->status = 1;
+ $riskAssessment->status = RiskAssessment::STATUS_VALIDATED;
$riskAssessment->fk_risk = $risk->id;
if ($digiriskExportRisk['evaluation_method']['name'] == 'Evarisk') {
@@ -617,165 +624,180 @@
}
}
-if (GETPOST('dataMigrationImportGlobalDolibarr', 'alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
+if ($action == 'import_global_dolibarr' && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
// Submit file
+ $actionError = [];
+
if ( ! empty($_FILES)) {
- if ( ! preg_match('/dolibarr_global_export.zip/', $_FILES['dataMigrationImportGlobalDolibarrfile']['name'][0]) || $_FILES['dataMigrationImportGlobalDolibarrfile']['size'][0] < 1) {
- setEventMessages($langs->trans('ErrorFileNotWellFormattedZIP'), null, 'errors');
+ if ( ! preg_match('/dolibarr_global_export.zip/', $_FILES['file']['name']) || $_FILES['file']['size'] < 1) {
+ $actionError[] = $langs->trans('ErrorFileNotWellFormattedZIP');
} else {
- if (is_array($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'])) $userfiles = $_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'];
- else $userfiles = array($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name']);
- foreach ($userfiles as $key => $userfile) {
- if (empty($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'][$key])) {
- $error++;
- if ($_FILES['dataMigrationImportGlobalDolibarrfile']['error'][$key] == 1 || $_FILES['dataMigrationImportGlobalDolibarrfile']['error'][$key] == 2) {
- setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
- } else {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
- }
- }
- }
+ if (empty($_FILES['file']['tmp_name'])) {
+ $error++;
+ if ($_FILES['file']['error'] == 1 || $_FILES['file']['error'] == 2) {
+ $actionError[] = $langs->trans('ErrorFileSizeTooLarge');
+ } else {
+ $actionError[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File"));
+ }
+ }
if ( ! $error) {
$filedir = $upload_dir . '/temp/';
if ( ! empty($filedir)) {
- $result = dol_add_file_process($filedir, 0, 1, 'dataMigrationImportGlobalDolibarrfile', '', null, '', 0, null);
+ $result = dol_add_file_process($filedir, 0, 1, 'file', '', null, '', 0, null);
}
}
if ($result > 0) {
$zip = new ZipArchive;
- if ($zip->open($filedir . $_FILES['dataMigrationImportGlobalDolibarrfile']['name'][0]) === TRUE) {
+ if ($zip->open($filedir . $_FILES['file']['name']) === TRUE) {
$zip->extractTo($filedir);
$zip->close();
}
}
- $filename = preg_replace( '/\.zip/', '.json', $_FILES['dataMigrationImportGlobalDolibarrfile']['name'][0]);
+ $filename = preg_replace( '/\.zip/', '.json', $_FILES['file']['name']);
$json = file_get_contents($filedir . $filename);
$digiriskExportArray = json_decode($json, true);
- if (is_array($digiriskExportArray['digiriskelements']) && !empty($digiriskExportArray['digiriskelements'])) {
- foreach ($digiriskExportArray['digiriskelements'] as $digiriskelementsingle) {
- if ($digiriskelementsingle['element_type'] == 'groupment') {
- $digiriskElement->ref = $refGroupmentMod->getNextValue($digiriskElement);
- } elseif ($digiriskelementsingle['element_type'] == 'workunit') {
- $digiriskElement->ref = $refWorkUnitMod->getNextValue($digiriskElement);
- }
- $digiriskElement->label = $digiriskelementsingle['label'];
- $digiriskElement->status = $digiriskelementsingle['status'];
- $digiriskElement->description = $digiriskelementsingle['description'];
- $digiriskElement->element = $digiriskelementsingle['element_type'];
- $digiriskElement->element_type = $digiriskelementsingle['element_type'];
- $digiriskElement->photo = $digiriskelementsingle['photo'];
- $digiriskElement->show_in_selector = $digiriskelementsingle['show_in_selector'];
- $digiriskElement->ranks = $digiriskelementsingle['ranks'];
-
- $digiriskElement->array_options['wp_digi_id'] = $digiriskelementsingle['rowid'];
- $digiriskElement->array_options['entity'] = $conf->entity;
-
- $digiriskElement->fk_parent = $digiriskElement->fetch_id_from_wp_digi_id($digiriskelementsingle['fk_parent']) ?: 0;
-
- $digiriskelementid = $digiriskElement->create($user);
-
- //Risk
- if (array_key_exists('risks', $digiriskelementsingle)) {
- foreach ($digiriskelementsingle['risks'] as $digiriskExportRisk) {
- $risk->ref = $refRiskMod->getNextValue($risk);
- $risk->status = $digiriskExportRisk['status'];
- $risk->category = $digiriskExportRisk['category'];
- $risk->description = $digiriskExportRisk['description'];
- $risk->type = $digiriskExportRisk['type'];
- $risk->fk_element = $digiriskelementid;
- $risk->fk_projet = $digiriskExportRisk['type'] == 'risk' ? $conf->global->DIGIRISKDOLIBARR_DU_PROJECT : $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT;
-
- if ( ! $error) {
- $result = $risk->create($user, true);
- if ($result > 0) {
- if (array_key_exists('riskassessments', $digiriskExportRisk)) {
- foreach ($digiriskExportRisk['riskassessments'] as $digiriskExportRiskAssessement) {
- $riskAssessment->ref = $refRiskAssessmentMod->getNextValue($riskAssessment);
- $riskAssessment->status = $digiriskExportRiskAssessement['status'];
- $riskAssessment->method = $digiriskExportRiskAssessement['method'];
- $riskAssessment->cotation = $digiriskExportRiskAssessement['cotation'];
- $riskAssessment->gravite = $digiriskExportRiskAssessement['gravite'];
- $riskAssessment->protection = $digiriskExportRiskAssessement['protection'];
- $riskAssessment->occurrence = $digiriskExportRiskAssessement['occurrence'];
- $riskAssessment->formation = $digiriskExportRiskAssessement['formation'];
- $riskAssessment->exposition = $digiriskExportRiskAssessement['exposition'];
- $riskAssessment->date_riskassessment = $digiriskExportRiskAssessement['date_riskassessment'];
- $riskAssessment->comment = $digiriskExportRiskAssessement['comment'];
- $riskAssessment->photo = $digiriskExportRiskAssessement['photo'];
- $riskAssessment->fk_risk = $risk->id;
-
- $result2 = $riskAssessment->create($user, true, false);
-
- if ($result2 < 0) {
- // Creation evaluation KO
- if ( ! empty($riskAssessment->errors)) setEventMessages('', $riskAssessment->errors, 'errors');
- else setEventMessages($riskAssessment->error, array(), 'errors');
- }
- }
- }
- if (array_key_exists('tasks', $digiriskExportRisk)) {
- foreach ($digiriskExportRisk['tasks'] as $digiriskExportTask) {
- $task->ref = $refTaskMod->getNextValue('', $task);
- $task->date_start = $digiriskExportTask['date_start'];
- $task->date_end = $digiriskExportTask['date_end'];
- $task->label = $digiriskExportTask['label'];
- $task->description = $digiriskExportTask['description'];
- $task->duration_effective = $digiriskExportTask['duration_effective'];
- $task->planned_workload = $digiriskExportTask['planned_workload'];
- $task->progress = $digiriskExportTask['progress'];
- $task->priority = $digiriskExportTask['priority'];
- $task->budget_amount = $digiriskExportTask['budget_amount'];
- // $task->fk_statut = $digiriskExportTask['fk_statut'];
- $task->note_public = $digiriskExportTask['note_public'];
- $task->note_private = $digiriskExportTask['note_private'];
- $task->fk_project = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
- $task->array_options['fk_risk'] = $risk->id;
-
- $result3 = $task->create($user, true);
-
- if ($result3 < 0) {
- // Creation task KO
- if ( ! empty($task->errors)) setEventMessages('', $task->errors, 'errors');
- else setEventMessages($task->error, array(), 'errors');
- }
- }
- }
- } else {
- // Creation risk KO
- if ( ! empty($risk->errors)) setEventMessages('', $risk->errors, 'errors');
- else setEventMessages($risk->error, array(), 'errors');
- }
- }
- }
- }
-
- //RiskSign
- if (array_key_exists('risksigns', $digiriskelementsingle)) {
- foreach ($digiriskelementsingle['risksigns'] as $digiriskExportRiskSign) {
- $risksign->ref = $refRiskSignMod->getNextValue($risksign);
- $risksign->status = $digiriskExportRiskSign['status'];
- $risksign->category = $digiriskExportRiskSign['category'];
- $risksign->description = $digiriskExportRiskSign['description'];
- $risksign->fk_element = $digiriskelementid;
-
- if (!$error) {
- $result = $risksign->create($user, true);
- if ($result < 0) {
- // Creation risksign KO
- if (!empty($risksign->errors)) setEventMessages(null, $risksign->errors, 'errors');
- else setEventMessages($risksign->error, null, 'errors');
- }
- }
- }
- }
- }
- }
+ if ($digiriskExportArray != null) {
+ if (is_array($digiriskExportArray['digiriskelements']) && !empty($digiriskExportArray['digiriskelements'])) {
+ foreach ($digiriskExportArray['digiriskelements'] as $digiriskelementsingle) {
+ if ($digiriskelementsingle['element_type'] == 'groupment') {
+ $digiriskElement->ref = $refGroupmentMod->getNextValue($digiriskElement);
+ } elseif ($digiriskelementsingle['element_type'] == 'workunit') {
+ $digiriskElement->ref = $refWorkUnitMod->getNextValue($digiriskElement);
+ }
+ $digiriskElement->label = $digiriskelementsingle['label'];
+ $digiriskElement->status = $digiriskelementsingle['status'];
+ $digiriskElement->description = $digiriskelementsingle['description'];
+ $digiriskElement->element = $digiriskelementsingle['element_type'];
+ $digiriskElement->element_type = $digiriskelementsingle['element_type'];
+ $digiriskElement->photo = $digiriskelementsingle['photo'];
+ $digiriskElement->show_in_selector = $digiriskelementsingle['show_in_selector'];
+ $digiriskElement->ranks = $digiriskelementsingle['ranks'];
+
+ $digiriskElement->array_options['wp_digi_id'] = $digiriskelementsingle['rowid'];
+ $digiriskElement->array_options['entity'] = $conf->entity;
+
+ $digiriskElement->fk_parent = $digiriskElement->fetch_id_from_wp_digi_id($digiriskelementsingle['fk_parent']) ?: 0;
+
+ $digiriskelementid = $digiriskElement->create($user);
+
+ //Risk
+ if (array_key_exists('risks', $digiriskelementsingle)) {
+ foreach ($digiriskelementsingle['risks'] as $digiriskExportRisk) {
+ $risk->ref = $refRiskMod->getNextValue($risk);
+ $risk->status = $digiriskExportRisk['status'];
+ $risk->category = $digiriskExportRisk['category'];
+ $risk->description = $digiriskExportRisk['description'];
+ $risk->type = $digiriskExportRisk['type'];
+ $risk->fk_element = $digiriskelementid;
+ $risk->fk_projet = $digiriskExportRisk['type'] == 'risk' ? $conf->global->DIGIRISKDOLIBARR_DU_PROJECT : $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT;
+
+ if (!$error) {
+ $result = $risk->create($user, true);
+ if ($result > 0) {
+ if (array_key_exists('riskassessments', $digiriskExportRisk)) {
+ foreach ($digiriskExportRisk['riskassessments'] as $digiriskExportRiskAssessement) {
+ $riskAssessment->ref = $refRiskAssessmentMod->getNextValue($riskAssessment);
+ $riskAssessment->status = $digiriskExportRiskAssessement['status'];
+ $riskAssessment->method = $digiriskExportRiskAssessement['method'];
+ $riskAssessment->cotation = $digiriskExportRiskAssessement['cotation'];
+ $riskAssessment->gravite = $digiriskExportRiskAssessement['gravite'];
+ $riskAssessment->protection = $digiriskExportRiskAssessement['protection'];
+ $riskAssessment->occurrence = $digiriskExportRiskAssessement['occurrence'];
+ $riskAssessment->formation = $digiriskExportRiskAssessement['formation'];
+ $riskAssessment->exposition = $digiriskExportRiskAssessement['exposition'];
+ $riskAssessment->date_riskassessment = $digiriskExportRiskAssessement['date_riskassessment'];
+ $riskAssessment->comment = $digiriskExportRiskAssessement['comment'];
+ $riskAssessment->photo = $digiriskExportRiskAssessement['photo'];
+ $riskAssessment->fk_risk = $risk->id;
+
+ $result2 = $riskAssessment->create($user, true, false);
+
+ if ($result2 < 0) {
+ // Creation evaluation KO
+ if (!empty($riskAssessment->errors)) {
+ $actionError[] = join(' ', $riskAssessment->errors);
+ } else {
+ $actionError[] = $riskAssessment->error;
+ }
+ }
+ }
+ }
+ if (array_key_exists('tasks', $digiriskExportRisk)) {
+ foreach ($digiriskExportRisk['tasks'] as $digiriskExportTask) {
+ $task->ref = $refTaskMod->getNextValue('', $task);
+ $task->date_start = $digiriskExportTask['date_start'];
+ $task->date_end = $digiriskExportTask['date_end'];
+ $task->label = $digiriskExportTask['label'];
+ $task->description = $digiriskExportTask['description'];
+ $task->duration_effective = $digiriskExportTask['duration_effective'];
+ $task->planned_workload = $digiriskExportTask['planned_workload'];
+ $task->progress = $digiriskExportTask['progress'];
+ $task->priority = $digiriskExportTask['priority'];
+ $task->budget_amount = $digiriskExportTask['budget_amount'];
+ // $task->fk_statut = $digiriskExportTask['fk_statut'];
+ $task->note_public = $digiriskExportTask['note_public'];
+ $task->note_private = $digiriskExportTask['note_private'];
+ $task->fk_project = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
+ $task->array_options['fk_risk'] = $risk->id;
+
+ $result3 = $task->create($user, true);
+
+ if ($result3 < 0) {
+ // Creation task KO
+ if (!empty($task->errors)) {
+ $actionError[] = join(' ', $task->errors);
+ } else {
+ $actionError[] = $task->error;
+ }
+
+ }
+ }
+ }
+ } else {
+ // Creation risk KO
+ if (!empty($risk->errors)) {
+ $actionError[] = join(' ', $risk->errors);
+ } else {
+ $actionError[] = $risk->error;
+ }
+ }
+ }
+ }
+ }
+
+ //RiskSign
+ if (array_key_exists('risksigns', $digiriskelementsingle)) {
+ foreach ($digiriskelementsingle['risksigns'] as $digiriskExportRiskSign) {
+ $risksign->ref = $refRiskSignMod->getNextValue($risksign);
+ $risksign->status = $digiriskExportRiskSign['status'];
+ $risksign->category = $digiriskExportRiskSign['category'];
+ $risksign->description = $digiriskExportRiskSign['description'];
+ $risksign->fk_element = $digiriskelementid;
+
+ if (!$error) {
+ $result = $risksign->create($user, true);
+ if ($result < 0) {
+ // Creation risksign KO
+ if (!empty($risksign->errors)) {
+ $actionError[] = join(' ', $risksign->errors);
+ } else {
+ $actionError[] = $risksign->error;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ $actionError[] = $langs->transnoentities('ErrorJsonBadFormatted');
+ }
}
$fileImportGlobals = dol_dir_list($filedir, "files", 0, '', '', '', '', 1);
@@ -784,7 +806,12 @@
unlink($fileImportGlobal['fullname']);
}
}
- }
+ if (empty($actionError)) {
+ $actionSuccess = $langs->transnoentities('SuccessImport');
+ }
+ } else {
+ $actionError[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File"));
+ }
}
if ($action == 'repair_category') {
@@ -812,6 +839,92 @@
$action = '';
}
+if ($action == 'repair_risk') {
+ $riskFkElements = $risk->fetchAll('', '', 0, 0, ['customsql' => 't.fk_element <= 0']);
+ $riskAssessmentFkElements = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 'r.fk_element <= 0'], 'AND', false, true, false, ' LEFT JOIN ' . MAIN_DB_PREFIX . $risk->table_element . ' as r ON r.rowid = t.fk_risk');
+ $riskStatus = $risk->fetchAll('', '', 0, 0, ['customsql' => 't.status < 0']);
+ $riskAssessmentStatus = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 'r.status <= 0'], 'AND', false, true, false, ' LEFT JOIN ' . MAIN_DB_PREFIX . $risk->table_element . ' as r ON r.rowid = t.fk_risk');
+ $riskExistFkElements = $risk->checkNotExistsDigiriskElementForRisk();
+ $riskExistRiskAssessment = $risk->checkNotExistsRiskAssessmentForRisk();
+ $riskAssessmentExistFkRisks = $riskAssessment->checkNotExistsRiskForRiskAssessment();
+
+ $ObjectToDeletes = [];
+ if (is_array($riskFkElements)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskFkElements);
+ }
+ if (is_array($riskFkElements)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskFkElements);
+ }
+ if (is_array($riskStatus)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskStatus);
+ }
+ if (is_array($riskAssessmentStatus)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskAssessmentStatus);
+ }
+ if (is_array($riskExistFkElements)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskExistFkElements);
+ }
+ if (is_array($riskExistRiskAssessment)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskExistRiskAssessment);
+ }
+ if (is_array($riskAssessmentExistFkRisks)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskAssessmentExistFkRisks);
+ }
+
+ foreach ($ObjectToDeletes as $object) {
+ $result = $object->delete($user, '', false);
+ if ($result <= 0) {
+ $errors[] = $object->errors;
+ }
+ }
+
+ if (!empty($errors)) {
+ setEventMessages('', $errors, 'errors');
+ } else {
+ setEventMessages($langs->trans('RiskSuccessfullyRepaired'), []);
+ }
+
+ header("Location: " . $_SERVER["PHP_SELF"]);
+ exit;
+}
+
+if ($action == 'repair_risk_assessment') {
+ $riskAssessmentStatus = $riskAssessment->fetchAll('', '', 0, 0, ['customsql' => 't.status < 0 || t.status IS NULL']);
+ $riskAssessmentCotations = $riskAssessment->fetchAll('', '', 0, 0, ['customsql' => 't.cotation IS NULL']);
+ $risks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 'ra.cotation IS NULL'], 'AND', false, true, false, ' LEFT JOIN ' . MAIN_DB_PREFIX . $riskAssessment->table_element . ' as ra ON ra.fk_risk = t.rowid');
+ $riskAssessmentExistFkRisks = $riskAssessment->checkNotExistsRiskForRiskAssessment();
+
+ $ObjectToDeletes = [];
+ if (is_array($riskAssessmentStatus)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskAssessmentStatus);
+ }
+ if (is_array($riskAssessmentCotations)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskAssessmentCotations);
+ }
+ if (is_array($risks)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $risks);
+ }
+ if (is_array($riskAssessmentExistFkRisks)) {
+ $ObjectToDeletes = array_merge($ObjectToDeletes, $riskAssessmentExistFkRisks);
+ }
+
+ foreach ($ObjectToDeletes as $object) {
+ $result = $object->delete($user, '', false);
+ if ($result <= 0) {
+ $errors[] = $object->errors;
+ }
+ }
+
+ if (!empty($errors)) {
+ setEventMessages('', $errors, 'errors');
+ } else {
+ setEventMessages($langs->trans('RiskAssessmentSuccessfullyRepaired'), []);
+ }
+
+ header("Location: " . $_SERVER["PHP_SELF"]);
+ exit;
+}
+
/*
* View
*/
@@ -823,6 +936,12 @@
print load_fiche_titre($title, '', 'wrench');
+if (!empty($actionError)) {
+ echo ' ';
+} elseif (isset($actionSuccess)) {
+ echo ' ';
+}
+
if ($user->rights->digiriskdolibarr->adminpage->read) {
if ($conf->global->DIGIRISKDOLIBARR_TOOLS_TREE_ALREADY_IMPORTED == 1) : ?>
@@ -924,6 +1043,8 @@
print '