Skip to content

Commit

Permalink
Merge branch 'develop' into add_graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka authored Apr 24, 2024
2 parents 0f7e445 + 654e461 commit e77e36a
Show file tree
Hide file tree
Showing 60 changed files with 1,515 additions and 340 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
## Informations

- Numéro du module : 436302
- Dernière mise à jour : 08/04/2024
- Dernière mise à jour : 23/04/2024
- Éditeur : [Evarisk](https://evarisk.com)
- Thème : Eldy Menu
- Licence : GPLv3
- Disponible sur : Windows - MacOS - Linux

### Version

- Version : 9.15.0
- Version : 10.0.0
- PHP : 7.4.33
- Compatibilité : Dolibarr 16.0.0 - 19.0.1
- Saturne Framework : 1.3.0
Expand Down
30 changes: 30 additions & 0 deletions admin/config/riskassessmentdocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
if (($action == 'update' && ! GETPOST("cancel", 'alpha')) || ($action == 'updateedit')) {
$DUProject = GETPOST('DUProject', 'none');
$DUProject = preg_split('/_/', $DUProject);
$EnvironmentProject = GETPOST('EnvironmentProject', 'none');
$EnvironmentProject = preg_split('/_/', $EnvironmentProject);
$evaluatorDuration = GETPOST('EvaluatorDuration', 'alpha');
$taskTimeSpentDuration = GETPOST('TaskTimeSpentDuration', 'alpha');

Expand All @@ -101,6 +103,23 @@
}
}

if ($EnvironmentProject[0] > 0 && $EnvironmentProject[0] != $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT) {
dolibarr_set_const($db, "DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT", $EnvironmentProject[0], 'integer', 0, '', $conf->entity);

$url = '/projet/tasks.php?id=' . $EnvironmentProject[0];

$sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
$sql .= " url='".$db->escape($url)."'";
$sql .= " WHERE leftmenu='digiriskenvironmentalactionplan'";
$sql .= " AND entity=" . $conf->entity;

$resql = $db->query($sql);
if (!$resql) {
$error = "Error ".$db->lasterror();
return -1;
}
}

if (!empty($evaluatorDuration) || $evaluatorDuration === '0') {
dolibarr_set_const($db, "DIGIRISKDOLIBARR_EVALUATOR_DURATION", $evaluatorDuration, 'integer', 0, '', $conf->entity);
}
Expand Down Expand Up @@ -193,6 +212,11 @@
'name' => 'RiskListParentView',
'description' => 'RiskListParentViewDescription',
'code' => 'DIGIRISKDOLIBARR_RISK_LIST_PARENT_VIEW',
],
'CategoryOnRisk' => [
'name' => 'CategoryOnRisk',
'description' => 'CategoryOnRiskDescription',
'code' => 'DIGIRISKDOLIBARR_CATEGORY_ON_RISK',
],
'ShowInheritedRisksInDocuments' => [
'name' => 'ShowInheritedRisksInDocuments',
Expand Down Expand Up @@ -278,6 +302,12 @@
print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="EnvironmentProject">' . $langs->trans("EnvironmentProject") . '</label></td><td>';
$formproject->select_projects(-1, $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT, 'EnvironmentProject', 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 'maxwidth500');
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create&socid=' . $soc->id) . '"><span class="fa fa-plus-circle valignmiddle" title="' . $langs->trans("AddProject") . '"></span></a>';
print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="projectContactType">' . $langs->trans("DefaultProjectContactType") . '</label></td><td class="maxwidth500">';
$formcompany->selectTypeContact($project, $conf->global->DIGIRISKDOLIBARR_DEFAULT_PROJECT_CONTACT_TYPE, 'project_contact_type', 'internal', 'position', 0, 'minwidth500');
print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
Expand Down
19 changes: 15 additions & 4 deletions class/actions_digiriskdolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function constructCategory($parameters, &$object)
{
$error = 0; // Error counter

if (($parameters['currentcontext'] == 'category')) {
if (strpos($parameters['context'], 'category') !== false) {
$tags = [
'accident' => [
'id' => 436302001,
Expand All @@ -92,6 +92,12 @@ public function constructCategory($parameters, &$object)
'obj_class' => 'FirePermit',
'obj_table' => 'digiriskdolibarr_firepermit',
],
'risk' => [
'id' => 436302004,
'code' => 'risk',
'obj_class' => 'Risk',
'obj_table' => 'digiriskdolibarr_risk',
],
];
}

Expand Down Expand Up @@ -210,7 +216,7 @@ public function printCommonFooter($parameters)
$fileDir = $upload_dir . '/' . $dirFiles;
$urlSource = $_SERVER['PHP_SELF'] . '?id=' . $object->id;

$out = saturne_show_documents('digiriskdolibarr:TicketDocument', $dirFiles, $fileDir, $urlSource, $user->rights->ticket->write, $user->rights->ticket->delete, getDolGlobalString('DIGIRISKDOLIBARR_TICKET_DEFAULT_MODEL'), 1, 0, 0, 0, '', '', '', '', '', $object); ?>
$out = saturne_show_documents('digiriskdolibarr:TicketDocument', $dirFiles, $fileDir, $urlSource, $user->rights->ticket->write, $user->rights->ticket->delete, getDolGlobalString('DIGIRISKDOLIBARR_TICKETDOCUMENT_DEFAULT_MODEL'), 1, 0, 0, 0, '', '', '', '', '', $object); ?>

<script>
jQuery('.fichehalfleft .div-table-responsive-no-min').first().append(<?php echo json_encode($out); ?>);
Expand Down Expand Up @@ -568,7 +574,7 @@ public function doActions($parameters, $object, $action)
$permissiontoadd = $user->rights->ticket->write;
}

if ($action == 'remove_file') {
if ($action == 'remove_file' && preg_match('/\bticketdocument\b/', GETPOST('file'))) {
$upload_dir = $conf->digiriskdolibarr->multidir_output[$conf->entity ?? 1];
$permissiontodelete = $user->rights->ticket->delete;
}
Expand Down Expand Up @@ -968,6 +974,10 @@ public function saturneAdminDocumentData(array $parameters): int
'documentType' => 'listingrisksaction',
'picto' => 'fontawesome_fa-exclamation_fas_#d35968'
],
'ListingRisksEnvironmentalAction' => [
'documentType' => 'listingrisksenvironmentalaction',
'picto' => 'fontawesome_fa-exclamation_fas_#d35968'
],
'ListingRisksPhoto' => [
'documentType' => 'listingrisksphoto',
'picto' => 'fontawesome_fa-images_fas_#d35968'
Expand Down Expand Up @@ -1031,7 +1041,8 @@ public function saturneAdminAdditionalConfig(array $parameters): int
{
$additionalConfig = [
'ShowPictoName' => 'DIGIRISKDOLIBARR_DOCUMENT_SHOW_PICTO_NAME',
'GenerateZipArchiveWithDigiriskElementDocuments' => 'DIGIRISKDOLIBARR_GENERATE_ARCHIVE_WITH_DIGIRISKELEMENT_DOCUMENTS'
'GenerateZipArchiveWithDigiriskElementDocuments' => 'DIGIRISKDOLIBARR_GENERATE_ARCHIVE_WITH_DIGIRISKELEMENT_DOCUMENTS',
'RiskAssessmentColor' => 'DIGIRISKDOLIBARR_PROJECTDOCUMENT_DISPLAY_RISKASSESSMENT_COLOR'
];

// Do something only for the current context.
Expand Down
45 changes: 16 additions & 29 deletions class/digiriskdocuments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,18 @@ public function __construct(DoliDB $db, $module, $element)
parent::__construct($db, $module, $element);
}

/**
* Create object into database
*
* @param User $user User that creates
* @param bool $notrigger false=launch triggers after, true=disable triggers
* @return int 0 < if KO, ID of created object if OK
*/
public function create(User $user, bool $notrigger = false, object $parentObject = null): int
{
$now = dol_now();

$this->ref_ext = 'digirisk_' . $this->ref;
$this->date_creation = $this->db->idate($now);
$this->tms = $now;
$this->import_key = "";
$this->status = 1;
$this->type = $this->element;
$this->module_name = $this->module;
$this->fk_user_creat = $user->id ?: 1;
$this->parent_id = $parentObject->id;
$this->parent_type = $parentObject->element;

$this->DigiriskFillJSON();
return $this->createCommon($user, $notrigger);
}
/**
* Create object into database
*
* @param User $user User that creates
* @param bool $notrigger false = launch triggers after, true = disable triggers
* @return int 0 < if KO, ID of created object if OK
*/
public function create(User $user, bool $notrigger = false, object $parentObject = null): int
{
$this->DigiriskFillJSON();
return parent::create($user, $notrigger, $parentObject);
}

/**
* Function for JSON filling before saving in database
Expand Down Expand Up @@ -230,15 +217,15 @@ public function fillRiskData(Odf $odfHandler, $object, Translate $outputLangs, $
}

if ($conf->global->DIGIRISKDOLIBARR_SHOW_RISK_ORIGIN) {
$nomElement .= (!empty($conf->global->DIGIRISKDOLIBARR_SHOW_SHARED_RISKS) ? 'S' . $element->entity . ' - ' : '') . $element->ref . ' - ' . $element->label;
$nomElement .= (!empty($conf->global->DIGIRISKDOLIBARR_SHOW_SHARED_RISKS) ? 'S' . $element->entity : '') . ' - ' . $element->ref . ' - ' . $element->label;
if ($line->fk_element != $line->appliedOn) {
$nomElement .= "\n" . ($dash > 0 ? ' - ' : '') . $langs->trans('AppliedOn') . ' ' . $linked_element->ref . ' - ' . $linked_element->label;
$nomElement .= ($dash > 0 ? ' - ' : '') . $langs->trans('AppliedOn') . ' ' . $linked_element->ref . ' - ' . $linked_element->label;
}
} else {
if ($linked_element->id > 0) {
$nomElement .= "\n" . ($dash > 0 ? ' - ' : '') . $linked_element->ref . ' - ' . $linked_element->label;
$nomElement .= ($dash > 0 ? ' - ' : '') . $linked_element->ref . ' - ' . $linked_element->label;
} else {
$nomElement .= "\n" . ($dash > 0 ? ' - ' : '') . $element->ref . ' - ' . $element->label;
$nomElement .= ($dash > 0 ? ' - ' : '') . $element->ref . ' - ' . $element->label;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/* Copyright (C) 2024 EVARISK <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file class/digiriskdolibarrdocuments/listingrisksenvironmentalaction.class.php
* \ingroup digiriskdolibarr
* \brief This file is a class file for ListingRisksEnvironmentalAction
*/

// Load DigiriskDolibarr libraries
require_once __DIR__ . '/../digiriskdocuments.class.php';

/**
* Class for ListingRisksEnvironmentalAction
*/
class ListingRisksEnvironmentalAction extends DigiriskDocuments
{
/**
* @var string Module name
*/
public $module = 'digiriskdolibarr';

/**
* @var string Element type of object
*/
public $element = 'listingrisksenvironmentalaction';

/**
* Constructor
*
* @param DoliDb $db Database handler
*/
public function __construct(DoliDB $db)
{
parent::__construct($db, $this->module, $this->element);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/* Copyright (C) 2024 EVARISK <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file class/digiriskdolibarrdocuments/listingrisksenvironmentaldocument.class.php
* \ingroup digiriskdolibarr
* \brief This file is a class file for ListingRisksEnvironmentalDocument
*/


// Load DigiriskDolibarr librairies
require_once __DIR__ . '/../digiriskdocuments.class.php';

/**
* Class for ListingRisksEnvironmentalDocument
*/

class ListingRisksEnvironmentalDocument extends DigiriskDocuments
{
/**
* @var string Module name
*/
public $module = 'digiriskdolibarr';

/**
* @var string Element type of object
*/
public $element = 'listingrisksenvironmentaldocument';

/**
* Constructor
*
* @param DoliDb $db Database handler
*/
public function __construct(DoliDB $db)
{
parent::__construct($db, $this->module, $this->element);
}
}
3 changes: 2 additions & 1 deletion class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ public function getBannerTabContent(): array
}
$morehtmlref .= '<br>';
$this->fetch($this->id);
$this->fk_project = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
$riskType = GETPOST('type');
$this->fk_project = $riskType == 'riskenvironmental' ? $conf->global->DIGIRISKDOLIBARR_ENVIRONMENT_PROJECT : $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
$moreParams['project']['disable_edit'] = 1;

return [$morehtmlref, $moreParams];
Expand Down
15 changes: 12 additions & 3 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Risk extends SaturneObject
'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 0,),
'category' => array('type' => 'varchar(255)', 'label' => 'RiskCategory', 'enabled' => '1', 'position' => 21, 'notnull' => 0, 'visible' => 1,),
'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => '1', 'position' => 23, 'notnull' => 0, 'visible' => -1,),
'type' => array('type' => 'varchar(255)', 'label' => 'Type', 'enabled' => '1', 'position' => 24, 'notnull' => 1, 'visible' => 0, 'default' => '(PROV)'),
'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => '1', 'position' => 110, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid',),
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 120, 'notnull' => -1, 'visible' => 0,),
'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php', 'label' => 'Projet', 'enabled' => '1', 'position' => 140, 'notnull' => 1, 'visible' => 0,),
Expand All @@ -103,6 +104,7 @@ class Risk extends SaturneObject
public $status;
public $category;
public $description;
public $type = 'risk';
public $fk_user_creat;
public $fk_user_modif;
public $fk_element;
Expand Down Expand Up @@ -148,6 +150,12 @@ public function __construct(DoliDB $db)
]
];

$riskType = GETPOST('type');
if ($riskType == 'riskenvironmental') {
$this->type = 'riskenvironmental';
$this->picto = 'fontawesome_fa-leaf_fas_#d35968';
}

parent::__construct($db, $this->module, $this->element);
}

Expand Down Expand Up @@ -181,10 +189,10 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
$objects = $object->getActiveDigiriskElements();

$risk = new Risk($this->db);
$riskList = $risk->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . self::STATUS_VALIDATED . $moreParams['filter']], 'AND', $get_shared_data ? 1 : 0);
$riskList = $risk->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . self::STATUS_VALIDATED . $moreParams['filterRisk']], 'AND', $get_shared_data ? 1 : 0);

$riskAssessment = new RiskAssessment($this->db);
$riskAssessmentList = $riskAssessment->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . RiskAssessment::STATUS_VALIDATED . $moreParams['filter']], 'AND', $get_shared_data ? 1 : 0);
$riskAssessmentList = $riskAssessment->fetchAll('', '', 0, 0, ['customsql' => 'status = ' . RiskAssessment::STATUS_VALIDATED . $moreParams['filterRiskAssessment']], 'AND', $get_shared_data ? 1 : 0);

if (is_array($riskAssessmentList) && !empty($riskAssessmentList)) {
foreach ($riskAssessmentList as $riskAssessmentSingle) {
Expand Down Expand Up @@ -338,7 +346,8 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
public function getDangerCategories()
{
$json_categories = file_get_contents(DOL_DOCUMENT_ROOT . '/custom/digiriskdolibarr/js/json/dangerCategories.json');
return json_decode($json_categories, true);
$jsonArray = json_decode($json_categories, true);
return $jsonArray[0][$this->type];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
// Replace tags of lines.
try {
$this->setAttendantsSegment($odfHandler, $outputLangs, $moreParam);

$risks = $moreParam['gp_ut_id'] > 0 ? $risk->fetchRisksOrderedByCotation($moreParam['gp_ut_id'], true, $conf->global->DIGIRISKDOLIBARR_SHOW_INHERITED_RISKS_IN_DOCUMENTS, $conf->global->DIGIRISKDOLIBARR_SHOW_SHARED_RISKS) : [];
$moreParam['filterRisk'] = ' AND t.type = "risk"';
$risks = $moreParam['gp_ut_id'] > 0 ? $risk->fetchRisksOrderedByCotation($moreParam['gp_ut_id'], true, $conf->global->DIGIRISKDOLIBARR_SHOW_INHERITED_RISKS_IN_DOCUMENTS, $conf->global->DIGIRISKDOLIBARR_SHOW_SHARED_RISKS, $moreParam) : [];
$digiriskDocument->fillRiskData($odfHandler, $this, $outputLangs, [], null, $risks);

$moreParam['task_type'] = 'cur_task';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$filter = " AND (t.date_creation BETWEEN '$startDate' AND '$endDate' OR t.tms BETWEEN '$startDate' AND '$endDate')";
$specificFilter = " AND (t.datec BETWEEN '$startDate' AND '$endDate' OR t.tms BETWEEN '$startDate' AND '$endDate')";

$moreParam['filter'] = $filter;
$moreParam['specificFilter'] = $specificFilter;
$moreParam['filter'] = $filter;
$moreParam['filterRisk'] = $filter . ' AND t.type = "risk"';
$moreParam['filterRiskAssessment'] = $filter;
$moreParam['specificFilter'] = $specificFilter;
}

$groupments = [];
Expand Down
Loading

0 comments on commit e77e36a

Please sign in to comment.