Skip to content

Commit 561ad53

Browse files
committed
#2842 [SocialConf] add: Deficiency report management
1 parent c5d4102 commit 561ad53

File tree

3 files changed

+146
-61
lines changed

3 files changed

+146
-61
lines changed

admin/securityconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
$allLinks = $resources->digirisk_dolibarr_fetch_resources();
7272

73-
$hookmanager->initHooks(array('admincompany', 'globaladmin'));
73+
$hookmanager->initHooks(array('adminsecurity', 'globaladmin'));
7474

7575
/*
7676
* Actions

admin/socialconf.php

Lines changed: 141 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@
6565

6666
$allLinks = $resources->digirisk_dolibarr_fetch_resources();
6767

68-
$hookmanager->initHooks(array('admincompany', 'globaladmin'));
68+
$hookmanager->initHooks(array('adminsocial', 'globaladmin'));
6969

70-
$electionDateCSE = dol_mktime(0, 0, 0, GETPOST('date_debutmonth', 'int'), GETPOST('date_debutday', 'int'), GETPOST('date_debutyear', 'int'));
71-
$electionDateDP = dol_mktime(0, 0, 0, GETPOST('date_finmonth', 'int'), GETPOST('date_finday', 'int'), GETPOST('date_finyear', 'int'));
72-
$date = dol_mktime(0, 0, 0, GETPOST('datemonth', 'int'), GETPOST('dateday', 'int'), GETPOST('dateyear', 'int'));
70+
$submissionElectionDateCSE = dol_mktime(0, 0, 0, GETPOST('SubmissionElectionDateCSEmonth', 'int'), GETPOST('SubmissionElectionDateCSEday', 'int'), GETPOST('SubmissionElectionDateCSEyear', 'int'));
71+
$electionDateCSE = dol_mktime(0, 0, 0, GETPOST('date_debutmonth', 'int'), GETPOST('date_debutday', 'int'), GETPOST('date_debutyear', 'int'));
72+
$secondElectionDateCSE = dol_mktime(0, 0, 0, GETPOST('SecondElectionDateCSEmonth', 'int'), GETPOST('SecondElectionDateCSEday', 'int'), GETPOST('SecondElectionDateCSEyear', 'int'));
73+
$electionDateDP = dol_mktime(0, 0, 0, GETPOST('date_finmonth', 'int'), GETPOST('date_finday', 'int'), GETPOST('date_finyear', 'int'));
74+
$date = dol_mktime(0, 0, 0, GETPOST('datemonth', 'int'), GETPOST('dateday', 'int'), GETPOST('dateyear', 'int'));
7375

7476
/*
7577
* Actions
@@ -81,18 +83,24 @@
8183

8284
if (empty($reshook)) {
8385
if (($action == 'update' && ! GETPOST("cancel", 'alpha')) || ($action == 'updateedit')) {
84-
$electionDateCSE = GETPOST('ElectionDateCSE', 'none');
85-
$electionDateCSE = explode('/', $electionDateCSE);
86-
$electionDateCSE = $electionDateCSE[2] . '-' . $electionDateCSE[1] . '-' . $electionDateCSE[0];
86+
$submissionElectionDateCSE = GETPOST('SubmissionElectionDateCSE');
87+
$submissionElectionDateCSE = dol_print_date(dol_stringtotime($submissionElectionDateCSE), 'dayrfc');
8788

88-
$electionDateDP = GETPOST('ElectionDateDP', 'none');
89-
$electionDateDP = explode('/', $electionDateDP);
90-
$electionDateDP = $electionDateDP[2] . '-' . $electionDateDP[1] . '-' . $electionDateDP[0];
89+
$electionDateCSE = GETPOST('ElectionDateCSE');
90+
$electionDateCSE = dol_print_date(dol_stringtotime($electionDateCSE), 'dayrfc');
91+
92+
$secondElectionDateCSE = GETPOST('SecondElectionDateCSE');
93+
$secondElectionDateCSE = dol_print_date(dol_stringtotime($secondElectionDateCSE), 'dayrfc');
94+
95+
$electionDateDP = GETPOST('ElectionDateDP');
96+
$electionDateDP = dol_print_date(dol_stringtotime($electionDateDP), 'dayrfc');
9197

9298
dolibarr_set_const($db, "DIGIRISKDOLIBARR_PARTICIPATION_AGREEMENT_INFORMATION_PROCEDURE", GETPOST("modalites", 'none'), 'chaine', 0, '', $conf->entity);
9399
dolibarr_set_const($db, "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_PERMANENT", GETPOST("permanent", 'none'), 'chaine', 0, '', $conf->entity);
94100
dolibarr_set_const($db, "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_OCCASIONAL", GETPOST("occasional", 'none'), 'chaine', 0, '', $conf->entity);
101+
dolibarr_set_const($db, "DIGIRISKDOLIBARR_CSE_SUBMISSION_ELECTION_DATE", $submissionElectionDateCSE, 'date', 0, '', $conf->entity);
95102
dolibarr_set_const($db, "DIGIRISKDOLIBARR_CSE_ELECTION_DATE", $electionDateCSE, 'date', 0, '', $conf->entity);
103+
dolibarr_set_const($db, "DIGIRISKDOLIBARR_CSE_SECOND_ELECTION_DATE", $secondElectionDateCSE, 'date', 0, '', $conf->entity);
96104
dolibarr_set_const($db, "DIGIRISKDOLIBARR_DP_ELECTION_DATE", $electionDateDP, 'date', 0, '', $conf->entity);
97105

98106
$CSEtitulaires = ! empty(GETPOST('TitularsCSE', 'array')) ? GETPOST('TitularsCSE', 'array') : (GETPOST('TitularsCSE', 'int') > 0 ? array(GETPOST('TitularsCSE', 'int')) : array());
@@ -111,11 +119,53 @@
111119
$resources->digirisk_dolibarr_set_resources($db, $user->id, 'HarassmentOfficer', 'user', array($HarassmentOfficer), $conf->entity);
112120
$resources->digirisk_dolibarr_set_resources($db, $user->id, 'HarassmentOfficerCSE', 'user', array($HarassmentOfficerCSE), $conf->entity);
113121

122+
// Submit file
123+
if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
124+
if (!empty($_FILES) && ! empty($_FILES['userfile']['name'][0])) {
125+
if (is_array($_FILES['userfile']['tmp_name'])) {
126+
$userFiles = $_FILES['userfile']['tmp_name'];
127+
} else {
128+
$userFiles = [$_FILES['userfile']['tmp_name']];
129+
}
130+
131+
foreach ($userFiles as $key => $userFile) {
132+
if (empty($_FILES['userfile']['tmp_name'][$key])) {
133+
$error++;
134+
if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
135+
setEventMessages($langs->trans('ErrorFileSizeTooLarge'), [], 'errors');
136+
}
137+
}
138+
}
139+
140+
$fileDir = $conf->digiriskdolibarr->multidir_output[$conf->entity] . '/informationssharing/deficiencyreport/';
141+
if (!file_exists($fileDir)) {
142+
if (dol_mkdir($fileDir) < 0) {
143+
$db->error = $langs->transnoentities('ErrorCanNotCreateDir', $fileDir);
144+
$error++;
145+
}
146+
}
147+
148+
if (!$error) {
149+
digirisk_dol_add_file_process($fileDir, 0, 1, 'userfile', '', null, '', 0);
150+
}
151+
}
152+
}
153+
114154
if ($action != 'updateedit' && ! $error) {
115155
header("Location: " . $_SERVER["PHP_SELF"]);
116156
exit;
117157
}
118158
}
159+
160+
if ($action == 'delete_file' && !empty($user->admin)) {
161+
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
162+
$fileToDelete = $conf->digiriskdolibarr->multidir_output[$conf->entity] . '/informationssharing/deficiencyreport/' . GETPOST('file');
163+
$result = dol_delete_file($fileToDelete);
164+
if ($result > 0) {
165+
setEventMessage($langs->trans('FileWasRemoved', GETPOST('file')));
166+
header('Location: ' . $_SERVER['PHP_SELF']);
167+
}
168+
}
119169
}
120170

121171
/*
@@ -131,7 +181,7 @@
131181
$counter = 0;
132182

133183
$socialResources = array("TitularsCSE", "AlternatesCSE", "TitularsDP", "AlternatesDP");
134-
$socialConsts = array("DIGIRISKDOLIBARR_PARTICIPATION_AGREEMENT_INFORMATION_PROCEDURE", "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_PERMANENT", "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_OCCASIONAL", "DIGIRISKDOLIBARR_CSE_ELECTION_DATE", "DIGIRISKDOLIBARR_DP_ELECTION_DATE");
184+
$socialConsts = array("DIGIRISKDOLIBARR_PARTICIPATION_AGREEMENT_INFORMATION_PROCEDURE", "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_PERMANENT", "DIGIRISKDOLIBARR_DEROGATION_SCHEDULE_OCCASIONAL", 'DIGIRISKDOLIBARR_CSE_SUBMISSION_ELECTION_DATE', "DIGIRISKDOLIBARR_CSE_ELECTION_DATE", "DIGIRISKDOLIBARR_DP_ELECTION_DATE");
135185

136186
$maxnumber = count($socialResources) + count($socialConsts);
137187

@@ -159,13 +209,15 @@
159209

160210
$allLinks = $resources->digirisk_dolibarr_fetch_resources();
161211

162-
$electionDateCSE = $conf->global->DIGIRISKDOLIBARR_CSE_ELECTION_DATE;
163-
$electionDateDP = $conf->global->DIGIRISKDOLIBARR_DP_ELECTION_DATE;
212+
$submissionElectionDateCSE = $conf->global->DIGIRISKDOLIBARR_CSE_SUBMISSION_ELECTION_DATE;
213+
$electionDateCSE = $conf->global->DIGIRISKDOLIBARR_CSE_ELECTION_DATE;
214+
$secondElectionDateCSE = $conf->global->DIGIRISKDOLIBARR_CSE_SECOND_ELECTION_DATE;
215+
$electionDateDP = $conf->global->DIGIRISKDOLIBARR_DP_ELECTION_DATE;
164216

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

168-
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" name="social_form">';
220+
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" name="social_form" enctype="multipart/form-data">';
169221
print '<input type="hidden" name="token" value="' . newToken() . '">';
170222
print '<input type="hidden" name="action" value="update">'; ?>
171223

@@ -225,61 +277,90 @@
225277
if ( ! GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
226278
print '</td></tr>';
227279

228-
/*
229-
* Harassment officer CSE
230-
*/
231-
232-
print '<tr class="liste_titre"><th class="titlefield wordbreak">' . $langs->trans("HarassmentOfficerCSE") . '</th><th>' . $langs->trans("") . '</th></tr>' . "\n";
233-
$HarassmentOfficerCSE = $allLinks['HarassmentOfficerCSE'];
234-
print '<tr>';
235-
print '<td>' . $langs->trans("ActionOnUser") . '</td>';
236-
print '<td colspan="3" class="maxwidthonsmartphone">';
237-
print $form->select_dolusers($HarassmentOfficerCSE->id, 'HarassmentOfficerCSE', 1, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', 'minwidth300');
238-
if ( ! GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
239-
print '</td></tr>';
280+
if (!empty($allLinks['TitularsCSE']) || !empty($allLinks['AlternatesCSE'])) {
281+
/*
282+
* Harassment officer CSE
283+
*/
284+
285+
print '<tr class="liste_titre"><th class="titlefield wordbreak">' . $langs->trans("HarassmentOfficerCSE") . '</th><th>' . $langs->trans("") . '</th></tr>' . "\n";
286+
$HarassmentOfficerCSE = $allLinks['HarassmentOfficerCSE'];
287+
print '<tr>';
288+
print '<td>' . $langs->trans("ActionOnUser") . '</td>';
289+
print '<td colspan="3" class="maxwidthonsmartphone">';
290+
print $form->select_dolusers($HarassmentOfficerCSE->id, 'HarassmentOfficerCSE', 1, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', 'minwidth300');
291+
if ( ! GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
292+
print '</td></tr>';
293+
}
240294

241295
/*
242296
*** ESC -- CSE ***
243297
*/
244298

245299
print '<tr class="liste_titre"><th class="titlefield wordbreak">' . $langs->trans("ESC") . '</th><th>' . $langs->trans("") . '</th></tr>' . "\n";
246300

247-
// * ESC Election Date - Date d'élection du CSE *
248-
249-
print '<tr class="oddeven"><td><label for="ElectionDateCSE">' . $langs->trans("ElectionDate") . '</label></td><td>';
250-
print $form->selectDate(strtotime($electionDateCSE) ? $electionDateCSE : -1, 'ElectionDateCSE', 0, 0, 0, 'social_form', 1, 1);
251-
print '</td></tr>';
252-
253-
// * ESC Titulars - Titulaires CSE *
254-
255-
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
256-
$titulars_cse = $allLinks['TitularsCSE'];
257-
258-
print '<tr>';
259-
print '<td>' . $form->editfieldkey('Titulars', 'TitularsCSE_id', '', $object, 0) . '</td>';
260-
print '<td colspan="3" class="maxwidthonsmartphone">';
261-
262-
263-
print $form->multiselectarray('TitularsCSE', $userlist, $titulars_cse->id, null, null, null, null, "300");
264-
265-
if ( ! GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
266-
301+
// ESC submission election date - Date de présentation de l'élection du CSE
302+
print '<tr class="oddeven"><td><label for="SubmissionElectionDateCSE">' . $langs->trans('SubmissionElectionDate') . '</label></td><td>';
303+
print $form->selectDate(strtotime($submissionElectionDateCSE) ? $submissionElectionDateCSE : -1, 'SubmissionElectionDateCSE', 0, 0, 0, 'social_form', 1, 1);
267304
print '</td></tr>';
268305

269-
// * ESC Alternates - Suppléants CSE *
270-
271-
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
272-
$alternates_cse = $allLinks['AlternatesCSE'];
273-
274-
print '<tr>';
275-
print '<td>' . $form->editfieldkey('Alternates', 'AlternatesCSE_id', '', $object, 0) . '</td>';
276-
print '<td colspan="3" class="maxwidthonsmartphone">';
277-
278-
print $form->multiselectarray('AlternatesCSE', $userlist, $alternates_cse->id, null, null, null, null, "300");
279-
280-
if ( ! GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
281-
282-
print '</td></tr>';
306+
if (!empty($submissionElectionDateCSE)) {
307+
$deficiencyReportDate = dol_time_plus_duree(dol_stringtotime($submissionElectionDateCSE), '30', 'd');
308+
if ((dol_now() > $deficiencyReportDate) || (!empty($secondElectionDateCSE) && dol_now() > dol_stringtotime($secondElectionDateCSE) && empty($allLinks['TitularsCSE']) && empty($allLinks['AlternatesCSE']))) {
309+
// Deficiency report - Procès-verbal de carence
310+
print '<tr class="oddeven"><td><label for="DeficiencyReport">' . $langs->trans('DeficiencyReport') . '</label></td><td>';
311+
print ajax_constantonoff('DIGIRISKDOLIBARR_DEFICIENCY_REPORT');
312+
print '<input class="flat" type="file" name="userfile[]" id="DeficiencyReportFile" />';
313+
$fileArray = dol_dir_list($conf->digiriskdolibarr->multidir_output[$conf->entity] . '/informationssharing/deficiencyreport/', 'files');
314+
// Scan directories
315+
if (is_array($fileArray) && !empty($fileArray)) {
316+
$out = '<div>';
317+
// Show list of found files
318+
foreach ($fileArray as $file) {
319+
$out .= $file['name'] . ' <a class="reposition" href="' . DOL_URL_ROOT . '/document.php?modulepart=digiriskdolibarr&file=informationssharing/deficiencyreport/' . urlencode(basename($file['name'])) . '">' . img_picto('', 'listlight') . '</a>';
320+
$out .= ' <a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=delete_file&token=' . newToken() . '&file=' . urlencode(basename($file['name'])) . '">' . img_picto('', 'delete') . '</a>';
321+
$out .= '<br>';
322+
}
323+
$out .= '</div>';
324+
print $out;
325+
}
326+
print '</td></tr>';
327+
328+
// Deficiency report date - Date du procès-verbal de carence
329+
print '<tr class="oddeven"><td><label for="DeficiencyReportDate">' . $langs->trans('DeficiencyReportDate') . '</label></td><td>';
330+
print dol_print_date($deficiencyReportDate, 'day');
331+
print '</td></tr>';
332+
} else {
333+
// ESC election date - Date d'élection du CSE
334+
print '<tr class="oddeven"><td><label for="ElectionDateCSE">' . $langs->trans("ElectionDate") . '</label></td><td>';
335+
print $form->selectDate(strtotime($electionDateCSE) ? $electionDateCSE : -1, 'ElectionDateCSE', 0, 0, 0, 'social_form', 1, 1);
336+
print '</td></tr>';
337+
338+
// ESC Second election date - Date d'élection du second tour du CSE
339+
print '<tr class="oddeven"><td><label for="SecondElectionDateCSE">' . $langs->trans("SecondElectionDate") . '</label></td><td>';
340+
print $form->selectDate(strtotime($secondElectionDateCSE) ? $secondElectionDateCSE : -1, 'SecondElectionDateCSE', 0, 0, 0, 'social_form', 1, 1);
341+
print '</td></tr>';
342+
343+
// ESC titulars - Titulaires CSE
344+
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
345+
$titulars_cse = $allLinks['TitularsCSE'];
346+
print '<tr>';
347+
print '<td>' . $form->editfieldkey('Titulars', 'TitularsCSE_id', '', $object, 0) . '</td>';
348+
print '<td colspan="3" class="maxwidthonsmartphone">';
349+
print $form->multiselectarray('TitularsCSE', $userlist, $titulars_cse->id, null, null, null, null, "300");
350+
if (!GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
351+
print '</td></tr>';
352+
353+
// ESC alternates - Suppléants CSE
354+
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', $conf->entity, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
355+
$alternates_cse = $allLinks['AlternatesCSE'];
356+
print '<tr>';
357+
print '<td>' . $form->editfieldkey('Alternates', 'AlternatesCSE_id', '', $object, 0) . '</td>';
358+
print '<td colspan="3" class="maxwidthonsmartphone">';
359+
print $form->multiselectarray('AlternatesCSE', $userlist, $alternates_cse->id, null, null, null, null, "300");
360+
if (!GETPOSTISSET('backtopage')) print ' <a href="' . DOL_URL_ROOT . '/user/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddUser") . '"></span></a>';
361+
print '</td></tr>';
362+
}
363+
}
283364

284365
/*
285366
*** Staff Representative -- Délégués du Personnel ***

langs/fr_FR/digiriskdolibarr.lang

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ TermsAndConditions = Modalités
266266

267267
ESC = Comité Social & Économique
268268
StaffRepresentatives = Délégués du personnel
269+
DeficiencyReport = Procès-verbal de carence
270+
DeficiencyReportDate = Date du procès-verbal de carence
271+
SubmissionElectionDate = Date de présentation de l'élection
269272
ElectionDate = Date d'élection
273+
SecondElectionDate = Date d'élection du second tour
270274
ElectionDateCSE = Date d'élection du CSE
271275
ElectionDateDP = Date d'élection des DP
272276

0 commit comments

Comments
 (0)