FIX filter on categories
This commit is contained in:
parent
92d0dff65d
commit
f516a4b052
@ -73,15 +73,15 @@ $massaction = GETPOST('massaction', 'alpha');
|
||||
$show_files = GETPOST('show_files', 'int');
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
$toselect = GETPOST('toselect', 'array');
|
||||
$optioncss = GETPOST('optioncss', 'alpha');
|
||||
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist';
|
||||
|
||||
if ($contextpage == 'poslist') {
|
||||
$_GET['optioncss'] = 'print';
|
||||
$optioncss = 'print';
|
||||
}
|
||||
|
||||
$lineid = GETPOST('lineid', 'int');
|
||||
$userid = GETPOST('userid', 'int');
|
||||
$search_product_category = GETPOST('search_product_category', 'int');
|
||||
$search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
|
||||
$search_refcustomer = GETPOST('search_refcustomer', 'alpha');
|
||||
$search_type = GETPOST('search_type', 'int');
|
||||
@ -137,10 +137,10 @@ $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
|
||||
$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
|
||||
$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
|
||||
$search_categ_cus = GETPOST("search_categ_cus", 'int');
|
||||
$search_product_category = GETPOST('search_product_category', 'int');
|
||||
$search_fac_rec_source_title = GETPOST("search_fac_rec_source_title", 'alpha');
|
||||
$search_btn = GETPOST('button_search', 'alpha');
|
||||
$search_remove_btn = GETPOST('button_removefilter', 'alpha');
|
||||
$optioncss = GETPOST('optioncss', 'alpha');
|
||||
|
||||
$option = GETPOST('search_option');
|
||||
if ($option == 'late') {
|
||||
@ -581,9 +581,6 @@ if (!$sall) {
|
||||
$sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed';
|
||||
}
|
||||
*/
|
||||
if ($search_categ_cus && $search_categ_cus != -1) {
|
||||
$sql .= ", cc.fk_categorie, cc.fk_soc";
|
||||
}
|
||||
// Add fields from extrafields
|
||||
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
||||
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
|
||||
@ -598,10 +595,6 @@ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
|
||||
if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
|
||||
}
|
||||
|
||||
$sql .= ', '.MAIN_DB_PREFIX.'facture as f';
|
||||
if ($sortfield == "f.datef") {
|
||||
$sql .= $db->hintindex('idx_facture_datef');
|
||||
@ -619,10 +612,6 @@ if (!$sall) {
|
||||
if ($sall || $search_product_category > 0) {
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
|
||||
}
|
||||
if ($search_product_category > 0) {
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
|
||||
}
|
||||
|
||||
if (!empty($search_fac_rec_source_title)) {
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source=facrec.rowid';
|
||||
}
|
||||
@ -646,9 +635,6 @@ $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
|
||||
if (empty($user->rights->societe->client->voir) && !$socid) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($search_product_category > 0) {
|
||||
$sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
|
||||
}
|
||||
if ($socid > 0) {
|
||||
$sql .= ' AND s.rowid = '.((int) $socid);
|
||||
}
|
||||
@ -746,12 +732,6 @@ if ($search_multicurrency_montant_ttc != '') {
|
||||
if ($search_login) {
|
||||
$sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
|
||||
}
|
||||
if ($search_categ_cus > 0) {
|
||||
$sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
|
||||
}
|
||||
if ($search_categ_cus == -2) {
|
||||
$sql .= " AND cc.fk_categorie IS NULL";
|
||||
}
|
||||
if ($search_status != '-1' && $search_status != '') {
|
||||
if (is_numeric($search_status) && $search_status >= 0) {
|
||||
if ($search_status == '0') {
|
||||
@ -813,6 +793,58 @@ if ($search_user > 0) {
|
||||
if (!empty($search_fac_rec_source_title)) {
|
||||
$sql .= natural_search('facrec.titre', $search_fac_rec_source_title);
|
||||
}
|
||||
// Search for tag/category ($searchCategoryProductList is an array of ID)
|
||||
$searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
|
||||
$searchCategoryProductOperator = 0;
|
||||
if (!empty($searchCategoryProductList)) {
|
||||
$searchCategoryProductSqlList = array();
|
||||
$listofcategoryid = '';
|
||||
foreach ($searchCategoryProductList as $searchCategoryProduct) {
|
||||
if (intval($searchCategoryProduct) == -2) {
|
||||
$searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)";
|
||||
} elseif (intval($searchCategoryProduct) > 0) {
|
||||
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
|
||||
}
|
||||
}
|
||||
if ($listofcategoryid) {
|
||||
$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
|
||||
}
|
||||
if ($searchCategoryProductOperator == 1) {
|
||||
if (!empty($searchCategoryProductSqlList)) {
|
||||
$sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
|
||||
}
|
||||
} else {
|
||||
if (!empty($searchCategoryProductSqlList)) {
|
||||
$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
|
||||
}
|
||||
}
|
||||
}
|
||||
$searchCategoryCustomerList = $search_categ_cus ? array($search_categ_cus) : array();;
|
||||
$searchCategoryCustomerOperator = 0;
|
||||
// Search for tag/category ($searchCategoryCustomerList is an array of ID)
|
||||
if (!empty($searchCategoryCustomerList)) {
|
||||
$searchCategoryCustomerSqlList = array();
|
||||
$listofcategoryid = '';
|
||||
foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
|
||||
if (intval($searchCategoryCustomer) == -2) {
|
||||
$searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
|
||||
} elseif (intval($searchCategoryCustomer) > 0) {
|
||||
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
|
||||
}
|
||||
}
|
||||
if ($listofcategoryid) {
|
||||
$searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
|
||||
}
|
||||
if ($searchCategoryCustomerOperator == 1) {
|
||||
if (!empty($searchCategoryCustomerSqlList)) {
|
||||
$sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
|
||||
}
|
||||
} else {
|
||||
if (!empty($searchCategoryCustomerSqlList)) {
|
||||
$sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add where from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
||||
// Add where from hooks
|
||||
|
||||
@ -1096,7 +1096,7 @@ class Translate
|
||||
if ($obj) {
|
||||
// If a translation exists, we use it lese we use the default label
|
||||
$this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso) != "Currency".$obj->code_iso ? $this->trans("Currency".$obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
|
||||
$this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode($obj->unicode, true);
|
||||
$this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode((empty($obj->unicode) ? '' : $obj->unicode), true);
|
||||
$label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label'];
|
||||
}
|
||||
$i++;
|
||||
|
||||
@ -967,7 +967,10 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options
|
||||
break;
|
||||
case 'custom':
|
||||
if (empty($filter)) {
|
||||
return 'BadFourthParameterForGETPOST';
|
||||
return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
|
||||
}
|
||||
if (empty($options)) {
|
||||
return 'BadParameterForGETPOST - Param 4 of sanitizeVal()';
|
||||
}
|
||||
$out = filter_var($out, $filter, $options);
|
||||
break;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -472,7 +472,7 @@ $moreforfilter.= '</div>';*/
|
||||
|
||||
// Filter on categories
|
||||
$moreforfilter = '';
|
||||
if (isModEnabled('categorie') && $user->rights->categorie->lire) {
|
||||
if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
|
||||
$moreforfilter .= '<div class="divsearchfield">';
|
||||
$moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
|
||||
$categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1);
|
||||
|
||||
@ -682,7 +682,7 @@ print '</tr>'."\n";
|
||||
$needToFetchEachLine = 0;
|
||||
if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
|
||||
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
|
||||
if (preg_match('/\$object/', $val)) {
|
||||
if ($val && preg_match('/\$object/', $val)) {
|
||||
$needToFetchEachLine++; // There is at least one compute field that use $object
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,6 +270,7 @@ foreach ($search as $key => $val) {
|
||||
if ($search_all) {
|
||||
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
|
||||
}
|
||||
// Search for tag/category
|
||||
$searchCategoryProductSqlList = array();
|
||||
if ($searchCategoryProductOperator == 1) {
|
||||
$existsCategoryProductList = array();
|
||||
@ -314,7 +315,6 @@ if ($searchCategoryProductOperator == 1) {
|
||||
$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
|
||||
}
|
||||
}
|
||||
//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
|
||||
// Add where from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
||||
// Add where from hooks
|
||||
|
||||
@ -375,7 +375,7 @@ if ($result || !($id > 0)) {
|
||||
$morefilters = ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')';
|
||||
}
|
||||
if ($search_categ == -2) {
|
||||
$morefilters = ' AND d.fk_product NOT IN (SELECT cp.fk_product from '.MAIN_DB_PREFIX.'categorie_product as cp)';
|
||||
$morefilters = ' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
|
||||
}
|
||||
|
||||
if ($key == 'propal') {
|
||||
|
||||
@ -46,7 +46,7 @@ $mode = GETPOST('mode', 'aZ');
|
||||
$id = GETPOST('id', 'int');
|
||||
|
||||
$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
|
||||
$search_categ = GETPOST("search_categ", 'alpha');
|
||||
$search_categ = GETPOST("search_categ", 'int');
|
||||
|
||||
$search_projectstatus = GETPOST('search_projectstatus');
|
||||
if (!isset($search_projectstatus) || $search_projectstatus === '') {
|
||||
@ -332,13 +332,9 @@ $distinct = 'DISTINCT'; // We add distinct until we are added a protection to be
|
||||
$sql = "SELECT ".$distinct." p.rowid as projectid, p.ref as projectref, p.title as projecttitle, p.fk_statut as projectstatus, p.datee as projectdatee, p.fk_opp_status, p.public, p.fk_user_creat as projectusercreate, p.usage_bill_time,";
|
||||
$sql .= " s.nom as name, s.name_alias as alias, s.rowid as socid,";
|
||||
$sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_update,";
|
||||
$sql .= " t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut, ";
|
||||
$sql .= " t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut,";
|
||||
$sql .= " t.description, t.fk_task_parent";
|
||||
$sql .= " ,t.budget_amount";
|
||||
// We'll need these fields in order to filter by categ
|
||||
if ($search_categ > 0) {
|
||||
$sql .= ", cs.fk_categorie, cs.fk_project";
|
||||
}
|
||||
// Add sum fields
|
||||
if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
|
||||
$sql .= " , SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "0", "1").") as billed";
|
||||
@ -355,10 +351,6 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
|
||||
// We'll need this table joined to the select in order to filter by categ
|
||||
if ($search_categ > 0) {
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_project as cs ON p.rowid = cs.fk_project"; // We'll need this table joined to the select in order to filter by categ
|
||||
}
|
||||
$sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
|
||||
if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid";
|
||||
@ -384,12 +376,6 @@ if (is_object($projectstatic) && $projectstatic->id > 0) {
|
||||
if ($socid) {
|
||||
$sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
|
||||
}
|
||||
if ($search_categ > 0) {
|
||||
$sql .= " AND cs.fk_categorie = ".((int) $search_categ);
|
||||
}
|
||||
if ($search_categ == -2) {
|
||||
$sql .= " AND cs.fk_categorie IS NULL";
|
||||
}
|
||||
if ($search_project_ref) {
|
||||
$sql .= natural_search('p.ref', $search_project_ref);
|
||||
}
|
||||
@ -448,6 +434,32 @@ if ($search_project_user > 0) {
|
||||
if ($search_task_user > 0) {
|
||||
$sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user);
|
||||
}
|
||||
// Search for tag/category ($searchCategoryProjectList is an array of ID)
|
||||
$searchCategoryProjectList = array($search_categ);
|
||||
$searchCategoryProjectOperator = 0;
|
||||
if (!empty($searchCategoryProjectList)) {
|
||||
$searchCategoryProjectSqlList = array();
|
||||
$listofcategoryid = '';
|
||||
foreach ($searchCategoryProjectList as $searchCategoryProject) {
|
||||
if (intval($searchCategoryProject) == -2) {
|
||||
$searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project)";
|
||||
} elseif (intval($searchCategoryProject) > 0) {
|
||||
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject);
|
||||
}
|
||||
}
|
||||
if ($listofcategoryid) {
|
||||
$searchCategoryProjectSqlList[] = " EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
|
||||
}
|
||||
if ($searchCategoryProjectOperator == 1) {
|
||||
if (!empty($searchCategoryProjectSqlList)) {
|
||||
$sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")";
|
||||
}
|
||||
} else {
|
||||
if (!empty($searchCategoryProjectSqlList)) {
|
||||
$sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")";
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add where from extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
||||
// Add where from hooks
|
||||
@ -459,9 +471,6 @@ if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed
|
||||
$sql .= " s.nom, s.rowid,";
|
||||
$sql .= " t.datec, t.dateo, t.datee, t.tms,";
|
||||
$sql .= " t.rowid, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress,t.budget_amount, t.fk_statut";
|
||||
if ($search_categ) {
|
||||
$sql .= ", cs.fk_categorie, cs.fk_project";
|
||||
}
|
||||
// Add fields from extrafields
|
||||
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
||||
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
|
||||
@ -675,7 +684,7 @@ if (isModEnabled('categorie') && $user->rights->categorie->lire) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
$moreforfilter .= '<div class="divsearchfield">';
|
||||
$tmptitle = $langs->trans('ProjectCategories');
|
||||
$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('project', $search_categ, 'search_categ', 0, $tmptitle, 'maxwidth300');
|
||||
$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('project', $search_categ, 'search_categ', 1, $tmptitle, 'maxwidth300');
|
||||
$moreforfilter .= '</div>';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user