From b3c49f2ec83a2bb0608cec4afe5b60f41452b99c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 24 Sep 2019 16:26:15 +0200 Subject: [PATCH] End of dev for extrafields on holiday --- htdocs/core/class/extrafields.class.php | 22 +- .../tpl/extrafields_list_search_input.tpl.php | 16 +- .../tpl/extrafields_list_search_sql.tpl.php | 10 +- htdocs/expensereport/list.php | 13 +- htdocs/holiday/card.php | 1470 +++++++++-------- htdocs/holiday/class/holiday.class.php | 2 + htdocs/holiday/list.php | 991 +++++------ 7 files changed, 1321 insertions(+), 1203 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 0a9f98b4afd..5f26365c2a8 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -959,9 +959,10 @@ class ExtraFields * @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric) * @param int $objectid Current object id * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data + * @param string $mode 1=Used for search filters * @return string */ - public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '') + public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0) { global $conf,$langs,$form; @@ -1116,13 +1117,20 @@ class ExtraFields } elseif ($type == 'boolean') { - $checked=''; - if (!empty($value)) { - $checked=' checked value="1" '; - } else { - $checked=' value="1" '; + if (empty($mode)) + { + $checked=''; + if (!empty($value)) { + $checked=' checked value="1" '; + } else { + $checked=' value="1" '; + } + $out=''; + } + else + { + $out.=$form->selectyesno($keyprefix.$key.$keysuffix, $value, 1, false, 1); } - $out=''; } elseif ($type == 'price') { diff --git a/htdocs/core/tpl/extrafields_list_search_input.tpl.php b/htdocs/core/tpl/extrafields_list_search_input.tpl.php index b4a98946f94..0b9a048f28a 100644 --- a/htdocs/core/tpl/extrafields_list_search_input.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_input.tpl.php @@ -22,28 +22,28 @@ if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_ if (! empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) { $align=$extrafields->getAlignFlag($key); $typeofextrafield=$extrafields->attributes[$extrafieldsobjectkey]['type'][$key]; + print ''; $tmpkey=preg_replace('/'.$search_options_pattern.'/', '', $key); if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) { - $crit=$val; $searchclass=''; if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; print ''; } - elseif (! in_array($typeofextrafield, array('datetime','timestamp'))) - { - // for the type as 'checkbox', 'chkbxlst', 'sellist' we should use code instead of id (example: I declare a 'chkbxlst' to have a link with dictionnairy, I have to extend it with the 'code' instead 'rowid') - $morecss=''; - if ($typeofextrafield == 'sellist') $morecss='maxwidth200'; - echo $extrafields->showInputField($key, $search_array_options[$search_options_pattern.$tmpkey], '', '', $search_options_pattern, $morecss); - } elseif (in_array($typeofextrafield, array('datetime','timestamp'))) { // TODO // Use showInputField in a particular manner to have input with a comparison operator, not input for a specific value date-hour-minutes } + else + { + // for the type as 'checkbox', 'chkbxlst', 'sellist' we should use code instead of id (example: I declare a 'chkbxlst' to have a link with dictionnairy, I have to extend it with the 'code' instead 'rowid') + $morecss=''; + if ($typeofextrafield == 'sellist') $morecss='maxwidth200'; + echo $extrafields->showInputField($key, $search_array_options[$search_options_pattern.$tmpkey], '', '', $search_options_pattern, $morecss, 0, $extrafieldsobjectkey, 1); + } print ''; } } diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index c2c4934c832..29c67094975 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -25,10 +25,18 @@ if (! empty($extrafieldsobjectkey) && ! empty($search_array_options) && is_array { $sql .= " AND ".$extrafieldsobjectprefix.$tmpkey." = '".$db->idate($crit)."'"; } + elseif (in_array($typ, array('boolean'))) + { + if ($crit !== '-1' && $crit !== '') { + $sql .= " AND (".$extrafieldsobjectprefix.$tmpkey." = '".$db->escape($crit)."'"; + if ($crit == '0') $sql.=" OR ".$extrafieldsobjectprefix.$tmpkey." IS NULL"; + $sql.= ")"; + } + } elseif ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1')) { $mode_search=0; - if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric + if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text if (is_array($crit)) $crit = implode(' ', $crit); // natural_search() expects a string diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index b51ae3d05f5..fd53e8af1d1 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -168,7 +168,7 @@ if (empty($reshook)) 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')) // Both test must be present to be compatible with all browsers + 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_user=""; @@ -259,9 +259,9 @@ $title = $langs->trans("ListOfTrips"); llxHeader('', $title); $max_year = 5; -$min_year = 5; +$min_year = 10; -// Récupération de l'ID de l'utilisateur +// Get current user id $user_id = $user->id; if ($id > 0) @@ -803,10 +803,9 @@ if ($resql) } else { - $colspan=1; - foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } - - print ''.''.$langs->trans("NoRecordFound").''; + $colspan=1; + foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } + print ''.$langs->trans("NoRecordFound").''; } // Show total line diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 2f0b9be9954..bc9c10045a8 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -37,9 +37,13 @@ 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/common.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; // Get parameters -$action=GETPOST('action', 'alpha'); +$action=GETPOST('action', 'aZ09'); +$cancel=GETPOST('cancel', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); + $id=GETPOST('id', 'int'); $ref=GETPOST('ref', 'alpha'); $fuserid = (GETPOST('fuserid', 'int')?GETPOST('fuserid', 'int'):$user->id); @@ -48,10 +52,10 @@ $fuserid = (GETPOST('fuserid', 'int')?GETPOST('fuserid', 'int'):$user->id); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'holiday', $id, 'holiday'); -$now=dol_now(); - // Load translation files required by the page -$langs->load("holiday"); +$langs->loadLangs(array("holiday","mails")); + +$now=dol_now(); $childids = $user->getAllChildIds(1); @@ -61,6 +65,11 @@ if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; $error = 0; $object = new Holiday($db); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + if ($id > 0) { $object->fetch($id); @@ -83,745 +92,798 @@ $candelete = 0; if (! empty($user->rights->holiday->delete)) $candelete=1; if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) $candelete=1; + /* * Actions */ -if (GETPOST('cancel', 'alpha')) -{ - $action = ''; -} +$parameters = array('socid' => $socid); +$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 create a request -if ($action == 'create') +if (empty($reshook)) { - // If no right to create a request - if (! $cancreate) - { - $error++; - setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); - $action='request'; - } + if ($cancel) + { + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + $action = ''; + } - if (! $error) - { - $object = new Holiday($db); + // If create a request + if ($action == 'create') + { - $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) + // If no right to create a request + if (! $cancreate) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $error++; - $action='create'; + $error++; + setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); + $action='request'; } - // 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; + $object = new Holiday($db); - $result = $object->create($user); - if ($result <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } + $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 + { + $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; + } } - // If no SQL error we redirect to the request card - if (! $error) - { - $db->commit(); + $action = ''; + } - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + if ($action == 'update' && ! GETPOSTISSET('savevalidator')) + { + $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'); + $halfday=0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; + elseif ($starthalfday == 'afternoon') $halfday=-1; + elseif ($endhalfday == 'morning') $halfday=1; + + // If no right to modify a request + if (! $user->rights->holiday->write) + { + header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=CantUpdate'); exit; } - else - { - $db->rollback(); + + $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', '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 + $verif = $object->update($user); + + if ($verif <= 0) + { + setEventMessages($object->error, $object->errors, 'warnings'); + $action='edit'; + } + 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=''; + } + } -if ($action == 'update' && GETPOSTISSET('savevalidator') && ! empty($user->rights->holiday->approve)) -{ - $object->fetch($id); + // If delete of request + if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete) + { + $error=0; - $object->oldcopy = dol_clone($object); + $db->begin(); - $object->fk_validator = GETPOST('valideur', 'int'); + $object->fetch($id); - 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')) -{ - $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'); - $halfday=0; - if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; - elseif ($starthalfday == 'afternoon') $halfday=-1; - elseif ($endhalfday == 'morning') $halfday=1; - - // 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', '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 - $verif = $object->update($user); - - if ($verif <= 0) + // 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) { - setEventMessages($object->error, $object->errors, 'warnings'); - $action='edit'; + $result=$object->delete($user); } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + $error++; + setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors'); + $action=''; } - } - else - { - setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - $action=''; - } - } - else - { - setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors'); - $action=''; - } -} + } -// If delete of request -if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete) -{ - $error=0; - - $db->begin(); - - $object->fetch($id); - - // 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) + if (! $error) { - $result=$object->delete($user); + $db->commit(); + header('Location: list.php?restore_lastsearch_values=1'); + exit; } else { - $error++; - setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors'); - $action=''; + $db->rollback(); } } - if (! $error) + // Action validate (+ send email for approval) + if ($action == 'confirm_send') { - $db->commit(); - header('Location: list.php?restore_lastsearch_values=1'); - exit; + $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=''; + } + } } - else + + if ($action == 'update_extras') { - $db->rollback(); + $object->oldcopy = dol_clone($object); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + if ($ret < 0) $error++; + + if (! $error) + { + // Actions on extra fields + $result = $object->insertExtraFields('HOLIDAY_MODIFY'); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + + if ($error) + $action = 'edit_extras'; } -} - -// Action validate (+ send email for approval) -if ($action == 'confirm_send') -{ - $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=''; - } - } -} - - -// Approve leave request -if ($action == 'confirm_valid') -{ - $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; - - // 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'; - } -} - - -// Si Validation de la demande -if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') -{ - $error = 0; - - $object->fetch($id); - - $oldstatus = $object->statut; - $object->statut = Holiday::STATUS_DRAFT; - - $result = $object->update($user); - if ($result < 0) - { - $error++; - setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors'); - } - - if (! $error) - { - $db->commit(); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $db->rollback(); - } -} - -// Si confirmation of cancellation -if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') -{ - $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($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; - } - } - } + + // Approve leave request + if ($action == 'confirm_valid') + { + $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; + + // 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'; + } + } + + + // Si Validation de la demande + if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') + { + $error = 0; + + $object->fetch($id); + + $oldstatus = $object->statut; + $object->statut = Holiday::STATUS_DRAFT; + + $result = $object->update($user); + if ($result < 0) + { + $error++; + setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $db->rollback(); + } + } + + // Si confirmation of cancellation + if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') + { + $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($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; + } + } + } + } + + /* + // Actions when printing a doc from card + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; + + // Actions to send emails + $trigger_name='HOLIDAY_SENTBYMAIL'; + $autocopy='MAIN_MAIL_AUTOCOPY_HOLIDAY_TO'; + $trackid='leav'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + + // Actions to build doc + $upload_dir = $conf->holiday->dir_output; + $permissioncreate = $user->rights->holiday->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + */ } @@ -1049,6 +1111,9 @@ if ((empty($id) && empty($ref)) || $action == 'add' || $action == 'request' || $ print $doleditor->Create(1); print ''; + // Other attributes + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; + print ''; print ''; @@ -1248,6 +1313,9 @@ else print ''; } + // Other attributes + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + print ''; print ''."\n"; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 7557a7941fb..25d1c1d5a2d 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -402,6 +402,8 @@ class Holiday extends CommonObject } $this->db->free($resql); + $this->fetch_optionals(); + return 1; } else diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 145f2f7b48f..072a6aacc45 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -210,68 +210,19 @@ $form = new Form($db); $formother = new FormOther($db); $formfile = new FormFile($db); -$holidaystatic=new Holiday($db); $fuser = new User($db); +$holidaystatic=new Holiday($db); // Update sold $result = $object->updateBalance(); -$max_year = 5; -$min_year = 10; -$filter=''; - $title = $langs->trans('CPTitreMenu'); llxHeader('', $title); -$order = $db->order($sortfield, $sortorder).$db->plimit($limit + 1, $offset); +$max_year = 5; +$min_year = 10; -// Ref -if(!empty($search_ref)) -{ - $filter.= " AND cp.rowid = ".(int) $db->escape($search_ref); -} -// Start date -$filter.= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start); -// End date -$filter.= dolSqlDateFilter("cp.date_fin", $search_day_end, $search_month_end, $search_year_end); -// Create date -$filter.= dolSqlDateFilter("cp.date_create", $search_day_create, $search_month_create, $search_year_create); -// Employee -if(!empty($search_employee) && $search_employee != -1) { - $filter.= " AND cp.fk_user = '".$db->escape($search_employee)."'\n"; -} -// Validator -if(!empty($search_valideur) && $search_valideur != -1) { - $filter.= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n"; -} -// Type -if (!empty($search_type) && $search_type != -1) { - $filter.= ' AND cp.fk_type IN ('.$db->escape($search_type).')'; -} -// Status -if(!empty($search_statut) && $search_statut != -1) { - $filter.= " AND cp.statut = '".$db->escape($search_statut)."'\n"; -} -// Search all -if (!empty($sall)) -{ - $filter.= natural_search(array_keys($fieldstosearchall), $sall); -} - -if (empty($user->rights->holiday->read_all)) $filter.=' AND cp.fk_user IN ('.join(',', $childids).')'; - -$sql=''; -// Add where from extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; -// Add where from hooks -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; - -$filter.=$sql; - - -// Récupération de l'ID de l'utilisateur +// Get current user id $user_id = $user->id; if ($id > 0) @@ -286,476 +237,558 @@ if ($id > 0) // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy // Load array $object->holiday -if (empty($user->rights->holiday->read_all) || $id > 0) -{ - if ($id > 0) $result = $object->fetchByUser($id, $order, $filter); - else $result = $object->fetchByUser(join(',', $childids), $order, $filter); -} -else -{ - $result = $object->fetchAll($order, $filter); -} -// Si erreur SQL -if ($result == '-1') -{ - print load_fiche_titre($langs->trans('CPTitreMenu'), '', 'title_hrm.png'); - dol_print_error($db, $langs->trans('Error').' '.$object->error); - exit(); +$sql = "SELECT"; +$sql.= " cp.rowid,"; +$sql.= " cp.ref,"; + +$sql.= " cp.fk_user,"; +$sql.= " cp.fk_type,"; +$sql.= " cp.date_create,"; +$sql.= " cp.tms as date_update,"; +$sql.= " cp.description,"; +$sql.= " cp.date_debut,"; +$sql.= " cp.date_fin,"; +$sql.= " cp.halfday,"; +$sql.= " cp.statut,"; +$sql.= " cp.fk_validator,"; +$sql.= " cp.date_valid,"; +$sql.= " cp.fk_user_valid,"; +$sql.= " cp.date_refuse,"; +$sql.= " cp.fk_user_refuse,"; +$sql.= " cp.date_cancel,"; +$sql.= " cp.fk_user_cancel,"; +$sql.= " cp.detail_refuse,"; + +$sql.= " uu.lastname as user_lastname,"; +$sql.= " uu.firstname as user_firstname,"; +$sql.= " uu.login as user_login,"; +$sql.= " uu.statut as user_statut,"; +$sql.= " uu.photo as user_photo,"; + +$sql.= " ua.lastname as validator_lastname,"; +$sql.= " ua.firstname as validator_firstname,"; +$sql.= " ua.login as validator_login,"; +$sql.= " ua.statut as validator_statut,"; +$sql.= " ua.photo as validator_photo"; +// Add fields from extrafields +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); +// Add fields from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."holiday_extrafields as ef on (cp.rowid = ef.fk_object)"; +$sql.= ", ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua"; +$sql.= " WHERE cp.entity IN (".getEntity('holiday').")"; +$sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau +// Search all +if (!empty($sall)) $sql.= natural_search(array_keys($fieldstosearchall), $sall); +// Ref +if(!empty($search_ref)) +{ + $sql.= " AND cp.rowid = ".(int) $db->escape($search_ref); +} +// Start date +$sql.= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start); +// End date +$sql.= dolSqlDateFilter("cp.date_fin", $search_day_end, $search_month_end, $search_year_end); +// Create date +$sql.= dolSqlDateFilter("cp.date_create", $search_day_create, $search_month_create, $search_year_create); +// Employee +if(!empty($search_employee) && $search_employee != -1) { + $sql.= " AND cp.fk_user = '".$db->escape($search_employee)."'\n"; +} +// Validator +if(!empty($search_valideur) && $search_valideur != -1) { + $sql.= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n"; +} +// Type +if (!empty($search_type) && $search_type != -1) { + $sql.= ' AND cp.fk_type IN ('.$db->escape($search_type).')'; +} +// Status +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.")"; -// Show table of vacations +// Add where from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; +// Add where from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; -$num = count($object->holiday); +$sql.= $db->order($sortfield, $sortorder); -$arrayofselected=is_array($toselect)?$toselect:array(); - -$param=''; -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); -if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); -if ($search_ref) $param.='&search_ref='.urlencode($search_ref); -if ($search_day_create) $param.='&search_day_create='.urlencode($search_day_create); -if ($search_month_create) $param.='&search_month_create='.urlencode($search_month_create); -if ($search_year_create) $param.='&search_year_create='.urlencode($search_year_create); -if ($search_day_start) $param.='&search_day_start='.urlencode($search_day_start); -if ($search_month_start) $param.='&search_month_start='.urlencode($search_month_start); -if ($search_year_start) $param.='&search_year_start='.urlencode($search_year_start); -if ($search_day_end) $param.='&search_day_end='.urlencode($search_day_end); -if ($search_month_end) $param.='&search_month_end='.urlencode($search_month_end); -if ($search_year_end) $param.='&search_year_end='.urlencode($search_year_end); -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_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'; - -// List of mass actions available -$arrayofmassactions = array( - //'generate_doc'=>$langs->trans("ReGeneratePDF"), - //'builddoc'=>$langs->trans("PDFMerge"), - //'presend'=>$langs->trans("SendByMail"), -); -if ($user->rights->holiday->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); -if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); -$massactionbutton=$form->selectMassAction('', $arrayofmassactions); - -print '
'; -if ($optioncss != '') print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -if ($id > 0) print ''; - -if ($id > 0) // For user tab +// Count total nb of records +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $title = $langs->trans("User"); - $linkback = ''.$langs->trans("BackToList").''; - $head = user_prepare_head($fuser); - - 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)) + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 { - print '
'; - - print '
'; - - showMyBalance($object, $user_id); + $page = 0; + $offset = 0; } - - dol_fiche_end(); - - // Buttons for actions - - print '
'; - - $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 '
'; } -else + +$sql.= $db->plimit($limit+1, $offset); + + +//print $sql; +$resql = $db->query($sql); +if ($resql) { - $nbtotalofrecords = count($object->holiday); - //print $num; - //print count($object->holiday); + $num = $db->num_rows($resql); - $title = $langs->trans("ListeCP"); + $arrayofselected=is_array($toselect)?$toselect:array(); - $newcardbutton=''; - if ($user->rights->holiday->write) + $param=''; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + if ($search_ref) $param.='&search_ref='.urlencode($search_ref); + if ($search_day_create) $param.='&search_day_create='.urlencode($search_day_create); + if ($search_month_create) $param.='&search_month_create='.urlencode($search_month_create); + if ($search_year_create) $param.='&search_year_create='.urlencode($search_year_create); + if ($search_day_start) $param.='&search_day_start='.urlencode($search_day_start); + if ($search_month_start) $param.='&search_month_start='.urlencode($search_month_start); + if ($search_year_start) $param.='&search_year_start='.urlencode($search_year_start); + if ($search_day_end) $param.='&search_day_end='.urlencode($search_day_end); + if ($search_month_end) $param.='&search_month_end='.urlencode($search_month_end); + if ($search_year_end) $param.='&search_year_end='.urlencode($search_year_end); + 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_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'; + + // List of mass actions available + $arrayofmassactions = array( + //'generate_doc'=>$langs->trans("ReGeneratePDF"), + //'builddoc'=>$langs->trans("PDFMerge"), + //'presend'=>$langs->trans("SendByMail"), + ); + if ($user->rights->holiday->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); + if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + + // Lines of title fields + print ''."\n"; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($id > 0) print ''; + + if ($id > 0) // For user tab { - $newcardbutton.= dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=request'); - } + $title = $langs->trans("User"); + $linkback = ''.$langs->trans("BackToList").''; + $head = user_prepare_head($fuser); - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm.png', 0, $newcardbutton, '', $limit); + 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); + } + + dol_fiche_end(); + + // Buttons for actions + + print '
'; + + $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 '
'; + } + else + { + $title = $langs->trans("ListeCP"); + + $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.png', 0, $newcardbutton, '', $limit); + } $topicmail="Information"; $modelmail="leaverequest"; $objecttmp=new Holiday($db); $trackid='leav'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -} -if ($sall) -{ - foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; -} - -$moreforfilter=''; - -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; - -if (! empty($moreforfilter)) -{ - print '
'; - print $moreforfilter; - print '
'; -} - -$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) : ''); - - -$include = ''; -if (! empty($user->rights->holiday->read_all)) $include = 'hierarchyme'; // Can see all - -print '
'; -print ''."\n"; - - -// Filters -print ''; - -if (! empty($arrayfields['cp.ref']['checked'])) -{ - print ''; -} - -if (! empty($arrayfields['cp.fk_user']['checked'])) -{ - $morefilter = 'AND employee = 1'; - if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; - - // User - $disabled=0; - // If into the tab holiday of a user ($id is set in such a case) - if ($id && ! GETPOSTISSET('search_employee')) + if ($sall) { - $search_employee=$id; - $disabled=1; + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; } - print ''; -} + $moreforfilter=''; -// Approver -if (! empty($arrayfields['cp.fk_validator']['checked'])) -{ - if ($user->rights->holiday->read_all) + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; + else $moreforfilter = $hookmanager->resPrint; + + if (! empty($moreforfilter)) { - print ''; + print '
'; + print $moreforfilter; + print '
'; } - else + + $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) : ''); + + + $include = ''; + if (! empty($user->rights->holiday->read_all)) $include = 'hierarchyme'; // Can see all + + print '
'; + print '
'; - print ''; - print ''; - 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, '', 'maxwidth200'); - print '
'."\n"; + + + // Filters + print ''; + + if (! empty($arrayfields['cp.ref']['checked'])) { - print ''; + print ''; } -} -// Type -if (! empty($arrayfields['cp.fk_type']['checked'])) -{ - print ''; -} - -// Duration -if (! empty($arrayfields['duration']['checked'])) -{ - print ''; -} - -// Start date -if (! empty($arrayfields['cp.date_debut']['checked'])) -{ - print ''; -} - -// End date -if (! empty($arrayfields['cp.date_fin']['checked'])) -{ - print ''; -} - -// Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; -// Fields from hook -$parameters=array('arrayfields'=>$arrayfields); -$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; - -// Create date -if (! empty($arrayfields['cp.date_create']['checked'])) -{ - print ''; -} - -// Create date -if (! empty($arrayfields['cp.tms']['checked'])) -{ - print ''; -} - -// Status -if (! empty($arrayfields['cp.statut']['checked'])) -{ - print ''; -} - -// Actions -print ''; - -print "\n"; - -print ''; -if (! empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder); -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 '); -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 -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; -// Hook fields -$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); -$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; -if (! empty($arrayfields['cp.date_create']['checked'])) print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center '); -if (! empty($arrayfields['cp.tms']['checked'])) print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center '); -if (! empty($arrayfields['cp.statut']['checked'])) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right '); -print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); -print "\n"; - -$listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); - - -// If we ask a dedicated card and not allow to see it, we forc on user. -if ($id && empty($user->rights->holiday->read_all) && ! in_array($id, $childids)) { - $langs->load("errors"); - print ''; - $result = 0; -} -elseif (! empty($object->holiday) && !empty($mysoc->country_id)) -{ - // Lines - $userstatic = new User($db); - $approbatorstatic = new User($db); - - $typeleaves=$object->getTypes(1, -1); - - $i = 0; - $totalarray=array(); - foreach($object->holiday as $infos_CP) + if (! empty($arrayfields['cp.fk_user']['checked'])) { - // Leave request - $holidaystatic->id=$infos_CP['rowid']; - $holidaystatic->ref=($infos_CP['ref']?$infos_CP['ref']:$infos_CP['rowid']); + $morefilter = 'AND employee = 1'; + if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; // User - $userstatic->id=$infos_CP['fk_user']; - $userstatic->lastname=$infos_CP['user_lastname']; - $userstatic->firstname=$infos_CP['user_firstname']; - $userstatic->login=$infos_CP['user_login']; - $userstatic->statut=$infos_CP['user_statut']; - $userstatic->photo=$infos_CP['user_photo']; - - // Validator - $approbatorstatic->id=$infos_CP['fk_validator']; - $approbatorstatic->lastname=$infos_CP['validator_lastname']; - $approbatorstatic->firstname=$infos_CP['validator_firstname']; - $approbatorstatic->login=$infos_CP['validator_login']; - $approbatorstatic->statut=$infos_CP['validator_statut']; - $approbatorstatic->photo=$infos_CP['validator_photo']; - - $date = $infos_CP['date_create']; - $date_modif = $infos_CP['date_update']; - - $starthalfday=($infos_CP['halfday'] == -1 || $infos_CP['halfday'] == 2)?'afternoon':'morning'; - $endhalfday=($infos_CP['halfday'] == 1 || $infos_CP['halfday'] == 2)?'morning':'afternoon'; - - print ''; - - if (! empty($arrayfields['cp.ref']['checked'])) + $disabled=0; + // If into the tab holiday of a user ($id is set in such a case) + if ($id && ! GETPOSTISSET('search_employee')) { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.fk_user']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.fk_validator']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.fk_type']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['duration']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.date_debut']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.date_fin']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; + $search_employee=$id; + $disabled=1; } - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); - $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Date creation - if (! empty($arrayfields['cp.date_create']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.tms']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - if (! empty($arrayfields['cp.statut']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - - // Action column - print ''; - if (! $i) $totalarray['nbfield']++; - - print ''."\n"; - - $i++; } -} -// Si il n'y a pas d'enregistrement suite à une recherche -if ($result == '2') -{ - print ''; - print ''; - print ''; -} + // Approver + if (! empty($arrayfields['cp.fk_validator']['checked'])) + { + if ($user->rights->holiday->read_all) + { + print ''; + } + else + { + print ''; + } + } -print '
 '; + print ''; + print ''; - if (empty($mysoc->country_id)) { - setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"),$langs->trans("CompanyFoundation")), 'errors'); - } else { - $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']); - //$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); - } - print ' '; - print ''; - $formother->select_year($search_year_start, 'search_year_start', 1, $min_year, $max_year); - print ''; - print ''; - $formother->select_year($search_year_end, 'search_year_end', 1, $min_year, $max_year); - print ''; - print ''; - $formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0); - print ''; - print ''; - $formother->select_year($search_year_update, 'search_year_update', 1, $min_year, 0); - print ''; - $object->selectStatutCP($search_statut, 'search_statut'); - print ''; -$searchpicto=$form->showFilterButtons(); -print $searchpicto; -print '
'.$langs->trans("NotEnoughPermissions").'
'; - print $holidaystatic->getNomUrl(1, 1); - print ''.$userstatic->getNomUrl(-1, 'leave').''.$approbatorstatic->getNomUrl(-1).''; - $labeltypeleavetoshow = ($langs->trans($typeleaves[$infos_CP['fk_type']]['code'])!=$typeleaves[$infos_CP['fk_type']]['code'] ? $langs->trans($typeleaves[$infos_CP['fk_type']]['code']) : $typeleaves[$infos_CP['fk_type']]['label']); - print empty($typeleaves[$infos_CP['fk_type']]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $infos_CP['fk_type']) : $labeltypeleavetoshow; - print ''; - $nbopenedday=num_open_day($infos_CP['date_debut_gmt'], $infos_CP['date_fin_gmt'], 0, 1, $infos_CP['halfday']); - print $nbopenedday.' '.$langs->trans('DurationDays'); - print ''; - print dol_print_date($infos_CP['date_debut'], 'day'); - print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; - print ''; - print dol_print_date($infos_CP['date_fin'], 'day'); - print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; - print ''.dol_print_date($date, 'day').''.dol_print_date($date_modif, 'day').''.$holidaystatic->LibStatut($infos_CP['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; - if (in_array($infos_CP['rowid'], $arrayofselected)) $selected=1; - print ''; - } + print ''; + print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200'); print '
'.$langs->trans('NoRecordFound').'
'; + $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 ' 
'; -print '
'; + // Type + if (! empty($arrayfields['cp.fk_type']['checked'])) + { + print ''; + if (empty($mysoc->country_id)) { + setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"),$langs->trans("CompanyFoundation")), 'errors'); + } else { + $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']); + //$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); + } + print ''; + } -print '
'; + // Duration + if (! empty($arrayfields['duration']['checked'])) + { + print ' '; + } -/*if ($user_id == $user->id) -{ - print '
'; - print '
'; - print ''.$langs->trans('AddCP').''; + // Start date + if (! empty($arrayfields['cp.date_debut']['checked'])) + { + print ''; + print ''; + $formother->select_year($search_year_start, 'search_year_start', 1, $min_year, $max_year); + print ''; + } + + // End date + if (! empty($arrayfields['cp.date_fin']['checked'])) + { + print ''; + print ''; + $formother->select_year($search_year_end, 'search_year_end', 1, $min_year, $max_year); + print ''; + } + + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Create date + if (! empty($arrayfields['cp.date_create']['checked'])) + { + print ''; + print ''; + $formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0); + print ''; + } + + // Create date + if (! empty($arrayfields['cp.tms']['checked'])) + { + print ''; + print ''; + $formother->select_year($search_year_update, 'search_year_update', 1, $min_year, 0); + print ''; + } + + // Status + if (! empty($arrayfields['cp.statut']['checked'])) + { + print ''; + $object->selectStatutCP($search_statut, 'search_statut'); + print ''; + } + + // Action column + print ''; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print ''; + + print "\n"; + + print ''; + if (! empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder); + 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 '); + 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 + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; + // Hook fields + $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); + $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (! empty($arrayfields['cp.date_create']['checked'])) print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center '); + if (! empty($arrayfields['cp.tms']['checked'])) print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center '); + if (! empty($arrayfields['cp.statut']['checked'])) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); + print "\n"; + + $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); + + + // If we ask a dedicated card and not allow to see it, we force on user. + if ($id && empty($user->rights->holiday->read_all) && ! in_array($id, $childids)) { + $langs->load("errors"); + print ''.$langs->trans("NotEnoughPermissions").''; + $result = 0; + } + elseif ($num > 0 && !empty($mysoc->country_id)) + { + // Lines + $userstatic = new User($db); + $approbatorstatic = new User($db); + + $typeleaves=$object->getTypes(1, -1); + + $i = 0; + $totalarray=array(); + while ($i < min($num, $limit)) + { + $obj = $db->fetch_object($resql); + + // Leave request + $holidaystatic->id=$obj->rowid; + $holidaystatic->ref=($obj->ref?$obj->ref:$obj->rowid); + + // User + $userstatic->id=$obj->fk_user; + $userstatic->lastname=$obj->user_lastname; + $userstatic->firstname=$obj->user_firstname; + $userstatic->login=$obj->user_login; + $userstatic->statut=$obj->user_statut; + $userstatic->photo=$obj->user_photo; + + // Validator + $approbatorstatic->id=$obj->fk_validator; + $approbatorstatic->lastname=$obj->validator_lastname; + $approbatorstatic->firstname=$obj->validator_firstname; + $approbatorstatic->login=$obj->validator_login; + $approbatorstatic->statut=$obj->validator_statut; + $approbatorstatic->photo=$obj->validator_photo; + + $date = $obj->date_create; + $date_modif = $obj->date_update; + + $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning'; + $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon'; + + print ''; + + if (! empty($arrayfields['cp.ref']['checked'])) + { + print ''; + print $holidaystatic->getNomUrl(1, 1); + print ''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.fk_user']['checked'])) + { + print ''.$userstatic->getNomUrl(-1, 'leave').''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.fk_validator']['checked'])) + { + print ''.$approbatorstatic->getNomUrl(-1).''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.fk_type']['checked'])) + { + print ''; + $labeltypeleavetoshow = ($langs->trans($typeleaves[$obj->fk_type]['code'])!=$typeleaves[$obj->fk_type]['code'] ? $langs->trans($typeleaves[$obj->fk_type]['code']) : $typeleaves[$obj->fk_type]['label']); + print empty($typeleaves[$obj->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $obj->fk_type) : $labeltypeleavetoshow; + print ''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['duration']['checked'])) + { + print ''; + $nbopenedday=num_open_day($db->jdate($obj->date_debut, 1), $db->jdate($obj->date_fin, 1), 0, 1, $obj->halfday); + print $nbopenedday.' '.$langs->trans('DurationDays'); + print ''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.date_debut']['checked'])) + { + print ''; + print dol_print_date($db->jdate($obj->date_debut), 'day'); + print ' ('.$langs->trans($listhalfday[$starthalfday]).')'; + print ''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.date_fin']['checked'])) + { + print ''; + print dol_print_date($db->jdate($obj->date_fin), 'day'); + print ' ('.$langs->trans($listhalfday[$endhalfday]).')'; + print ''; + if (! $i) $totalarray['nbfield']++; + } + + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Date creation + if (! empty($arrayfields['cp.date_create']['checked'])) + { + print ''.dol_print_date($date, 'dayhour').''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.tms']['checked'])) + { + print ''.dol_print_date($date_modif, 'dayhour').''; + if (! $i) $totalarray['nbfield']++; + } + if (! empty($arrayfields['cp.statut']['checked'])) + { + print ''.$holidaystatic->LibStatut($obj->statut, 5).''; + if (! $i) $totalarray['nbfield']++; + } + + // Action column + print ''; + 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; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print ''; + } + print ''; + if (! $i) $totalarray['nbfield']++; + + print ''."\n"; + + $i++; + } + } + + // Si il n'y a pas d'enregistrement suite à une recherche + if ($num == 0) + { + $colspan=1; + foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } + print ''.$langs->trans("NoRecordFound").''; + } + + print ''; print '
'; -}*/ + + print ''; +} +else +{ + dol_print_error($db); +} // End of page llxFooter();