From 7fd6d8839a4ffad778426dcc4afa5a5ba6189db4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Oct 2015 01:40:46 +0200 Subject: [PATCH] Uniformize code and use a new generic search architecture --- htdocs/comm/index.php | 2 +- htdocs/compta/hrm.php | 51 ++++++++++++++++++----------------- htdocs/compta/index.php | 2 +- htdocs/core/search.php | 17 ++++++++++-- htdocs/expensereport/list.php | 24 +++++++++++++++++ htdocs/holiday/list.php | 27 ++++++++++++++++++- htdocs/langs/en_US/boxes.lang | 2 +- htdocs/product/index.php | 2 +- htdocs/societe/index.php | 2 +- 9 files changed, 97 insertions(+), 32 deletions(-) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 534b7af4572..18991f66bba 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -108,7 +108,7 @@ if (count($listofsearchfields)) { if ($i == 0) print ''.$langs->trans("Search").''; print ''; - print ':'; + print ':'; if ($i == 0) print ''; print ''; $i++; diff --git a/htdocs/compta/hrm.php b/htdocs/compta/hrm.php index 12b410e29af..4122f850723 100644 --- a/htdocs/compta/hrm.php +++ b/htdocs/compta/hrm.php @@ -71,37 +71,40 @@ print load_fiche_titre($langs->trans("HRMArea"),'', 'title_hrm.png'); print '
'; -/* - * Search expenses - */ + +if (! empty($conf->holiday->enabled) && $user->rights->holiday->read) +{ + $langs->load("holiday"); + $listofsearchfields['search_holiday']=array('text'=>'TitreRequestCP'); +} if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire) { $langs->load("trips"); - print '
'; - print ''; - print ''; - print ''; - print ""; - print "'; - print ''; - //print "'; - print ''; - print "
'.$langs->trans("SearchATripAndExpense").'
:
:

"; + $listofsearchfields['search_deplacement']=array('text'=>'ExpenseReport'); } - if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) { $langs->load("trips"); - print '
'; - print ''; - print ''; - print ''; - print ""; - print "'; - print ''; - //print "'; - print ''; - print "
'.$langs->trans("SearchATripAndExpense").'
:
:

"; + $listofsearchfields['search_expensereport']=array('text'=>'ExpenseReport'); +} +if (count($listofsearchfields)) +{ + print '
'; + print ''; + print ''; + $i=0; + foreach($listofsearchfields as $key => $value) + { + if ($i == 0) print ''; + print ''; + print ''; + if ($i == 0) print ''; + print ''; + $i++; + } + print '
'.$langs->trans("Search").'
:
'; + print '
'; + print '
'; } diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 076b6a9b209..fea0708e2a8 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -116,7 +116,7 @@ if (count($listofsearchfields)) { if ($i == 0) print ''.$langs->trans("Search").''; print ''; - print ':'; + print ':'; if ($i == 0) print ''; print ''; $i++; diff --git a/htdocs/core/search.php b/htdocs/core/search.php index 5413ae0d162..a0b6146caf6 100644 --- a/htdocs/core/search.php +++ b/htdocs/core/search.php @@ -94,9 +94,22 @@ if (GETPOST('search_contact') != '') header("Location: ".DOL_URL_ROOT.'/contact/list.php?mode=search&sall='.urlencode(GETPOST('search_contact'))); exit; } +if (GETPOST('search_deplacement') != '') +{ + header("Location: ".DOL_URL_ROOT.'/compta/deplacement/list.php?mode=search&sall='.urlencode(GETPOST('search_deplacement'))); + exit; +} +if (GETPOST('search_expensereport') != '') +{ + header("Location: ".DOL_URL_ROOT.'/expensereport/list.php?mode=search&sall='.urlencode(GETPOST('search_expensereport'))); + exit; +} +if (GETPOST('search_holiday') != '') +{ + header("Location: ".DOL_URL_ROOT.'/holiday/list.php?mode=search&sall='.urlencode(GETPOST('search_holiday'))); + exit; +} - - // If we are here, search was called with no supported criteria if (! empty($_SERVER['HTTP_REFERER'])) diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index ba3b652a3a9..4a12d25f8f2 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -39,6 +39,7 @@ $socid = $_GET["socid"]?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'expensereport','',''); +$sall = GETPOST('sall'); $search_ref = GETPOST('search_ref'); $search_user = GETPOST('search_user','int'); $search_amount_ht = GETPOST('search_amount_ht','alpha'); @@ -66,6 +67,14 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both if ($search_status == '') $search_status=-1; if ($search_user == '') $search_user=-1; +// List of fields to search into when doing a "search in all" +$fieldstosearchall = array( + 'd.ref'=>'Ref', + 'u.lastname'=>'Lastname', + 'u.firstname'=>"Firstname", +); + + /* * View */ @@ -101,6 +110,11 @@ $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid"; $sql.= " WHERE d.entity = ".$conf->entity; +// Search all +if (!empty($sall)) +{ + $sql.= natural_search(array_keys($fieldstosearchall), $sall); +} // Ref if(!empty($search_ref)){ $sql.= " AND d.ref LIKE '%".$db->escape($search_ref)."%'"; @@ -183,6 +197,16 @@ if ($resql) print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); print '
'."\n"; if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + + if ($sall) + { + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print $langs->trans("FilterOnInto", $sall, join(', ',$fieldstosearchall)); + } print ''; print ""; diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 419fabf9087..b309eade0f4 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -53,6 +53,7 @@ $pagenext = $page + 1; $id = GETPOST('id','int'); +$sall = GETPOST('sall'); $search_ref = GETPOST('search_ref'); $month_create = GETPOST('month_create'); $year_create = GETPOST('year_create'); @@ -64,7 +65,7 @@ $search_employe = GETPOST('search_employe'); $search_valideur = GETPOST('search_valideur'); $search_statut = GETPOST('select_statut'); -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { $search_ref=""; $month_create=""; @@ -78,6 +79,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $search_statut=""; } +// List of fields to search into when doing a "search in all" +$fieldstosearchall = array( + 'cp.rowid'=>'Ref', + 'cp.description'=>'Description', +); + /* * Actions @@ -171,6 +178,12 @@ if(!empty($search_valideur) && $search_valideur != -1) { if(!empty($search_statut) && $search_statut != -1) { $filter.= " AND cp.statut = '".$db->escape($search_statut)."'\n"; } +// Search all +if (!empty($sall)) +{ + $filter.= natural_search(array_keys($fieldstosearchall), $sall); +} + /************************************* * Fin des filtres de recherche @@ -252,6 +265,18 @@ if ($id > 0) print '
'; print ''."\n"; +if ($optioncss != '') print ''; +print ''; +print ''; +print ''; +print ''; + +if ($sall) +{ + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print $langs->trans("FilterOnInto", $sall, join(', ',$fieldstosearchall)); +} + print '
'; print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cp.rowid","",'','',$sortfield,$sortorder); diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index b61cf77019f..634b058f6d4 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -58,7 +58,7 @@ BoxLastExpiredServices=Last %s oldest contacts with active expired services BoxTitleLastActionsToDo=Last %s actions to do BoxTitleLastContracts=Last %s contracts BoxTitleLastModifiedDonations=Last %s modified donations -BoxTitleLastModifiedExpenses=Last %s modified expenses +BoxTitleLastModifiedExpenses=Last %s modified expense reports BoxGlobalActivity=Global activity (invoices, proposals, orders) FailedToRefreshDataInfoNotUpToDate=Failed to refresh RSS flux. Last successfull refresh date: %s LastRefreshDate=Last refresh date diff --git a/htdocs/product/index.php b/htdocs/product/index.php index a03fac431d5..a47f4488ea4 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -95,7 +95,7 @@ if (count($listofsearchfields)) { if ($i == 0) print ''; print ''; - print ''; + print ''; if ($i == 0) print ''; print ''; $i++; diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index d7ff0067462..d27d6891119 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -78,7 +78,7 @@ if (count($listofsearchfields)) { if ($i == 0) print ''; print ''; - print ''; + print ''; if ($i == 0) print ''; print ''; $i++;
'.$langs->trans("Search").'
::
'.$langs->trans("Search").'
::