Skip to content

Commit

Permalink
FIX Error management in leave request
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 20, 2018
1 parent a3a416a commit fe53ff5
Showing 1 changed file with 128 additions and 111 deletions.
239 changes: 128 additions & 111 deletions htdocs/holiday/card.php
Expand Up @@ -261,21 +261,28 @@

// Update
$verif = $object->update($user);
if ($verif > 0)
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
else
{
// Otherwise we display the request form with the SQL error message
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=SQL_Create&msg='.$object->error);
exit;
}

if ($verif <= 0)
{
setEventMessages($object->error, $object->errors, 'warnings');
$action='edit';
}
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
}
} else {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
else
{
setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
$action='';
}
}
else
{
setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
$action='';
}
}

Expand All @@ -299,7 +306,9 @@
}
else
{
$error = $langs->trans('ErrorCantDeleteCP');
$error++;
setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors');
$action='';
}
}

Expand Down Expand Up @@ -393,24 +402,26 @@

$trackid='leav'.$object->id;

$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid);
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

// Envoi du mail
$result=$mail->sendfile();

if (!$result)
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
exit;
setEventMessages($mail->error, $mail->errors, 'warnings');
$action='';
}
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
else
{
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit;
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}
}
Expand Down Expand Up @@ -481,42 +492,44 @@

$trackid='leav'.$object->id;

$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid);
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

// Envoi du mail
$result=$mail->sendfile();

if (!$result) {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
exit;
if (!$result)
{
setEventMessages($mail->error, $mail->errors, 'warnings');
$action='';
}
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}

header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} else {
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit;
}

else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}

}

if ($action == 'confirm_refuse')
if ($action == 'confirm_refuse' && GETPOST('confirm','alpha') == 'yes')
{
if (! empty($_POST['detail_refuse']))
if (! empty($_POST['detail_refuse']))
{
$object = new Holiday($db);
$object->fetch($id);

// Si statut en attente de validation et valideur = utilisateur
if ($object->statut == 2 && $user->id == $object->fk_validator)
{
$object->date_refuse = date('Y-m-d H:i:s', time());
$object->date_refuse = dol_print_date('dayhour', dol_now());
$object->fk_user_refuse = $user->id;
$object->statut = 5;
$object->detail_refuse = $_POST['detail_refuse'];
$object->detail_refuse = GETPOST('detail_refuse','alphanohtml');

$verif = $object->update($user);

Expand Down Expand Up @@ -558,36 +571,40 @@

$trackid='leav'.$object->id;

$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid);
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

// Envoi du mail
$result=$mail->sendfile();

if(!$result) {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
exit;
if (!$result)
{
setEventMessages($mail->error, $mail->errors, 'warnings');
$action='';
}
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}

header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} else {
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit;
}

else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}

} else {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=NoMotifRefuse');
exit;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
$action='refuse';
}
}


// Si Validation de la demande
if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
{
$error = 0;

$object = new Holiday($db);
$object->fetch($id);

Expand All @@ -597,7 +614,8 @@
$result = $object->update($user);
if ($result < 0)
{
$error = $langs->trans('ErrorBackToDraft');
$error++;
setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
}

if (! $error)
Expand All @@ -616,6 +634,8 @@
// Si Validation de la demande
if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
{
$error = 0;

$object = new Holiday($db);
$object->fetch($id);

Expand Down Expand Up @@ -647,7 +667,8 @@

if ($result1 < 0 || $result2 < 0)
{
$error = $langs->trans('ErrorCantDeleteCP');
$error++;
setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
}
}

Expand Down Expand Up @@ -697,27 +718,22 @@

$trackid='leav'.$object->id;

$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid);
$mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);

// Envoi du mail
$result=$mail->sendfile();

if(!$result)
if (!$result)
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
exit;
setEventMessages($mail->error, $mail->errors, 'warnings');
$action='';
}
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}

header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
else
{
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit;
}

}

}
Expand Down Expand Up @@ -1010,48 +1026,8 @@ function valider()
// On vérifie si l'utilisateur à le droit de lire cette demande
if ($cancreate)
{
if ($action == 'delete')
{
if ($user->rights->holiday->delete)
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1);
}
}

// Si envoi en validation
if ($action == 'sendToValidate' && $object->statut == 1)
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1);
}

// Si validation de la demande
if ($action == 'valid')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1);
}

// Si refus de la demande
if ($action == 'refuse')
{
$array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
}

// Si annulation de la demande
if ($action == 'cancel')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1);
}

// Si back to draft
if ($action == 'backtodraft')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1);
}

$head=holiday_prepare_head($object);


if ($action == 'edit' && $object->statut == 1)
{
$edit = true;
Expand Down Expand Up @@ -1242,6 +1218,47 @@ function valider()
dol_fiche_end();


// Confirmation messages
if ($action == 'delete')
{
if ($user->rights->holiday->delete)
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1);
}
}

// Si envoi en validation
if ($action == 'sendToValidate' && $object->statut == 1)
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1);
}

// Si validation de la demande
if ($action == 'valid')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1);
}

// Si refus de la demande
if ($action == 'refuse')
{
$array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
}

// Si annulation de la demande
if ($action == 'cancel')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1);
}

// Si back to draft
if ($action == 'backtodraft')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1);
}


if ($action == 'edit' && $object->statut == 1)
{
print '<div align="center">';
Expand Down

0 comments on commit fe53ff5

Please sign in to comment.