From 2bb8efa86f3d9dd277a5e3e3a4ed5582a256f540 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Fri, 26 Jun 2020 10:54:27 +0200 Subject: [PATCH 1/2] Common behavior for monthly leave list view --- htdocs/holiday/month_report.php | 238 ++++++++++++++++++++++++-------- 1 file changed, 179 insertions(+), 59 deletions(-) diff --git a/htdocs/holiday/month_report.php b/htdocs/holiday/month_report.php index 0c4ffe76335..6259b64062e 100644 --- a/htdocs/holiday/month_report.php +++ b/htdocs/holiday/month_report.php @@ -2,6 +2,7 @@ /* 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 @@ -42,13 +43,79 @@ if ($user->socid > 0) // Protection if external user } $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', 'alpha'); + +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST('sortfield', 'alpha'); +$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 = ''; + $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 */ -$html = new Form($db); +$form = new Form($db); $formother = new FormOther($db); $holidaystatic = new Holiday($db); @@ -56,36 +123,21 @@ $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->t 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); -print $formother->select_month($search_month, 'remonth'); +$sql = "SELECT cp.rowid, cp.ref, 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 (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')"; -print $formother->select_year($search_year, 'reyear'); +if ($search_ref != '') $sql.= natural_search('cp.ref', $search_ref, 0); -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"; // 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)."')"; -$sql .= " ORDER BY u.lastname, cp.date_debut"; +$sql.= $db->order($sortfield, $sortorder); $resql = $db->query($sql); if (empty($resql)) @@ -96,31 +148,79 @@ if (empty($resql)) $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 ($search_ref) $param = '&search_ref='.urlencode($search_ref); + +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'); +print $formother->select_year($search_year, 'reyear'); +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 ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -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 ''; +// 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 ''; if ($num == 0) { print ''; -} else { +} +else +{ while ($obj = $db->fetch_object($resql)) { $user = new User($db); @@ -161,34 +261,54 @@ if ($num == 0) // Leave request $holidaystatic->id = $obj->rowid; - $holidaystatic->ref = $obj->rowid; + $holidaystatic->ref = $obj->ref; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - 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 '
'.$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').''; +$searchpicto = $form->showFilterButtons(); +print $searchpicto; +print '
'.$langs->trans('None').'
'; - 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)).''.$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 '
'; +print '
'; // End of page llxFooter(); From a8ad21c011741bbbed63c05c6cf672ca37c46e7e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 26 Jun 2020 08:59:50 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/holiday/month_report.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/holiday/month_report.php b/htdocs/holiday/month_report.php index 6259b64062e..b6da0427464 100644 --- a/htdocs/holiday/month_report.php +++ b/htdocs/holiday/month_report.php @@ -44,9 +44,9 @@ if ($user->socid > 0) // Protection if external user $result = restrictedArea($user, 'holiday', $id, ''); $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; -$massaction = GETPOST('massaction', 'alpha'); +$massaction = GETPOST('massaction', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ'); -$optioncss = GETPOST('optioncss', 'aZ'); +$optioncss = GETPOST('optioncss', 'aZ'); $search_ref = GETPOST('search_ref', 'alpha'); @@ -219,8 +219,7 @@ if ($num == 0) { print ''.$langs->trans('None').''; } -else -{ +else { while ($obj = $db->fetch_object($resql)) { $user = new User($db);