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
$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;
if (!$reorderable) {
$this->sortData();
}
}
public function setReorderable($bool)
{
$this->reorderable= $bool;
}
public function setDefaultSortColumn($id)
{
$this->sortColumn = $id;
}
public function setListData($data, $displayData= null)
{
// Save data to display
$this->setData($data);
if (!$displayData) {
$displayData= array();
foreach ($data as $key => $value) {
$displayData[$key]= array("data" => array($value));
}
}
$this->setDisplayData($displayData);
}
private function setData($data)
{
$this->data= $data;
}
private function setDisplayData($data)
{
if (!is_array($data)) {
trigger_error ("sortableList needs an array as data!");
}
// Transfer information
$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
if(count($this->keys)){
$this->mapping= range(0, abs(count($this->keys)-1));
}
$this->current_mapping= $this->mapping;
// Find the number of coluns
reset($this->displayData);
$first= current($this->displayData);
if (is_array($first)) {
$this->columns= count($first);
} else {
$this->columns= 1;
}
// Preset sort orders to 'down'
for ($column= 0; $column<$this->columns; $column++) {
if(!isset($this->sortDirection[$column])){
$this->sortDirection[$column]= true;
}
}
}
public function setWidth($width)
{
$this->width= $width;
}
public function setInstantDelete($flag)
{
$this->instantDelete= $flag;
}
public function setColorAlternate($flag)
{
$this->colorAlternate= $flag;
}
public function setEditable($flag)
{
$this->editable= $flag;
}
public function setDeleteable($flag)
{
$this->deleteable= $flag;
}
public function setHeight($height)
{
$this->height= $height;
}
public function setCssClass($css)
{
$this->cssclass= $css;
}
public function setHeader($header)
{
$this->header= $header;
}
public function setColspecs($specs)
{
$this->colspecs= $specs;
}
public function render()
{
$result= "
\n";
$result.= "
cssclass)?" class='".$this->cssclass."'":"").">\n";
$action_width= 0;
if (strpos($this->acl, 'w') === false) {
$edit_image= $this->editable?image("images/lists/edit-grey.png"):"";
} else {
$edit_image= $this->editable?image('images/lists/edit.png', "%ID", _("Edit this entry")):"";
}
if (strpos($this->acl, 'd') === false) {
$delete_image= $this->deleteable?image('images/lists/trash-grey.png'):"";
} else {
$delete_image= $this->deleteable?image('images/lists/trash.png', "%ID", _("Delete this entry")):"";
}
// Do we need colspecs?
$action_width= ($this->editable?30:0) + ($this->deleteable?30:0);
if ($this->colspecs) {
$result.= "
";
}
$first= "";
}
if ($action_width) {
$result.= "
";
}
$result.= "\n
\n \n";
}
// Render table body if we've read permission
$result.= " \n";
$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()'":"";
$id= "";
if (isset($this->modes[$row])) {
switch ($this->modes[$row]) {
case LIST_DISABLED:
$id= " sortableListItemDisabled";
$editable= "";
break;
case LIST_MARKED:
$id= " sortableListItemMarked";
break;
}
}
$result.= "
\n";
$first= " style='border:0'";
foreach ($this->displayData[$row] as $column) {
// Do NOT use the onClick statement for columns that contain links or buttons.
if(preg_match("<.*type=.submit..*>", $column) || preg_match("", $column)){
$result.= "
".$column."
\n";
}else{
$result.= "
".$column."
\n";
}
$first= "";
}
if ($action_width) {
$result.= "