code syntax ftp holiday directory

This commit is contained in:
Frédéric FRANCE 2021-02-26 17:59:31 +01:00
parent c4e98486f7
commit 5f1d7ee763
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
10 changed files with 1338 additions and 1133 deletions

View File

@ -28,7 +28,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$langs->loadLangs(array("admin", "ftp")); $langs->loadLangs(array("admin", "ftp"));
// Security check // Security check
if (!$user->admin) accessforbidden(); if (!$user->admin) {
accessforbidden();
}
$def = array(); $def = array();
$lastftpentry = 0; $lastftpentry = 0;
@ -45,36 +47,33 @@ $entry = GETPOST('numero_entry', 'alpha');
$sql = "select MAX(name) as name from ".MAIN_DB_PREFIX."const"; $sql = "select MAX(name) as name from ".MAIN_DB_PREFIX."const";
$sql .= " WHERE name like 'FTP_SERVER_%'"; $sql .= " WHERE name like 'FTP_SERVER_%'";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
preg_match('/([0-9]+)$/i', $obj->name, $reg); preg_match('/([0-9]+)$/i', $obj->name, $reg);
if ($reg[1]) $lastftpentry = $reg[1]; if ($reg[1]) {
$lastftpentry = $reg[1];
}
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
if ($action == 'add' || GETPOST('modify', 'alpha')) if ($action == 'add' || GETPOST('modify', 'alpha')) {
{
$ftp_name = "FTP_NAME_".$entry; // $_POST["numero_entry"]; $ftp_name = "FTP_NAME_".$entry; // $_POST["numero_entry"];
$ftp_server = "FTP_SERVER_".$entry; //$_POST["numero_entry"]; $ftp_server = "FTP_SERVER_".$entry; //$_POST["numero_entry"];
$error = 0; $error = 0;
if (!GETPOST("$ftp_name", 'alpha')) if (!GETPOST("$ftp_name", 'alpha')) {
{
$error = 1; $error = 1;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
} }
if (!GETPOST("$ftp_server", 'alpha')) if (!GETPOST("$ftp_server", 'alpha')) {
{
$error = 1; $error = 1;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
} }
if (!$error) if (!$error) {
{
$ftp_port = "FTP_PORT_".$entry; $ftp_port = "FTP_PORT_".$entry;
$ftp_user = "FTP_USER_".$entry; $ftp_user = "FTP_USER_".$entry;
$ftp_password = "FTP_PASSWORD_".$entry; $ftp_password = "FTP_PASSWORD_".$entry;
@ -83,14 +82,23 @@ if ($action == 'add' || GETPOST('modify', 'alpha'))
$db->begin(); $db->begin();
$result1 = dolibarr_set_const($db, "FTP_PORT_".$entry, GETPOST($ftp_port, 'alpha'), 'chaine', 0, '', $conf->entity); $result1 = dolibarr_set_const($db, "FTP_PORT_".$entry, GETPOST($ftp_port, 'alpha'), 'chaine', 0, '', $conf->entity);
if ($result1) $result2 = dolibarr_set_const($db, "FTP_SERVER_".$entry, GETPOST($ftp_server, 'alpha'), 'chaine', 0, '', $conf->entity); if ($result1) {
if ($result2) $result3 = dolibarr_set_const($db, "FTP_USER_".$entry, GETPOST($ftp_user, 'alpha'), 'chaine', 0, '', $conf->entity); $result2 = dolibarr_set_const($db, "FTP_SERVER_".$entry, GETPOST($ftp_server, 'alpha'), 'chaine', 0, '', $conf->entity);
if ($result3) $result4 = dolibarr_set_const($db, "FTP_PASSWORD_".$entry, GETPOST($ftp_password, 'alpha'), 'chaine', 0, '', $conf->entity); }
if ($result4) $result5 = dolibarr_set_const($db, "FTP_NAME_".$entry, GETPOST($ftp_name, 'alpha'), 'chaine', 0, '', $conf->entity); if ($result2) {
if ($result5) $result6 = dolibarr_set_const($db, "FTP_PASSIVE_".$entry, GETPOST($ftp_passive, 'alpha'), 'chaine', 0, '', $conf->entity); $result3 = dolibarr_set_const($db, "FTP_USER_".$entry, GETPOST($ftp_user, 'alpha'), 'chaine', 0, '', $conf->entity);
}
if ($result3) {
$result4 = dolibarr_set_const($db, "FTP_PASSWORD_".$entry, GETPOST($ftp_password, 'alpha'), 'chaine', 0, '', $conf->entity);
}
if ($result4) {
$result5 = dolibarr_set_const($db, "FTP_NAME_".$entry, GETPOST($ftp_name, 'alpha'), 'chaine', 0, '', $conf->entity);
}
if ($result5) {
$result6 = dolibarr_set_const($db, "FTP_PASSIVE_".$entry, GETPOST($ftp_passive, 'alpha'), 'chaine', 0, '', $conf->entity);
}
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
{
$db->commit(); $db->commit();
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
@ -101,21 +109,28 @@ if ($action == 'add' || GETPOST('modify', 'alpha'))
} }
} }
if (GETPOST('delete', 'alpha')) if (GETPOST('delete', 'alpha')) {
{ if ($entry) {
if ($entry)
{
$db->begin(); $db->begin();
$result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity); $result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity);
if ($result1) $result2 = dolibarr_del_const($db, "FTP_SERVER_".$entry, $conf->entity); if ($result1) {
if ($result2) $result3 = dolibarr_del_const($db, "FTP_USER_".$entry, $conf->entity); $result2 = dolibarr_del_const($db, "FTP_SERVER_".$entry, $conf->entity);
if ($result3) $result4 = dolibarr_del_const($db, "FTP_PASSWORD_".$entry, $conf->entity); }
if ($result4) $result5 = dolibarr_del_const($db, "FTP_NAME_".$entry, $conf->entity); if ($result2) {
if ($result4) $result6 = dolibarr_del_const($db, "FTP_PASSIVE_".$entry, $conf->entity); $result3 = dolibarr_del_const($db, "FTP_USER_".$entry, $conf->entity);
}
if ($result3) {
$result4 = dolibarr_del_const($db, "FTP_PASSWORD_".$entry, $conf->entity);
}
if ($result4) {
$result5 = dolibarr_del_const($db, "FTP_NAME_".$entry, $conf->entity);
}
if ($result4) {
$result6 = dolibarr_del_const($db, "FTP_PASSIVE_".$entry, $conf->entity);
}
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
{
$db->commit(); $db->commit();
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
@ -139,8 +154,7 @@ $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_valu
print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup'); print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup');
print '<br>'; print '<br>';
if (!function_exists('ftp_connect')) if (!function_exists('ftp_connect')) {
{
print $langs->trans("FTPFeatureNotSupportedByYourPHP"); print $langs->trans("FTPFeatureNotSupportedByYourPHP");
} else { } else {
// Formulaire ajout // Formulaire ajout
@ -186,7 +200,9 @@ if (!function_exists('ftp_connect'))
print '<tr class="impair">'; print '<tr class="impair">';
print '<td>'.$langs->trans("FTPPassiveMode").'</td>'; print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
$defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1)); $defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1));
if (!isset($_POST["FTP_PASSIVE_".($lastftpentry + 1)])) $defaultpassive = empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT) ? 0 : 1; if (!isset($_POST["FTP_PASSIVE_".($lastftpentry + 1)])) {
$defaultpassive = empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT) ? 0 : 1;
}
print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).'</td>'; print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).'</td>';
print '<td>'.$langs->trans("No").'</td>'; print '<td>'.$langs->trans("No").'</td>';
print '</tr>'; print '</tr>';
@ -211,13 +227,11 @@ if (!function_exists('ftp_connect'))
dol_syslog("ftpclient select ftp setup", LOG_DEBUG); dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
preg_match('/([0-9]+)$/i', $obj->name, $reg); preg_match('/([0-9]+)$/i', $obj->name, $reg);

View File

@ -32,13 +32,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
$langs->loadLangs(array('ftp', 'companies', 'other')); $langs->loadLangs(array('ftp', 'companies', 'other'));
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'ftp', ''); $result = restrictedArea($user, 'ftp', '');
// Get parameters // Get parameters
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$section = GETPOST('section'); $section = GETPOST('section');
if (!$section) $section = '/'; if (!$section) {
$section = '/';
}
$numero_ftp = GETPOST("numero_ftp"); $numero_ftp = GETPOST("numero_ftp");
/* if (! $numero_ftp) $numero_ftp=1; */ /* if (! $numero_ftp) $numero_ftp=1; */
$file = GETPOST("file"); $file = GETPOST("file");
@ -51,12 +55,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "label"; $sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "label";
}
$s_ftp_name = 'FTP_NAME_'.$numero_ftp; $s_ftp_name = 'FTP_NAME_'.$numero_ftp;
$s_ftp_server = 'FTP_SERVER_'.$numero_ftp; $s_ftp_server = 'FTP_SERVER_'.$numero_ftp;
@ -66,7 +76,9 @@ $s_ftp_password = 'FTP_PASSWORD_'.$numero_ftp;
$s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp; $s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp;
$ftp_name = $conf->global->$s_ftp_name; $ftp_name = $conf->global->$s_ftp_name;
$ftp_server = $conf->global->$s_ftp_server; $ftp_server = $conf->global->$s_ftp_server;
$ftp_port = $conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port = 21; $ftp_port = $conf->global->$s_ftp_port; if (empty($ftp_port)) {
$ftp_port = 21;
}
$ftp_user = $conf->global->$s_ftp_user; $ftp_user = $conf->global->$s_ftp_user;
$ftp_password = $conf->global->$s_ftp_password; $ftp_password = $conf->global->$s_ftp_password;
$ftp_passive = $conf->global->$s_ftp_passive; $ftp_passive = $conf->global->$s_ftp_passive;
@ -83,29 +95,24 @@ $mesg = '';
*/ */
// Submit file // Submit file
if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) {
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$result = $ecmdir->fetch(GETPOST("section", 'int')); $result = $ecmdir->fetch(GETPOST("section", 'int'));
if (!$result > 0) if (!$result > 0) {
{
dol_print_error($db, $ecmdir->error); dol_print_error($db, $ecmdir->error);
exit; exit;
} }
$relativepath = $ecmdir->getRelativePath(); $relativepath = $ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
if (dol_mkdir($upload_dir) >= 0) if (dol_mkdir($upload_dir) >= 0) {
{
$resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir."/".dol_unescapefile($_FILES['userfile']['name']), 0); $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir."/".dol_unescapefile($_FILES['userfile']['name']), 0);
if (is_numeric($resupload) && $resupload > 0) if (is_numeric($resupload) && $resupload > 0) {
{
$result = $ecmdir->changeNbOfFiles('+'); $result = $ecmdir->changeNbOfFiles('+');
} else { } else {
$langs->load("errors"); $langs->load("errors");
if ($resupload < 0) // Unknown error if ($resupload < 0) { // Unknown error
{
setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors'); setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
} elseif (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) { } elseif (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) {
// Files infected by a virus // Files infected by a virus
@ -123,15 +130,13 @@ if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC))
} }
// Action ajout d'un rep // Action ajout d'un rep
if ($action == 'add' && $user->rights->ftp->setup) if ($action == 'add' && $user->rights->ftp->setup) {
{
$ecmdir->ref = GETPOST("ref"); $ecmdir->ref = GETPOST("ref");
$ecmdir->label = GETPOST("label"); $ecmdir->label = GETPOST("label");
$ecmdir->description = GETPOST("desc"); $ecmdir->description = GETPOST("desc");
$id = $ecmdir->create($user); $id = $ecmdir->create($user);
if ($id > 0) if ($id > 0) {
{
header("Location: ".$_SERVER["PHP_SELF"]); header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
} else { } else {
@ -141,11 +146,9 @@ if ($action == 'add' && $user->rights->ftp->setup)
} }
// Remove 1 file // Remove 1 file
if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes') {
{
// set up a connection or die // set up a connection or die
if (!$conn_id) if (!$conn_id) {
{
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
$conn_id = $resultarray['conn_id']; $conn_id = $resultarray['conn_id'];
@ -153,11 +156,9 @@ if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
$mesg = $resultarray['mesg']; $mesg = $resultarray['mesg'];
} }
if ($conn_id && $ok && !$mesg) if ($conn_id && $ok && !$mesg) {
{
$newsection = $section; $newsection = $section;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
$newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
} }
@ -175,8 +176,7 @@ if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
} else { } else {
$result = @ftp_delete($conn_id, $newremotefileiso); $result = @ftp_delete($conn_id, $newremotefileiso);
} }
if ($result) if ($result) {
{
setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs'); setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
} else { } else {
dol_syslog("ftp/index.php ftp_delete", LOG_ERR); dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
@ -192,11 +192,9 @@ if ($action == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
} }
// Delete several lines at once // Delete several lines at once
if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $langs->trans("Delete")) {
{
// set up a connection or die // set up a connection or die
if (!$conn_id) if (!$conn_id) {
{
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
$conn_id = $resultarray['conn_id']; $conn_id = $resultarray['conn_id'];
@ -204,19 +202,15 @@ if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $lang
$mesg = $resultarray['mesg']; $mesg = $resultarray['mesg'];
} }
if ($conn_id && $ok && !$mesg) if ($conn_id && $ok && !$mesg) {
{ foreach (GETPOST('const', 'array') as $const) {
foreach (GETPOST('const', 'array') as $const) if ($const["check"]) { // Is checkbox checked
{
if ($const["check"]) // Is checkbox checked
{
$langs->load("other"); $langs->load("other");
// Remote file // Remote file
$file = $const["file"]; $file = $const["file"];
$newsection = $const["section"]; $newsection = $const["section"];
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
$newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
} }
$remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file; $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
@ -229,8 +223,7 @@ if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $lang
} else { } else {
$result = @ftp_delete($conn_id, $newremotefileiso); $result = @ftp_delete($conn_id, $newremotefileiso);
} }
if ($result) if ($result) {
{
setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs'); setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
} else { } else {
dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR); dol_syslog("ftp/index.php ftp_delete n files", LOG_ERR);
@ -248,11 +241,9 @@ if (GETPOST("const", 'array') && GETPOST("delete") && GETPOST("delete") == $lang
} }
// Remove directory // Remove directory
if ($action == 'confirm_deletesection' && $confirm == 'yes') if ($action == 'confirm_deletesection' && $confirm == 'yes') {
{
// set up a connection or die // set up a connection or die
if (!$conn_id) if (!$conn_id) {
{
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
$conn_id = $resultarray['conn_id']; $conn_id = $resultarray['conn_id'];
@ -260,11 +251,9 @@ if ($action == 'confirm_deletesection' && $confirm == 'yes')
$mesg = $resultarray['mesg']; $mesg = $resultarray['mesg'];
} }
if ($conn_id && $ok && !$mesg) if ($conn_id && $ok && !$mesg) {
{
$newsection = $section; $newsection = $section;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
$newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
} }
@ -278,8 +267,7 @@ if ($action == 'confirm_deletesection' && $confirm == 'yes')
} else { } else {
$result = @ftp_rmdir($conn_id, $newremotefileiso); $result = @ftp_rmdir($conn_id, $newremotefileiso);
} }
if ($result) if ($result) {
{
setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs'); setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs');
} else { } else {
setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors'); setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors');
@ -294,11 +282,9 @@ if ($action == 'confirm_deletesection' && $confirm == 'yes')
} }
// Download directory // Download directory
if ($action == 'download') if ($action == 'download') {
{
// set up a connection or die // set up a connection or die
if (!$conn_id) if (!$conn_id) {
{
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive); $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
$conn_id = $resultarray['conn_id']; $conn_id = $resultarray['conn_id'];
@ -306,14 +292,12 @@ if ($action == 'download')
$mesg = $resultarray['mesg']; $mesg = $resultarray['mesg'];
} }
if ($conn_id && $ok && !$mesg) if ($conn_id && $ok && !$mesg) {
{
// Local file // Local file
$localfile = tempnam($download_dir, 'dol_'); $localfile = tempnam($download_dir, 'dol_');
$newsection = $section; $newsection = $section;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
$newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
} }
@ -327,23 +311,31 @@ if ($action == 'download')
} else { } else {
$result = ftp_get($conn_id, $localfile, $newremotefileiso, FTP_BINARY); $result = ftp_get($conn_id, $localfile, $newremotefileiso, FTP_BINARY);
} }
if ($result) if ($result) {
{ if (!empty($conf->global->MAIN_UMASK)) {
if (!empty($conf->global->MAIN_UMASK)) @chmod($localfile, octdec($conf->global->MAIN_UMASK));
@chmod($localfile, octdec($conf->global->MAIN_UMASK)); }
// Define mime type // Define mime type
$type = 'application/octet-stream'; $type = 'application/octet-stream';
if (GETPOSTISSET("type")) $type = GETPOST("type"); if (GETPOSTISSET("type")) {
else $type = dol_mimetype($file); $type = GETPOST("type");
} else {
$type = dol_mimetype($file);
}
// Define attachment (attachment=true to force choice popup 'open'/'save as') // Define attachment (attachment=true to force choice popup 'open'/'save as')
$attachment = true; $attachment = true;
//if ($encoding) header('Content-Encoding: '.$encoding); //if ($encoding) header('Content-Encoding: '.$encoding);
if ($type) header('Content-Type: '.$type); if ($type) {
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-Type: '.$type);
else header('Content-Disposition: inline; filename="'.$filename.'"'); }
if ($attachment) {
header('Content-Disposition: attachment; filename="'.$filename.'"');
} else {
header('Content-Disposition: inline; filename="'.$filename.'"');
}
// Ajout directives pour resoudre bug IE // Ajout directives pour resoudre bug IE
header('Cache-Control: Public, must-revalidate'); header('Cache-Control: Public, must-revalidate');
@ -374,8 +366,7 @@ if ($action == 'download')
llxHeader(); llxHeader();
// Add logic to shoow/hide buttons // Add logic to shoow/hide buttons
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax) {
{
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
@ -411,21 +402,17 @@ print load_fiche_titre($langs->trans("FTPArea"));
print $langs->trans("FTPAreaDesc")."<br>"; print $langs->trans("FTPAreaDesc")."<br>";
if (!function_exists('ftp_connect')) if (!function_exists('ftp_connect')) {
{
print $langs->trans("FTPFeatureNotSupportedByYourPHP"); print $langs->trans("FTPFeatureNotSupportedByYourPHP");
} else { } else {
if (!empty($ftp_server)) if (!empty($ftp_server)) {
{
// Confirm remove file // Confirm remove file
if ($action == 'delete') if ($action == 'delete') {
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 1); print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 1);
} }
// Confirmation de la suppression d'une ligne categorie // Confirmation de la suppression d'une ligne categorie
if ($action == 'delete_section') if ($action == 'delete_section') {
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection', '', '', 1); print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode(GETPOST('section')).'&file='.urlencode(GETPOST('file')), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection', '', '', 1);
} }
@ -443,11 +430,11 @@ if (!function_exists('ftp_connect'))
print '</a> '; print '</a> ';
// For other directories // For other directories
$i = 0; $i = 0;
foreach ($sectionarray as $val) foreach ($sectionarray as $val) {
{ if (empty($val)) {
if (empty($val)) continue; // Discard first and last entry that should be empty as section start/end with / continue; // Discard first and last entry that should be empty as section start/end with /
if ($i > 0) }
{ if ($i > 0) {
print ' / '; print ' / ';
$newsection .= '/'; $newsection .= '/';
} }
@ -476,14 +463,15 @@ if (!function_exists('ftp_connect'))
print '<td class="liste_titre center">'.$langs->trans("Group").'</td>'."\n"; print '<td class="liste_titre center">'.$langs->trans("Group").'</td>'."\n";
print '<td class="liste_titre center">'.$langs->trans("Permissions").'</td>'."\n"; print '<td class="liste_titre center">'.$langs->trans("Permissions").'</td>'."\n";
print '<td class="liste_titre nowrap right">'; print '<td class="liste_titre nowrap right">';
if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> '; if ($conf->use_javascript_ajax) {
print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
}
print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;';
print '</td>'."\n"; print '</td>'."\n";
print '</tr>'."\n"; print '</tr>'."\n";
// set up a connection or die // set up a connection or die
if (empty($conn_id)) if (empty($conn_id)) {
{
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive); $resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
$conn_id = $resultarray['conn_id']; $conn_id = $resultarray['conn_id'];
@ -491,8 +479,7 @@ if (!function_exists('ftp_connect'))
$mesg = $resultarray['mesg']; $mesg = $resultarray['mesg'];
} }
if ($ok) if ($ok) {
{
//$type = ftp_systype($conn_id); //$type = ftp_systype($conn_id);
$newsection = $section; $newsection = $section;
@ -500,8 +487,7 @@ if (!function_exists('ftp_connect'))
//$newsection='/home'; //$newsection='/home';
// List content of directory ($newsection = '/', '/home', ...) // List content of directory ($newsection = '/', '/home', ...)
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
if ($newsection == '/') { if ($newsection == '/') {
//$newsection = '/./'; //$newsection = '/./';
$newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 $newsection = ssh2_sftp_realpath($conn_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
@ -511,8 +497,7 @@ if (!function_exists('ftp_connect'))
//$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./'); //$dirHandle = opendir("ssh2.sftp://".intval($conn_id).ssh2_sftp_realpath($conn_id, ".").'/./');
$contents = scandir('ssh2.sftp://'.intval($conn_id).$newsection); $contents = scandir('ssh2.sftp://'.intval($conn_id).$newsection);
$buff = array(); $buff = array();
foreach ($contents as $i => $key) foreach ($contents as $i => $key) {
{
$buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key; $buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key;
} }
} else { } else {
@ -525,31 +510,32 @@ if (!function_exists('ftp_connect'))
$nboflines = count($contents); $nboflines = count($contents);
$rawlisthasfailed = false; $rawlisthasfailed = false;
$i = 0; $i = 0;
while ($i < $nboflines && $i < 1000) while ($i < $nboflines && $i < 1000) {
{
$vals = preg_split('@ +@', utf8_encode($buff[$i]), 9); $vals = preg_split('@ +@', utf8_encode($buff[$i]), 9);
//$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9); //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
//var_dump($vals); //var_dump($vals);
$file = $vals[8]; $file = $vals[8];
if (empty($file)) if (empty($file)) {
{
$rawlisthasfailed = true; $rawlisthasfailed = true;
$file = utf8_encode($contents[$i]); $file = utf8_encode($contents[$i]);
} }
if ($file == '.' || ($file == '..' && $section == '/')) if ($file == '.' || ($file == '..' && $section == '/')) {
{
$i++; $i++;
continue; continue;
} }
// Is it a directory ? // Is it a directory ?
$is_directory = 0; $is_directory = 0;
if ($file == '..') $is_directory = 1; if ($file == '..') {
elseif (!$rawlisthasfailed) $is_directory = 1;
{ } elseif (!$rawlisthasfailed) {
if (preg_match('/^d/', $vals[0])) $is_directory = 1; if (preg_match('/^d/', $vals[0])) {
if (preg_match('/^l/', $vals[0])) $is_link = 1; $is_directory = 1;
}
if (preg_match('/^l/', $vals[0])) {
$is_link = 1;
}
} else { } else {
// Remote file // Remote file
$filename = $file; $filename = $file;
@ -569,14 +555,21 @@ if (!function_exists('ftp_connect'))
print '<td>'; print '<td>';
$newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file; $newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
$newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa $newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa
if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">'; if ($is_directory) {
print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
}
print dol_escape_htmltag($file); print dol_escape_htmltag($file);
if ($is_directory) print '</a>'; if ($is_directory) {
print '</a>';
}
print '</td>'; print '</td>';
// Size // Size
print '<td class="center nowrap">'; print '<td class="center nowrap">';
if (!$is_directory && !$is_link) print $vals[4]; if (!$is_directory && !$is_link) {
else print '&nbsp;'; print $vals[4];
} else {
print '&nbsp;';
}
print '</td>'; print '</td>';
// Date // Date
print '<td class="center nowrap">'; print '<td class="center nowrap">';
@ -596,12 +589,13 @@ if (!function_exists('ftp_connect'))
print '</td>'; print '</td>';
// Action // Action
print '<td class="right nowrap" width="64">'; print '<td class="right nowrap" width="64">';
if ($is_directory) if ($is_directory) {
{ if ($file != '..') {
if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
else print '&nbsp;'; } else {
} elseif ($is_link) print '&nbsp;';
{ }
} elseif ($is_link) {
$newfile = $file; $newfile = $file;
$newfile = preg_replace('/ ->.*/', '', $newfile); $newfile = preg_replace('/ ->.*/', '', $newfile);
print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
@ -624,8 +618,7 @@ if (!function_exists('ftp_connect'))
print "</table>"; print "</table>";
if (!$ok) if (!$ok) {
{
print $mesg.'<br>'."\n"; print $mesg.'<br>'."\n";
setEventMessages($mesg, null, 'errors'); setEventMessages($mesg, null, 'errors');
} }
@ -650,19 +643,16 @@ if (!function_exists('ftp_connect'))
$foundsetup = false; $foundsetup = false;
$MAXFTP = 20; $MAXFTP = 20;
$i = 1; $i = 1;
while ($i <= $MAXFTP) while ($i <= $MAXFTP) {
{
$paramkey = 'FTP_NAME_'.$i; $paramkey = 'FTP_NAME_'.$i;
//print $paramkey; //print $paramkey;
if (!empty($conf->global->$paramkey)) if (!empty($conf->global->$paramkey)) {
{
$foundsetup = true; $foundsetup = true;
break; break;
} }
$i++; $i++;
} }
if (!$foundsetup) if (!$foundsetup) {
{
print $langs->trans("SetupOfFTPClientModuleNotComplete"); print $langs->trans("SetupOfFTPClientModuleNotComplete");
} else { } else {
print $langs->trans("ChooseAFTPEntryIntoMenu"); print $langs->trans("ChooseAFTPEntryIntoMenu");
@ -673,12 +663,9 @@ if (!function_exists('ftp_connect'))
print '<br>'; print '<br>';
// Close FTP connection // Close FTP connection
if ($conn_id) if ($conn_id) {
{ if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
{
} elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL))
{
ftp_close($conn_id); ftp_close($conn_id);
} else { } else {
ftp_close($conn_id); ftp_close($conn_id);
@ -709,14 +696,12 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
$ok = 1; $ok = 1;
$conn_id = null; $conn_id = null;
if (!is_numeric($ftp_port)) if (!is_numeric($ftp_port)) {
{
$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port); $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port);
$ok = 0; $ok = 0;
} }
if ($ok) if ($ok) {
{
$connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT); $connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) { if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
dol_syslog('Try to connect with ssh2_ftp'); dol_syslog('Try to connect with ssh2_ftp');
@ -728,15 +713,11 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
dol_syslog('Try to connect with ftp_connect'); dol_syslog('Try to connect with ftp_connect');
$conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout); $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
} }
if ($conn_id || $tmp_conn_id) if ($conn_id || $tmp_conn_id) {
{ if ($ftp_user) {
if ($ftp_user) if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
{
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
{
dol_syslog('Try to authenticate with ssh2_auth_password'); dol_syslog('Try to authenticate with ssh2_auth_password');
if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) {
{
// Turn on passive mode transfers (must be after a successful login // Turn on passive mode transfers (must be after a successful login
//if ($ftp_passive) ftp_pasv($conn_id, true); //if ($ftp_passive) ftp_pasv($conn_id, true);
@ -744,31 +725,31 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
//ftp_chdir($conn_id, $newsectioniso); //ftp_chdir($conn_id, $newsectioniso);
$conn_id = ssh2_sftp($tmp_conn_id); $conn_id = ssh2_sftp($tmp_conn_id);
if (!$conn_id) if (!$conn_id) {
{
dol_syslog('Failed to connect to SFTP after sssh authentication', LOG_DEBUG); dol_syslog('Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
$mesg = $langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication"); $mesg = $langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
$ok = 0; $ok = 0;
$error++; $error++;
} }
} else { } else {
dol_syslog('Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG); dol_syslog('Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials"); $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
$ok = 0; $ok = 0;
$error++; $error++;
} }
} else { } else {
if (ftp_login($conn_id, $ftp_user, $ftp_password)) if (ftp_login($conn_id, $ftp_user, $ftp_password)) {
{
// Turn on passive mode transfers (must be after a successful login // Turn on passive mode transfers (must be after a successful login
if ($ftp_passive) ftp_pasv($conn_id, true); if ($ftp_passive) {
ftp_pasv($conn_id, true);
}
// Change the dir // Change the dir
$newsectioniso = utf8_decode($section); $newsectioniso = utf8_decode($section);
ftp_chdir($conn_id, $newsectioniso); ftp_chdir($conn_id, $newsectioniso);
} else { } else {
$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials"); $mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
$ok = 0; $ok = 0;
$error++; $error++;
} }
} }
@ -794,8 +775,7 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
*/ */
function ftp_isdir($connect_id, $dir) function ftp_isdir($connect_id, $dir)
{ {
if (@ftp_chdir($connect_id, $dir)) if (@ftp_chdir($connect_id, $dir)) {
{
ftp_cdup($connect_id); ftp_cdup($connect_id);
return 1; return 1;
} else { } else {

File diff suppressed because it is too large Load Diff

View File

@ -170,13 +170,11 @@ class Holiday extends CommonObject
global $langs, $conf; global $langs, $conf;
$langs->load("order"); $langs->load("order");
if (empty($conf->global->HOLIDAY_ADDON)) if (empty($conf->global->HOLIDAY_ADDON)) {
{
$conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna'; $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
} }
if (!empty($conf->global->HOLIDAY_ADDON)) if (!empty($conf->global->HOLIDAY_ADDON)) {
{
$mybool = false; $mybool = false;
$file = $conf->global->HOLIDAY_ADDON.".php"; $file = $conf->global->HOLIDAY_ADDON.".php";
@ -184,16 +182,14 @@ class Holiday extends CommonObject
// Include file with class // Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{
$dir = dol_buildpath($reldir."core/modules/holiday/"); $dir = dol_buildpath($reldir."core/modules/holiday/");
// Load file with numbering class (if found) // Load file with numbering class (if found)
$mybool |= @include_once $dir.$file; $mybool |= @include_once $dir.$file;
} }
if ($mybool === false) if ($mybool === false) {
{
dol_print_error('', "Failed to include file ".$file); dol_print_error('', "Failed to include file ".$file);
return ''; return '';
} }
@ -201,8 +197,7 @@ class Holiday extends CommonObject
$obj = new $classname(); $obj = new $classname();
$numref = $obj->getNextValue($objsoc, $this); $numref = $obj->getNextValue($objsoc, $this);
if ($numref != "") if ($numref != "") {
{
return $numref; return $numref;
} else { } else {
$this->error = $obj->error; $this->error = $obj->error;
@ -230,8 +225,7 @@ class Holiday extends CommonObject
// Check nb of users into table llx_holiday_users and update with empty lines // Check nb of users into table llx_holiday_users and update with empty lines
//if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser')); //if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
if ($result >= 0) if ($result >= 0) {
{
$this->db->commit(); $this->db->commit();
return 1; return 1;
} else { } else {
@ -255,9 +249,15 @@ class Holiday extends CommonObject
$now = dol_now(); $now = dol_now();
// Check parameters // Check parameters
if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error = "ErrorBadParameterFkUser"; return -1; } if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) { $this->error = "ErrorBadParameterFkValidator"; return -1; } $this->error = "ErrorBadParameterFkUser"; return -1;
if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error = "ErrorBadParameterFkType"; return -1; } }
if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
$this->error = "ErrorBadParameterFkValidator"; return -1;
}
if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
$this->error = "ErrorBadParameterFkType"; return -1;
}
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
@ -296,32 +296,33 @@ class Holiday extends CommonObject
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
if ($this->id) if ($this->id) {
{
// update ref // update ref
$initialref = '(PROV'.$this->id.')'; $initialref = '(PROV'.$this->id.')';
if (!empty($this->ref)) $initialref = $this->ref; if (!empty($this->ref)) {
$initialref = $this->ref;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".$this->id; $sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".$this->id;
if ($this->db->query($sql)) if ($this->db->query($sql)) {
{
$this->ref = $initialref; $this->ref = $initialref;
if (!$error) if (!$error) {
{
$result = $this->insertExtraFields(); $result = $this->insertExtraFields();
if ($result < 0) $error++; if ($result < 0) {
$error++;
}
} }
if (!$error && !$notrigger) if (!$error && !$notrigger) {
{
// Call trigger // Call trigger
$result = $this->call_trigger('HOLIDAY_CREATE', $user); $result = $this->call_trigger('HOLIDAY_CREATE', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
} }
@ -329,10 +330,8 @@ class Holiday extends CommonObject
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -380,15 +379,16 @@ class Holiday extends CommonObject
$sql .= " cp.fk_type,"; $sql .= " cp.fk_type,";
$sql .= " cp.entity"; $sql .= " cp.entity";
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
if ($id > 0) $sql .= " WHERE cp.rowid = ".$id; if ($id > 0) {
else $sql .= " WHERE cp.ref = '".$this->db->escape($ref)."'"; $sql .= " WHERE cp.rowid = ".$id;
} else {
$sql .= " WHERE cp.ref = '".$this->db->escape($ref)."'";
}
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -693,8 +693,7 @@ class Holiday extends CommonObject
$error = 0; $error = 0;
// Define new ref // Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) {
{
$num = $this->getNextNumRef(null); $num = $this->getNextNumRef(null);
} else { } else {
$num = $this->ref; $num = $this->ref;
@ -719,22 +718,20 @@ class Holiday extends CommonObject
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{ if (!$notrigger) {
if (!$notrigger)
{
// Call trigger // Call trigger
$result = $this->call_trigger('HOLIDAY_VALIDATE', $user); $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -831,22 +828,20 @@ class Holiday extends CommonObject
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{ if (!$notrigger) {
if (!$notrigger)
{
// Call trigger // Call trigger
$result = $this->call_trigger('HOLIDAY_APPROVE', $user); $result = $this->call_trigger('HOLIDAY_APPROVE', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -942,22 +937,20 @@ class Holiday extends CommonObject
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{ if (!$notrigger) {
if (!$notrigger)
{
// Call trigger // Call trigger
$result = $this->call_trigger('HOLIDAY_MODIFY', $user); $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -993,22 +986,20 @@ class Holiday extends CommonObject
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{ if (!$notrigger) {
if (!$notrigger)
{
// Call trigger // Call trigger
$result = $this->call_trigger('HOLIDAY_DELETE', $user); $result = $this->call_trigger('HOLIDAY_DELETE', $user);
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -1037,60 +1028,67 @@ class Holiday extends CommonObject
{ {
$this->fetchByUser($fk_user, '', ''); $this->fetchByUser($fk_user, '', '');
foreach ($this->holiday as $infos_CP) foreach ($this->holiday as $infos_CP) {
{ if ($infos_CP['statut'] == 4) {
if ($infos_CP['statut'] == 4) continue; // ignore not validated holidays continue; // ignore not validated holidays
if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays }
if ($infos_CP['statut'] == 5) {
continue; // ignore not validated holidays
}
/* /*
var_dump("--"); var_dump("--");
var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']); var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday); var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
*/ */
if ($halfday == 0) if ($halfday == 0) {
{ if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin'])
{
return false; return false;
} }
if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
{
return false; return false;
} }
} elseif ($halfday == -1) } elseif ($halfday == -1) {
{
// new start afternoon, new end afternoon // new start afternoon, new end afternoon
if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
{ if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) return false; return false;
}
} }
if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
{ if ($dateStart < $dateEnd) {
if ($dateStart < $dateEnd) return false; return false;
if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) return false; }
if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
return false;
}
} }
} elseif ($halfday == 1) } elseif ($halfday == 1) {
{
// new start morning, new end morning // new start morning, new end morning
if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
{ if ($dateStart < $dateEnd) {
if ($dateStart < $dateEnd) return false; return false;
if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) return false; }
if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
return false;
}
} }
if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
{ if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) return false; return false;
}
} }
} elseif ($halfday == 2) } elseif ($halfday == 2) {
{
// new start afternoon, new end morning // new start afternoon, new end morning
if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
{ if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) return false; return false;
}
} }
if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
{ if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) return false; return false;
}
} }
} else { } else {
dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP'); dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP');
@ -1123,18 +1121,17 @@ class Holiday extends CommonObject
$sql .= " WHERE cp.entity IN (".getEntity('holiday').")"; $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
$sql .= " AND cp.fk_user = ".(int) $fk_user; $sql .= " AND cp.fk_user = ".(int) $fk_user;
$sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'"; $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
if ($status != '-1') $sql .= " AND cp.statut IN (".$this->db->sanitize($this->db->escape($status)).")"; if ($status != '-1') {
$sql .= " AND cp.statut IN (".$this->db->sanitize($this->db->escape($status)).")";
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
if ($num_rows > 0) if ($num_rows > 0) {
{
$arrayofrecord = array(); $arrayofrecord = array();
$i = 0; $i = 0;
while ($i < $num_rows) while ($i < $num_rows) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
// Note: $obj->halfday is 0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning // Note: $obj->halfday is 0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning
@ -1144,27 +1141,39 @@ class Holiday extends CommonObject
// We found a record, user is on holiday by default, so is not available is true. // We found a record, user is on holiday by default, so is not available is true.
$isavailablemorning = true; $isavailablemorning = true;
foreach ($arrayofrecord as $record) foreach ($arrayofrecord as $record) {
{ if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
if ($timestamp == $record['date_start'] && $record['halfday'] == 2) continue; continue;
if ($timestamp == $record['date_start'] && $record['halfday'] == -1) continue; }
if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
continue;
}
$isavailablemorning = false; $isavailablemorning = false;
break; break;
} }
$isavailableafternoon = true; $isavailableafternoon = true;
foreach ($arrayofrecord as $record) foreach ($arrayofrecord as $record) {
{ if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
if ($timestamp == $record['date_end'] && $record['halfday'] == 2) continue; continue;
if ($timestamp == $record['date_end'] && $record['halfday'] == 1) continue; }
if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
continue;
}
$isavailableafternoon = false; $isavailableafternoon = false;
break; break;
} }
} }
} else dol_print_error($this->db); } else {
dol_print_error($this->db);
}
$result = array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); $result = array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon);
if (!$isavailablemorning) $result['morning_reason'] = 'leave_request'; if (!$isavailablemorning) {
if (!$isavailableafternoon) $result['afternoon_reason'] = 'leave_request'; $result['morning_reason'] = 'leave_request';
}
if (!$isavailableafternoon) {
$result['afternoon_reason'] = 'leave_request';
}
return $result; return $result;
} }
@ -1194,16 +1203,24 @@ class Holiday extends CommonObject
//{ //{
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; $add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
//} //}
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>'; $linkend = '</a>';
$result .= $linkstart; $result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); if ($withpicto) {
if ($withpicto != 2) $result .= $this->ref; $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend; $result .= $linkend;
return $result; return $result;
@ -1233,8 +1250,7 @@ class Holiday extends CommonObject
public function LibStatut($status, $mode = 0, $startdate = '') public function LibStatut($status, $mode = 0, $startdate = '')
{ {
// phpcs:enable // phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort)) if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
{
global $langs; global $langs;
//$langs->load("mymodule"); //$langs->load("mymodule");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('DraftCP'); $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('DraftCP');
@ -1250,11 +1266,21 @@ class Holiday extends CommonObject
} }
$statusType = 'status6'; $statusType = 'status6';
if (!empty($startdate) && $startdate > dol_now()) $statusType = 'status4'; if (!empty($startdate) && $startdate > dol_now()) {
if ($status == self::STATUS_DRAFT) $statusType = 'status0'; $statusType = 'status4';
if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; }
if ($status == self::STATUS_CANCELED) $statusType = 'status5'; if ($status == self::STATUS_DRAFT) {
if ($status == self::STATUS_REFUSED) $statusType = 'status5'; $statusType = 'status0';
}
if ($status == self::STATUS_VALIDATED) {
$statusType = 'status1';
}
if ($status == self::STATUS_CANCELED) {
$statusType = 'status5';
}
if ($status == self::STATUS_REFUSED) {
$statusType = 'status5';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
} }
@ -1338,15 +1364,12 @@ class Holiday extends CommonObject
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
// Return value // Return value
if (empty($obj)) if (empty($obj)) {
{ if ($createifnotfound) {
if ($createifnotfound)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
$sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')"; $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
return $createifnotfound; return $createifnotfound;
} else { } else {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
@ -1379,8 +1402,7 @@ class Holiday extends CommonObject
$error = 0; $error = 0;
if (empty($userID) && empty($nbHoliday) && empty($fk_type)) if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
{
$langs->load("holiday"); $langs->load("holiday");
// Si mise à jour pour tout le monde en début de mois // Si mise à jour pour tout le monde en début de mois
@ -1395,8 +1417,7 @@ class Holiday extends CommonObject
//print 'month: '.$month.' lastUpdate:'.$lastUpdate.' monthLastUpdate:'.$monthLastUpdate;exit; //print 'month: '.$month.' lastUpdate:'.$lastUpdate.' monthLastUpdate:'.$monthLastUpdate;exit;
// Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp
if ($month != $monthLastUpdate) if ($month != $monthLastUpdate) {
{
$this->db->begin(); $this->db->begin();
$users = $this->fetchUsers(false, false); $users = $this->fetchUsers(false, false);
@ -1412,7 +1433,9 @@ class Holiday extends CommonObject
// Update each user counter // Update each user counter
foreach ($users as $userCounter) { foreach ($users as $userCounter) {
$nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newByMonth']) ? $typeleaves[$userCounter['type']]['newByMonth'] : 0); $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newByMonth']) ? $typeleaves[$userCounter['type']]['newByMonth'] : 0);
if (empty($nbDaysToAdd)) continue; if (empty($nbDaysToAdd)) {
continue;
}
dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG); dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
@ -1424,15 +1447,13 @@ class Holiday extends CommonObject
$result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type'], $langs->trans('HolidaysMonthlyUpdate')); $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type'], $langs->trans('HolidaysMonthlyUpdate'));
if ($result < 0) if ($result < 0) {
{
$error++; $error++;
break; break;
} }
} }
if (!$error) if (!$error) {
{
$this->db->commit(); $this->db->commit();
return 1; return 1;
} else { } else {
@ -1449,19 +1470,16 @@ class Holiday extends CommonObject
$sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users"; $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
$sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type; $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
if ($num > 0) if ($num > 0) {
{
// Update for user // Update for user
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
$sql .= " nb_holiday = ".$nbHoliday; $sql .= " nb_holiday = ".$nbHoliday;
$sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type; $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (!$result) if (!$result) {
{
$error++; $error++;
$this->errors[] = $this->db->lasterror(); $this->errors[] = $this->db->lasterror();
} }
@ -1471,8 +1489,7 @@ class Holiday extends CommonObject
$sql .= $nbHoliday; $sql .= $nbHoliday;
$sql .= ", ".(int) $userID.", ".(int) $fk_type.")"; $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (!$result) if (!$result) {
{
$error++; $error++;
$this->errors[] = $this->db->lasterror(); $this->errors[] = $this->db->lasterror();
} }
@ -1482,8 +1499,7 @@ class Holiday extends CommonObject
$error++; $error++;
} }
if (!$error) if (!$error) {
{
return 1; return 1;
} else { } else {
return -1; return -1;
@ -1527,19 +1543,19 @@ class Holiday extends CommonObject
public function createCPusers($single = false, $userid = '') public function createCPusers($single = false, $userid = '')
{ {
// do we have to add balance for all users ? // do we have to add balance for all users ?
if (!$single) if (!$single) {
{
dol_syslog(get_class($this).'::createCPusers'); dol_syslog(get_class($this).'::createCPusers');
$arrayofusers = $this->fetchUsers(false, true); $arrayofusers = $this->fetchUsers(false, true);
foreach ($arrayofusers as $users) foreach ($arrayofusers as $users) {
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
$sql .= " (fk_user, nb_holiday)"; $sql .= " (fk_user, nb_holiday)";
$sql .= " VALUES (".((int) $users['rowid'])."', '0')"; $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) dol_print_error($this->db); if (!$resql) {
dol_print_error($this->db);
}
} }
} else { } else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
@ -1547,7 +1563,9 @@ class Holiday extends CommonObject
$sql .= " VALUES (".((int) $userid)."', '0')"; $sql .= " VALUES (".((int) $userid)."', '0')";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) dol_print_error($this->db); if (!$resql) {
dol_print_error($this->db);
}
} }
} }
@ -1579,16 +1597,20 @@ class Holiday extends CommonObject
$sql = "SELECT nb_holiday"; $sql = "SELECT nb_holiday";
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
$sql .= " WHERE fk_user = ".(int) $user_id; $sql .= " WHERE fk_user = ".(int) $user_id;
if ($fk_type > 0) $sql .= " AND fk_type = ".(int) $fk_type; if ($fk_type > 0) {
$sql .= " AND fk_type = ".(int) $fk_type;
}
dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG); dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
//return number_format($obj->nb_holiday,2); //return number_format($obj->nb_holiday,2);
if ($obj) return $obj->nb_holiday; if ($obj) {
else return null; return $obj->nb_holiday;
} else {
return null;
}
} else { } else {
return null; return null;
} }
@ -1608,10 +1630,8 @@ class Holiday extends CommonObject
dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG); dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
if ($stringlist) if ($stringlist) {
{ if ($type) {
if ($type)
{
// If user of Dolibarr // If user of Dolibarr
$sql = "SELECT"; $sql = "SELECT";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
@ -1620,8 +1640,7 @@ class Holiday extends CommonObject
$sql .= " u.rowid"; $sql .= " u.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
{
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql .= " WHERE ((ug.fk_user = u.rowid"; $sql .= " WHERE ((ug.fk_user = u.rowid";
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))"; $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
@ -1630,7 +1649,9 @@ class Holiday extends CommonObject
$sql .= " WHERE u.entity IN (".getEntity('user').")"; $sql .= " WHERE u.entity IN (".getEntity('user').")";
} }
$sql .= " AND u.statut > 0"; $sql .= " AND u.statut > 0";
if ($filters) $sql .= $filters; if ($filters) {
$sql .= $filters;
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -1641,8 +1662,7 @@ class Holiday extends CommonObject
$stringlist = ''; $stringlist = '';
// Boucles du listage des utilisateurs // Boucles du listage des utilisateurs
while ($i < $num) while ($i < $num) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($i == 0) { if ($i == 0) {
@ -1665,7 +1685,9 @@ class Holiday extends CommonObject
$sql = "SELECT DISTINCT cpu.fk_user"; $sql = "SELECT DISTINCT cpu.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE cpu.fk_user = u.rowid"; $sql .= " WHERE cpu.fk_user = u.rowid";
if ($filters) $sql .= $filters; if ($filters) {
$sql .= $filters;
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -1676,8 +1698,7 @@ class Holiday extends CommonObject
$stringlist = ''; $stringlist = '';
// Boucles du listage des utilisateurs // Boucles du listage des utilisateurs
while ($i < $num) while ($i < $num) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($i == 0) { if ($i == 0) {
@ -1699,8 +1720,7 @@ class Holiday extends CommonObject
} else { } else {
// Si faux donc return array // Si faux donc return array
// List for Dolibarr users // List for Dolibarr users
if ($type) if ($type) {
{
// If user of Dolibarr // If user of Dolibarr
$sql = "SELECT"; $sql = "SELECT";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
@ -1709,8 +1729,7 @@ class Holiday extends CommonObject
$sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user"; $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
{
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql .= " WHERE ((ug.fk_user = u.rowid"; $sql .= " WHERE ((ug.fk_user = u.rowid";
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))"; $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
@ -1720,13 +1739,14 @@ class Holiday extends CommonObject
} }
$sql .= " AND u.statut > 0"; $sql .= " AND u.statut > 0";
if ($filters) $sql .= $filters; if ($filters) {
$sql .= $filters;
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
// Si pas d'erreur SQL // Si pas d'erreur SQL
if ($resql) if ($resql) {
{
$i = 0; $i = 0;
$tab_result = $this->holiday; $tab_result = $this->holiday;
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -1761,20 +1781,20 @@ class Holiday extends CommonObject
$sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user"; $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE cpu.fk_user = u.rowid"; $sql .= " WHERE cpu.fk_user = u.rowid";
if ($filters) $sql .= $filters; if ($filters) {
$sql .= $filters;
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
// Si pas d'erreur SQL // Si pas d'erreur SQL
if ($resql) if ($resql) {
{
$i = 0; $i = 0;
$tab_result = $this->holiday; $tab_result = $this->holiday;
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
// Boucles du listage des utilisateurs // Boucles du listage des utilisateurs
while ($i < $num) while ($i < $num) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid; // rowid of user $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
@ -1827,11 +1847,9 @@ class Holiday extends CommonObject
dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql); dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$num_rows = $this->db->num_rows($result); $i = 0; $num_rows = $this->db->num_rows($result); $i = 0;
while ($i < $num_rows) while ($i < $num_rows) {
{
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
array_push($users_validator, $objp->fk_user); array_push($users_validator, $objp->fk_user);
$i++; $i++;
@ -1888,7 +1906,9 @@ class Holiday extends CommonObject
*/ */
public function verifNbUsers($userDolibarrWithoutCP, $userCP) public function verifNbUsers($userDolibarrWithoutCP, $userCP)
{ {
if (empty($userCP)) $userCP = 0; if (empty($userCP)) {
$userCP = 0;
}
dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP); dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
return 1; return 1;
} }
@ -1914,7 +1934,9 @@ class Holiday extends CommonObject
$new_solde = price2num($new_solde, 5); $new_solde = price2num($new_solde, 5);
//print "$prev_solde == $new_solde"; //print "$prev_solde == $new_solde";
if ($prev_solde == $new_solde) return 0; if ($prev_solde == $new_solde) {
return 0;
}
$this->db->begin(); $this->db->begin();
@ -1938,21 +1960,17 @@ class Holiday extends CommonObject
$sql .= ")"; $sql .= ")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql) {
{
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }
if (!$error) if (!$error) {
{
$this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs"); $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -2051,23 +2069,26 @@ class Holiday extends CommonObject
$sql = "SELECT rowid, code, label, affect, delay, newByMonth"; $sql = "SELECT rowid, code, label, affect, delay, newByMonth";
$sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types"; $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
$sql .= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')'; $sql .= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
if ($active >= 0) $sql .= " AND active = ".((int) $active); if ($active >= 0) {
if ($affect >= 0) $sql .= " AND affect = ".((int) $affect); $sql .= " AND active = ".((int) $active);
}
if ($affect >= 0) {
$sql .= " AND affect = ".((int) $affect);
}
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
if ($num) if ($num) {
{ while ($obj = $this->db->fetch_object($result)) {
while ($obj = $this->db->fetch_object($result))
{
$types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth); $types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
} }
return $types; return $types;
} }
} else dol_print_error($this->db); } else {
dol_print_error($this->db);
}
return array(); return array();
} }
@ -2099,10 +2120,8 @@ class Holiday extends CommonObject
$sql .= " AND f.entity = ".$conf->entity; $sql .= " AND f.entity = ".$conf->entity;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -2116,26 +2135,22 @@ class Holiday extends CommonObject
$cuser->fetch($obj->fk_user_author); $cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser; $this->user_creation = $cuser;
if ($obj->fk_user_creation) if ($obj->fk_user_creation) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_creation); $cuser->fetch($obj->fk_user_creation);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_valid) if ($obj->fk_user_valid) {
{
$vuser = new User($this->db); $vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid); $vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser; $this->user_validation = $vuser;
} }
if ($obj->fk_user_modification) if ($obj->fk_user_modification) {
{
$muser = new User($this->db); $muser = new User($this->db);
$muser->fetch($obj->fk_user_modification); $muser->fetch($obj->fk_user_modification);
$this->user_modification = $muser; $this->user_modification = $muser;
} }
if ($obj->fk_user_approve) if ($obj->fk_user_approve) {
{
$auser = new User($this->db); $auser = new User($this->db);
$auser->fetch($obj->fk_user_approve); $auser->fetch($obj->fk_user_approve);
$this->user_approve = $auser; $this->user_approve = $auser;
@ -2191,8 +2206,7 @@ class Holiday extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
$sql .= " WHERE h.statut > 1"; $sql .= " WHERE h.statut > 1";
$sql .= " AND h.entity IN (".getEntity('holiday').")"; $sql .= " AND h.entity IN (".getEntity('holiday').")";
if (empty($user->rights->expensereport->readall)) if (empty($user->rights->expensereport->readall)) {
{
$userchildids = $user->getAllChildIds(1); $userchildids = $user->getAllChildIds(1);
$sql .= " AND (h.fk_user IN (".join(',', $userchildids).")"; $sql .= " AND (h.fk_user IN (".join(',', $userchildids).")";
$sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))"; $sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))";
@ -2224,7 +2238,9 @@ class Holiday extends CommonObject
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe if ($user->socid) {
return -1; // protection pour eviter appel par utilisateur externe
}
$now = dol_now(); $now = dol_now();
@ -2232,16 +2248,14 @@ class Holiday extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
$sql .= " WHERE h.statut = 2"; $sql .= " WHERE h.statut = 2";
$sql .= " AND h.entity IN (".getEntity('holiday').")"; $sql .= " AND h.entity IN (".getEntity('holiday').")";
if (empty($user->rights->expensereport->read_all)) if (empty($user->rights->expensereport->read_all)) {
{
$userchildids = $user->getAllChildIds(1); $userchildids = $user->getAllChildIds(1);
$sql .= " AND (h.fk_user IN (".join(',', $userchildids).")"; $sql .= " AND (h.fk_user IN (".join(',', $userchildids).")";
$sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))"; $sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))";
} }
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$langs->load("members"); $langs->load("members");
$response = new WorkboardResponse(); $response = new WorkboardResponse();
@ -2251,8 +2265,7 @@ class Holiday extends CommonObject
$response->url = DOL_URL_ROOT.'/holiday/list.php?search_statut=2&amp;mainmenu=hrm&amp;leftmenu=holiday'; $response->url = DOL_URL_ROOT.'/holiday/list.php?search_statut=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
$response->img = img_object('', "holiday"); $response->img = img_object('', "holiday");
while ($obj = $this->db->fetch_object($resql)) while ($obj = $this->db->fetch_object($resql)) {
{
$response->nbtodo++; $response->nbtodo++;
if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) { if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {

View File

@ -44,19 +44,29 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortfield) $sortfield = "t.rowid"; // Set here default search field if (!$sortfield) {
if (!$sortorder) $sortorder = "ASC"; $sortfield = "t.rowid"; // Set here default search field
}
if (!$sortorder) {
$sortorder = "ASC";
}
// Protection if external user // Protection if external user
if ($user->socid > 0) accessforbidden(); if ($user->socid > 0) {
accessforbidden();
}
// If the user does not have perm to read the page // If the user does not have perm to read the page
if (empty($user->rights->holiday->read)) accessforbidden(); if (empty($user->rights->holiday->read)) {
accessforbidden();
}
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
@ -65,8 +75,7 @@ $extrafields = new ExtraFields($db);
$holiday = new Holiday($db); $holiday = new Holiday($db);
if (empty($conf->holiday->enabled)) if (empty($conf->holiday->enabled)) {
{
llxHeader('', $langs->trans('CPTitreMenu')); llxHeader('', $langs->trans('CPTitreMenu'));
print '<div class="tabBar">'; print '<div class="tabBar">';
print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>'; print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>';
@ -81,21 +90,25 @@ if (empty($conf->holiday->enabled))
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Selection of new fields // Selection of new fields
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')) // All tests are required 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_name = ''; $search_name = '';
$search_supervisor = ''; $search_supervisor = '';
$toselect = ''; $toselect = '';
@ -104,17 +117,16 @@ if (empty($reshook))
// Mass actions // Mass actions
/* /*
$objectclass='Skeleton'; $objectclass='Skeleton';
$objectlabel='Skeleton'; $objectlabel='Skeleton';
$permissiontoread = $user->rights->skeleton->read; $permissiontoread = $user->rights->skeleton->read;
$permissiontodelete = $user->rights->skeleton->delete; $permissiontodelete = $user->rights->skeleton->delete;
$uploaddir = $conf->skeleton->dir_output; $uploaddir = $conf->skeleton->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
*/ */
// Si il y a une action de mise à jour // Si il y a une action de mise à jour
if ($action == 'update' && isset($_POST['update_cp'])) if ($action == 'update' && isset($_POST['update_cp'])) {
{
$error = 0; $error = 0;
$typeleaves = $holiday->getTypes(1, 1); $typeleaves = $holiday->getTypes(1, 1);
@ -122,13 +134,11 @@ if (empty($reshook))
$userID = array_keys($_POST['update_cp']); $userID = array_keys($_POST['update_cp']);
$userID = $userID[0]; $userID = $userID[0];
foreach ($typeleaves as $key => $val) foreach ($typeleaves as $key => $val) {
{
$userValue = $_POST['nb_holiday_'.$val['rowid']]; $userValue = $_POST['nb_holiday_'.$val['rowid']];
$userValue = $userValue[$userID]; $userValue = $userValue[$userID];
if (!empty($userValue) || (string) $userValue == '0') if (!empty($userValue) || (string) $userValue == '0') {
{
$userValue = price2num($userValue, 5); $userValue = price2num($userValue, 5);
} else { } else {
$userValue = ''; $userValue = '';
@ -138,37 +148,36 @@ if (empty($reshook))
$comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : ''); $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : '');
//print 'holiday: '.$val['rowid'].'-'.$userValue; //print 'holiday: '.$val['rowid'].'-'.$userValue;
if ($userValue != '') if ($userValue != '') {
{
// We add the modification to the log (must be before update of sold because we read current value of sold) // We add the modification to the log (must be before update of sold because we read current value of sold)
$result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']); $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']);
if ($result < 0) if ($result < 0) {
{
setEventMessages($holiday->error, $holiday->errors, 'errors'); setEventMessages($holiday->error, $holiday->errors, 'errors');
$error++; $error++;
} }
// Update of the days of the employee // Update of the days of the employee
$result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']); $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']);
if ($result < 0) if ($result < 0) {
{
setEventMessages($holiday->error, $holiday->errors, 'errors'); setEventMessages($holiday->error, $holiday->errors, 'errors');
$error++; $error++;
} }
// If it first update of balance, we set date to avoid to have sold incremented by new month // If it first update of balance, we set date to avoid to have sold incremented by new month
/* /*
$now=dol_now(); $now=dol_now();
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
$sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'"; $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";
$sql.= " WHERE name = 'lastUpdate' and value IS NULL"; // Add value IS NULL to be sure to update only at init. $sql.= " WHERE name = 'lastUpdate' and value IS NULL"; // Add value IS NULL to be sure to update only at init.
dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG); dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG);
$result = $db->query($sql); $result = $db->query($sql);
*/ */
} }
} }
if (!$error) setEventMessages('UpdateConfCPOK', '', 'mesgs'); if (!$error) {
setEventMessages('UpdateConfCPOK', '', 'mesgs');
}
} }
} }
@ -191,7 +200,9 @@ if ($result < 0) {
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
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="'.newToken().'">'; print '<input type="hidden" name="token" value="'.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="update">'; print '<input type="hidden" name="action" value="update">';
@ -217,35 +228,36 @@ $filters = '';
// Filter on array of ids of all childs // Filter on array of ids of all childs
$userchilds = array(); $userchilds = array();
if (empty($user->rights->holiday->readall)) if (empty($user->rights->holiday->readall)) {
{
$userchilds = $user->getAllChildIds(1); $userchilds = $user->getAllChildIds(1);
$filters .= ' AND u.rowid IN ('.join(', ', $userchilds).')'; $filters .= ' AND u.rowid IN ('.join(', ', $userchilds).')';
} }
if (!empty($search_name)) { if (!empty($search_name)) {
$filters .= natural_search(array('u.firstname', 'u.lastname'), $search_name); $filters .= natural_search(array('u.firstname', 'u.lastname'), $search_name);
} }
if ($search_supervisor > 0) $filters .= natural_search(array('u.fk_user'), $search_supervisor, 2); if ($search_supervisor > 0) {
$filters .= natural_search(array('u.fk_user'), $search_supervisor, 2);
}
$filters .= ' AND employee = 1'; // Only employee users are visible $filters .= ' AND employee = 1'; // Only employee users are visible
$listUsers = $holiday->fetchUsers(false, true, $filters); $listUsers = $holiday->fetchUsers(false, true, $filters);
if (is_numeric($listUsers) && $listUsers < 0) if (is_numeric($listUsers) && $listUsers < 0) {
{
setEventMessages($holiday->error, $holiday->errors, 'errors'); setEventMessages($holiday->error, $holiday->errors, 'errors');
} }
$i = 0; $i = 0;
if (count($typeleaves) == 0) if (count($typeleaves) == 0) {
{
//print '<div class="info">'; //print '<div class="info">';
print $langs->trans("NoLeaveWithCounterDefined")."<br>\n"; print $langs->trans("NoLeaveWithCounterDefined")."<br>\n";
print $langs->trans("GoIntoDictionaryHolidayTypes"); print $langs->trans("GoIntoDictionaryHolidayTypes");
//print '</div>'; //print '</div>';
} else { } else {
$canedit = 0; $canedit = 0;
if (!empty($user->rights->holiday->define_holiday)) $canedit = 1; if (!empty($user->rights->holiday->define_holiday)) {
$canedit = 1;
}
$moreforfilter = ''; $moreforfilter = '';
@ -263,10 +275,8 @@ if (count($typeleaves) == 0)
print '</td>'; print '</td>';
// Type of leave request // Type of leave request
if (count($typeleaves)) if (count($typeleaves)) {
{ foreach ($typeleaves as $key => $val) {
foreach ($typeleaves as $key => $val)
{
print '<td class="liste_titre" style="text-align:center"></td>'; print '<td class="liste_titre" style="text-align:center"></td>';
} }
} else { } else {
@ -285,10 +295,8 @@ if (count($typeleaves) == 0)
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]); print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]);
print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]); print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]);
if (count($typeleaves)) if (count($typeleaves)) {
{ foreach ($typeleaves as $key => $val) {
foreach ($typeleaves as $key => $val)
{
$labeltype = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']); $labeltype = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']);
print_liste_field_titre($labeltype, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center '); print_liste_field_titre($labeltype, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center ');
} }
@ -301,12 +309,12 @@ if (count($typeleaves) == 0)
$usersupervisor = new User($db); $usersupervisor = new User($db);
foreach ($listUsers as $users) foreach ($listUsers as $users) {
{
// If user has not permission to edit/read all, we must see only subordinates // If user has not permission to edit/read all, we must see only subordinates
if (empty($user->rights->holiday->readall)) if (empty($user->rights->holiday->readall)) {
{ if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) {
if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) continue; // This user is not into hierarchy of current user, we hide it. continue; // This user is not into hierarchy of current user, we hide it.
}
} }
$userstatic->id = $users['rowid']; $userstatic->id = $users['rowid'];
@ -318,7 +326,9 @@ if (count($typeleaves) == 0)
$userstatic->employee = $users['employee']; $userstatic->employee = $users['employee'];
$userstatic->fk_user = $users['fk_user']; $userstatic->fk_user = $users['fk_user'];
if ($userstatic->fk_user > 0) $usersupervisor->fetch($userstatic->fk_user); if ($userstatic->fk_user > 0) {
$usersupervisor->fetch($userstatic->fk_user);
}
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -329,21 +339,26 @@ if (count($typeleaves) == 0)
// Supervisor // Supervisor
print '<td>'; print '<td>';
if ($userstatic->fk_user > 0) print $usersupervisor->getNomUrl(-1); if ($userstatic->fk_user > 0) {
print $usersupervisor->getNomUrl(-1);
}
print '</td>'; print '</td>';
// Amount for each type // Amount for each type
if (count($typeleaves)) if (count($typeleaves)) {
{ foreach ($typeleaves as $key => $val) {
foreach ($typeleaves as $key => $val)
{
$nbtoshow = ''; $nbtoshow = '';
if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow = price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5); if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') {
$nbtoshow = price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5);
}
//var_dump($users['rowid'].' - '.$val['rowid']); //var_dump($users['rowid'].' - '.$val['rowid']);
print '<td style="text-align:center">'; print '<td style="text-align:center">';
if ($canedit) print '<input type="text"'.($canedit ? '' : ' disabled="disabled"').' value="'.$nbtoshow.'" name="nb_holiday_'.$val['rowid'].'['.$users['rowid'].']" size="5" style="text-align: center;"/>'; if ($canedit) {
else print $nbtoshow; print '<input type="text"'.($canedit ? '' : ' disabled="disabled"').' value="'.$nbtoshow.'" name="nb_holiday_'.$val['rowid'].'['.$users['rowid'].']" size="5" style="text-align: center;"/>';
} else {
print $nbtoshow;
}
//print ' '.$langs->trans('days'); //print ' '.$langs->trans('days');
print '</td>'."\n"; print '</td>'."\n";
} }
@ -353,13 +368,14 @@ if (count($typeleaves) == 0)
// Note // Note
print '<td>'; print '<td>';
if ($canedit) print '<input type="text"'.($canedit ? '' : ' disabled="disabled"').' class="maxwidthonsmartphone" value="" name="note_holiday['.$users['rowid'].']" size="30"/>'; if ($canedit) {
print '<input type="text"'.($canedit ? '' : ' disabled="disabled"').' class="maxwidthonsmartphone" value="" name="note_holiday['.$users['rowid'].']" size="30"/>';
}
print '</td>'; print '</td>';
// Button modify // Button modify
print '<td>'; print '<td>';
if (!empty($user->rights->holiday->define_holiday)) // Allowed to set the balance of any user if (!empty($user->rights->holiday->define_holiday)) { // Allowed to set the balance of any user
{
print '<input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Save")).'" class="button smallpaddingimp"/>'; print '<input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Save")).'" class="button smallpaddingimp"/>';
} }
print '</td>'."\n"; print '</td>'."\n";

View File

@ -45,7 +45,9 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'holiday', $id, 'holiday'); $result = restrictedArea($user, 'holiday', $id, 'holiday');
// Get parameters // Get parameters
@ -53,12 +55,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "position_name"; $sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "position_name";
}
$object = new Holiday($db); $object = new Holiday($db);
@ -86,8 +94,7 @@ $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->t
llxHeader("", "", $langs->trans("InterventionCard")); llxHeader("", "", $langs->trans("InterventionCard"));
if ($object->id) if ($object->id) {
{
$valideur = new User($db); $valideur = new User($db);
$valideur->fetch($object->fk_validator); $valideur->fetch($object->fk_validator);
@ -102,8 +109,7 @@ if ($object->id)
// Build file list // Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0; $totalsize = 0;
foreach ($filearray as $key => $file) foreach ($filearray as $key => $file) {
{
$totalsize += $file['size']; $totalsize += $file['size'];
} }
@ -138,8 +144,7 @@ if ($object->id)
$starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning'; $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
$endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon'; $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
if (!$edit) if (!$edit) {
{
print '<tr>'; print '<tr>';
print '<td>'; print '<td>';
print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday")); print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
@ -162,8 +167,7 @@ if ($object->id)
print '</tr>'; print '</tr>';
} }
if (!$edit) if (!$edit) {
{
print '<tr>'; print '<tr>';
print '<td>'; print '<td>';
print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday")); print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
@ -192,15 +196,18 @@ if ($object->id)
$htmlhelp = $langs->trans('NbUseDaysCPHelp'); $htmlhelp = $langs->trans('NbUseDaysCPHelp');
$includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1); $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
$includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1); $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
if ($includesaturday) $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday")); if ($includesaturday) {
if ($includesunday) $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday")); $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
}
if ($includesunday) {
$htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
}
print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp); print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
print '</td>'; print '</td>';
print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>'; print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
print '</tr>'; print '</tr>';
if ($object->statut == 5) if ($object->statut == 5) {
{
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DetailRefusCP').'</td>'; print '<td>'.$langs->trans('DetailRefusCP').'</td>';
print '<td>'.$object->detail_refuse.'</td>'; print '<td>'.$object->detail_refuse.'</td>';
@ -208,8 +215,7 @@ if ($object->id)
} }
// Description // Description
if (!$edit) if (!$edit) {
{
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DescCP').'</td>'; print '<td>'.$langs->trans('DescCP').'</td>';
print '<td>'.nl2br($object->description).'</td>'; print '<td>'.nl2br($object->description).'</td>';
@ -227,67 +233,67 @@ if ($object->id)
print '</tbody>'; print '</tbody>';
print '</table>'."\n"; print '</table>'."\n";
/* /*
print '</div>'; print '</div>';
print '<div class="fichehalfright">'; print '<div class="fichehalfright">';
print '<div class="ficheaddleft">'; print '<div class="ficheaddleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
// Info workflow // Info workflow
print '<table class="border tableforfield centpercent">'."\n"; print '<table class="border tableforfield centpercent">'."\n";
print '<tbody>'; print '<tbody>';
if (! empty($object->fk_user_create)) if (! empty($object->fk_user_create))
{ {
$userCreate=new User($db); $userCreate=new User($db);
$userCreate->fetch($object->fk_user_create); $userCreate->fetch($object->fk_user_create);
print '<tr>'; print '<tr>';
print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>'; print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
print '<td>'.$userCreate->getNomUrl(-1).'</td>'; print '<td>'.$userCreate->getNomUrl(-1).'</td>';
print '</tr>'; print '</tr>';
} }
if (!$edit) { if (!$edit) {
print '<tr>'; print '<tr>';
print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
print '<td>'.$valideur->getNomUrl(-1).'</td>'; print '<td>'.$valideur->getNomUrl(-1).'</td>';
print '</tr>'; print '</tr>';
} else { } else {
print '<tr>'; print '<tr>';
print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
print '<td>'; print '<td>';
print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DateCreation').'</td>'; print '<td>'.$langs->trans('DateCreation').'</td>';
print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>'; print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
print '</tr>'; print '</tr>';
if ($object->statut == 3) { if ($object->statut == 3) {
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DateValidCP').'</td>'; print '<td>'.$langs->trans('DateValidCP').'</td>';
print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>'; print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
print '</tr>'; print '</tr>';
} }
if ($object->statut == 4) { if ($object->statut == 4) {
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DateCancelCP').'</td>'; print '<td>'.$langs->trans('DateCancelCP').'</td>';
print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>'; print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
print '</tr>'; print '</tr>';
} }
if ($object->statut == 5) { if ($object->statut == 5) {
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('DateRefusCP').'</td>'; print '<td>'.$langs->trans('DateRefusCP').'</td>';
print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>'; print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
print '</tr>'; print '</tr>';
} }
print '</tbody>'; print '</tbody>';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '</div>'; */ print '</div>'; */
print '</div>'; print '</div>';
print '<div class="clearboth"></div>'; print '<div class="clearboth"></div>';

View File

@ -37,23 +37,26 @@ $ref = GETPOST('ref', 'alpha');
$childids = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'holiday', $id, 'holiday'); $result = restrictedArea($user, 'holiday', $id, 'holiday');
$object = new Holiday($db); $object = new Holiday($db);
if (!$object->fetch($id, $ref) > 0) if (!$object->fetch($id, $ref) > 0) {
{
dol_print_error($db); dol_print_error($db);
} }
if ($object->id > 0) if ($object->id > 0) {
{
// Check current user can read this expense report // Check current user can read this expense report
$canread = 0; $canread = 0;
if (!empty($user->rights->holiday->readall)) $canread = 1; if (!empty($user->rights->holiday->readall)) {
if (!empty($user->rights->holiday->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; $canread = 1;
if (!$canread) }
{ if (!empty($user->rights->holiday->lire) && in_array($object->fk_user_author, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -69,8 +72,7 @@ $title = $langs->trans("Holiday")." - ".$langs->trans("Info");
$helpurl = ""; $helpurl = "";
llxHeader("", $title, $helpurl); llxHeader("", $title, $helpurl);
if ($id > 0 || !empty($ref)) if ($id > 0 || !empty($ref)) {
{
$object = new Holiday($db); $object = new Holiday($db);
$object->fetch($id, $ref); $object->fetch($id, $ref);
$object->info($object->id); $object->info($object->id);

View File

@ -40,7 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
$langs->loadLangs(array('users', 'other', 'holiday', 'hrm')); $langs->loadLangs(array('users', 'other', 'holiday', 'hrm'));
// Protection if external user // Protection if external user
if ($user->socid > 0) accessforbidden(); if ($user->socid > 0) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09'); // The action 'add', 'create', 'edit', 'update', 'view', ... $action = GETPOST('action', 'aZ09'); // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
@ -59,21 +61,24 @@ $childids = $user->getAllChildIds(1);
// Security check // Security check
$socid = 0; $socid = 0;
if ($user->socid > 0) // Protection if external user if ($user->socid > 0) { // Protection if external user
{ //$socid = $user->socid;
//$socid = $user->socid;
accessforbidden(); accessforbidden();
} }
$result = restrictedArea($user, 'holiday', '', ''); $result = restrictedArea($user, 'holiday', '', '');
// If we are on the view of a specific user // If we are on the view of a specific user
if ($id > 0) if ($id > 0) {
{
$canread = 0; $canread = 0;
if ($id == $user->id) $canread = 1; if ($id == $user->id) {
if (!empty($user->rights->holiday->readall)) $canread = 1; $canread = 1;
if (!empty($user->rights->holiday->read) && in_array($id, $childids)) $canread = 1; }
if (!$canread) if (!empty($user->rights->holiday->readall)) {
{ $canread = 1;
}
if (!empty($user->rights->holiday->read) && in_array($id, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -86,12 +91,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "cp.rowid"; $sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "cp.rowid";
}
$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_ref = GETPOST('search_ref', 'alphanohtml'); $search_ref = GETPOST('search_ref', 'alphanohtml');
@ -145,8 +156,7 @@ $arrayfields = array(
// Extra fields // Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
if (empty($conf->holiday->enabled)) if (empty($conf->holiday->enabled)) {
{
llxHeader('', $langs->trans('CPTitreMenu')); llxHeader('', $langs->trans('CPTitreMenu'));
print '<div class="tabBar">'; print '<div class="tabBar">';
print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>'; print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>';
@ -160,21 +170,25 @@ if (empty($conf->holiday->enabled))
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid'=>$socid); $parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Selection of new fields // Selection of new fields
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')) // All tests are required 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_month_create = ""; $search_month_create = "";
$search_year_create = ""; $search_year_create = "";
@ -190,8 +204,7 @@ if (empty($reshook))
$search_array_options = array(); $search_array_options = array();
} }
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
{
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
} }
@ -230,8 +243,7 @@ $min_year = 10;
// Get current user id // Get current user id
$user_id = $user->id; $user_id = $user->id;
if ($id > 0) if ($id > 0) {
{
// Charge utilisateur edite // Charge utilisateur edite
$fuser->fetch($id, '', '', 1); $fuser->fetch($id, '', '', 1);
$fuser->getrights(); $fuser->getrights();
@ -282,21 +294,29 @@ $sql .= " ua.statut as validator_status,";
$sql .= " ua.photo as validator_photo"; $sql .= " ua.photo as validator_photo";
// Add fields from extrafields // Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
}
} }
// Add fields from hooks // Add fields from hooks
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)";
}
$sql .= ", ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua"; $sql .= ", ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
$sql .= " WHERE cp.entity IN (".getEntity('holiday').")"; $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 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
// Search all // Search all
if (!empty($sall)) $sql .= natural_search(array_keys($fieldstosearchall), $sall); if (!empty($sall)) {
$sql .= natural_search(array_keys($fieldstosearchall), $sall);
}
// Ref // Ref
if (!empty($search_ref)) $sql .= natural_search("cp.ref", $search_ref); if (!empty($search_ref)) {
$sql .= natural_search("cp.ref", $search_ref);
}
// Start date // Start date
$sql .= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start); $sql .= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start);
// End date // End date
@ -320,8 +340,12 @@ if (!empty($search_status) && $search_status != -1) {
$sql .= " AND cp.statut = '".$db->escape($search_status)."'\n"; $sql .= " AND cp.statut = '".$db->escape($search_status)."'\n";
} }
if (empty($user->rights->holiday->readall)) $sql .= ' AND cp.fk_user IN ('.join(',', $childids).')'; if (empty($user->rights->holiday->readall)) {
if ($id > 0) $sql .= " AND cp.fk_user IN (".$id.")"; $sql .= ' AND cp.fk_user IN ('.join(',', $childids).')';
}
if ($id > 0) {
$sql .= " AND cp.fk_user IN (".$id.")";
}
// Add where from extra fields // Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
@ -334,12 +358,10 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
{
$result = $db->query($sql); $result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result); $nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
{
$page = 0; $page = 0;
$offset = 0; $offset = 0;
} }
@ -350,30 +372,63 @@ $sql .= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$arrayofselected = is_array($toselect) ? $toselect : array(); $arrayofselected = is_array($toselect) ? $toselect : array();
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); $param .= '&contextpage='.urlencode($contextpage);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); }
if ($search_ref) $param .= '&search_ref='.urlencode($search_ref); if ($limit > 0 && $limit != $conf->liste_limit) {
if ($search_day_create) $param .= '&search_day_create='.urlencode($search_day_create); $param .= '&limit='.urlencode($limit);
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 ($optioncss != '') {
if ($search_day_start) $param .= '&search_day_start='.urlencode($search_day_start); $param .= '&optioncss='.urlencode($optioncss);
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_ref) {
if ($search_day_end) $param .= '&search_day_end='.urlencode($search_day_end); $param .= '&search_ref='.urlencode($search_ref);
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_day_create) {
if ($search_employee > 0) $param .= '&search_employee='.urlencode($search_employee); $param .= '&search_day_create='.urlencode($search_day_create);
if ($search_valideur > 0) $param .= '&search_valideur='.urlencode($search_valideur); }
if ($search_type > 0) $param .= '&search_type='.urlencode($search_type); if ($search_month_create) {
if ($search_status > 0) $param .= '&search_status='.urlencode($search_status); $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_status > 0) {
$param .= '&search_status='.urlencode($search_status);
}
// Add $param from extra fields // Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -383,23 +438,30 @@ if ($resql)
//'builddoc'=>$langs->trans("PDFMerge"), //'builddoc'=>$langs->trans("PDFMerge"),
//'presend'=>$langs->trans("SendByMail"), //'presend'=>$langs->trans("SendByMail"),
); );
if ($user->rights->holiday->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete"); if ($user->rights->holiday->supprimer) {
if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
if (in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
// Lines of title fields // Lines of title fields
print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n"; 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="'.newToken().'">'; print '<input type="hidden" name="token" value="'.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="'.($action == 'edit' ? 'update' : 'list').'">'; print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
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="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; 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
{
$title = $langs->trans("User"); $title = $langs->trans("User");
$linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$head = user_prepare_head($fuser); $head = user_prepare_head($fuser);
@ -408,8 +470,7 @@ if ($resql)
dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin); dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
{
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<br>'; print '<br>';
@ -425,8 +486,7 @@ if ($resql)
$canedit = (($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance)))); $canedit = (($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance))));
if ($canedit) if ($canedit) {
{
print '<a href="'.DOL_URL_ROOT.'/holiday/card.php?action=create&fuserid='.$user_id.'" class="butAction">'.$langs->trans("AddCP").'</a>'; print '<a href="'.DOL_URL_ROOT.'/holiday/card.php?action=create&fuserid='.$user_id.'" class="butAction">'.$langs->trans("AddCP").'</a>';
} }
@ -445,9 +505,10 @@ if ($resql)
$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) {
{ foreach ($fieldstosearchall as $key => $val) {
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); $fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>'; print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
} }
@ -455,11 +516,13 @@ if ($resql)
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; if (empty($reshook)) {
else $moreforfilter = $hookmanager->resPrint; $moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if (!empty($moreforfilter)) if (!empty($moreforfilter)) {
{
print '<div class="liste_titre liste_titre_bydiv centpercent">'; print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter; print $moreforfilter;
print '</div>'; print '</div>';
@ -471,7 +534,9 @@ if ($resql)
$include = ''; $include = '';
if (empty($user->rights->holiday->readall)) $include = 'hierarchyme'; // Can see only its hierarchyl if (empty($user->rights->holiday->readall)) {
$include = 'hierarchyme'; // Can see only its hierarchyl
}
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n"; print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
@ -480,23 +545,22 @@ if ($resql)
// Filters // Filters
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
if (!empty($arrayfields['cp.ref']['checked'])) if (!empty($arrayfields['cp.ref']['checked'])) {
{
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">'; print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['cp.fk_user']['checked'])) if (!empty($arrayfields['cp.fk_user']['checked'])) {
{
$morefilter = ''; $morefilter = '';
if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) $morefilter = 'AND employee = 1'; if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
$morefilter = 'AND employee = 1';
}
// User // User
$disabled = 0; $disabled = 0;
// If into the tab holiday of a user ($id is set in such a case) // If into the tab holiday of a user ($id is set in such a case)
if ($id && !GETPOSTISSET('search_employee')) if ($id && !GETPOSTISSET('search_employee')) {
{
$search_employee = $id; $search_employee = $id;
$disabled = 1; $disabled = 1;
} }
@ -507,16 +571,16 @@ if ($resql)
} }
// Approver // Approver
if (!empty($arrayfields['cp.fk_validator']['checked'])) if (!empty($arrayfields['cp.fk_validator']['checked'])) {
{ if ($user->rights->holiday->readall) {
if ($user->rights->holiday->readall)
{
print '<td class="liste_titre maxwidthonsmartphone left">'; print '<td class="liste_titre maxwidthonsmartphone left">';
$validator = new UserGroup($db); $validator = new UserGroup($db);
$excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id; $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id;
$valideurobjects = $validator->listUsersForGroup($excludefilter); $valideurobjects = $validator->listUsersForGroup($excludefilter);
$valideurarray = array(); $valideurarray = array();
foreach ($valideurobjects as $val) $valideurarray[$val->id] = $val->id; foreach ($valideurobjects as $val) {
$valideurarray[$val->id] = $val->id;
}
print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150'); print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150');
print '</td>'; print '</td>';
} else { } else {
@ -525,16 +589,14 @@ if ($resql)
} }
// Type // Type
if (!empty($arrayfields['cp.fk_type']['checked'])) if (!empty($arrayfields['cp.fk_type']['checked'])) {
{
print '<td class="liste_titre">'; print '<td class="liste_titre">';
if (empty($mysoc->country_id)) { if (empty($mysoc->country_id)) {
setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"), $langs->trans("CompanyFoundation")), 'errors'); setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"), $langs->trans("CompanyFoundation")), 'errors');
} else { } else {
$typeleaves = $holidaystatic->getTypes(1, -1); $typeleaves = $holidaystatic->getTypes(1, -1);
$arraytypeleaves = array(); $arraytypeleaves = array();
foreach ($typeleaves as $key => $val) foreach ($typeleaves as $key => $val) {
{
$labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
//$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':''); //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
$arraytypeleaves[$val['rowid']] = $labeltoshow; $arraytypeleaves[$val['rowid']] = $labeltoshow;
@ -545,14 +607,12 @@ if ($resql)
} }
// Duration // Duration
if (!empty($arrayfields['duration']['checked'])) if (!empty($arrayfields['duration']['checked'])) {
{
print '<td class="liste_titre">&nbsp;</td>'; print '<td class="liste_titre">&nbsp;</td>';
} }
// Start date // Start date
if (!empty($arrayfields['cp.date_debut']['checked'])) if (!empty($arrayfields['cp.date_debut']['checked'])) {
{
print '<td class="liste_titre center nowraponall">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle maxwidth25" type="text" 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);
@ -560,8 +620,7 @@ if ($resql)
} }
// End date // End date
if (!empty($arrayfields['cp.date_fin']['checked'])) if (!empty($arrayfields['cp.date_fin']['checked'])) {
{
print '<td class="liste_titre center nowraponall">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle maxwidth25" type="text" 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);
@ -576,8 +635,7 @@ if ($resql)
print $hookmanager->resPrint; 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 nowraponall">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle maxwidth25" type="text" 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);
@ -585,8 +643,7 @@ if ($resql)
} }
// Create date // Create date
if (!empty($arrayfields['cp.tms']['checked'])) if (!empty($arrayfields['cp.tms']['checked'])) {
{
print '<td class="liste_titre center nowraponall">'; print '<td class="liste_titre center nowraponall">';
print '<input class="flat valignmiddle maxwidth25" type="text" 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);
@ -594,8 +651,7 @@ if ($resql)
} }
// Status // Status
if (!empty($arrayfields['cp.statut']['checked'])) if (!empty($arrayfields['cp.statut']['checked'])) {
{
print '<td class="liste_titre maxwidthonsmartphone maxwidth200 right">'; print '<td class="liste_titre maxwidthonsmartphone maxwidth200 right">';
$object->selectStatutCP($search_status, 'search_status'); $object->selectStatutCP($search_status, 'search_status');
print '</td>'; print '</td>';
@ -610,22 +666,42 @@ if ($resql)
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
if (!empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cp.ref']['checked'])) {
if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], "cp.fk_user", "", $param, '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['cp.fk_validator']['checked'])) print_liste_field_titre($arrayfields['cp.fk_validator']['label'], $_SERVER["PHP_SELF"], "cp.fk_validator", "", $param, '', $sortfield, $sortorder); }
if (!empty($arrayfields['cp.fk_type']['checked'])) print_liste_field_titre($arrayfields['cp.fk_type']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cp.fk_user']['checked'])) {
if (!empty($arrayfields['duration']['checked'])) print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right maxwidth100'); print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], "cp.fk_user", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], "cp.date_debut", "", $param, '', $sortfield, $sortorder, 'center '); }
if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], "cp.date_fin", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['cp.fk_validator']['checked'])) {
print_liste_field_titre($arrayfields['cp.fk_validator']['label'], $_SERVER["PHP_SELF"], "cp.fk_validator", "", $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cp.fk_type']['checked'])) {
print_liste_field_titre($arrayfields['cp.fk_type']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['duration']['checked'])) {
print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right maxwidth100');
}
if (!empty($arrayfields['cp.date_debut']['checked'])) {
print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], "cp.date_debut", "", $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['cp.date_fin']['checked'])) {
print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], "cp.date_fin", "", $param, '', $sortfield, $sortorder, 'center ');
}
// Extra fields // Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields // Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
if (!empty($arrayfields['cp.date_create']['checked'])) print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['cp.date_create']['checked'])) {
if (!empty($arrayfields['cp.tms']['checked'])) print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['cp.statut']['checked'])) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right '); }
if (!empty($arrayfields['cp.tms']['checked'])) {
print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['cp.statut']['checked'])) {
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right ');
}
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
@ -637,8 +713,7 @@ if ($resql)
$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 ($num > 0 && !empty($mysoc->country_id)) } elseif ($num > 0 && !empty($mysoc->country_id)) {
{
// Lines // Lines
$userstatic = new User($db); $userstatic = new User($db);
$approbatorstatic = new User($db); $approbatorstatic = new User($db);
@ -647,8 +722,7 @@ if ($resql)
$i = 0; $i = 0;
$totalarray = array(); $totalarray = array();
while ($i < min($num, $limit)) while ($i < min($num, $limit)) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
// Leave request // Leave request
@ -684,54 +758,61 @@ if ($resql)
print '<tr class="oddeven">'; print '<tr class="oddeven">';
if (!empty($arrayfields['cp.ref']['checked'])) if (!empty($arrayfields['cp.ref']['checked'])) {
{
print '<td class="nowraponall">'; 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']++;
}
} }
if (!empty($arrayfields['cp.fk_user']['checked'])) if (!empty($arrayfields['cp.fk_user']['checked'])) {
{
print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1, 'leave').'</td>'; print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
if (!empty($arrayfields['cp.fk_validator']['checked'])) if (!empty($arrayfields['cp.fk_validator']['checked'])) {
{
print '<td class="tdoverflowmax150">'.$approbatorstatic->getNomUrl(-1).'</td>'; print '<td class="tdoverflowmax150">'.$approbatorstatic->getNomUrl(-1).'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
if (!empty($arrayfields['cp.fk_type']['checked'])) if (!empty($arrayfields['cp.fk_type']['checked'])) {
{
print '<td>'; print '<td>';
$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']); $labeltypeleavetoshow = ($langs->trans($typeleaves[$obj->fk_type]['code']) != $typeleaves[$obj->fk_type]['code'] ? $langs->trans($typeleaves[$obj->fk_type]['code']) : $typeleaves[$obj->fk_type]['label']);
print empty($typeleaves[$obj->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $obj->fk_type) : $labeltypeleavetoshow; print 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($db->jdate($obj->date_debut, 1), $db->jdate($obj->date_fin, 1), 0, 1, $obj->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']++;
}
} }
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($db->jdate($obj->date_debut), 'day'); print dol_print_date($db->jdate($obj->date_debut), 'day');
print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$starthalfday]).')</span>'; print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
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($db->jdate($obj->date_fin), 'day'); print dol_print_date($db->jdate($obj->date_fin), 'day');
print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$endhalfday]).')</span>'; print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Extra fields // Extra fields
@ -742,32 +823,38 @@ if ($resql)
print $hookmanager->resPrint; print $hookmanager->resPrint;
// 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, 'dayhour').'</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, 'dayhour').'</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->getLibStatut(5).'</td>'; print '<td class="right nowrap">'.$holidaystatic->getLibStatut(5).'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Action column // Action column
print '<td class="nowrap center">'; print '<td class="nowrap center">';
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($obj->rowid, $arrayofselected)) $selected = 1; if (in_array($obj->rowid, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->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']++;
}
print '</tr>'."\n"; print '</tr>'."\n";
@ -776,10 +863,13 @@ if ($resql)
} }
// Si il n'y a pas d'enregistrement suite à une recherche // Si il n'y a pas d'enregistrement suite à une recherche
if ($num == 0) if ($num == 0) {
{
$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>';
} }
@ -815,8 +905,7 @@ function showMyBalance($holiday, $user_id)
$out = ''; $out = '';
$nb_holiday = 0; $nb_holiday = 0;
$typeleaves = $holiday->getTypes(1, 1); $typeleaves = $holiday->getTypes(1, 1);
foreach ($typeleaves as $key => $val) foreach ($typeleaves as $key => $val) {
{
$nb_type = $holiday->getCPforUser($user_id, $val['rowid']); $nb_type = $holiday->getCPforUser($user_id, $val['rowid']);
$nb_holiday += $nb_type; $nb_holiday += $nb_type;
$out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>'; $out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';

View File

@ -36,9 +36,8 @@ $langs->loadLangs(array("holiday"));
// Security check // Security check
$socid = 0; $socid = 0;
if ($user->socid > 0) // Protection if external user if ($user->socid > 0) { // Protection if external user
{ //$socid = $user->socid;
//$socid = $user->socid;
accessforbidden(); accessforbidden();
} }
$result = restrictedArea($user, 'holiday', $id, ''); $result = restrictedArea($user, 'holiday', $id, '');
@ -57,8 +56,12 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
if (!$sortfield) $sortfield = "cp.rowid"; if (!$sortfield) {
if (!$sortorder) $sortorder = "ASC"; $sortfield = "cp.rowid";
}
if (!$sortorder) {
$sortorder = "ASC";
}
$hookmanager->initHooks(array('leavemovementlist')); $hookmanager->initHooks(array('leavemovementlist'));
@ -69,21 +72,25 @@ $arrayofmassactions = array();
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Selection of new fields // Selection of new fields
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')) // All tests are required 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_employee = ''; $search_employee = '';
$search_type = ''; $search_type = '';
@ -97,8 +104,7 @@ if (empty($reshook))
|| GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search_x', 'alpha')
|| GETPOST('button_search.x', 'alpha') || GETPOST('button_search.x', 'alpha')
|| GETPOST('button_search', 'alpha')) || GETPOST('button_search', 'alpha')) {
{
$massaction = ''; $massaction = '';
} }
} }
@ -141,16 +147,23 @@ $sql .= " WHERE cp.rowid > 0";
$sql .= " AND cp.statut = 3"; // 3 = Approved $sql .= " AND cp.statut = 3"; // 3 = Approved
$sql .= " AND (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')"; $sql .= " AND (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')";
if (!empty($search_ref)) $sql .= natural_search('cp.ref', $search_ref); if (!empty($search_ref)) {
if (!empty($search_employee)) $sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'"; $sql .= natural_search('cp.ref', $search_ref);
if (!empty($search_type)) $sql .= ' AND cp.fk_type IN ('.$db->escape($search_type).')'; }
if (!empty($search_description)) $sql .= natural_search('cp.description', $search_description); if (!empty($search_employee)) {
$sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'";
}
if (!empty($search_type)) {
$sql .= ' AND cp.fk_type IN ('.$db->escape($search_type).')';
}
if (!empty($search_description)) {
$sql .= natural_search('cp.description', $search_description);
}
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$resql = $db->query($sql); $resql = $db->query($sql);
if (empty($resql)) if (empty($resql)) {
{
dol_print_error($db); dol_print_error($db);
exit; exit;
} }
@ -158,15 +171,29 @@ if (empty($resql))
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); $param .= '&contextpage='.urlencode($contextpage);
if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref); }
if (!empty($search_employee)) $param .= '&search_employee='.urlencode($search_employee); if ($limit > 0 && $limit != $conf->liste_limit) {
if (!empty($search_type)) $param .= '&search_type='.urlencode($search_type); $param .= '&limit='.urlencode($limit);
if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); }
if (!empty($search_ref)) {
$param .= '&search_ref='.urlencode($search_ref);
}
if (!empty($search_employee)) {
$param .= '&search_employee='.urlencode($search_employee);
}
if (!empty($search_type)) {
$param .= '&search_type='.urlencode($search_type);
}
if (!empty($search_description)) {
$param .= '&search_description='.urlencode($search_description);
}
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
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="'.newToken().'">'; print '<input type="hidden" name="token" value="'.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="list">';
@ -215,8 +242,7 @@ if (!empty($arrayfields['cp.fk_user']['checked'])) {
if (!empty($arrayfields['ct.label']['checked'])) { if (!empty($arrayfields['ct.label']['checked'])) {
$typeleaves = $holidaystatic->getTypes(1, -1); $typeleaves = $holidaystatic->getTypes(1, -1);
$arraytypeleaves = array(); $arraytypeleaves = array();
foreach ($typeleaves as $key => $val) foreach ($typeleaves as $key => $val) {
{
$labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']); $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
$arraytypeleaves[$val['rowid']] = $labeltoshow; $arraytypeleaves[$val['rowid']] = $labeltoshow;
} }
@ -226,12 +252,24 @@ if (!empty($arrayfields['ct.label']['checked'])) {
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['cp.date_debut']['checked'])) print '<td class="liste_titre"></td>'; if (!empty($arrayfields['cp.date_debut']['checked'])) {
if (!empty($arrayfields['cp.date_fin']['checked'])) print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
if (!empty($arrayfields['used_days']['checked'])) print '<td class="liste_titre"></td>'; }
if (!empty($arrayfields['date_start_month']['checked'])) print '<td class="liste_titre"></td>'; if (!empty($arrayfields['cp.date_fin']['checked'])) {
if (!empty($arrayfields['date_end_month']['checked'])) print '<td class="liste_titre"></td>'; print '<td class="liste_titre"></td>';
if (!empty($arrayfields['used_days_month']['checked'])) print '<td class="liste_titre"></td>'; }
if (!empty($arrayfields['used_days']['checked'])) {
print '<td class="liste_titre"></td>';
}
if (!empty($arrayfields['date_start_month']['checked'])) {
print '<td class="liste_titre"></td>';
}
if (!empty($arrayfields['date_end_month']['checked'])) {
print '<td class="liste_titre"></td>';
}
if (!empty($arrayfields['used_days_month']['checked'])) {
print '<td class="liste_titre"></td>';
}
// Filter: Description // Filter: Description
if (!empty($arrayfields['cp.description']['checked'])) { if (!empty($arrayfields['cp.description']['checked'])) {
@ -248,26 +286,43 @@ print '</td>';
print '</tr>'; print '</tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
if (!empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], 'cp.ref', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['cp.ref']['checked'])) {
if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], 'cp.fk_user', '', '', '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], 'cp.ref', '', '', '', $sortfield, $sortorder);
if (!empty($arrayfields['ct.label']['checked'])) print_liste_field_titre($arrayfields['ct.label']['label'], $_SERVER["PHP_SELF"], 'ct.label', '', '', '', $sortfield, $sortorder); }
if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], 'cp.date_debut', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['cp.fk_user']['checked'])) {
if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], 'cp.date_fin', '', '', '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], 'cp.fk_user', '', '', '', $sortfield, $sortorder);
if (!empty($arrayfields['used_days']['checked'])) print_liste_field_titre($arrayfields['used_days']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); }
if (!empty($arrayfields['date_start_month']['checked'])) print_liste_field_titre($arrayfields['date_start_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['ct.label']['checked'])) {
if (!empty($arrayfields['date_end_month']['checked'])) print_liste_field_titre($arrayfields['date_end_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['ct.label']['label'], $_SERVER["PHP_SELF"], 'ct.label', '', '', '', $sortfield, $sortorder);
if (!empty($arrayfields['used_days_month']['checked'])) print_liste_field_titre($arrayfields['used_days_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder); }
if (!empty($arrayfields['cp.description']['checked'])) print_liste_field_titre($arrayfields['cp.description']['label'], $_SERVER["PHP_SELF"], 'cp.description', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['cp.date_debut']['checked'])) {
print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], 'cp.date_debut', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cp.date_fin']['checked'])) {
print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], 'cp.date_fin', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['used_days']['checked'])) {
print_liste_field_titre($arrayfields['used_days']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['date_start_month']['checked'])) {
print_liste_field_titre($arrayfields['date_start_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['date_end_month']['checked'])) {
print_liste_field_titre($arrayfields['date_end_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['used_days_month']['checked'])) {
print_liste_field_titre($arrayfields['used_days_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cp.description']['checked'])) {
print_liste_field_titre($arrayfields['cp.description']['label'], $_SERVER["PHP_SELF"], 'cp.description', '', '', '', $sortfield, $sortorder);
}
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n"; print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
print '</tr>'; print '</tr>';
if ($num == 0) if ($num == 0) {
{
print '<tr><td colspan="10" class="opacitymedium">'.$langs->trans('None').'</td></tr>'; print '<tr><td colspan="10" class="opacitymedium">'.$langs->trans('None').'</td></tr>';
} } else {
else { while ($obj = $db->fetch_object($resql)) {
while ($obj = $db->fetch_object($resql))
{
$user = new User($db); $user = new User($db);
$user->fetch($obj->fk_user); $user->fetch($obj->fk_user);
@ -289,19 +344,25 @@ else {
// Set date_start_gmt and date_end_gmt that are date to show for the selected month // Set date_start_gmt and date_end_gmt that are date to show for the selected month
$date_start_inmonth = $db->jdate($obj->date_debut, true); $date_start_inmonth = $db->jdate($obj->date_debut, true);
$date_end_inmonth = $db->jdate($obj->date_fin, true); $date_end_inmonth = $db->jdate($obj->date_fin, true);
if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month) if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month) {
{
$date_start_inmonth = dol_get_first_day($search_year, $search_month, true); $date_start_inmonth = dol_get_first_day($search_year, $search_month, true);
$starthalfdayinmonth = 'morning'; $starthalfdayinmonth = 'morning';
if ($halfdayinmonth == 2) $halfdayinmonth = 1; if ($halfdayinmonth == 2) {
if ($halfdayinmonth == -1) $halfdayinmonth = 0; $halfdayinmonth = 1;
}
if ($halfdayinmonth == -1) {
$halfdayinmonth = 0;
}
} }
if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month) if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month) {
{
$date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1); $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1);
$endhalfdayinmonth = 'afternoon'; $endhalfdayinmonth = 'afternoon';
if ($halfdayinmonth == 2) $halfdayinmonth = -1; if ($halfdayinmonth == 2) {
if ($halfdayinmonth == 1) $halfdayinmonth = 0; $halfdayinmonth = -1;
}
if ($halfdayinmonth == 1) {
$halfdayinmonth = 0;
}
} }
// Leave request // Leave request
@ -310,42 +371,50 @@ else {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
if (!empty($arrayfields['cp.ref']['checked'])) print '<td>'.$holidaystatic->getNomUrl(1, 1).'</td>'; if (!empty($arrayfields['cp.ref']['checked'])) {
if (!empty($arrayfields['cp.fk_user']['checked'])) print '<td>'.$user->getFullName($langs).'</td>'; print '<td>'.$holidaystatic->getNomUrl(1, 1).'</td>';
if (!empty($arrayfields['ct.label']['checked'])) print '<td>'.$obj->label.'</td>'; }
if (!empty($arrayfields['cp.fk_user']['checked'])) {
print '<td>'.$user->getFullName($langs).'</td>';
}
if (!empty($arrayfields['ct.label']['checked'])) {
print '<td>'.$obj->label.'</td>';
}
if (!empty($arrayfields['cp.date_debut']['checked'])) if (!empty($arrayfields['cp.date_debut']['checked'])) {
{
print '<td class="center">'.dol_print_date($db->jdate($obj->date_debut), 'day'); print '<td class="center">'.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 (!empty($arrayfields['cp.date_fin']['checked'])) if (!empty($arrayfields['cp.date_fin']['checked'])) {
{
print '<td class="center">'.dol_print_date($db->jdate($obj->date_fin), 'day'); print '<td class="center">'.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 (!empty($arrayfields['used_days']['checked'])) print '<td class="right">'.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).'</td>'; if (!empty($arrayfields['used_days']['checked'])) {
print '<td class="right">'.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).'</td>';
}
if (!empty($arrayfields['date_start_month']['checked'])) if (!empty($arrayfields['date_start_month']['checked'])) {
{
print '<td class="center">'.dol_print_date($date_start_inmonth, 'day'); print '<td class="center">'.dol_print_date($date_start_inmonth, 'day');
print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfdayinmonth]).')</span>'; print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfdayinmonth]).')</span>';
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['date_end_month']['checked'])) if (!empty($arrayfields['date_end_month']['checked'])) {
{
print '<td class="center">'.dol_print_date($date_end_inmonth, 'day'); print '<td class="center">'.dol_print_date($date_end_inmonth, 'day');
print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfdayinmonth]).')</span>'; print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfdayinmonth]).')</span>';
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['used_days_month']['checked'])) print '<td class="right">'.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).'</td>'; if (!empty($arrayfields['used_days_month']['checked'])) {
if (!empty($arrayfields['cp.description']['checked'])) print '<td class="maxwidth300">'.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'</td>'; print '<td class="right">'.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).'</td>';
}
if (!empty($arrayfields['cp.description']['checked'])) {
print '<td class="maxwidth300">'.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'</td>';
}
print '<td></td>'; print '<td></td>';
print '</tr>'; print '</tr>';

View File

@ -61,15 +61,23 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortfield) $sortfield = "cpl.rowid"; if (!$sortfield) {
if (!$sortorder) $sortorder = "DESC"; $sortfield = "cpl.rowid";
}
if (!$sortorder) {
$sortorder = "DESC";
}
// Si l'utilisateur n'a pas le droit de lire cette page // Si l'utilisateur n'a pas le droit de lire cette page
if (!$user->rights->holiday->readall) accessforbidden(); if (!$user->rights->holiday->readall) {
accessforbidden();
}
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('users', 'other', 'holiday')); $langs->loadLangs(array('users', 'other', 'holiday'));
@ -83,8 +91,7 @@ $hookmanager->initHooks(array('leavemovementlist')); // Note that conf->hooks_mo
$arrayfields = array(); $arrayfields = array();
$arrayofmassactions = array(); $arrayofmassactions = array();
if (empty($conf->holiday->enabled)) if (empty($conf->holiday->enabled)) {
{
llxHeader('', $langs->trans('CPTitreMenu')); llxHeader('', $langs->trans('CPTitreMenu'));
print '<div class="tabBar">'; print '<div class="tabBar">';
print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>'; print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>';
@ -98,12 +105,18 @@ if (empty($conf->holiday->enabled))
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) { if (empty($reshook)) {
// Selection of new fields // Selection of new fields
@ -129,8 +142,7 @@ if (empty($reshook)) {
|| GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search_x', 'alpha')
|| GETPOST('button_search.x', 'alpha') || GETPOST('button_search.x', 'alpha')
|| GETPOST('button_search', 'alpha')) || GETPOST('button_search', 'alpha')) {
{
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
} }
@ -184,13 +196,27 @@ if (!empty($search_year) && $search_year > 0) {
$sqlwhere .= "AND date_action BETWEEN '".$db->idate($from_date)."' AND '".$db->idate($to_date)."'"; $sqlwhere .= "AND date_action BETWEEN '".$db->idate($from_date)."' AND '".$db->idate($to_date)."'";
} }
if (!empty($search_id) && $search_id > 0) $sqlwhere .= natural_search('rowid', $search_id, 1); if (!empty($search_id) && $search_id > 0) {
if (!empty($search_validator) && $search_validator > 0) $sqlwhere .= natural_search('fk_user_action', $search_validator, 1); $sqlwhere .= natural_search('rowid', $search_id, 1);
if (!empty($search_employee) && $search_employee > 0) $sqlwhere .= natural_search('fk_user_update', $search_employee, 1); }
if (!empty($search_description)) $sqlwhere .= natural_search('type_action', $search_description); if (!empty($search_validator) && $search_validator > 0) {
if (!empty($search_type) && $search_type > 0) $sqlwhere .= natural_search('fk_type', $search_type, 1); $sqlwhere .= natural_search('fk_user_action', $search_validator, 1);
if (!empty($search_prev_solde)) $sqlwhere .= natural_search('prev_solde', $search_prev_solde, 1); }
if (!empty($search_new_solde)) $sqlwhere .= natural_search('new_solde', $search_new_solde, 1); if (!empty($search_employee) && $search_employee > 0) {
$sqlwhere .= natural_search('fk_user_update', $search_employee, 1);
}
if (!empty($search_description)) {
$sqlwhere .= natural_search('type_action', $search_description);
}
if (!empty($search_type) && $search_type > 0) {
$sqlwhere .= natural_search('fk_type', $search_type, 1);
}
if (!empty($search_prev_solde)) {
$sqlwhere .= natural_search('prev_solde', $search_prev_solde, 1);
}
if (!empty($search_new_solde)) {
$sqlwhere .= natural_search('new_solde', $search_new_solde, 1);
}
$sqlorder = $db->order($sortfield, $sortorder); $sqlorder = $db->order($sortfield, $sortorder);
@ -214,20 +240,44 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$num = is_array($object->logs) ? count($object->logs) : 0; $num = is_array($object->logs) ? count($object->logs) : 0;
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); $param .= '&contextpage='.urlencode($contextpage);
if (!empty($search_id)) $param .= '&search_statut='.urlencode($search_statut); }
if (!empty($search_month) && $search_month > 0) $param .= '&search_month='.urlencode($search_month); if ($limit > 0 && $limit != $conf->liste_limit) {
if (!empty($search_year) && $search_year > 0) $param .= '&search_year='.urlencode($search_year); $param .= '&limit='.urlencode($limit);
if (!empty($search_validator) && $search_validator > 0) $param .= '&search_validator='.urlencode($search_validator); }
if (!empty($search_employee) && $search_employee > 0) $param .= '&search_employee='.urlencode($search_employee); if (!empty($search_id)) {
if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); $param .= '&search_statut='.urlencode($search_statut);
if (!empty($search_type) && $search_type > 0) $param .= '&search_type='.urlencode($search_type); }
if (!empty($search_prev_solde)) $param .= '&search_prev_solde='.urlencode($search_prev_solde); if (!empty($search_month) && $search_month > 0) {
if (!empty($search_new_solde)) $param .= '&search_new_solde='.urlencode($search_new_solde); $param .= '&search_month='.urlencode($search_month);
}
if (!empty($search_year) && $search_year > 0) {
$param .= '&search_year='.urlencode($search_year);
}
if (!empty($search_validator) && $search_validator > 0) {
$param .= '&search_validator='.urlencode($search_validator);
}
if (!empty($search_employee) && $search_employee > 0) {
$param .= '&search_employee='.urlencode($search_employee);
}
if (!empty($search_description)) {
$param .= '&search_description='.urlencode($search_description);
}
if (!empty($search_type) && $search_type > 0) {
$param .= '&search_type='.urlencode($search_type);
}
if (!empty($search_prev_solde)) {
$param .= '&search_prev_solde='.urlencode($search_prev_solde);
}
if (!empty($search_new_solde)) {
$param .= '&search_new_solde='.urlencode($search_new_solde);
}
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
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="'.newToken().'">'; print '<input type="hidden" name="token" value="'.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="list">';
@ -348,23 +398,40 @@ print '</td>';
print '</tr>'; print '</tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
if (!empty($arrayfields['cpl.rowid']['checked'])) print_liste_field_titre($arrayfields['cpl.rowid']['label'], $_SERVER["PHP_SELF"], 'rowid', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['cpl.rowid']['checked'])) {
if (!empty($arrayfields['cpl.date_action']['checked'])) print_liste_field_titre($arrayfields['cpl.date_action']['label'], $_SERVER["PHP_SELF"], 'date_action', '', '', '', $sortfield, $sortorder, 'center '); print_liste_field_titre($arrayfields['cpl.rowid']['label'], $_SERVER["PHP_SELF"], 'rowid', '', '', '', $sortfield, $sortorder);
if (!empty($arrayfields['cpl.fk_user_action']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_user_action']['label'], $_SERVER["PHP_SELF"], 'fk_user_action', '', '', '', $sortfield, $sortorder); }
if (!empty($arrayfields['cpl.fk_user_update']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_user_update']['label'], $_SERVER["PHP_SELF"], 'fk_user_update', '', '', '', $sortfield, $sortorder); if (!empty($arrayfields['cpl.date_action']['checked'])) {
if (!empty($arrayfields['cpl.type_action']['checked'])) print_liste_field_titre($arrayfields['cpl.type_action']['label'], $_SERVER["PHP_SELF"], 'type_action', '', '', '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['cpl.date_action']['label'], $_SERVER["PHP_SELF"], 'date_action', '', '', '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['cpl.fk_type']['checked'])) print_liste_field_titre($arrayfields['cpl.fk_type']['label'], $_SERVER["PHP_SELF"], 'fk_type', '', '', '', $sortfield, $sortorder); }
if (!empty($arrayfields['cpl.prev_solde']['checked'])) print_liste_field_titre($arrayfields['cpl.prev_solde']['label'], $_SERVER["PHP_SELF"], 'prev_solde', '', '', '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['cpl.fk_user_action']['checked'])) {
if (!empty($arrayfields['variation']['checked'])) print_liste_field_titre($arrayfields['variation']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre($arrayfields['cpl.fk_user_action']['label'], $_SERVER["PHP_SELF"], 'fk_user_action', '', '', '', $sortfield, $sortorder);
if (!empty($arrayfields['cpl.new_solde']['checked'])) print_liste_field_titre($arrayfields['cpl.new_solde']['label'], $_SERVER["PHP_SELF"], 'new_solde', '', '', '', $sortfield, $sortorder, 'right '); }
if (!empty($arrayfields['cpl.fk_user_update']['checked'])) {
print_liste_field_titre($arrayfields['cpl.fk_user_update']['label'], $_SERVER["PHP_SELF"], 'fk_user_update', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cpl.type_action']['checked'])) {
print_liste_field_titre($arrayfields['cpl.type_action']['label'], $_SERVER["PHP_SELF"], 'type_action', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cpl.fk_type']['checked'])) {
print_liste_field_titre($arrayfields['cpl.fk_type']['label'], $_SERVER["PHP_SELF"], 'fk_type', '', '', '', $sortfield, $sortorder);
}
if (!empty($arrayfields['cpl.prev_solde']['checked'])) {
print_liste_field_titre($arrayfields['cpl.prev_solde']['label'], $_SERVER["PHP_SELF"], 'prev_solde', '', '', '', $sortfield, $sortorder, 'right ');
}
if (!empty($arrayfields['variation']['checked'])) {
print_liste_field_titre($arrayfields['variation']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'right ');
}
if (!empty($arrayfields['cpl.new_solde']['checked'])) {
print_liste_field_titre($arrayfields['cpl.new_solde']['label'], $_SERVER["PHP_SELF"], 'new_solde', '', '', '', $sortfield, $sortorder, 'right ');
}
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
print '</tr>'; print '</tr>';
// TODO: $i = 0; // TODO: $i = 0;
$i = 1; $i = 1;
while ($i < min($num, $limit)) while ($i < min($num, $limit)) {
{
//TODO: $obj = $db->fetch_object($resql); //TODO: $obj = $db->fetch_object($resql);
$obj = next($object->logs); $obj = next($object->logs);