*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,6 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
+if (!empty($conf->categorie->enabled))
+{
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
+ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+}
+
// Load translation files required by the page
$langs->loadLangs(array('projects', 'companies', 'commercial'));
@@ -72,7 +79,6 @@ $pageprev = $page - 1;
$pagenext = $page + 1;
$search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
-$search_categ = GETPOST("search_categ", 'alpha');
$search_ref = GETPOST("search_ref", 'alpha');
$search_label = GETPOST("search_label", 'alpha');
$search_societe = GETPOST("search_societe", 'alpha');
@@ -101,6 +107,11 @@ $search_eyear = GETPOST('search_eyear', 'int');
if ($search_status == '') $search_status = -1; // -1 or 1
+if (!empty($conf->categorie->enabled))
+{
+ $search_category_list = GETPOST("search_category_".Categorie::TYPE_PROJECT."_list", "array");
+}
+
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new Project($db);
$hookmanager->initHooks(array('projectlist'));
@@ -174,7 +185,6 @@ if (empty($reshook))
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_all = '';
- $search_categ = '';
$search_ref = "";
$search_label = "";
$search_societe = "";
@@ -197,6 +207,7 @@ if (empty($reshook))
$search_usage_bill_time = '';
$toselect = '';
$search_array_options = array();
+ $search_category_list = array();
}
@@ -293,8 +304,6 @@ $sql = "SELECT ".$distinct." p.rowid as id, p.ref, p.title, p.fk_statut, p.fk_op
$sql .= ", p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, (p.opp_amount*p.opp_percent/100) as opp_weighted_amount, p.tms as date_update, p.budget_amount, p.usage_opportunity, p.usage_task, p.usage_bill_time";
$sql .= ", s.rowid as socid, s.nom as name, s.email";
$sql .= ", cls.code as opp_status_code";
-// We'll need these fields in order to filter by categ
-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) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
@@ -304,11 +313,12 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
-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 (p.rowid = ef.fk_object)";
+if (!empty($conf->categorie->enabled))
+{
+ $sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_PROJECT, "p.rowid");
+}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
-// We'll need this table joined to the select in order to filter by categ
-if (!empty($search_categ)) $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
// We'll need this table joined to the select in order to filter by sale
// No check is done on company permission because readability is managed by public status of project and assignement.
//if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
@@ -318,11 +328,13 @@ if ($search_project_user > 0)
$sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
}
$sql .= " WHERE p.entity IN (".getEntity('project').')';
+if (!empty($conf->categorie->enabled))
+{
+ $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_PROJECT, "p.rowid", $search_category_list);
+}
if (!$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
// No need to check if company is external user, as filtering of projects must be done by getProjectsAuthorizedForUser
if ($socid > 0) $sql .= " AND (p.fk_soc = ".$socid.")"; // This filter if when we use a hard coded filter on company on url (not related to filter for external users)
-if ($search_categ > 0) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ);
-if ($search_categ == -2) $sql .= " AND cs.fk_categorie IS NULL";
if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
if ($search_label) $sql .= natural_search('p.title', $search_label);
if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
@@ -486,11 +498,8 @@ $moreforfilter = '';
// Filter on categories
if (!empty($conf->categorie->enabled))
{
- require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
- $moreforfilter .= '';
- $moreforfilter .= $langs->trans('ProjectCategories').': ';
- $moreforfilter .= $formother->select_categories('project', $search_categ, 'search_categ', 1, 1, 'maxwidth300');
- $moreforfilter .= '
';
+ $formcategory = new FormCategory($db);
+ $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_list);
}
// If the user can view user other than himself