/** * Returns HTML form element for editing of setting * * Options: * * 'name' => sets the name of the HTML form element explicitly, otherwise 'setting_<name_of_setting>' is used * 'id' => sets the id of the HTML form element explicitly, otherwise 'setting_<name_of_setting>' is used * 'value' => sets the value of the HTML form element explicitly, otherwise the current value for the setting in the loaded row is used * 'label_id' => sets the id of the label for the setting form element (used to link tools tips to the label); if not set then the default is to set it to 'setting_<name_of_setting>_label' */ public function settingHTMLFormElement($ps_setting, $pa_options = null) { if (!$this->isValidSetting($ps_setting)) { return false; } $va_available_settings = $this->getAvailableSettings(); $va_properties = $va_available_settings[$ps_setting]; if (isset($pa_options['name'])) { $vs_input_name = $pa_options['name']; } else { $vs_input_name = "setting_{$ps_setting}"; } if (isset($pa_options['id'])) { $vs_input_id = $pa_options['id']; } else { $vs_input_id = "setting_{$ps_setting}"; } if (isset($pa_options['value'])) { $vs_value = $pa_options['value']; } else { $vs_value = $this->getSetting(trim($ps_setting)); } if (isset($pa_options['label_id'])) { $vs_label_id = $pa_options['label_id']; } else { $vs_label_id = "setting_{$ps_setting}_label"; } $vs_return = "\n" . '<div class="formLabel" id="' . $vs_input_id . '_container">' . "\n"; $vs_return .= '<span id="' . $vs_label_id . '" class="' . $vs_label_id . '">' . $va_properties['label'] . '</span>'; if ($vs_help_text = $pa_options['helpText']) { $vs_return .= "<a href='#' onclick='jQuery(\"#" . str_replace(".", "_", $vs_label_id) . "_help_text\").slideToggle(250); return false;' class='settingsKeyButton'>" . _t('Key') . "</a>"; } $vs_return .= '<br />' . "\n"; if ($vs_help_text) { $vs_return .= "\n<div id='" . str_replace(".", "_", $vs_label_id) . "_help_text' class='settingsKey'>{$vs_help_text}</div>\n"; } switch ($va_properties['displayType']) { # -------------------------------------------- case DT_FIELD: $vb_takes_locale = false; if (isset($va_properties['takesLocale']) && $va_properties['takesLocale']) { $vb_takes_locale = true; $va_locales = ca_locales::getLocaleList(array('sort_field' => '', 'sort_order' => 'asc', 'index_by_code' => true, 'available_for_cataloguing_only' => true)); } else { $va_locales = array('_generic' => array()); } foreach ($va_locales as $vs_locale => $va_locale_info) { if ($vb_takes_locale && sizeof($va_locales) > 1) { $vs_locale_label = " (" . $va_locale_info['name'] . ")"; $vs_input_name_suffix = '_' . $vs_locale; } else { if ($vb_takes_locale) { $vs_input_name_suffix = '_' . $vs_locale; } else { $vs_input_name_suffix = $vs_locale_label = ''; } } if ($vs_locale != '_generic' && is_array($vs_value)) { // _generic means this setting doesn't take a locale if (!($vs_text_value = $vs_value[$va_locale_info['locale_id']])) { $vs_text_value = is_array($vs_value) && isset($vs_value[$va_locale_info['code']]) ? $vs_value[$va_locale_info['code']] : ''; } } else { $vs_text_value = $vs_value; } $vs_return .= caHTMLTextInput($vs_input_name . $vs_input_name_suffix, array('size' => $va_properties["width"], 'height' => $va_properties["height"], 'value' => $vs_text_value, 'id' => $vs_input_id)) . "{$vs_locale_label}<br/>\n"; } break; # -------------------------------------------- # -------------------------------------------- case DT_CHECKBOXES: $va_attributes = array('value' => '1', 'id' => $vs_input_id); if ((int) $vs_value === 1) { $va_attributes['checked'] = '1'; } if (isset($va_properties['hideOnSelect'])) { if (!is_array($va_properties['hideOnSelect'])) { $va_properties['hideOnSelect'] = array($va_properties['hideOnSelect']); } $va_ids = array(); foreach ($va_properties['hideOnSelect'] as $vs_n) { $va_ids[] = "#" . $pa_options['id_prefix'] . "_{$vs_n}_container"; } $va_attributes['onchange'] = 'jQuery(this).prop("checked") ? jQuery("' . join(",", $va_ids) . '").slideUp(250).find("input, textarea").val("") : jQuery("' . join(",", $va_ids) . '").slideDown(250);'; } $vs_return .= caHTMLCheckboxInput($vs_input_name, $va_attributes, array()); break; # -------------------------------------------- # -------------------------------------------- case DT_COLORPICKER: $va_attributes = array('value' => $vs_value, 'id' => $vs_input_id); $vs_return .= caHTMLHiddenInput($vs_input_name, $va_attributes, array()); $vs_return .= "<div id='{$vs_input_id}_colorchip' class='colorpicker_chip' style='background-color: #{$vs_value}'><!-- empty --></div>"; $vs_return .= "<script type='text/javascript'>jQuery(document).ready(function() { jQuery('#{$vs_input_name}_colorchip').ColorPicker({\n\t\t\t\t\t\t\t\tonShow: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeIn(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonHide: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeOut(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonChange: function (hsb, hex, rgb) {\n\t\t\t\t\t\t\t\t\tjQuery('#{$vs_input_name}').val(hex);\n\t\t\t\t\t\t\t\t\tjQuery('#{$vs_input_name}_colorchip').css('backgroundColor', '#' + hex);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcolor: jQuery('#" . $pa_options["name"] . "').val()\n\t\t\t\t\t\t\t})}); </script>\n"; JavascriptLoadManager::register('jquery', 'colorpicker'); break; # -------------------------------------------- # -------------------------------------------- case DT_SELECT: include_once __CA_MODELS_DIR__ . '/ca_relationship_types.php'; $vn_width = isset($va_properties['width']) && strlen($va_properties['width']) > 0 ? $va_properties['width'] : "100px"; $vn_height = isset($va_properties['height']) && strlen($va_properties['height']) > 0 ? $va_properties['height'] : "50px"; $vs_select_element = ''; if (($vs_rel_table = $va_properties['useRelationshipTypeList']) || ($vb_locale_list = (bool) $va_properties['useLocaleList']) || ($vs_list_code = $va_properties['useList']) || ($vb_show_lists = (bool) $va_properties['showLists'] || (bool) $va_properties['showVocabularies'])) { if ($vs_rel_table) { $t_rel = new ca_relationship_types(); $va_rels = $t_rel->getRelationshipInfo($vs_rel_table); $va_rel_opts = array(); if (isset($va_properties['allowNull']) && $va_properties['allowNull']) { $va_rel_opts['-'] = null; } foreach ($va_rels as $vn_type_id => $va_rel_type_info) { if (!$va_rel_type_info['parent_id']) { continue; } $va_rel_opts[$va_rel_type_info['typename'] . '/' . $va_rel_type_info['typename_reverse']] = $va_rel_type_info['type_id']; } } else { if ($vb_locale_list) { include_once __CA_MODELS_DIR__ . '/ca_locales.php'; $va_rel_opts = array_flip(ca_locales::getLocaleList(array('return_display_values' => true))); } else { if ($vb_show_lists) { include_once __CA_MODELS_DIR__ . '/ca_lists.php'; $t_list = new ca_lists(); $va_lists = caExtractValuesByUserLocale($t_list->getListOfLists()); $va_rel_opts = array(); foreach ($va_lists as $vn_list_id => $va_list_info) { if ($va_properties['showVocabularies'] && !$va_list_info['use_as_vocabulary']) { continue; } $va_rel_opts[$va_list_info['name'] . ' (' . $va_list_info['list_code'] . ')'] = $vn_list_id; } } } } $va_attr = array(); if ($vn_height > 1) { $va_attr['multiple'] = 1; $vs_input_name .= '[]'; } $va_opts = array('id' => $vs_input_id, 'width' => $vn_width, 'height' => $vn_height); if ($vn_height > 1) { if ($vs_value && !is_array($vs_value)) { $vs_value = array($vs_value); } $va_opts['values'] = $vs_value; } else { if (is_array($vs_value)) { $va_opts['value'] = array_pop($vs_value); } else { if ($vs_value) { $va_opts['value'] = $vs_value; } else { $va_opts['value'] = null; } } } if ($vs_list_code) { $t_list = new ca_lists(); if (!isset($va_opts['value'])) { $va_opts['value'] = -1; } // make sure default list item is never selected $vs_select_element = $t_list->getListAsHTMLFormElement($vs_list_code, $vs_input_name, $va_attr, $va_opts); } else { if (!isset($va_opts['value'])) { $va_opts['value'] = -1; } // make sure default list item is never selected $vs_select_element = caHTMLSelect($vs_input_name, $va_rel_opts, $va_attr, $va_opts); } } else { if (strlen($va_properties['showSortableBundlesFor']) > 0) { require_once __CA_MODELS_DIR__ . '/ca_metadata_elements.php'; $o_dm = Datamodel::load(); if (!($t_rel = $o_dm->getInstanceByTableName($va_properties['showSortableBundlesFor'], true))) { break; } $va_elements = ca_metadata_elements::getSortableElements($va_properties['showSortableBundlesFor']); $va_select_opts = array(_t('User defined sort order') => '', _t('Order created') => 'relation_id', _t('Preferred label') => $va_properties['showSortableBundlesFor'] . ".preferred_labels." . $t_rel->getLabelDisplayField()); foreach ($va_elements as $vn_element_id => $va_element) { if (!$va_element['display_label']) { continue; } $va_select_opts[_t('Element: %1', $va_element['display_label'])] = $va_properties['showSortableBundlesFor'] . "." . $va_element['element_code']; } $va_opts = array('id' => $vs_input_id, 'width' => $vn_width, 'height' => $vn_height, 'value' => is_array($vs_value) ? $vs_value[0] : $vs_value, 'values' => is_array($vs_value) ? $vs_value : array($vs_value)); $vs_select_element = caHTMLSelect($vs_input_name, $va_select_opts, array(), $va_opts); } elseif ((int) $va_properties['showSortableElementsFor'] > 0) { require_once __CA_MODELS_DIR__ . '/ca_metadata_elements.php'; $t_element = new ca_metadata_elements($va_properties['showSortableElementsFor']); if (!$t_element->getPrimaryKey()) { return ''; } $va_elements = $t_element->getElementsInSet(); $va_select_opts = array(_t('Order created') => ''); foreach ($va_elements as $vn_i => $va_element) { if ((int) $va_element['element_id'] == (int) $va_properties['showSortableElementsFor']) { continue; } if (!$va_element['display_label']) { continue; } $va_select_opts[_t('Element: %1', $va_element['display_label'])] = $va_element['element_code']; } $va_opts = array('id' => $vs_input_id, 'width' => $vn_width, 'height' => $vn_height, 'value' => is_array($vs_value) ? $vs_value[0] : $vs_value, 'values' => is_array($vs_value) ? $vs_value : array($vs_value)); $vs_select_element = caHTMLSelect($vs_input_name, $va_select_opts, array(), $va_opts); } elseif ((int) $va_properties['showMetadataElementsWithDataType'] > 0) { require_once __CA_MODELS_DIR__ . '/ca_metadata_elements.php'; $va_rep_elements = ca_metadata_elements::getElementsAsList(true, $va_properties['table'], null, true, false, true, array($va_properties['showMetadataElementsWithDataType'])); if (is_array($va_rep_elements)) { $va_select_opts = array(); foreach ($va_rep_elements as $vs_element_code => $va_element_info) { $va_select_opts[$va_element_info['display_label']] = $vs_element_code; } $va_opts = array('id' => $vs_input_id, 'width' => $vn_width, 'height' => $vn_height, 'value' => is_array($vs_value) ? $vs_value[0] : $vs_value, 'values' => is_array($vs_value) ? $vs_value : array($vs_value)); $vs_select_element = caHTMLSelect($vs_input_name, $va_select_opts, array(), $va_opts); } } else { // Regular drop-down with configured options if ($vn_height > 1) { $va_attr['multiple'] = 1; $vs_input_name .= '[]'; } $va_opts = array('id' => $vs_input_id, 'width' => $vn_width, 'height' => $vn_height, 'value' => is_array($vs_value) ? $vs_value[0] : $vs_value, 'values' => is_array($vs_value) ? $vs_value : array($vs_value)); if (!isset($va_opts['value'])) { $va_opts['value'] = -1; } // make sure default list item is never selected $vs_select_element = caHTMLSelect($vs_input_name, $va_properties['options'], array(), $va_opts); } } if ($vs_select_element) { $vs_return .= $vs_select_element; } else { return ''; } break; # -------------------------------------------- # -------------------------------------------- default: break; # -------------------------------------------- } $vs_return .= '</div>' . "\n"; TooltipManager::add('.' . $vs_label_id, "<h3>" . $va_properties["label"] . "</h3>" . $va_properties["description"]); return $vs_return; }
/** * Return array containing information about all lists, including their root_id's */ public function getHierarchyList($pb_vocabularies = false) { $t_list = new ca_lists(); $va_hierarchies = caExtractValuesByUserLocale($t_list->getListOfLists()); $vs_template = $this->getAppConfig()->get('ca_list_items_hierarchy_browser_display_settings'); $o_db = $this->getDb(); $va_hierarchy_ids = array(); foreach ($va_hierarchies as $vn_list_id => $va_list_info) { $va_hierarchy_ids[] = intval($vn_list_id); } if (!sizeof($va_hierarchy_ids)) { return array(); } // get root for each hierarchy $qr_res = $o_db->query("\n\t\t\tSELECT cli.item_id, cli.list_id, count(*) children\n\t\t\tFROM ca_list_items cli\n\t\t\tLEFT JOIN ca_list_items AS cli2 ON cli.item_id = cli2.parent_id\n\t\t\tINNER JOIN ca_lists AS l ON l.list_id = cli.list_id\n\t\t\tWHERE \n\t\t\t\tcli.parent_id IS NULL and cli.list_id IN (" . join(',', $va_hierarchy_ids) . ") " . ($pb_vocabularies ? " AND (l.use_as_vocabulary = 1)" : "") . "\n\t\t\tGROUP BY\n\t\t\t\tcli.item_id\n\t\t"); $vs_template = $this->getAppConfig()->get('ca_list_hierarchy_browser_display_settings'); while ($qr_res->nextRow()) { $vn_hierarchy_id = $qr_res->get('list_id'); $va_hierarchies[$vn_hierarchy_id]['list_id'] = $qr_res->get('list_id'); // when we need to edit the list $va_hierarchies[$vn_hierarchy_id]['item_id'] = $qr_res->get('item_id'); $qr_children = $o_db->query("\n\t\t\t\tSELECT count(*) children\n\t\t\t\tFROM ca_list_items cli\n\t\t\t\tWHERE \n\t\t\t\t\tcli.parent_id = ?\n\t\t\t", (int) $qr_res->get('item_id')); $vn_children_count = 0; if ($qr_children->nextRow()) { $vn_children_count = $qr_children->get('children'); } $va_hierarchies[$vn_hierarchy_id]['name'] = caProcessTemplateForIDs($vs_template, 'ca_lists', array($vn_hierarchy_id), array('requireLinkTags' => true)); $va_hierarchies[$vn_hierarchy_id]['children'] = intval($vn_children_count); $va_hierarchies[$vn_hierarchy_id]['has_children'] = $vn_children_count > 0 ? 1 : 0; } // sort by label $va_hierarchies_indexed_by_label = array(); foreach ($va_hierarchies as $vs_k => $va_v) { $va_hierarchies_indexed_by_label[$va_v['name']][$vs_k] = $va_v; } ksort($va_hierarchies_indexed_by_label); $va_sorted_hierarchies = array(); foreach ($va_hierarchies_indexed_by_label as $vs_l => $va_v) { foreach ($va_v as $vs_k => $va_hier) { $va_sorted_hierarchies[$vs_k] = $va_hier; } } return $va_sorted_hierarchies; }
/** * */ public function htmlFormElement($ps_field, $ps_format = null, $pa_options = null) { if ($ps_field == 'list_id') { // Custom list drop-down $vs_format = $this->_CONFIG->get('form_element_display_format'); $t_list = new ca_lists(); $va_lists = caExtractValuesByUserLocale($t_list->getListOfLists()); $va_opts = array(); foreach ($va_lists as $vn_list_id => $va_list_info) { $va_opts[$va_list_info['name'] . ' (' . $va_list_info['list_code'] . ')'] = $vn_list_id; } ksort($va_opts); $vs_format = str_replace('^LABEL', $vs_field_label = $this->getFieldInfo('list_id', 'LABEL'), $vs_format); $vs_format = str_replace('^EXTRA', '', $vs_format); $vs_format = str_replace('^ELEMENT', caHTMLSelect($ps_field, $va_opts, array('id' => $ps_field), array('value' => $this->get('list_id'))), $vs_format); if (!isset($pa_options['no_tooltips']) || !$pa_options['no_tooltips']) { TooltipManager::add('#list_id', "<h3>{$vs_field_label}</h3>" . $this->getFieldInfo('list_id', 'DESCRIPTION'), $pa_options['tooltip_namespace']); } return $vs_format; } return parent::htmlFormElement($ps_field, $ps_format, $pa_options); }