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 '';
+}
+else
+{
+ dol_print_error($db);
+}
// End of page
llxFooter();