--- /tmp/dsg/dolibarr/htdocs/holiday/github_card.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_card.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; // Get parameters @@ -49,14 +49,14 @@ $fuserid = (GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id); // Load translation files required by the page -$langs->loadLangs(array("other", "holiday", "mails")); +$langs->loadLangs(array("holiday", "mails")); $now = dol_now(); $childids = $user->getAllChildIds(1); -$morefilter = ''; -if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) $morefilter = 'AND employee = 1'; +$morefilter = 'AND employee = 1'; +if (!empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; $error = 0; @@ -69,21 +69,20 @@ if (($id > 0) || $ref) { - $object->fetch($id, $ref); - - // Check current user can read this leave request - $canread = 0; - if (!empty($user->rights->holiday->readall)) $canread = 1; - if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) $canread = 1; - if (!$canread) - { - accessforbidden(); - } + $object->fetch($id, $ref); + + // Check current user can read this leave request + $canread = 0; + if (!empty($user->rights->holiday->read_all)) $canread = 1; + if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) $canread = 1; + if (!$canread) + { + accessforbidden(); + } } $cancreate = 0; - -if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance)) $cancreate = 1; +if (!empty($user->rights->holiday->write_all)) $cancreate = 1; if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) $cancreate = 1; $candelete = 0; @@ -112,169 +111,156 @@ header("Location: ".$backtopage); exit; } - $action = ''; + $action = ''; } - // Add leave request - if ($action == 'add') + // If create a request + if ($action == 'create') { - // If no right to create a request - if (!$cancreate) - { - $error++; - setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); - $action = 'create'; - } - - if (!$error) - { - $object = new Holiday($db); - - $db->begin(); - - $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); - $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); - $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); - $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); - $starthalfday = GETPOST('starthalfday'); - $endhalfday = GETPOST('endhalfday'); - $type = GETPOST('type'); - $halfday = 0; - if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday = 2; - elseif ($starthalfday == 'afternoon') $halfday = -1; - elseif ($endhalfday == 'morning') $halfday = 1; - - $valideur = GETPOST('valideur', 'int'); - $description = trim(GETPOST('description', 'restricthtml')); - - // Check that leave is for a user inside the hierarchy or advanced permission for all is set - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->holiday->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->id == $fuserid && empty($user->rights->holiday->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->id != $fuserid && empty($user->rights->holiday->writeall_advance)) - ) { - $error++; - setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - } else { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->holiday->writeall_advance)) { - if (!in_array($fuserid, $childids)) { - $error++; - setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); - $action = 'create'; - } - } - } - - // If no type - if ($type <= 0) + // If no right to create a request + if (!$cancreate) + { + $error++; + setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); + $action = 'request'; + } + + if (!$error) + { + $object = new Holiday($db); + + $db->begin(); + + $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); + $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); + $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); + $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); + $starthalfday = GETPOST('starthalfday'); + $endhalfday = GETPOST('endhalfday'); + $type = GETPOST('type'); + $halfday = 0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday = 2; + elseif ($starthalfday == 'afternoon') $halfday = -1; + elseif ($endhalfday == 'morning') $halfday = 1; + + $valideur = GETPOST('valideur', 'int'); + $description = trim(GETPOST('description')); + + // If no type + if ($type <= 0) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); + $error++; + $action = 'create'; + } + + // If no start date + if (empty($date_debut)) + { + setEventMessages($langs->trans("NoDateDebut"), null, 'errors'); + $error++; + $action = 'create'; + } + // If no end date + if (empty($date_fin)) + { + setEventMessages($langs->trans("NoDateFin"), null, 'errors'); + $error++; + $action = 'create'; + } + // If start date after end date + if ($date_debut > $date_fin) + { + setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors'); + $error++; + $action = 'create'; + } + + // Check if there is already holiday for this period + $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday); + if (!$verifCP) + { + setEventMessages($langs->trans("alreadyCPexist"), null, 'errors'); + $error++; + $action = 'create'; + } + + // If there is no Business Days within request + $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); + if ($nbopenedday < 0.5) + { + setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); + $error++; + $action = 'create'; + } + + // If no validator designated + if ($valideur < 1) + { + setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors'); + $error++; + } + + $result = 0; + + if (!$error) + { + $object->fk_user = $fuserid; + $object->description = $description; + $object->fk_validator = $valideur; + $object->fk_type = $type; + $object->date_debut = $date_debut; + $object->date_fin = $date_fin; + $object->halfday = $halfday; + + $result = $object->create($user); + if ($result <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + + // If no SQL error we redirect to the request card + if (!$error) + { + $db->commit(); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $error++; - $action = 'create'; - } - - // If no start date - if (empty($date_debut)) - { - setEventMessages($langs->trans("NoDateDebut"), null, 'errors'); - $error++; - $action = 'create'; - } - // If no end date - if (empty($date_fin)) - { - setEventMessages($langs->trans("NoDateFin"), null, 'errors'); - $error++; - $action = 'create'; - } - // If start date after end date - if ($date_debut > $date_fin) - { - setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors'); - $error++; - $action = 'create'; - } - - // Check if there is already holiday for this period - $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday); - if (!$verifCP) - { - setEventMessages($langs->trans("alreadyCPexist"), null, 'errors'); - $error++; - $action = 'create'; - } - - // If there is no Business Days within request - $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); - if ($nbopenedday < 0.5) - { - setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day - $error++; - $action = 'create'; - } - - // If no validator designated - if ($valideur < 1) - { - setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors'); - $error++; - } - - $result = 0; - - if (!$error) - { - $object->fk_user = $fuserid; - $object->description = $description; - $object->fk_validator = $valideur; - $object->fk_type = $type; - $object->date_debut = $date_debut; - $object->date_fin = $date_fin; - $object->halfday = $halfday; - - $result = $object->create($user); - if ($result <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - - // If no SQL error we redirect to the request card - if (!$error) - { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - $db->rollback(); - } - } + $db->rollback(); + } + } } if ($action == 'update' && GETPOSTISSET('savevalidator') && !empty($user->rights->holiday->approve)) { - $object->fetch($id); - - $object->oldcopy = dol_clone($object); - - $object->fk_validator = GETPOST('valideur', 'int'); - - if ($object->fk_validator != $object->oldcopy->fk_validator) - { - $verif = $object->update($user); - - if ($verif <= 0) - { - setEventMessages($object->error, $object->errors, 'warnings'); - $action = 'editvalidator'; - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } - - $action = ''; + $object->fetch($id); + + $object->oldcopy = dol_clone($object); + + $object->fk_validator = GETPOST('valideur', 'int'); + + if ($object->fk_validator != $object->oldcopy->fk_validator) + { + $verif = $object->update($user); + + if ($verif <= 0) + { + setEventMessages($object->error, $object->errors, 'warnings'); + $action = 'editvalidator'; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + } + + $action = ''; } if ($action == 'update' && !GETPOSTISSET('savevalidator')) @@ -290,61 +276,60 @@ elseif ($starthalfday == 'afternoon') $halfday = -1; elseif ($endhalfday == 'morning') $halfday = 1; - // If no right to modify a request - if (!$user->rights->holiday->write) - { - setEventMessages($langs->trans("CantUpdate"), null, 'errors'); - header('Location: '.$_SERVER["PHP_SELF"].'?action=create'); - exit; - } - - $object->fetch($id); + // If no right to modify a request + if (!$user->rights->holiday->write) + { + header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=CantUpdate'); + exit; + } + + $object->fetch($id); // If under validation - if ($object->statut == Holiday::STATUS_DRAFT) - { - // If this is the requestor or has read/write rights - if ($cancreate) - { - $valideur = GETPOST('valideur', 'int'); - $description = trim(GETPOST('description', 'restricthtml')); - - // If no start date - if (empty($_POST['date_debut_'])) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatedebut'); - exit; - } - - // If no end date - if (empty($_POST['date_fin_'])) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatefin'); - exit; - } - - // If start date after end date - if ($date_debut > $date_fin) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=datefin'); - exit; - } - - // If no validator designated - if ($valideur < 1) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=Valideur'); - exit; - } - - // If there is no Business Days within request - $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); - if ($nbopenedday < 0.5) - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=DureeHoliday'); - exit; - } - - $object->description = $description; - $object->date_debut = $date_debut; - $object->date_fin = $date_fin; - $object->fk_validator = $valideur; + if ($object->statut == Holiday::STATUS_DRAFT) + { + // If this is the requestor or has read/write rights + if ($cancreate) + { + $valideur = GETPOST('valideur', 'int'); + $description = trim(GETPOST('description', 'none')); + + // If no start date + if (empty($_POST['date_debut_'])) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatedebut'); + exit; + } + + // If no end date + if (empty($_POST['date_fin_'])) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatefin'); + exit; + } + + // If start date after end date + if ($date_debut > $date_fin) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=datefin'); + exit; + } + + // If no validator designated + if ($valideur < 1) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=Valideur'); + exit; + } + + // If there is no Business Days within request + $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); + if ($nbopenedday < 0.5) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=DureeHoliday'); + exit; + } + + $object->description = $description; + $object->date_debut = $date_debut; + $object->date_fin = $date_fin; + $object->fk_validator = $valideur; $object->halfday = $halfday; // Update @@ -354,18 +339,24 @@ { setEventMessages($object->error, $object->errors, 'warnings'); $action = 'edit'; - } else { + } + 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 = ''; - } + } + else + { + setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); + $action = ''; + } + } + else + { + setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors'); + $action = ''; + } } // If delete of request @@ -377,14 +368,16 @@ $object->fetch($id); - // If this is a rough draft, approved, canceled or refused + // If this is a rough draft, approved, canceled or refused if ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED) { // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer if ($candelete) { $result = $object->delete($user); - } else { + } + else + { $error++; setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors'); $action = ''; @@ -396,7 +389,9 @@ $db->commit(); header('Location: list.php?restore_lastsearch_values=1'); exit; - } else { + } + else + { $db->rollback(); } } @@ -404,102 +399,104 @@ // Action validate (+ send email for approval) if ($action == 'confirm_send') { - $object->fetch($id); - - // If draft and owner of leave - if ($object->statut == Holiday::STATUS_DRAFT && $cancreate) - { - $object->oldcopy = dol_clone($object); - - $object->statut = Holiday::STATUS_VALIDATED; - - $verif = $object->validate($user); - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - if ($verif > 0) - { - // To - $destinataire = new User($db); - $destinataire->fetch($object->fk_validator); - $emailTo = $destinataire->email; - - if (!$emailTo) - { - dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email"); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - - // From - $expediteur = new User($db); - $expediteur->fetch($object->fk_user); - //$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 + $object->fetch($id); + + // Si brouillon et créateur + if ($object->statut == Holiday::STATUS_DRAFT && $cancreate) + { + $object->oldcopy = dol_clone($object); + + $object->statut = Holiday::STATUS_VALIDATED; + + $verif = $object->validate($user); + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + if ($verif > 0) + { + // To + $destinataire = new User($db); + $destinataire->fetch($object->fk_validator); + $emailTo = $destinataire->email; + + if (!$emailTo) + { + dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email"); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + + // From + $expediteur = new User($db); + $expediteur->fetch($object->fk_user); + $emailFrom = $expediteur->email; + + // 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("HolidaysToValidate"); - - // Content - $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n"; - $message .= "\n"; - - $message .= $langs->transnoentities("HolidaysToValidateBody")."\n"; - - $delayForRequest = $object->getConfCP('delayForRequest'); - //$delayForRequest = $delayForRequest * (60*60*24); - - $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); - - // Si l'option pour avertir le valideur en cas de délai trop court - if ($object->getConfCP('AlertValidatorDelay')) - { - if ($object->date_debut < $nextMonth) - { - $message .= "\n"; - $message .= $langs->transnoentities("HolidaysToValidateDelay", $object->getConfCP('delayForRequest'))."\n"; - } - } - - // Si l'option pour avertir le valideur en cas de solde inférieur à la demande - if ($object->getConfCP('AlertValidatorSolde')) - { - $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); - if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) - { - $message .= "\n"; - $message .= $langs->transnoentities("HolidaysToValidateAlertSolde")."\n"; - } - } - - $message .= "\n"; - $message .= "- ".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; - $message .= "- ".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut, 'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin, 'day')."\n"; - $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); - - // Envoi du mail - $result = $mail->sendfile(); - - if (!$result) - { - setEventMessages($mail->error, $mail->errors, 'warnings'); - $action = ''; - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } - } + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + + $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate"); + + // Content + $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n"; + $message .= "\n"; + $message .= $langs->transnoentities("HolidaysToValidateBody")."\n"; + + $delayForRequest = $object->getConfCP('delayForRequest'); + //$delayForRequest = $delayForRequest * (60*60*24); + + $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); + + // Si l'option pour avertir le valideur en cas de délai trop court + if ($object->getConfCP('AlertValidatorDelay')) + { + if ($object->date_debut < $nextMonth) + { + $message .= "\n"; + $message .= $langs->transnoentities("HolidaysToValidateDelay", $object->getConfCP('delayForRequest'))."\n"; + } + } + + // Si l'option pour avertir le valideur en cas de solde inférieur à la demande + if ($object->getConfCP('AlertValidatorSolde')) + { + $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); + if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) + { + $message .= "\n"; + $message .= $langs->transnoentities("HolidaysToValidateAlertSolde")."\n"; + } + } + + $message .= "\n"; + $message .= "- ".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; + $message .= "- ".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut, 'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin, 'day')."\n"; + $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; + $message .= "\n"; + + $trackid = 'leav'.$object->id; + + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); + + // Envoi du mail + $result = $mail->sendfile(); + + if (!$result) + { + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action = ''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + } } if ($action == 'update_extras') @@ -507,7 +504,7 @@ $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (!$error) @@ -528,204 +525,210 @@ // 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++; - } - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - 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); - - // On ajoute la modification dans le LOG - $result = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $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 .= "\n"; - - $message .= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); - - // Envoi du mail - $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 = ''; - } - } + $object->fetch($id); + + // Si statut en attente de validation et valideur = utilisateur + 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++; + } + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + 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); + + // On ajoute la modification dans le LOG + $result = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $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; + + // 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 .= "\n"; + $message .= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n"; + + $message .= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; + + $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; + $message .= "\n"; + + $trackid = 'leav'.$object->id; + + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); + + // Envoi du mail + $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 (!empty($_POST['detail_refuse'])) - { - $object->fetch($id); - - // Si statut en attente de validation et valideur = utilisateur - 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'); - } - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - 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 .= "\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')."\n\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); - - // Envoi du mail - $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'; - } + { + $object->fetch($id); + + // Si statut en attente de validation et valideur = utilisateur + 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'); + } + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + 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; + + // 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 .= "\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')."\n\n"; + + $message .= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; + + $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; + $message .= "\n"; + + $trackid = 'leav'.$object->id; + + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); + + // Envoi du mail + $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'; + } } @@ -734,27 +737,29 @@ { $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(); - } + $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(); + } } // Si confirmation of cancellation @@ -762,102 +767,104 @@ { $error = 0; - $object->fetch($id); - - // Si statut en attente de validation et valideur = valideur ou utilisateur, ou droits de faire pour les autres - if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) && ($user->id == $object->fk_validator || in_array($object->fk_user, $childids) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance)))) - { - $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 - { - // 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); - - // On ajoute la modification dans le LOG - $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type); - - // Mise à jour du solde - $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(); - } - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - 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 + $object->fetch($id); + + // Si statut en attente de validation et valideur = valideur ou utilisateur, ou droits de faire pour les autres + if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) && ($user->id == $object->fk_validator || in_array($object->fk_user, $childids) || !empty($user->rights->holiday->write_all))) + { + $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 + { + // 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); + + // On ajoute la modification dans le LOG + $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type); + + // Mise à jour du solde + $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(); + } + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + 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; + + // 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 .= "\n"; - - $message .= $langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n"; - $message .= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; - $message .= "\n"; - - $trackid = 'leav'.$object->id; - - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); - - // Envoi du mail - $result = $mail->sendfile(); - - if (!$result) - { - setEventMessages($mail->error, $mail->errors, 'warnings'); - $action = ''; - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } - } + 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 .= "\n"; + + $message .= $langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."\n"; + $message .= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; + + $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n"; + $message .= "\n"; + + $trackid = 'leav'.$object->id; + + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); + + // Envoi du mail + $result = $mail->sendfile(); + + if (!$result) + { + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action = ''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + } + } } /* @@ -890,53 +897,55 @@ llxHeader('', $langs->trans('CPTitreMenu')); -if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') +if ((empty($id) && empty($ref)) || $action == 'add' || $action == 'request' || $action == 'create') { - // If user has no permission to create a leave - if ((in_array($fuserid, $childids) && empty($user->rights->holiday->write)) || (!in_array($fuserid, $childids) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->holiday->writeall_advance)))) - { - $errors[] = $langs->trans('CantCreateCP'); - } else { - // Form to add a leave request - print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png'); - - // Error management - if (GETPOST('error')) { - switch (GETPOST('error')) { - case 'datefin' : - $errors[] = $langs->trans('ErrorEndDateCP'); - break; - case 'SQL_Create' : - $errors[] = $langs->trans('ErrorSQLCreateCP').' '.htmlentities($_GET['msg']).''; - break; - case 'CantCreate' : - $errors[] = $langs->trans('CantCreateCP'); - break; - case 'Valideur' : - $errors[] = $langs->trans('InvalidValidatorCP'); - break; - case 'nodatedebut' : - $errors[] = $langs->trans('NoDateDebut'); - break; - case 'nodatefin' : - $errors[] = $langs->trans('NoDateFin'); - break; - case 'DureeHoliday' : - $errors[] = $langs->trans('ErrorDureeCP'); - break; - case 'alreadyCP' : - $errors[] = $langs->trans('alreadyCPexist'); - break; - } - - setEventMessages($errors, null, 'errors'); - } - - - $delayForRequest = $object->getConfCP('delayForRequest'); - //$delayForRequest = $delayForRequest * (60*60*24); - - $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); + // Si l'utilisateur n'a pas le droit de faire une demande + if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) + { + $errors[] = $langs->trans('CantCreateCP'); + } + else + { + // Formulaire de demande de congés payés + print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png'); + + // Si il y a une erreur + if (GETPOST('error')) { + switch (GETPOST('error')) { + case 'datefin' : + $errors[] = $langs->trans('ErrorEndDateCP'); + break; + case 'SQL_Create' : + $errors[] = $langs->trans('ErrorSQLCreateCP').' '.htmlentities($_GET['msg']).''; + break; + case 'CantCreate' : + $errors[] = $langs->trans('CantCreateCP'); + break; + case 'Valideur' : + $errors[] = $langs->trans('InvalidValidatorCP'); + break; + case 'nodatedebut' : + $errors[] = $langs->trans('NoDateDebut'); + break; + case 'nodatefin' : + $errors[] = $langs->trans('NoDateFin'); + break; + case 'DureeHoliday' : + $errors[] = $langs->trans('ErrorDureeCP'); + break; + case 'alreadyCP' : + $errors[] = $langs->trans('alreadyCPexist'); + break; + } + + setEventMessages($errors, null, 'errors'); + } + + + $delayForRequest = $object->getConfCP('delayForRequest'); + //$delayForRequest = $delayForRequest * (60*60*24); + + $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); print ''."\n"; - // Formulaire de demande - print '
'."\n"; - print ''."\n"; - print ''."\n"; - - if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) { - print dol_get_fiche_head('', '', '', -1); - - $out = ''; - $typeleaves = $object->getTypes(1, 1); - foreach ($typeleaves as $key => $val) + // Formulaire de demande + print ''."\n"; + print ''."\n"; + print ''."\n"; + + if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) + { + dol_fiche_head('', '', '', -1); + + $out = ''; + $typeleaves = $object->getTypes(1, 1); + foreach ($typeleaves as $key => $val) { $nb_type = $object->getCPforUser($user->id, $val['rowid']); $nb_holiday += $nb_type; - $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': '.($nb_type ? price2num($nb_type) : 0).'
'; + $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': '.($nb_type ?price2num($nb_type) : 0).'
'; //$out .= ' - '.$val['label'].': '.($nb_type ?price2num($nb_type) : 0).'
'; } - print $langs->trans('SoldeCPUser', round($nb_holiday, 5)).'
'; + print $langs->trans('SoldeCPUser', round($nb_holiday, 5)).'
'; print $out; - print dol_get_fiche_end(); - } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) { - print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'
'; - } - - print dol_get_fiche_head(); - - //print ''.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'

'; - - print ''; - print ''; - - // User for leave request - print ''; - print ''; - print ''; - print ''; - - // Type - print ''; - print ''; - print ''; + print ''; + + // Date start + print ''; + print ''; + print ''; + print ''; + + // Date end + print ''; + print ''; + print ''; + print ''; + + // Approver + print ''; + print ''; + print ''; + print ''; + + // Description + print ''; + print ''; + print ''; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; + + print ''; + print '
'.$langs->trans("User").''; - - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->holiday->writeall_advance)) - { - print img_picto('', 'user').$form->select_dolusers(($fuserid ? $fuserid : $user->id), 'fuserid', 0, '', 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500'); - //print ''; - } else { - print img_picto('', 'user').$form->select_dolusers(GETPOST('fuserid', 'int') ? GETPOST('fuserid', 'int') : $user->id, 'fuserid', 0, '', 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500'); - } - print '
'.$langs->trans("Type").''; - $typeleaves = $object->getTypes(1, -1); - $arraytypeleaves = array(); - foreach ($typeleaves as $key => $val) - { - $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); - $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : ''); + dol_fiche_end(); + } + elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) + { + print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'
'; + } + + dol_fiche_head(); + + //print ''.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'

'; + + print ''; + print ''; + + // User for leave request + print ''; + print ''; + print ''; + print ''; + + // Type + print ''; + print ''; + print ''; - print ''; - - // Date start - print ''; - print ''; - print ''; - print ''; - - // Date end - print ''; - print ''; - print ''; - print ''; - - // Approver - print ''; - print ''; - print ''; - print ''; - - // Description - print ''; - print ''; - print ''; - - // Other attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; - - print ''; - print '
'.$langs->trans("User").''; + + if (empty($user->rights->holiday->write_all)) + { + print $form->select_dolusers(($fuserid ? $fuserid : $user->id), 'fuserid', 0, '', 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'maxwidth300'); + //print ''; + } + else print $form->select_dolusers(GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id, 'fuserid', 0, '', 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'maxwidth300'); + print '
'.$langs->trans("Type").''; + $typeleaves = $object->getTypes(1, -1); + $arraytypeleaves = array(); + foreach ($typeleaves as $key => $val) + { + $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); + $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : ''); $arraytypeleaves[$val['rowid']] = $labeltoshow; - } - print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', true); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'; - print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday")); - print ''; - // Si la demande ne vient pas de l'agenda - if (!GETPOST('date_debut_')) { - print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1); - } else { - $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int')); - print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1); - } - print '     '; - print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ?GETPOST('starthalfday', 'alpha') : 'morning')); - print '
'; - print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday")); - print ''; - if (!GETPOST('date_fin_')) { - print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1); - } else { - $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month', 'int'), GETPOST('date_fin_day', 'int'), GETPOST('date_fin_year', 'int')); - print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1); - } - print '     '; - print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ?GETPOST('endhalfday', 'alpha') : 'afternoon')); - print '
'.$langs->trans("ReviewedByCP").''; - - $object = new Holiday($db); - $include_users = $object->fetch_users_approver_holiday(); - if (empty($include_users)) { - print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); - } else { - $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator); // Will work only if supervisor has permission to approve so is inside include_users - if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver - if (GETPOST('valideur', 'int') > 0) $defaultselectuser = GETPOST('valideur', 'int'); - $s = $form->select_dolusers($defaultselectuser, "valideur", 1, '', 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500'); - print img_picto('', 'user').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); - } - - //print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent - print '
'.$langs->trans("DescCP").''; - $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
'; - - print dol_get_fiche_end(); - - print '
'; - print ''; - print '    '; - print ''; - print '
'; - - print ''."\n"; - } -} else { - if ($error) { - print '
'; - print $error; - print '

'; - print '
'; - } else { - // Affichage de la fiche d'une demande de congés payés - if (($id > 0) || $ref) - { - $result = $object->fetch($id, $ref); - - $valideur = new User($db); - $valideur->fetch($object->fk_validator); - - $userRequest = new User($db); - $userRequest->fetch($object->fk_user); - - //print load_fiche_titre($langs->trans('TitreRequestCP')); - - // Si il y a une erreur - if (GETPOST('error')) - { - switch (GETPOST('error')) - { - case 'datefin' : - $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP'); - break; - case 'SQL_Create' : - $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP').' '.$_GET['msg']; - break; - case 'CantCreate' : - $errors[] = $langs->transnoentitiesnoconv('CantCreateCP'); - break; - case 'Valideur' : - $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP'); - break; - case 'nodatedebut' : - $errors[] = $langs->transnoentitiesnoconv('NoDateDebut'); - break; - case 'nodatefin' : - $errors[] = $langs->transnoentitiesnoconv('NoDateFin'); - break; - case 'DureeHoliday' : - $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP'); - break; - case 'NoMotifRefuse' : - $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP'); - break; - case 'mail' : - $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend')."\n".$_GET['error_content']; - break; - } - - setEventMessages($errors, null, 'errors'); - } - - // On vérifie si l'utilisateur à le droit de lire cette demande - if ($cancreate) - { - $head = holiday_prepare_head($object); - - if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) - { - if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) $edit = true; - - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - - print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); - - - print '
'; - print '
'; - print '
'; - - print ''; - print ''; - - // User - print ''; - print ''; - print ''; - - // Type - print ''; - print ''; - print ''; - print ''; - - $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning'; - $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon'; - - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - print ''; - } - - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - print ''; - } - - // Nb of days - print ''; - print ''; - print ''; - print ''; - - if ($object->statut == Holiday::STATUS_REFUSED) - { - print ''; - print ''; - print ''; - print ''; - } - - // Description - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - } - - // Other attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print ''; - print '
'.$langs->trans("User").''; - print $userRequest->getNomUrl(-1, 'leave'); - print '
'.$langs->trans("Type").''; - $typeleaves = $object->getTypes(1, -1); - $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']); - print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow; - print '
'; - print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday")); - print ''.dol_print_date($object->date_debut, 'day'); - print '     '; - print ''.$langs->trans($listhalfday[$starthalfday]).''; - print '
'; - print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday")); - print ''; - print $form->selectDate($object->date_debut, 'date_debut_'); - print '     '; - print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday)); - print '
'; - print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday")); - print ''.dol_print_date($object->date_fin, 'day'); - print '     '; - print ''.$langs->trans($listhalfday[$endhalfday]).''; - print '
'; - print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday")); - print ''; - print $form->selectDate($object->date_fin, 'date_fin_'); - print '     '; - print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday)); - print '
'; - $htmlhelp = $langs->trans('NbUseDaysCPHelp'); - $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1); - $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1); - if ($includesaturday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday")); - if ($includesunday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday")); - print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp); - print '
'; - print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); - print '
'.$langs->trans('DetailRefusCP').''.$object->detail_refuse.'
'.$langs->trans('DescCP').''.nl2br($object->description).'
'.$langs->trans('DescCP').''; - $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
'."\n"; - - print '
'; - print '
'; - print '
'; - - print '
'; + } + print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : ''), 1); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print '
'; + print $langs->trans("DateDebCP"); + print ' ('.$langs->trans("FirstDayOfHoliday").')'; + print ''; + // Si la demande ne vient pas de l'agenda + if (!GETPOST('date_debut_')) { + print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1); + } else { + $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int')); + print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1); + } + print '     '; + print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ?GETPOST('starthalfday', 'alpha') : 'morning')); + print '
'; + print $langs->trans("DateFinCP"); + print ' ('.$langs->trans("LastDayOfHoliday").')'; + print ''; + // Si la demande ne vient pas de l'agenda + if (!GETPOST('date_fin_')) { + print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1); + } else { + $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month', 'int'), GETPOST('date_fin_day', 'int'), GETPOST('date_fin_year', 'int')); + print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1); + } + print '     '; + print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ?GETPOST('endhalfday', 'alpha') : 'afternoon')); + print '
'.$langs->trans("ReviewedByCP").''; + + $object = new Holiday($db); + $include_users = $object->fetch_users_approver_holiday(); + if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); + else + { + $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator); // Will work only if supervisor has permission to approve so is inside include_users + if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver + if (GETPOST('valideur', 'int') > 0) $defaultselectuser = GETPOST('valideur', 'int'); + $s = $form->select_dolusers($defaultselectuser, "valideur", 1, "", 0, $include_users); + print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); + } + + //print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent + print '
'.$langs->trans("DescCP").''; + $doleditor = new DolEditor('description', GETPOST('description', 'none'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '    '; + print ''; + print '
'; + + print ''."\n"; + } +} +else +{ + if ($error) + { + print '
'; + print $error; + print '

'; + print '
'; + } + else + { + // Affichage de la fiche d'une demande de congés payés + if (($id > 0) || $ref) + { + $result = $object->fetch($id, $ref); + + $valideur = new User($db); + $valideur->fetch($object->fk_validator); + + $userRequest = new User($db); + $userRequest->fetch($object->fk_user); + + //print load_fiche_titre($langs->trans('TitreRequestCP')); + + // Si il y a une erreur + if (GETPOST('error')) + { + switch (GETPOST('error')) + { + case 'datefin' : + $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP'); + break; + case 'SQL_Create' : + $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP').' '.$_GET['msg']; + break; + case 'CantCreate' : + $errors[] = $langs->transnoentitiesnoconv('CantCreateCP'); + break; + case 'Valideur' : + $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP'); + break; + case 'nodatedebut' : + $errors[] = $langs->transnoentitiesnoconv('NoDateDebut'); + break; + case 'nodatefin' : + $errors[] = $langs->transnoentitiesnoconv('NoDateFin'); + break; + case 'DureeHoliday' : + $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP'); + break; + case 'NoMotifRefuse' : + $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP'); + break; + case 'mail' : + $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend')."\n".$_GET['error_content']; + break; + } + + setEventMessages($errors, null, 'errors'); + } + + // On vérifie si l'utilisateur à le droit de lire cette demande + if ($cancreate) + { + $head = holiday_prepare_head($object); + + if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) + { + if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) $edit = true; + + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + } + + dol_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); + + + print '
'; + print '
'; + print '
'; + + print ''; + print ''; + + // User + print ''; + print ''; + print ''; + + // Type + print ''; + print ''; + print ''; + print ''; + + $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning'; + $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon'; + + if (!$edit) + { + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; + print ''; + } + + if (!$edit) + { + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; + print ''; + } + + // Nb of days + print ''; + print ''; + print ''; + print ''; + + if ($object->statut == Holiday::STATUS_REFUSED) + { + print ''; + print ''; + print ''; + print ''; + } + + // Description + if (!$edit) + { + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; + } + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print ''; + print '
'.$langs->trans("User").''; + print $userRequest->getNomUrl(-1, 'leave'); + print '
'.$langs->trans("Type").''; + $typeleaves = $object->getTypes(1, -1); + $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']); + print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow; + print '
'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'.dol_print_date($object->date_debut, 'day'); + print '     '; + print ''.$langs->trans($listhalfday[$starthalfday]).''; + print '
'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'; + print $form->selectDate($object->date_debut, 'date_debut_'); + print '     '; + print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday)); + print '
'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'.dol_print_date($object->date_fin, 'day'); + print '     '; + print ''.$langs->trans($listhalfday[$endhalfday]).''; + print '
'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'; + print $form->selectDate($object->date_fin, 'date_fin_'); + print '     '; + print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday)); + print '
'; + $htmlhelp = $langs->trans('NbUseDaysCPHelp'); + $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1); + $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1); + if ($includesaturday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday")); + if ($includesunday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday")); + print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp); + print '
'; + print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday); + print '
'.$langs->trans('DetailRefusCP').''.$object->detail_refuse.'
'.$langs->trans('DescCP').''.nl2br($object->description).'
'.$langs->trans('DescCP').''; + $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print '
'."\n"; + + print '
'; + print '
'; + print '
'; + + print '
'; // Info workflow - print ''."\n"; - print ''; - - if (!empty($object->fk_user_create)) - { - $userCreate = new User($db); - $userCreate->fetch($object->fk_user_create); - print ''; - print ''; - print ''; - print ''; - } - - // Approver - if (!$edit && $action != 'editvalidator') { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - print ''; - } - - print ''; - print ''; - print ''; - print ''; - if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) { - print ''; - print ''; - print ''; // warning: date_valid is approval date on holiday module - print ''; - } - if ($object->statut == Holiday::STATUS_CANCELED) { - print ''; - print ''; - print ''; - print ''; - } - if ($object->statut == Holiday::STATUS_REFUSED) { - print ''; - print ''; - print ''; - print ''; - } - print ''; - print '
'.$langs->trans('RequestByCP').''.$userCreate->getNomUrl(-1).'
'; - if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) print $langs->trans('ApprovedBy'); - else print $langs->trans('ReviewedByCP'); - print ''.$valideur->getNomUrl(-1); - $include_users = $object->fetch_users_approver_holiday(); - if (is_array($include_users) && in_array($user->id, $include_users) && $object->statut == Holiday::STATUS_VALIDATED) - { - print ''.img_edit($langs->trans("Edit")).''; - } - print '
'.$langs->trans('ReviewedByCP').''; - $include_users = $object->fetch_users_approver_holiday(); - if (!in_array($object->fk_validator, $include_users)) // Add the current validator to the list to not lose it when editing. - { - $include_users[] = $object->fk_validator; - } - if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); - else { - $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ? '' : array($user->id)); // Nobody if we are admin or if we are not the user of the leave. - $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users); - print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); - } - if ($action == 'editvalidator') - { - print ''; - print ''; - } - print '
'.$langs->trans('DateCreation').''.dol_print_date($object->date_create, 'dayhour', 'tzuser').'
'.$langs->trans('DateValidCP').''.dol_print_date($object->date_valid, 'dayhour', 'tzuser').'
'.$langs->trans('DateCancelCP').''.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'
'.$langs->trans('DateRefusCP').''.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'
'; - - print '
'; - print '
'; - print '
'; - - print '
'; - - print dol_get_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 == Holiday::STATUS_DRAFT) - { - 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 == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) - { - if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) - { - print '
'; - if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) - { - print ''; - } - print '
'; - } - - print '
'; - } - - if (!$edit) - { - // Buttons for actions - - print '
'; - - if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) - { - print ''.$langs->trans("EditCP").''; - } - if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) // If draft - { - print ''.$langs->trans("Validate").''; - } - if ($object->statut == Holiday::STATUS_VALIDATED) // If validated - { - if ($user->id == $object->fk_validator) - { - print ''.$langs->trans("Approve").''; - print ''.$langs->trans("ActionRefuseCP").''; - } else { - print ''.$langs->trans("Approve").''; - print ''.$langs->trans("ActionRefuseCP").''; - } - } - if (($user->id == $object->fk_validator || in_array($object->fk_user, $childids) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance))) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved - { - if (($object->date_debut > dol_now()) || $user->admin) print ''.$langs->trans("ActionCancelCP").''; - else print ''.$langs->trans("ActionCancelCP").''; - } - if ($cancreate && $object->statut == Holiday::STATUS_CANCELED) - { - print ''.$langs->trans("SetToDraft").''; - } - if ($candelete && ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)) // If draft or canceled or refused - { - print ''.$langs->trans("DeleteCP").''; - } - - print '
'; - } - } else { - print '
'; - print $langs->trans('ErrorUserViewCP'); - print '

'; - print '
'; - } - } else { - print '
'; - print $langs->trans('ErrorIDFicheCP'); - print '

'; - print '
'; - } - - - // Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } - - if ($action != 'presend') - { - print '
'; - print ''; // ancre - - $includedocgeneration = 0; - - // Documents - if ($includedocgeneration) { - $objref = dol_sanitizeFileName($object->ref); - $relativepath = $objref.'/'.$objref.'.pdf'; - $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref; - $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed = ($user->rights->holiday->read && $object->fk_user == $user->id) || !empty($user->rights->holiday->readall); // If you can read, you can build the PDF to read content - $delallowed = ($user->rights->holiday->write && $object->fk_user == $user->id) || !empty($user->rights->holiday->writeall_advance); // If you can create/edit, you can remove a file on card - print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); - } - - // Show links to link elements - //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject')); - //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - - - 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, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright); - - print '
'; - } - } + print ''."\n"; + print ''; + + if (!empty($object->fk_user_create)) + { + $userCreate = new User($db); + $userCreate->fetch($object->fk_user_create); + print ''; + print ''; + print ''; + print ''; + } + + // Validator + if (!$edit && $action != 'editvalidator') { + print ''; + print ''; + print ''; + print ''; + } else { + print ''; + print ''; + print ''; + print ''; + } + + print ''; + print ''; + print ''; + print ''; + if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) { + print ''; + print ''; + print ''; // warning: date_valid is approval date on holiday module + print ''; + } + if ($object->statut == Holiday::STATUS_CANCELED) { + print ''; + print ''; + print ''; + print ''; + } + if ($object->statut == Holiday::STATUS_REFUSED) { + print ''; + print ''; + print ''; + print ''; + } + print ''; + print '
'.$langs->trans('RequestByCP').''.$userCreate->getNomUrl(-1).'
'; + if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) print $langs->trans('ApprovedBy'); + else print $langs->trans('ReviewedByCP'); + print ''.$valideur->getNomUrl(-1); + $include_users = $object->fetch_users_approver_holiday(); + if (is_array($include_users) && in_array($user->id, $include_users) && $object->statut == Holiday::STATUS_VALIDATED) + { + print ''.img_edit($langs->trans("Edit")).''; + } + print '
'.$langs->trans('ReviewedByCP').''; + $include_users = $object->fetch_users_approver_holiday(); + if (!in_array($object->fk_validator, $include_users)) // Add the current validator to the list to not lose it when editing. + { + $include_users[] = $object->fk_validator; + } + if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); + else + { + $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ? '' : array($user->id)); // Nobody if we are admin or if we are not the user of the leave. + $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users); + print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); + } + if ($action == 'editvalidator') + { + print ''; + print ''; + } + print '
'.$langs->trans('DateCreation').''.dol_print_date($object->date_create, 'dayhour').'
'.$langs->trans('DateValidCP').''.dol_print_date($object->date_valid, 'dayhour').'
'.$langs->trans('DateCancelCP').''.dol_print_date($object->date_cancel, 'dayhour').'
'.$langs->trans('DateRefusCP').''.dol_print_date($object->date_refuse, 'dayhour').'
'; + + print ''; + print ''; + print ''; + + print '
'; + + 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 == Holiday::STATUS_DRAFT) + { + 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 == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) + { + if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) + { + print '
'; + if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) + { + print ''; + } + print '
'; + } + + print ''; + } + + if (!$edit) + { + // Buttons for actions + + print '
'; + + if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) + { + print ''.$langs->trans("EditCP").''; + } + if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) // If draft + { + print ''.$langs->trans("Validate").''; + } + if ($object->statut == Holiday::STATUS_VALIDATED) // If validated + { + if ($user->id == $object->fk_validator) + { + print ''.$langs->trans("Approve").''; + print ''.$langs->trans("ActionRefuseCP").''; + } + else + { + print ''.$langs->trans("Approve").''; + print ''.$langs->trans("ActionRefuseCP").''; + } + } + if (($user->id == $object->fk_validator || in_array($object->fk_user, $childids) || !empty($user->rights->holiday->write_all)) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved + { + if (($object->date_debut > dol_now()) || $user->admin) print ''.$langs->trans("ActionCancelCP").''; + else print ''.$langs->trans("ActionCancelCP").''; + } + if ($cancreate && $object->statut == Holiday::STATUS_CANCELED) + { + print ''.$langs->trans("SetToDraft").''; + } + if ($candelete && ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)) // If draft or canceled or refused + { + print ''.$langs->trans("DeleteCP").''; + } + + print '
'; + } + } else { + print '
'; + print $langs->trans('ErrorUserViewCP'); + print '

'; + print '
'; + } + } else { + print '
'; + print $langs->trans('ErrorIDFicheCP'); + print '

'; + print '
'; + } + } } // End of page --- /tmp/dsg/dolibarr/htdocs/holiday/github_define_holiday.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_define_holiday.php @@ -28,10 +28,10 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; // Load translation files required by the page -$langs->loadlangs(array('users', 'other', 'holiday', 'hrm')); +$langs->loadlangs(array('users', 'hrm')); $action = GETPOST('action', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'defineholidaylist'; @@ -41,8 +41,8 @@ // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; @@ -56,7 +56,7 @@ if ($user->socid > 0) accessforbidden(); // If the user does not have perm to read the page -if (empty($user->rights->holiday->read)) accessforbidden(); +if (!$user->rights->holiday->read) accessforbidden(); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array @@ -65,17 +65,6 @@ $holiday = new Holiday($db); -if (empty($conf->holiday->enabled)) -{ - llxHeader('', $langs->trans('CPTitreMenu')); - print '
'; - print ''.$langs->trans('NotActiveModCP').''; - print '
'; - llxFooter(); - exit(); -} - - /* * Actions @@ -90,20 +79,20 @@ if (empty($reshook)) { - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - - // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { - $search_name = ''; - $search_supervisor = ''; - $toselect = ''; - $search_array_options = array(); - } - - // Mass actions - /* + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + $search_name = ''; + $search_supervisor = ''; + $toselect = ''; + $search_array_options = array(); + } + + // Mass actions + /* $objectclass='Skeleton'; $objectlabel='Skeleton'; $permissiontoread = $user->rights->skeleton->read; @@ -112,52 +101,52 @@ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; */ - // Si il y a une action de mise à jour - if ($action == 'update' && isset($_POST['update_cp'])) - { - $error = 0; - - $typeleaves = $holiday->getTypes(1, 1); - - $userID = array_keys($_POST['update_cp']); - $userID = $userID[0]; - - foreach ($typeleaves as $key => $val) - { - $userValue = $_POST['nb_holiday_'.$val['rowid']]; - $userValue = $userValue[$userID]; - - if (!empty($userValue) || (string) $userValue == '0') - { - $userValue = price2num($userValue, 5); - } else { - $userValue = ''; - } - - //If the user set a comment, we add it to the log comment - $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : ''); - - //print 'holiday: '.$val['rowid'].'-'.$userValue; - if ($userValue != '') - { - // We add the modification to the log (must be before update of sold because we read current value of sold) - $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']); - if ($result < 0) - { - setEventMessages($holiday->error, $holiday->errors, 'errors'); - $error++; - } - - // Update of the days of the employee - $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']); - if ($result < 0) - { - setEventMessages($holiday->error, $holiday->errors, 'errors'); - $error++; - } - - // If it first update of balance, we set date to avoid to have sold incremented by new month - /* + // Si il y a une action de mise à jour + if ($action == 'update' && isset($_POST['update_cp'])) + { + $error = 0; + + $typeleaves = $holiday->getTypes(1, 1); + + $userID = array_keys($_POST['update_cp']); + $userID = $userID[0]; + + foreach ($typeleaves as $key => $val) + { + $userValue = $_POST['nb_holiday_'.$val['rowid']]; + $userValue = $userValue[$userID]; + + if (!empty($userValue) || (string) $userValue == '0') + { + $userValue = price2num($userValue, 5); + } else { + $userValue = ''; + } + + //If the user set a comment, we add it to the log comment + $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : ''); + + //print 'holiday: '.$val['rowid'].'-'.$userValue; + if ($userValue != '') + { + // We add the modification to the log (must be before update of sold because we read current value of sold) + $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']); + if ($result < 0) + { + setEventMessages($holiday->error, $holiday->errors, 'errors'); + $error++; + } + + // Update of the days of the employee + $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']); + if ($result < 0) + { + setEventMessages($holiday->error, $holiday->errors, 'errors'); + $error++; + } + + // If it first update of balance, we set date to avoid to have sold incremented by new month + /* $now=dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'"; @@ -165,11 +154,11 @@ dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG); $result = $db->query($sql); */ - } - } - - if (!$error) setEventMessages('UpdateConfCPOK', '', 'mesgs'); - } + } + } + + if (!$error) setEventMessages('UpdateConfCPOK', '', 'mesgs'); + } } @@ -205,10 +194,10 @@ print '
'.$langs->trans('LastUpdateCP').': '."\n"; $lastUpdate = $holiday->getConfCP('lastUpdate'); if ($lastUpdate) { - print ''.dol_print_date($db->jdate($lastUpdate), 'dayhour').''; - print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$langs->trans('Month'.substr($lastUpdate, 4, 2)).' '.substr($lastUpdate, 0, 4).''."\n"; + print ''.dol_print_date($db->jdate($lastUpdate), 'dayhour').''; + print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$langs->trans('Month'.substr($lastUpdate, 4, 2)).' '.substr($lastUpdate, 0, 4).''."\n"; } else { - print $langs->trans('None'); + print $langs->trans('None'); } print "

\n"; @@ -217,7 +206,7 @@ // Filter on array of ids of all childs $userchilds = array(); -if (empty($user->rights->holiday->readall)) +if (empty($user->rights->holiday->read_all)) { $userchilds = $user->getAllChildIds(1); $filters .= ' AND u.rowid IN ('.join(', ', $userchilds).')'; @@ -231,7 +220,7 @@ $listUsers = $holiday->fetchUsers(false, true, $filters); if (is_numeric($listUsers) && $listUsers < 0) { - setEventMessages($holiday->error, $holiday->errors, 'errors'); + setEventMessages($holiday->error, $holiday->errors, 'errors'); } $i = 0; @@ -239,137 +228,145 @@ if (count($typeleaves) == 0) { - //print '
'; - print $langs->trans("NoLeaveWithCounterDefined")."
\n"; - print $langs->trans("GoIntoDictionaryHolidayTypes"); - //print '
'; -} else { - $canedit = 0; - if (!empty($user->rights->holiday->define_holiday)) $canedit = 1; - - $moreforfilter = ''; - - print '
'; - print ''."\n"; - - print ''; - - // User - print ''; - - // Supervisor - print ''; - - // Type of leave request - if (count($typeleaves)) - { - foreach ($typeleaves as $key => $val) - { - print ''; - } - } else { - print ''; - } - print ''; - - // Action column - print ''; - - print ''; - - print ''; - print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]); - print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]); - if (count($typeleaves)) - { - foreach ($typeleaves as $key => $val) - { - $labeltype = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']); - print_liste_field_titre($labeltype, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center '); - } - } else { - print_liste_field_titre('NoLeaveWithCounterDefined', $_SERVER["PHP_SELF"], '', '', '', ''); - } - print_liste_field_titre((empty($user->rights->holiday->define_holiday) ? '' : 'Note'), $_SERVER["PHP_SELF"]); - print_liste_field_titre(''); - print ''; - - $usersupervisor = new User($db); - - foreach ($listUsers as $users) - { - // If user has not permission to edit/read all, we must see only subordinates - if (empty($user->rights->holiday->readall)) - { - if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) continue; // This user is not into hierarchy of current user, we hide it. - } - - $userstatic->id = $users['rowid']; - $userstatic->lastname = $users['lastname']; - $userstatic->firstname = $users['firstname']; - $userstatic->gender = $users['gender']; - $userstatic->photo = $users['photo']; - $userstatic->statut = $users['status']; - $userstatic->employee = $users['employee']; - $userstatic->fk_user = $users['fk_user']; - - if ($userstatic->fk_user > 0) $usersupervisor->fetch($userstatic->fk_user); - - print ''; - - // User - print ''; - - // Supervisor - print ''; - - // Amount for each type - if (count($typeleaves)) - { - foreach ($typeleaves as $key => $val) - { - $nbtoshow = ''; - if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow = price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5); - - //var_dump($users['rowid'].' - '.$val['rowid']); - print ''."\n"; - } - } else { - print ''; - } - - // Note - print ''; - - // Button modify - print ''."\n"; - print ''; - - $i++; - } - - print '
'; - print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, null, 0, null, null, 0, 0, 0, '', 0, '', 'maxwidth200'); - print ''; - $searchpicto = $form->showFilterButtons(); - print $searchpicto; - print '
'; - print $userstatic->getNomUrl(-1); - print ''; - if ($userstatic->fk_user > 0) print $usersupervisor->getNomUrl(-1); - print ''; - if ($canedit) print ''; - else print $nbtoshow; - //print ' '.$langs->trans('days'); - print ''; - if ($canedit) print ''; - print ''; - if (!empty($user->rights->holiday->define_holiday)) // Allowed to set the balance of any user - { - print ''; - } - print '
'; - print '
'; + //print '
'; + print $langs->trans("NoLeaveWithCounterDefined")."
\n"; + print $langs->trans("GoIntoDictionaryHolidayTypes"); + //print '
'; +} +else +{ + $canedit = 0; + if (!empty($user->rights->holiday->define_holiday)) $canedit = 1; + + $moreforfilter = ''; + + print '
'; + print ''."\n"; + + print ''; + + // User + print ''; + + // Supervisor + print ''; + + // Type of leave request + if (count($typeleaves)) + { + foreach ($typeleaves as $key => $val) + { + print ''; + } + } + else + { + print ''; + } + print ''; + + // Action column + print ''; + + print ''; + + print ''; + print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]); + print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]); + if (count($typeleaves)) + { + foreach ($typeleaves as $key => $val) + { + $labeltype = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']); + print_liste_field_titre($labeltype, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center '); + } + } + else + { + print_liste_field_titre('NoLeaveWithCounterDefined', $_SERVER["PHP_SELF"], '', '', '', ''); + } + print_liste_field_titre((empty($user->rights->holiday->define_holiday) ? '' : 'Note'), $_SERVER["PHP_SELF"]); + print_liste_field_titre(''); + print ''; + + $usersupervisor = new User($db); + + foreach ($listUsers as $users) + { + // If user has not permission to edit/read all, we must see only subordinates + if (empty($user->rights->holiday->read_all)) + { + if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) continue; // This user is not into hierarchy of current user, we hide it. + } + + $userstatic->id = $users['rowid']; + $userstatic->lastname = $users['lastname']; + $userstatic->firstname = $users['firstname']; + $userstatic->gender = $users['gender']; + $userstatic->photo = $users['photo']; + $userstatic->statut = $users['status']; + $userstatic->employee = $users['employee']; + $userstatic->fk_user = $users['fk_user']; + + if ($userstatic->fk_user > 0) $usersupervisor->fetch($userstatic->fk_user); + + print ''; + + // User + print ''; + + // Supervisor + print ''; + + // Amount for each type + if (count($typeleaves)) + { + foreach ($typeleaves as $key => $val) + { + $nbtoshow = ''; + if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow = price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5); + + //var_dump($users['rowid'].' - '.$val['rowid']); + print ''."\n"; + } + } + else + { + print ''; + } + + // Note + print ''; + + // Button modify + print ''."\n"; + print ''; + + $i++; + } + + print '
'; + print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, null, 0, null, null, 0, 0, 0, '', 0, '', 'maxwidth200'); + print ''; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'; + print $userstatic->getNomUrl(-1); + print ''; + if ($userstatic->fk_user > 0) print $usersupervisor->getNomUrl(-1); + print ''; + if ($canedit) print ''; + else print $nbtoshow; + //print ' '.$langs->trans('days'); + print ''; + if ($canedit) print ''; + print ''; + if (!empty($user->rights->holiday->define_holiday)) // Allowed to set the balance of any user + { + print ''; + } + print '
'; + print '
'; } print ''; --- /tmp/dsg/dolibarr/htdocs/holiday/github_document.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_document.php @@ -41,7 +41,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); // Security check @@ -50,8 +50,8 @@ // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; @@ -64,7 +64,7 @@ $object = new Holiday($db); $object->fetch($id, $ref); -$upload_dir = $conf->holiday->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, ''); +$upload_dir = $conf->holiday->dir_output.'/'.get_exdir($object->id, 0, 0, 0, $object, 'holiday').dol_sanitizeFileName($object->ref); $modulepart = 'holiday'; @@ -96,7 +96,7 @@ $head = holiday_prepare_head($object); - print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday'); + dol_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday'); // Build file list @@ -119,114 +119,102 @@ print ''; - print ''; - print ''; + print ''; + print ''; print ''; - // Type - print ''; - print ''; - print ''; - print ''; - - $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning'; - $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon'; - - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + + $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning'; + $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon'; + + if (!$edit) + { + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; - print ''; - } - - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - print ''; - } - - // Nb days consumed - print ''; - print ''; - print ''; - print ''; - - if ($object->statut == 5) - { - print ''; - print ''; - print ''; - print ''; - } - - // Description - if (!$edit) - { - print ''; - print ''; - print ''; - print ''; - } else { - print ''; - print ''; - print ''; - print ''; - } - - print ''; - print ''; - - print ''; - print '
'.$langs->trans("User").'
'.$langs->trans("User").''; print $userRequest->getNomUrl(-1, 'leave'); print '
'.$langs->trans("Type").''; - $typeleaves = $object->getTypes(1, -1); - $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']); - print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow; - print '
'; - print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday")); - print ''.dol_print_date($object->date_debut, 'day'); - print '     '; - print ''.$langs->trans($listhalfday[$starthalfday]).''; - print '
'; - print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday")); - print ''; - print $form->selectDate($object->date_debut, 'date_debut_'); - print '     '; + // Type + print '
'.$langs->trans("Type").''; + $typeleaves = $object->getTypes(1, -1); + print empty($typeleaves[$object->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $typeleaves[$object->fk_type]['label']; + print '
'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'.dol_print_date($object->date_debut, 'day'); + print '     '; + print ''.$langs->trans($listhalfday[$starthalfday]).''; + print '
'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'; + print $form->selectDate($object->date_debut, 'date_debut_'); + print '     '; print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday)); - print '
'; - print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday")); - print ''.dol_print_date($object->date_fin, 'day'); - print '     '; - print ''.$langs->trans($listhalfday[$endhalfday]).''; - print '
'; - print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday")); - print ''; - print $form->selectDate($object->date_fin, 'date_fin_'); - print '     '; - print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday)); - print '
'; - $htmlhelp = $langs->trans('NbUseDaysCPHelp'); - $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1); - $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1); - if ($includesaturday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday")); - if ($includesunday) $htmlhelp .= '
'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday")); - print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp); - print '
'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'
'.$langs->trans('DetailRefusCP').''.$object->detail_refuse.'
'.$langs->trans('DescCP').''.nl2br($object->description).'
'.$langs->trans('DescCP').'
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.dol_print_size($totalsize, 1, 1).'
'."\n"; - /* + print ''; + print ''; + } + + if (!$edit) + { + print ''; + print ''.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'; + print ''.dol_print_date($object->date_fin, 'day'); + print '     '; + print ''.$langs->trans($listhalfday[$endhalfday]).''; + print ''; + print ''; + } + else + { + print ''; + print ''.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'; + print ''; + print $form->selectDate($object->date_fin, 'date_fin_'); + print '     '; + print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday)); + print ''; + print ''; + } + print ''; + print ''.$langs->trans('NbUseDaysCP').''; + print ''.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).''; + print ''; + + if ($object->statut == 5) + { + print ''; + print ''.$langs->trans('DetailRefusCP').''; + print ''.$object->detail_refuse.''; + print ''; + } + + // Description + if (!$edit) + { + print ''; + print ''.$langs->trans('DescCP').''; + print ''.nl2br($object->description).''; + print ''; + } + else + { + print ''; + print ''.$langs->trans('DescCP').''; + print ''; + print ''; + } + + print ''.$langs->trans("NbOfAttachedFiles").''.count($filearray).''; + print ''.$langs->trans("TotalSizeOfAttachedFiles").''.dol_print_size($totalsize, 1, 1).''; + + print ''; + print ''."\n"; + /* print ''; print '
'; print '
'; @@ -288,20 +276,22 @@ print '
'; print '
'; */ - print ''; - - print '
'; - - print dol_get_fiche_end(); - - - - $modulepart = 'holiday'; - $permission = $user->rights->holiday->write; - $permtoedit = $user->rights->holiday->write; - $param = '&id='.$object->id; - include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; -} else { + print ''; + + print '
'; + + dol_fiche_end(); + + + + $modulepart = 'holiday'; + $permission = $user->rights->holiday->write; + $permtoedit = $user->rights->holiday->write; + $param = '&id='.$object->id; + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ print $langs->trans("ErrorUnknown"); } --- /tmp/dsg/dolibarr/htdocs/holiday/github_list.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_list.php @@ -32,12 +32,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('users', 'other', 'holiday', 'hrm')); +$langs->loadLangs(array('users', 'holiday', 'hrm')); // Protection if external user if ($user->socid > 0) accessforbidden(); @@ -68,14 +68,14 @@ // If we are on the view of a specific user if ($id > 0) { - $canread = 0; - if ($id == $user->id) $canread = 1; - if (!empty($user->rights->holiday->readall)) $canread = 1; - if (!empty($user->rights->holiday->read) && in_array($id, $childids)) $canread = 1; - if (!$canread) - { - accessforbidden(); - } + $canread = 0; + if ($id == $user->id) $canread = 1; + if (!empty($user->rights->holiday->read_all)) $canread = 1; + if (!empty($user->rights->holiday->read) && in_array($id, $childids)) $canread = 1; + if (!$canread) + { + accessforbidden(); + } } $diroutputmassaction = $conf->holiday->dir_output.'/temp/massgeneration/'.$user->id; @@ -83,8 +83,8 @@ // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; @@ -106,7 +106,7 @@ $search_year_end = GETPOST('search_year_end', 'int'); $search_employee = GETPOST('search_employee', 'int'); $search_valideur = GETPOST('search_valideur', 'int'); -$search_status = GETPOST('search_statut', 'int'); +$search_statut = GETPOST('search_statut', 'int'); $search_type = GETPOST('search_type', 'int'); // Initialize technical objects @@ -122,9 +122,9 @@ // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'cp.ref'=>'Ref', - 'cp.description'=>'Description', - 'uu.lastname'=>'EmployeeLastname', - 'uu.firstname'=>'EmployeeFirstname', + 'cp.description'=>'Description', + 'uu.lastname'=>'EmployeeLastname', + 'uu.firstname'=>'EmployeeFirstname', 'uu.login'=>'Login' ); @@ -143,17 +143,15 @@ 'cp.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - -if (empty($conf->holiday->enabled)) +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) { - llxHeader('', $langs->trans('CPTitreMenu')); - print '
'; - print ''.$langs->trans('NotActiveModCP').''; - print '
'; - llxFooter(); - exit(); -} + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} + /* @@ -178,13 +176,13 @@ $search_ref = ""; $search_month_create = ""; $search_year_create = ""; - $search_month_start = ""; + $search_month_start = ""; $search_year_start = ""; $search_month_end = ""; $search_year_end = ""; $search_employee = ""; $search_valideur = ""; - $search_status = ""; + $search_statut = ""; $search_type = ''; $toselect = ''; $search_array_options = array(); @@ -255,7 +253,7 @@ $sql .= " cp.date_debut,"; $sql .= " cp.date_fin,"; $sql .= " cp.halfday,"; -$sql .= " cp.statut as status,"; +$sql .= " cp.statut,"; $sql .= " cp.fk_validator,"; $sql .= " cp.date_valid,"; $sql .= " cp.fk_user_valid,"; @@ -270,7 +268,7 @@ $sql .= " uu.admin as user_admin,"; $sql .= " uu.email as user_email,"; $sql .= " uu.login as user_login,"; -$sql .= " uu.statut as user_status,"; +$sql .= " uu.statut as user_statut,"; $sql .= " uu.photo as user_photo,"; $sql .= " ua.lastname as validator_lastname,"; @@ -278,7 +276,7 @@ $sql .= " ua.admin as validator_admin,"; $sql .= " ua.email as validator_email,"; $sql .= " ua.login as validator_login,"; -$sql .= " ua.statut as validator_status,"; +$sql .= " ua.statut as validator_statut,"; $sql .= " ua.photo as validator_photo"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { @@ -313,14 +311,14 @@ } // Type if (!empty($search_type) && $search_type != -1) { - $sql .= ' AND cp.fk_type IN ('.$db->sanitize($db->escape($search_type)).')'; + $sql .= ' AND cp.fk_type IN ('.$db->escape($search_type).')'; } // Status -if (!empty($search_status) && $search_status != -1) { - $sql .= " AND cp.statut = '".$db->escape($search_status)."'\n"; -} - -if (empty($user->rights->holiday->readall)) $sql .= ' AND cp.fk_user IN ('.join(',', $childids).')'; +if (!empty($search_statut) && $search_statut != -1) { + $sql .= " AND cp.statut = '".$db->escape($search_statut)."'\n"; +} + +if (empty($user->rights->holiday->read_all)) $sql .= ' AND cp.fk_user IN ('.join(',', $childids).')'; if ($id > 0) $sql .= " AND cp.fk_user IN (".$id.")"; // Add where from extra fields @@ -373,7 +371,7 @@ if ($search_employee > 0) $param .= '&search_employee='.urlencode($search_employee); if ($search_valideur > 0) $param .= '&search_valideur='.urlencode($search_valideur); if ($search_type > 0) $param .= '&search_type='.urlencode($search_type); - if ($search_status > 0) $param .= '&search_status='.urlencode($search_status); + if ($search_statut > 0) $param .= '&search_statut='.urlencode($search_statut); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -404,37 +402,43 @@ $linkback = ''.$langs->trans("BackToList").''; $head = user_prepare_head($fuser); - print dol_get_fiche_head($head, 'paidholidays', $title, -1, 'user'); - - dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin); + dol_fiche_head($head, 'paidholidays', $title, -1, 'user'); + + dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin); if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) { - print '
'; - - print '
'; - - showMyBalance($object, $user_id); + print '
'; + + print '
'; + + showMyBalance($object, $user_id); } - print dol_get_fiche_end(); + dol_fiche_end(); // Buttons for actions print '
'; - $canedit = (($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance)))); + $canedit = (($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && $user->rights->holiday->write_all)); if ($canedit) { - print ''.$langs->trans("AddCP").''; + print ''.$langs->trans("AddCP").''; } print '
'; - } else { + } + else + { $title = $langs->trans("ListeCP"); - $newcardbutton = dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=create', '', $user->rights->holiday->write); + $newcardbutton = ''; + if ($user->rights->holiday->write) + { + $newcardbutton .= dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=request'); + } print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm', 0, $newcardbutton, '', $limit, 0, 0, 1); } @@ -447,8 +451,8 @@ if ($sall) { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } $moreforfilter = ''; @@ -471,7 +475,7 @@ $include = ''; - if (empty($user->rights->holiday->readall)) $include = 'hierarchyme'; // Can see only its hierarchyl + if (empty($user->rights->holiday->read_all)) $include = 'hierarchyme'; // Can see only its hierarchyl print '
'; print ''."\n"; @@ -489,8 +493,8 @@ if (!empty($arrayfields['cp.fk_user']['checked'])) { - $morefilter = ''; - if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) $morefilter = 'AND employee = 1'; + $morefilter = 'AND employee = 1'; + if (!empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; // User $disabled = 0; @@ -502,25 +506,27 @@ } print ''; } // Approver if (!empty($arrayfields['cp.fk_validator']['checked'])) { - if ($user->rights->holiday->readall) + if ($user->rights->holiday->read_all) { - print ''; - } else { - print ''; + print ''; + } + else + { + print ''; } } @@ -539,7 +545,7 @@ //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':''); $arraytypeleaves[$val['rowid']] = $labeltoshow; } - print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1); + print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1); } print ''; } @@ -597,7 +603,7 @@ if (!empty($arrayfields['cp.statut']['checked'])) { print ''; } @@ -614,7 +620,7 @@ if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], "cp.fk_user", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cp.fk_validator']['checked'])) print_liste_field_titre($arrayfields['cp.fk_validator']['label'], $_SERVER["PHP_SELF"], "cp.fk_validator", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cp.fk_type']['checked'])) print_liste_field_titre($arrayfields['cp.fk_type']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['duration']['checked'])) print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right maxwidth100'); + if (!empty($arrayfields['duration']['checked'])) print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], "cp.date_debut", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], "cp.date_fin", "", $param, '', $sortfield, $sortorder, 'center '); // Extra fields @@ -633,15 +639,16 @@ // If we ask a dedicated card and not allow to see it, we force on user. - if ($id && empty($user->rights->holiday->readall) && !in_array($id, $childids)) { + if ($id && empty($user->rights->holiday->read_all) && !in_array($id, $childids)) { $langs->load("errors"); print ''; $result = 0; - } elseif ($num > 0 && !empty($mysoc->country_id)) - { - // Lines - $userstatic = new User($db); - $approbatorstatic = new User($db); + } + elseif ($num > 0 && !empty($mysoc->country_id)) + { + // Lines + $userstatic = new User($db); + $approbatorstatic = new User($db); $typeleaves = $object->getTypes(1, -1); @@ -654,7 +661,6 @@ // Leave request $holidaystatic->id = $obj->rowid; $holidaystatic->ref = ($obj->ref ? $obj->ref : $obj->rowid); - $holidaystatic->statut = $obj->status; // User $userstatic->id = $obj->fk_user; @@ -663,7 +669,7 @@ $userstatic->admin = $obj->user_admin; $userstatic->email = $obj->user_email; $userstatic->login = $obj->user_login; - $userstatic->statut = $obj->user_status; + $userstatic->statut = $obj->user_statut; $userstatic->photo = $obj->user_photo; // Validator @@ -673,7 +679,7 @@ $approbatorstatic->admin = $obj->validator_admin; $approbatorstatic->email = $obj->validator_email; $approbatorstatic->login = $obj->validator_login; - $approbatorstatic->statut = $obj->validator_status; + $approbatorstatic->statut = $obj->validator_statut; $approbatorstatic->photo = $obj->validator_photo; $date = $obj->date_create; @@ -693,12 +699,12 @@ } if (!empty($arrayfields['cp.fk_user']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['cp.fk_validator']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['cp.fk_type']['checked'])) @@ -721,7 +727,7 @@ { print ''; if (!$i) $totalarray['nbfield']++; } @@ -729,7 +735,7 @@ { print ''; if (!$i) $totalarray['nbfield']++; } @@ -754,18 +760,18 @@ } if (!empty($arrayfields['cp.statut']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; - } - - // Action column - print ''; + if (!$i) $totalarray['nbfield']++; + } + + // Action column + print ''; if (!$i) $totalarray['nbfield']++; @@ -787,7 +793,9 @@ print ''; print ''; -} else { +} +else +{ dol_print_error($db); } --- /tmp/dsg/dolibarr/htdocs/holiday/github_month_report.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_month_report.php @@ -2,7 +2,6 @@ /* Copyright (C) 2007-2010 Laurent Destailleur * Copyright (C) 2011 François Legastelois * Copyright (C) 2018-2019 Frédéric France - * Copyright (C) 2020 Tobias Sekan * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,85 +42,13 @@ } $result = restrictedArea($user, 'holiday', $id, ''); -$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; -$massaction = GETPOST('massaction', 'alpha'); -$contextpage = GETPOST('contextpage', 'aZ'); -$optioncss = GETPOST('optioncss', 'aZ'); - -$search_ref = GETPOST('search_ref', 'alphanohtml'); -$search_employee = GETPOST('search_employee', 'int'); -$search_type = GETPOST('search_type', 'int'); -$search_description = GETPOST('search_description', 'alphanohtml'); - -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'alpha'); - -if (!$sortfield) $sortfield = "cp.rowid"; -if (!$sortorder) $sortorder = "ASC"; - -$hookmanager->initHooks(array('leavemovementlist')); - -$arrayfields = array(); -$arrayofmassactions = array(); - -/* - * Actions - */ - -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } - -$parameters = array(); -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -if (empty($reshook)) -{ - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - - // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { - $search_ref = ''; - $search_employee = ''; - $search_type = ''; - $search_description = ''; - $toselect = ''; - $search_array_options = array(); - } - - if (GETPOST('button_removefilter_x', 'alpha') - || GETPOST('button_removefilter.x', 'alpha') - || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') - || GETPOST('button_search.x', 'alpha') - || GETPOST('button_search', 'alpha')) - { - $massaction = ''; - } -} - -$arrayfields = array( - 'cp.ref'=>array('label'=>$langs->trans('Ref'), 'checked'=>1), - 'cp.fk_user'=>array('label'=>$langs->trans('Employee'), 'checked'=>1), - 'ct.label'=>array('label'=>$langs->trans('Type'), 'checked'=>1), - 'cp.date_debut'=>array('label'=>$langs->trans('DateDebCP'), 'checked'=>1), - 'cp.date_fin'=>array('label'=>$langs->trans('DateFinCP'), 'checked'=>1), - 'used_days'=>array('label'=>$langs->trans('NbUseDaysCPShort'), 'checked'=>1), - 'date_start_month'=>array('label'=>$langs->trans('DateStartInMonth'), 'checked'=>1), - 'date_end_month'=>array('label'=>$langs->trans('DateEndInMonth'), 'checked'=>1), - 'used_days_month'=>array('label'=>$langs->trans('NbUseDaysCPShortInMonth'), 'checked'=>1), - 'cp.description'=>array('label'=>$langs->trans('DescCP'), 'checked'=>1), -); /* * View */ -$form = new Form($db); +$html = new Form($db); $formother = new FormOther($db); $holidaystatic = new Holiday($db); @@ -129,24 +56,36 @@ llxHeader('', $langs->trans('CPTitreMenu')); +print load_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm'); + + +// Selection filter +print '
'; + +print '
'."\n"; + $search_month = GETPOST("remonth", 'int') ?GETPOST("remonth", 'int') : date("m", time()); $search_year = GETPOST("reyear", 'int') ?GETPOST("reyear", 'int') : date("Y", time()); + $year_month = sprintf("%04d", $search_year).'-'.sprintf("%02d", $search_month); -$sql = "SELECT cp.rowid, cp.ref, cp.fk_user, cp.date_debut, cp.date_fin, ct.label, cp.description, cp.halfday"; +print $formother->select_month($search_month, 'remonth'); + +print $formother->select_year($search_year, 'reyear'); + +print ''; + +print ''; + + +$sql = "SELECT cp.rowid, cp.fk_user, cp.date_debut, cp.date_fin, ct.label, cp.description, cp.halfday"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday cp"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON cp.fk_user = u.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_holiday_types ct ON cp.fk_type = ct.rowid"; $sql .= " WHERE cp.rowid > 0"; -$sql .= " AND cp.statut = 3"; // 3 = Approved +$sql .= " AND cp.statut = 3"; // Approved $sql .= " AND (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')"; - -if (!empty($search_ref)) $sql .= natural_search('cp.ref', $search_ref); -if (!empty($search_employee)) $sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'"; -if (!empty($search_type)) $sql .= ' AND cp.fk_type IN ('.$db->escape($search_type).')'; -if (!empty($search_description)) $sql .= natural_search('cp.description', $search_description); - -$sql .= $db->order($sortfield, $sortorder); +$sql .= " ORDER BY u.lastname, cp.date_debut"; $resql = $db->query($sql); if (empty($resql)) @@ -157,203 +96,101 @@ $num = $db->num_rows($resql); -$param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref); -if (!empty($search_employee)) $param .= '&search_employee='.urlencode($search_employee); -if (!empty($search_type)) $param .= '&search_type='.urlencode($search_type); -if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); +print '
'; -print '
'; -if ($optioncss != '') print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print load_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm'); - -// Selection filter -print '
'; -print $formother->select_month($search_month, 'remonth', 0, 0, 'minwidth50 maxwidth75imp valignmiddle', true); -print $formother->selectyear($search_year, 'reyear', 0, 10, 5, 0, 0, '', 'valignmiddle width75', true); -print ''; -print '
'; print '
'; - -$moreforfilter = ''; - -$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; -$selectedfields = ''; -$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields -$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); print '
'; print '
'; - print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150'); + print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200'); print ''; - $validator = new UserGroup($db); - $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id; - $valideurobjects = $validator->listUsersForGroup($excludefilter); - $valideurarray = array(); - foreach ($valideurobjects as $val) $valideurarray[$val->id] = $val->id; - print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150'); - print ' '; + $validator = new UserGroup($db); + $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id; + $valideurobjects = $validator->listUsersForGroup($excludefilter); + $valideurarray = array(); + foreach ($valideurobjects as $val) $valideurarray[$val->id] = $val->id; + print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200'); + print ' '; - $object->selectStatutCP($search_status, 'search_status'); + $object->selectStatutCP($search_statut, 'search_statut'); print '
'.$langs->trans("NotEnoughPermissions").'
'.$userstatic->getNomUrl(-1, 'leave').''.$userstatic->getNomUrl(-1, 'leave').''.$approbatorstatic->getNomUrl(-1).''.$approbatorstatic->getNomUrl(-1).''; print dol_print_date($db->jdate($obj->date_debut), 'day'); - print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; + print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; print ''; print dol_print_date($db->jdate($obj->date_fin), 'day'); - print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; + print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; print ''.$holidaystatic->getLibStatut(5).''; + print ''.$holidaystatic->LibStatut($obj->statut, 5).''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { - $selected = 0; + { + $selected = 0; if (in_array($obj->rowid, $arrayofselected)) $selected = 1; print ''; - } + } print '
'; print ''; - -// Filter: Ref -if (!empty($arrayfields['cp.ref']['checked'])) { - print ''; -} - -// Filter: Employee -if (!empty($arrayfields['cp.fk_user']['checked'])) { - print ''; -} - -// Filter: Type -if (!empty($arrayfields['ct.label']['checked'])) { - $typeleaves = $holidaystatic->getTypes(1, -1); - $arraytypeleaves = array(); - foreach ($typeleaves as $key => $val) - { - $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); - $arraytypeleaves[$val['rowid']] = $labeltoshow; - } - - print ''; -} - -if (!empty($arrayfields['cp.date_debut']['checked'])) print ''; -if (!empty($arrayfields['cp.date_fin']['checked'])) print ''; -if (!empty($arrayfields['used_days']['checked'])) print ''; -if (!empty($arrayfields['date_start_month']['checked'])) print ''; -if (!empty($arrayfields['date_end_month']['checked'])) print ''; -if (!empty($arrayfields['used_days_month']['checked'])) print ''; - -// Filter: Description -if (!empty($arrayfields['cp.description']['checked'])) { - print ''; -} - -// Action column -print ''; -print ''; - -print ''; -if (!empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], 'cp.ref', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], 'cp.fk_user', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['ct.label']['checked'])) print_liste_field_titre($arrayfields['ct.label']['label'], $_SERVER["PHP_SELF"], 'ct.label', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], 'cp.date_debut', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], 'cp.date_fin', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['used_days']['checked'])) print_liste_field_titre($arrayfields['used_days']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['date_start_month']['checked'])) print_liste_field_titre($arrayfields['date_start_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['date_end_month']['checked'])) print_liste_field_titre($arrayfields['date_end_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['used_days_month']['checked'])) print_liste_field_titre($arrayfields['used_days_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cp.description']['checked'])) print_liste_field_titre($arrayfields['cp.description']['label'], $_SERVER["PHP_SELF"], 'cp.description', '', '', '', $sortfield, $sortorder); -print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; print ''; if ($num == 0) { - print ''; + print ''; } -else { - while ($obj = $db->fetch_object($resql)) - { - $user = new User($db); - $user->fetch($obj->fk_user); +else +{ + while ($obj = $db->fetch_object($resql)) + { + $user = new User($db); + $user->fetch($obj->fk_user); - $date_start = $db->jdate($obj->date_debut, true); - $date_end = $db->jdate($obj->date_fin, true); + $date_start = $db->jdate($obj->date_debut, true); + $date_end = $db->jdate($obj->date_fin, true); - $tmpstart = dol_getdate($date_start); - $tmpend = dol_getdate($date_end); + $tmpstart = dol_getdate($date_start); + $tmpend = dol_getdate($date_end); - $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning'; - $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon'; + $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning'; + $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon'; - $halfdayinmonth = $obj->halfday; - $starthalfdayinmonth = $starthalfday; - $endhalfdayinmonth = $endhalfday; + $halfdayinmonth = $obj->halfday; + $starthalfdayinmonth = $starthalfday; + $endhalfdayinmonth = $endhalfday; - //0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning + //0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning - // Set date_start_gmt and date_end_gmt that are date to show for the selected month - $date_start_inmonth = $db->jdate($obj->date_debut, true); - $date_end_inmonth = $db->jdate($obj->date_fin, true); - if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month) - { - $date_start_inmonth = dol_get_first_day($search_year, $search_month, true); - $starthalfdayinmonth = 'morning'; - if ($halfdayinmonth == 2) $halfdayinmonth = 1; - if ($halfdayinmonth == -1) $halfdayinmonth = 0; - } - if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month) - { - $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1); - $endhalfdayinmonth = 'afternoon'; - if ($halfdayinmonth == 2) $halfdayinmonth = -1; - if ($halfdayinmonth == 1) $halfdayinmonth = 0; - } + // Set date_start_gmt and date_end_gmt that are date to show for the selected month + $date_start_inmonth = $db->jdate($obj->date_debut, true); + $date_end_inmonth = $db->jdate($obj->date_fin, true); + if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month) + { + $date_start_inmonth = dol_get_first_day($search_year, $search_month, true); + $starthalfdayinmonth = 'morning'; + if ($halfdayinmonth == 2) $halfdayinmonth = 1; + if ($halfdayinmonth == -1) $halfdayinmonth = 0; + } + if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month) + { + $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1); + $endhalfdayinmonth = 'afternoon'; + if ($halfdayinmonth == 2) $halfdayinmonth = -1; + if ($halfdayinmonth == 1) $halfdayinmonth = 0; + } - // Leave request - $holidaystatic->id = $obj->rowid; - $holidaystatic->ref = $obj->ref; + // Leave request + $holidaystatic->id = $obj->rowid; + $holidaystatic->ref = $obj->rowid; - print ''; - - if (!empty($arrayfields['cp.ref']['checked'])) print ''; - if (!empty($arrayfields['cp.fk_user']['checked'])) print ''; - if (!empty($arrayfields['ct.label']['checked'])) print ''; - - if (!empty($arrayfields['cp.date_debut']['checked'])) - { - print ''; - } - - if (!empty($arrayfields['cp.date_fin']['checked'])) - { - print ''; - } - - if (!empty($arrayfields['used_days']['checked'])) print ''; - - if (!empty($arrayfields['date_start_month']['checked'])) - { - print ''; - } - - if (!empty($arrayfields['date_end_month']['checked'])) - { - print ''; - } - - if (!empty($arrayfields['used_days_month']['checked'])) print ''; - if (!empty($arrayfields['cp.description']['checked'])) print ''; - - print ''; - print ''; - } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } } print '
'; - print ''; - print ''; - print $form->select_dolusers($search_employee, "search_employee", 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); - print ''; - print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1); - print ''; - print ''; - print ''; -$searchpicto = $form->showFilterButtons(); -print $searchpicto; -print '
'.$langs->trans('Ref').''.$langs->trans('Employee').''.$langs->trans('Type').''.$langs->trans('DateDebCP').''.$langs->trans('DateFinCP').''.$langs->trans('NbUseDaysCPShort').''.$langs->trans('DateStartInMonth').''.$langs->trans('DateEndInMonth').''.$langs->trans('NbUseDaysCPShortInMonth').''.$langs->trans('DescCP').'
'.$langs->trans('None').'
'.$langs->trans('None').'
'.$holidaystatic->getNomUrl(1, 1).''.$user->getFullName($langs).''.$obj->label.''.dol_print_date($db->jdate($obj->date_debut), 'day'); - print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; - print ''.dol_print_date($db->jdate($obj->date_fin), 'day'); - print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; - print ''.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).''.dol_print_date($date_start_inmonth, 'day'); - print ' ('.$langs->trans($listhalfday[$starthalfdayinmonth]).')'; - print ''.dol_print_date($date_end_inmonth, 'day'); - print ' ('.$langs->trans($listhalfday[$endhalfdayinmonth]).')'; - print ''.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).''.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'
'; + print $holidaystatic->getNomUrl(1, 1); + print ''.$user->getFullName($langs).''.$obj->label.''.dol_print_date($db->jdate($obj->date_debut), 'day'); + print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; + print ''.dol_print_date($db->jdate($obj->date_fin), 'day'); + print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; + print ''.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).''.dol_print_date($date_start_inmonth, 'day'); + print ' ('.$langs->trans($listhalfday[$starthalfdayinmonth]).')'; + print ''.dol_print_date($date_end_inmonth, 'day'); + print ' ('.$langs->trans($listhalfday[$endhalfdayinmonth]).')'; + print ''.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).''.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'
'; print '
'; -print ''; // End of page llxFooter(); --- /tmp/dsg/dolibarr/htdocs/holiday/github_view_log.php +++ /tmp/dsg/dolibarr/htdocs/holiday/client_view_log.php @@ -1,7 +1,6 @@ * Copyright (C) 2011 Dimitri Mouillard - * Copyright (C) 2020 Tobias Sekan * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,54 +24,49 @@ */ require '../main.inc.php'; - -// Security check (access forbidden for external user too) -if (empty($user->rights->holiday->define_holiday) || $user->socid > 0) { - accessforbidden(); -} - +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; -require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; -require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; - -$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... -$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) -$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? -$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation -$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button -$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list -$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectlist'; // To manage different context of search -$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page -$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') - -$search_id = GETPOST('search_id', 'alphanohtml'); -$search_month = GETPOST('search_month', 'int'); -$search_year = GETPOST('search_year', 'int'); -$search_employee = GETPOST('search_employee', 'int'); -$search_validator = GETPOST('search_validator', 'int'); -$search_description = GETPOST('search_description', 'alphanohtml'); -$search_type = GETPOST('search_type', 'int'); -$search_prev_solde = GETPOST('search_prev_solde', 'alphanohtml'); -$search_new_solde = GETPOST('search_new_solde', 'alphanohtml'); + +$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) +$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? +$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation +$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectlist'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') + +$search_id = GETPOST('search_id', 'alpha'); +$year = GETPOST('year'); +if (empty($year)) +{ + $tmpdate = dol_getdate(dol_now()); + $year = $tmpdate['year']; +} // Load variable for pagination -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = "cpl.rowid"; -if (!$sortorder) $sortorder = "DESC"; +//if (! $sortfield) $sortfield="p.date_fin"; +//if (! $sortorder) $sortorder="DESC"; + + +// Protection if external user +if ($user->socid > 0) accessforbidden(); // Si l'utilisateur n'a pas le droit de lire cette page -if (!$user->rights->holiday->readall) accessforbidden(); +if (!$user->rights->holiday->read_all) accessforbidden(); // Load translation files required by the page -$langs->loadLangs(array('users', 'other', 'holiday')); +$langs->load('users'); // Initialize technical objects $object = new Holiday($db); @@ -83,16 +77,6 @@ $arrayfields = array(); $arrayofmassactions = array(); -if (empty($conf->holiday->enabled)) -{ - llxHeader('', $langs->trans('CPTitreMenu')); - print '
'; - print ''.$langs->trans('NotActiveModCP').''; - print '
'; - llxFooter(); - exit(); -} - /* * Actions @@ -105,58 +89,34 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) { - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - - // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - $search_id = ''; - $search_month = ''; - $search_year = ''; - $search_employee = ''; - $search_validator = ''; - $search_description = ''; - $search_type = ''; - $search_prev_solde = ''; - $search_new_solde = ''; - $toselect = ''; - $search_array_options = array(); - } - - if (GETPOST('button_removefilter_x', 'alpha') - || GETPOST('button_removefilter.x', 'alpha') - || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') - || GETPOST('button_search.x', 'alpha') - || GETPOST('button_search', 'alpha')) - { - $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation - } - - // Mass actions - /*$objectclass='MyObject'; - $objectlabel='MyObject'; - $permissiontoread = $user->rights->mymodule->read; - $permissiontodelete = $user->rights->mymodule->delete; - $uploaddir = $conf->mymodule->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - */ -} - - -// Definition of fields for lists -$arrayfields = array( - 'cpl.rowid'=>array('label'=>$langs->trans("ID"), 'checked'=>1), - 'cpl.date_action'=>array('label'=>$langs->trans("Date"), 'checked'=>1), - 'cpl.fk_user_action'=>array('label'=>$langs->trans("ActionByCP"), 'checked'=>1), - 'cpl.fk_user_update'=>array('label'=>$langs->trans("UserUpdateCP"), 'checked'=>1), - 'cpl.type_action'=>array('label'=>$langs->trans("Description"), 'checked'=>1), - 'cpl.fk_type'=>array('label'=>$langs->trans("Type"), 'checked'=>1), - 'cpl.prev_solde'=>array('label'=>$langs->trans("PrevSoldeCP"), 'checked'=>1), - 'variation'=>array('label'=>$langs->trans("Variation"), 'checked'=>1), - 'cpl.new_solde'=>array('label'=>$langs->trans("NewSoldeCP"), 'checked'=>1), -); +if (empty($reshook)) +{ + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + $search_id = ''; + $toselect = ''; + $search_array_options = array(); + } + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) + { + $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } + + // Mass actions + /*$objectclass='MyObject'; + $objectlabel='MyObject'; + $permissiontoread = $user->rights->mymodule->read; + $permissiontodelete = $user->rights->mymodule->delete; + $uploaddir = $conf->mymodule->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + */ +} + /* @@ -164,67 +124,26 @@ */ $form = new Form($db); -$formother = new FormOther($db); -$holidaylogstatic = new stdClass(); + $alltypeleaves = $object->getTypes(1, -1); // To have labels -llxHeader('', $langs->trans('CPTitreMenu')); +llxHeader('', $langs->trans('CPTitreMenu').' ('.$langs->trans("Year").' '.$year.')'); + + $sqlwhere = ''; - -if (!empty($search_year) && $search_year > 0) { - if (!empty($search_month) && $search_month > 0) { - $from_date = dol_get_first_day($search_year, $search_month, 1); - $to_date = dol_get_last_day($search_year, $search_month, 1); - } else { - $from_date = dol_get_first_day($search_year, 1, 1); - $to_date = dol_get_last_day($search_year, 12, 1); - } - - $sqlwhere .= "AND date_action BETWEEN '".$db->idate($from_date)."' AND '".$db->idate($to_date)."'"; -} - -if (!empty($search_id) && $search_id > 0) $sqlwhere .= natural_search('rowid', $search_id, 1); -if (!empty($search_validator) && $search_validator > 0) $sqlwhere .= natural_search('fk_user_action', $search_validator, 1); -if (!empty($search_employee) && $search_employee > 0) $sqlwhere .= natural_search('fk_user_update', $search_employee, 1); -if (!empty($search_description)) $sqlwhere .= natural_search('type_action', $search_description); -if (!empty($search_type) && $search_type > 0) $sqlwhere .= natural_search('fk_type', $search_type, 1); -if (!empty($search_prev_solde)) $sqlwhere .= natural_search('prev_solde', $search_prev_solde, 1); -if (!empty($search_new_solde)) $sqlwhere .= natural_search('new_solde', $search_new_solde, 1); - -$sqlorder = $db->order($sortfield, $sortorder); +$sqlwhere .= " AND date_action BETWEEN '".$db->idate(dol_get_first_day($year, 1, 1))."' AND '".$db->idate(dol_get_last_day($year, 12, 1))."'"; +if ($search_id != '') $sqlwhere .= natural_search('rowid', $search_id, 1); + +$sqlorder = 'ORDER BY cpl.rowid DESC'; // Recent changes are more important than old changes $log_holiday = $object->fetchLog($sqlorder, $sqlwhere); // Load $object->logs -// Count total nb of records -$nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - //TODO: $result = $db->query($sql); - //TODO: $nbtotalofrecords = $db->num_rows($result); - $nbtotalofrecords = is_array($object->logs) ? count($object->logs) : 0; - - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 - $page = 0; - $offset = 0; - } -} - -// TODO: $num = $db->num_rows($resql); -$num = is_array($object->logs) ? count($object->logs) : 0; - $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -if (!empty($search_id)) $param .= '&search_statut='.urlencode($search_statut); -if (!empty($search_month) && $search_month > 0) $param .= '&search_month='.urlencode($search_month); -if (!empty($search_year) && $search_year > 0) $param .= '&search_year='.urlencode($search_year); -if (!empty($search_validator) && $search_validator > 0) $param .= '&search_validator='.urlencode($search_validator); -if (!empty($search_employee) && $search_employee > 0) $param .= '&search_employee='.urlencode($search_employee); -if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); -if (!empty($search_type) && $search_type > 0) $param .= '&search_type='.urlencode($search_type); -if (!empty($search_prev_solde)) $param .= '&search_prev_solde='.urlencode($search_prev_solde); -if (!empty($search_new_solde)) $param .= '&search_new_solde='.urlencode($search_new_solde); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); +if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); +if ($search_id) $param = '&search_id='.urlencode($search_id); print '
'; if ($optioncss != '') print ''; @@ -236,110 +155,43 @@ print ''; print ''; -$newcardbutton = dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=request', '', $user->rights->holiday->write); -print_barre_liste($langs->trans('LogCP'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_hrm', 0, $newcardbutton, '', $limit, 0, 0, 1); - -print '
'.$langs->trans('LastUpdateCP').': '; - +$pagination = ''; +print load_fiche_titre($langs->trans('LogCP'), $pagination, 'title_hrm.png'); + +print '
'.$langs->trans('LastUpdateCP').': '."\n"; $lastUpdate = $object->getConfCP('lastUpdate'); -if ($lastUpdate) { - $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; - $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3]; - print ''.dol_print_date($db->jdate($object->getConfCP('lastUpdate')), 'dayhour', 'tzuser').''; - print '
'; - print $langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''; -} else { - print $langs->trans('None'); -} -print '
'; -print '
'; +if ($lastUpdate) +{ + $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; + $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3]; + print ''.dol_print_date($db->jdate($object->getConfCP('lastUpdate')), 'dayhour', 'tzuser').''; + print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''."\n"; +} +else print $langs->trans('None'); +print "

\n"; $moreforfilter = ''; $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; +//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields +//$selectedfields.=(count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); $selectedfields = ''; -$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields -$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); print '
'; -print ''; - -print ''; - -// Filter Id -if (!empty($arrayfields['cpl.rowid']['checked'])) { - print ''; -} - -// Filter: Date -if (!empty($arrayfields['cpl.date_action']['checked'])) { - print ''; -} - -// Filter: Validator -if (!empty($arrayfields['cpl.fk_user_action']['checked'])) { - $validator = new UserGroup($db); - $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id; - $valideurobjects = $validator->listUsersForGroup($excludefilter); - $valideurarray = array(); - - foreach ($valideurobjects as $val) { - $valideurarray[$val->id] = $val->id; - } - - print ''; -} - -// Filter: User -if (!empty($arrayfields['cpl.fk_user_update']['checked'])) { - print ''; -} - -// Filter: Description -if (!empty($arrayfields['cpl.type_action']['checked'])) { - print ''; -} - -// Filter: Type -if (!empty($arrayfields['cpl.fk_type']['checked'])) { - foreach ($alltypeleaves as $key => $val) { - $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); - $arraytypeleaves[$val['rowid']] = $labeltoshow; - } - - print ''; -} - -// Filter: Previous balance -if (!empty($arrayfields['cpl.prev_solde']['checked'])) { - print ''; -} - -// Filter: Variation (only placeholder) -if (!empty($arrayfields['variation']['checked'])) { - print ''; -} - -// Filter: New Balance -if (!empty($arrayfields['cpl.new_solde']['checked'])) { - print ''; -} - +print '
'; - print ''; - print $formother->selectyear($search_year, 'search_year', 1, 10, 5, 0, 0, '', 'valignmiddle width75', true); - print ''; - print $form->select_dolusers($search_validator, "search_validator", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200'); - print ''; - print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200'); - print ''; - print ''; - print ''; - print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1); - print ''; - print ''; - print ''; - print ''; - print '
'."\n"; + +print ''; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; // Action column print ''; print ''; -if (!empty($arrayfields['cpl.rowid']['checked'])) print_liste_field_titre($arrayfields['cpl.rowid']['label'], $_SERVER["PHP_SELF"], 'rowid', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cpl.date_action']['checked'])) print_liste_field_titre($arrayfields['cpl.date_action']['label'], $_SERVER["PHP_SELF"], 'date_action', '', '', '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['cpl.fk_user_action']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_user_action']['label'], $_SERVER["PHP_SELF"], 'fk_user_action', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cpl.fk_user_update']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_user_update']['label'], $_SERVER["PHP_SELF"], 'fk_user_update', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cpl.type_action']['checked'])) print_liste_field_titre($arrayfields['cpl.type_action']['label'], $_SERVER["PHP_SELF"], 'type_action', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cpl.fk_type']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_type']['label'], $_SERVER["PHP_SELF"], 'fk_type', '', '', '', $sortfield, $sortorder); -if (!empty($arrayfields['cpl.prev_solde']['checked'])) print_liste_field_titre($arrayfields['cpl.prev_solde']['label'], $_SERVER["PHP_SELF"], 'prev_solde', '', '', '', $sortfield, $sortorder, 'right '); -if (!empty($arrayfields['variation']['checked'])) print_liste_field_titre($arrayfields['variation']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'right '); -if (!empty($arrayfields['cpl.new_solde']['checked'])) print_liste_field_titre($arrayfields['cpl.new_solde']['label'], $_SERVER["PHP_SELF"], 'new_solde', '', '', '', $sortfield, $sortorder, 'right '); -print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); +print_liste_field_titre('ID'); +print_liste_field_titre('Date', $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center '); +print_liste_field_titre('ActionByCP'); +print_liste_field_titre('UserUpdateCP'); +print_liste_field_titre('Description'); +print_liste_field_titre('Type'); +print_liste_field_titre('PrevSoldeCP', $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'right '); +print_liste_field_titre('Variation', $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'right '); +print_liste_field_titre('NewSoldeCP', $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'right '); +print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; print ''; -// TODO: $i = 0; -$i = 1; - -while ($i < min($num, $limit)) -{ - //TODO: $obj = $db->fetch_object($resql); - $obj = next($object->logs); - - $holidaylogstatic->id = $obj['rowid']; - $holidaylogstatic->date = $obj['date_action']; - $holidaylogstatic->validator = $obj['fk_user_action']; - $holidaylogstatic->employee = $obj['fk_user_update']; - $holidaylogstatic->description = $obj['type_action']; - $holidaylogstatic->type = $obj['fk_type']; - $holidaylogstatic->balance_previous = $obj['prev_solde']; - $holidaylogstatic->balance_new = $obj['new_solde']; - - print ''; - - // Id - if (!empty($arrayfields['cpl.rowid']['checked'])) { - print ''; - } - - // Date - if (!empty($arrayfields['cpl.date_action']['checked'])) { - print ''; - } - - // Validator - if (!empty($arrayfields['cpl.fk_user_action']['checked'])) { - $user_action = new User($db); - $user_action->fetch($holidaylogstatic->validator); - print ''; - } - - // Emloyee - if (!empty($arrayfields['cpl.fk_user_update']['checked'])) { - $user_update = new User($db); - $user_update->fetch($holidaylogstatic->employee); - print ''; - } - - // Description - if (!empty($arrayfields['cpl.type_action']['checked'])) { - print ''; - } - - // Type - if (!empty($arrayfields['cpl.fk_type']['checked'])) { - if ($alltypeleaves[$holidaylogstatic->type]['code'] && $langs->trans($alltypeleaves[$holidaylogstatic->type]['code']) != $alltypeleaves[$holidaylogstatic->type]['code']) { - $label = $langs->trans($alltypeleaves[$holidaylogstatic->type]['code']); - } else { - $label = $alltypeleaves[$holidaylogstatic->type]['label']; - } - - print ''; - } - - // Previous balance - if (!empty($arrayfields['cpl.prev_solde']['checked'])) { - print ''; - } - - // Variation - if (!empty($arrayfields['variation']['checked'])) { - $delta = price2num($holidaylogstatic->balance_new - $holidaylogstatic->balance_previous, 5); - $detasign = ($delta > 0 ? '+' : ''); - print ''; - } - - // New Balance - if (!empty($arrayfields['cpl.new_solde']['checked'])) { - print ''; - } - - // Buttons - print ''; - - print ''; - - $i++; -} - -if ($log_holiday == '2') { - print ''; - print ''; - print ''; -} - -print '
'; $searchpicto = $form->showFilterButtons(); @@ -348,111 +200,56 @@ print '
'.$holidaylogstatic->id.''.$holidaylogstatic->date.''.$user_action->getNomUrl(-1).''.$user_update->getNomUrl(-1).''.$holidaylogstatic->description.''; - print $label ? $label : $holidaylogstatic->type; - print ''.price2num($holidaylogstatic->balance_previous, 5).' '.$langs->trans('days').''.$detasign.$delta.''.price2num($holidaylogstatic->balance_new, 5).' '.$langs->trans('days').'
'.$langs->trans('NoRecordFound').'
'; + +foreach ($object->logs as $logs_CP) +{ + $user_action = new User($db); + $user_action->fetch($logs_CP['fk_user_action']); + + $user_update = new User($db); + $user_update->fetch($logs_CP['fk_user_update']); + + $delta = price2num($logs_CP['new_solde'] - $logs_CP['prev_solde'], 5); + $detasign = ($delta > 0 ? '+' : '-'); + + print ''; + print ''.$logs_CP['rowid'].''; + print ''.$logs_CP['date_action'].''; + print ''.$user_action->getNomUrl(-1).''; + print ''.$user_update->getNomUrl(-1).''; + print ''.$logs_CP['type_action'].''; + print ''; + $label = (($alltypeleaves[$logs_CP['fk_type']]['code'] && $langs->trans($alltypeleaves[$logs_CP['fk_type']]['code']) != $alltypeleaves[$logs_CP['fk_type']]['code']) ? $langs->trans($alltypeleaves[$logs_CP['fk_type']]['code']) : $alltypeleaves[$logs_CP['fk_type']]['label']); + print $label ? $label : $logs_CP['fk_type']; + print ''; + print ''.price2num($logs_CP['prev_solde'], 5).' '.$langs->trans('days').''; + print ''.$detasign.$delta.''; + print ''.price2num($logs_CP['new_solde'], 5).' '.$langs->trans('days').''; + print ''; + print ''."\n"; +} + +if ($log_holiday == '2') +{ + print ''; + print ''.$langs->trans('NoRecordFound').''; + print ''; +} + +print ''."\n"; +print ''."\n"; print '
'; print '
';