34 protected $entries = [];
35 protected $entriesIndex = [];
38 protected $sortDirection = NULL;
39 protected $sortColumn = NULL;
41 protected $baseMode = TRUE;
42 protected $multiSelect = TRUE;
43 protected $bases = [];
44 protected $header = [];
45 protected $objectTypeCount = [];
46 protected $baseSelector;
53 protected $showFooter;
64 $this->parent = $parent;
65 $this->baseMode = $baseMode;
66 $this->multiSelect = $multiSelect;
69 $this->pid = preg_replace(
'/[^0-9]/',
'', microtime(TRUE));
71 $this->setUpBaseSelector();
74 $this->showFooter = ($config->get_cfg_value(
'listSummary') ==
'TRUE');
76 $this->reloadColumns();
79 function setUpBaseSelector ()
84 if ($this->baseMode) {
85 $this->base = $ui->getCurrentBase();
91 $this->base = $config->current[
'BASE'];
95 function getBaseMode ():
bool 97 return $this->baseMode;
100 function getMultiSelect ():
bool 102 return $this->multiSelect;
105 function reloadColumns ()
107 $columnInfos = $this->parent->getColumnConfiguration();
111 foreach ($columnInfos as $columnInfo) {
112 $column =
Column::build($this, $columnInfo[0], $columnInfo[1]);
113 if ($first && !empty($columnInfo[1][
'attributes'])) {
114 $column->setTemplateAttributes([
'cn']);
117 $this->columns[] = $column;
121 function getColumns (): array
123 return $this->columns;
126 function renderHeader ()
132 if (!isset($this->sortDirection)) {
133 $this->sortColumn = 0;
134 $this->sortDirection = [];
138 foreach ($this->columns as $index => $column) {
141 $this->sortDirection[$index] = FALSE;
144 $this->header[$index] = [
145 'props' => $column->getHtmlProps(),
146 'sortable' => $column->isSortable(),
147 'label' => $column->getLabel(),
149 if ($index == $this->sortColumn) {
150 if ($column->isSortable()) {
151 $this->header[$index][
'sortdirection'] = $this->sortDirection[$index];
152 } elseif ($sortInit) {
168 if (($message = $ui->getSizeLimitHandler()->check()) !=
'') {
172 $this->renderHeader();
175 $smarty->assign(
'PID', $this->pid);
176 $smarty->assign(
'PLUG', $_GET[
'plug']);
177 $smarty->assign(
'multiSelect', $this->multiSelect);
178 $smarty->assign(
'showFooter', $this->showFooter);
179 $smarty->assign(
'headers', $this->header);
181 $smarty->assign(
'columnCount', (count($this->columns) + ($this->multiSelect ? 1 : 0)));
184 $entryIterator = $this->getIterator();
187 foreach ($entryIterator as $entry) {
192 foreach ($this->columns as $column) {
194 'props' => $column->getHtmlCellProps(),
195 'render' => $column->renderCell($entry)
197 $column->fillRowClasses($row[
'classes'], $entry);
200 $row[
'index'] = $entry->row;
204 $smarty->assign(
'rows', $rows);
207 if ($this->showFooter) {
209 foreach ($this->parent->objectTypes as $type) {
210 if (isset($this->objectTypeCount[$type])) {
211 $infos = objects::infos($type);
213 'name' => $infos[
'name'],
214 'icon' => $infos[
'icon'],
215 'count' => $this->objectTypeCount[$type],
218 if (isset($this->objectTypeCount[
'template_'.$type])) {
219 $infos = objects::infos($type);
221 'name' => sprintf(_(
'%s template'), $infos[
'name']),
222 'icon' =>
'geticon.php?context=devices&icon=template&size=16',
223 'count' => $this->objectTypeCount[
'template_'.$type],
227 $smarty->assign(
'objectCounts', $types);
232 count($this->entries),
233 _(
'The number of listed entries (%d) is greater than or too close to configured max_input_vars PHP ini setting (%d). Please change max_input_vars ini setting to a higher value.')
235 if ($error !== FALSE) {
244 return new EntrySortIterator($this->entries, $this->columns[$this->sortColumn] ?? NULL, $this->sortDirection[$this->sortColumn] ?? FALSE);
255 if ($this->baseMode) {
266 $ui->setCurrentBase($this->base);
270 if ($this->baseMode || !(isset($_REQUEST[
'PID']) && ($_REQUEST[
'PID'] != $this->pid))) {
272 if (isset($_GET[
'act'])) {
274 if (preg_match(
'/^SORT_([0-9]+)$/', $key, $match)) {
278 $this->renderHeader();
282 if ($this->baseMode) {
285 foreach (array_keys($_POST) as $key) {
286 if (preg_match(
'/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
293 if ($action ==
'ROOT') {
294 $this->
setBase(key($this->bases));
295 } elseif ($action ==
'BACK') {
296 $parentBase = preg_replace(
'/^[^,]+,/',
'', $this->base);
297 $this->tryAndSetBase($parentBase);
298 } elseif ($action ==
'HOME') {
300 $this->tryAndSetBase($ui->getBase());
316 $this->parent->filter->update($this->base);
319 $attrs = $this->parent->neededAttrs;
320 foreach ($this->columns as $column) {
321 $column->fillNeededAttributes($attrs);
324 $this->parent->filter->setScope(
'base');
325 list($this->entries, $this->objectTypeCount) = $this->parent->filter->query($attrs, $dn);
326 $this->parent->filter->setScope(
'one');
328 list($this->entries, $this->objectTypeCount) = $this->parent->filter->query($attrs, $this->base);
331 $this->entriesIndex = array_keys($this->entries);
343 if ($this->baseMode) {
345 $ui->setCurrentBase($this->base);
349 function tryAndSetBase ($base)
351 if (isset($this->bases[$base])) {
366 function renderBase ():
string 368 if (!$this->baseMode) {
375 function renderNavigation (
bool $skipConfiguration = FALSE): array
379 if ($this->baseMode) {
385 $deps = array_keys($this->bases);
387 if (!count($deps) || $deps[0] == $this->base) {
393 if (!count($deps) || ($this->base == $ui->getBase()) || !
in_array_ics($ui->getBase(), $deps)) {
400 'desc' => _(
'Go to root department'),
402 'icon' =>
'geticon.php?context=actions&icon=go-first&size=16',
403 'enabled' => $enableRoot,
408 'desc' => _(
'Go up one department'),
410 'icon' =>
'geticon.php?context=actions&icon=go-up&size=16',
411 'enabled' => $enableBack,
416 'desc' => _(
'Go to user\'s department'),
418 'icon' =>
'geticon.php?context=actions&icon=go-home&size=16',
419 'enabled' => $enableHome,
429 'desc' => _(
'Reload list'),
430 'name' => _(
'Reload'),
431 'icon' =>
'geticon.php?context=actions&icon=view-refresh&size=16',
433 'class' =>
'optional',
436 if (!$skipConfiguration) {
438 'id' =>
'listing_configure',
439 'desc' => _(
'Configure this management list'),
440 'name' => _(
'Configure'),
441 'icon' =>
'geticon.php?context=categories&icon=settings&size=16',
457 $result = [
'targets' => [],
'action' =>
'',
'subaction' => NULL];
460 if (!isset($_REQUEST[
'dn']) && (!isset($_REQUEST[
'PID']) || $_REQUEST[
'PID'] != $this->pid)) {
464 if (isset($_GET[
'act'])) {
467 if (preg_match(
'/^listing_([[:alnum:]_\.]+)_([0-9]+)$/', $key, $m)) {
469 if (isset($this->entriesIndex[$target])) {
470 $result[
'action'] = $m[1];
471 $result[
'targets'][] = $this->entriesIndex[$target];
473 } elseif (isset($_REQUEST[
'dn']) && preg_match(
'/^listing_([[:alnum:]_\.]+)$/', $key, $m)) {
475 $dn = urldecode($_REQUEST[
'dn']);
479 $result[
'action'] = $m[1];
480 $result[
'targets'][] = $dn;
482 unset($_REQUEST[
'dn']);
486 if (isset($_POST[
'act']) && ($_POST[
'act'] !=
'')) {
487 $result[
'action'] =
validate($_POST[
'act']);
491 foreach (array_keys($_POST) as $key) {
493 if (preg_match(
'/^listing_selected_([0-9]+)$/', $key, $m)) {
495 if (isset($this->entriesIndex[$target])) {
496 $result[
'targets'][] = $this->entriesIndex[$target];
502 if (preg_match(
'/^listing_([[:alnum:]_\.]+)_([0-9]+)(|_x)$/', $key, $m)) {
504 if (isset($this->entriesIndex[$target])) {
505 $result[
'action'] = $m[1];
506 $result[
'targets'] = [$this->entriesIndex[$target]];
512 if (preg_match(
'/^listing_([[:alnum:]_\.]+)(|_x)$/', $key, $m)) {
513 $result[
'action'] = $m[1];
519 if (strpos($result[
'action'],
'_') !== FALSE) {
520 list($result[
'action'], $result[
'subaction']) = explode(
'_', $result[
'action'], 2);
532 foreach (array_keys($this->bases) as $base) {
533 if (preg_match(
'/'.preg_quote($base,
'/').
'$/i', $dn)
534 && (strlen($base) > strlen($longerBase))) {
554 foreach ($this->parent->objectTypes as $otype) {
555 $i = objects::infos($otype);
556 $categories[$i[
'aclCategory']] = $i[
'aclCategory'];
559 $deps = $ui->get_module_departments(array_values($categories));
560 $departmentTree = $config->getDepartmentTree();
561 foreach ($departmentTree as $key => $dep) {
563 $this->bases[$key] = $dep;
567 if (!empty($this->bases) && !isset($this->bases[$this->base])) {
568 $this->base = key($this->bases);
586 if (isset($this->entries[$dn])) {
587 return $this->entries[$dn];
600 if ($direction === NULL) {
602 $direction = (($this->sortColumn == $column) && !$this->sortDirection[$column]);
604 $this->sortColumn = $column;
605 $this->sortDirection[$column] = $direction;
608 function fillSearchedAttributes (
string $type, array &$attrs)
612 $searchedAttributes = [];
613 foreach ($this->columns as $column) {
614 $column->fillSearchedAttributes($searchedAttributes);
617 $searchedAttributes = array_unique($searchedAttributes);
619 foreach ($searchedAttributes as $attr) {
620 if (!isset($attrs[$attr])) {
621 $category = $ui->getAttributeCategory($type, $attr);
622 if ($category !== FALSE) {
623 $attrs[$attr] = $category;
render()
Accessor of the member tree.
in_array_ics($value, array $items)
Check if a value exists in an array (case-insensitive)
get_template_path($filename='', $plugin=FALSE, $path='')
Return themed path for specified base file.
setBase(string $base)
Set a new base valor.
getEntry(string $dn)
Get entry.
This class contains all the function needed to sort list go up, go down , back , next. etc...
update(bool $force=FALSE)
Update the base.
& get_userinfo()
Return the current userinfo object.
updateBase()
Updates base and sorting according to POST and GET infos.
static build(managementListing $parent, string $type, array $data)
Builds a column object from given data.
update(string $dn=NULL)
Update a listing.
checkLastBaseUpdate()
Check the last base value updated.
__construct(management $parent, bool $baseMode=TRUE, bool $multiSelect=TRUE)
Create a listing.
& get_smarty()
Get global smarty object.
This class handles the entries list for a management instance.
static checkMaxInputVars(int $newLimit, string $messageTemplate=NULL)
static check_base()
Display error when checking the base.
getBase()
Accessor of the base.
focusDn(string $dn)
Set base close to this dn and load only him.
validate($string)
Removes malicious characters from a (POST) string.
getBase()
Accessor of the base.
refreshBasesList()
Refresh the bases list.
Parent class for all errors in FusionDirectory.
setSortColumn(int $column, bool $direction=NULL)
Set sort column.
setBases(array $bases)
Set new bases.
setBase(string $base)
Set a new value of the member base.