X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_sortableListing.inc;h=79bc25e7ab45bb4821db12350d818bef09f4e473;hb=652bb3908381dd238ce5bc023203ec8d67ae7bff;hp=06d817806dd777b8e03ed62e42bf0d15d99deec1;hpb=37a863af6c001e5760070adb1d74dc77e4df61f9;p=gosa.git diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index 06d817806..79bc25e7a 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -1,7 +1,7 @@ setListData($data, $displayData); + // Get list of used IDs + if(!session::is_set('sortableListing_USED_IDS')){ + session::set('sortableListing_USED_IDS',array()); + } + $usedIds = session::get('sortableListing_USED_IDS'); + // Generate instance wide unique ID - $tmp= gettimeofday(); - $this->id= 'l'.md5($tmp['sec']); + $id = ""; + while($id == "" || in_array($id, $usedIds)){ + + // Wait 1 msec to ensure that we definately get a new id + if($id != "") usleep(1); + $tmp= gettimeofday(); + $id = 'l'.md5(microtime().$tmp['sec']); + } + + // Only keep the last 10 list IDsi + $usedIds = array_slice($usedIds, count($usedIds) -10, 10); + $usedIds[] = $id; + session::set('sortableListing_USED_IDS',$usedIds); + $this->id = $id; // Set reorderable flag $this->reorderable= $reorderable; @@ -66,6 +89,15 @@ class sortableListing { } } + public function setReorderable($bool) + { + $this->reorderable= $bool; + } + + public function setDefaultSortColumn($id) + { + $this->sortColumn = $id; + } public function setListData($data, $displayData= null) { @@ -74,10 +106,9 @@ class sortableListing { if (!$displayData) { $displayData= array(); foreach ($data as $key => $value) { - $displayData[$key]= array($value); + $displayData[$key]= array("data" => array($value)); } } - $this->setDisplayData($displayData); } @@ -91,15 +122,25 @@ class sortableListing { private function setDisplayData($data) { if (!is_array($data)) { - die ("sortableList needs an array as data!"); + trigger_error ("sortableList needs an array as data!"); } // Transfer information - $this->displayData= array_values($data); + $this->displayData= array(); + $this->modes= array(); + $this->mapping= array(); + foreach ($data as $key => $value) { + $this->displayData[]= $value['data']; + if (isset($value['mode'])) { + $this->modes[]= $value['mode']; + } + } $this->keys= array_keys($data); // Create initial mapping - $this->mapping= range(0, abs(count($this->keys)-1)); + if(count($this->keys)){ + $this->mapping= range(0, abs(count($this->keys)-1)); + } $this->current_mapping= $this->mapping; // Find the number of coluns @@ -113,7 +154,9 @@ class sortableListing { // Preset sort orders to 'down' for ($column= 0; $column<$this->columns; $column++) { - $this->sortDirection[]= true; + if(!isset($this->sortDirection[$column])){ + $this->sortDirection[$column]= true; + } } } @@ -175,30 +218,34 @@ class sortableListing { public function render() { $result= "
".(isset($this->header[$i])?$this->header[$i]:"")." | "; } else { - $result.= "".(isset($this->header[$i])?$this->header[$i]:"")."$sorter | "; + $result.= "".(isset($this->header[$i])?$this->header[$i]:"")."$sorter | "; } $first= ""; } @@ -232,17 +279,40 @@ class sortableListing { $reorderable= $this->reorderable?"":" style='cursor:default'"; if (strpos($this->acl, 'r') !== false) { foreach ($this->mapping as $nr => $row) { - $editable= $this->editable?" onclick='$(\"edit_".$this->id."_$nr\").click()'":""; - $result.= "|
---|---|---|---|
".htmlentities($column)." | \n"; - $first= ""; + + // Do NOT use the onClick statement for columns that contain links or buttons. + if(preg_match("<.*type=.submit..*>", $column) || preg_match("".$column." | \n"; + }else{ + $result.= "".$column." | \n"; + } + $first= ""; } + if ($action_width) { $result.= "".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image). str_replace('%ID', "del_".$this->id."_$nr", $delete_image)." | "; } + $result.= "