31 import(
'Dataface/Table.php');
32 import(
'Dataface/QueryBuilder.php');
33 import(
'Dataface/Record.php');
34 import(
'Dataface/QueryTool.php');
54 if (empty($db) ) $db =
$app->db();
57 if ( !is_array(
$columns) ) $this->_columns = array();
58 $this->_query = $query;
59 if( !is_array($query) ) $this->_query = array();
62 $fieldnames = array_keys($this->_table->fields(
false,
true));
63 $fields =& $this->_table->fields(
false,
true);
65 if ( count($this->_columns)==0 ){
67 foreach ($fieldnames as
$field){
68 if ( @$fields[$field][
'filter'] ) $this->_filterCols[] =
$field;
69 if ( $fields[$field][
'visibility'][
'list'] !=
'visible')
continue;
70 if ( $this->_table->isPassword($field) )
continue;
71 if ( isset( $fields[$field] ) and !preg_match(
'/blob/i', $fields[$field][
'Type']) ){
72 $this->_columns[] =
$field;
80 foreach ($fieldnames as
$field){
81 if ( @$fields[$field][
'filter'] ) $this->_filterCols[] =
$field;
91 $del =& $record->_table->getDelegate();
92 if ( isset($del) and method_exists($del,
$fieldname.
'__renderCell') ){
94 return $del->$method($record);
99 if ( !@
$field[
'noEditInListView'] and @
$field[
'noLinkFromListView'] and $record->checkPermission(
'edit', array(
'field'=>
$fieldname) ) ){
100 $recid = $record->getId();
101 $out =
'<span df:showlink="1" df:id="'.$recid.
'#'.
$fieldname.
'" class="df__editable">'.
$out.
'</span>';
108 $del =& $this->_table->getDelegate();
109 if ( isset($del) and method_exists($del,
'renderRowHeader') ){
113 $appdel =&
$app->getDelegate();
114 if ( isset($appdel) and method_exists($appdel,
'renderRowHeader') ){
121 $del =& $record->_table->getDelegate();
122 if ( isset($del) and method_exists($del,
'renderRow') ){
123 return $del->renderRow($record);
126 $appdel =&
$app->getDelegate();
127 if ( isset($appdel) and method_exists($appdel,
'renderRow') ){
128 return $appdel->renderRow($record);
134 if ( !isset($this->_results) ){
149 $this->_resultSet->loadSet(null,
true,
false,
true);
159 $query =&
$app->getQuery();
160 if ( isset( $query[
'-sort']) ){
161 $sortcols = explode(
',', trim($query[
'-sort']));
162 $sort_columns = array();
163 foreach ($sortcols as $sortcol){
164 $sortcol = trim($sortcol);
165 if (strlen($sortcol) === 0 )
continue;
166 $sortcol = explode(
' ', $sortcol);
167 if ( count($sortcol) > 1 ){
168 $sort_columns[$sortcol[0]] = strtolower($sortcol[1]);
170 $sort_columns[$sortcol[0]] =
'asc';
176 $sort_columns = array();
184 if ( $this->_resultSet->found() > 0 ) {
187 if ( @
$app->prefs[
'use_old_resultlist_controller'] ){
189 df_display(array(),
'Dataface_ResultListController.html');
190 $controller = ob_get_contents();
197 if ( !defined(
'Dataface_ResultList_Javascript') ){
198 define(
'Dataface_ResultList_Javascript',
true);
200 $jt->import(
'Dataface/ResultList.js');
205 if ( !@
$app->prefs[
'hide_result_filters'] and count($this->_filterCols) > 0 ){
210 if ( @
$app->prefs[
'use_old_resultlist_controller'] ){
211 echo
'<div class="resultlist-controller" id="resultlist-controller-top">';
220 if ( !@
$app->prefs[
'disable_select_rows'] ){
226 $sq = $myq =
$app->getQuery();
227 foreach ($sq as $sqk=>$sqv ){
228 if ( !$sqk or $sqk{0} ==
'-' ){
232 if ( @$myq[
'-sort'] ) $sq[
'-sort'] = $myq[
'-sort'];
233 if ( @$myq[
'-skip'] ) $sq[
'-skip'] = $myq[
'-skip'];
234 if ( @$myq[
'-limit'] ) $sq[
'-limit'] = $myq[
'-limit'];
237 $sq = json_encode($sq);
239 $jt->import(
'list.js');
241 <table data-xataface-query="'.htmlspecialchars($sq).
'" id="result_list" class="listing resultList resultList--'.$this->_tablename.
'">
245 echo
'<th><input type="checkbox" onchange="toggleSelectedRows(this,\'result_list\');"></th>';
248 if ( !@
$app->prefs[
'disable_ajax_record_details'] ){
249 echo
' <th><!-- Expand record column --></th>
252 echo
'<th class="row-actions-header"></th>';
257 foreach ($this->_columns as $key){
258 $cursor=$this->_resultSet->start();
260 $perms[$key] =
false;
261 while ( $results->hasNext() ){
262 $record = $results->next();
263 if ( $record->checkPermission(
'list', array(
"field"=>$key)) ){
273 if ( isset($rowHeaderHtml) ){
279 foreach ($this->_columns as $key ){
280 if ( in_array($key, $this->_columns) ){
282 if ( !@$perms[$key] )
continue;
283 if ( isset($sort_columns[$key]) ){
284 $class =
'sorted-column-'.$sort_columns[$key];
286 $qs_columns = $sort_columns;
287 unset($qs_columns[$key]);
288 $sort_query = $key.
' '.($sort_columns[$key] ==
'desc' ?
'asc' :
'desc');
289 foreach ( $qs_columns as $qcolkey=> $qcolvalue){
290 $sort_query .=
', '.$qcolkey.
' '.$qcolvalue;
293 $class =
'unsorted-column';
294 $sort_query = $key.
' asc';
295 foreach ( $sort_columns as $scolkey=>$scolvalue){
296 $sort_query .=
', '.$scolkey.
' '.$scolvalue;
300 $sq = array(
'-sort'=>$sort_query);
303 $label = $this->_table->getFieldProperty(
'column:label', $key);
304 $legend = $this->_table->getFieldProperty(
'column:legend', $key);
306 $legend =
'<span class="column-legend">'.htmlspecialchars($legend).
'</span>';
309 $colType = $this->_table->getType($key);
310 $class .=
' coltype-'.$colType;
311 $cperms = $this->_table->getPermissions(array(
'field'=>$key));
312 if ( !$this->_table->isSearchable($key) or !@$cperms[
'find'] ){
313 $class .=
' unsearchable-column';
315 $class .=
' searchable-column';
318 $class .=
' '.$this->getHeaderCellClass($key);
320 if ( !$label ) $label = $this->_table->getFieldProperty(
'widget:label',$key);
321 echo
"<th data-column=\"$key\" class=\"$class\"><a href=\"$link\">".htmlspecialchars($label).
"</a> $legend</th>";
331 $cursor=$this->_resultSet->start();
333 $baseQuery = array();
334 foreach ( $_GET as $key=>$value){
335 if ( strpos($key,
'-') !== 0 ){
336 $baseQuery[$key] = $value;
340 while ($results->hasNext() ){
341 $rowClass = $evenRow ?
'even' :
'odd';
342 $evenRow = !$evenRow;
343 $record =& $results->next();
344 $recperms = $record->getPermissions();
346 if ( !@$recperms[
'view'] ){
351 $rowClass .=
' '.$this->getRowClass($record);
355 $query = array_merge( $baseQuery, array(
"-action"=>
"browse",
"-relationship"=>null,
"-cursor"=>$cursor++) );
357 if ( @$recperms[
'link'] ){
358 if ( @
$app->prefs[
'result_list_use_geturl'] ){
359 $link = $record->getURL(
'-action=view');
365 $del =& $record->_table->getDelegate();
366 if ( $del and method_exists($del,
'no_access_link') ){
367 $link = $del->no_access_link($record);
372 $recordid = $record->getId();
375 echo
"<tr class=\"listing $rowClass\">";
378 foreach ($recperms as $pk=>$pv){
379 if ( $pv ) $permStr[] = $pk;
381 $permStr = htmlspecialchars(implode(
',', $permStr));
382 echo
'<td class="checkbox-cell"><input class="rowSelectorCheckbox" xf-record-id="'.htmlspecialchars($recordid).
'" id="rowSelectorCheckbox:'.htmlspecialchars($recordid).
'" type="checkbox" data-xf-permissions="'.$permStr.
'"></td>';
388 if ( !@
$app->prefs[
'disable_ajax_record_details'] ){
389 echo
'<td class="ajax-record-details-cell">';
390 echo
'<script language="javascript" type="text/javascript"><!--
391 registerRecord(\''.addslashes($recordid).
'\',
'.$record->toJS(array()).');
393 <img src=
"'.DATAFACE_URL.'/images/treeCollapsed.gif" onclick=
"resultList.showRecordDetails(this, \''.addslashes($recordid).'\')"/>
';
397 unset($at, $actions);
400 $at =& Dataface_ActionTool::getInstance();
401 $actions = $at->getActions(array('category
'=>'list_row_actions
', 'record
'=>&$record));
403 echo '<td
class=
"row-actions-cell">
';
404 if ( count($actions)>0){
405 echo ' <span
class=
"row-actions">
';
406 foreach ($actions as $action){
407 echo '<a href=
"'.htmlspecialchars($action['url']).'" class=
"'.htmlspecialchars($action['class']).' '.(@$action['icon']?'with-icon':'').'" '.(@$action['icon
']?' style=
"'.htmlspecialchars('background-image: url('.$action['icon'].')').'"':'').(@$action['target
']?' target=
"'.htmlspecialchars($action['target']).'"':'').' title=
"'.htmlspecialchars(@$action['description']?$action['description']:$action['label']).'"><span>
'.htmlspecialchars($action['label
']).'</span></a>
';
415 $rowContentHtml = $this->renderRow($record);
416 if ( isset($rowContentHtml) ){
417 echo $rowContentHtml;
419 //$expandTree=false; // flag to indicate when we added the expandTree button
420 //if ( @$app->prefs['enable_ajax_record_details
'] === 0 ){
421 // $expandTree = true;
424 foreach ($this->_columns as $key){
425 $thisField =& $record->_table->getField($key);
426 if ( !$perms[$key] ) continue;
428 $val = $this->renderCell($record, $key);
429 if ( $record->checkPermission('edit
', array('field
'=>$key)) and !$record->_table->isMetaField($key)){
430 $editable_class = 'df__editable_wrapper
';
432 $editable_class = '';
435 if ( !@$thisField['noLinkFromListView
'] and $link and $val ){
436 $val = "<a href=\"$link\" class=\"unmarked_link\">".$val."</a>";
437 $editable_class = '';
442 if ( @$thisField['noEditInListView
'] ) $editable_class='';
445 $cellClass = 'resultListCell resultListCell--
'.$key;
446 $cellClass .= ' '.$record->table()->getType($key);
447 echo "<td id=\"td-".rand()."\" class=\"field-content $cellClass $rowClass $editable_class\"> $val</td>";
453 echo "<tr class=\"listing $rowClass\" style=\"display:none\" id=\"{$recordid}-row\">";
455 echo "<td><!--placeholder for checkbox col --></td>";
457 echo '<td><!-- placeholder
for actions --></td>
';
458 echo "<td colspan=\"".($numCols+1)."\" id=\"{$recordid}-cell\"></td>
463 if ( @$app->prefs['enable_resultlist_add_row
'] ){
464 echo "<tr id=\"add-new-row\" df:table=\"".htmlspecialchars($this->_table->tablename)."\">";
465 if ( $canSelect ) $colspan=2;
467 echo "<td colspan=\"$colspan\"><script language=\"javascript\">require(DATAFACE_URL+'/js/addable.js
')</script><a href=\"#\" onclick=\"df_addNew('add-
new-row
');return false;\">".df_translate('scripts.GLOBAL.LABEL_ADD_ROW
', "Add Row")."</a></td>";
468 foreach ( $this->_columns as $key ){
469 echo "<td><span df:field=\"".htmlspecialchars($key)."\"></span></td>";
476 echo '<form
id=
"result_list_selected_items_form" method=
"post" action=
"'.df_absolute_url(DATAFACE_SITE_HREF).'">
';
477 $app =& Dataface_Application::getInstance();
478 $q =& $app->getQuery();
479 foreach ( $q as $key=>$val){
480 if ( strlen($key)>1 and $key{0} == '-
' and $key{1} == '-
' ){
483 echo '<input type=
"hidden" name=
"'.urlencode($key).'" value=
"'.htmlspecialchars($val).'" />
';
485 echo '<input type=
"hidden" name=
"--selected-ids" id=
"--selected-ids" />
';
486 echo '<input type=
"hidden" name=
"-from" id=
"-from" value=
"'.$q['-action'].'" />
';
487 echo '<input type=
"hidden" name=
"--redirect" value=
"'.base64_encode($app->url('')).'" />
';
491 import('Dataface/ActionTool.php
');
492 $at =& Dataface_ActionTool::getInstance();
493 $actions = $at->getActions(array('category
'=>'selected_result_actions
'));
494 if ( count($actions) > 0){
495 echo '<div
id=
"selected-actions">
'.df_translate('scripts.Dataface_ResultList.MESSAGE_WITH_SELECTED
', "With Selected").': <ul
class=
"selectedActionsMenu" id=
"result_list-selectedActionsMenu">
';
496 foreach ($actions as $action){
498 if ( @$action['icon
'] ){
499 $img = '<img src=
"'.$action['icon'].'"/>
';
502 if ( !@$action['onclick
'] and !$action['url
'] ){
503 $action['onclick
'] = "return actOnSelected('result_list
', '".@$action['name']."'".(@$action['confirm
']?", function(){return confirm('".addslashes($action['confirm'])."');}":"").")";
508 <li id="action-{$action['id']}"><a href="{$action['url
']}" onclick="{$action['onclick
']}" title="{$action['description
']}">{$img}{$action['label
']}</a></li>
517 if ( @$app->prefs['use_old_resultlist_controller
'] ){
518 echo '<div
class=
"resultlist-controller" id=
"resultlist-controller-bottom">
';
525 $out = ob_get_contents();
528 if ( @$app->prefs['use_old_resultlist_controller
'] ){
530 df_display(array(), 'Dataface_ResultListController.html
');
531 $out = ob_get_contents();
536 $out .= "<p style=\"clear:both\">".df_translate('scripts.GLOBAL.MESSAGE_NO_MATCH
', "No records matched your request.")."</p>";
542 function getRowClass(&$record){
543 $del =& $this->_table->getDelegate();
544 if ( isset($del) and method_exists($del, 'css__tableRowClass
') ){
545 return $del->css__tableRowClass($record);
550 function getHeaderCellClass($col){
551 $del =& $this->_table->getDelegate();
552 if ( isset($del) and method_exists($del, 'css__tableHeaderCellClass
') ){
553 return $del->css__tableHeaderCellClass($col);
558 function getResultFilters(){
560 $app =& Dataface_Application::getInstance();
561 $query =& $app->getQuery();
563 echo '<div
class=
"resultlist-filters">
564 <h3>
'.df_translate('scripts.Dataface_ResultList.MESSAGE_FILTER_RESULTS
', 'Filter Results
').':</h3>
565 <script language=
"javascript"><!--
567 function resultlist__updateFilters(col,select){
568 var currentURL =
"'.$app->url('').'";
569 var currentParts = currentURL.split(
"?");
570 var currentQuery =
"?"+currentParts[1];
571 var value = select.options[select.selectedIndex].value;
572 var regex =
new RegExp(\
'([?&])\'+col+\'={1,2}[^&]*\');
573 if ( currentQuery.match(regex) ){
579 currentQuery = currentQuery.replace(regex, \'$1\'+col+\'=\'+prefix+encodeURIComponent(value));
581 currentQuery += \'&\'+col+\'==\'+encodeURIComponent(value);
583 currentQuery = currentQuery.replace(/([&\?])-skip=[^&]+/, "$1");
584 window.location=currentParts[0]+currentQuery;
590 foreach ( $this->_filterCols as $col ){
591 $field =& $this->_table->getField($col);
594 if ( isset(
$field[
'vocabulary']) ){
595 $vocab =& $this->_table->getValuelist(
$field[
'vocabulary']);
602 echo
'<li> '.htmlspecialchars(
$field[
'widget'][
'label']).
' <select onchange="resultlist__updateFilters(\''.addslashes($col).
'\',
this);
"><option value="">'.df_translate('scripts.GLOBAL.LABEL_ALL', 'All').'</option>';
604 $res = df_query("select `$col`, count(*) as `num`
".$qb->_from()." ".$qb->_secure( $qb->_where(array($col=>null)) )." group by `$col`
", null, true);
605 if ( !$res and !is_array($res)) trigger_error(mysql_error(df_db()), E_USER_ERROR);
606 if ( @$query[$col] and $query[$col]{0} == '=' ) $queryColVal = substr($query[$col],1);
608 else $queryColVal = @$query[$col];
610 //while ( $row = mysql_fetch_assoc($res) ){
611 foreach ($res as $row){
612 if ( isset($vocab) and isset($vocab[$row[$col]]) ){
613 $val = $vocab[$row[$col]];
618 if ( $queryColVal == $row[$col] ) $selected = ' selected';
620 echo '<option value="'.htmlspecialchars($row[$col]).'"'.$selected.'>'.htmlspecialchars($val).' ('.$row['num'].')</option>';
623 //@mysql_free_result($res);
624 echo '</select></li>';
627 $out = ob_get_contents();