1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_listing.inc 15087 2010-01-06 13:45:49Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class sortableListing {
24 private $header= null;
25 private $colspecs= null;
26 private $reorderable= true;
27 private $width= "400px";
28 private $height= "100px";
29 private $cssclass= "";
30 private $id;
32 private $data= array();
33 private $columns= 0;
35 function sortableListing($data= array())
36 {
37 global $config;
39 // Save data to display
40 $this->setData($data);
42 // Generate instance wide unique ID
43 $tmp= gettimeofday();
44 $this->id= 'l'.md5($t['sec']);
45 }
48 function setData($data)
49 {
50 if (!is_array($data)) {
51 die ("sortableList needs an array as data!");
52 }
54 // Transfer information
55 $this->data= $data;
57 // Find the number of coluns
58 reset($this->data);
59 $first= current($this->data);
60 if (is_array($first)) {
61 $this->columns= count($first);
62 } else {
63 $this->columns= 1;
64 }
66 }
69 function setWidth($width)
70 {
71 $this->width= $width;
72 }
75 function setHeight($height)
76 {
77 $this->height= $height;
78 }
81 function setCssClass($css)
82 {
83 $this->cssclass= $css;
84 }
87 function setHeader($header)
88 {
89 $this->header= $header;
90 }
93 function setColspecs($specs)
94 {
95 $this->colspecs= $specs;
96 }
99 function render()
100 {
101 $result= "<div class='sortableListContainer' style='width: ".$this->width."; height: ".$this->height."'>\n";
102 $result.= "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%' style='position: relative;'".(!empty($this->cssclass)?" class='".$this->cssclass."'":"").">\n";
104 // Do we need colspecs?
105 if ($this->colspecs) {
106 $result.= " <colgroup>\n";
107 for ($i= 0; $i<$this->columns; $i++) {
108 $result.= " <col width='".(isset($this->colspecs[$i])?$this->colspecs[$i]:"*")."'/>\n";
109 }
110 $result.= " </colgroup>\n";
111 }
113 // Do we need a header?
114 if ($this->header) {
115 $result.= " <thead>\n <tr>\n";
116 for ($i= 0; $i<$this->columns; $i++) {
117 $result.= " <th>".(isset($this->header[$i])?$this->header[$i]:"")."</th>\n";
118 }
119 $result.= " </tr>\n </thead>\n";
120 }
122 // Render table body
123 $result.= " <tbody id='".$this->id."'>\n";
124 foreach ($this->data as $nr => $row) {
125 $result.= " <tr class='sortableListItem".($nr&1?'Odd':'')."' id='item_$nr'>\n";
126 foreach ($row as $column) {
127 $result.= " <td>".htmlentities($column)."</td>\n";
128 }
129 $result.= " </tr>\n";
130 }
132 $result.= " </tbody>\n</table>\n</div>\n";
133 $result.= " <div id='dropmarker' class='dropmarker' style='display: none; width: ".(intval($this->width)-17)."px'\>\n";
135 // Append script stuff if needed
136 $result.= '<script type="text/javascript" language="javascript">';
137 $result.= ' function updateOrder(){';
138 $result.= ' var ampcharcode= \'%26\';';
139 $result.= ' var serializeOpts = Sortable.serialize(\''.$this->id.'\')+ unescape(ampcharcode)+"key='.$this->id.'"+unescape(ampcharcode)+"update=products";';
140 $result.= ' var options = {';
141 $result.= ' method : \'post\',';
142 $result.= ' parameters : serializeOpts';
143 $result.= ' };';
144 // $result.= ' // new Ajax.Request(\'Reorder.aspx\',options);';
145 $result.= ' }';
146 $result.= ' Sortable.create(\''.$this->id.'\',{tag:\'tr\', ghosting:true,constraint:\'vertical\', onUpdate : updateOrder,tree:true})';
147 $result.= '</script>';
149 return $result;
150 }
153 function update()
154 {
155 }
157 }