diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 1eda2d0ec4f..a450aaa7d6c 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -873,7 +873,7 @@ class Form
console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
- if (atleastoneselected || ' . $alwaysvisible . ')
+ if (atleastoneselected || ' . ((int) $alwaysvisible) . ')
{
jQuery("."+name).show();
' . ($selected ? 'if (atleastoneselected) { jQuery("."+name+"select").val("' . $selected . '").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' : '') . '
diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php
index 1e4b1407046..10d04ebf202 100644
--- a/htdocs/hrm/class/position.class.php
+++ b/htdocs/hrm/class/position.class.php
@@ -1135,7 +1135,7 @@ class Position extends CommonObject
$return .= '';
$return .= '
';
$return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'';
- $return .= '';
+ $return .= '';
if (!empty($arraydata['user'])) {
$return .= '
'.$arraydata['user'].'';
}
diff --git a/htdocs/hrm/position_list.php b/htdocs/hrm/position_list.php
index fd562ed9858..aa2dce54f9b 100644
--- a/htdocs/hrm/position_list.php
+++ b/htdocs/hrm/position_list.php
@@ -47,7 +47,7 @@ require_once DOL_DOCUMENT_ROOT.'/hrm/class/position.class.php';
// Load translation files required by the page
$langs->loadLangs(array('hrm', 'other'));
-// Get Parameters
+// Get parameters
$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
@@ -66,7 +66,7 @@ $ref = GETPOST('ref', 'alpha');
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
-$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
+$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
// If $page is not defined, or '' or -1 or if we click on clear filters
$page = 0;
@@ -80,7 +80,7 @@ $object = new Position($db);
$extrafields = new ExtraFields($db);
$userstatic = new User($db);
$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
-$hookmanager->initHooks(array('positionlist')); // Note that conf->hooks_modules contains array
+$hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
@@ -98,7 +98,7 @@ if (!$sortorder) {
}
// Initialize array of search criteria
-$search_all = GETPOST('search_all', 'alphanohtml');
+$search_all = trim(GETPOST('search_all', 'alphanohtml'));
$search = array();
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha') !== '') {
@@ -119,12 +119,13 @@ foreach ($object->fields as $key => $val) {
}
// Definition of array of fields for columns
+$tableprefix = 't';
$arrayfields = array();
foreach ($object->fields as $key => $val) {
// If $val['visible']==0, then we never show the field
if (!empty($val['visible'])) {
$visible = (int) dol_eval((string) $val['visible'], 1);
- $arrayfields['t.'.$key] = array(
+ $arrayfields[$tableprefix.'.'.$key] = array(
'label' => $val['label'],
'checked' => (($visible < 0) ? 0 : 1),
'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
@@ -173,7 +174,7 @@ if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massa
$massaction = '';
}
-$parameters = array();
+$parameters = array('arrayfields' => &$arrayfields);
$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');
@@ -192,6 +193,7 @@ if (empty($reshook)) {
$search[$key.'_dtend'] = '';
}
}
+ $search_all = '';
$toselect = array();
$search_array_options = array();
}
@@ -218,9 +220,9 @@ $jobstatic = new Job($db);
$now = dol_now();
+$title = $langs->trans('EmployeePositions');
//$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
$help_url = '';
-$title = $langs->trans('EmployeePositions');
$morejs = array();
$morecss = array();
@@ -236,24 +238,29 @@ $sql .= ', j.rowid as job_id, j.label as job_label';
// Add fields from extrafields
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 : '');
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : "");
}
}
// Add fields from hooks
$parameters = array();
-$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql = preg_replace('/,\s*$/', '', $sql);
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t LEFT JOIN ".MAIN_DB_PREFIX.$userstatic->table_element." as u on t.fk_user = u.rowid, ".MAIN_DB_PREFIX."hrm_job as j";
+
+//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
if (isset($extrafields->attributes[$object->table_element]['label']) && 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 (t.rowid = ef.fk_object)";
}
// Add table from hooks
$parameters = array();
-$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
+$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
if ($object->ismultientitymanaged == 1) {
- $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
+ $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
} else {
$sql .= " WHERE 1 = 1";
}
@@ -270,18 +277,24 @@ foreach ($search as $key => $val) {
}
$mode_search = 2;
}
- if ($search[$key] != '') {
- $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
+ if (empty($object->fields[$key]['searchmulti'])) {
+ if (!is_array($search[$key]) && $search[$key] != '') {
+ $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
+ }
+ } else {
+ if (is_array($search[$key]) && !empty($search[$key])) {
+ $sql .= natural_search("t.".$db->escape($key), implode(',', $search[$key]), (($key == 'status') ? 2 : $mode_search));
+ }
}
} else {
if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
- $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
+ $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
if (preg_match('/_dtstart$/', $key)) {
- $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
+ $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
}
if (preg_match('/_dtend$/', $key)) {
- $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
+ $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
}
}
}
@@ -299,13 +312,13 @@ if ($search_all) {
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
$parameters = array();
-$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
/* If a group by is required
$sql .= " GROUP BY ";
foreach($object->fields as $key => $val) {
- $sql .= "t.".$db->escape($key).", ";
+ $sql .= "t.".$db->sanitize($key).", ";
}
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
@@ -313,9 +326,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
}
}
-// Add where from hooks
+// Add groupby from hooks
$parameters = array();
-$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
+$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql = preg_replace('/,\s*$/', '', $sql);
*/
@@ -323,9 +336,19 @@ $sql = preg_replace('/,\s*$/', '', $sql);
// Count total nb of records
$nbtotalofrecords = '';
if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
- $resql = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($resql);
- if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@@ -348,7 +371,7 @@ $num = $db->num_rows($resql);
// Direct jump if only one record found
-if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
+if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
$obj = $db->fetch_object($resql);
$id = $obj->rowid;
header("Location: ".dol_buildpath('/hrm/position.php', 1).'?id='.$id);
@@ -362,7 +385,7 @@ if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $s
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
// Example : Adding jquery code
-// print '