/** * If there is a link associated with a field of the table, this method * returns a full and proper url for the link. * @param fieldname The name of the field in the table. * @param $values */ function resolveLink($fieldname, &$record) { if (!is_a($record, 'Dataface_Record')) { trigger_error("Dataface_TableTool::resolveLink() expects an object of type 'Dataface_Record' as the second argument, but received '" . get_class($record) . "'\n<br>" . Dataface_Error::printStackTrace()); } $link = $record->getLink($fieldname); if (is_array($link)) { return Dataface_LinkTool::buildLink($link); } else { if ($link) { return $this->_app->filterUrl($link); } else { return null; } } }
/** * If there is a link associated with a field of the table, this method * returns a full and proper url for the link. * @param fieldname The name of the field in the table. * @param $values */ function resolveLink($fieldname, &$record) { if (!is_a($record, 'Dataface_Record')) { throw new Exception("Dataface_TableTool::resolveLink() expects an object of type 'Dataface_Record' as the second argument, but received '" . get_class($record)); } $link = $record->getLink($fieldname); if (is_array($link)) { return Dataface_LinkTool::buildLink($link); } else { if ($link) { return $this->_app->filterUrl($link); } else { return null; } } }
function test_build_links() { $_GET = array('-table' => 'Profiles'); $_POST = array(); $_REQUEST = array('-table' => 'Profiles'); $link = Dataface_LinkTool::buildLink(array("fname" => "John", "lname" => "Thomas")); $this->assertEquals($_SERVER['HOST_URI'] . $_SERVER['PHP_SELF'] . '?fname=John&lname=Thomas&-table=Profiles', $link); // try to use the context a bit $_GET['-table'] = 'Addresses'; $_REQUEST = $_GET; $link = Dataface_LinkTool::buildLink(array("fname" => "John", "lname" => "Thomas")); $this->assertEquals($_SERVER['HOST_URI'] . $_SERVER['PHP_SELF'] . '?fname=John&lname=Thomas&-table=Profiles', $link); $link = Dataface_LinkTool::buildLink(array("fname" => "John", "lname" => "Thomas"), false); $this->assertEquals($_SERVER['HOST_URI'] . $_SERVER['PHP_SELF'] . '?fname=John&lname=Thomas&-table=Profiles', $link); $link = Dataface_LinkTool::buildLink(array("fname" => "John", "lname" => "Thomas", "-table" => null)); $this->assertEquals($_SERVER['HOST_URI'] . $_SERVER['PHP_SELF'] . '?fname=John&lname=Thomas&-table=Profiles', $link); }
function limitField($prefix = '') { $currentLink = Dataface_LinkTool::buildLink(array('-' . $prefix . 'limit' => null, '-' . $prefix . 'skip' => 0)); if (!$prefix) { $limitval = $this->_resultSet->limit(); } else { if (isset($_GET['-' . $prefix . 'limit'])) { $limitval = $_GET['-' . $prefix . 'limit']; } else { $limitval = 30; } } $limitField = '<input type="text" value="' . $limitval . '" onchange="window.location = \'' . $currentLink . '&-' . $prefix . 'limit=\'+this.value" size="3"/>'; $displayStr = df_translate('display x records per page', 'Display %s records per page'); return '(' . sprintf($displayStr, $limitField) . ')'; }
function toHtml() { $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); if (isset($query['-sort'])) { $sortcols = explode(',', trim($query['-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 should now be of the form [ColumnName] -> [Direction] // where Direction is "asc" or "desc" if ($this->_resultSet->found() > 0) { if (@$app->prefs['use_old_resultlist_controller']) { ob_start(); df_display(array(), 'Dataface_ResultListController.html'); $controller = ob_get_contents(); ob_end_clean(); } ob_start(); //echo '<div style="clear: both"/>'; if (!defined('Dataface_ResultList_Javascript')) { define('Dataface_ResultList_Javascript', true); echo '<script language="javascript" type="text/javascript" src="' . DATAFACE_URL . '/js/Dataface/ResultList.js"></script>'; } if (!@$app->prefs['hide_result_filters'] and count($this->_filterCols) > 0) { echo $this->getResultFilters(); } unset($query); if (@$app->prefs['use_old_resultlist_controller']) { echo '<div class="resultlist-controller" id="resultlist-controller-top">'; echo $controller; echo "</div>"; } $canSelect = false; if (!@$app->prefs['disable_select_rows']) { $canSelect = Dataface_PermissionsTool::checkPermission('select_rows', Dataface_PermissionsTool::getPermissions($this->_table)); } echo '<table id="result_list" class="listing"> <thead> <tr>'; if ($canSelect) { echo '<th><input type="checkbox" onchange="toggleSelectedRows(this,\'result_list\');"></th>'; } if (!@$app->prefs['disable_ajax_record_details']) { echo ' <th><!-- Expand record column --></th> '; } $results =& $this->getResults(); $perms = array(); $numCols = 0; $rowHeaderHtml = $this->renderRowHeader(); if (isset($rowHeaderHtml)) { echo $rowHeaderHtml; } else { foreach ($this->_columns as $key) { if (in_array($key, $this->_columns)) { if (!($perms[$key] = Dataface_PermissionsTool::checkPermission('list', $this->_table, array('field' => $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('-sort' => $sort_query); $link = Dataface_LinkTool::buildLink($sq); $numCols++; $label = $this->_table->getFieldProperty('column:label', $key); $legend = $this->_table->getFieldProperty('column:legend', $key); if ($legend) { $legend = '<span class="column-legend">' . htmlspecialchars($legend) . '</span>'; } if (!$label) { $label = $this->_table->getFieldProperty('widget:label', $key); } echo "<th class=\"{$class}\"><a href=\"{$link}\">" . htmlspecialchars($label) . "</a> {$legend}</th>"; } } } echo "</tr>\n\t\t\t\t</thead>\n\t\t\t\t<tbody>\n\t\t\t\t"; $cursor = $this->_resultSet->start(); $results->reset(); $baseQuery = array(); foreach ($_GET as $key => $value) { if (strpos($key, '-') !== 0) { $baseQuery[$key] = $value; } } $evenRow = false; while ($results->hasNext()) { $rowClass = $evenRow ? 'even' : 'odd'; $evenRow = !$evenRow; $record =& $results->next(); if (!$record->checkPermission('view')) { $cursor++; unset($record); continue; } $rowClass .= ' ' . $this->getRowClass($record); $query = array_merge($baseQuery, array("-action" => "browse", "-relationship" => null, "-cursor" => $cursor++)); if ($record->checkPermission('link')) { if (@$app->prefs['result_list_use_geturl']) { $link = $record->getURL('-action=view'); } else { $link = Dataface_LinkTool::buildLink($query) . '&-recordid=' . urlencode($record->getId()); } } else { $del =& $record->_table->getDelegate(); if ($del and method_exists($del, 'no_access_link')) { $link = $del->no_access_link($record); } else { $link = null; } } $recordid = $record->getId(); echo "<tr class=\"listing {$rowClass}\">"; if ($canSelect) { echo '<td><input class="rowSelectorCheckbox" id="rowSelectorCheckbox:' . $record->getId() . '" type="checkbox"></td>'; } if (!@$app->prefs['disable_ajax_record_details']) { echo '<td>'; echo '<script language="javascript" type="text/javascript"><!-- registerRecord(\'' . addslashes($recordid) . '\', ' . $record->toJS(array()) . '); //--></script> <img src="' . DATAFACE_URL . '/images/treeCollapsed.gif" onclick="resultList.showRecordDetails(this, \'' . addslashes($recordid) . '\')"/>'; $at =& Dataface_ActionTool::getInstance(); $actions = $at->getActions(array('category' => 'list_row_actions', 'record' => &$record)); //print_r($actions); if (count($actions) > 0) { echo ' <span class="row-actions">'; foreach ($actions as $action) { 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> '; } echo '</span>'; } echo '</td>'; unset($at, $actions); } $rowContentHtml = $this->renderRow($record); if (isset($rowContentHtml)) { echo $rowContentHtml; } else { //$expandTree=false; // flag to indicate when we added the expandTree button //if ( @$app->prefs['enable_ajax_record_details'] === 0 ){ // $expandTree = true; //} foreach ($this->_columns as $key) { $thisField =& $record->_table->getField($key); if (!$perms[$key]) { continue; } $val = $this->renderCell($record, $key); if ($record->checkPermission('edit', array('field' => $key)) and !$record->_table->isMetaField($key)) { $editable_class = 'df__editable_wrapper'; } else { $editable_class = ''; } if (!@$thisField['noLinkFromListView'] and $link and $val) { $val = "<a href=\"{$link}\" class=\"unmarked_link\">" . $val . "</a>"; $editable_class = ''; } else { } if (@$thisField['noEditInListView']) { $editable_class = ''; } echo "<td id=\"td-" . rand() . "\" class=\"{$rowClass} {$editable_class}\"> {$val}</td>"; unset($thisField); } } echo "</tr>"; echo "<tr class=\"listing {$rowClass}\" style=\"display:none\" id=\"{$recordid}-row\">"; if ($canSelect) { echo "<td><!--placeholder for checkbox col --></td>"; } echo "<td colspan=\"" . ($numCols + 1) . "\" id=\"{$recordid}-cell\"></td>\n\t\t\t\t\t </tr>"; unset($record); } if (@$app->prefs['enable_resultlist_add_row']) { echo "<tr id=\"add-new-row\" df:table=\"" . htmlspecialchars($this->_table->tablename) . "\">"; if ($canSelect) { $colspan = 2; } else { $colspan = 1; } 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>"; foreach ($this->_columns as $key) { echo "<td><span df:field=\"" . htmlspecialchars($key) . "\"></span></td>"; } echo "</tr>"; } echo "</tbody>\n\t\t\t\t</table>"; if ($canSelect) { echo '<form id="result_list_selected_items_form" method="post" action="' . df_absolute_url(DATAFACE_SITE_HREF) . '">'; $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="' . urlencode($key) . '" value="' . htmlspecialchars($val) . '" />'; } echo '<input type="hidden" name="--selected-ids" id="--selected-ids" />'; echo '<input type="hidden" name="-from" id="-from" value="' . $q['-action'] . '" />'; echo '<input type="hidden" name="--redirect" value="' . base64_encode($app->url('')) . '" />'; echo '</form>'; import('Dataface/ActionTool.php'); $at =& Dataface_ActionTool::getInstance(); $actions = $at->getActions(array('category' => 'selected_result_actions')); if (count($actions) > 0) { echo '<div id="selected-actions">' . df_translate('scripts.Dataface_ResultList.MESSAGE_WITH_SELECTED', "With Selected") . ': <ul class="selectedActionsMenu" id="result_list-selectedActionsMenu">'; foreach ($actions as $action) { $img = ''; if (@$action['icon']) { $img = '<img src="' . $action['icon'] . '"/>'; } if (!@$action['onclick'] and !$action['url']) { $action['onclick'] = "return actOnSelected('result_list', '" . @$action['name'] . "'" . (@$action['confirm'] ? ", function(){return confirm('" . addslashes($action['confirm']) . "');}" : "") . ")"; } echo <<<END \t\t\t\t\t\t<li id="action-{$action['id']}"><a href="{$action['url']}" onclick="{$action['onclick']}" title="{$action['description']}">{$img}{$action['label']}</a></li> END; } echo '</ul></div>'; } } if (@$app->prefs['use_old_resultlist_controller']) { echo '<div class="resultlist-controller" id="resultlist-controller-bottom">'; echo $controller; echo '</div>'; } $out = ob_get_contents(); ob_end_clean(); } else { if (@$app->prefs['use_old_resultlist_controller']) { ob_start(); df_display(array(), 'Dataface_ResultListController.html'); $out = ob_get_contents(); ob_end_clean(); } else { $out = ''; } $out .= "<p style=\"clear:both\">" . df_translate('scripts.GLOBAL.MESSAGE_NO_MATCH', "No records matched your request.") . "</p>"; } return $out; }
function handle(&$params) { import('Dataface/ExistingRelatedRecordForm.php'); $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $resultSet =& $app->getResultSet(); //$record =& $app->getRecord(); // loads the current record if (!isset($query['-relationship'])) { return PEAR::raiseError(Dataface_LanguageTool::translate('Error: No relationship specified', 'Error. No relationship was specified when trying to add existing related record.'), DATAFACE_E_NOTICE); } $record = null; $form = new Dataface_ExistingRelatedRecordForm($record, $query['-relationship']); $res = $form->_build(); if (PEAR::isError($res)) { return Dataface_Error::permissionDenied($res->getMessage()); } /* * * We need to add the current GET parameter flags (the GET vars starting with '-') so * that the controller knows to pass control to this method again upon form submission. * */ foreach ($query as $key => $value) { if (strpos($key, '-') === 0) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); } } /* * Store the current query string (the portion after the '?') in the form, so we * can retrieve it after and redirect back to our original location. */ $form->addElement('hidden', '-query'); $form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING'])); if (!$form->_record || !is_a($form->_record, 'Dataface_Record')) { trigger_error(Dataface_LanguageTool::translate('Fatal Error', 'Fatal Error: Form should have loaded record but the record was null. ' . Dataface_Error::printStackTrace(), array('stack_trace' => Dataface_Error::printStackTrace(), 'msg' => 'Form should have loaded record but the record was null.')), E_USER_ERROR); } if (!Dataface_PermissionsTool::checkPermission('add existing related record', $form->_record)) { return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Error: Permission denied adding existing related record', 'Permission Denied. You do not have sufficient permissions to add an existing related record. Required permission: "add existing related record", but you have only been granted permissions: "' . implode(',', $form->_record->getPermissions()) . '".', array('required_permission' => 'add existing related record', 'granted_permissions' => implode(',', $form->_record->getPermissions())))); } if ($form->validate()) { $res = $form->process(array(&$form, 'save'), true); $response =& Dataface_Application::getResponse(); if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) { return $res; } else { if (Dataface_Error::isNotice($res)) { //$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage(); $app->addError(PEAR::raiseError(df_translate('Failed to add record because of errors', 'Failed to add record to relationship because of the following errors:'), DATAFACE_E_NOTICE)); $app->addError($res); $success = false; } else { $success = true; } } if ($success) { import('Dataface/Utilities.php'); Dataface_Utilities::fireEvent('after_action_existing_related_record'); $fquery = array('-action' => 'browse'); $msg = Dataface_LanguageTool::translate('Record successfully added to relationship', "The record has been successfully added to the " . $query['-relationship'] . " relationship.\n", array('relationship' => $query['-relationship'])); $msg = urlencode(trim(($success ? $msg : '') . @$response['--msg'])); $vals = $form->exportValues(); if (isset($vals['--redirect'])) { $qmark = strpos($vals['--redirect'], '?') !== false ? '&' : '?'; header('Location: ' . $vals['--redirect'] . $qmark . '--msg=' . $msg); exit; } foreach ($vals['__keys__'] as $key => $value) { $fquery[$key] = "=" . $value; } $link = Dataface_LinkTool::buildLink($fquery); header("Location: {$link}" . "&--msg=" . $msg); exit; } } ob_start(); $form->display(); $out = ob_get_contents(); ob_end_clean(); $context = array('form' => $out); if (isset($query['-template'])) { $template = $query['-template']; } else { if (isset($params['action']['template'])) { $template = $params['action']['template']; } else { $template = 'Dataface_Add_Existing_Related_Record.html'; } } df_display($context, $template, true); }
public static function buildSetLink($query, $useContext = true, $forceContext = false) { return Dataface_LinkTool::buildLink($query, $useContext, $forceContext, true); }
/** * Returns the URL to this record. * * @param $params An array of parameters to use when building the url. e.g., array('-action'=>'edit') * would cause the URL to be for editing this record. * * @returns String url to this record. */ function getURL($params = array()) { if (is_string($params)) { $pairs = explode('&', $params); $params = array(); foreach ($pairs as $pair) { list($key, $value) = explode('=', $pair); $params[$key] = $value; } } if ($this->secureDisplay and !$this->checkPermission('link')) { $del =& $this->_table->getDelegate(); if ($del and method_exists($del, 'no_access_link')) { return $del->no_access_link($this, $params); } } $params['-table'] = $this->_table->tablename; if (!isset($params['-action'])) { $params['-action'] = 'browse'; } foreach (array_keys($this->_table->keys()) as $key) { $params[$key] = '=' . $this->strval($key); } $delegate =& $this->_table->getDelegate(); if (isset($delegate) and method_exists($delegate, 'getURL')) { $res = $delegate->getURL($this, $params); if ($res and is_string($res)) { return $res; } } import('Dataface/LinkTool.php'); //$linkTool =& Dataface_LinkTool::getInstance(); return Dataface_LinkTool::buildLink($params, false); }
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; }
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>"' . htmlspecialchars($filterQuery['-related:search']) . '"</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; }
/** * Handles initialization and control for the import records form. */ function _import_init() { import('Dataface/ImportForm.php'); $form = new Dataface_ImportForm($this->_tablename); $record =& $form->_record; if (!Dataface_PermissionsTool::edit($record)) { $this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line " . __LINE__ . " of file " . __FILE__ . " --></div>"; return; } $form->_build(); $this->_vars['form'] =& $form; if ($form->validate()) { //echo "validated"; $querystr = $form->exportValue('-query'); if (intval($form->_step) === 1) { if (preg_match('/-step=1/', $querystr)) { $querystr = preg_replace('/-step=1/', '-step=2', $querystr); } else { $querystr .= '&-step=2'; } $importTablename = $form->process(array(&$form, 'import')); //echo "Table: $importTablename"; //exit; //$link = 'Location: '.$_SERVER['PHP_SELF'].'?'.$querystr.'&--importTablename='.$importTablename; //echo $link; //exit; header('Location: ' . $_SERVER['PHP_SELF'] . '?' . $querystr . '&--importTablename=' . $importTablename); exit; } else { $records = $form->process(array(&$form, 'import')); $keys = $form->exportValue('__keys__'); $keys['-action'] = 'browse'; $keys['-step'] = null; $keys['-query'] = null; $link = Dataface_LinkTool::buildLink($keys); $response =& Dataface_Application::getResponse(); $msg = urlencode(trim("Records imported successfully.\n" . @$response['--msg'])); header('Location: ' . $link . '&--msg=' . $msg); exit; } } //echo "Not validated"; }
function limitField($prefix = '') { $currentLink = Dataface_LinkTool::buildLink(array('-' . $prefix . 'limit' => null)); if (!$prefix) { $limitval = $this->_resultSet->limit(); } else { if (isset($_GET['-' . $prefix . 'limit'])) { $limitval = $_GET['-' . $prefix . 'limit']; } else { $limitval = 30; } } return '(Display <input type="text" value="' . $limitval . '" onchange="window.location = \'' . $currentLink . '&-' . $prefix . 'limit=\'+this.value" size="3"/> Records per page)'; }
function handle(&$params) { //global $myctr; $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $resultSet =& $app->getResultSet(); //$record =& $app->getRecord(); // loads the current record import('Dataface/ShortRelatedRecordForm.php'); if (!isset($query['-relationship'])) { return PEAR::raiseError(Dataface_LanguageTool::translate('No relationship specified in new related record', 'No relationship was specified while trying to create new related record. Please specify a relationship.'), DATAFACE_E_ERROR); } $record = null; // we let the Form automatically handle loading of record. $form = new Dataface_ShortRelatedRecordForm($record, $query['-relationship']); $form->_build(); /* * * We need to add the current GET parameter flags (the GET vars starting with '-') so * that the controller knows to pass control to this method again upon form submission. * */ //$myctr = 0; foreach ($query as $key => $value) { //echo "doing $key"; if (strpos($key, '-') === 0) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); //if ( $myctr == 2 ) exit; } //$myctr++; } /* * Store the current query string (the portion after the '?') in the form, so we * can retrieve it after and redirect back to our original location. */ $form->addElement('hidden', '-query'); $form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING'])); if (!Dataface_PermissionsTool::checkPermission('add new related record', $form->_record, array('relationship' => $query['-relationship']))) { return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Permission denied while trying to add new related record', 'Permission Denied: You do not have permission to add related records to the current record.')); //$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>"; //return; } if ($form->validate()) { $vals = $form->exportValues(); $res = $form->process(array(&$form, 'save'), true); $response =& Dataface_Application::getResponse(); if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) { return $res; //$this->_vars['error'] = "<div class=\"error\">Error. ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>"; //return; } else { if (Dataface_Error::isNotice($res)) { $success = false; $app->addError($res); //$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage(); } else { $success = true; } } if ($success) { import('Dataface/Utilities.php'); Dataface_Utilities::fireEvent('after_action_new_related_record'); $fquery = array('-action' => 'browse'); $table = Dataface_Table::loadTable($query['-table']); $rel = $table->getRelationship($query['-relationship']); $msg = urlencode(trim(Dataface_LanguageTool::translate("Record successfully added to relationship", "Record successfully added to " . $rel->getLabel() . " relationship.\n", array('relationship' => $rel->getLabel())) . (isset($response['--msg']) ? $response['--msg'] : ''))); foreach ($vals['__keys__'] as $key => $value) { $fquery[$key] = "=" . $value; } $fquery['-relationship'] = $query['-relationship']; $fquery['-action'] = 'related_records_list'; $link = Dataface_LinkTool::buildLink($fquery); $app->redirect("{$link}" . "&--msg=" . $msg); } } ob_start(); $gdefs = array(); foreach ($_GET as $gkey => $gval) { if (substr($gkey, 0, 4) == '--q:') { $gdefs[substr($gkey, 4)] = $gval; } } if (count($gdefs) > 0) { $form->setDefaults($gdefs); } $form->display(); $out = ob_get_contents(); ob_end_clean(); $context = array('form' => $out); if (isset($query['-template'])) { $template = $query['-template']; } else { if (isset($params['action']['template'])) { $template = $params['action']['template']; } else { $template = 'Dataface_Add_New_Related_Record.html'; } } df_display($context, $template, true); }