1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
<?php
/*
@author dhtmlx.com
@license GPL, see license.txt
*/
class GridConfiguration{
/*! attaching header functionality
*/
protected $headerDelimiter = ',';
protected $headerNames = false;
protected $headerAttaches = array();
protected $footerAttaches = array();
protected $headerWidthsUnits = 'px';
protected $headerIds = false;
protected $headerWidths = false;
protected $headerTypes = false;
protected $headerAlign = false;
protected $headerVAlign = false;
protected $headerSorts = false;
protected $headerColors = false;
protected $headerHidden = false;
protected $headerFormat = false;
protected $convert_mode = false;
function __construct($headers = false){
if ($headers === false || $headers === true )
$this->headerNames = $headers;
else
$this->setHeader($headers);
}
/*! brief convert list of parameters to an array
@param param
list of values or array of values
@return array of parameters
*/
private function parse_param_array($param, $check=false, $default = ""){
if (gettype($param) == 'string')
$param = explode($this->headerDelimiter, $param);
if ($check){
for ($i=0; $i < sizeof($param); $i++) {
if (!array_key_exists($param[$i],$check))
$param[$i] = $default;
}
}
return $param;
}
/*! sets delimiter for string arguments in attach header functions (default is ,)
@param headerDelimiter
string delimiter
*/
public function setHeaderDelimiter($headerDelimiter) {
$this->headerDelimiter = $headerDelimiter;
}
/*! sets header
@param names
array of names or string of names, delimited by headerDelimiter (default is ,)
*/
public function setHeader($names) {
if ($names instanceof DataConfig){
$out = array();
for ($i=0; $i < sizeof($names->text); $i++)
$out[]=$names->text[$i]["name"];
$names = $out;
}
$this->headerNames = $this->parse_param_array($names);
}
/*! sets init columns width in pixels
@param wp
array of widths or string of widths, delimited by headerDelimiter (default is ,)
*/
public function setInitWidths($wp) {
$this->headerWidths = $this->parse_param_array($wp);
$this->headerWidthsUnits = 'px';
}
/*! sets init columns width in persents
@param wp
array of widths or string of widths, delimited by headerDelimiter (default is ,)
*/
public function setInitWidthsP($wp) {
$this->setInitWidths($wp);
$this->headerWidthsUnits = '%';
}
/*! sets columns align
@param alStr
array of aligns or string of aligns, delimited by headerDelimiter (default is ,)
*/
public function setColAlign($alStr) {
$this->headerAlign = $this->parse_param_array($alStr,
array("right"=>1, "left"=>1, "center"=>1, "justify"=>1),
"left");
}
/*! sets columns vertical align
@param alStr
array of vertical aligns or string of vertical aligns, delimited by headerDelimiter (default is ,)
*/
public function setColVAlign($alStr) {
$this->headerVAlign = $this->parse_param_array($alStr,
array("baseline"=>1, "sub"=>1, "super"=>1, "top"=>1, "text-top"=>1, "middle"=>1, "bottom"=>1, "text-bottom"=>1),
"top");
}
/*! sets column types
@param typeStr
array of types or string of types, delimited by headerDelimiter (default is ,)
*/
public function setColTypes($typeStr) {
$this->headerTypes = $this->parse_param_array($typeStr);
}
/*! sets columns sorting
@param sortStr
array if sortings or string of sortings, delimited by headerDelimiter (default is ,)
*/
public function setColSorting($sortStr) {
$this->headerSorts = $this->parse_param_array($sortStr);
}
/*! sets columns colors
@param colorStr
array of colors or string of colors, delimited by headerDelimiter (default is ,)
if (color should not be applied it's value should be null)
*/
public function setColColor($colorStr) {
$this->headerColors = $this->parse_param_array($colorStr);
}
/*! sets hidden columns
@param hidStr
array of bool values or string of bool values, delimited by headerDelimiter (default is ,)
*/
public function setColHidden($hidStr) {
$this->headerHidden = $this->parse_param_array($hidStr);
}
/*! sets columns id
@param idsStr
array of ids or string of ids, delimited by headerDelimiter (default is ,)
*/
public function setColIds($idsStr) {
$this->headerIds = $this->parse_param_array($idsStr);
}
/*! sets number/date format
@param formatArr
array of mask formats for number/dates , delimited by headerDelimiter (default is ,)
*/
public function setColFormat($formatArr) {
$this->headerFormat = $this->parse_param_array($formatArr);
}
/*! attaches header
@param values
array of header names or string of header names, delimited by headerDelimiter (default is ,)
@param styles
array of header styles or string of header styles, delimited by headerDelimiter (default is ,)
*/
public function attachHeader($values, $styles = null, $footer = false) {
$header = array();
$header['values'] = $this->parse_param_array($values);
if ($styles != null) {
$header['styles'] = $this->parse_param_array($styles);
} else {
$header['styles'] = null;
}
if ($footer)
$this->footerAttaches[] = $header;
else
$this->headerAttaches[] = $header;
}
/*! attaches footer
@param values
array of footer names or string of footer names, delimited by headerDelimiter (default is ,)
@param styles
array of footer styles or string of footer styles, delimited by headerDelimiter (default is ,)
*/
public function attachFooter($values, $styles = null) {
$this->attachHeader($values, $styles, true);
}
private function auto_fill($mode){
$headerWidths = array();
$headerTypes = array();
$headerSorts = array();
$headerAttaches = array();
for ($i=0; $i < sizeof($this->headerNames); $i++) {
$headerWidths[] = 100;
$headerTypes[] = "ro";
$headerSorts[] = "connector";
$headerAttaches[] = "#connector_text_filter";
}
if ($this->headerWidths == false)
$this->setInitWidths($headerWidths);
if ($this->headerTypes == false)
$this->setColTypes($headerTypes);
if ($mode){
if ($this->headerSorts == false)
$this->setColSorting($headerSorts);
$this->attachHeader($headerAttaches);
}
}
public function defineOptions($conn){
if (!$conn->is_first_call()) return; //render head only for first call
$config = $conn->get_config();
$full_header = ($this->headerNames === true);
if (gettype($this->headerNames) == 'boolean') //auto-config
$this->setHeader($config);
$this->auto_fill($full_header);
if (isset($_GET["dhx_colls"])) return;
$fillList = array();
for ($i = 0; $i < count($this->headerNames); $i++)
if ($this->headerTypes[$i] == "co" || $this->headerTypes[$i] == "coro")
$fillList[$i] = true;
for ($i = 0; $i < count($this->headerAttaches); $i++) {
for ($j = 0; $j < count($this->headerAttaches[$i]['values']); $j++) {
if ($this->headerAttaches[$i]['values'][$j] == "#connector_select_filter"
|| $this->headerAttaches[$i]['values'][$j] == "#select_filter") {
$fillList[$j] = true;;
}
}
}
$temp = array();
foreach($fillList as $k => $v)
$temp[] = $k;
if (count($temp))
$_GET["dhx_colls"] = implode(",",$temp);
}
/*! gets header as array
*/
private function getHeaderArray() {
$head = Array();
$head[0] = $this->headerNames;
$head = $this->getAttaches($head, $this->headerAttaches);
return $head;
}
/*! get footer as array
*/
private function getFooterArray() {
$foot = Array();
$foot = $this->getAttaches($foot, $this->footerAttaches);
return $foot;
}
/*! gets array of data with attaches
*/
private function getAttaches($to, $from) {
for ($i = 0; $i < count($from); $i++) {
$line = $from[$i]['values'];
$to[] = $line;
}
return $to;
}
/*! calculates rowspan array according #cspan markers
*/
private function processCspan($data) {
$rspan = Array();
for ($i = 0; $i < count($data); $i++) {
$last = 0;
$rspan[$i] = Array();
for ($j = 0; $j < count($data[$i]); $j++) {
$rspan[$i][$j] = 0;
if ($data[$i][$j] === '#cspan') {
$rspan[$i][$last]++;
} else {
$last = $j;
}
}
}
return $rspan;
}
/*! calculates colspan array according #rspan markers
*/
private function processRspan($data) {
$last = Array();
$cspan = Array();
for ($i = 0; $i < count($data); $i++) {
$cspan[$i] = Array();
for ($j = 0; $j < count($data[$i]); $j++) {
$cspan[$i][$j] = 0;
if (!isset($last[$j])) $last[$j] = 0;
if ($data[$i][$j] === '#rspan') {
$cspan[$last[$j]][$j]++;
} else {
$last[$j] = $i;
}
}
}
return $cspan;
}
/*! sets mode of output format: usual mode or convert mode.
* @param mode
* true - convert mode, false - otherwise
*/
public function set_convert_mode($mode) {
$this->convert_mode = $mode;
}
/*! adds header configuration in output XML
*/
public function attachHeaderToXML($conn, $out) {
if (!$conn->is_first_call()) return; //render head only for first call
$head = $this->getHeaderArray();
$foot = $this->getFooterArray();
$rspan = $this->processRspan($head);
$cspan = $this->processCspan($head);
$str = '<head>';
if ($this->convert_mode) $str .= "<columns>";
for ($i = 0; $i < count($this->headerNames); $i++) {
$str .= '<column';
$str .= ' type="'. $this->headerTypes[$i].'"';
$str .= ' width="'.$this->headerWidths[$i].'"';
$str .= $this->headerIds ? ' id="'.$this->headerIds[$i].'"' : '';
$str .= $this->headerAlign[$i] ? ' align="'.$this->headerAlign[$i].'"' : '';
$str .= $this->headerVAlign[$i] ? ' valign="'.$this->headerVAlign[$i].'"' : '';
$str .= $this->headerSorts[$i] ? ' sort="'.$this->headerSorts[$i].'"' : '';
$str .= $this->headerColors[$i] ? ' color="'.$this->headerColors[$i].'"' : '';
$str .= $this->headerHidden[$i] ? ' hidden="'.$this->headerHidden[$i].'"' : '';
$str .= $this->headerFormat[$i] ? ' format="'.$this->headerFormat[$i].'"' : '';
$str .= $cspan[0][$i] ? ' colspan="'.($cspan[0][$i] + 1).'"' : '';
$str .= $rspan[0][$i] ? ' rowspan="'.($rspan[0][$i] + 1).'"' : '';
$str .= '>'.$this->headerNames[$i].'</column>';
}
if (!$this->convert_mode) {
$str .= '<settings><colwidth>'.$this->headerWidthsUnits.'</colwidth></settings>';
if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
$str .= '<afterInit>';
}
for ($i = 0; $i < count($this->headerAttaches); $i++) {
$str .= '<call command="attachHeader">';
$str .= '<param>'.implode(",",$this->headerAttaches[$i]['values']).'</param>';
if ($this->headerAttaches[$i]['styles'] != null) {
$str .= '<param>'.implode(",",$this->headerAttaches[$i]['styles']).'</param>';
}
$str .= '</call>';
}
for ($i = 0; $i < count($this->footerAttaches); $i++) {
$str .= '<call command="attachFooter">';
$str .= '<param>'.implode(",",$this->footerAttaches[$i]['values']).'</param>';
if ($this->footerAttaches[$i]['styles'] != null) {
$str .= '<param>'.implode(",",$this->footerAttaches[$i]['styles']).'</param>';
}
$str .= '</call>';
}
if ((count($this->headerAttaches) > 0)||(count($this->footerAttaches) > 0)) {
$str .= '</afterInit>';
}
} else {
$str .= "</columns>";
for ($i = 1; $i < count($head); $i++) {
$str .= "<columns>";
for ($j = 0; $j < count($head[$i]); $j++) {
$str .= '<column';
$str .= $cspan[$i][$j] ? ' colspan="'.($cspan[$i][$j] + 1).'"' : '';
$str .= $rspan[$i][$j] ? ' rowspan="'.($rspan[$i][$j] + 1).'"' : '';
$str .= '>'.$head[$i][$j].'</column>';
}
$str .= "</columns>\n";
}
}
$str .= '</head>';
if ($this->convert_mode && count($foot) > 0) {
$rspan = $this->processRspan($foot);
$cspan = $this->processCspan($foot);
$str .= "<foot>";
for ($i = 0; $i < count($foot); $i++) {
$str .= "<columns>";
for ($j = 0; $j < count($foot[$i]); $j++) {
$str .= '<column';
$str .= $cspan[$i][$j] ? ' colspan="'.($cspan[$i][$j] + 1).'"' : '';
$str .= $rspan[$i][$j] ? ' rowspan="'.($rspan[$i][$j] + 1).'"' : '';
$str .= '>'.$foot[$i][$j].'</column>';
}
$str .= "</columns>\n";
}
$str .= "</foot>";
}
$out->add($str);
}
}
?>
|