/**
  *
  */
 public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     parent::__construct($po_request, $po_response, $pa_view_paths);
     // merge displays with drop-in print templates
     $va_export_options = caGetAvailablePrintTemplates('results', array('table' => $this->ops_tablename));
     $this->view->setVar('export_formats', $va_export_options);
     //$this->view->setVar('current_export_format', $this->opo_result_context->getParameter('last_export_type'));
     $va_options = array();
     foreach ($va_export_options as $vn_i => $va_format_info) {
         $va_options[$va_format_info['name']] = $va_format_info['code'];
     }
     // Get current display list
     $t_display = new ca_bundle_displays();
     foreach (caExtractValuesByUserLocale($t_display->getBundleDisplays(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'checkAccess' => caGetUserAccessValues($this->request)))) as $va_display) {
         $va_options[$va_display['name']] = "_display_" . $va_display['display_id'];
     }
     ksort($va_options);
     $this->view->setVar('export_format_select', caHTMLSelect('export_format', $va_options, array('class' => 'searchToolsSelect'), array('value' => $this->view->getVar('current_export_format'), 'width' => '150px')));
 }
 /** 
  * Set up basic "find" action
  */
 public function Index($pa_options = null)
 {
     $po_search = isset($pa_options['search']) ? $pa_options['search'] : null;
     $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
     $vn_display_id = $this->opo_result_context->getCurrentBundleDisplay();
     // Make sure user has access to at least one type
     if (method_exists($t_model, 'getTypeFieldName') && $t_model->getTypeFieldName() && (!is_null($va_types = caGetTypeListForUser($this->ops_tablename, array('access' => __CA_BUNDLE_ACCESS_READONLY__))) && (is_array($va_types) && !sizeof($va_types)))) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2320?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     $va_display_list = array();
     $t_display = $this->opo_datamodel->getInstanceByTableName('ca_bundle_displays', true);
     $t_display->load($vn_display_id);
     $vs_view = $this->opo_result_context->getCurrentView();
     if ($vn_display_id && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
         $va_placements = $t_display->getPlacements(array('settingsOnly' => true));
         foreach ($va_placements as $vn_placement_id => $va_display_item) {
             $va_settings = caUnserializeForDatabase($va_display_item['settings']);
             // get column header text
             $vs_header = $va_display_item['display'];
             if (isset($va_settings['label']) && is_array($va_settings['label'])) {
                 $va_tmp = caExtractValuesByUserLocale(array($va_settings['label']));
                 if ($vs_tmp = array_shift($va_tmp)) {
                     $vs_header = $vs_tmp;
                 }
             }
             $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings);
             if ($vs_view == 'editable') {
                 $va_display_list[$vn_placement_id] = array_merge($va_display_list[$vn_placement_id], array('allowInlineEditing' => $va_display_item['allowInlineEditing'], 'inlineEditingType' => $va_display_item['inlineEditingType'], 'inlineEditingListValues' => $va_display_item['inlineEditingListValues']));
                 AssetLoadManager::register('panel');
             }
         }
     }
     //
     // Default display list (if none are specifically defined)
     //
     if (!sizeof($va_display_list)) {
         if ($vs_idno_fld = $t_model->getProperty('ID_NUMBERING_ID_FIELD')) {
             $va_display_list[$this->ops_tablename . '.' . $vs_idno_fld] = array('placement_id' => $this->ops_tablename . '.' . $vs_idno_fld, 'bundle_name' => $this->ops_tablename . '.' . $vs_idno_fld, 'display' => $t_model->getDisplayLabel($this->ops_tablename . '.' . $vs_idno_fld), 'settings' => array(), 'allowInlineEditing' => true, 'inlineEditingType' => DT_FIELD, 'inlineEditingListValues' => array());
         }
         if (method_exists($t_model, 'getLabelTableInstance') && !($this->ops_tablename === 'ca_objects' && $this->request->config->get('ca_objects_dont_use_labels'))) {
             $t_label = $t_model->getLabelTableInstance();
             $va_display_list[$this->ops_tablename . '.preferred_labels'] = array('placement_id' => $this->ops_tablename . '.preferred_labels', 'bundle_name' => $this->ops_tablename . '.preferred_labels', 'display' => $t_label->getDisplayLabel($t_label->tableName() . '.' . $t_label->getDisplayField()), 'settings' => array(), 'allowInlineEditing' => true, 'inlineEditingType' => DT_FIELD, 'inlineEditingListValues' => array());
         }
         if ($vs_view == 'editable') {
             AssetLoadManager::register('panel');
         }
     }
     $this->view->setVar('current_display_list', $vn_display_id);
     $this->view->setVar('t_display', $t_display);
     if ($vs_view == 'editable') {
         $this->view->setVar('columns', $this->getInlineEditColumns($va_display_list, array('request' => $this->request)));
         $this->view->setVar('columnHeaders', caExtractValuesFromArrayList($va_display_list, 'display', array('preserveKeys' => false)));
         $this->view->setVar('rowHeaders', array());
     }
     // figure out which items in the display are sortable
     if (method_exists($t_model, 'getApplicableElementCodes')) {
         $va_sortable_elements = ca_metadata_elements::getSortableElements($t_model->tableName());
         $va_attribute_list = array_flip($t_model->getApplicableElementCodes($this->opo_result_context->getTypeRestriction($vb_dummy), false, false));
         $t_label = $t_model->getLabelTableInstance();
         $vs_label_table_name = $t_label->tableName();
         $vs_label_display_field = $t_label->getDisplayField();
         foreach ($va_display_list as $vn_i => $va_display_item) {
             $va_tmp = explode('.', $va_display_item['bundle_name']);
             if ($va_tmp[0] === $vs_label_table_name && $va_tmp[1] === $vs_label_display_field || $va_tmp[0] == $this->ops_tablename && $va_tmp[1] === 'preferred_labels') {
                 $va_display_list[$vn_i]['is_sortable'] = true;
                 $va_display_list[$vn_i]['bundle_sort'] = $vs_label_table_name . '.' . $vs_label_display_field;
                 continue;
             }
             if ($va_tmp[0] != $this->ops_tablename) {
                 continue;
             }
             if ($t_model->hasField($va_tmp[1])) {
                 $va_display_list[$vn_i]['is_sortable'] = true;
                 if ($t_model->hasField($va_tmp[1] . '_sort')) {
                     $va_display_list[$vn_i]['bundle_sort'] = $va_display_item['bundle_name'] . '_sort';
                 } else {
                     $va_display_list[$vn_i]['bundle_sort'] = $va_display_item['bundle_name'];
                 }
                 continue;
             }
             if (isset($va_attribute_list[$va_tmp[1]]) && $va_sortable_elements[$va_attribute_list[$va_tmp[1]]]) {
                 $va_display_list[$vn_i]['is_sortable'] = true;
                 $va_display_list[$vn_i]['bundle_sort'] = $va_display_item['bundle_name'];
                 continue;
             }
         }
     }
     $this->view->setVar('display_list', $va_display_list);
     // Get current display list
     $va_displays = array('0' => _t('Default'));
     foreach (caExtractValuesByUserLocale($t_display->getBundleDisplays(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__))) as $va_display) {
         $va_displays[$va_display['display_id']] = $va_display['name'];
     }
     $this->view->setVar('display_lists', $va_displays);
     # --- print forms used for printing search results as labels - in tools show hide under page bar
     if ((bool) $this->request->config->get('use_legacy_print_labels_generator')) {
         $this->view->setVar('label_formats', $this->getLegacyPrintForms());
     } else {
         $this->view->setVar('label_formats', caGetAvailablePrintTemplates('labels', array('table' => $this->ops_tablename, 'type' => 'label')));
     }
     # --- export options used to export search results - in tools show hide under page bar
     $vn_table_num = $this->opo_datamodel->getTableNum($this->ops_tablename);
     //default export formats, not configureable
     $va_export_options = array(array('name' => _t('Tab delimited'), 'code' => '_tab'), array('name' => _t('Comma delimited (CSV)'), 'code' => '_csv'), array('name' => _t('Spreadsheet with media icons (XLSX)'), 'code' => '_xlsx'));
     // merge default formats with drop-in print templates
     $va_export_options = array_merge($va_export_options, caGetAvailablePrintTemplates('results', array('table' => $this->ops_tablename)));
     $this->view->setVar('export_formats', $va_export_options);
     $this->view->setVar('current_export_format', $this->opo_result_context->getParameter('last_export_type'));
     //
     // Available sets
     //
     $t_set = new ca_sets();
     $this->view->setVar('available_sets', caExtractValuesByUserLocale($t_set->getSets(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_SET_EDIT_ACCESS__, 'omitCounts' => true))));
     if (strlen($this->ops_tablename) > 0) {
         if (!$this->request->user->canDoAction("can_edit_{$this->ops_tablename}")) {
             $this->view->setVar("default_action", "Summary");
         } else {
             $this->view->setVar("default_action", "Edit");
         }
     }
     $this->view->setVar('result_context', $this->opo_result_context);
     $this->view->setVar('access_restrictions', AccessRestrictions::load());
 }
 /**
  *
  */
 public function __call($ps_function, $pa_args)
 {
     AssetLoadManager::register("panel");
     AssetLoadManager::register("mediaViewer");
     AssetLoadManager::register("carousel");
     AssetLoadManager::register("readmore");
     AssetLoadManager::register("maps");
     $ps_function = strtolower($ps_function);
     $ps_id = urldecode($this->request->getActionExtra());
     if (!isset($this->opa_detail_types[$ps_function]) || !isset($this->opa_detail_types[$ps_function]['table']) || !($vs_table = $this->opa_detail_types[$ps_function]['table'])) {
         // invalid detail type – throw error
         die("Invalid detail type");
     }
     $t_table = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
     if (($vb_use_identifiers_in_urls = caUseIdentifiersInUrls()) && substr($ps_id, 0, 3) == "id:") {
         $va_tmp = explode(":", $ps_id);
         $ps_id = (int) $va_tmp[1];
         $vb_use_identifiers_in_urls = false;
     }
     if (!$t_table->load($vb_use_identifiers_in_urls && $t_table->getProperty('ID_NUMBERING_ID_FIELD') ? $t_table->hasField('deleted') ? array($t_table->getProperty('ID_NUMBERING_ID_FIELD') => $ps_id, 'deleted' => 0) : array($t_table->getProperty('ID_NUMBERING_ID_FIELD') => $ps_id) : ($t_table->hasField('deleted') ? array($t_table->primaryKey() => (int) $ps_id, 'deleted' => 0) : array($t_table->primaryKey() => (int) $ps_id)))) {
         // invalid id - throw error
         die("Invalid id");
     }
     // Printables
     // 	merge displays with drop-in print templates
     //
     $va_export_options = caGetAvailablePrintTemplates('summary', array('table' => $t_table->tableName()));
     $this->view->setVar('export_formats', $va_export_options);
     $va_options = array();
     foreach ($va_export_options as $vn_i => $va_format_info) {
         $va_options[$va_format_info['name']] = $va_format_info['code'];
     }
     // Get current display list
     $t_display = new ca_bundle_displays();
     foreach (caExtractValuesByUserLocale($t_display->getBundleDisplays(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'checkAccess' => caGetUserAccessValues($this->request)))) as $va_display) {
         $va_options[$va_display['name']] = "_display_" . $va_display['display_id'];
     }
     ksort($va_options);
     $this->view->setVar('export_format_select', caHTMLSelect('export_format', $va_options, array('class' => 'searchToolsSelect'), array('value' => $this->view->getVar('current_export_format'), 'width' => '150px')));
     #
     # Enforce access control
     #
     if (sizeof($this->opa_access_values) && $t_table->hasField('access') && !in_array($t_table->get("access"), $this->opa_access_values)) {
         $this->notification->addNotification(_t("This item is not available for view"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . $t_table->getTypeName() . ": " . $t_table->get('preferred_labels') . (($vs_idno = $t_table->get($t_table->getProperty('ID_NUMBERING_ID_FIELD'))) ? " [{$vs_idno}]" : ""));
     $vs_type = $t_table->getTypeCode();
     $this->view->setVar('detailType', $vs_table);
     $this->view->setVar('item', $t_table);
     $this->view->setVar('itemType', $vs_type);
     caAddPageCSSClasses(array($vs_table, $ps_function, $vs_type));
     // Do we need to pull in the multisearch result set?
     if (ResultContext::getLastFind($this->request, $vs_table, array('noSubtype' => true)) === 'multisearch') {
         $o_context = new ResultContext($this->request, $vs_table, 'multisearch', $ps_function);
         $o_context->setAsLastFind();
         $o_context->saveContext();
     } else {
         $o_context = ResultContext::getResultContextForLastFind($this->request, $vs_table);
     }
     $this->view->setVar('previousID', $vn_previous_id = $o_context->getPreviousID($t_table->getPrimaryKey()));
     $this->view->setVar('nextID', $vn_next_id = $o_context->getNextID($t_table->getPrimaryKey()));
     $this->view->setVar('previousURL', caDetailUrl($this->request, $vs_table, $vn_previous_id));
     $this->view->setVar('nextURL', caDetailUrl($this->request, $vs_table, $vn_next_id));
     $this->view->setVar('resultsURL', ResultContext::getResultsUrlForLastFind($this->request, $vs_table));
     $va_options = isset($this->opa_detail_types[$ps_function]['options']) && is_array($this->opa_detail_types[$ps_function]['options']) ? $this->opa_detail_types[$ps_function]['options'] : array();
     $this->view->setVar('previousLink', $vn_previous_id > 0 ? caDetailLink($this->request, caGetOption('previousLink', $va_options, _t('Previous')), '', $vs_table, $vn_previous_id) : '');
     $this->view->setVar('nextLink', $vn_next_id > 0 ? caDetailLink($this->request, caGetOption('nextLink', $va_options, _t('Next')), '', $vs_table, $vn_next_id) : '');
     $this->view->setVar('resultsLink', ResultContext::getResultsLinkForLastFind($this->request, $vs_table, caGetOption('resultsLink', $va_options, _t('Back'))));
     $this->view->setVar('commentsEnabled', (bool) $va_options['enableComments']);
     //
     //
     //
     if (method_exists($t_table, 'getPrimaryRepresentationInstance')) {
         if ($pn_representation_id = $this->request->getParameter('representation_id', pInteger)) {
             $t_representation = $this->opo_datamodel->getInstanceByTableName("ca_object_representations", true);
             $t_representation->load($pn_representation_id);
         } else {
             $t_representation = $t_table->getPrimaryRepresentationInstance(array("checkAccess" => $this->opa_access_values));
         }
         if ($t_representation) {
             $this->view->setVar("t_representation", $t_representation);
             $this->view->setVar("representation_id", $t_representation->get("representation_id"));
         } else {
             $t_representation = $this->opo_datamodel->getInstanceByTableName("ca_object_representations", true);
         }
         $this->view->setVar("representationViewer", caObjectDetailMedia($this->request, $t_table->getPrimaryKey(), $t_representation, $t_table, array("primaryOnly" => caGetOption('representationViewerPrimaryOnly', $va_options, false), "dontShowPlaceholder" => caGetOption('representationViewerDontShowPlaceholder', $va_options, false))));
     }
     //
     // map
     //
     if (!is_array($va_map_attributes = caGetOption('map_attributes', $va_options, array())) || !sizeof($va_map_attributes)) {
         if ($vs_map_attribute = caGetOption('map_attribute', $va_options, false)) {
             $va_map_attributes = array($vs_map_attribute);
         }
     }
     $this->view->setVar("map", "");
     if (is_array($va_map_attributes) && sizeof($va_map_attributes)) {
         $o_map = new GeographicMap(($vn_width = caGetOption('map_width', $va_options, false)) ? $vn_width : 285, ($vn_height = caGetOption('map_height', $va_options, false)) ? $vn_height : 200, 'map');
         $vn_mapped_count = 0;
         foreach ($va_map_attributes as $vs_map_attribute) {
             if ($t_table->get($vs_map_attribute)) {
                 $o_map->mapFrom($t_table, $vs_map_attribute);
                 $vn_mapped_count++;
             }
         }
         if ($vn_mapped_count > 0) {
             $this->view->setVar("map", $o_map->render('HTML'));
         }
     }
     //
     // comments, tags, rank
     //
     $this->view->setVar('averageRank', $t_table->getAverageRating(true));
     $this->view->setVar('numRank', $t_table->getNumRatings(true));
     #
     # User-generated comments, tags and ratings
     #
     $va_user_comments = $t_table->getComments(null, true);
     $va_comments = array();
     if (is_array($va_user_comments)) {
         foreach ($va_user_comments as $va_user_comment) {
             if ($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]) {
                 # TODO: format date based on locale
                 $va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
                 # -- get name of commenter
                 if ($va_user_comment["user_id"]) {
                     $t_user = new ca_users($va_user_comment["user_id"]);
                     $va_user_comment["author"] = $t_user->getName();
                 } elseif ($va_user_comment["name"]) {
                     $va_user_comment["author"] = $va_user_comment["name"];
                 }
                 $va_comments[] = $va_user_comment;
             }
         }
     }
     $this->view->setVar('comments', $va_comments);
     $va_user_tags = $t_table->getTags(null, true);
     $va_tags = array();
     if (is_array($va_user_tags)) {
         foreach ($va_user_tags as $va_user_tag) {
             if (!in_array($va_user_tag["tag"], $va_tags)) {
                 $va_tags[] = $va_user_tag["tag"];
             }
         }
     }
     $this->view->setVar('tags_array', $va_tags);
     $this->view->setVar('tags', implode(", ", $va_tags));
     $this->view->setVar("itemComments", caDetailItemComments($this->request, $t_table->getPrimaryKey(), $t_table, $va_comments, $va_tags));
     //
     // share link
     //
     $this->view->setVar("shareLink", "<a href='#' onclick='caMediaPanel.showPanel(\"" . caNavUrl($this->request, '', 'Detail', 'ShareForm', array("tablename" => $t_table->tableName(), "item_id" => $t_table->getPrimaryKey())) . "\"); return false;'>Share</a>");
     // find view
     //		first look for type-specific view
     if (!$this->viewExists($vs_path = "Details/{$vs_table}_{$vs_type}_html.php")) {
         // If no type specific view use the default
         $vs_path = "Details/{$vs_table}_default_html.php";
     }
     switch ($ps_view = $this->request->getParameter('view', pString)) {
         case 'pdf':
             $this->_genExport($t_table, $this->request->getParameter("export_format", pString), 'Detail', 'Detail');
             break;
         default:
             //
             // Tag substitution
             //
             // Views can contain tags in the form {{{tagname}}}. Some tags, such as "itemType" and "detailType" are defined by
             // the detail controller. More usefully, you can pull data from the item being detailed by using a valid "get" expression
             // as a tag (Eg. {{{ca_objects.idno}}}. Even more usefully for some, you can also use a valid bundle display template
             // (see http://docs.collectiveaccess.org/wiki/Bundle_Display_Templates) as a tag. The template will be evaluated in the
             // context of the item being detailed.
             //
             $va_defined_vars = array_keys($this->view->getAllVars());
             // get list defined vars (we don't want to copy over them)
             $va_tag_list = $this->getTagListForView($vs_path);
             // get list of tags in view
             foreach ($va_tag_list as $vs_tag) {
                 if (in_array($vs_tag, $va_defined_vars)) {
                     continue;
                 }
                 if (strpos($vs_tag, "^") !== false || strpos($vs_tag, "<") !== false) {
                     $this->view->setVar($vs_tag, $t_table->getWithTemplate($vs_tag, array('checkAccess' => $this->opa_access_values)));
                 } elseif (strpos($vs_tag, ".") !== false) {
                     $this->view->setVar($vs_tag, $t_table->get($vs_tag, array('checkAccess' => $this->opa_access_values)));
                 } else {
                     $this->view->setVar($vs_tag, "?{$vs_tag}");
                 }
             }
             $this->render($vs_path);
             break;
     }
 }
Exemple #4
0
    }
    ?>
				<table class="attributeListItem" cellpadding="5" cellspacing="0">
					<tr>
<?php 
    foreach ($va_element_list as $vs_element) {
        // any <textarea> tags in the template needs to be renamed to 'textentry' for the template to work
        print '<td class="attributeListItem" valign="top">' . str_replace("textarea", "textentry", $vs_element) . '</td>';
    }
    ?>
					</tr>
				</table>
<?php 
}
if (caGetOption('canMakePDFForValue', $va_element_info[$t_element->getPrimaryKey()]['settings'], false)) {
    $va_template_list = caGetAvailablePrintTemplates('bundles', array('table' => $t_instance->tableName(), 'elementCode' => $t_element->get('element_code'), 'forHTMLSelect' => true));
    if (sizeof($va_template_list) > 0) {
        ?>
	<div class='editorBundleValuePrintControl' id='<?php 
        print $vs_id_prefix;
        ?>
_print_control_{n}'>
<?php 
        print sizeof($va_template_list) > 1 ? caHTMLSelect('template', $va_template_list, array('class' => 'dontTriggerUnsavedChangeWarning', 'id' => "{$vs_id_prefix}PrintTemplate{n}")) : caHTMLHiddenInput('template', array('value' => array_pop($va_template_list), 'id' => "{$vs_id_prefix}PrintTemplate{n}"));
        print "<a href='#' onclick='{$vs_id_prefix}Print({n}); return false;'>" . caNavIcon($this->request, __CA_NAV_BUTTON_PDF_SMALL__) . "</a>";
        ?>
	</div>
<?php 
    }
}
if (isset($va_elements['_locale_id'])) {