Source for file basic_view_list.php

Documentation is available at basic_view_list.php


1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage view
9 * $Id: basic_view_list.php,v 1.31 2005/02/16 05:02:53 jan Exp $
10 */
11 require_once('basic_collection.php');
12 require_once('basic_field.php');
13
14 define('LIMIT', 100);
15
16 class basic_view_list extends basic_collection {
17
18 var $_listobj;
19 var $totalcount;
20 var $offset = 0;
21 var $standardsortcol = 'name';
22 var $standardsortway = 'ASC';
23 var $_preset = false;
24
25 function basic_view_list() {
26 $this->basic_collection();
27 }
28
29 function loadLanguage() {
30 parent::loadLanguage();
31 $this->loadLangFile('basic_view_list');
32 }
33
34 function contextmenu_single() {
35 $result .= basic_collection::contextmenu_single();
36 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_recycle').'", "garbage", "code:window.location.href=\''.$this->callGui($this->otype,'','','listdeleted').'\'"));';
37 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_category').'", "category", ""));';
38 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_filter').'", "filter", ""));';
39 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_advanced').'", "advanced", ""));';
40 return $result;
41 }
42
43 function contextmenu_multiple() {
44 $result .= basic_collection::contextmenu_multiple();
45
46 if ($this->CanView('delete')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_delete').'", "delete", "code:'.$this->modelessdialogdynamic('','delete','jscallerreload,jswindowclose').'"));';
47 if ($this->CanView('createcopy')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_createcopy').'", "createcopy", "code:'.$this->modelessdialogdynamic('','createcopy','jscallerreload,jswindowclose').'"));';
48 if ($this->CanView('createvariant')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_createvariant').'", "createvariant", "code:'.$this->modelessdialogdynamic('','createvariant','jscallerreload,jswindowclose').'"));';
49 if ($this->CanView('createrevision')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_createrevision').'", "createrevision", "code:'.$this->modelessdialogdynamic('','createrevision','jscallerreload,jswindowclose').'"));';
50 if ($this->CanView('requestapproval')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_requestapproval').'", "requestapproval", "code:'.$this->modelessdialogdynamic('','requestapproval','jscallerreload,jswindowclose').'"));';
51 if ($this->CanView('approvepublish')) $result .= 'addMenuItem(new menuItem("'.$this->gl('context_approvepublish').'", "approvepublish", "code:'.$this->modelessdialogdynamic('','approvepublish','jscallerreload,jswindowclose').'"));';
52
53 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_recycle').'", "garbage", "code:window.location.href=\''.$this->callGui($this->otype,'','','listdeleted').'\'"));';
54 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_category').'", "category", ""));';
55 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_filter').'", "filter", ""));';
56 $result .= 'addMenuItem(new menuItem("'.$this->gl('context_advanced').'", "advanced", ""));';
57 return $result;
58 }
59
60 function getColHeader($colname,&$obj) {
61 if (method_exists($this,'getcolheader_'.$colname)) {
62 $methodname = 'getcolheader_'.$colname;
63 return $this->$methodname($colname,$obj);
64 }
65 $txt = $this->gl('label_'.$colname);
66 if (!$txt) $txt = $colname;
67 # return $txt;
68 return $txt . ' [<A HREF="'.$this->ReturnMeURL().'&sortby='.$colname.'&sortway=ASC">+</A>/<A HREF="'.$this->ReturnMeURL().'&sortby='.$colname.'&sortway=DESC">-</A>]';
69 }
70
71 function getColFooter($colname,&$obj) {
72 if (method_exists($this,'getcolfooter_'.$colname)) {
73 $methodname = 'getcolfooter_'.$colname;
74 return $this->$methodname($colname,$obj);
75 }
76 return '&nbsp;';
77 }
78
79 function getColFooter_Name($colname,&$obj) {
80 $result = $this->gl('footer_count') . ' ' . $this->totalcount;
81 return $result;
82 }
83
84 function getInfocolElement($arr,$colname,&$obj) {
85 if ($colname == 'variant' && $arr['object']['hasvariant']) {
86 return '<img src="image/view/infocol_variant.gif" alt="'.$this->gl('alt_variant').'">';
87 }
88 if ($colname == 'permission' && $arr['object']['haspermission']) {
89 return '<img src="image/view/infocol_access.gif" alt="'.$this->gl('alt_access').'">';
90 }
91 if ($colname == 'active' && !$arr['object']['active']) {
92 return '<img src="image/view/infocol_inactive.gif" alt="'.$this->gl('alt_inactive').'">';
93 }
94 if ($colname == 'default' && $arr['object']['standard']) {
95 return '<img src="image/view/infocol_default.gif" alt="'.$this->gl('alt_default').'">';
96 }
97 return "&nbsp;";
98 }
99
100 function getInfocolHeader($colname,&$obj) {
101 return '<img src="image/empty.gif" width="16">';
102 }
103
104 function getInfocolFooter($colname,&$obj) {
105 return '&nbsp;';
106 }
107
108 function setInfocols() {
109 $obj = owNew($this->otype);
110 $_SESSION['gui'][$this->otype]['infocols'] = $obj->stdListInfocol();
111 }
112
113 function setCols($colsetid) {
114 unset($_SESSION['gui'][$this->otype]['cols']);
115 if ($colsetid > 0) {
116 $obj = owRead($colsetid);
117 foreach ($obj->elements[0]['fieldname'] as $cur)
118 $_SESSION['gui'][$this->otype]['cols'][] = $cur;
119 } else {
120 $obj = owNew($this->otype);
121 $_SESSION['gui'][$this->otype]['cols'] = $obj->stdListCol();
122 }
123 }
124
125 function setColsByArray($colset) {
126 unset($_SESSION['gui'][$this->otype]['cols']);
127 if (is_array($colset)) {
128 foreach ($colset as $cur)
129 $_SESSION['gui'][$this->otype]['cols'][] = $cur;
130 }
131 }
132
133 function title() {
134 $result = '<div class="metatitle">';
135
136 $result .= '<!--<div style="float: right"><a href="http://manual.metajour.org/view/'.$this->view.'/otype/'.$this->otype.'" target="_blank"><img src="image/view/title_help.gif" border="0"></A></div>-->
137 <div style="float: right">&nbsp;&nbsp;<a href="'.$this->returnMeUrl().'" target="_blank"><img src="image/view/title_detach.gif" border="0"></A></div>
138 <div style="float: right">'.$this->shadowtext($this->userhandler->getPrgName()).'</div>
139 ';
140
141 if ($this->_preset) {
142 if ($this->userhandler->getGuiLanguage() == 'da') {
143 $text = base64_decode('QmVncuZuc2V0IGRlbW91ZGdhdmU=').'&nbsp;-&nbsp;';
144 } else {
145 $text = base64_decode('TGltaXRlZCBkZW1vIGVkaXRpb24=').'&nbsp;-&nbsp;';
146 }
147 $result .= '<div style="float: right">'.$this->shadowtext($text).'</div>';
148 }
149 $result .= $this->shadowtext($this->gl('title').' :: '.$this->gl('name')).'</div>';
150
151 return $result;
152 }
153
154 function colsBar($colfname='setlistcolarray[]') {
155 $dtcols = owDatatypeColsDesc($this->otype);
156 $result = '<select name="'.$colfname.'" style="width:160px;" multiple>';
157 $obj = owNew($this->otype);
158 foreach ($dtcols as $cur) {
159 $s = '';
160 if (in_array($cur['name'],$_SESSION['gui'][$this->otype]['cols'])) $s = ' SELECTED';
161 $result .= '<option value="'.$cur['name'].'" '.$s.'>Feltet '.$cur['label'].'</option>';
162 }
163 $result .= '</select>';
164 return $result;
165 }
166
167 function searchBar($index=0,$colfname='searchcol', $compfname='searchtype', $textfname='search') {
168 $dtcols = owDatatypeColsDesc($this->otype);
169 $result = '<select name="'.$colfname.'" style="width:160px;">';
170 $obj = owNew($this->otype);
171 $l = $index;
172 foreach ($dtcols as $cur) {
173 $s = '';
174 #$l = sizeof($_SESSION['gui'][$this->otype]['searchcol']) - 1;
175 if ($cur['name'] == $_SESSION['gui'][$this->otype]['searchcol'][$l]) $s = ' SELECTED';
176 $result .= '<option value="'.$cur['name'].'" '.$s.'>'.$this->gl('tool_field').' '.$cur['label'].'</option>';
177 }
178 $result .= '</select>';
179
180 #$l = sizeof($_SESSION['gui'][$this->otype]['searchtype']) - 1;
181 $l = $index;
182 $result .= '<select name="'.$compfname.'" style="width:160px;">';
183 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == LIKE) ? ' SELECTED' : '';
184 $result .= '<option value="'.LIKE.'"'.$s.'>'.$this->gl('tool_like').'</option>';
185 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == LIKESTART) ? ' SELECTED' : '';
186 $result .= '<option value="'.LIKESTART.'"'.$s.'>'.$this->gl('tool_likestart').'</option>';
187 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == LIKEEND) ? ' SELECTED' : '';
188 $result .= '<option value="'.LIKEEND.'"'.$s.'>'.$this->gl('tool_likeend').'</option>';
189 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == GREATER) ? ' SELECTED' : '';
190 $result .= '<option value="'.GREATER.'"'.$s.'>&gt;</option>';
191 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == GREATEREQUAL) ? ' SELECTED' : '';
192 $result .= '<option value="'.GREATEREQUAL.'"'.$s.'>&gt;=</option>';
193 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == LESS) ? ' SELECTED' : '';
194 $result .= '<option value="'.LESS.'"'.$s.'>&lt;</option>';
195 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == LESSEQUAL) ? ' SELECTED' : '';
196 $result .= '<option value="'.LESSEQUAL.'"'.$s.'>&lt;=</option>';
197 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == NOTEQUAL) ? ' SELECTED' : '';
198 $result .= '<option value="'.NOTEQUAL.'"'.$s.'>&lt;&gt;</option>';
199 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == EQUAL) ? ' SELECTED' : '';
200 $result .= '<option value="'.EQUAL.'"'.$s.'>=</option>';
201 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == SOUNDSLIKE) ? ' SELECTED' : '';
202 #$result .= '<option value="'.SOUNDSLIKE.'"'.$s.'>Lyder som</option>';
203 $s = ($_SESSION['gui'][$this->otype]['searchtype'][$l] == NOTSOUNDSLIKE) ? ' SELECTED' : '';
204 #$result .= '<option value="'.NOTSOUNDSLIKE.'"'.$s.'>Lyder ikke som</option>';
205 $result .= '</select>';
206 $result .= '<input type="text" name="'.$textfname.'" value="'.$_SESSION['gui'][$this->otype]['search'][$l].'" style="width: 154px;">';
207 return $result;
208 }
209
210 function categoryBar() {
211 echo '<select name="categoryid" style="width:160px;" onChange="location.href = \''.$this->ReturnMeUrl().'&categoryid=\' + this.options[this.selectedIndex].value;">';
212 $fieldobj = new basic_field($this);
213 echo $fieldobj->listallcategories(@$_SESSION['gui'][$this->otype]['category']);
214 echo '</select>';
215
216 $listcolobj = owNew('listcol');
217 $listcolobj->setlistaccess(true);
218 $listcolobj->setfilter_search('name',$this->otype,EQUAL);
219 $listcolobj->listobjects();
220 echo '<select name="setlistcol" style="width:160px;" onChange="location.href = \''.$this->ReturnMeUrl().'&setlistcol=\' + this.options[this.selectedIndex].value;">';
221 echo '<option value="">'.$this->gl('tool_standardcol').'</option>';
222 if ($listcolobj->elementscount > 0) {
223 foreach ($listcolobj->elements as $cur) {
224 $s = '';
225 if ($cur['objectid'] == $_SESSION['gui'][$this->otype]['listcol']) $s = ' SELECTED';
226 echo '<option value="'.$cur['objectid'].'"'.$s.'>';
227 foreach ($cur['fieldname'] as $curfield) {
228 echo $curfield.',';
229 }
230 echo '</option>';
231 }
232 }
233 echo '</select>';
234
235 echo '<select name="setlistsort" style="width:160px;" onChange="location.href = \''.$this->ReturnMeUrl().'&setlistsort=\' + this.options[this.selectedIndex].value;">';
236 echo '<option value="">'.$this->gl('tool_standardsort').'</option>';
237 $sortcolobj = owNew('sortcol');
238 $sortcolobj->setlistaccess(true);
239 $sortcolobj->setfilter_search('name', $this->otype, EQUAL);
240 $sortcolobj->listobjects();
241 $columnlabels = owDatatypeColsDesc($this->otype);
242 if ($sortcolobj->elementscount > 0) {
243 foreach ($sortcolobj->elements as $cur) {
244 $s = '';
245 if ($cur['objectid'] == $_SESSION['gui'][$this->otype]['sortcol']) $s = ' SELECTED';
246 echo '<option value="'.$cur['objectid'].'"'.$s.'>';
247 foreach ($cur['fieldname'] as $curfield) {
248 echo $columnlabels[$curfield]['label'].',';
249 }
250 echo '</option>';
251 }
252 }
253 echo '</select><br>';
254 }
255
256 function toolBar() {
257 ob_start();
258 echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top">';
259 echo '<form name="listsearch" method="POST" style="margin:0px; spacing:0px; clear: none;" action="'.$this->ReturnMeUrl().'">';
260
261 $this->categoryBar();
262
263 echo $this->searchBar();
264
265 echo '<input type="hidden" name="otype" value="'.$this->otype.'">';
266 echo '</form>';
267 echo '</td><td valign="top" style="padding-left: 5px;">';
268 echo $this->buttonOnClick('search_small.png',$this->gl('img_search'),'document.listsearch.submit()');
269 echo $this->button('list_small.png',$this->gl('img_listall'),$this->ReturnMeUrl().'&clearall=1');
270 if ($this->canView('create')) echo $this->button('create_small.png',$this->gl('img_create'),$this->callgui($this->otype,'','','create','',$this->view,$this->parentid));
271 if ($this->canView('list') && empty($this->parentid) && empty($this->relcol)) echo $this->button('tree_small.png',$this->gl('img_hierarchy'),$this->callgui($this->otype,'','','split'));
272 if ($this->offset > 0) echo $this->button('prev_small.png', 'prev', $this->returnMeUrl() . '&offset=' . ($this->offset - LIMIT) . '&count=' . LIMIT);
273 if ($this->offset + LIMIT < $this->totalcount) echo $this->button('next_small.png', 'next', $this->returnMeUrl() . '&offset=' . ($this->offset + LIMIT) . '&count=' . LIMIT);
274 echo '</td></tr></table>';
275 $result = ob_get_contents();
276 ob_end_clean();
277 return $result;
278 }
279
280 function setFilters() {
281 $obj =& $this->_listobj;
282 if (@$_REQUEST['clearall'] == '1') {
283 /**
284 @todo: hov det går ikke - fjerner oplysninger om user hidden og secret
285 **/
286 unset($_SESSION['gui'][$this->otype]);
287 }
288 $guisession =& $_SESSION['gui'][$this->otype];
289
290 if (!isset($guisession['listcol'])) {
291 $listcolobj = owNew('listcol');
292 $listcolobj->setlistaccess(true);
293 $listcolobj->setfilter_search('name',$this->otype,EQUAL);
294 $listcolobj->setfilter_search('makedefault','1',EQUAL);
295 $listcolobj->listobjects();
296 if ($listcolobj->elementscount > 0) {
297 $guisession['listcol'] = $listcolobj->elements[0]['objectid'];
298 } else {
299 $guisession['listcol'] = 0;
300 }
301 $this->setcols($guisession['listcol']);
302 }
303
304 if (isset($_REQUEST['setlistcol'])) {
305 $guisession['listcol'] = $_REQUEST['setlistcol'];
306 $this->setcols($guisession['listcol']);
307 }
308
309 if (isset($_REQUEST['setlistcolarray'])) {
310 $guisession['listcolarray'] = $_REQUEST['setlistcolarray'];
311 $this->setcolsByArray($guisession['listcolarray']);
312 }
313 if (isset($_REQUEST['createdfrom'])) {
314 $guisession['createdfrom'] = $_REQUEST['createdfrom'];
315 }
316 if (isset($_REQUEST['createdto'])) {
317 $guisession['createdto'] = $_REQUEST['createdto'];
318 }
319 if (isset($guisession['createdfrom'])) {
320 $obj->setfilter_search('created',$guisession['createdfrom']." 00:00:00",GREATEREQUAL);
321 }
322 if (isset($guisession['createdto'])) {
323 $obj->setfilter_search('created',$guisession['createdto']." 23:59:29",LESSEQUAL);
324 }
325
326 if (isset($_REQUEST['setlistsort'])) {
327 $guisession['listsort'] = $_REQUEST['setlistsort'];
328 }
329 ###
330 if (@$_REQUEST['categoryid'] != '')
331 $guisession['category'] = $_REQUEST['categoryid'];
332
333 if (isset($guisession['category']))
334 $obj->setfilter_category($guisession['category']);
335
336 ###
337 if (isset($_REQUEST['search']) && is_array($_REQUEST['search'])) {
338 $guisession['search'] = $_REQUEST['search'];
339 $guisession['searchcol'] = $_REQUEST['searchcol'];
340 $guisession['searchtype'] = $_REQUEST['searchtype'];
341 } elseif (isset($_REQUEST['search'])) {
342 if (@$_REQUEST['search'] != '')
343 $guisession['search'][0] = $_REQUEST['search'];
344 if (@$_REQUEST['searchcol'] != '')
345 $guisession['searchcol'][0] = $_REQUEST['searchcol'];
346 if (@$_REQUEST['searchtype'] != '')
347 $guisession['searchtype'][0] = $_REQUEST['searchtype'];
348 }
349 if (isset($guisession['searchcol']) && $guisession['searchcol'][0] != '') {
350 $count = 0;
351 foreach ($guisession['searchcol'] as $c) {
352 if (!empty($guisession['search'][$count]))
353 $obj->setfilter_advsearch($guisession['searchcol'][$count],$guisession['search'][$count],$guisession['searchtype'][$count]);
354 $count++;
355 }
356 } else {
357 if (isset($guisession['search']))
358 $obj->setfilter_name($guisession['search']);
359 }
360
361
362 ###
363 if (isset($_REQUEST['sortby']))
364 $guisession['sortby'] = $_REQUEST['sortby'];
365
366 if (isset($_REQUEST['sortway']))
367 $guisession['sortway'] = $_REQUEST['sortway'];
368
369 if (isset($guisession['sortby'])) {
370 $obj->setsort_col($guisession['sortby']);
371 $obj->setsort_way($guisession['sortway']);
372 } else {
373 $obj->setsort_col($this->standardsortcol);
374 $obj->setsort_way($this->standardsortway);
375 }
376 ###
377 if (isset($_SESSION[$this->otype]['filter_approved'])) $obj->setfilter_approved($_SESSION[$this->otype]['filter_approved']);
378 if (isset($_SESSION[$this->otype]['filter_datacol'])) $obj->setfilter_data($_SESSION[$this->otype]['filter_datacol'],$_SESSION[$this->otype]['filter_datavalue']);
379
380 $obj->setlistaccess(true);
381 $obj->setfilter_getname(true);
382 /**
383 * @todo: make setfilter_data work on multiple calls
384 */
385 if ($this->data['_relcol']) $obj->setfilter_data($this->data['_relcol'],$this->data['_relval']);
386
387 }
388
389 function setLimits() {
390 $obj =& $this->_listobj;
391
392 if (isset($_REQUEST['offset'])) {
393 $obj->setfilter_limit($_REQUEST['offset'], LIMIT);
394 $this->offset = $_REQUEST['offset'];
395 } else {
396 $obj->setfilter_limit(0, LIMIT);
397 $this->offset = 0;
398 }
399
400 }
401
402
403 function view() {
404 #owReIndexAll();
405 basic_collection::view();
406
407 $this->_listobj = owNew($this->otype);
408 $obj =& $this->_listobj;
409 $this->setFilters();
410 #echo $obj->_getsql(0,0);
411 $guisession =& $_SESSION['gui'][$this->otype];
412
413 if ($this->parentid) {
414 $this->totalcount = $obj->getNumElements($this->parentid);
415 } else {
416 $this->totalcount = $obj->getNumElements(0);
417 }
418
419
420 if ($this->totalcount > LIMIT) {
421 $this->setLimits();
422 }
423
424 if ($this->parentid) {
425 $obj->listobjects($this->parentid);
426 } else {
427 $obj->listobjects(0);
428 }
429 echo '<div class="metawindow">';
430 echo $this->title();
431 echo $this->toolbar();
432 echo '<table id="st" class="metalist" onselectstart="return false" style="width: 100%">';
433 echo '<tr class="metalistheadrow" id="headerrow">';
434
435 if (!isset($_SESSION['gui'][$this->otype]['infocols'])) $this->setinfocols();
436 $i = 0;
437 $userhandler =& $this->userhandler;
438 foreach ($guisession['cols'] as $curheader) {
439 if (!$userhandler->isFieldHidden($this->otype,$curheader) &&