End of dev for extrafields on holiday

This commit is contained in:
Laurent Destailleur 2019-09-24 16:26:15 +02:00
parent 961f2b5165
commit b3c49f2ec8
7 changed files with 1321 additions and 1203 deletions

View File

@ -959,9 +959,10 @@ class ExtraFields
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric) * @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
* @param int $objectid Current object id * @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 $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 * @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; global $conf,$langs,$form;
@ -1115,6 +1116,8 @@ class ExtraFields
} }
} }
elseif ($type == 'boolean') elseif ($type == 'boolean')
{
if (empty($mode))
{ {
$checked=''; $checked='';
if (!empty($value)) { if (!empty($value)) {
@ -1124,6 +1127,11 @@ class ExtraFields
} }
$out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
} }
else
{
$out.=$form->selectyesno($keyprefix.$key.$keysuffix, $value, 1, false, 1);
}
}
elseif ($type == 'price') elseif ($type == 'price')
{ {
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.

View File

@ -22,28 +22,28 @@ if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_
if (! empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) { if (! empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) {
$align=$extrafields->getAlignFlag($key); $align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attributes[$extrafieldsobjectkey]['type'][$key]; $typeofextrafield=$extrafields->attributes[$extrafieldsobjectkey]['type'][$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">'; print '<td class="liste_titre'.($align?' '.$align:'').'">';
$tmpkey=preg_replace('/'.$search_options_pattern.'/', '', $key); $tmpkey=preg_replace('/'.$search_options_pattern.'/', '', $key);
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]))
{ {
$crit=$val;
$searchclass=''; $searchclass='';
if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="'.$search_options_pattern.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options[$search_options_pattern.$tmpkey]).'">'; print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="'.$search_options_pattern.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options[$search_options_pattern.$tmpkey]).'">';
} }
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'))) elseif (in_array($typeofextrafield, array('datetime','timestamp')))
{ {
// TODO // TODO
// Use showInputField in a particular manner to have input with a comparison operator, not input for a specific value date-hour-minutes // 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 '</td>'; print '</td>';
} }
} }

View File

@ -25,6 +25,14 @@ if (! empty($extrafieldsobjectkey) && ! empty($search_array_options) && is_array
{ {
$sql .= " AND ".$extrafieldsobjectprefix.$tmpkey." = '".$db->idate($crit)."'"; $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')) elseif ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1'))
{ {
$mode_search=0; $mode_search=0;

View File

@ -168,7 +168,7 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria // 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_ref="";
$search_user=""; $search_user="";
@ -259,9 +259,9 @@ $title = $langs->trans("ListOfTrips");
llxHeader('', $title); llxHeader('', $title);
$max_year = 5; $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; $user_id = $user->id;
if ($id > 0) if ($id > 0)
@ -805,8 +805,7 @@ if ($resql)
{ {
$colspan=1; $colspan=1;
foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
print '<tr>'.'<td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
} }
// Show total line // Show total line

View File

@ -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/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.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.'/holiday/common.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Get parameters // Get parameters
$action=GETPOST('action', 'alpha'); $action=GETPOST('action', 'aZ09');
$cancel=GETPOST('cancel', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$id=GETPOST('id', 'int'); $id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha'); $ref=GETPOST('ref', 'alpha');
$fuserid = (GETPOST('fuserid', 'int')?GETPOST('fuserid', 'int'):$user->id); $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; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'holiday', $id, 'holiday'); $result = restrictedArea($user, 'holiday', $id, 'holiday');
$now=dol_now();
// Load translation files required by the page // Load translation files required by the page
$langs->load("holiday"); $langs->loadLangs(array("holiday","mails"));
$now=dol_now();
$childids = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
@ -61,6 +65,11 @@ if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = '';
$error = 0; $error = 0;
$object = new Holiday($db); $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) if ($id > 0)
{ {
$object->fetch($id); $object->fetch($id);
@ -83,12 +92,25 @@ $candelete = 0;
if (! empty($user->rights->holiday->delete)) $candelete=1; 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; if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) $candelete=1;
/* /*
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) $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 (empty($reshook))
{ {
if ($cancel)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
$action = ''; $action = '';
} }
@ -478,6 +500,29 @@ if ($action == 'confirm_send')
} }
} }
if ($action == 'update_extras')
{
$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';
}
// Approve leave request // Approve leave request
if ($action == 'confirm_valid') if ($action == 'confirm_valid')
@ -824,6 +869,23 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
} }
} }
/*
// 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 $doleditor->Create(1);
print '</td></tr>'; print '</td></tr>';
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
print '</tbody>'; print '</tbody>';
print '</table>'; print '</table>';
@ -1248,6 +1313,9 @@ else
print '</td></tr>'; print '</td></tr>';
} }
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</tbody>'; print '</tbody>';
print '</table>'."\n"; print '</table>'."\n";

View File

@ -402,6 +402,8 @@ class Holiday extends CommonObject
} }
$this->db->free($resql); $this->db->free($resql);
$this->fetch_optionals();
return 1; return 1;
} }
else else

View File

@ -210,68 +210,19 @@ $form = new Form($db);
$formother = new FormOther($db); $formother = new FormOther($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$holidaystatic=new Holiday($db);
$fuser = new User($db); $fuser = new User($db);
$holidaystatic=new Holiday($db);
// Update sold // Update sold
$result = $object->updateBalance(); $result = $object->updateBalance();
$max_year = 5;
$min_year = 10;
$filter='';
$title = $langs->trans('CPTitreMenu'); $title = $langs->trans('CPTitreMenu');
llxHeader('', $title); llxHeader('', $title);
$order = $db->order($sortfield, $sortorder).$db->plimit($limit + 1, $offset); $max_year = 5;
$min_year = 10;
// Ref // Get current user id
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
$user_id = $user->id; $user_id = $user->id;
if ($id > 0) if ($id > 0)
@ -286,28 +237,114 @@ if ($id > 0)
// Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy
// Load array $object->holiday // 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); $sql = "SELECT";
exit(); $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);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$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
{
$page = 0;
$offset = 0;
}
}
$sql.= $db->plimit($limit+1, $offset);
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$arrayofselected=is_array($toselect)?$toselect:array(); $arrayofselected=is_array($toselect)?$toselect:array();
@ -342,15 +379,16 @@ if ($user->rights->holiday->supprimer) $arrayofmassactions['predelete']='<span c
if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
$massactionbutton=$form->selectMassAction('', $arrayofmassactions); $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; // Lines of title fields
print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">'; print '<input type="hidden" name="action" value="'.($action=='edit'?'update':'list').'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">'; print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">'; if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
if ($id > 0) // For user tab if ($id > 0) // For user tab
@ -389,10 +427,6 @@ if ($id > 0) // For user tab
} }
else else
{ {
$nbtotalofrecords = count($object->holiday);
//print $num;
//print count($object->holiday);
$title = $langs->trans("ListeCP"); $title = $langs->trans("ListeCP");
$newcardbutton=''; $newcardbutton='';
@ -402,13 +436,13 @@ else
} }
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm.png', 0, $newcardbutton, '', $limit); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm.png', 0, $newcardbutton, '', $limit);
}
$topicmail="Information"; $topicmail="Information";
$modelmail="leaverequest"; $modelmail="leaverequest";
$objecttmp=new Holiday($db); $objecttmp=new Holiday($db);
$trackid='leav'.$object->id; $trackid='leav'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
}
if ($sall) if ($sall)
{ {
@ -520,8 +554,8 @@ if (! empty($arrayfields['duration']['checked']))
// Start date // Start date
if (! empty($arrayfields['cp.date_debut']['checked'])) if (! empty($arrayfields['cp.date_debut']['checked']))
{ {
print '<td class="liste_titre center">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_start" value="'.dol_escape_htmltag($search_month_start).'">'; print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_start" value="'.dol_escape_htmltag($search_month_start).'">';
$formother->select_year($search_year_start, 'search_year_start', 1, $min_year, $max_year); $formother->select_year($search_year_start, 'search_year_start', 1, $min_year, $max_year);
print '</td>'; print '</td>';
} }
@ -529,8 +563,8 @@ if (! empty($arrayfields['cp.date_debut']['checked']))
// End date // End date
if (! empty($arrayfields['cp.date_fin']['checked'])) if (! empty($arrayfields['cp.date_fin']['checked']))
{ {
print '<td class="liste_titre center">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_end" value="'.dol_escape_htmltag($search_month_end).'">'; print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_end" value="'.dol_escape_htmltag($search_month_end).'">';
$formother->select_year($search_year_end, 'search_year_end', 1, $min_year, $max_year); $formother->select_year($search_year_end, 'search_year_end', 1, $min_year, $max_year);
print '</td>'; print '</td>';
} }
@ -545,8 +579,8 @@ print $hookmanager->resPrint;
// Create date // Create date
if (! empty($arrayfields['cp.date_create']['checked'])) if (! empty($arrayfields['cp.date_create']['checked']))
{ {
print '<td class="liste_titre center">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_create" value="'.dol_escape_htmltag($search_month_create).'">'; print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_create" value="'.dol_escape_htmltag($search_month_create).'">';
$formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0); $formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0);
print '</td>'; print '</td>';
} }
@ -554,8 +588,8 @@ if (! empty($arrayfields['cp.date_create']['checked']))
// Create date // Create date
if (! empty($arrayfields['cp.tms']['checked'])) if (! empty($arrayfields['cp.tms']['checked']))
{ {
print '<td class="liste_titre center">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_update" value="'.dol_escape_htmltag($search_month_update).'">'; print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_update" value="'.dol_escape_htmltag($search_month_update).'">';
$formother->select_year($search_year_update, 'search_year_update', 1, $min_year, 0); $formother->select_year($search_year_update, 'search_year_update', 1, $min_year, 0);
print '</td>'; print '</td>';
} }
@ -568,7 +602,7 @@ if (! empty($arrayfields['cp.statut']['checked']))
print '</td>'; print '</td>';
} }
// Actions // Action column
print '<td class="liste_titre maxwidthsearch">'; print '<td class="liste_titre maxwidthsearch">';
$searchpicto=$form->showFilterButtons(); $searchpicto=$form->showFilterButtons();
print $searchpicto; print $searchpicto;
@ -599,13 +633,13 @@ print "</tr>\n";
$listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); $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 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)) { if ($id && empty($user->rights->holiday->read_all) && ! in_array($id, $childids)) {
$langs->load("errors"); $langs->load("errors");
print '<tr class="oddeven opacitymediuem"><td colspan="10">'.$langs->trans("NotEnoughPermissions").'</td></tr>'; print '<tr class="oddeven opacitymediuem"><td colspan="10">'.$langs->trans("NotEnoughPermissions").'</td></tr>';
$result = 0; $result = 0;
} }
elseif (! empty($object->holiday) && !empty($mysoc->country_id)) elseif ($num > 0 && !empty($mysoc->country_id))
{ {
// Lines // Lines
$userstatic = new User($db); $userstatic = new User($db);
@ -615,39 +649,41 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
$i = 0; $i = 0;
$totalarray=array(); $totalarray=array();
foreach($object->holiday as $infos_CP) while ($i < min($num, $limit))
{ {
$obj = $db->fetch_object($resql);
// Leave request // Leave request
$holidaystatic->id=$infos_CP['rowid']; $holidaystatic->id=$obj->rowid;
$holidaystatic->ref=($infos_CP['ref']?$infos_CP['ref']:$infos_CP['rowid']); $holidaystatic->ref=($obj->ref?$obj->ref:$obj->rowid);
// User // User
$userstatic->id=$infos_CP['fk_user']; $userstatic->id=$obj->fk_user;
$userstatic->lastname=$infos_CP['user_lastname']; $userstatic->lastname=$obj->user_lastname;
$userstatic->firstname=$infos_CP['user_firstname']; $userstatic->firstname=$obj->user_firstname;
$userstatic->login=$infos_CP['user_login']; $userstatic->login=$obj->user_login;
$userstatic->statut=$infos_CP['user_statut']; $userstatic->statut=$obj->user_statut;
$userstatic->photo=$infos_CP['user_photo']; $userstatic->photo=$obj->user_photo;
// Validator // Validator
$approbatorstatic->id=$infos_CP['fk_validator']; $approbatorstatic->id=$obj->fk_validator;
$approbatorstatic->lastname=$infos_CP['validator_lastname']; $approbatorstatic->lastname=$obj->validator_lastname;
$approbatorstatic->firstname=$infos_CP['validator_firstname']; $approbatorstatic->firstname=$obj->validator_firstname;
$approbatorstatic->login=$infos_CP['validator_login']; $approbatorstatic->login=$obj->validator_login;
$approbatorstatic->statut=$infos_CP['validator_statut']; $approbatorstatic->statut=$obj->validator_statut;
$approbatorstatic->photo=$infos_CP['validator_photo']; $approbatorstatic->photo=$obj->validator_photo;
$date = $infos_CP['date_create']; $date = $obj->date_create;
$date_modif = $infos_CP['date_update']; $date_modif = $obj->date_update;
$starthalfday=($infos_CP['halfday'] == -1 || $infos_CP['halfday'] == 2)?'afternoon':'morning'; $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning';
$endhalfday=($infos_CP['halfday'] == 1 || $infos_CP['halfday'] == 2)?'morning':'afternoon'; $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon';
print '<tr class="oddeven">'; print '<tr class="oddeven">';
if (! empty($arrayfields['cp.ref']['checked'])) if (! empty($arrayfields['cp.ref']['checked']))
{ {
print '<td>'; print '<td class="nowraponall">';
print $holidaystatic->getNomUrl(1, 1); print $holidaystatic->getNomUrl(1, 1);
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
@ -665,15 +701,15 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
if (! empty($arrayfields['cp.fk_type']['checked'])) if (! empty($arrayfields['cp.fk_type']['checked']))
{ {
print '<td>'; print '<td>';
$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']); $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[$infos_CP['fk_type']]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $infos_CP['fk_type']) : $labeltypeleavetoshow; print empty($typeleaves[$obj->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $obj->fk_type) : $labeltypeleavetoshow;
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
if (! empty($arrayfields['duration']['checked'])) if (! empty($arrayfields['duration']['checked']))
{ {
print '<td class="right">'; print '<td class="right">';
$nbopenedday=num_open_day($infos_CP['date_debut_gmt'], $infos_CP['date_fin_gmt'], 0, 1, $infos_CP['halfday']); $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 $nbopenedday.' '.$langs->trans('DurationDays');
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
@ -681,7 +717,7 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
if (! empty($arrayfields['cp.date_debut']['checked'])) if (! empty($arrayfields['cp.date_debut']['checked']))
{ {
print '<td class="center">'; print '<td class="center">';
print dol_print_date($infos_CP['date_debut'], 'day'); print dol_print_date($db->jdate($obj->date_debut), 'day');
print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>'; print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
@ -689,7 +725,7 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
if (! empty($arrayfields['cp.date_fin']['checked'])) if (! empty($arrayfields['cp.date_fin']['checked']))
{ {
print '<td class="center">'; print '<td class="center">';
print dol_print_date($infos_CP['date_fin'], 'day'); print dol_print_date($db->jdate($obj->date_fin), 'day');
print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>'; print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
@ -705,17 +741,17 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
// Date creation // Date creation
if (! empty($arrayfields['cp.date_create']['checked'])) if (! empty($arrayfields['cp.date_create']['checked']))
{ {
print '<td style="text-align: center;">'.dol_print_date($date, 'day').'</td>'; print '<td style="text-align: center;">'.dol_print_date($date, 'dayhour').'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
if (! empty($arrayfields['cp.tms']['checked'])) if (! empty($arrayfields['cp.tms']['checked']))
{ {
print '<td style="text-align: center;">'.dol_print_date($date_modif, 'day').'</td>'; print '<td style="text-align: center;">'.dol_print_date($date_modif, 'dayhour').'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
if (! empty($arrayfields['cp.statut']['checked'])) if (! empty($arrayfields['cp.statut']['checked']))
{ {
print '<td class="right nowrap">'.$holidaystatic->LibStatut($infos_CP['statut'], 5).'</td>'; print '<td class="right nowrap">'.$holidaystatic->LibStatut($obj->statut, 5).'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
@ -724,8 +760,8 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{ {
$selected=0; $selected=0;
if (in_array($infos_CP['rowid'], $arrayofselected)) $selected=1; if (in_array($obj->rowid, $arrayofselected)) $selected=1;
print '<input id="cb'.$infos_CP['rowid'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$infos_CP['rowid'].'"'.($selected?' checked="checked"':'').'>'; print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
} }
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
@ -737,25 +773,22 @@ elseif (! empty($object->holiday) && !empty($mysoc->country_id))
} }
// Si il n'y a pas d'enregistrement suite à une recherche // Si il n'y a pas d'enregistrement suite à une recherche
if ($result == '2') if ($num == 0)
{ {
print '<tr>'; $colspan=1;
print '<td colspan="10" class="opacitymedium">'.$langs->trans('NoRecordFound').'</td>'; foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
print '</tr>'; print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
} }
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '</form>'; print '</form>';
}
/*if ($user_id == $user->id) else
{ {
print '<br>'; dol_print_error($db);
print '<div style="float: right; margin-top: 8px;">'; }
print '<a href="./card.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
print '</div>';
}*/
// End of page // End of page
llxFooter(); llxFooter();