From 8be0d004bb2ce4d7bac193179eba7e93c41296f2 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 17 Aug 2009 15:32:50 +0000 Subject: [PATCH] Added department browsing git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14080 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../include/class_departmentSortIterator.inc | 84 +++++++++ gosa-core/include/class_listing.inc | 161 +++++++++++++++--- 2 files changed, 217 insertions(+), 28 deletions(-) create mode 100644 gosa-core/include/class_departmentSortIterator.inc diff --git a/gosa-core/include/class_departmentSortIterator.inc b/gosa-core/include/class_departmentSortIterator.inc new file mode 100644 index 000000000..2a2863227 --- /dev/null +++ b/gosa-core/include/class_departmentSortIterator.inc @@ -0,0 +1,84 @@ +data= array_reverse($data); + } else { + $this->data= $data; + } + } + + function rewind() { + return reset($this->data); + } + + function current() { + return current($this->data); + } + + function key() { + return key($this->data); + } + + function next() { + return next($this->data); + } + + function valid() { + return key($this->data) !== null; + } +} + +?> diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index ed1354a84..e9cc5d9eb 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -36,13 +36,14 @@ class listing { var $sortColumn= null; var $sortAttribute; var $sortType; + var $numColumns; var $baseMode= false; var $bases= array(); var $header= array(); var $colprops= array(); var $filters= array(); var $pid; - var $objectTypes; + var $objectTypes= array(); var $objectTypeCount= array(); @@ -50,6 +51,9 @@ class listing { { global $config; + // Initialize pid + $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE)); + if (!$this->load($filename)) { die("Cannot parse $filename!"); } @@ -66,11 +70,9 @@ class listing { // Register build in filters $this->registerElementFilter("objectType", "listing::filterObjectType"); + $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink"); $this->registerElementFilter("link", "listing::filterLink"); $this->registerElementFilter("actions", "listing::filterActions"); - - // Initialize pid - $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE)); } @@ -104,7 +106,13 @@ class listing { } } - // Fill objectTypes + // Fill objectTypes from departments and xml definition + $types = departmentManagement::get_support_departments(); + foreach ($types as $class => $data) { + $this->objectTypes[]= array("label" => $data['TITLE'], + "objectClass" => $data['OC'], + "image" => $data['IMG']); + } if (isset($this->xmlData['definition']['objectType'])) { foreach ($this->xmlData['definition']['objectType'] as $index => $otype) { $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index]; @@ -158,7 +166,7 @@ class listing { } $sortable= (isset($config['sortAttribute'])); - $link= "href='?plug=".$_GET['plug']."&PID=$this->pid&act=SORT_$index'"; + $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'"; if (isset($config['label'])) { if ($sortable) { $this->header[$index]= "colprops[$index].">"._($config['label'])."$sorter"; @@ -178,14 +186,14 @@ class listing { function render() { -echo "department browsing, copypaste handler, snapshot handler, daemon handler
"; +echo "sizelimit, copypaste handler, snapshot handler, daemon handler
"; // Initialize list $result= ""; $result.= "
"; $result.= "
"; - $num_cols= count($this->colprops) + ($this->multiSelect?1:0); + $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0); // Build list header $result.= ""; @@ -200,20 +208,49 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerentries) + count($this->departments) == 0) { - $result.= ""; + $result.= ""; } - // Fill with department browser if configured this way -############### + // Line color alternation + $alt= 0; + $deps= 0; + + // Draw department browser if configured and we're not in sub mode + if ($this->departmentBrowser && $this->filter->scope != "sub") { + // Fill with department browser if configured this way + $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]); + foreach ($departmentIterator as $row => $entry){ + $result.=""; + + // Render multi select if needed + if ($this->multiSelect) { + $result.=""; + } + + // Render defined department columns, fill the rest with some stuff + foreach ($this->xmlData['table']['department'] as $index => $config) { + $result.=""; + } + $last= count($this->xmlData['table']['department']) + 1; + $rest= $this->numColumns - $last; + for ($i= 0; $i<$rest; $i++){ + $result.= ""; + } + $result.=""; + + $alt++; + } + $deps= $alt; + } // Fill with contents, sort as configured $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], $this->sortAttribute, $this->sortType); foreach ($entryIterator as $row => $entry){ - $result.=""; + $result.=""; // Render multi select if needed if ($this->multiSelect) { @@ -224,18 +261,20 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlercolprops[$index]." class='list0'>".$this->renderCell($config['value'], $entry, $row).""; } $result.=""; + + $alt++; } // Need to fill the list if it's not full (nobody knows why this is 22 ;-)) - $emptyListStyle= (count($this->entries) == 0)?"border:0;":""; - if (count($this->entries) < 22) { + $emptyListStyle= (count($this->entries) + count($deps) == 0)?"border:0;":""; + if (count($this->entries) + count($deps) < 22) { $result.= ""; - for ($i= 0; $i<$num_cols; $i++) { + for ($i= 0; $i<$this->numColumns; $i++) { if ($i == 0) { $result.= ""; continue; } - if ($i != $num_cols-1) { + if ($i != $this->numColumns-1) { $result.= ""; } else { $result.= ""; @@ -290,7 +329,7 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerfilter= &$filter; if ($this->departmentBrowser){ - # $this->departments= $this->filter->getDepartments(); + $this->departments= $this->getDepartments(); } $this->filter->setBase($this->base); $this->entries= $this->filter->query(); @@ -307,10 +346,6 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerdepartmentBrowser){ - # $this->departments= $this->filter->getDepartments(); - } - // Save base if (isset($_POST['BASE']) && $this->baseMode == true) { $base= validate($_POST['BASE']); @@ -319,6 +354,15 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerdepartmentBrowser && isset($_GET['act'])) { + if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){ + if (isset($this->departments[$match[1]])){ + $this->base= $this->departments[$match[1]]['dn']; + } + } + } + // Filter GET with "act" attributes if (isset($_GET['act'])) { $key= validate($_GET['act']); @@ -362,8 +406,9 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerbase= get_base_from_people($ui->dn); } - // Check sorting - if (isset($_GET['SORT'])) { + // Reload departments + if ($this->departmentBrowser){ + $this->departments= $this->getDepartments(); } // Update filter and refresh entries @@ -407,6 +452,9 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlernumColumns= count($cols); + return $result; } @@ -637,17 +685,29 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerdepartments[$row]['sort-attribute']; + $name= $this->departments[$row][$attr]; + if (is_array($name)){ + $name= $name[0]; + } + $result= sprintf("%s [%s]", $name, $description[0]); + return("pid&act=department_$row' title='$dn'>$result"); + } + + function filterLink() { $result= " "; $row= func_get_arg(0); - $pid= func_get_arg(1); - $dn= LDAP::fix(func_get_arg(2)); - $params= array(func_get_arg(3)); + $pid= $this->pid; + $dn= LDAP::fix(func_get_arg(1)); + $params= array(func_get_arg(2)); // Collect sprintf params - for ($i = 4;$i < func_num_args();$i++) { + for ($i = 3;$i < func_num_args();$i++) { $val= func_get_arg($i); if (is_array($val)){ $params[]= $val[0]; @@ -967,6 +1027,51 @@ echo "department browsing, copypaste handler, snapshot handler, daemon handlerget_module_departments($this->module); + + // Build filter and look in the LDAP for possible sub departments + // of current base + $filter= "(&(objectClass=gosaDepartment)(|"; + $attrs= array("description", "objectClass"); + foreach($types as $name => $data){ + $filter.= "(objectClass=".$data['OC'].")"; + $attrs[]= $data['ATTR']; + } + $filter.= "))"; + $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE | GL_SIZELIMIT); + + // Analyze list of departments + foreach ($res as $department) { + if (!in_array($department['dn'], $validDepartments)) { + continue; + } + + // Add the attribute where we use for sorting + $oc= null; + foreach(array_keys($types) as $type) { + if (in_array($type, $department['objectClass'])) { + $oc= $type; + break; + } + } + $department['sort-attribute']= $types[$oc]['ATTR']; + + // Move to the result list + $departments[]= $department; + } + + return $departments; + } + } ?> -- 2.30.2
 
 
 colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."colprops[$last+$i-1]." class='list1'>