function getPermissions(&$record) { if (getUser()) { return Dataface_PermissionsTool::ALL(); } return null; }
/** * Returns permissions array. This method is called every time an action is * performed to make sure that the user has permission to perform the action. * @param record A Dataface_Record object (may be null) against which we check * permissions. * @see Dataface_PermissionsTool * @see Dataface_AuthenticationTool */ function getPermissions(&$record) { if (SweteTools::isAdmin()) { return Dataface_PermissionsTool::ALL(); } else { return Dataface_PermissionsTool::NO_ACCESS(); } }
/** * Returns permissions array. This method is called every time an action is * performed to make sure that the user has permission to perform the action. * @param record A Dataface_Record object (may be null) against which we check * permissions. * @see Dataface_PermissionsTool * @see Dataface_AuthenticationTool */ function getPermissions($record) { $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser(); if ($user and $user->val('role') == 'ADMIN') { return Dataface_PermissionsTool::getRolePermissions('ADMIN'); } else { return Dataface_PermissionsTool::NO_ACCESS(); } }
function getPermissions(&$record) { // $record is a Dataface_Record object $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ($user) { return Dataface_PermissionsTool::ALL(); } return Dataface_PermissionsTool::NO_ACCESS(); }
function test_table_permissions() { $pt =& Dataface_PermissionsTool::getInstance(); $perms = $pt->getPermissions(Dataface_Table::loadTable('Profiles')); $this->assertEquals(array(1, 1, 1), array($perms['view'], $perms['edit'], $perms['delete'])); $perms = $pt->getPermissions(Dataface_Table::loadTable('Profiles'), array('field' => 'fname')); $this->assertEquals(array(1, 1, 1), array($perms['view'], $perms['edit'], $perms['delete'])); // varcharfield_checkboxes has view disabled in the fields.ini file $this->assertTrue(!$pt->view(Dataface_Table::loadTable('Test'), array('field' => 'varcharfield_checkboxes'))); $this->assertTrue($pt->edit(Dataface_Table::loadTable('Test'), array('field' => 'varcharfield_checkboxes'))); }
function getPermissions($record) { if (SweteTools::isAdmin()) { $perms = Dataface_PermissionsTool::ALL(); $perms['edit'] = 0; $perms['new'] = 0; $perms['copy'] = 0; $perms['update'] = 0; $perms['update_set'] = 0; return $perms; } }
/** * Returns permissions array. This method is called every time an action is * performed to make sure that the user has permission to perform the action. * @param record A Dataface_Record object (may be null) against which we check * permissions. * @see Dataface_PermissionsTool * @see Dataface_AuthenticationTool */ function getPermissions(&$record) { $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if (!isset($user)) { return Dataface_PermissionsTool::NO_ACCESS(); } // if the user is null then nobody is logged in... no access. // This will force a login prompt. $role = $user->val('role'); return Dataface_PermissionsTool::getRolePermissions($role); // Returns all of the permissions for the user's current role. }
function getCellTemplate($column, $fieldId, $value = null, $permissions = array('view' => 1, 'edit' => 1)) { $element = df_clone($this->elements[$column]); $element->setName($this->name . '[' . $this->next_row_id . '][' . $column . ']'); $element->updateAttributes(array('id' => $column . '_' . $fieldId, 'onchange' => (($this->addNew or $this->addExisting) ? 'dataGridFieldFunctions.addRowOnChange(this);' : '') . $element->getAttribute('onchange'), 'style' => 'width:100%;' . $element->getAttribute('style'))); if ($this->isFrozen() or !Dataface_PermissionsTool::checkPermission('edit', $permissions)) { $element->freeze(); } else { $element->unfreeze(); } if (isset($value)) { $element->setValue($value); } return $element->toHtml(); }
function getPermissions(&$record) { $app =& Dataface_Application::getInstance(); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); $query =& $app->getQuery(); if ($query['-action'] == 'new' and !isset($user)) { return Dataface_PermissionsTool::READ_EDIT(); } else { if ($user and isAdmin($user->val('role'))) { return Dataface_PermissionsTool::ALL(); } else { return Dataface_PermissionsTool::NO_ACCESS(); } } }
function Dataface_View($name, $sql = null) { import('Dataface/ViewRecord.php'); $this->name = $name; $this->tablename = $name; if (is_array($sql)) { // The sql is parsed SQL $this->sql_data = $sql; } else { $this->sql = $sql; } $this->app =& Dataface_Application::getInstance(); $this->_atts = array(); $this->_atts['name'] =& $this->tablename; $this->_atts['label'] = isset($this->app->_tables[$this->tablename]) ? $this->app->_tables[$this->tablename] : $this->tablename; $this->_permissions = Dataface_PermissionsTool::getRolePermissions($this->app->_conf['default_table_role']); }
function getPermissions($record) { $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser(); // If user is an admin defer to the application delegate class for // permissions if ($user and $user->val('role') == 'ADMIN') { return null; } elseif ($user and $user->val('role') == 'REGULAR') { return Dataface_PermissionsTool::getRolePermissions('REGULAR'); } if ($user) { // User is logged in return Dataface_PermissionsTool::READ_ONLY(); } // Defer to the application delegate class for all other users return null; }
function getPermissions(&$record) { $user =& SweteTools::getUser(); if (!isset($user)) { return null; } if (SweteTools::isAdmin()) { return null; } if (isset($record)) { require_once 'inc/SweteJob.class.php'; require_once 'inc/SweteDb.class.php'; if ($record->val('posted_by') === $user->val('username')) { //error_log($record->val("job_note_id")." note posted by ".$record->val('posted_by') ." user ".$user->val('username')); return Dataface_PermissionsTool::getRolePermissions('OWNER'); } } return Dataface_PermissionsTool::getRolePermissions('READ ONLY'); }
function handle($params) { $app = Dataface_Application::getInstance(); $query =& $app->getQuery(); $related_record = df_get_record_by_id($query['-related-record-id']); if (!$related_record || PEAR::isError($related_record)) { $this->out_404(); } $app->_conf['orig_permissions'] = $related_record->_record->getPermissions(); Dataface_PermissionsTool::addContextMask($related_record); $perms = $related_record->getPermissions(); //print_r($perms);exit; if (!@$perms['view']) { return Dataface_Error::permissionDenied('You don\'t have permission to view this record.'); } $query['-relationship'] = $related_record->_relationship->getName(); Dataface_JavascriptTool::getInstance()->import('xataface/actions/view_related_record.js'); df_display(array('related_record' => $related_record), 'xataface/actions/view_related_record.html'); }
function getPermissions(&$record) { $user =& SweteTools::getUser(); if (!isset($user)) { return null; } if (SweteTools::isAdmin()) { return null; } if (isset($record)) { $job = new SweteJob($record); if ($record->val("assigned_to") === $user->val('username')) { //error_log("job is assigned to ".$user->val('username')); return Dataface_PermissionsTool::getRolePermissions('ASSIGNEE'); } } //default return null; }
/** * Returns comma-delimited list of names of granted permissions in a given permissions * array. */ function namesAsString($permissions) { return implode(',', Dataface_PermissionsTool::namesAsArray($permissions)); }
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; }
/** * @brief Builds a widget that can be added to a form. This will delegate * to the WidgetHandler::buildWidget() method if defined for the field's widget * type. * * @param Dataface_Record &$record The Dataface Record that this widget * is to be editing. * @param array &$field The field definition. * @param HTML_QuickForm The form to which the widget will be added. * @param string $formFieldName The name of the field on the form. * @returns HTML_QuickForm_element */ function &buildWidget($record, &$field, $form, $formFieldName, $new = false, $permissions = null) { $table =& $record->_table; $widget =& $field['widget']; if (!isset($permissions)) { //$permissions =& $record->getPermissions(array('field'=>$field['name'])); $permissions = Dataface_PermissionsTool::ALL(); // reference to widget descriptor array } $pt =& Dataface_PermissionsTool::getInstance(); // Reference to permissions tool to operate on $permissions $widgetHandler =& $this->getWidgetHandler($widget['type']); if (isset($widgetHandler) and method_exists($widgetHandler, 'buildWidget')) { $el =& $widgetHandler->buildWidget($record, $field, $form, $formFieldName, $new); } else { $factory =& Dataface_FormTool::factory(); // A dummy HTML_QuickForm used as a factory to create temporary elements. // Reference to the table object. $el =& $factory->addElement($widget['type'], $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $formFieldName)); } if (PEAR::isError($el)) { throw new Exception($el->toString(), E_USER_ERROR); } $el->setFieldDef($field); if (isset($record) && $record && $record->_table->hasField($field['name'])) { if ($link = $record->getLink($field['name'])) { $el->setProperty('link', $link); } $el->setProperty('record_url', $record->getURL()); } $atts = $el->getAttributes(); if (!is_array($atts)) { $atts = array(); } $atts = array_merge($atts, $field['widget']['atts']); foreach ($atts as $k => $v) { if (strpos($k, 'data-xf-override-') === 0) { $atts[substr($k, 17)] = $v; } } if (!isset($atts['data-xf-field'])) { $atts['data-xf-field'] = $field['name']; } $el->setAttributes($atts); if ($new and !$pt->checkPermission('new', $permissions)) { $el->freeze(); } else { if (!$new and !$pt->checkPermission('edit', $permissions)) { $el->freeze(); } } /* // Deal with permissions on this field. if ( $pt->view($permissions) and !$pt->edit($permissions) ){ if ( !($new && $pt->checkPermission('new', $permissions)) ){ $el->freeze(); } } */ $el->record =& $record; $form->addElement($el); /* * * If there are any validation options set for the field, we must add these rules to the quickform * element. * */ $validators = $field['validators']; foreach ($validators as $vname => $validator) { /* * * $validator['arg'] would be specified in the INI file. * Example ini file listing: * ------------------------- * [FirstName] * widget:label = First name * widget:description = Enter your first name * validators:regex = "/[0-9a-zA-Z/" * * This would result in $validator['arg'] = "/[0-9a-zA-Z/" in this section * and $vname == "regex". Hence it would mean that a regular expression validator * is being placed on this field so that only Alphanumeric characters are accepted. * Please see documentation for HTML_QuickForm PEAR class for more information * about QuickForm validators. * */ if ($vname == 'required' && $widget['type'] == 'file') { continue; } $form->addRule($formFieldName, $validator['message'], $vname, @$validator['arg'], $widget['type'] == 'htmlarea' ? null : 'client'); } $this->pullField($record, $field, $form, $formFieldName, $new); $el->_persistantFreeze = true; return $el; }
/** * @brief Returns an HTML-friendly value of a field. * * @param string $fieldname The name of the field to return. * @param int $index For related fields indicates the index within the related list of the record to retrieve. * @param string $where Optional where clause to filter related list when retrieving a related field. * @param string $sort Optional sort clause when retrieving a related field. Used to sort related list before * selecting the related record from which the value is to be returned. * @param array $params Optional additional parameters to customize the HTML output. This may be passed to * include HTML attributes width and height to blob fields containing an image. * * @return string The HTML string result. * * @since 0.5 * * @section Synopsis * * This method sits above "display" on the output stack for a field. * I.e. it wraps display() and adds some extra filtering to make the * output directly appropriate to be displayed as HTML. In text fields * this will convert newlines to breaks, and in blob fields, this will output * either the full a-href tag or img tag depending on the type of content that * is stored. * * * @see display() * @see getValue() * @see getValueAsString() * */ function htmlValue($fieldname, $index = 0, $where = 0, $sort = 0, $params = array()) { $recid = $this->getId(); $uri = $recid . '#' . $fieldname; $domid = $uri . '-' . rand(); $delegate =& $this->_table->getDelegate(); if (isset($delegate) && method_exists($delegate, $fieldname . '__htmlValue')) { $methodname = $fieldname . '__htmlValue'; $res = $delegate->{$methodname}($this); //$res = call_user_func(array(&$delegate, $fieldname.'__htmlValue'), $this); if (is_string($res) and DATAFACE_USAGE_MODE == 'edit' and $this->checkPermission('edit', array('field' => $fieldname)) and !$this->_table->isMetaField($fieldname)) { $res = '<span id="' . df_escape($domid) . '" df:id="' . df_escape($uri) . '" class="df__editable">' . $res . '</span>'; } return $res; } $event = new StdClass(); $event->record = $this; $event->fieldname = $fieldname; $event->index = $index; $event->where = $where; $event->sort = $sort; $event->params = $params; $event->out = null; Dataface_Application::getInstance()->fireEvent('Dataface_Record__htmlValue', $event); if (isset($event->out)) { return $event->out; } $parent =& $this->getParentRecord(); if (isset($parent) and $parent->_table->hasField($fieldname)) { return $parent->htmlValue($fieldname, $index, $where, $sort, $params); } $val = $this->display($fieldname, $index, $where, $sort); $strval = $this->strval($fieldname, $index, $where, $sort); $field = $this->_table->getField($fieldname); if (!@$field['passthru'] and $this->escapeOutput) { $val = nl2br(df_escape($val)); } if ($this->secureDisplay and !Dataface_PermissionsTool::view($this, array('field' => $fieldname))) { $del =& $this->_table->getDelegate(); if ($del and method_exists($del, 'no_access_link')) { $link = $del->no_access_link($this, array('field' => $fieldname)); return '<a href="' . df_escape($link) . '">' . $val . '</a>'; } } //if ( $field['widget']['type'] != 'htmlarea' ) $val = htmlentities($val,ENT_COMPAT, 'UTF-8'); //if ( $this->_table->isText($fieldname) and $field['widget']['type'] != 'htmlarea' and $field['contenttype'] != 'text/html' ) $val = nl2br($val); if ($this->_table->isBlob($fieldname) or $this->_table->isContainer($fieldname)) { if ($this->getLength($fieldname, $index, $where, $sort) > 0) { if ($this->isImage($fieldname, $index, $where, $sort)) { $val = '<img src="' . $val . '"'; if (!isset($parmas['alt'])) { $params['alt'] = $strval; } if (!isset($params['width']) and isset($field['width'])) { $params['width'] = $field['width']; } foreach ($params as $pkey => $pval) { $val .= ' ' . df_escape($pkey) . '="' . df_escape($pval) . '"'; } $val .= '/>'; } else { $file_icon = df_translate($this->getMimetype($fieldname, $index, $where, $sort) . ' file icon', df_absolute_url(DATAFACE_URL) . '/images/document_icon.gif'); $val = '<img src="' . df_escape($file_icon) . '"/><a href="' . $val . '" target="_blank"'; foreach ($params as $pkey => $pval) { $val .= ' ' . df_escape($pkey) . '="' . df_escape($pval) . '"'; } $val .= '>' . df_escape($strval) . ' (' . df_escape($this->getMimetype($fieldname, $index, $where, $sort)) . ')</a>'; } } else { $val = "(Empty)"; } } if (is_string($val) and DATAFACE_USAGE_MODE == 'edit' and $this->checkPermission('edit', array('field' => $fieldname)) and !$this->_table->isMetaField($fieldname)) { $val = '<span id="' . df_escape($domid) . '" df:id="' . df_escape($uri) . '" class="df__editable">' . $val . '</span>'; } return $val; }
/** * * Constructor for the relationship. * * @param $tablename The name of the source table. * @wparam $relationshipName The name of the relationship * @param An array of initializing values. Usually produced by parsing the relationships.ini * file. * */ function Dataface_Relationship($tablename, $relationshipName, &$values) { $this->app =& Dataface_Application::getInstance(); $this->_name = $relationshipName; $this->_sourceTable =& Dataface_Table::loadTable($tablename); $this->_schema = array(); $res = $this->_init($values); if (PEAR::isError($res)) { throw new Exception($res->getMessage()); } if (!isset($this->_schema['permissions'])) { $app =& Dataface_Application::getInstance(); $this->_schema['permissions'] = Dataface_PermissionsTool::getRolePermissions($app->_conf['default_relationship_role']); } $this->_permissions =& $this->_schema['permissions']; }
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); }
function handle(&$params) { if (!isset($_POST['-redirect']) and !isset($_POST['relatedList-body'])) { return PEAR::raiseError('Cannot reorder related records because no redirect url was specified in the POST parameters.' . Dataface_Error::printStackTrace()); } $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); if (!($record = df_get_selected_records($query))) { $record =& $app->getRecord(); } else { $record = $record[0]; } if (PEAR::isError($record)) { return $record; } if (!$record) { return PEAR::raiseError('The specified record could not be found.'); } if (!@$query['-relationship']) { return PEAR::raiseError("No relationship specified."); } $relationship =& $record->_table->getRelationship($query['-relationship']); if (PEAR::isError($relationship)) { return $relationship; } $orderColumn = $relationship->getOrderColumn(); if (!$orderColumn) { return PEAR::raiseError('Could not reorder records of this relationship because it does not have any order column specified.'); } if (!Dataface_PermissionsTool::checkPermission('reorder_related_records', $record, array('relationship' => $query['-relationship']))) { return Dataface_Error::permissionDenied('You do not have permission to reorder the records in this relationship.'); } if (isset($_POST['relatedList-body'])) { $relatedIds = array_map('urldecode', $_POST['relatedList-body']); // In this case we are not just moving a record up or down the list, // we may be reordering the list altogether. // We may also just be ordering a subset of the list. // so we will want to be reordering the given set of records // with respect to each other. // First let's see if the ordering has been initialized yet. $records = array(); //print_r($relatedIds);exit; foreach ($relatedIds as $recid) { //$recid = urldecode($recid); $records[] = df_get_record_by_id($recid); } $start = isset($query['-related:start']) ? $query['-related:start'] : 0; $record->sortRelationship($query['-relationship'], $start, $records); echo 'Sorted Successfully'; exit; } if (!isset($_POST['-reorder:direction'])) { return PEAR::raiseError('Cannot reorder related records because no direction was specified.'); } if (!isset($_POST['-reorder:index'])) { return PEAR::raiseError('Cannot reorder related records because no index was specified.'); } $index = intval($_POST['-reorder:index']); switch ($_POST['-reorder:direction']) { case 'up': //echo "Moving up";exit; $res = $record->moveUp($query['-relationship'], $index); break; case 'down': $res = $record->moveDown($query['-relationship'], $index); break; default: return PEAR::raiseError('Invalid input for direction of reordering. Must be up or down but received "' . $_POST['-reorder:direction'] . '"'); } if (PEAR::isError($res)) { return $res; } header('Location: ' . $_POST['-redirect']); exit; }
/** * Builds the form. */ function _build() { if ($this->_built) { return true; } $r =& $this->_relationship->_schema; $t =& $this->_parentTable; $fkCols = $this->_relatedRecord->getForeignKeyValues(); if (PEAR::isError($fkCols)) { $fkCols->addUserInfo("Error getting foreign key columns while building Related Record Form"); error_log($fkCols->toString()); return $fkCols; } //echo "<h1>fkcols</h1>";print_r($fkCols); //$cols =& $r['columns']; $cols =& $this->_fieldNames; $dummyRecords = array(); // to hold records that will allow us to get permissions information form existing data. foreach ($cols as $col) { list($tablename, $fieldname) = explode('.', $col); if (!isset($dummyRecords[$tablename])) { $dummyRecords[$tablename] = new Dataface_Record($tablename, array()); } } foreach (array_keys($dummyRecords) as $dummyTable) { if (isset($fkCols[$dummyTable])) { $dummyRecords[$dummyTable]->setValues($fkCols[$dummyTable]); } } $quickForms = array(); // array for each quickform object.. one for each table in relationship. //$permissions = $t->getRelationshipPermissions($this->_relationshipName); $permissions = $this->_record->getPermissions(array('relationship' => $this->_relationshipName)); if (isset($permissions['add new related record']) and $permissions['add new related record']) { // We are allowed to add a new related record, so we will create a mask to allow this. $mask = array('edit' => 1, 'new' => 1, 'view' => 1); } else { $mask = array(); } $groupsStarted = array(); $fieldDefs = array(); foreach ($cols as $col) { $absFieldname = Dataface_Table::absoluteFieldName($col, $r['tables']); if (PEAR::isError($absFieldname)) { $absFieldname->addUserInfo("Error obtaining absolute field name for field '{$col}' while building Related Record Form "); return $absFieldname; } list($tablename, $fieldname) = explode('.', $absFieldname); $thisTable =& Dataface_Table::loadTable($tablename); //echo $absFieldname; if (array_key_exists($tablename, $fkCols) and array_key_exists($fieldname, $fkCols[$tablename])) { // This column is already specified by the foreign key relationship so we don't need to pass // this information using the form. // Actually - this isn't entirely true. If there is no auto-incrementing field // associated with this foreign key, then if ($this->_relationship->isNullForeignKey($fkCols[$tablename][$fieldname])) { $furthestField = $fkCols[$tablename][$fieldname]->getFurthestField(); if ($furthestField != $absFieldname) { // We only display this field if it is the furthest field of the key continue; } } else { continue; } } $field =& $this->_parentTable->getTableField($col); if (@$field['grafted'] && !@$field['transient']) { continue; } $fieldDefs[$absFieldname] =& $field; unset($field); unset($thisTable); } //foreach ($cols as $col){ $formTool =& Dataface_FormTool::getInstance(); $groups = $formTool->groupFields($fieldDefs); $firstGroup = true; // Let's see if we need to use tabs foreach ($groups as $sectionName => $fields) { unset($group); $firstField = reset($fields); if (!$firstField) { continue; } $thisTable =& Dataface_Table::loadTable($firstField['tablename']); $group =& $thisTable->getFieldgroup($sectionName); if (PEAR::isError($group)) { $group = array('label' => df_translate('scripts.Dataface_QuickForm.LABEL_EDIT_DETAILS', 'Edit Details'), 'order' => 1); } $groupEmpty = true; // A flag to check when the group has at least one element foreach ($fields as $field) { $tablename = $field['tablename']; $fieldname = $field['name']; $absFieldname = $tablename . '.' . $fieldname; unset($thisTable); $thisTable =& Dataface_Table::loadTable($tablename); if (isset($r[$thisTable->tablename]['readonly'])) { continue; } if (!isset($this->_quickForms[$tablename])) { $this->_quickForms[$tablename] = new Dataface_QuickForm($tablename, '', '', '', true); } if (isset($quickForm)) { unset($quickForm); } $quickForm =& $this->_quickForms[$tablename]; if (array_key_exists($tablename, $fkCols) and array_key_exists($fieldname, $fkCols[$tablename])) { // This column is already specified by the foreign key relationship so we don't need to pass // this information using the form. // Actually - this isn't entirely true. If there is no auto-incrementing field // associated with this foreign key, then if ($this->_relationship->isNullForeignKey($fkCols[$tablename][$fieldname])) { $furthestField = $fkCols[$tablename][$fieldname]->getFurthestField(); if ($furthestField != $absFieldname) { // We only display this field if it is the furthest field of the key continue; } } else { continue; } //continue; } //$field =& $this->_parentTable->getTableField($col); $widget =& $field['widget']; $perms = $dummyRecords[$tablename]->getPermissions(array('field' => $fieldname, 'recordmask' => $mask)); if (!Dataface_PermissionsTool::view($perms)) { continue; } $el = $quickForm->_buildWidget($field, $perms); if (PEAR::isError($el)) { error_log($el->toString() . "\n" . implode("\n", $el->getBacktrace())); throw new Exception("Failed to build widget for {$fieldname}. See error log for details.", E_USER_ERROR); } if ($groupEmpty and @$field['widget']['type'] !== 'hidden') { // This is the first field in the group, so we add a header for the // group. if (!$firstGroup) { $this->addElement('submit', '', df_translate('save_button_label', 'Save')); } $headerel =& $this->addElement('header', $group['label'], $group['label']); $headerel->setFieldDef($group); unset($headerel); $groupEmpty = false; $firstGroup = false; } $this->addElement($el); // set default value $defaultValue = $thisTable->getDefaultValue($fieldname); if (isset($defaultValue)) { $defaults = array($fieldname => $defaultValue); $this->setDefaults($defaults); } /* * * If there are any validation options set for the field, we must add these rules to the quickform * element. * */ $validators = $field['validators']; foreach ($validators as $vname => $validator) { /* * * $validator['arg'] would be specified in the INI file. * Example ini file listing: * ------------------------- * [FirstName] * widget:label = First name * widget:description = Enter your first name * validators:regex = "/[0-9a-zA-Z/" * * This would result in $validator['arg'] = "/[0-9a-zA-Z/" in this section * and $vname == "regex". Hence it would mean that a regular expression validator * is being placed on this field so that only Alphanumeric characters are accepted. * Please see documentation for HTML_QuickForm PEAR class for more information * about QuickForm validators. * */ $this->addRule($fieldname, $validator['message'], $vname, $validator['arg'], 'client'); } unset($field); unset($widget); unset($grp); unset($thisTable); unset($el); } } $factory = new HTML_QuickForm('factory'); $keyEls = array(); $keyDefaults = array(); foreach (array_keys($this->_parentTable->keys()) as $key) { $keyEls[] = $factory->addElement('hidden', $key); } $this->addGroup($keyEls, '__keys__'); $keyvals = array(); foreach (array_keys($this->_parentTable->keys()) as $key) { $keyvals[$key] = $this->_record->getValueAsString($key); } $this->setDefaults(array('__keys__' => $keyvals)); $this->addElement('hidden', '-table'); $this->addElement('hidden', '-relationship'); $this->addElement('hidden', '-action'); $this->addElement('submit', '-Save', df_translate('save_button_label', 'Save')); $this->setDefaults(array('-table' => $this->_parentTable->tablename, '-relationship' => $this->_relationshipName, '-action' => "new_related_record")); /* * There may be some default values specified in the relationship schema. */ if (isset($r['new'])) { $this->setDefaults($r['new']); } $this->_built = true; }
function build() { $formTool =& Dataface_FormTool::getInstance(); foreach ($this->getFieldDefs() as $uri => $fieldDef) { //$qf =& $this->getQuickForm($uri); $record =& $this->getRecord($uri); /* * * If the user does not have permission to view this field, we should not generate this widget. * */ if (!Dataface_PermissionsTool::view($record, array('field' => $fieldDef['name']))) { continue; } $el =& $formTool->buildWidget($record, $fieldDef, $this, $uri); if (PEAR::isError($el)) { trigger_error($el->getMessage(), E_USER_ERROR); } //$el->setName($uri); //$this->addElement($el); //$this->setDefaults(array( $uri => df_get($uri,'strval'))); unset($el); unset($record); unset($fieldDef); } $this->addElement('submit', 'submit', 'Save'); }
function loadPermissions() { $this->_permissionsLoaded = true; $configTool =& Dataface_ConfigTool::getInstance(); $conf =& $configTool->loadConfig('permissions', $this->tablename); $permissionsTool =& Dataface_PermissionsTool::getInstance(); $permissionsTool->addPermissions($conf); }
public function getPermissions(Dataface_Record $record = null) { return Dataface_PermissionsTool::NO_ACCESS(); }
/** * This method sits above "display" on the output stack for a field. * I.e. it wraps "display()" and adds some extra filtering to make the * output directly appropriate to be displayed as HTML. In text fields * this will convert newlines to breaks, and in blob fields, this will output * either the full a-href tag or img tag depending on the type of content that * is stored. * * @param $fieldname The name of the field to output * @param $params Associative array of html parameters that can optionally * be supplied. * Returns HTML string. */ function htmlValue($fieldname, $index = 0, $where = 0, $sort = 0, $params = array()) { $recid = $this->getId(); $uri = $recid . '#' . $fieldname; $domid = $uri . '-' . rand(); $delegate =& $this->_table->getDelegate(); if (isset($delegate) && method_exists($delegate, $fieldname . '__htmlValue')) { $methodname = $fieldname . '__htmlValue'; $res = $delegate->{$methodname}($this); //$res = call_user_func(array(&$delegate, $fieldname.'__htmlValue'), $this); if (is_string($res) and DATAFACE_USAGE_MODE == 'edit' and $this->checkPermission('edit', array('field' => $fieldname)) and !$this->_table->isMetaField($fieldname)) { $res = '<span id="' . $domid . '" df:id="' . $uri . '" class="df__editable">' . $res . '</span>'; } return $res; } $parent =& $this->getParentRecord(); if (isset($parent) and $parent->_table->hasField($fieldname)) { return $parent->htmlValue($fieldname, $index, $where, $sort, $params); } $val = $this->display($fieldname, $index, $where, $sort); if ($this->secureDisplay and !Dataface_PermissionsTool::view($this, array('field' => $fieldname))) { $del =& $this->_table->getDelegate(); if ($del and method_exists($del, 'no_access_link')) { $link = $del->no_access_link($this, array('field' => $fieldname)); return '<a href="' . htmlspecialchars($link) . '">' . $val . '</a>'; } } $field = $this->_table->getField($fieldname); //if ( $field['widget']['type'] != 'htmlarea' ) $val = htmlentities($val,ENT_COMPAT, 'UTF-8'); if ($this->_table->isText($fieldname) and $field['widget']['type'] != 'htmlarea') { $val = nl2br($val); } if ($this->_table->isBlob($fieldname) or $this->_table->isContainer($fieldname)) { if ($this->getLength($fieldname, $index, $where, $sort) > 0) { if ($this->isImage($fieldname, $index, $where, $sort)) { $val = '<img src="' . $val . '"'; if (!isset($params['width']) and isset($field['width'])) { $params['width'] = $field['width']; } foreach ($params as $pkey => $pval) { $val .= ' ' . $pkey . '="' . $pval . '"'; } $val .= '/>'; } else { $file_icon = df_translate($this->getMimetype($fieldname, $index, $where, $sort) . ' file icon', df_absolute_url(DATAFACE_URL) . '/images/document_icon.gif'); $val = '<img src="' . $file_icon . '"/><a href="' . $val . '" target="_blank"'; foreach ($params as $pkey => $pval) { $val .= ' ' . $pkey . '="' . $pval . '"'; } $val .= '>View Field Content In New Window (' . $this->getMimetype($fieldname, $index, $where, $sort) . ')</a>'; } } else { $val = "(Empty)"; } } if (is_string($val) and DATAFACE_USAGE_MODE == 'edit' and $this->checkPermission('edit', array('field' => $fieldname)) and !$this->_table->isMetaField($fieldname)) { $val = '<span id="' . $domid . '" df:id="' . $uri . '" class="df__editable">' . $val . '</span>'; } return $val; }
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; }
function display() { if ($this->_resultSet->found() > 0 || $this->_new) { $res = $this->_build(); if (PEAR::isError($res)) { return $res; } else { //$this->displayTabs(); if (!$this->_new and !Dataface_PermissionsTool::edit($this->_record)) { $this->freeze(); } if ($this->_new and !Dataface_PermissionsTool::checkPermission('new', $this->_table)) { $this->freeze(); } $formTool =& Dataface_FormTool::getInstance(); if ($this->_new || Dataface_PermissionsTool::view($this->_record)) { //echo $this->_renderer->toHtml(); echo $formTool->display($this); } else { echo "<p>" . df_translate('scripts.GLOBAL.INSUFFICIENT_PERMISSIONS_TO_VIEW_RECORD', 'Sorry you have insufficient permissions to view this record.') . "</p>"; } //parent::display(); } } else { echo "<p>" . df_translate('scripts.GLOBAL.NO_RECORDS_MATCHED_REQUEST', 'No records matched your request.') . "</p>"; } }
function df_permission_names_as_string(&$perms) { $ptool = Dataface_PermissionsTool::getInstance(); return $ptool->namesAsString($perms); }
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; }