Xataface 2.0
Xataface Application Framework
Dataface/ResultList.php
Go to the documentation of this file.
00001 <?php
00002 /*-------------------------------------------------------------------------------
00003  * Xataface Web Application Framework
00004  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *-------------------------------------------------------------------------------
00020  */
00021 
00022 /******************************************************************************
00023  * File:                Dataface/ResultList.php
00024  * Author:              Steve Hannah
00025  * Created:     September 3, 2005
00026  * Description:
00027  *      Handles creation and display of a result list from an SQL database.
00028  *      
00029  *****************************************************************************/
00030  
00031  import( 'Dataface/Table.php');
00032 import('Dataface/QueryBuilder.php');
00033 import('Dataface/Record.php');
00034 import('Dataface/QueryTool.php');
00038  class Dataface_ResultList {
00039         
00040         var $_tablename;
00041         var $_db;
00042         var $_columns;
00043         var $_query;
00044         var $_table;
00045         
00046         var $_results;
00047         var $_resultSet;
00048         
00049         var $_filterCols = array();
00050  
00051         function Dataface_ResultList( $tablename, $db='', $columns=array(), $query=array()){
00052                 $app =& Dataface_Application::getInstance();
00053                 $this->_tablename = $tablename;
00054                 if (empty($db) ) $db = $app->db();
00055                 $this->_db = $db;
00056                 $this->_columns = $columns;
00057                 if ( !is_array($columns) ) $this->_columns = array();
00058                 $this->_query = $query;
00059                 if( !is_array($query) ) $this->_query = array();
00060                 
00061                 $this->_table =& Dataface_Table::loadTable($tablename);
00062                 $fieldnames = array_keys($this->_table->fields(false,true));
00063                 $fields =& $this->_table->fields(false,true);
00064                 
00065                 if ( count($this->_columns)==0 ){
00066                         
00067                         foreach ($fieldnames as $field){
00068                                 if ( @$fields[$field]['filter'] ) $this->_filterCols[] = $field;
00069                                 if ( $fields[$field]['visibility']['list'] != 'visible') continue;
00070                                         if ( $this->_table->isPassword($field) ) continue;
00071                                 if ( isset( $fields[$field] ) and !preg_match('/blob/i', $fields[$field]['Type']) ){
00072                                         $this->_columns[] = $field;
00073                                 }
00074                         }
00075                         
00076                         
00077                 } else {
00078                         
00079                 
00080                         foreach ($fieldnames as $field){
00081                                 if ( @$fields[$field]['filter'] ) $this->_filterCols[] = $field;
00082                         }
00083                 }
00084                 
00085                 
00086                 $this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);
00087                 
00088         }
00089         
00090         function renderCell(&$record, $fieldname){
00091                 $del =& $record->_table->getDelegate();
00092                 if ( isset($del) and method_exists($del, $fieldname.'__renderCell') ){
00093                         $method = $fieldname.'__renderCell';
00094                         return $del->$method($record);
00095                         //return call_user_func(array(&$del, $fieldname.'__renderCell'), $record); 
00096                 }
00097                 $field =& $record->_table->getField($fieldname);
00098                 $out = $record->preview($fieldname);
00099                 if ( !@$field['noEditInListView'] and @$field['noLinkFromListView'] and $record->checkPermission('edit', array('field'=>$fieldname) ) ){
00100                         $recid = $record->getId();
00101                         $out = '<span df:showlink="1" df:id="'.$recid.'#'.$fieldname.'" class="df__editable">'.$out.'</span>';
00102                 } 
00103                 return $out;
00104         }
00105         
00106         function renderRowHeader($tablename=null){
00107                 if ( !isset($tablename) ) $tablename = $this->_table->tablename;
00108                 $del =& $this->_table->getDelegate();
00109                 if ( isset($del) and method_exists($del, 'renderRowHeader') ){
00110                         return $del->renderRowHeader($tablename);
00111                 }
00112                 $app =& Dataface_Application::getInstance();
00113                 $appdel =& $app->getDelegate();
00114                 if ( isset($appdel) and method_exists($appdel,'renderRowHeader') ){
00115                         return $appdel->renderRowHeader($tablename);
00116                 }
00117                 return null;
00118         }
00119         
00120         function renderRow(&$record){
00121                 $del =& $record->_table->getDelegate();
00122                 if ( isset($del) and method_exists($del, 'renderRow') ){
00123                         return $del->renderRow($record);
00124                 }
00125                 $app =& Dataface_Application::getInstance();
00126                 $appdel =& $app->getDelegate();
00127                 if ( isset($appdel) and method_exists($appdel,'renderRow') ){
00128                         return $appdel->renderRow($record);
00129                 }
00130                 return null;
00131         }
00132         
00133         function &getResults(){
00134                 if ( !isset($this->_results) ){
00135                         /*
00136                         // It seems all dandy to only load the columns we need...but if the user
00137                         // is using a custom template we may need more columns.
00138                         // boo!!!
00139                         $columns = array_unique(
00140                                 array_merge( 
00141                                         $this->_columns, 
00142                                         array_keys(
00143                                                 $this->_table->keys()
00144                                         ) 
00145                                 )
00146                         );
00147                         */
00148                         
00149                         $this->_resultSet->loadSet(null/*$columns*/,true,false,true);
00150                         $this->_results = new Dataface_RecordIterator($this->_tablename, $this->_resultSet->data());
00151                         
00152                 }
00153                 return $this->_results;
00154         
00155         }
00156         
00157         function toHtml(){
00158                 $app =& Dataface_Application::getInstance();
00159                 $query =& $app->getQuery();
00160                 if ( isset( $query['-sort']) ){
00161                         $sortcols = explode(',', trim($query['-sort']));
00162                         $sort_columns = array();
00163                         foreach ($sortcols as $sortcol){
00164                                 $sortcol = trim($sortcol);
00165                                 if (strlen($sortcol) === 0 ) continue;
00166                                 $sortcol = explode(' ', $sortcol);
00167                                 if ( count($sortcol) > 1 ){
00168                                         $sort_columns[$sortcol[0]] = strtolower($sortcol[1]);
00169                                 } else {
00170                                         $sort_columns[$sortcol[0]] = 'asc';
00171                                 }
00172                                 break;
00173                         }
00174                         unset($sortcols);       // this was just a temp array so we get rid of it here
00175                 } else {
00176                         $sort_columns = array();
00177                 }
00178                 
00179                 // $sort_columns should now be of the form [ColumnName] -> [Direction]
00180                 // where Direction is "asc" or "desc"
00181                 
00182                 
00183                 
00184                 if ( $this->_resultSet->found() > 0 ) {
00185                 
00186                         
00187                         if ( @$app->prefs['use_old_resultlist_controller'] ){
00188                                 ob_start();
00189                                 df_display(array(), 'Dataface_ResultListController.html');
00190                                 $controller = ob_get_contents();
00191                                 ob_end_clean();
00192                         }
00193                 
00194                         
00195                         ob_start();
00196                         //echo '<div style="clear: both"/>';
00197                         if ( !defined('Dataface_ResultList_Javascript') ){
00198                                 define('Dataface_ResultList_Javascript',true);
00199                                 $jt = Dataface_JavascriptTool::getInstance();
00200                                 $jt->import('Dataface/ResultList.js');
00201                                 
00202                                 //echo '<script language="javascript" type="text/javascript" src="'.DATAFACE_URL.'/js/Dataface/ResultList.js"></script>';
00203                         }
00204                         
00205                         if ( !@$app->prefs['hide_result_filters'] and count($this->_filterCols) > 0 ){
00206                                 echo $this->getResultFilters();
00207                         }
00208                         unset($query);
00209                         
00210                         if ( @$app->prefs['use_old_resultlist_controller'] ){
00211                                 echo '<div class="resultlist-controller" id="resultlist-controller-top">';
00212         
00213                                 echo $controller;
00214                                 echo "</div>";
00215                         }
00216                 
00217                         
00218                         
00219                         $canSelect = false;
00220                         if ( !@$app->prefs['disable_select_rows'] ){
00221                                 $canSelect = Dataface_PermissionsTool::checkPermission('select_rows',
00222                                                         Dataface_PermissionsTool::getPermissions( $this->_table ));
00223                         }
00224                         
00225                         
00226                         $sq = $myq = $app->getQuery();
00227                         foreach ($sq as $sqk=>$sqv ){
00228                                 if ( !$sqk or $sqk{0} == '-' ){
00229                                         unset($sq[$sqk]);
00230                                 }
00231                         }
00232                         if ( @$myq['-sort'] ) $sq['-sort'] = $myq['-sort'];
00233                         if ( @$myq['-skip'] ) $sq['-skip'] = $myq['-skip'];
00234                         if ( @$myq['-limit'] ) $sq['-limit'] = $myq['-limit'];
00235                         
00236                         
00237                         $sq = json_encode($sq);
00238                         $jt = Dataface_JavascriptTool::getInstance();
00239                         $jt->import('list.js');
00240                         echo '
00241                                 <table data-xataface-query="'.htmlspecialchars($sq).'" id="result_list" class="listing resultList resultList--'.$this->_tablename.'">
00242                                 <thead>
00243                                 <tr>';
00244                         if ( $canSelect){
00245                                 echo '<th><input type="checkbox" onchange="toggleSelectedRows(this,\'result_list\');"></th>';
00246                         }
00247                         
00248                         if ( !@$app->prefs['disable_ajax_record_details']  ){
00249                                 echo '  <th><!-- Expand record column --></th>
00250                                 ';
00251                         }
00252                         echo '<th class="row-actions-header"></th>';
00253                         $results =& $this->getResults();
00254                         $perms = array();
00255                         $numCols = 0;
00256                         
00257                         $rowHeaderHtml = $this->renderRowHeader();
00258                         if ( isset($rowHeaderHtml) ){
00259                                 echo $rowHeaderHtml;
00260                         } else {
00261                                 
00262                                 foreach ($this->_columns as $key ){
00263                                         if ( in_array($key, $this->_columns) ){
00264                                                 if ( !($perms[$key] =  Dataface_PermissionsTool::checkPermission('list', $this->_table, array('field'=>$key)) /*Dataface_PermissionsTool::view($this->_table, array('field'=>$key))*/) ) continue;
00265                                                 if ( isset($sort_columns[$key]) ){
00266                                                         $class = 'sorted-column-'.$sort_columns[$key];
00267                                                         $query = array();
00268                                                         $qs_columns = $sort_columns;
00269                                                         unset($qs_columns[$key]);
00270                                                         $sort_query = $key.' '.($sort_columns[$key] == 'desc' ? 'asc' : 'desc');
00271                                                         foreach ( $qs_columns as $qcolkey=> $qcolvalue){
00272                                                                 $sort_query .= ', '.$qcolkey.' '.$qcolvalue;
00273                                                         }
00274                                                 } else {
00275                                                         $class = 'unsorted-column';
00276                                                         $sort_query = $key.' asc';
00277                                                         foreach ( $sort_columns as $scolkey=>$scolvalue){
00278                                                                 $sort_query .= ', '.$scolkey.' '.$scolvalue;
00279                                                         }
00280                                                         
00281                                                 }
00282                                                 $sq = array('-sort'=>$sort_query);
00283                                                 $link = Dataface_LinkTool::buildLink($sq);
00284                                                 $numCols++;
00285                                                 $label = $this->_table->getFieldProperty('column:label', $key);
00286                                                 $legend = $this->_table->getFieldProperty('column:legend', $key);
00287                                                 if ( $legend ){
00288                                                         $legend = '<span class="column-legend">'.htmlspecialchars($legend).'</span>';
00289                                                 }
00290                                                 
00291                                                 $colType = $this->_table->getType($key);
00292                                                 $class .= ' coltype-'.$colType;
00293                                                 $cperms = $this->_table->getPermissions(array('field'=>$key));
00294                                                 if ( !$this->_table->isSearchable($key) or !@$cperms['find'] ){
00295                                                         $class .= ' unsearchable-column';
00296                                                 } else {
00297                                                         $class .= ' searchable-column';
00298                                                 }
00299                                                 
00300                                                 if ( !$label ) $label = $this->_table->getFieldProperty('widget:label',$key);
00301                                                 echo "<th data-column=\"$key\" class=\"$class\"><a href=\"$link\">".htmlspecialchars($label)."</a> $legend</th>";
00302                                         }
00303                                 }
00304                         }
00305                         echo "</tr>
00306                                 </thead>
00307                                 <tbody>
00308                                 ";
00309         
00310                         
00311                         $cursor=$this->_resultSet->start();
00312                         $results->reset();
00313                         $baseQuery = array();
00314                         foreach ( $_GET as $key=>$value){
00315                                 if ( strpos($key,'-') !== 0 ){
00316                                         $baseQuery[$key] = $value;
00317                                 }
00318                         }
00319                         $evenRow = false;
00320                         while ($results->hasNext() ){
00321                                 $rowClass = $evenRow ? 'even' : 'odd';
00322                                 $evenRow = !$evenRow;
00323                                 $record =& $results->next();
00324                                 $recperms = $record->getPermissions();
00325                                 
00326                                 if ( !@$recperms['view'] ){
00327                                         $cursor++;
00328                                         unset($record);
00329                                         continue;
00330                                 }
00331                                 $rowClass .= ' '.$this->getRowClass($record);
00332                                 
00333                                 
00334                                 
00335                                 $query = array_merge( $baseQuery, array( "-action"=>"browse", "-relationship"=>null, "-cursor"=>$cursor++) );
00336                                 
00337                                 if (  @$recperms['link'] ){
00338                                         if ( @$app->prefs['result_list_use_geturl'] ){
00339                                                 $link = $record->getURL('-action=view');
00340                                         } else {
00341                                                 
00342                                                 $link = Dataface_LinkTool::buildLink($query).'&-recordid='.urlencode($record->getId());
00343                                         }
00344                                 } else {
00345                                         $del =& $record->_table->getDelegate();
00346                                         if ( $del and method_exists($del, 'no_access_link') ){
00347                                                 $link = $del->no_access_link($record);
00348                                         } else {
00349                                                 $link = null;
00350                                         }
00351                                 }
00352                                 $recordid = $record->getId();
00353                                 
00354                                 
00355                                 echo "<tr class=\"listing $rowClass\">";
00356                                 if ( $canSelect ) {
00357                                         $permStr = array();
00358                                         foreach ($recperms as $pk=>$pv){
00359                                                 if ( $pv ) $permStr[] = $pk;
00360                                         }
00361                                         $permStr = htmlspecialchars(implode(',', $permStr));
00362                                         echo '<td class="checkbox-cell"><input class="rowSelectorCheckbox" xf-record-id="'.htmlspecialchars($recordid).'" id="rowSelectorCheckbox:'.htmlspecialchars($recordid).'" type="checkbox" data-xf-permissions="'.$permStr.'"></td>';
00363                                 }
00364                                 
00365                                 
00366                                 
00367                                 
00368                                 if ( !@$app->prefs['disable_ajax_record_details']  ){
00369                                         echo '<td class="ajax-record-details-cell">';
00370                                         echo '<script language="javascript" type="text/javascript"><!--
00371                                                         registerRecord(\''.addslashes($recordid).'\',  '.$record->toJS(array()).');
00372                                                         //--></script>
00373                                                         <img src="'.DATAFACE_URL.'/images/treeCollapsed.gif" onclick="resultList.showRecordDetails(this, \''.addslashes($recordid).'\')"/>';
00374                                         
00375                                         
00376                                         echo '</td>';
00377                                         unset($at, $actions);
00378                                 }
00379                                 
00380                                 $at =& Dataface_ActionTool::getInstance();
00381                                 $actions = $at->getActions(array('category'=>'list_row_actions', 'record'=>&$record));
00382                                 //print_r($actions);
00383                                 echo '<td class="row-actions-cell">';
00384                                 if ( count($actions)>0){
00385                                         echo ' <span class="row-actions">';
00386                                         foreach ($actions as $action){
00387                                                 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> ';
00388                                         }
00389                                         echo '</span>';
00390                                 }
00391                                 echo '</td>';
00392                                 
00393                                 
00394                                 
00395                                 $rowContentHtml = $this->renderRow($record);
00396                                 if ( isset($rowContentHtml) ){
00397                                         echo $rowContentHtml;
00398                                 } else {
00399                                         //$expandTree=false; // flag to indicate when we added the expandTree button
00400                                         //if ( @$app->prefs['enable_ajax_record_details'] === 0 ){
00401                                         //      $expandTree = true;
00402                                         //}
00403                                         
00404                                         foreach ($this->_columns as $key){
00405                                                 $thisField =& $record->_table->getField($key);
00406                                                 if ( !$perms[$key] ) continue;
00407                                                 
00408                                                 $val = $this->renderCell($record, $key);
00409                                                 if ( $record->checkPermission('edit', array('field'=>$key)) and !$record->_table->isMetaField($key)){
00410                                                         $editable_class = 'df__editable_wrapper';
00411                                                 } else {
00412                                                         $editable_class = '';
00413                                                 }
00414                                                 
00415                                                 if ( !@$thisField['noLinkFromListView'] and $link and $val ){
00416                                                         $val = "<a href=\"$link\" class=\"unmarked_link\">".$val."</a>";
00417                                                         $editable_class = '';
00418                                                 } else {
00419                                                         
00420                                                 }
00421                                                 
00422                                                 if ( @$thisField['noEditInListView'] ) $editable_class='';
00423                                                 
00424                                                 
00425                                                 $cellClass = 'resultListCell resultListCell--'.$key;
00426                                                 $cellClass .= ' '.$record->table()->getType($key);
00427                                                 echo "<td id=\"td-".rand()."\" class=\"field-content $cellClass $rowClass $editable_class\">&nbsp;$val</td>";
00428                                                 unset($thisField);
00429                                         }
00430                                 }
00431                                 echo "</tr>";
00432                                 
00433                                 echo "<tr class=\"listing $rowClass\" style=\"display:none\" id=\"{$recordid}-row\">";
00434                                 if ( $canSelect ){
00435                                         echo "<td><!--placeholder for checkbox col --></td>";
00436                                 }
00437                                 echo '<td><!-- placeholder for actions --></td>';
00438                                 echo "<td colspan=\"".($numCols+1)."\" id=\"{$recordid}-cell\"></td>
00439                                           </tr>";
00440                                 
00441                                 unset($record);
00442                         }
00443                         if ( @$app->prefs['enable_resultlist_add_row'] ){
00444                                 echo "<tr id=\"add-new-row\" df:table=\"".htmlspecialchars($this->_table->tablename)."\">";
00445                                 if ( $canSelect ) $colspan=2;
00446                                 else $colspan = 1;
00447                                 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>";
00448                                 foreach ( $this->_columns as $key ){
00449                                         echo "<td><span df:field=\"".htmlspecialchars($key)."\"></span></td>";
00450                                 }
00451                                 echo "</tr>";
00452                         }
00453                         echo "</tbody>
00454                                 </table>";
00455                         if ( $canSelect ){
00456                                 echo  '<form id="result_list_selected_items_form" method="post" action="'.df_absolute_url(DATAFACE_SITE_HREF).'">';
00457                                 $app =& Dataface_Application::getInstance();
00458                                 $q =& $app->getQuery();
00459                                 foreach ( $q as $key=>$val){
00460                                         if ( strlen($key)>1 and $key{0} == '-' and $key{1} == '-' ){
00461                                                 continue;
00462                                         }
00463                                         echo '<input type="hidden" name="'.urlencode($key).'" value="'.htmlspecialchars($val).'" />';
00464                                 }
00465                                 echo '<input type="hidden" name="--selected-ids" id="--selected-ids" />';
00466                                 echo '<input type="hidden" name="-from" id="-from" value="'.$q['-action'].'" />';
00467                                 echo '<input type="hidden" name="--redirect" value="'.base64_encode($app->url('')).'" />';
00468                                 echo '</form>';
00469                         
00470         
00471                                 import('Dataface/ActionTool.php');
00472                                 $at =& Dataface_ActionTool::getInstance();
00473                                 $actions = $at->getActions(array('category'=>'selected_result_actions'));
00474                                 if ( count($actions) > 0){
00475                                         echo '<div id="selected-actions">'.df_translate('scripts.Dataface_ResultList.MESSAGE_WITH_SELECTED', "With Selected").': <ul class="selectedActionsMenu" id="result_list-selectedActionsMenu">';
00476                                         foreach ($actions as $action){
00477                                                 $img = '';
00478                                                 if ( @$action['icon'] ){
00479                                                         $img = '<img src="'.$action['icon'].'"/>';
00480                                                 }
00481                                                 
00482                                                 if ( !@$action['onclick'] and !$action['url'] ){
00483                                                         $action['onclick'] = "return actOnSelected('result_list', '".@$action['name']."'".(@$action['confirm']?", function(){return confirm('".addslashes($action['confirm'])."');}":"").")";
00484                                                         
00485                                                 }
00486                                                 
00487                                                 echo <<<END
00488                                                 <li id="action-{$action['id']}"><a href="{$action['url']}" onclick="{$action['onclick']}" title="{$action['description']}">{$img}{$action['label']}</a></li>
00489 END;
00490                                         }
00491                         
00492                         
00493                                         echo '</ul></div>';
00494                                 }
00495                         }
00496                 
00497                         if ( @$app->prefs['use_old_resultlist_controller'] ){
00498                                 echo '<div class="resultlist-controller" id="resultlist-controller-bottom">';
00499         
00500                                 echo $controller;
00501                                 echo '</div>';
00502                         }
00503                 
00504                         
00505                         $out = ob_get_contents();
00506                         ob_end_clean();
00507                 } else {
00508                         if ( @$app->prefs['use_old_resultlist_controller'] ){
00509                                 ob_start();
00510                                 df_display(array(), 'Dataface_ResultListController.html');
00511                                 $out = ob_get_contents();
00512                                 ob_end_clean();
00513                         } else {
00514                                 $out = '';
00515                         }
00516                         $out .= "<p style=\"clear:both\">".df_translate('scripts.GLOBAL.MESSAGE_NO_MATCH', "No records matched your request.")."</p>";
00517                 }
00518                 
00519                 return $out;
00520         }
00521         
00522         function getRowClass(&$record){
00523                 $del =& $this->_table->getDelegate();
00524                 if ( isset($del) and method_exists($del, 'css__tableRowClass') ){
00525                         return $del->css__tableRowClass($record);
00526                 }
00527                 return '';
00528         }
00529         
00530         function getResultFilters(){
00531                 ob_start();
00532                 $app =& Dataface_Application::getInstance();
00533                 $query =& $app->getQuery();
00534 
00535                 echo '<div class="resultlist-filters">
00536                 <h3>'.df_translate('scripts.Dataface_ResultList.MESSAGE_FILTER_RESULTS', 'Filter Results').':</h3>
00537                 <script language="javascript"><!--
00538                 
00539                 function resultlist__updateFilters(col,select){
00540                         var currentURL = "'.$app->url('').'";
00541                         var currentParts = currentURL.split("?");
00542                         var currentQuery = "?"+currentParts[1];
00543                         var value = select.options[select.selectedIndex].value;
00544                         var regex = new RegExp(\'([?&])\'+col+\'={1,2}[^&]*\');
00545                         if ( currentQuery.match(regex) ){
00546                                 if ( value ){
00547                                         prefix = "=";
00548                                 } else {
00549                                         prefix = "";
00550                                 }
00551                                 currentQuery = currentQuery.replace(regex, \'$1\'+col+\'=\'+prefix+encodeURIComponent(value));
00552                         } else {
00553                                 currentQuery += \'&\'+col+\'==\'+encodeURIComponent(value);
00554                         }
00555                         window.location=currentParts[0]+currentQuery;
00556                 }
00557                 //--></script>
00558                 <ul>';
00559 
00560                 $qb = new Dataface_QueryBuilder($this->_table->tablename, $query);
00561                 foreach ( $this->_filterCols as $col ){
00562                         $field =& $this->_table->getField($col);
00563                         
00564                         unset($vocab);
00565                         if ( isset($field['vocabulary']) ){
00566                                 $vocab =& $this->_table->getValuelist($field['vocabulary']);
00567                                 
00568                         } else {
00569                                 $vocab=null;
00570                                 
00571                         }
00572                         
00573                         echo '<li> '.htmlspecialchars($field['widget']['label']).' <select onchange="resultlist__updateFilters(\''.addslashes($col).'\', this);"><option value="">'.df_translate('scripts.GLOBAL.LABEL_ALL', 'All').'</option>';
00574                         
00575                         $res = df_query("select `$col`, count(*) as `num` ".$qb->_from()." ".$qb->_secure( $qb->_where(array($col=>null)) )." group by `$col`", null, true);
00576                         if ( !$res and !is_array($res)) trigger_error(mysql_error(df_db()), E_USER_ERROR);
00577                         if ( @$query[$col] and $query[$col]{0} == '=' ) $queryColVal = substr($query[$col],1);
00578                         
00579                         else $queryColVal = @$query[$col];
00580                         
00581                         //while ( $row = mysql_fetch_assoc($res) ){
00582                         foreach ($res as $row){
00583                                 if ( isset($vocab) and isset($vocab[$row[$col]]) ){
00584                                         $val = $vocab[$row[$col]];
00585                                 } else {
00586                                         $val = $row[$col];
00587                                 }
00588                                 
00589                                 if ( $queryColVal == $row[$col] ) $selected = ' selected';
00590                                 else $selected = '';
00591                                 echo '<option value="'.htmlspecialchars($row[$col]).'"'.$selected.'>'.htmlspecialchars($val).' ('.$row['num'].')</option>';
00592                                 
00593                         }
00594                         //@mysql_free_result($res);
00595                         echo '</select></li>';
00596                 }
00597                 echo '</ul></div>';
00598                 $out = ob_get_contents();
00599                 ob_end_clean();
00600                 return $out;
00601         
00602         
00603         }
00604         
00605         
00606 
00607         
00608  
00609  }
00610  
 All Data Structures Namespaces Files Functions Variables Enumerations