Skip to content

Commit

Permalink
[PreventionPlan] fix: edit action & event messages
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-theo committed May 31, 2021
1 parent 4083a6a commit 12ea081
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
10 changes: 5 additions & 5 deletions class/digiriskelement/preventionplan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ public function update($user = '', $notrigger = 0)

// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."digiriskdolibarr_preventionplandet SET";
$sql .= " description='".$db->escape($this->description)."'";
$sql .= " category='".$db->escape($this->category)."'";
$sql .= " prevention_method='".$db->escape($this->prevention_method)."'";
$sql .= " fk_preventionplan='".$db->escape($this->fk_preventionplan)."'";
$sql .= " fk_element='".$db->escape($this->fk_element)."'";
$sql .= " description='".$db->escape($this->description)."',";
$sql .= " category=".$db->escape($this->category) . ",";
$sql .= " prevention_method='".$db->escape($this->prevention_method)."'" . ",";
$sql .= " fk_preventionplan=".$db->escape($this->fk_preventionplan) . ",";
$sql .= " fk_element=".$db->escape($this->fk_element);

$sql .= " WHERE rowid = ".$this->id;

Expand Down
26 changes: 21 additions & 5 deletions preventionplan_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@
$objectline->prevention_method = $prevention_method;
$objectline->fk_preventionplan = $parent_id;
$objectline->fk_element = $location;
$objectline->db = $db;

if ($parent_id < 1) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Location')), null, 'errors');
$error++;
}
if ($risk_category_id < 0) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('INRSRisk')), null, 'errors');
$error++;
}

if (!$error) {
$result = $objectline->insert(1);
Expand All @@ -256,8 +264,7 @@
}
else
{
if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
setEventMessages($objectline->error, $objectline->errors, 'errors');
}
}
}
Expand All @@ -281,6 +288,15 @@
$objectline->fk_preventionplan = $parent_id;
$objectline->fk_element = $location;

if ($parent_id < 1) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Location')), null, 'errors');
$error++;
}
if ($risk_category_id < 0) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('INRSRisk')), null, 'errors');
$error++;
}

if (!$error) {
$result = $objectline->update(1);

Expand Down Expand Up @@ -840,7 +856,7 @@
foreach($preventionplanlines as $key => $item) {
if ($action == 'editline' && $lineid == $key) {

print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"] . '?id=' . $object->id .'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updateLine">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
Expand Down Expand Up @@ -983,7 +999,7 @@
print '</tr>';
}

print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"] . '?id=' . $object->id .'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="addLine">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
Expand Down

0 comments on commit 12ea081

Please sign in to comment.