diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc
index 06d817806dd777b8e03ed62e42bf0d15d99deec1..a30758ebc3c3ccba455edc2e079eeecb61530b65 100644 (file)
<?php
/*
* This code is part of GOsa (http://www.gosa-project.org)
- * Copyright (C) 2003-2008 GONICUS GmbH
+ * Copyright (C) 2003-2010 GONICUS GmbH
*
* ID: $$Id$$
*
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+define ('LIST_NORMAL', 0);
+define ('LIST_MARKED', 1);
+define ('LIST_DISABLED', 2);
+
class sortableListing {
private $header= null;
private $colspecs= null;
private $data= array();
private $keys= array();
+ private $modes= array();
private $displayData= array();
private $columns= 0;
private $deleteable= false;
if (!$displayData) {
$displayData= array();
foreach ($data as $key => $value) {
- $displayData[$key]= array($value);
+ $displayData[$key]= array("data" => array($value));
}
}
-
$this->setDisplayData($displayData);
}
}
// Transfer information
- $this->displayData= array_values($data);
+ $this->displayData= array();
+ $this->modes= 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
if (strpos($this->acl, 'r') !== false) {
foreach ($this->mapping as $nr => $row) {
$editable= $this->editable?" onclick='$(\"edit_".$this->id."_$nr\").click()'":"";
- $result.= " <tr class='sortableListItem".((($nr&1)||!$this->colorAlternate)?'':'Odd')."' id='item_".$this->id."_$nr'$reorderable>\n";
+
+ $id= "";
+ if (isset($this->modes[$row])) {
+ switch ($this->modes[$row]) {
+ case LIST_DISABLED:
+ $id= " sortableListItemDisabled";
+ $editable= "";
+ break;
+ case LIST_MARKED:
+ $id= " sortableListItemMarked";
+ break;
+ }
+ }
+
+ $result.= " <tr class='sortableListItem".((($nr&1)||!$this->colorAlternate)?'':'Odd')."$id' id='item_".$this->id."_$nr'$reorderable>\n";
$first= " style='border:0'";
+
foreach ($this->displayData[$row] as $column) {
- $result.= " <td$editable$first>".htmlentities($column)."</td>\n";
+ $result.= " <td$editable$first>".$column."</td>\n";
$first= "";
}
+
if ($action_width) {
$result.= "<td>".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image).
str_replace('%ID', "del_".$this->id."_$nr", $delete_image)."</td>";
}
+
$result.= " </tr>\n";
}
}
$this->sortData();
}
}
+ }
+
+
+ public function save_object()
+ {
+ // Do not do anything if this is not our PID, or there's even no PID available...
+ if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->id) {
+ return;
+ }
// Do not do anything if we're not posted - or have no permission
if (strpos($this->acl, 'w') !== false && isset($_POST['reorder_'.$this->id])){
foreach ($_POST as $key => $value) {
if (preg_match('/^del_'.$this->id.'_([0-9]+)_x.*$/', $key, $matches)) {
$this->active_index= $this->mapping[$matches[1]];
+
+ // Ignore request if mode requests it
+ if (isset($this->modes[$this->active_index]) && $this->modes[$this->active_index] == LIST_DISABLED) {
+ $this->active_index= null;
+ continue;
+ }
+
+ // Set action
$this->action= "delete";
+
+ // Remove value if requested
if ($this->instantDelete) {
$this->deleteEntry($this->active_index);
}
foreach ($_POST as $key => $value) {
if (preg_match('/^edit_'.$this->id.'_([0-9]+)_x.*$/', $key, $matches)) {
$this->active_index= $this->mapping[$matches[1]];
+
+ // Ignore request if mode requests it
+ if (isset($this->modes[$this->active_index]) && $this->modes[$this->active_index] == LIST_DISABLED) {
+ $this->active_index= null;
+ continue;
+ }
+
$this->action= "edit";
}
}
// Prefill with default value if not specified
if (!$displayEntry) {
- $displayEntry= array($entry);
+ $displayEntry= array('data' => array($entry));
}
// Append to data and mapping
$this->data[]= $entry;
$this->keys[]= count($this->mapping);
}
- $this->displayData[]= $displayEntry;
+ $this->displayData[]= $displayEntry['data'];
$this->mapping[]= count($this->mapping);
$this->modified= true;
+
+ // Sort data after we've added stuff
+ $this->sortData();
}