diff --git a/accident_card.php b/accident_card.php
index 36d849e5e..0911a6d00 100644
--- a/accident_card.php
+++ b/accident_card.php
@@ -48,7 +48,7 @@
require_once __DIR__ . '/lib/digiriskdolibarr_function.lib.php';
require_once __DIR__ . '/lib/digiriskdolibarr_accident.lib.php';
require_once __DIR__ . '/core/modules/digiriskdolibarr/digiriskelement/accident/mod_accident_standard.php';
-require_once __DIR__ . '/core/modules/digiriskdolibarr/digiriskelement/accidentdet/mod_accidentdet_standard.php';
+require_once __DIR__ . '/core/modules/digiriskdolibarr/digiriskelement/accident_workstop/mod_accident_workstop_standard.php';
//require_once __DIR__ . '/core/modules/digiriskdolibarr/digiriskdocuments/accidentdocument/mod_accidentdocument_standard.php';
//require_once __DIR__ . '/core/modules/digiriskdolibarr/digiriskdocuments/accidentdocument/modules_accidentdocument.php';
@@ -73,8 +73,7 @@
$object = new Accident($db);
$preventionplan = new PreventionPlan($db);
$preventionplanline = new PreventionPlanLine($db);
-$signatory = new AccidentSignature($db);
-$objectline = new AccidentLine($db);
+$objectline = new AccidentWorkStop($db);
//$accidentdocument = new AccidentDocument($db);
$risk = new Risk($db);
$contact = new Contact($db);
@@ -85,7 +84,7 @@
$digiriskresources = new DigiriskResources($db);
$project = new Project($db);
$refAccidentMod = new $conf->global->DIGIRISKDOLIBARR_ACCIDENT_ADDON($db);
-$refAccidentDetMod = new $conf->global->DIGIRISKDOLIBARR_ACCIDENTDET_ADDON($db);
+$refAccidentWorkStopMod = new $conf->global->DIGIRISKDOLIBARR_ACCIDENT_WORKSTOP_ADDON($db);
// Load object
$object->fetch($id);
@@ -309,7 +308,7 @@
// Initialize object accident line
$objectline->date_creation = $object->db->idate($now);
- $objectline->ref = $refAccidentDetMod->getNextValue($objectline);
+ $objectline->ref = $refAccidentWorkStopMod->getNextValue($objectline);
$objectline->entity = $conf->entity;
$objectline->workstop_days = $workstop_days;
$objectline->fk_accident = $parent_id;
@@ -982,7 +981,7 @@
print '
';
print '';
- print $refAccidentDetMod->getNextValue($objectline);
+ print $refAccidentWorkStopMod->getNextValue($objectline);
print ' | ';
$coldisplay++;
diff --git a/accident_list.php b/accident_list.php
index 1e02b98d7..e069744b0 100644
--- a/accident_list.php
+++ b/accident_list.php
@@ -68,7 +68,6 @@
// Initialize technical objects
$accident = new Accident($db);
-$signatory = new AccidentSignature($db);
$preventionplan = new PreventionPlan($db);
$societe = new Societe($db);
$contact = new Contact($db);
diff --git a/accident_metadata.php b/accident_metadata.php
index 3f45cfcb1..f9047433b 100644
--- a/accident_metadata.php
+++ b/accident_metadata.php
@@ -50,10 +50,7 @@
// Get parameters
$id = GETPOST('id', 'int');
-$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
-$confirm = GETPOST('confirm', 'alpha');
-$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'accidentmetadata'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
@@ -61,19 +58,17 @@
// Initialize technical objects
$object = new Accident($db);
$accidentmetadata = new AccidentMetaData($db);
+$accidentlesion = new AccidentLesion($db);
$project = new Project($db);
// Load object
$object->fetch($id);
-$accidentmetadata = $accidentmetadata->fetchFromParent($object->id);
$hookmanager->initHooks(array('accidentmetadata', 'globalmetadata')); // Note that conf->hooks_modules contains array
-$upload_dir = $conf->digiriskdolibarr->multidir_output[isset($object->entity) ? $object->entity : 1];
// Security check
$permissiontoread = $user->rights->digiriskdolibarr->accident->read;
$permissiontoadd = $user->rights->digiriskdolibarr->accident->write;
-$permissiontodelete = $user->rights->digiriskdolibarr->accident->delete;
if (!$permissiontoread) accessforbidden();
@@ -86,7 +81,6 @@
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
- $error = 0;
$backurlforlist = dol_buildpath('/digiriskdolibarr/accident_list.php', 1);
@@ -97,16 +91,8 @@
}
}
- if (GETPOST('cancel')) {
- // Cancel fire permit
- $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);
- exit;
- }
-
- // Action to add record
- if ($action == 'add' && $permissiontoadd) {
+ // Action to update record
+ if ($action == 'update' && $permissiontoadd) {
// Get parameters
$relative_location = GETPOST('relative_location');
$lesion_localization = GETPOST('lesion_localization');
@@ -119,7 +105,7 @@
$collateral_victim = GETPOST('collateral_victim');
$police_report = GETPOST('police_report');
$cerfa_link = GETPOST('cerfa_link');
- $fk_accident = GETPOST('parent_id');
+ $fk_accident = GETPOST('id');
// Initialize object AccidentMetaData
$now = dol_now();
@@ -142,70 +128,105 @@
if (!$error) {
$result = $accidentmetadata->create($user, false);
if ($result > 0) {
- // Creation Accident metadata OK
+ // Update Accident metadata 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);
exit;
}
else {
- // Creation Accident metadata KO
+ // Update Accident metadata KO
if (!empty($accidentmetadata->errors)) setEventMessages(null, $accidentmetadata->errors, 'errors');
else setEventMessages($accidentmetadata->error, null, 'errors');
}
} else {
- $action = 'create';
+ $action = 'edit';
}
}
- // Action to update record
- if ($action == 'update' && $permissiontoadd) {
+ // Action to add line
+ if ($action == 'addLine' && $permissiontoadd) {
// Get parameters
- $relative_location = GETPOST('relative_location');
- $lesion_localization = GETPOST('lesion_localization');
- $lesion_nature = GETPOST('lesion_nature');
- $thirdparty_responsibility = GETPOST('thirdparty_responsibility');
- $fatal = GETPOST('fatal');
- $accident_investigation = GETPOST('accident_investigation');
- $accident_investigation_link = GETPOST('accident_investigation_link');
- $accident_location = GETPOST('accident_location');
- $collateral_victim = GETPOST('collateral_victim');
- $police_report = GETPOST('police_report');
- $cerfa_link = GETPOST('cerfa_link');
+ $workstop_days = GETPOST('workstop_days');
+ $parent_id = GETPOST('parent_id');
+
+ // Initialize object accident line
+ $objectline->date_creation = $object->db->idate($now);
+ $objectline->ref = $refAccidentDetMod->getNextValue($objectline);
+ $objectline->entity = $conf->entity;
+ $objectline->workstop_days = $workstop_days;
+ $objectline->fk_accident = $parent_id;
+
+ // Check parameters
+ if (empty($workstop_days)) {
+ setEventMessages($langs->trans('ErrorFieldNotEmpty', $langs->transnoentitiesnoconv('WorkStopDays')), null, 'errors');
+ $error++;
+ }
- // Initialize object AccidentMetaData
- $accidentmetadata = array_shift($accidentmetadata);
+ if (!$error) {
+ $result = $objectline->insert($user, false);
+ if ($result > 0) {
+ // Creation accident line OK
+ setEventMessages($langs->trans('AddAccidentLine').' '.$objectline->ref, array());
+ $objectline->call_trigger('ACCIDENTDET_CREATE', $user);
+ $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);
+ exit;
+ }
+ else {
+ // Creation accident line KO
+ if (!empty($objectline->errors)) setEventMessages(null, $objectline->errors, 'errors');
+ else setEventMessages($objectline->error, null, 'errors');
+ }
+ }
+ }
- $now = dol_now();
- $accidentmetadata->tms = $now;
- $accidentmetadata->relative_location = $relative_location;
- $accidentmetadata->lesion_localization = $lesion_localization;
- $accidentmetadata->lesion_nature = $lesion_nature;
- $accidentmetadata->thirdparty_responsibility = $thirdparty_responsibility;
- $accidentmetadata->fatal = $fatal;
- $accidentmetadata->accident_investigation = $accident_investigation;
- $accidentmetadata->accident_investigation_link = $accident_investigation_link;
- $accidentmetadata->accident_location = $accident_location;
- $accidentmetadata->collateral_victim = $collateral_victim;
- $accidentmetadata->police_report = $police_report;
- $accidentmetadata->cerfa_link = $cerfa_link;
+ // Action to update line
+ if ($action == 'updateLine' && $permissiontoadd) {
+ // Get parameters
+ $workstop_days = GETPOST('workstop_days');
+ $parent_id = GETPOST('parent_id');
+
+ $objectline->fetch($lineid);
+
+ // Initialize object accident line
+ $objectline->workstop_days = $workstop_days;
+ $objectline->fk_accident = $parent_id;
if (!$error) {
- $result = $accidentmetadata->update($user, false);
+ $result = $objectline->update($user, false);
if ($result > 0) {
- // Update Accident metadata OK
+ // Update accident line OK
+ setEventMessages($langs->trans('UpdateAccidentLine').' '.$objectline->ref, array());
$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
+ $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $parent_id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: " . $urltogo);
exit;
}
else {
- // Update Accident metadata KO
- if (!empty($accidentmetadata->errors)) setEventMessages(null, $accidentmetadata->errors, 'errors');
- else setEventMessages($accidentmetadata->error, null, 'errors');
+ // Update accident line KO
+ if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
+ else setEventMessages($object->error, null, 'errors');
}
+ }
+ }
+
+ // Action to delete line
+ if ($action == 'deleteline' && $permissiontodelete) {
+ $objectline->fetch($lineid);
+ $result = $objectline->delete($user, false);
+ if ($result > 0) {
+ // Deletion accident line OK
+ setEventMessages($langs->trans('DeleteAccidentLine').' '.$objectline->ref, array());
+ $urltogo = str_replace('__ID__', $result, $backtopage);
+ $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $parent_id, $urltogo); // New method to autoselect project after a New on another form object creation
+ header("Location: " . $urltogo);
+ exit;
} else {
- $action = 'edit';
+ // Deletion accident line KO
+ if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
+ else setEventMessages($object->error, null, 'errors');
}
}
}
@@ -217,9 +238,12 @@
$form = new Form($db);
$formother = new FormOther($db);
+$morewhere = ' AND fk_accident = ' . $object->id;
+$morewhere .= ' AND status = 1';
+
+$accidentmetadata->fetch(0, '', $morewhere);
+
$title = $langs->trans("AccidentMetaData");
-$title_create = $langs->trans("NewAccidentMetaData");
-$title_edit = $langs->trans("ModifyAccidentMetaData");
$object->picto = 'accident@digiriskdolibarr';
$help_url = 'FR:Module_DigiriskDolibarr';
@@ -228,253 +252,112 @@
llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss);
-// Part to create
-if ($action == 'create') {
- print load_fiche_titre($title_create, '', "digiriskdolibarr32px@digiriskdolibarr");
-
- print '';
-}
-
-// Part to edit record
-if (($id || $ref) && $action == 'edit') {
- print load_fiche_titre($title_edit, '', "digiriskdolibarr32px@digiriskdolibarr");
-
- print '';
-}
-
-// Part to show record
-if ((empty($action) || ($action != 'create' && $action != 'edit'))) {
- // Object metadata
- // ------------------------------------------------------------
- $res = $object->fetch_optionals();
-
- $head = accidentPrepareHead($object);
- print dol_get_fiche_head($head, 'accidentMetadata', $title, -1, "digiriskdolibarr@digiriskdolibarr");
-
- dol_strlen($object->label) ? $morehtmlref = ''. ' - ' .$object->label . '' : '';
- $morehtmlref .= '';
- // Project
- $project->fetch($object->fk_project);
- $morehtmlref .= $langs->trans('Project').' : '.getNomUrlProject($project, 1, 'blank');
- $morehtmlref .= '
';
-
- digirisk_banner_tab($object, 'ref', '', 0, 'ref', 'ref', $morehtmlref, '', 0, '', $object->getLibStatut(5));
-
- print '';
- print '
';
- print '
';
-
- //Unset for order
-
- $object = array_shift($accidentmetadata);
-
- include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
-
- print '
';
- print '
';
- print '
';
-
- print dol_get_fiche_end();
-
- if ($object->id > 0) {
- // Buttons for actions
- print '';
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-
- if (empty($reshook)) {
- print '
fk_accident . '&action=edit') : '#') . '">' . $langs->trans("Modify") . '';
- }
- print '
';
- }
- if ($permissiontoadd) {
- print '';
- } else {
- print '
';
- }
-
- $MAXEVENT = 10;
-
- $morehtmlright = '
';
- $morehtmlright .= $langs->trans("SeeAll");
- $morehtmlright .= '';
-
- // List of actions on element
- include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
- $formactions = new FormActions($db);
- $somethingshown = $formactions->showactions($object, $object->element . '@digiriskdolibarr', '', 1, '', $MAXEVENT, '', $morehtmlright);
-
- print '
';
-}
-
+// Object metadata
+// ------------------------------------------------------------
+$head = accidentPrepareHead($object);
+print dol_get_fiche_head($head, 'accidentMetadata', $title, -1, "digiriskdolibarr@digiriskdolibarr");
+
+dol_strlen($object->label) ? $morehtmlref = ''. ' - ' .$object->label . '' : '';
+$morehtmlref .= '';
+// Project
+$project->fetch($object->fk_project);
+$morehtmlref .= $langs->trans('Project').' : '.getNomUrlProject($project, 1, 'blank');
+$morehtmlref .= '
';
+
+digirisk_banner_tab($object, 'ref', '', 0, 'ref', 'ref', $morehtmlref, '', 0, '', $object->getLibStatut(5));
+
+print '';
+print '
';
+print '
';
+
+//Unset for order
+
+print load_fiche_titre($title, '', "digiriskdolibarr32px@digiriskdolibarr");
+
+print '';
+print '';
+print '';
+
+print dol_get_fiche_end();
// End of page
llxFooter();
$db->close();