Exemple #1
0
    function toHtml()
    {
        $context = array();
        $context['relatedList'] = $this;
        $app =& Dataface_Application::getInstance();
        $context['app'] =& $app;
        $query =& $app->getQuery();
        $context['query'] =& $query;
        if (isset($query['-related:sort'])) {
            $sortcols = explode(',', trim($query['-related:sort']));
            $sort_columns = array();
            foreach ($sortcols as $sortcol) {
                $sortcol = trim($sortcol);
                if (strlen($sortcol) === 0) {
                    continue;
                }
                $sortcol = explode(' ', $sortcol);
                if (count($sortcol) > 1) {
                    $sort_columns[$sortcol[0]] = strtolower($sortcol[1]);
                } else {
                    $sort_columns[$sortcol[0]] = 'asc';
                }
                break;
            }
            unset($sortcols);
            // this was just a temp array so we get rid of it here
        } else {
            $sort_columns = array();
        }
        $context['sort_columns'] =& $sort_columns;
        $sort_columns_arr = array();
        foreach ($sort_columns as $colkey => $colorder) {
            $sort_columns_arr[] = '`' . $colkey . '`' . $colorder;
        }
        if (count($sort_columns_arr) > 0) {
            $sort_columns_str = implode(', ', $sort_columns_arr);
        } else {
            $sort_columns_str = 0;
        }
        unset($query);
        $skinTool =& Dataface_SkinTool::getInstance();
        $context['skinTool'] =& $skinTool;
        $resultController =& $skinTool->getResultController();
        $context['resultController'] =& $resultController;
        $s =& $this->_table;
        $r =& $this->_relationship->_schema;
        $fkeys = $this->_relationship->getForeignKeyValues();
        $local_fkey_fields = array();
        foreach ($fkeys as $fk_table_name => $fk_table_cols) {
            foreach ($fk_table_cols as $k => $v) {
                if (is_string($v) and $v and $v[0] === '$') {
                    $local_fkey_fields[$k] = $v;
                }
            }
        }
        $default_order_column = $this->_relationship->getOrderColumn();
        //echo "Def order col = $default_order_column";
        ob_start();
        df_display(array('redirectUrl' => $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']), 'Dataface_MoveUpForm.html');
        $moveUpForm = ob_get_contents();
        ob_end_clean();
        $context['moveUpForm'] = $moveUpForm;
        $records =& $this->_record->getRelatedRecords($this->_relationship_name, true, $this->_start, $this->_limit, $this->_where);
        if (PEAR::isError($records)) {
            $records->addUserInfo("Error retrieving records from relationship " . $this->_relationship_name);
            return $records;
        }
        $context['records'] =& $records;
        //echo "<br/><b>Now Showing</b> ".($this->_start+1)." to ".(min($this->_start + $this->_limit, $this->_record->numRelatedRecords($this->_relationship_name)));
        $perms = $this->_record->getPermissions(array('relationship' => $this->_relationship_name));
        $context['perms'] = $perms;
        $context['record_editable'] = Dataface_PermissionsTool::edit($this->_record);
        $context['can_add_new_related_record'] = @$perms['add new related record'];
        $context['can_add_existing_related_record'] = @$perms['add existing related record'];
        if (!$this->hideActions and ($context['record_editable'] or @$perms['add new related record'] or @$perms['add existing related record'])) {
            $query = array('-action' => 'new_related_record');
            $link = Dataface_LinkTool::buildLink($query);
            $context['new_related_record_query'] = $query;
            $context['new_related_record_link'] = $link;
            $domainTable = $this->_relationship->getDomainTable();
            //$context['domainTable'] =& $domainTable;
            $importTablename = $domainTable;
            if (!PEAR::isError($domainTable)) {
                //This relationship is many-to-many so we can add existing records to it.
                $query2 = array('-action' => 'existing_related_record');
                $context['existing_related_record_query'] = $query2;
                $link2 = Dataface_LinkTool::buildLink($query2);
                $context['existing_related_record_link'] = $link2;
                $destTables = $this->_relationship->getDestinationTables();
                $context['destTables'] =& $destTables;
                $importTablename = $destTables[0]->tablename;
                $context['importTablename'] = $importTablename;
            }
            if (!PEAR::isError($importTablename)) {
                $importTable =& Dataface_Table::loadTable($importTablename);
                $context['importTable'] =& $importTable;
                $query3 = array('-action' => 'import');
                $context['import_related_records_query'] =& $query3;
                $link3 = Dataface_LinkTool::buildLink($query3);
                $context['import_related_records_link'] = $link3;
            }
        }
        $imgIcon = DATAFACE_URL . '/images/search_icon.gif';
        $searchSrc = DATAFACE_URL . '/js/Dataface/RelatedList/search.js';
        $relname = $this->_relationship_name;
        $context['relationship_label'] = $this->_relationship->getLabel();
        $context['relname'] = $relname;
        $context['relationship_name'] = $this->_relationship_name;
        $context['searchSrc'] = $searchSrc;
        $context['imgIcon'] = $imgIcon;
        if (!$this->hideActions) {
            $num_related_records = $this->_record->numRelatedRecords($this->_relationship_name, $this->_where);
            $now_showing_start = $this->_start + 1;
            $now_showing_finish = min($this->_start + $this->_limit, $this->_record->numRelatedRecords($this->_relationship_name, $this->_where));
            $stats_context = array('num_related_records' => $num_related_records, 'now_showing_start' => $now_showing_start, 'now_showing_finish' => $now_showing_finish, 'relationship_name' => $this->_relationship_name, 'limit_field' => $resultController->limitField('related:'), 'back_link' => $this->_backButtonHtml(), 'next_link' => $this->_forwardButtonHtml());
            import('Dataface/ActionTool.php');
            $at =& Dataface_ActionTool::getInstance();
            $actions = $at->getActions(array('category' => 'related_list_actions'));
            $context['related_list_actions'] = $actions;
            foreach ($stats_context as $k => $v) {
                $context[$k] = $v;
            }
        }
        import('Dataface/ActionTool.php');
        $at =& Dataface_ActionTool::getInstance();
        $selected_actions = $at->getActions(array('category' => 'selected_related_result_actions'));
        $context['selected_actions'] = $selected_actions;
        if ($this->_relationship->_schema['list']['type'] == 'treetable') {
            import('Dataface/TreeTable.php');
            $treetable = new Dataface_TreeTable($this->_record, $this->_relationship->getName());
            $context['treetable'] = $treetable->toHtml();
        } else {
            echo $moveUpForm;
            if (!$this->hideActions and $this->_where) {
                $filterQuery =& $app->getQuery();
                $context['filterQuery'] =& $filterQuery;
            }
            if (count($records) > 0) {
                ob_start();
                echo '
                        <table class="listing relatedList relatedList--' . $this->_tablename . ' relatedList--' . $this->_tablename . '--' . $this->_relationship_name . '" id="relatedList">
                        <thead>
                        <tr>';
                if (count($selected_actions) > 0) {
                    echo '<th>';
                    if (!$this->hideActions) {
                        echo '<input type="checkbox" onchange="toggleSelectedRows(this,\'relatedList\');">';
                    }
                    echo '</th>';
                }
                $cols = array_keys(current($records));
                $col_tables = array();
                $table_keys = array();
                $localFields = $this->_record->table()->fields();
                $usedColumns = array();
                foreach ($cols as $key) {
                    if ($key == $default_order_column) {
                        continue;
                    }
                    if (is_int($key)) {
                        continue;
                    }
                    if (isset($sort_columns[$key])) {
                        $class = 'sorted-column-' . $sort_columns[$key];
                        $query = array();
                        $qs_columns = $sort_columns;
                        unset($qs_columns[$key]);
                        $sort_query = $key . ' ' . ($sort_columns[$key] == 'desc' ? 'asc' : 'desc');
                        foreach ($qs_columns as $qcolkey => $qcolvalue) {
                            $sort_query .= ', ' . $qcolkey . ' ' . $qcolvalue;
                        }
                    } else {
                        $class = 'unsorted-column';
                        $sort_query = $key . ' asc';
                        foreach ($sort_columns as $scolkey => $scolvalue) {
                            $sort_query .= ', ' . $scolkey . ' ' . $scolvalue;
                        }
                    }
                    $sq = array('-related:sort' => $sort_query);
                    $link = Dataface_LinkTool::buildLink($sq);
                    $fullpath = $this->_relationship_name . '.' . $key;
                    $field =& $this->_relationship->getField($key);
                    if (isset($this->_relationship->_schema['visibility'][$key]) and $this->_relationship->_schema['visibility'][$key] == 'hidden') {
                        continue;
                    }
                    if ($field['visibility']['list'] != 'visible') {
                        continue;
                    }
                    if ($s->isBlob($fullpath) or $s->isPassword($fullpath)) {
                        continue;
                    }
                    if (isset($local_fkey_fields[$key]) and !isset($this->_relationship->_schema['visibility'][$key])) {
                        continue;
                    }
                    if (PEAR::isError($field)) {
                        $field->addUserInfo("Error getting field info for field {$key} in RelatedList::toHtml() ");
                        return $field;
                    }
                    $usedColumns[] = $key;
                    $label = $field['widget']['label'];
                    if (isset($field['column']) and @$field['column']['label']) {
                        $label = $field['column']['label'];
                    }
                    $legend = '';
                    if (@$field['column'] and @$field['column']['legend']) {
                        $legend = '<span class="column-legend">' . df_escape($field['column']['legend']) . '</span>';
                    }
                    if (!$this->noLinks) {
                        echo '<th><a href="' . df_escape($link) . '">' . df_escape($field['widget']['label']) . "</a> {$legend}</th>\n";
                    } else {
                        echo '<th>' . $field['widget']['label'] . '</th>';
                    }
                    if (!isset($col_tables[$key])) {
                        $col_tables[$key] = $field['tablename'];
                    }
                    if (!isset($table_keys[$col_tables[$key]])) {
                        $table_table =& Dataface_Table::loadTable($field['tablename']);
                        $table_keys[$col_tables[$key]] = array_keys($table_table->keys());
                        unset($table_table);
                    }
                    unset($field);
                }
                echo "</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody id=\"relatedList-body\">\n\t\t\t\t\t";
                $limit = min($this->_limit, $this->_record->numRelatedRecords($this->_relationship_name, $this->_where) - $this->_start);
                $relatedTable = $this->_relationship->getDomainTable();
                if (PEAR::isError($relatedTable)) {
                    $relatedTable = reset($r['selected_tables']);
                }
                $relatedTable = Dataface_Table::loadTable($relatedTable);
                $relatedKeys = array_keys($relatedTable->keys());
                foreach (array_keys($relatedKeys) as $i) {
                    $relatedKeys[$i] = $this->_relationship_name . "." . $relatedKeys[$i];
                }
                $fullpaths = array();
                $fields_index = array();
                foreach ($usedColumns as $key) {
                    $fullpaths[$key] = $this->_relationship_name . '.' . $key;
                    $fields_index[$key] =& $this->_relationship->getField($key);
                }
                $evenRow = false;
                for ($i = $this->_start; $i < $this->_start + $limit; $i++) {
                    $rowClass = $evenRow ? 'even' : 'odd';
                    $evenRow = !$evenRow;
                    if ($default_order_column and @$perms['reorder_related_records']) {
                        $style = 'cursor:move';
                        // A variable that will be used below in javascript to decide
                        // whether to make the table sortable or not
                        $sortable_js = 'true';
                    } else {
                        $style = '';
                        $sortable_js = 'false';
                    }
                    $context['sortable_js'] = $sortable_js;
                    unset($rrec);
                    $rrec = $this->_record->getRelatedRecord($this->_relationship_name, $i, $this->_where, $sort_columns_str);
                    //new Dataface_RelatedRecord($this->_record, $this->_relationship_name, $this->_record->getValues($fullpaths, $i, 0, $sort_columns_str));
                    $rrecid = $rrec->getId();
                    $rowPerms = $rrec->getPermissions();
                    if (!@$rowPerms['view']) {
                        continue;
                    }
                    echo "<tr class=\"listing {$rowClass}\" style=\"{$style}\" id=\"row_{$rrecid}\">";
                    if (count($selected_actions) > 0) {
                        echo '
						<td class="' . $rowClass . ' viewableColumn" nowrap>';
                        if (!$this->hideActions) {
                            echo '<input xf-record-id="' . df_escape($rrecid) . '" class="rowSelectorCheckbox" id="rowSelectorCheckbox:' . df_escape($rrecid) . '" type="checkbox">';
                        }
                        echo '</td>';
                    }
                    $link_queries = array();
                    foreach ($usedColumns as $key) {
                        if (is_int($key)) {
                            continue;
                        }
                        $fullpath = $fullpaths[$key];
                        unset($field);
                        $field =& $fields_index[$key];
                        //$s->getField($fullpath);
                        $srcRecord =& $rrec->toRecord($field['tablename']);
                        if (!@$app->_conf['legacy_compatibility_mode']) {
                            $link = $this->_record->getURL('-action=view_related_record&-related-record-id=' . urlencode($rrecid));
                        } else {
                            //$link = $srcRecord->getURL('-action=browse&-portal-context=' . urlencode($rrecid));
                            $link = $rrec->getURL('-action=browse', $field['tablename']);
                        }
                        $srcRecordId = $srcRecord->getId();
                        //$val = $this->_record->preview($fullpath, $i,255, $this->_where, $sort_columns_str);
                        if ($srcRecord->table()->isContainer($field['name']) or $srcRecord->table()->isBlob($field['name'])) {
                            $val = $rrec->htmlValue($key, array('class' => 'blob-preview'));
                            //$rrec->htmlValue($key);
                        } else {
                            $val = strip_tags($rrec->display($key));
                        }
                        $title = "";
                        if ($key == $default_order_column) {
                            unset($field);
                            unset($srcRecord);
                            continue;
                        } else {
                            if ($val != 'NO ACCESS') {
                                $accessClass = 'viewableColumn';
                            } else {
                                $accessClass = '';
                            }
                            $cellClass = 'resultListCell resultListCell--' . $key;
                            $cellClass .= ' ' . $srcRecord->table()->getType($key);
                            $renderVal = $this->renderCell($srcRecord, $field['Field']);
                            if (isset($renderVal)) {
                                $val = $renderVal;
                            }
                            if ($link and !@$field['noLinkFromListView'] and !$this->noLinks and $rrec->checkPermission('link', array('field' => $key))) {
                                $val = "<a href=\"" . df_escape($link) . "\" title=\"" . df_escape($title) . "\" data-xf-related-record-id=\"" . df_escape($srcRecordId) . "\" class=\"xf-related-record-link\">" . $val . "</a>";
                            }
                            echo "<td class=\"{$cellClass} {$rowClass} {$accessClass}\">{$val}</td>\n";
                            unset($srcRecord);
                        }
                    }
                    echo "</tr>\n";
                }
                echo "</tbody>\n\t\t\t\t\t</table>";
                $related_table_html = ob_get_contents();
                $context['related_table_html'] = $related_table_html;
                ob_end_clean();
                if (!$this->hideActions) {
                    ob_start();
                    echo '<form id="result_list_selected_items_form" method="post">';
                    $app =& Dataface_Application::getInstance();
                    $q =& $app->getQuery();
                    foreach ($q as $key => $val) {
                        if (strlen($key) > 1 and $key[0] == '-' and $key[1] == '-') {
                            continue;
                        }
                        echo '<input type="hidden" name="' . $key . '" value="' . df_escape($val) . '">';
                    }
                    echo '<input type="hidden" name="--selected-ids" id="--selected-ids">';
                    echo '<input type="hidden" name="-from" id="-from" value="' . $q['-action'] . '">';
                    echo '</form>';
                    $selected_actions_form = ob_get_contents();
                    $context['selected_actions_form'] = $selected_actions_form;
                    ob_end_clean();
                    // This bit of javascript goes through all of the columns and removes all columns that
                    // don't have any accessible information for this query.  (i.e. any columns for which
                    // each row's value is 'NO ACCESS' is removed
                    $prototype_url = DATAFACE_URL . '/js/scriptaculous/lib/prototype.js';
                    $context['prototype_url'] = $prototype_url;
                    $scriptaculous_url = DATAFACE_URL . '/js/scriptaculous/src/scriptaculous.js';
                    $context['scriptaculous_url'] = $scriptaculous_url;
                    $effects_url = DATAFACE_URL . '/js/scriptaculous/src/effects.js';
                    $context['effects_url'] = $effects_url;
                    $dragdrop_url = DATAFACE_URL . '/js/scriptaculous/src/dragdrop.js';
                    $context['dragdrop_url'] = $dragdrop_url;
                    $thisRecordID = $this->_record->getId();
                    $context['thisRecordID'] = $thisRecordID;
                }
            }
        }
        Dataface_JavascriptTool::getInstance()->import('xataface/actions/related_list.js');
        ob_start();
        $context['filters'] = $this->filters;
        df_display($context, 'xataface/RelatedList/list.html');
        $out = ob_get_contents();
        ob_end_clean();
        return $out;
    }
Exemple #2
0
    function toHtml()
    {
        $app =& Dataface_Application::getInstance();
        $query =& $app->getQuery();
        if (isset($query['-related:sort'])) {
            $sortcols = explode(',', trim($query['-related:sort']));
            $sort_columns = array();
            foreach ($sortcols as $sortcol) {
                $sortcol = trim($sortcol);
                if (strlen($sortcol) === 0) {
                    continue;
                }
                $sortcol = explode(' ', $sortcol);
                if (count($sortcol) > 1) {
                    $sort_columns[$sortcol[0]] = strtolower($sortcol[1]);
                } else {
                    $sort_columns[$sortcol[0]] = 'asc';
                }
                break;
            }
            unset($sortcols);
            // this was just a temp array so we get rid of it here
        } else {
            $sort_columns = array();
        }
        $sort_columns_arr = array();
        foreach ($sort_columns as $colkey => $colorder) {
            $sort_columns_arr[] = '`' . $colkey . '`' . $colorder;
        }
        if (count($sort_columns_arr) > 0) {
            $sort_columns_str = implode(', ', $sort_columns_arr);
        } else {
            $sort_columns_str = 0;
        }
        //echo $sort_columns_str;exit;
        unset($query);
        $skinTool =& Dataface_SkinTool::getInstance();
        $resultController =& $skinTool->getResultController();
        $s =& $this->_table;
        $r =& $this->_relationship->_schema;
        $fkeys = $this->_relationship->getForeignKeyValues();
        $default_order_column = $this->_relationship->getOrderColumn();
        //echo "Def order col = $default_order_column";
        ob_start();
        df_display(array('redirectUrl' => $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']), 'Dataface_MoveUpForm.html');
        $moveUpForm = ob_get_contents();
        ob_end_clean();
        $records =& $this->_record->getRelatedRecords($this->_relationship_name, true, $this->_start, $this->_limit, $this->_where);
        if (PEAR::isError($records)) {
            $records->addUserInfo("Error retrieving records from relationship " . $this->_relationship_name . " on line " . __LINE__ . " of file " . __FILE__);
            return $records;
        }
        ob_start();
        //echo "<br/><b>Now Showing</b> ".($this->_start+1)." to ".(min($this->_start + $this->_limit, $this->_record->numRelatedRecords($this->_relationship_name)));
        $perms = $this->_record->getPermissions(array('relationship' => $this->_relationship_name));
        if (Dataface_PermissionsTool::edit($this->_record) or @$perms['add new related record'] or @$perms['add existing related record']) {
            $query = array('-action' => 'new_related_record');
            $link = Dataface_LinkTool::buildLink($query);
            $domainTable = $this->_relationship->getDomainTable();
            $importTablename = $domainTable;
            if (!PEAR::isError($domainTable)) {
                //This relationship is many-to-many so we can add existing records to it.
                $query2 = array('-action' => 'existing_related_record');
                $link2 = Dataface_LinkTool::buildLink($query2);
                $destTables = $this->_relationship->getDestinationTables();
                $importTablename = $destTables[0]->tablename;
            }
            if (!PEAR::isError($importTablename)) {
                $importTable =& Dataface_Table::loadTable($importTablename);
                $query3 = array('-action' => 'import');
                $link3 = Dataface_LinkTool::buildLink($query3);
            }
            echo "<div id=\"relatedActionsWrapper\" class=\"contentActions\"><ul id=\"relatedActions\">";
            if ($this->_relationship->supportsAddNew() and @$perms['add new related record']) {
                echo "<li id=\"addNew\"><a id=\"add_new_related_record\" href=\"{$link}\">" . df_translate('scripts.Dataface.RelatedList.toHtml.LABEL_ADD_NEW_RELATED_RECORD', "Add New " . ucfirst($this->_relationship_name) . " Record", array('relationship' => ucfirst($this->_relationship_name))) . "</a></li>";
            }
            if ($this->_relationship->supportsAddExisting() and isset($query2) and @$perms['add existing related record']) {
                echo "<li id=\"addExisting\"><a id=\"add_existing_related_record\" href=\"{$link2}\">" . df_translate('scripts.Dataface.RelatedList.toHtml.LABEL_ADD_EXISTING_RELATED_RECORD', "Add Existing " . ucfirst($this->_relationship_name) . " Record", array('relationship' => ucfirst($this->_relationship_name))) . "</a></li>";
            }
            if (isset($query3) and count($importTable->getImportFilters()) > 0) {
                echo "<li id=\"import\"><a id=\"import_related_records\" href=\"{$link3}\">" . df_translate('scripts.Dataface.RelatedList.toHtml.LABEL_IMPORT_RELATED_RECORDS', "Import " . ucfirst($this->_relationship_name) . " Records", array('relationship' => ucfirst($this->_relationship_name))) . "</a></li>";
            }
            echo "</ul></div>";
        }
        $out = ob_get_contents();
        ob_end_clean();
        ob_start();
        $imgIcon = DATAFACE_URL . '/images/search_icon.gif';
        $searchSrc = DATAFACE_URL . '/js/Dataface/RelatedList/search.js';
        $relname = $this->_relationship_name;
        echo <<<END
\t\t<div class="result-tools" style="float:left">
\t\t\t<script language="javascript" type="text/javascript" src="{$searchSrc}"></script>
\t\t\t<a href="#" onclick="Dataface.RelatedList.showSearch('{$relname}', document.getElementById('related_find_wrapper')); return false;" title="Filter these results"><img src="{$imgIcon}" alt="Filter" /></a>
\t\t\t
\t\t</div>
END;
        echo '<div class="result-stats">';
        $num_related_records = $this->_record->numRelatedRecords($this->_relationship_name, $this->_where);
        $now_showing_start = $this->_start + 1;
        $now_showing_finish = min($this->_start + $this->_limit, $this->_record->numRelatedRecords($this->_relationship_name, $this->_where));
        echo df_translate('scripts.Dataface.RelatedList.toHtml.MESSAGE_FOUND', "<b>Found</b> " . $num_related_records . " Records in relationship <i>" . $this->_relationship_name . "</i>", array('num' => $num_related_records, 'relationship' => $this->_relationship_name)) . "<br/>" . df_translate('scripts.Dataface.RelatedList.toHtml.MESSAGE_NOW_SHOWING', "<b>Now Showing</b> " . $now_showing_start . " to " . $now_showing_finish, array('start' => $now_showing_start, 'finish' => $now_showing_finish)) . "</div>\n\t\t\t<div class=\"limit-field\">\n\t\t\t";
        echo $resultController->limitField('related:');
        echo "</div>\n\t\t\t<div class=\"prev-link\">" . $this->_backButtonHtml() . "</div>\n\t\t\t<div class=\"next-link\">" . $this->_forwardButtonHtml() . "</div>\n\t\t";
        import('Dataface/ActionTool.php');
        $at =& Dataface_ActionTool::getInstance();
        $actions = $at->getActions(array('category' => 'related_list_actions'));
        echo <<<END
\t\t<div class="result-list-actions">
\t\t<ul class="icon-only" id="result-list-actions">
END;
        foreach ($actions as $action) {
            if (@$action['onclick']) {
                $onclick = 'onclick="' . htmlspecialchars($action['onclick']) . '"';
            } else {
                $onclick = '';
            }
            echo <<<END
\t\t\t  <li id="result-list-actions-{$action['id']}" class="plain">
\t\t\t
\t\t\t<a id="result-list-actions-{$action['id']}-link"href="{$action['url']}" {$onclick}
\t\t\t   accesskey="e" title="{$action['description']}">
\t\t\t   <img id="result-list-actions-{$action['id']}-icon"src="{$action['icon']}" alt="{$action['label']}"/>                   
\t\t\t\t<span class="action-label">{$action['label']}</span>
\t\t\t</a>
\t\t  </li>
END;
        }
        echo <<<END
\t\t</ul>
\t\t
\t\t</div>
END;
        $relatedResultController = ob_get_contents();
        ob_end_clean();
        ob_start();
        //echo '<div style="clear: both"/>';
        echo '<div class="resultlist-controller">';
        echo $relatedResultController;
        echo "</div>";
        import('Dataface/ActionTool.php');
        $at =& Dataface_ActionTool::getInstance();
        $selected_actions = $at->getActions(array('category' => 'selected_related_result_actions'));
        if ($this->_relationship->_schema['list']['type'] == 'treetable') {
            import('Dataface/TreeTable.php');
            $treetable = new Dataface_TreeTable($this->_record, $this->_relationship->getName());
            echo $treetable->toHtml();
        } else {
            echo $moveUpForm;
            if ($this->_where) {
                $filterQuery =& $app->getQuery();
                echo '<div>Showing matches for query <em>&quot;' . htmlspecialchars($filterQuery['-related:search']) . '&quot;</em>
				<a href="' . $app->url('-related:search=') . '" title="Remove this filter to show all records in this relationship">
					<img src="' . DATAFACE_URL . '/images/delete.gif" alt="Remove filter" />
				</a>
				</div>';
            }
            echo '<div style="display:none" id="related_find_wrapper"></div>';
            if (count($records) > 0) {
                echo '
					<table class="listing relatedList relatedList--' . $this->_tablename . ' relatedList--' . $this->_tablename . '--' . $this->_relationship_name . '" id="relatedList">
					<thead>
					<tr>';
                if (count($selected_actions) > 0) {
                    echo '<th><input type="checkbox" onchange="toggleSelectedRows(this,\'relatedList\');"></th>
					';
                }
                $cols = array_keys(current($records));
                $col_tables = array();
                $table_keys = array();
                $usedColumns = array();
                foreach ($cols as $key) {
                    if ($key == $default_order_column) {
                        continue;
                    }
                    if (is_int($key)) {
                        continue;
                    }
                    if (isset($sort_columns[$key])) {
                        $class = 'sorted-column-' . $sort_columns[$key];
                        $query = array();
                        $qs_columns = $sort_columns;
                        unset($qs_columns[$key]);
                        $sort_query = $key . ' ' . ($sort_columns[$key] == 'desc' ? 'asc' : 'desc');
                        foreach ($qs_columns as $qcolkey => $qcolvalue) {
                            $sort_query .= ', ' . $qcolkey . ' ' . $qcolvalue;
                        }
                    } else {
                        $class = 'unsorted-column';
                        $sort_query = $key . ' asc';
                        foreach ($sort_columns as $scolkey => $scolvalue) {
                            $sort_query .= ', ' . $scolkey . ' ' . $scolvalue;
                        }
                    }
                    $sq = array('-related:sort' => $sort_query);
                    $link = Dataface_LinkTool::buildLink($sq);
                    $fullpath = $this->_relationship_name . '.' . $key;
                    $field =& $s->getField($fullpath);
                    if (isset($this->_relationship->_schema['visibility'][$key]) and $this->_relationship->_schema['visibility'][$key] == 'hidden') {
                        continue;
                    }
                    if ($field['visibility']['list'] != 'visible') {
                        continue;
                    }
                    if ($s->isBlob($fullpath) or $s->isPassword($fullpath)) {
                        continue;
                    }
                    if (PEAR::isError($field)) {
                        $field->addUserInfo("Error getting field info for field {$key} in RelatedList::toHtml() on line " . __LINE__ . " of file " . __FILE__);
                        return $field;
                    }
                    $usedColumns[] = $key;
                    $label = $field['widget']['label'];
                    if (isset($field['column']) and @$field['column']['label']) {
                        $label = $field['column']['label'];
                    }
                    $legend = '';
                    if (@$field['column'] and @$field['column']['legend']) {
                        $legend = '<span class="column-legend">' . htmlspecialchars($field['column']['legend']) . '</span>';
                    }
                    echo '<th><a href="' . $link . '">' . $field['widget']['label'] . "</a> {$legend}</th>\n";
                    if (!isset($col_tables[$key])) {
                        $col_tables[$key] = $field['tablename'];
                    }
                    if (!isset($table_keys[$col_tables[$key]])) {
                        $table_table =& Dataface_Table::loadTable($field['tablename']);
                        $table_keys[$col_tables[$key]] = array_keys($table_table->keys());
                        unset($table_table);
                    }
                    unset($field);
                }
                echo "</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody id=\"relatedList-body\">\n\t\t\t\t\t";
                $limit = min($this->_limit, $this->_record->numRelatedRecords($this->_relationship_name, $this->_where) - $this->_start);
                $relatedTable = $this->_relationship->getDomainTable();
                if (PEAR::isError($relatedTable)) {
                    $relatedTable = reset($r['selected_tables']);
                }
                $relatedTable = Dataface_Table::loadTable($relatedTable);
                $relatedKeys = array_keys($relatedTable->keys());
                foreach (array_keys($relatedKeys) as $i) {
                    $relatedKeys[$i] = $this->_relationship_name . "." . $relatedKeys[$i];
                }
                $fullpaths = array();
                $fields_index = array();
                foreach ($usedColumns as $key) {
                    $fullpaths[$key] = $this->_relationship_name . '.' . $key;
                    $fields_index[$key] =& $s->getField($fullpaths[$key]);
                }
                $evenRow = false;
                for ($i = $this->_start; $i < $this->_start + $limit; $i++) {
                    $rowClass = $evenRow ? 'even' : 'odd';
                    $evenRow = !$evenRow;
                    if ($default_order_column and @$perms['reorder_related_records']) {
                        $style = 'cursor:move';
                        // A variable that will be used below in javascript to decide
                        // whether to make the table sortable or not
                        $sortable_js = 'true';
                    } else {
                        $style = '';
                        $sortable_js = 'false';
                    }
                    unset($rrec);
                    $rrec = $this->_record->getRelatedRecord($this->_relationship_name, $i, $this->_where, $sort_columns_str);
                    //new Dataface_RelatedRecord($this->_record, $this->_relationship_name, $this->_record->getValues($fullpaths, $i, 0, $sort_columns_str));
                    $rrecid = $rrec->getId();
                    echo "<tr class=\"listing {$rowClass}\" style=\"{$style}\" id=\"row_{$rrecid}\">";
                    if (count($selected_actions) > 0) {
                        echo '
						<td class="' . $rowClass . ' viewableColumn" nowrap>
							<input class="rowSelectorCheckbox" id="rowSelectorCheckbox:' . $rrecid . '" type="checkbox">
						';
                        echo '
						</td>';
                    }
                    $link_queries = array();
                    foreach ($usedColumns as $key) {
                        if (is_int($key)) {
                            continue;
                        }
                        $fullpath = $fullpaths[$key];
                        unset($field);
                        $field =& $fields_index[$key];
                        //$s->getField($fullpath);
                        $srcRecord =& $rrec->toRecord($field['tablename']);
                        $link = $srcRecord->getURL('-action=browse');
                        /*
                        if ( isset($link_queries[$col_tables[$key]]) ){
                        	$query = $link_queries[$col_tables[$key]];
                        	$failed = false;
                        } else {
                        	
                        	$query = array( "-action"=>"browse", "-relationship"=>null, "-cursor"=>0, "-table"=>$col_tables[$key]) ;
                        	$failed = false;
                        		// flag to indicate if we failed to generate appropriate link
                        	
                        	foreach ( $table_keys[$col_tables[$key]] as $table_key ){
                        		$query[$table_key] = "=".$this->_record->getValueAsString($this->_relationship_name.'.'.$table_key, $i, $this->_where, $sort_columns_str);
                        		if ( $query[$table_key] == '=' ){
                        			if ( isset( $fkeys[$col_tables[$key]][$table_key]) ){
                        				$query[$table_key] = $this->_record->parseString($fkeys[$col_tables[$key]][$table_key]);
                        			} else {
                        				$failed = true;
                        			}
                        		}
                        	}
                        	$link_queries[$col_tables[$key]] = $query;
                        }
                        
                        if ( $failed ){
                        	$link = "#";
                        } else {
                        	
                        	$link = Dataface_LinkTool::buildLink($query, false);
                        }
                        */
                        //$val = '';
                        $val = $this->_record->preview($fullpath, $i, 255, $this->_where, $sort_columns_str);
                        $title = "";
                        if ($key == $default_order_column) {
                            unset($field);
                            unset($srcRecord);
                            continue;
                        } else {
                            if ($val != 'NO ACCESS') {
                                $accessClass = 'viewableColumn';
                            } else {
                                $accessClass = '';
                            }
                            $cellClass = 'resultListCell resultListCell--' . $key;
                            $renderVal = $this->renderCell($srcRecord, $field['Field']);
                            if (isset($renderVal)) {
                                $val = $renderVal;
                            } else {
                                if ($link and !@$field['noLinkFromListView']) {
                                    $val = "<a href=\"{$link}\" title=\"" . htmlspecialchars($title) . "\">" . $val . "</a>";
                                }
                            }
                            echo "<td class=\"{$cellClass} {$rowClass} {$accessClass}\">{$val}</td>\n";
                            unset($srcRecord);
                        }
                    }
                    echo "</tr>\n";
                }
                echo "</tbody>\n\t\t\t\t\t</table>";
                echo '<form id="result_list_selected_items_form" method="post">';
                $app =& Dataface_Application::getInstance();
                $q =& $app->getQuery();
                foreach ($q as $key => $val) {
                    if (strlen($key) > 1 and $key[0] == '-' and $key[1] == '-') {
                        continue;
                    }
                    echo '<input type="hidden" name="' . $key . '" value="' . htmlspecialchars($val) . '">';
                }
                echo '<input type="hidden" name="--selected-ids" id="--selected-ids">';
                echo '<input type="hidden" name="-from" id="-from" value="' . $query['-action'] . '">';
                echo '</form>';
                if (count($selected_actions) > 0) {
                    echo '<div id="selected-actions">' . df_translate('scripts.GLOBAL.LABEL_WITH_SELECTED', 'With Selected') . ': <ul class="selectedActionsMenu" id="result_list-selectedActionsMenu">';
                    foreach ($selected_actions as $action) {
                        echo <<<END
\t\t\t\t\t\t<li id="action-{$action['id']}"><a href="{$action['url']}" title="{$action['description']}">{$action['label']}</a></li>
END;
                    }
                    echo '</ul></div>';
                }
                echo '<div class="resultlist-controller">';
                echo $relatedResultController;
                echo '</div>';
                // This bit of javascript goes through all of the columns and removes all columns that
                // don't have any accessible information for this query.  (i.e. any columns for which
                // each row's value is 'NO ACCESS' is removed
                $prototype_url = DATAFACE_URL . '/js/scriptaculous/lib/prototype.js';
                $scriptaculous_url = DATAFACE_URL . '/js/scriptaculous/src/scriptaculous.js';
                $effects_url = DATAFACE_URL . '/js/scriptaculous/src/effects.js';
                $dragdrop_url = DATAFACE_URL . '/js/scriptaculous/src/dragdrop.js';
                $thisRecordID = $this->_record->getId();
                echo <<<END
\t\t\t\t<script language="javascript" src="{$prototype_url}"></script>
\t\t\t\t<script language="javascript" src="{$scriptaculous_url}"></script>
\t\t\t\t<script language="javascript" src="{$effects_url}"></script>
\t\t\t\t<script language="javascript" src="{$dragdrop_url}"></script>
\t\t\t\t<script language="javascript"><!--
\t\t\t\tfunction removeUnauthorizedColumns(){
\t\t\t\t\tvar relatedList = document.getElementById('relatedList');
\t\t\t\t\tvar trs = relatedList.getElementsByTagName('tr');
\t\t\t\t\tvar viewableColumns = [];
\t\t\t\t\tvar numCols = 0;
\t\t\t\t\tfor (var i=0; i<trs.length; i++){
\t\t\t\t\t\tvar tr = trs[i];
\t\t\t\t\t\tvar tds = tr.getElementsByTagName('td');
\t\t\t\t\t\tfor (var j=0; j<tds.length; j++){
\t\t\t\t\t\t\tvar td = tds[j];
\t\t\t\t\t\t\tif ( td.className.indexOf('viewableColumn') >= 0 ){
\t\t\t\t\t\t\t\tviewableColumns[j] = true;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\tnumCols = j;
\t\t\t\t\t\t}
\t\t\t\t\t}
\t\t\t\t\tfor (var j=viewableColumns.length; j<=numCols; j++){
\t\t\t\t\t\tviewableColumns[j] = false;
\t\t\t\t\t}
\t\t\t\t\t
\t\t\t\t\t
\t\t\t\t\tfor (var i=0; i<trs.length; i++){
\t\t\t\t\t\tvar tds = trs[i].getElementsByTagName('td');
\t\t\t\t\t\tif ( tds.length <= 0 ){
\t\t\t\t\t\t\tvar tds = trs[i].getElementsByTagName('th');
\t\t\t\t\t\t}
\t\t\t\t\t\t
\t\t\t\t\t\tfor (var j=0; j<viewableColumns.length; j++){
\t\t\t\t\t\t\tif ( !viewableColumns[j] ){
\t\t\t\t\t\t\t\ttds[j].style.display = 'none';
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t\t
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\tremoveUnauthorizedColumns();
\t\t\t\t
\t\t\t\t
\t\t\t\tif ( {$sortable_js} ){
\t\t\t\t\tSortable.create("relatedList-body",
\t\t\t\t\t\t\t{
\t\t\t\t\t\t\t\tdropOnEmpty:true,
\t\t\t\t\t\t\t\tconstraint:false, 
\t\t\t\t\t\t\t\t//handle:'move-handle',
\t\t\t\t\t\t\t\ttag:'tr',
\t\t\t\t\t\t\t\tonUpdate: function(container){
\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t\tvar params = Sortable.serialize('relatedList-body');
\t\t\t\t\t\t\t\t\tparams += '&'+window.location.search.substring(1);
\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t\tparams += '&-action=reorder_related_records';//&--recordid='+escape('{$thisRecordID}');
\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t\tnew Ajax.Request(
\t\t\t\t\t\t\t\t\t\tDATAFACE_SITE_HREF, {
\t\t\t\t\t\t\t\t\t\t\tmethod: 'post', 
\t\t\t\t\t\t\t\t\t\t\tparameters: params, 
\t\t\t\t\t\t\t\t\t\t\tonSuccess: function(transport){
\t\t\t\t\t\t\t\t\t\t\t    
\t\t\t\t\t\t\t\t\t\t\t\t//document.getElementById('details-controller').innerHTML = transport.responseText;
\t\t\t\t\t\t\t\t\t\t\t},
\t\t\t\t\t\t\t\t\t\t\tonFailure:function(){
\t\t\t\t\t\t\t\t\t\t\t\talert('Failed to sort records.');
\t\t\t\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t\t);
\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t//only:'movable'
\t\t\t\t\t\t\t});
\t\t\t\t\t\t//Sortable.create("dataface-sections-main",
\t\t\t\t\t\t//{dropOnEmpty:true,constraint:false, handle:'movable-handle',tag:'div',only:'movable', onUpdate:updateSections});
\t\t\t\t}\t
\t\t\t\t
\t\t\t\t//--></script>
\t\t\t\t
END;
            } else {
                echo "<p>" . df_translate('scripts.GLOBAL.NO_RECORDS_MATCHED_REQUEST', 'No records matched your request.') . "</p>";
            }
        }
        $out .= ob_get_contents();
        ob_end_clean();
        return $out;
    }