diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index b9a92f85d5e..60fb76293ea 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -746,13 +746,19 @@ class Categorie extends CommonObject
/**
* Return list of fetched instance of elements having this category
*
- * @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
- * @param int $onlyids Return only ids of objects (consume less memory)
- * @return array|int -1 if KO, array of instance of object if OK
+ * @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
+ * @param int $onlyids Return only ids of objects (consume less memory)
+ * @param int $limit Limit
+ * @param int $offset Offset
+ * @param string $sortfield Sort fields
+ * @param string $sortorder Sort order ('ASC' or 'DESC');
+ * @return array|int -1 if KO, array of instance of object if OK
* @see containsObject()
*/
- public function getObjectsInCateg($type, $onlyids = 0)
+ public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC')
{
+ global $user;
+
$objs = array();
$obj = new $this->MAP_OBJ_CLASS[$type]( $this->db );
@@ -761,8 +767,15 @@ class Categorie extends CommonObject
$sql .= " FROM " . MAIN_DB_PREFIX . "categorie_" . $this->MAP_CAT_TABLE[$type] . " as c";
$sql .= ", " . MAIN_DB_PREFIX . $this->MAP_OBJ_TABLE[$type] . " as o";
$sql .= " WHERE o.entity IN (" . getEntity($obj->element).")";
- $sql.= " AND c.fk_categorie = ".$this->id;
+ $sql .= " AND c.fk_categorie = ".$this->id;
$sql .= " AND c.fk_" . $this->MAP_CAT_FK[$type] . " = o.rowid";
+ // Protection for external users
+ if (($type == 'customer' || $type == 'supplier') && $user->societe_id > 0)
+ {
+ $sql.= " AND o.rowid = ".$user->societe_id;
+ }
+ if ($limit > 0 || $offset > 0) $sql .= $this->db->plimit($limit + 1, $offset);
+ $sql .= $this->db->order($sortfield, $sortorder);
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
$resql = $this->db->query($sql);
diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php
index a7a0767c6b5..67ef7905235 100644
--- a/htdocs/categories/viewcat.php
+++ b/htdocs/categories/viewcat.php
@@ -34,14 +34,33 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// Load translation files required by the page
$langs->load("categories");
-$id = GETPOST('id', 'int');
-$label= GETPOST('label', 'alpha');
-$type = GETPOST('type', 'az09');
-$action=GETPOST('action', 'aZ09');
-$confirm = GETPOST('confirm', 'alpha');
+$id = GETPOST('id', 'int');
+$label = GETPOST('label', 'alpha');
+$type = GETPOST('type', 'az09');
$removeelem = GETPOST('removeelem', 'int');
$elemid = GETPOST('elemid', 'int');
+$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 = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
+$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
+$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
+$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
+$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'myobjectlist'; // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
+$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
+
+
+// Load variable for pagination
+$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
+$sortfield = GETPOST('sortfield', 'alpha');
+$sortorder = GETPOST('sortorder', 'alpha');
+$page = 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
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
if ($id == "" && $label == "")
{
dol_print_error('', 'Missing parameter id');
@@ -319,10 +338,20 @@ else
}
+// List of mass actions available
+$arrayofmassactions = array(
+ //'validate'=>$langs->trans("Validate"),
+ //'generate_doc'=>$langs->trans("ReGeneratePDF"),
+ //'builddoc'=>$langs->trans("PDFMerge"),
+ //'presend'=>$langs->trans("SendByMail"),
+);
+$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
+
+
// List of products or services (type is type of category)
if ($type == Categorie::TYPE_PRODUCT)
{
- $prods = $object->getObjectsInCateg("product");
+ $prods = $object->getObjectsInCateg("product", 0, $limit, $offset);
if ($prods < 0)
{
dol_print_error($db, $prods->error, $prods->errors);
@@ -351,14 +380,28 @@ if ($type == Categorie::TYPE_PRODUCT)
print '';
}
- print "
";
+ print '
| '.$langs->trans("Account").' '.count($accounts).' |