Skip to content

Commit

Permalink
Merge branch 'develop' into fix_fetchfromparent
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka authored Oct 9, 2023
2 parents c582350 + 79ded6f commit bbdf8a3
Show file tree
Hide file tree
Showing 22 changed files with 809 additions and 1,354 deletions.
186 changes: 186 additions & 0 deletions admin/event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
*
* 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/>.
* or see https://www.gnu.org/
*/

/**
* \file admin/event.php
* \ingroup digiriskdolibarr
* \brief Digiriskdolibarr config event auto page.
*/

// Load DigiriskDolibarr environment
if (file_exists('../digiriskdolibarr.main.inc.php')) {
require_once __DIR__ . '/../digiriskdolibarr.main.inc.php';
} elseif (file_exists('../../digiriskdolibarr.main.inc.php')) {
require_once __DIR__ . '/../../digiriskdolibarr.main.inc.php';
} else {
die('Include of digiriskdolibarr main fails');
}

global $conf, $db, $langs, $module, $user;

// Libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once __DIR__ . '/../lib/digiriskdolibarr.lib.php';

saturne_check_access($user->admin);

// Load translation files required by the page
saturne_load_langs(['admin', 'other', 'agenda']);

$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'alpha');
$searchEvent = GETPOST('search_event', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');

// Get list of triggers available
$triggers = saturne_fetch_dictionary('c_digiriskdolibarr_action_trigger', 'ASC', 't.rowid');

/*
* Actions
*/

// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$searchEvent = '';
$action = '';
}

if (GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { // To avoid the save when we click on search
$action = '';
}

if ($action == "save" && empty($cancel)) {
$db->begin();

foreach ($triggers as $trigger) {
$keyparam = 'DIGIRISKDOLIBARR_MAIN_AGENDA_ACTIONAUTO_'.$trigger->ref;
if ($searchEvent === '' || preg_match('/'.preg_quote($searchEvent, '/').'/i', $keyparam)) {
$res = dolibarr_set_const($db, $keyparam, GETPOST($keyparam, 'alpha') == 'on' ? 1 : 0, 'integer', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
}
}

if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
$db->commit();
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
$db->rollback();
}
}

/*
* View
*/

$form = new Form($db);

$title = $langs->trans("ModuleSetup", $moduleName);
$helpUrl = 'FR:Module_DigiriskDolibarr';

saturne_header(0, '', $title, $helpUrl);

// Subheader
$linkback = '<a href="' . ($backtopage ?: DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1') . '">' . $langs->trans("BackToModuleList") . '</a>';

print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');

print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="save">';

// Configuration header
$head = digiriskdolibarr_admin_prepare_head();
print dol_get_fiche_head($head, 'event', '', -1, $module->picto);

print load_fiche_titre('<i class="fas fa-calendar-alt"></i> ' . $langs->trans('ConfTrigger'), '', '');
print '<hr>';

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('Name') . '</td>';
print '<td>' . $langs->trans('Description') . '</td>';
print '<td class="center">' . $langs->trans('Status') . '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('AdvancedTriggers');
print '</td><td>';
print $langs->trans('AdvancedTriggersDescription', ucfirst($module));
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_ADVANCED_TRIGGER');
print '</td>';
print '</tr>';
print '</table>';

print load_fiche_titre($langs->trans('ConfEventAuto'), '', '');

print '<span class="opacitymedium">'.$langs->trans("DigiriskEventAutoDesc").'</span><br>';
print "<br>\n";

print '<div class="div-table-responsive">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td class="liste_titre"><input type="text" name="search_event" value="'.dol_escape_htmltag($searchEvent).'"></td>';
print '<td class="liste_titre"></td>';
// Action column
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
print '</tr>';
print '</tr>'.'\n';

$param = '';
$param .= '&search_event='.urlencode($searchEvent);

print '<tr class="liste_titre">';
print '<th class="liste_titre" colspan="2">'.$langs->trans("DigiriskActionsEvents").'</th>';
print '<th class="liste_titre"><a href="'.$_SERVER["PHP_SELF"].'?action=selectall'.($param ? $param : '').'">'.$langs->trans("All").'</a>/<a href="'.$_SERVER["PHP_SELF"].'?action=selectnone'.($param ? $param : '').'">'.$langs->trans("None").'</a></th>';
print '</tr>'.'\n';

// Show each trigger (list is in c_digiriskdolibarr_action_trigger)
if (!empty($triggers)) {
foreach ($triggers as $trigger) {
if ($searchEvent === '' || preg_match('/' . preg_quote($searchEvent, '/') . '/i', $trigger->ref)) {
print '<tr class="oddeven">';
print '<td>' . $trigger->ref . '</td>';
print '<td>' . $langs->trans($trigger->label) . '</td>';
print '<td class="right">';
$key = 'DIGIRISKDOLIBARR_MAIN_AGENDA_ACTIONAUTO_' . $trigger->ref;
$value = $conf->global->$key;
print '<input class="oddeven" type="checkbox" name="' . $key . '"' . ((($action == 'selectall' || $value) && $action != "selectnone") ? ' checked' : '') . '>';
print '</td></tr>';
}
}
}
print '</table>';
print '</div>';

print $form->buttonsSaveCancel();
print '</form>';
print '<br>';

// Page end
print dol_get_fiche_end();
llxFooter();
$db->close();
89 changes: 87 additions & 2 deletions class/accident.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,59 @@ public function getGravityRate() {
}

/**
* Return banner tab content.
* Write information of trigger description
*
* @param Object $object Object calling the trigger
* @return string Description to display in actioncomm->note_private
*/
public function getTriggerDescription(SaturneObject $object): string
{
global $conf, $langs;

require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';

$userVictim = new User($this->db);
$userEmployer = new User($this->db);
$userVictim->fetch($object->fk_user_victim);
$userEmployer->fetch($object->fk_user_employer);

//1 : Accident in DU / GP, 2 : Accident in society, 3 : Accident in another location
switch ($object->external_accident) {
case 1:
if (!empty($object->fk_standard)) {
require_once __DIR__ . '/digiriskstandard.class.php';
$digiriskStandard = new DigiriskStandard($this->db);
$digiriskStandard->fetch($object->fk_standard);
$accidentLocation = $digiriskStandard->ref . " - " . $conf->global->MAIN_INFO_SOCIETE_NOM;
} else if (!empty($object->fk_element)) {
require_once __DIR__ . '/digiriskelement.class.php';
$digiriskElement = new DigiriskElement($this->db);
$digiriskElement->fetch($object->fk_element);
$accidentLocation = $digiriskElement->ref . " - " . $digiriskElement->label;
}
break;
case 2:
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
$society = new Societe($this->db);
$society->fetch($object->fk_soc);
$accidentLocation = $society->ref . " - " . $society->label;
case 3:
$accidentLocation = (dol_strlen($object->accident_location) > 0 ? $object->accident_location : $langs->trans('NoData'));
break;
}

$ret = parent::getTriggerDescription($object);
$ret .= $langs->trans('UserVictim') . ' : ' . $userVictim->firstname . $userVictim->lastname . '<br>';
$ret .= $langs->trans('UserEmployer') . ' : ' . $userEmployer->firstname . $userEmployer->lastname . '<br>';
$ret .= $langs->trans('AccidentLocation') . ' : ' . $accidentLocation . '<br>';
$ret .= $langs->trans('AccidentType') . ' : ' . ($object->accident_type ? $langs->trans('CommutingAccident') : $langs->trans('WorkAccidentStatement')) . '<br>';
$ret .= (dol_strlen($object->accident_date) > 0 ? $langs->trans('AccidentDate') . ' : ' . dol_print_date($object->accident_date, 'dayhoursec') . '<br>' : '');

return $ret;
}

/**
* Return banner tab content.
* @return array
* @throws Exception
*/
Expand Down Expand Up @@ -774,7 +825,6 @@ public function __construct(DoliDB $db)
return parent::__construct($db, $this->module, $this->element);
}

/**
* Load object in memory from the database
*
* @param int $parent_id Id parent object
Expand All @@ -787,6 +837,24 @@ public function fetchFromParent(int $parent_id)

return $this->fetchAll('', '', 0, 0, $filter);
}

* Write information of trigger description
*
* @param Object $object Object calling the trigger
* @return string Description to display in actioncomm->note_private
*/
public function getTriggerDescription(SaturneObject $object): string
{
global $langs;

$ret = parent::getTriggerDescription($object);
$ret .= $langs->transnoentities('WorkStopDays') . ' : ' . $object->workstop_days . '<br>';
$ret .= $langs->transnoentities('WorkStopDocument') . ' : ' . (!empty($object->declaration_link) ? $object->declaration_link : 'N/A') . '<br>';
$ret .= (dol_strlen($object->date_start_workstop) > 0 ? $langs->transnoentities('DateStartWorkStop') . ' : ' . dol_print_date($object->date_start_workstop, 'dayhoursec') . '<br>' : '');
$ret .= (dol_strlen($object->date_end_workstop) > 0 ? $langs->transnoentities('DateEndWorkStop') . ' : ' . dol_print_date($object->date_end_workstop, 'dayhoursec') . '<br>' : '');

return $ret;
}
}

/**
Expand Down Expand Up @@ -1041,4 +1109,21 @@ public function __construct(DoliDB $db)
{
return parent::__construct($db, $this->module, $this->element);
}

/**
* Write information of trigger description
*
* @param Object $object Object calling the trigger
* @return string Description to display in actioncomm->note_private
*/
public function getTriggerDescription(SaturneObject $object): string
{
global $langs;

$ret = parent::getTriggerDescription($object);
$ret .= $langs->transnoentities('LesionLocalization') . ' : ' . $object->lesion_localization . '<br>';
$ret .= $langs->transnoentities('LesionNature') . ' : ' . $object->lesion_nature . '<br>';

return $ret;
}
}
37 changes: 26 additions & 11 deletions class/digiriskdocuments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public function __construct(DoliDB $db, $module, $element)
*/
public function create(User $user, bool $notrigger = false, object $parentObject = null): int
{
global $conf;

$now = dol_now();

$this->ref_ext = 'digirisk_' . $this->ref;
Expand All @@ -72,17 +70,10 @@ public function create(User $user, bool $notrigger = false, object $parentObject
$this->type = $this->element;
$this->module_name = $this->module;
$this->fk_user_creat = $user->id ?: 1;

if ($parentObject->id > 0) {
$this->parent_id = $parentObject->id;
$this->parent_type = $parentObject->element_type ?: $parentObject->element;
} else {
$this->parent_id = $conf->global->DIGIRISKDOLIBARR_ACTIVE_STANDARD;
$this->parent_type = 'digiriskstandard';
}
$this->parent_id = $parentObject->id;
$this->parent_type = $parentObject->element;

$this->DigiriskFillJSON();
$this->element = $this->element . '@digiriskdolibarr';
return $this->createCommon($user, $notrigger);
}

Expand Down Expand Up @@ -408,4 +399,28 @@ public function fillRiskData($odfHandler, $object, $outputlangs, $tmparray, $fil
}

}

/**
* Write information of trigger description
*
* @param Object $object Object calling the trigger
* @return string Description to display in actioncomm->note_private
*/
public function getTriggerDescription(SaturneObject $object): string
{
global $langs;

$className = $object->parent_type;
require_once __DIR__ . '/' . $className .'.class.php';
$parentElement = new $className($this->db);
$parentElement->fetch($object->parent_id);

$ret = parent::getTriggerDescription($object);

$ret .= $langs->transnoentities('ElementType') . ' : ' . $object->parent_type . '</br>';
$ret .= $langs->transnoentities('ParentElement') . ' : ' . $parentElement->ref . ' ' . $parentElement->label . '</br>';
$ret .= $langs->transnoentities('LastMainDoc') . ' : ' . $object->last_main_doc . '<br>';

return $ret;
}
}
7 changes: 2 additions & 5 deletions class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,18 @@ public function getBannerTabContent(): array

$digiriskstandard = new DigiriskStandard($db);

dol_strlen($this->label) ? $morehtmlref = ' - ' . $this->label : '';

// ParentElement
$parent_element = new self($db);
$result = $parent_element->fetch($this->fk_parent);
if ($result > 0) {
$morehtmlref .= '<br>' . $langs->trans("Description") . ' : ' . $this->description;
$morehtmlref .= $langs->trans("Description") . ' : ' . $this->description;
$morehtmlref .= '<br>' . $langs->trans("ParentElement") . ' : ' . $parent_element->getNomUrl(1, 'blank', 1);
} else {
$digiriskstandard->fetch($conf->global->DIGIRISKDOLIBARR_ACTIVE_STANDARD);
$morehtmlref .= '<br>' . $langs->trans("Description") . ' : ' . $this->description;
$morehtmlref .= $langs->trans("Description") . ' : ' . $this->description;
$morehtmlref .= '<br>' . $langs->trans("ParentElement") . ' : ' . $digiriskstandard->getNomUrl(1, 'blank', 1);
}
$morehtmlref .= '<br>';
$linkback = '<a href="' . dol_buildpath('/digiriskdolibarr/view/digiriskelement/risk_list.php', 1) . '">' . $langs->trans("BackToList") . '</a>';
$this->fetch($this->id);
$this->fk_project = $conf->global->DIGIRISKDOLIBARR_DU_PROJECT;
$moreParams['project']['disable_edit'] = 1;
Expand Down
Loading

0 comments on commit bbdf8a3

Please sign in to comment.