diff --git a/htdocs/holiday/card_group.php b/htdocs/holiday/card_group.php index 5d96bbbbc21..06157ee3e94 100644 --- a/htdocs/holiday/card_group.php +++ b/htdocs/holiday/card_group.php @@ -358,354 +358,6 @@ if (empty($reshook)) { } } } - - - if ($action == 'update_extras') { - $object->oldcopy = dol_clone($object); - - // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) { - $error++; - } - - if (!$error) { - // Actions on extra fields - $result = $object->insertExtraFields('HOLIDAY_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - - if ($error) { - $action = 'edit_extras'; - } - } - - // Approve leave request - if ($action == 'confirm_valid') { - $object->fetch($id); - - // If status is waiting approval and approver is also user - if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) { - $object->oldcopy = dol_clone($object); - - $object->date_valid = dol_now(); - $object->fk_user_valid = $user->id; - $object->statut = Holiday::STATUS_APPROVED; - - $db->begin(); - - $verif = $object->approve($user); - if ($verif <= 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - - // If no SQL error, we redirect to the request form - if (!$error) { - // Calculcate number of days consummed - $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); - $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type); - $newSolde = ($soldeActuel - $nbopenedday); - $label = $langs->transnoentitiesnoconv("Holidays").' - '.$object->ref; - - // The modification is added to the LOG - $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type); - if ($result < 0) { - $error++; - setEventMessages(null, $object->errors, 'errors'); - } - - // Update balance - $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type); - if ($result < 0) { - $error++; - setEventMessages(null, $object->errors, 'errors'); - } - } - - if (!$error) { - // To - $destinataire = new User($db); - $destinataire->fetch($object->fk_user); - $emailTo = $destinataire->email; - - if (!$emailTo) { - dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email"); - } else { - // From - $expediteur = new User($db); - $expediteur->fetch($object->fk_validator); - //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email. - $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM; - - // Subject - $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $societeName = $conf->global->MAIN_APPLICATION_TITLE; - } - - $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated"); - - // Content - $message = "

".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",

\n"; - - $message .= "

".$langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."

\n"; - - $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id; - - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid); - - // Sending email - $result = $mail->sendfile(); - - if (!$result) { - setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1 - $action = ''; - } - } - } - - if (!$error) { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - $db->rollback(); - $action = ''; - } - } - } - - if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes') { - if (GETPOST('detail_refuse')) { - $object->fetch($id); - - // If status pending validation and validator = user - if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) { - $object->date_refuse = dol_print_date('dayhour', dol_now()); - $object->fk_user_refuse = $user->id; - $object->statut = Holiday::STATUS_REFUSED; - $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml'); - - $db->begin(); - - $verif = $object->update($user); - if ($verif <= 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - // If no SQL error, we redirect to the request form - if (!$error) { - // To - $destinataire = new User($db); - $destinataire->fetch($object->fk_user); - $emailTo = $destinataire->email; - - if (!$emailTo) { - dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email"); - } else { - // From - $expediteur = new User($db); - $expediteur->fetch($object->fk_validator); - //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email. - $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM; - - // Subject - $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $societeName = $conf->global->MAIN_APPLICATION_TITLE; - } - - $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused"); - - // Content - $message = "

".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",

\n"; - - $message .= "

".$langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."

\n"; - $message .= "

".GETPOST('detail_refuse', 'alpha')."

"; - - $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id; - - $message .= ""; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid); - - // sending email - $result = $mail->sendfile(); - - if (!$result) { - setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1 - $action = ''; - } - } - } else { - $action = ''; - } - - if (!$error) { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - $db->rollback(); - $action = ''; - } - } - } else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors'); - $action = 'refuse'; - } - } - - - // If the request is validated - if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') { - $error = 0; - - $object->fetch($id); - - $oldstatus = $object->statut; - $object->statut = Holiday::STATUS_DRAFT; - - $result = $object->update($user); - if ($result < 0) { - $error++; - setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors'); - } - - if (!$error) { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - $db->rollback(); - } - } - - // If confirmation of cancellation - if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { - $error = 0; - - $object->fetch($id); - - // If status pending validation and validator = validator or user, or rights to do for others - if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) && - (!empty($user->admin) || $user->id == $object->fk_validator || $cancreate || $cancreateall)) { - $db->begin(); - - $oldstatus = $object->statut; - $object->date_cancel = dol_now(); - $object->fk_user_cancel = $user->id; - $object->statut = Holiday::STATUS_CANCELED; - - $result = $object->update($user); - - if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) { // holiday was already validated, status 3, so we must increase back the balance - // Call trigger - $result = $object->call_trigger('HOLIDAY_CANCEL', $user); - if ($result < 0) { - $error++; - } - - // Calculcate number of days consummed - $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); - - $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type); - $newSolde = ($soldeActuel + $nbopenedday); - - // The modification is added to the LOG - $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type); - - // Update of the balance - $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type); - - if ($result1 < 0 || $result2 < 0) { - $error++; - setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors'); - } - } - - if (!$error) { - $db->commit(); - } else { - $db->rollback(); - } - - // If no SQL error, we redirect to the request form - if (!$error && $result > 0) { - // To - $destinataire = new User($db); - $destinataire->fetch($object->fk_user); - $emailTo = $destinataire->email; - - if (!$emailTo) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - - // From - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_cancel); - //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email. - $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM; - - // Subject - $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $societeName = $conf->global->MAIN_APPLICATION_TITLE; - } - - $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled"); - - // Content - $message = "

".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",

\n"; - - $message .= "

".$langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."

\n"; - - $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id; - - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid); - - // sending email - $result = $mail->sendfile(); - - if (!$result) { - setEventMessages($mail->error, $mail->errors, 'warnings'); - $action = ''; - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } - } - } - }