1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//------------------------------------------------------------------------------ |
4
|
|
|
// |
5
|
|
|
// eTraxis - Records tracking web-based system |
6
|
|
|
// Copyright (C) 2006-2011 Artem Rodygin |
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 3 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, see <http://www.gnu.org/licenses/>. |
20
|
|
|
// |
21
|
|
|
//------------------------------------------------------------------------------ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Views |
25
|
|
|
* |
26
|
|
|
* This module provides API to work with user views. |
27
|
|
|
* See also {@link https://github.com/etraxis/etraxis-obsolete/wiki/tbl_views tbl_views} database table. |
28
|
|
|
* |
29
|
|
|
* @package DBO |
30
|
|
|
* @subpackage Views |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/**#@+ |
34
|
|
|
* Dependency. |
35
|
|
|
*/ |
36
|
|
|
require_once('../engine/engine.php'); |
37
|
|
|
require_once('../dbo/accounts.php'); |
38
|
|
|
require_once('../dbo/filters.php'); |
39
|
|
|
/**#@-*/ |
40
|
|
|
|
41
|
|
|
//------------------------------------------------------------------------------ |
42
|
|
|
// Definitions. |
43
|
|
|
//------------------------------------------------------------------------------ |
44
|
|
|
|
45
|
|
|
/**#@+ |
46
|
|
|
* Data restriction. |
47
|
|
|
*/ |
48
|
|
|
define('MAX_VIEW_NAME', 50); |
49
|
|
|
define('MAX_VIEW_SIZE', 20); |
50
|
|
|
/**#@-*/ |
51
|
|
|
|
52
|
|
|
/**#@+ |
53
|
|
|
* Standard column type. |
54
|
|
|
*/ |
55
|
|
|
define('COLUMN_TYPE_MINIMUM', 1); |
56
|
|
|
define('COLUMN_TYPE_ID', 1); |
57
|
|
|
define('COLUMN_TYPE_PROJECT', 2); |
58
|
|
|
define('COLUMN_TYPE_STATE_ABBR', 3); |
59
|
|
|
define('COLUMN_TYPE_SUBJECT', 4); |
60
|
|
|
define('COLUMN_TYPE_AUTHOR', 5); |
61
|
|
|
define('COLUMN_TYPE_RESPONSIBLE', 6); |
62
|
|
|
define('COLUMN_TYPE_LAST_EVENT', 7); |
63
|
|
|
define('COLUMN_TYPE_AGE', 8); |
64
|
|
|
define('COLUMN_TYPE_CREATION_DATE', 9); |
65
|
|
|
define('COLUMN_TYPE_TEMPLATE', 10); |
66
|
|
|
define('COLUMN_TYPE_STATE_NAME', 11); |
67
|
|
|
define('COLUMN_TYPE_LAST_STATE', 12); |
68
|
|
|
define('COLUMN_TYPE_MAXIMUM', 12); |
69
|
|
|
/**#@-*/ |
70
|
|
|
|
71
|
|
|
/**#@+ |
72
|
|
|
* Custom column type. |
73
|
|
|
*/ |
74
|
|
|
define('COLUMN_TYPE_NUMBER', 100); |
75
|
|
|
define('COLUMN_TYPE_STRING', 101); |
76
|
|
|
define('COLUMN_TYPE_MULTILINED', 102); |
77
|
|
|
define('COLUMN_TYPE_CHECKBOX', 103); |
78
|
|
|
define('COLUMN_TYPE_LIST_NUMBER', 104); |
79
|
|
|
define('COLUMN_TYPE_LIST_STRING', 105); |
80
|
|
|
define('COLUMN_TYPE_RECORD', 106); |
81
|
|
|
define('COLUMN_TYPE_DATE', 107); |
82
|
|
|
define('COLUMN_TYPE_DURATION', 108); |
83
|
|
|
define('COLUMN_TYPE_FLOAT', 109); |
84
|
|
|
/**#@-*/ |
85
|
|
|
|
86
|
|
|
// Column type resources. |
87
|
|
|
$column_type_res = array |
88
|
|
|
( |
89
|
|
|
// standard |
90
|
|
|
COLUMN_TYPE_ID => RES_ID_ID, |
91
|
|
|
COLUMN_TYPE_STATE_ABBR => RES_STATE_ID, |
92
|
|
|
COLUMN_TYPE_PROJECT => RES_PROJECT_ID, |
93
|
|
|
COLUMN_TYPE_SUBJECT => RES_SUBJECT_ID, |
94
|
|
|
COLUMN_TYPE_AUTHOR => RES_AUTHOR_ID, |
95
|
|
|
COLUMN_TYPE_RESPONSIBLE => RES_RESPONSIBLE_ID, |
96
|
|
|
COLUMN_TYPE_LAST_EVENT => RES_LAST_EVENT_ID, |
97
|
|
|
COLUMN_TYPE_AGE => RES_AGE_ID, |
98
|
|
|
COLUMN_TYPE_CREATION_DATE => RES_CREATED_ID, |
99
|
|
|
COLUMN_TYPE_TEMPLATE => RES_TEMPLATE_ID, |
100
|
|
|
COLUMN_TYPE_STATE_NAME => RES_STATE_NAME_ID, |
101
|
|
|
COLUMN_TYPE_LAST_STATE => RES_LAST_STATE_ID, |
102
|
|
|
|
103
|
|
|
// custom |
104
|
|
|
COLUMN_TYPE_NUMBER => RES_NUMBER_ID, |
105
|
|
|
COLUMN_TYPE_FLOAT => RES_DECIMAL_ID, |
106
|
|
|
COLUMN_TYPE_STRING => RES_STRING_ID, |
107
|
|
|
COLUMN_TYPE_MULTILINED => RES_MULTILINED_TEXT_ID, |
108
|
|
|
COLUMN_TYPE_CHECKBOX => RES_CHECKBOX_ID, |
109
|
|
|
COLUMN_TYPE_LIST_NUMBER => RES_LIST_INDEXES_ID, |
110
|
|
|
COLUMN_TYPE_LIST_STRING => RES_LIST_VALUES_ID, |
111
|
|
|
COLUMN_TYPE_RECORD => RES_RECORD_ID, |
112
|
|
|
COLUMN_TYPE_DATE => RES_DATE_ID, |
113
|
|
|
COLUMN_TYPE_DURATION => RES_DURATION_ID, |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
//------------------------------------------------------------------------------ |
117
|
|
|
// Functions. |
118
|
|
|
//------------------------------------------------------------------------------ |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Finds in database and returns the information about specified view. |
122
|
|
|
* |
123
|
|
|
* @param int $id View ID. |
124
|
|
|
* @return array Array with data if view is found in database, FALSE otherwise. |
125
|
|
|
*/ |
126
|
|
|
function view_find ($id) |
127
|
|
|
{ |
128
|
|
|
debug_write_log(DEBUG_TRACE, '[view_find]'); |
129
|
|
|
debug_write_log(DEBUG_DUMP, '[view_find] $id = ' . $id); |
130
|
|
|
|
131
|
|
|
$rs = dal_query('views/fndid.sql', $id, $_SESSION[VAR_USERID]); |
132
|
|
|
|
133
|
|
|
return ($rs->rows == 0 ? FALSE : $rs->fetch()); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns {@link CRecordset DAL recordset} which contains all existing views of logged in user. |
138
|
|
|
* |
139
|
|
|
* @param int &$sort Sort mode (used as output only). The function retrieves current sort mode from |
140
|
|
|
* client cookie ({@link COOKIE_VIEWS_SORT}) and updates it, if it's out of valid range. |
141
|
|
|
* @param int &$page Number of current page tab (used as output only). The function retrieves current |
142
|
|
|
* page from client cookie ({@link COOKIE_VIEWS_PAGE}) and updates it, if it's out of valid range. |
143
|
|
|
* @return CRecordset Recordset with list of views. |
144
|
|
|
*/ |
145
|
|
|
function views_list (&$sort, &$page) |
146
|
|
|
{ |
147
|
|
|
debug_write_log(DEBUG_TRACE, '[views_list]'); |
148
|
|
|
|
149
|
|
|
$sort_modes = array |
150
|
|
|
( |
151
|
|
|
1 => 'view_name asc', |
152
|
|
|
2 => 'view_name desc', |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$sort = try_request('sort', try_cookie(COOKIE_VIEWS_SORT, 1)); |
156
|
|
|
$sort = ustr2int($sort, 1, count($sort_modes)); |
157
|
|
|
|
158
|
|
|
$page = try_request('page', try_cookie(COOKIE_VIEWS_PAGE)); |
159
|
|
|
$page = ustr2int($page, 1, MAXINT); |
160
|
|
|
|
161
|
|
|
save_cookie(COOKIE_VIEWS_SORT, $sort); |
162
|
|
|
save_cookie(COOKIE_VIEWS_PAGE, $page); |
163
|
|
|
|
164
|
|
|
return dal_query('views/list.sql', $_SESSION[VAR_USERID], $sort_modes[$sort]); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Validates view information before creation or modification. |
169
|
|
|
* |
170
|
|
|
* @param string $view_name View name. |
171
|
|
|
* @return int Error code: |
172
|
|
|
* <ul> |
173
|
|
|
* <li>{@link NO_ERROR} - data are valid</li> |
174
|
|
|
* <li>{@link ERROR_INCOMPLETE_FORM} - at least one of required field is empty</li> |
175
|
|
|
* </ul> |
176
|
|
|
*/ |
177
|
|
View Code Duplication |
function view_validate ($view_name) |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
debug_write_log(DEBUG_TRACE, '[view_validate]'); |
180
|
|
|
debug_write_log(DEBUG_DUMP, '[view_validate] $view_name = ' . $view_name); |
181
|
|
|
|
182
|
|
|
if (ustrlen($view_name) == 0) |
183
|
|
|
{ |
184
|
|
|
debug_write_log(DEBUG_NOTICE, '[view_validate] At least one required field is empty.'); |
185
|
|
|
return ERROR_INCOMPLETE_FORM; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return NO_ERROR; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Creates new view for specified user. |
193
|
|
|
* |
194
|
|
|
* @param int $account_id User ID. |
195
|
|
|
* @param string $view_name View name. |
196
|
|
|
* @return int Error code: |
197
|
|
|
* <ul> |
198
|
|
|
* <li>{@link NO_ERROR} - view is successfully created</li> |
199
|
|
|
* <li>{@link ERROR_ALREADY_EXISTS} - view with specified name already exists</li> |
200
|
|
|
* <li>{@link ERROR_NOT_FOUND} - failure on attempt to create view</li> |
201
|
|
|
* </ul> |
202
|
|
|
*/ |
203
|
|
|
function view_create ($account_id, $view_name) |
204
|
|
|
{ |
205
|
|
|
debug_write_log(DEBUG_TRACE, '[view_create]'); |
206
|
|
|
debug_write_log(DEBUG_DUMP, '[view_create] $account_id = ' . $account_id); |
207
|
|
|
debug_write_log(DEBUG_DUMP, '[view_create] $view_name = ' . $view_name); |
208
|
|
|
|
209
|
|
|
// Check that user doesn't have another view with the same name. |
210
|
|
|
$rs = dal_query('views/fndk.sql', $account_id, ustrtolower($view_name)); |
211
|
|
|
|
212
|
|
|
if ($rs->rows != 0) |
|
|
|
|
213
|
|
|
{ |
214
|
|
|
debug_write_log(DEBUG_NOTICE, '[view_create] View already exists.'); |
215
|
|
|
return ERROR_ALREADY_EXISTS; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// Create a view. |
219
|
|
|
dal_query('views/create.sql', |
220
|
|
|
$account_id, |
221
|
|
|
$view_name); |
222
|
|
|
|
223
|
|
|
// Find newly created view. |
224
|
|
|
$rs = dal_query('views/fndk.sql', $account_id, ustrtolower($view_name)); |
225
|
|
|
|
226
|
|
|
if ($rs->rows == 0) |
|
|
|
|
227
|
|
|
{ |
228
|
|
|
debug_write_log(DEBUG_WARNING, '[view_create] Created view not found.'); |
229
|
|
|
return ERROR_NOT_FOUND; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// Get an ID of the created view. |
233
|
|
|
$view_id = $rs->fetch('view_id'); |
234
|
|
|
|
235
|
|
|
// Create default set of columns for new view. |
236
|
|
|
$columns = array(); |
237
|
|
|
|
238
|
|
|
for ($i = COLUMN_TYPE_MINIMUM; $i <= COLUMN_TYPE_AGE; $i++) |
239
|
|
|
{ |
240
|
|
|
array_push($columns, "{$i}::"); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
columns_add($view_id, $columns); |
244
|
|
|
|
245
|
|
|
return NO_ERROR; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Modifies specified view. |
250
|
|
|
* |
251
|
|
|
* @param int $id ID of view to be modified. |
252
|
|
|
* @param string $view_name New view name. |
253
|
|
|
* @return int Error code: |
254
|
|
|
* <ul> |
255
|
|
|
* <li>{@link NO_ERROR} - view is successfully modified</li> |
256
|
|
|
* <li>{@link ERROR_ALREADY_EXISTS} - view with specified name already exists</li> |
257
|
|
|
* </ul> |
258
|
|
|
*/ |
259
|
|
|
function view_modify ($id, $view_name) |
260
|
|
|
{ |
261
|
|
|
debug_write_log(DEBUG_TRACE, '[view_modify]'); |
262
|
|
|
debug_write_log(DEBUG_DUMP, '[view_modify] $id = ' . $id); |
263
|
|
|
debug_write_log(DEBUG_DUMP, '[view_modify] $view_name = ' . $view_name); |
264
|
|
|
|
265
|
|
|
// Check that user doesn't have another view with the same name, besides this one. |
266
|
|
|
$rs = dal_query('views/fndku.sql', $id, $_SESSION[VAR_USERID], ustrtolower($view_name)); |
267
|
|
|
|
268
|
|
|
if ($rs->rows != 0) |
|
|
|
|
269
|
|
|
{ |
270
|
|
|
debug_write_log(DEBUG_NOTICE, '[view_modify] View already exists.'); |
271
|
|
|
return ERROR_ALREADY_EXISTS; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// Modify the view. |
275
|
|
|
dal_query('views/modify.sql', |
276
|
|
|
$id, |
277
|
|
|
$view_name); |
278
|
|
|
|
279
|
|
|
return NO_ERROR; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Deletes specified views. |
284
|
|
|
* |
285
|
|
|
* @param array $views List of views IDs. |
286
|
|
|
* @return int Always {@link NO_ERROR}. |
287
|
|
|
*/ |
288
|
|
|
function views_delete ($views) |
289
|
|
|
{ |
290
|
|
|
debug_write_log(DEBUG_TRACE, '[views_delete]'); |
291
|
|
|
|
292
|
|
|
// If current view is in list of views to be deleted, change it to unknown. |
293
|
|
|
if (in_array($_SESSION[VAR_VIEW], $views)) |
294
|
|
|
{ |
295
|
|
|
filters_clear(); |
296
|
|
|
account_set_view(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
// Delete each of specified views. |
300
|
|
|
foreach ($views as $view) |
301
|
|
|
{ |
302
|
|
|
dal_query('views/clrview.sql', $view); |
303
|
|
|
dal_query('views/fdelall.sql', $view); |
304
|
|
|
dal_query('views/cdelall.sql', $view); |
305
|
|
|
dal_query('views/delete.sql', $view); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return NO_ERROR; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Returns array which contains IDs of all filters of specified set view. |
313
|
|
|
* |
314
|
|
|
* @param int $id ID of the view. |
315
|
|
|
* @return array List of columns of the view. |
316
|
|
|
*/ |
317
|
|
|
function view_filters_list ($id) |
318
|
|
|
{ |
319
|
|
|
debug_write_log(DEBUG_TRACE, '[view_filters_list]'); |
320
|
|
|
debug_write_log(DEBUG_DUMP, '[view_filters_list] id = ' . $id); |
321
|
|
|
|
322
|
|
|
$list = array(); |
323
|
|
|
|
324
|
|
|
$rs = dal_query('views/flist.sql', $id); |
325
|
|
|
|
326
|
|
|
while (($row = $rs->fetch())) |
327
|
|
|
{ |
328
|
|
|
array_push($list, $row['filter_id']); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
return $list; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Finds in database and returns the information about specified column. |
336
|
|
|
* |
337
|
|
|
* @param int $id Column ID. |
338
|
|
|
* @return array Array with data if column is found in database, FALSE otherwise. |
339
|
|
|
*/ |
340
|
|
|
function column_find ($id) |
341
|
|
|
{ |
342
|
|
|
debug_write_log(DEBUG_TRACE, '[column_find]'); |
343
|
|
|
debug_write_log(DEBUG_DUMP, '[column_find] $id = ' . $id); |
344
|
|
|
|
345
|
|
|
$rs = dal_query('columns/fndid.sql', $id, $_SESSION[VAR_USERID]); |
346
|
|
|
|
347
|
|
|
return ($rs->rows == 0 ? FALSE : $rs->fetch()); |
|
|
|
|
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns array which contains all columns of specified set view. |
352
|
|
|
* |
353
|
|
|
* @param int $id ID of the view (skip to get currently set view). |
354
|
|
|
* @return array List of columns of the view. Each item is an array with following keys: |
355
|
|
|
* <ul> |
356
|
|
|
* <li>column_id,</li> |
357
|
|
|
* <li>state_name,</li> |
358
|
|
|
* <li>field_name,</li> |
359
|
|
|
* <li>column_type,</li> |
360
|
|
|
* <li>column_order.</li> |
361
|
|
|
* </ul> |
362
|
|
|
*/ |
363
|
|
|
function columns_list ($id = NULL) |
364
|
|
|
{ |
365
|
|
|
debug_write_log(DEBUG_TRACE, '[columns_list]'); |
366
|
|
|
debug_write_log(DEBUG_DUMP, '[columns_list] id = ' . $id); |
367
|
|
|
|
368
|
|
|
if ($id == NULL) |
|
|
|
|
369
|
|
|
{ |
370
|
|
|
$id = $_SESSION[VAR_VIEW]; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$columns = array(); |
374
|
|
|
|
375
|
|
|
// Find all columns of currently set view. |
376
|
|
|
if (get_user_level() == USER_LEVEL_GUEST || is_null($id)) |
377
|
|
|
{ |
378
|
|
|
for ($i = COLUMN_TYPE_MINIMUM; $i <= COLUMN_TYPE_AGE; $i++) |
379
|
|
|
{ |
380
|
|
|
array_push($columns, array('column_id' => $i, |
381
|
|
|
'state_name' => NULL, |
382
|
|
|
'field_name' => NULL, |
383
|
|
|
'column_type' => $i, |
384
|
|
|
'column_order' => $i)); |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
else |
388
|
|
|
{ |
389
|
|
|
$rs = dal_query('columns/list.sql', $id); |
390
|
|
|
|
391
|
|
|
// Push all returned data from recordset to resulted array. |
392
|
|
|
while (($row = $rs->fetch()) && (count($columns) < MAX_VIEW_SIZE)) |
393
|
|
|
{ |
394
|
|
|
array_push($columns, array('column_id' => $row['column_id'], |
395
|
|
|
'state_name' => $row['state_name'], |
396
|
|
|
'field_name' => $row['field_name'], |
397
|
|
|
'column_type' => $row['column_type'], |
398
|
|
|
'column_order' => $row['column_order'])); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
return $columns; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Returns number of columns in the specified view. |
407
|
|
|
* |
408
|
|
|
* @param int $id ID of the view. |
409
|
|
|
* @return int Current number of columns. |
410
|
|
|
*/ |
411
|
|
|
function columns_count ($id) |
412
|
|
|
{ |
413
|
|
|
debug_write_log(DEBUG_TRACE, '[columns_count]'); |
414
|
|
|
debug_write_log(DEBUG_DUMP, '[columns_cound] id = ' . $id); |
415
|
|
|
|
416
|
|
|
$rs = dal_query('columns/count.sql', $id); |
417
|
|
|
|
418
|
|
|
return $rs->fetch(0); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Adds specified columns to the specified view. |
423
|
|
|
* |
424
|
|
|
* @param int $id ID of the view. |
425
|
|
|
* @param array $columns List of columns. Each item is a string, concatenated of following data, separated by colon: |
426
|
|
|
* <ul> |
427
|
|
|
* <li>column_type,</li> |
428
|
|
|
* <li>state_name,</li> |
429
|
|
|
* <li>field_name.</li> |
430
|
|
|
* </ul> |
431
|
|
|
* @return int Error code: |
432
|
|
|
* <ul> |
433
|
|
|
* <li>{@link NO_ERROR} - columns are successfully added</li> |
434
|
|
|
* <li>{@link ERROR_INTEGER_VALUE_OUT_OF_RANGE} - maximum allowed number of columns is reached</li> |
435
|
|
|
* </ul> |
436
|
|
|
*/ |
437
|
|
|
function columns_add ($id, $columns) |
438
|
|
|
{ |
439
|
|
|
debug_write_log(DEBUG_TRACE, '[columns_add]'); |
440
|
|
|
debug_write_log(DEBUG_DUMP, '[columns_add] id = ' . $id); |
441
|
|
|
|
442
|
|
|
// Get current number of columns in the view. |
443
|
|
|
$count = columns_count($id); |
444
|
|
|
|
445
|
|
|
// Add each if specified columns. |
446
|
|
|
foreach ($columns as $column) |
447
|
|
|
{ |
448
|
|
|
// Stop, if view already has maximum allowed number of columns. |
449
|
|
|
if ($count == MAX_VIEW_SIZE) |
450
|
|
|
{ |
451
|
|
|
return ERROR_INTEGER_VALUE_OUT_OF_RANGE; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
// Split string with column information into pieces. |
455
|
|
|
list($type, $state, $field) = ustr_getcsv($column, ':', '\''); |
456
|
|
|
|
457
|
|
|
// Add new column to the view. |
458
|
|
|
dal_query('columns/create.sql', $id, $state, $field, $type, ++$count); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
return NO_ERROR; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Removes specified columns from the specified view. |
466
|
|
|
* |
467
|
|
|
* @param int $id ID of the view. |
468
|
|
|
* @param array $columns List of columns IDs. |
469
|
|
|
* @return int Always {@link NO_ERROR}. |
470
|
|
|
*/ |
471
|
|
|
function columns_remove ($id, $columns) |
472
|
|
|
{ |
473
|
|
|
debug_write_log(DEBUG_TRACE, '[columns_remove]'); |
474
|
|
|
debug_write_log(DEBUG_DUMP, '[columns_remove] id = ' . $id); |
475
|
|
|
|
476
|
|
|
// Delete each of specified columns. |
477
|
|
|
foreach ($columns as $column) |
478
|
|
|
{ |
479
|
|
|
dal_query('columns/delete.sql', $column); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
// Enumerate the rest of columns of currently set view. |
483
|
|
|
$rs = dal_query('columns/list.sql', $id); |
484
|
|
|
|
485
|
|
|
// Reorder the rest of columns of currently set view. |
486
|
|
|
for ($i = 0; ($row = $rs->fetch()) && ($i < MAX_VIEW_SIZE); $i++) |
487
|
|
|
{ |
488
|
|
|
dal_query('columns/setorder.sql', $id, $row['column_order'], $i + 1); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
// View cannot contain no columns ... |
492
|
|
|
if (columns_count($id) == 0) |
493
|
|
|
{ |
494
|
|
|
// ... add default one if all previous were removed. |
495
|
|
|
dal_query('columns/create.sql', $id, NULL, NULL, COLUMN_TYPE_ID, 1); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return NO_ERROR; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
?> |
|
|
|
|
502
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.