getBaseUrlPath().'/'.$po_request->getScriptName(); if ($ps_module_path) { $vs_url .= '/'.$ps_module_path; } if ($ps_controller) { $vs_url .= "/".$ps_controller; } if ($ps_action) { $vs_url .= "/".$ps_action; } if (is_array($pa_other_params) && sizeof($pa_other_params)) { $vn_i = 0; foreach($pa_other_params as $vs_name => $vs_value) { if (in_array($vs_name, array('module', 'controller', 'action'))) { continue; } //$vs_url .= ($vn_i == 0) ? '?' : '&'; $vs_url .= '/'.$vs_name."/".urlencode($vs_value); $vn_i++; } } return $vs_url; } # ------------------------------------------------------------------------------------------------ /** * */ function caNavLink($po_request, $ps_content, $ps_classname, $ps_module_path, $ps_controller, $ps_action, $pa_other_params=null, $pa_attributes=null) { if (!($vs_url = caNavUrl($po_request, $ps_module_path, $ps_controller, $ps_action, $pa_other_params))) { return "Error: no url for navigation"; } $vs_tag = " $vs_value) { $vs_tag .= " $vs_attribute='".htmlspecialchars($vs_value, ENT_QUOTES, 'UTF-8')."'"; } } $vs_tag .= '>'.$ps_content.''; return $vs_tag; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * icon_position = * use_class = * no_background = * dont_show_content = * graphicsPath = */ function caNavButton($po_request, $pn_type, $ps_content, $ps_module_path, $ps_controller, $ps_action, $pa_other_params=null, $pa_attributes=null, $pa_options=null) { if ($ps_module_path && $ps_controller && $ps_action) { if (!($vs_url = caNavUrl($po_request, $ps_module_path, $ps_controller, $ps_action, $pa_other_params))) { return "Error: no url for navigation"; } } else { $vs_url = ''; } $vs_graphics_path = (isset($pa_options['graphicsPath']) && $pa_options['graphicsPath']) ? $pa_options['graphicsPath'] : $po_request->getThemeUrlPath()."/graphics"; $ps_icon_pos = isset($pa_options['icon_position']) ? $pa_options['icon_position'] : __CA_NAV_BUTTON_ICON_POS_LEFT__; $ps_use_classname = isset($pa_options['use_class']) ? $pa_options['use_class'] : ''; $pb_no_background = (isset($pa_options['no_background']) && $pa_options['no_background']) ? true : false; $pb_dont_show_content = (isset($pa_options['dont_show_content']) && $pa_options['dont_show_content']) ? true : false; if ($ps_use_classname) { $vs_classname = $ps_use_classname; } else { $vs_classname = (!$pb_no_background) ? 'form-button' : ''; } if ($vs_url) { $vs_tag = " $vs_value) { $vs_tag .= " $vs_attribute='".htmlspecialchars($vs_value, ENT_QUOTES, 'UTF-8')."'"; } } $vs_tag .= ">"; } else { $vs_tag = ''; } if (!$pb_no_background) { $vs_tag .= ""; $vn_padding = ($ps_content) ? 10 : 0; $vs_img_tag_stuff = " class='form-button-left' style='padding-right: {$vn_padding}px;'"; } else { $vn_padding = 0; $vs_img_tag_stuff = ''; } if (preg_match("/^[A-Za-z\.\-0-9 ]+$/", $ps_content)) { $vs_alt = $vs_title = htmlspecialchars($ps_content, ENT_QUOTES, 'UTF-8'); } else { $vs_alt = $vs_title = ''; } if ($vs_img_name = _caNavTypeToImgName($pn_type)) { $vs_tag .= "".$vs_alt.""; if (!$pb_dont_show_content) { $vs_tag .= $ps_content; } } else { $vs_tag .= $ps_content; } if (!$pb_no_background) { $vs_tag .= ""; } if ($vs_url) { $vs_tag .= ''; } return $vs_tag; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * icon_position = * use_class = * dont_show_content = * graphicsPath = */ function caNavHeaderButton($po_request, $pn_type, $ps_content, $ps_module_path, $ps_controller, $ps_action, $pa_other_params=null, $pa_attributes=null, $pa_options=null) { if (!($vs_url = caNavUrl($po_request, $ps_module_path, $ps_controller, $ps_action, $pa_other_params))) { return "Error: no url for navigation"; } $ps_icon_pos = isset($pa_options['icon_position']) ? $pa_options['icon_position'] : __CA_NAV_BUTTON_ICON_POS_LEFT__; $ps_use_classname = isset($pa_options['use_class']) ? $pa_options['use_class'] : ''; $pb_dont_show_content = (isset($pa_options['dont_show_content']) && $pa_options['dont_show_content']) ? true : false; $vs_graphics_path = (isset($pa_options['graphicsPath']) && $pa_options['graphicsPath']) ? $pa_options['graphicsPath'] : $po_request->getThemeUrlPath()."/graphics"; if ($ps_use_classname) { $vs_classname = $ps_use_classname; } else { $vs_classname = 'form-header-button'; } $vs_tag = "
$vs_value) { $vs_tag .= " $vs_attribute='".htmlspecialchars($vs_value, ENT_QUOTES, 'UTF-8')."'"; } } $vs_tag .= ">"; $vn_padding = ($ps_content) ? 5 : 0; $vs_img_tag_stuff = " padding= '{$vn_padding}px'"; if ($vs_img_name = _caNavTypeToImgName($pn_type, 24)) { $vs_icon_tag = " "; $vs_content = (!$pb_dont_show_content) ? $ps_content : ''; switch($ps_icon_pos) { case __CA_NAV_BUTTON_ICON_POS_LEFT__: $vs_tag .= $vs_icon_tag.$vs_content; break; case __CA_NAV_BUTTON_ICON_POS_BOTTOM__: $vs_tag .= $vs_content.'
'.$vs_icon_tag; break; case __CA_NAV_BUTTON_ICON_POS_TOP__: default: $vs_tag .= $vs_icon_tag.'
'.$vs_content; break; } } else { $vs_tag .= $ps_content; } $vs_tag .= '
'; return $vs_tag; } # ------------------------------------------------------------------------------------------------ /** * Options: * disableUnsavedChangesWarning = if true, unsaved change warnings (when user tries to navigate away from the form before saving) are disabled * noTimestamp = if true no form timestamp (used to determine if other users have made changes while the form is being displayed) is included. Default is false. */ function caFormTag($po_request, $ps_action, $ps_id, $ps_module_and_controller_path=null, $ps_method='post', $ps_enctype='multipart/form-data', $ps_target='_top', $pa_options=null) { if ($ps_target) { $vs_target = "target='".$ps_target."'"; } else { $vs_target = ''; } if ($ps_module_and_controller_path) { $vs_action = $po_request->getBaseUrlPath().'/'.$po_request->getScriptName().'/'.$ps_module_and_controller_path.'/'.$ps_action; } else { $vs_action = $po_request->getControllerUrl().'/'.$ps_action; } $vs_buf = "
\n\n"; if (!isset($pa_options['noTimestamp']) || !$pa_options['noTimestamp']) { $vs_buf .= caHTMLHiddenInput('form_timestamp', array('value' => time())); } if (!isset($pa_options['disableUnsavedChangesWarning']) || !$pa_options['disableUnsavedChangesWarning']) { $vs_buf .= ""; } if (isset($pa_options['disableSubmit']) && $pa_options['disableSubmit']) { $vs_buf .= ""; } return $vs_buf; } # ------------------------------------------------------------------------------------------------ /** * */ function caFormSubmitLink($po_request, $ps_content, $ps_classname, $ps_form_id, $ps_id=null) { $vs_button = "".$ps_content.""; return $vs_button; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * icon_position = * use_class = * no_background = * dont_show_content = * graphicsPath = */ function caFormSubmitButton($po_request, $pn_type, $ps_content, $ps_id, $pa_options=null) { $ps_icon_pos = isset($pa_options['icon_position']) ? $pa_options['icon_position'] : __CA_NAV_BUTTON_ICON_POS_LEFT__; $ps_use_classname = isset($pa_options['use_class']) ? $pa_options['use_class'] : ''; $pb_no_background = (isset($pa_options['no_background']) && $pa_options['no_background']) ? true : false; $pb_dont_show_content = (isset($pa_options['dont_show_content']) && $pa_options['dont_show_content']) ? true : false; $vs_graphics_path = (isset($pa_options['graphicsPath']) && $pa_options['graphicsPath']) ? $pa_options['graphicsPath'] : $po_request->getThemeUrlPath()."/graphics"; $vs_classname = (!$pb_no_background) ? 'form-button' : ''; $vs_button = ""; if (!$pb_no_background) { $vs_button .= ""; $vn_padding = ($ps_content) ? 10 : 0; } else { $vn_padding = 0; } if ($vs_img_name = _caNavTypeToImgName($pn_type)) { $vs_button .= "".addslashes($ps_content)." "; if (!$pb_dont_show_content) { $vs_button .= $ps_content; } } else { $vs_button = $ps_content; } if (!$pb_no_background) { $vs_button .= ""; } $vs_button .= ""; // Add hidden submit button... allows some browsers (like Firefox) to support submission of // form when the return key is hit within a text field // We don't actually display this button or use it to submit the form; the form-button output above does that. // Rather, this tag is only included to force browsers to support submit-on-return-key $vs_button .= "
"; return $vs_button; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * icon_position = * use_class = * no_background = * dont_show_content = * graphicsPath = */ function caJSButton($po_request, $pn_type, $ps_content, $ps_id, $pa_attributes=null, $pa_options=null) { $ps_icon_pos = isset($pa_options['icon_position']) ? $pa_options['icon_position'] : __CA_NAV_BUTTON_ICON_POS_LEFT__; $ps_use_classname = isset($pa_options['use_class']) ? $pa_options['use_class'] : ''; $pb_no_background = (isset($pa_options['no_background']) && $pa_options['no_background']) ? true : false; $pb_dont_show_content = (isset($pa_options['dont_show_content']) && $pa_options['dont_show_content']) ? true : false; $vs_graphics_path = (isset($pa_options['graphicsPath']) && $pa_options['graphicsPath']) ? $pa_options['graphicsPath'] : $po_request->getThemeUrlPath()."/graphics"; $vs_classname = (!$pb_no_background) ? 'form-button' : ''; $va_attr = array(); if (is_array($pa_attributes)) { foreach($pa_attributes as $vs_name => $vs_value) { $va_attr[] = $vs_name."='".($vs_value)."'"; } } $vs_button = ""; if (!$pb_no_background) { $vs_button .= ""; $vn_padding = ($ps_content) ? 10 : 0; } else { $vn_padding = 0; } if ($vs_img_name = _caNavTypeToImgName($pn_type)) { $vs_button .= "".addslashes($ps_content)." "; if (!$pb_dont_show_content) { $vs_button .= $ps_content; } } else { $vs_button = $ps_content; } if (!$pb_no_background) { $vs_button .= ""; } $vs_button .= ""; return $vs_button; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * icon_position = * use_class = * no_background = * dont_show_content = * graphicsPath = */ function caNavFormParameters($pa_other_params=null) { $vs_buf = ''; if (is_array($pa_other_params) && sizeof($pa_other_params)) { foreach($pa_other_params as $vs_name => $vs_val) { $vs_buf .= ''."\n"; } } return $vs_buf; } # ------------------------------------------------------------------------------------------------ /** * @param array $pa_options Options are: * graphicsPath = */ function caNavIcon($po_request, $pn_type, $pn_size=null, $pa_attributes=null, $pa_options=null) { if (!is_array($pa_attributes)) { $pa_attributes = array(); } $vs_graphics_path = (isset($pa_options['graphicsPath']) && $pa_options['graphicsPath']) ? $pa_options['graphicsPath'] : $po_request->getThemeUrlPath()."/graphics"; $vs_button = ''; if ($vs_img_name = _caNavTypeToImgName($pn_type, $pn_size)) { if (!isset($pa_attributes['alt'])) { $pa_attributes['alt'] = $vs_img_name; } $vs_attr = _caHTMLMakeAttributeString($pa_attributes); $vs_button = ""; } return $vs_button; } # ------------------------------------------------------------------------------------------------ /** * */ function _caNavTypeToImgName($pn_type, $pn_size='') { switch($pn_type) { case __CA_NAV_BUTTON_ADD__: $vs_img_name = 'add'; break; case __CA_NAV_BUTTON_DELETE__: $vs_img_name = 'delete2'; break; case __CA_NAV_BUTTON_CANCEL__: $vs_img_name = 'cancel'; break; case __CA_NAV_BUTTON_EDIT__: $vs_img_name = 'edit'; break; case __CA_NAV_BUTTON_ALERT__: $vs_img_name = 'alert'; break; case __CA_NAV_BUTTON_SEARCH__: $vs_img_name = 'lens'; break; case __CA_NAV_BUTTON_INFO__: $vs_img_name = 'info'; break; case __CA_NAV_BUTTON_DOWNLOAD__: $vs_img_name = 'download'; break; case __CA_NAV_BUTTON_MESSAGE__: $vs_img_name = 'msg'; break; case __CA_NAV_BUTTON_LOGIN__: $vs_img_name = 'login'; break; case __CA_NAV_BUTTON_SAVE__: $vs_img_name = 'save'; break; case __CA_NAV_BUTTON_HELP__: $vs_img_name = 'help'; break; case __CA_NAV_BUTTON_GO__: $vs_img_name = 'go'; break; case __CA_NAV_BUTTON_DEL_BUNDLE__: $vs_img_name = 'delete'; break; case __CA_NAV_BUTTON_CLOSE__: $vs_img_name = 'close'; break; case __CA_NAV_BUTTON_WATCH__: $vs_img_name = 'watch'; break; case __CA_NAV_BUTTON_UNWATCH__: $vs_img_name = 'unwatch'; break; case __CA_NAV_BUTTON_ADD_LARGE__: $vs_img_name = 'add'; break; default: $vs_img_name = ''; break; } return $vs_img_name.$pn_size; } # ------------------------------------------------------------------------------------------------ /** * Returns an HTML to edit an item in the appropriate bundle-based editor. If no specified item is specified (eg. no id value is set) * the a link to create a new item of the specfied type is returned. * * @param HTTPRequest $po_request The current request object * @param string $ps_content The displayed content of the link * @param string $ps_classname CSS classname(s) to apply to the link * @param string $ps_table The name or table_num of the edited items table * @param int $pn_id Optional row_id for edited item. If omitted a link will be returned to create a new item record. Note that unless the verifyLink option is set, the link will be returned with the specified id whether or not it actually exists. * @param array $pa_additional_parameters Optional array of parameters to return on the editor url * @param array $pa_attributes Optional array of attributes to set on the link's tag. You can use this to set the id of the link, as well as any other parameter. * @param array $pa_options Optional array of options. Supported options are: * verifyLink - if true and $pn_id is set, then existence of record with specified id is verified before link is returned. If the id does not exist then null is returned. Default is false - no verification performed. */ function caEditorLink($po_request, $ps_content, $ps_classname, $ps_table, $pn_id, $pa_additional_parameters=null, $pa_attributes=null, $pa_options=null) { if (!($vs_url = caEditorUrl($po_request, $ps_table, $pn_id, false, $pa_additional_parameters, $pa_options))) { return null; } $vs_tag = " $vs_value) { $vs_tag .= " $vs_attribute='".htmlspecialchars($vs_value, ENT_QUOTES, 'UTF-8')."'"; } } $vs_tag .= '>'.$ps_content.''; return $vs_tag; } # ------------------------------------------------------------------------------------------------ /** * Returns url to edit an item in the appropriate bundle-based editor. If no specified item is specified (eg. no id value is set) * the a link to create a new item of the specfied type is returned. * * @param HTTPRequest $po_request The current request object * @param string $ps_table The name or table_num of the edited items table * @param int $pn_id Optional row_id for edited item. If omitted a link will be returned to create a new item record. Note that unless the verifyLink option is set, the link will be returned with the specified id whether or not it actually exists. * @param boolean $pb_return_url_as_pieces If true an array is returned with the various components of the editor URL as separate keys. The keys will be 'module', 'controller', 'action' and '_pk' (the name of the primary key for the item); the primary key value itself is returned as both 'id' and whatever the primary key name is (eg. named whatever the value of _pk is). Default is false - return as a string rather than array. * @param array $pa_additional_parameters Optional array of parameters to return on the editor url * @param array $pa_options Optional array of options. Supported options are: * verifyLink - if true and $pn_id is set, then existence of record with specified id is verified before link is returned. If the id does not exist then null is returned. Default is false - no verification performed. * action - if set, action of returned link will be set to the supplied value */ function caEditorUrl($po_request, $ps_table, $pn_id=null, $pb_return_url_as_pieces=false, $pa_additional_parameters=null, $pa_options=null) { $o_dm = Datamodel::load(); if (is_numeric($ps_table)) { if (!($t_table = $o_dm->getInstanceByTableNum($ps_table, true))) { return null; } } else { if (!($t_table = $o_dm->getInstanceByTableName($ps_table, true))) { return null; } } $vs_pk = $t_table->primaryKey(); $vs_table = $ps_table; if ($vs_table == 'ca_list_items') { $vs_table = 'ca_lists'; } switch($vs_table) { case 'ca_relationship_types': $vs_action = isset($pa_options['action']) ? $pa_options['action'] : (($po_request->isLoggedIn() && $po_request->user->canDoAction('can_configure_relationship_types')) ? 'Edit' : 'Summary'); break; default: if (!ca_user_roles::isValidAction('can_edit_'.$vs_table)) { $vs_action = 'Edit'; } else { $vs_action = isset($pa_options['action']) ? $pa_options['action'] : (($po_request->isLoggedIn() && $po_request->user->canDoAction('can_edit_'.$vs_table)) ? 'Edit' : 'Summary'); } break; } switch($ps_table) { case 'ca_objects': case 57: $vs_module = 'editor/objects'; $vs_controller = 'ObjectEditor'; break; case 'ca_object_lots': case 51: $vs_module = 'editor/object_lots'; $vs_controller = 'ObjectLotEditor'; break; case 'ca_object_events': case 45: $vs_module = 'editor/object_events'; $vs_controller = 'ObjectEventEditor'; break; case 'ca_entities': case 20: $vs_module = 'editor/entities'; $vs_controller = 'EntityEditor'; break; case 'ca_places': case 72: $vs_module = 'editor/places'; $vs_controller = 'PlaceEditor'; break; case 'ca_occurrences': case 67: $vs_module = 'editor/occurrences'; $vs_controller = 'OccurrenceEditor'; break; case 'ca_collections': case 13: $vs_module = 'editor/collections'; $vs_controller = 'CollectionEditor'; break; case 'ca_storage_locations': case 89: $vs_module = 'editor/storage_locations'; $vs_controller = 'StorageLocationEditor'; break; case 'ca_sets': case 103: $vs_module = 'manage/sets'; $vs_controller = 'SetEditor'; break; case 'ca_set_items': case 105: $vs_module = 'manage/set_items'; $vs_controller = 'SetItemEditor'; break; case 'ca_lists': case 36: $vs_module = 'administrate/setup/list_editor'; $vs_controller = 'ListEditor'; break; case 'ca_list_items': case 33: $vs_module = 'administrate/setup/list_item_editor'; $vs_controller = 'ListItemEditor'; break; case 'ca_object_representations': case 56: $vs_module = 'editor/object_representations'; $vs_controller = 'ObjectRepresentationEditor'; break; case 'ca_relationship_types': case 79: $vs_module = 'administrate/setup/relationship_type_editor'; $vs_controller = 'RelationshipTypeEditor'; break; case 'ca_metadata_elements': case 42: $vs_module = 'administrate/setup'; $vs_controller = 'Elements'; break; case 'ca_loans': case 133: $vs_module = 'editor/loans'; $vs_controller = 'LoanEditor'; break; case 'ca_movements': case 137: $vs_module = 'editor/movements'; $vs_controller = 'MovementEditor'; break; case 'ca_tours': case 153: $vs_module = 'editor/tours'; $vs_controller = 'TourEditor'; break; case 'ca_tour_stops': case 155: $vs_module = 'editor/tour_stops'; $vs_controller = 'TourStopEditor'; break; case 'ca_bundle_mappings': case 128: $vs_module = 'administrate/setup/bundle_mapping_editor'; $vs_controller = 'BundleMappingEditor'; break; case 'ca_bundle_mapping_groups': case 130: $vs_module = 'administrate/setup/bundle_mapping_group_editor'; $vs_controller = 'BundleMappingGroupEditor'; break; default: return null; break; } if (isset($pa_options['verifyLink']) && $pa_options['verifyLink']) { // Make sure record link points to exists if (($pn_id > 0) && !$t_table->load($pn_id)) { return null; } } if ($pb_return_url_as_pieces) { return array( 'module' => $vs_module, 'controller' => $vs_controller, 'action' => $vs_action, $vs_pk => $pn_id, 'id' => $pn_id, '_pk' => $vs_pk // tells you what the name of the primary key is ); } else { if (!is_array($pa_additional_parameters)) { $pa_additional_parameters = array(); } $pa_additional_parameters = array_merge(array($vs_pk => $pn_id), $pa_additional_parameters); return caNavUrl($po_request, $vs_module, $vs_controller, $vs_action, $pa_additional_parameters); } } # ------------------------------------------------------------------------------------------------ /** * Returns urls for JSON lookup services */ function caJSONLookupServiceUrl($po_request, $ps_table) { $o_dm = Datamodel::load(); if (is_numeric($ps_table)) { if (!($t_table = $o_dm->getInstanceByTableNum($ps_table, true))) { return null; } } else { if (!($t_table = $o_dm->getInstanceByTableName($ps_table, true))) { return null; } } $vs_pk = $t_table->primaryKey(); $vs_module = 'lookup'; switch($ps_table) { case 'ca_objects': case 57: $vs_controller = 'Object'; break; case 'ca_object_lots': case 51: $vs_controller = 'ObjectLot'; break; case 'ca_entities': case 20: $vs_controller = 'Entity'; break; case 'ca_places': case 72: $vs_controller = 'Place'; break; case 'ca_occurrences': case 67: $vs_controller = 'Occurrence'; break; case 'ca_collections': case 13: $vs_controller = 'Collection'; break; case 'ca_storage_locations': case 89: $vs_controller = 'StorageLocation'; break; case 'ca_sets': case 103: $vs_controller = 'Set'; break; case 'ca_set_items': case 105: $vs_controller = 'SetItem'; break; case 'ca_lists': case 36: $vs_controller = 'List'; break; case 'ca_list_items': case 33: $vs_controller = 'ListItem'; break; case 'ca_relationship_types': case 79: $vs_controller = 'RelationshipType'; break; case 'ca_loans': case 133: $vs_controller = 'Loan'; break; case 'ca_movements': case 137: $vs_controller = 'Movement'; break; case 'ca_bundle_displays': case 124: $vs_controller = 'BundleDisplay'; break; case 'ca_metadata_elements': case 42: $vs_controller = 'MetadataElement'; break; case 'ca_search_forms': case 121: $vs_controller = 'SearchForm'; break; case 'ca_tours': case 153: $vs_controller = 'Tour'; break; case 'ca_tour_stops': case 155: $vs_controller = 'TourStop'; break; case 'ca_bundle_mappings': case 128: $vs_controller = 'BundleMappings'; break; case 'ca_bundle_mapping_groups': case 130: $vs_controller = 'BundleMappingGroups'; break; case 'ca_editor_uis': case 101: $vs_controller = 'EditorUI'; break; case 'ca_editor_ui_screens': case 100: $vs_controller = 'EditorUIScreen'; break; case 'ca_object_representations': case 56: $vs_controller = 'ObjectRepresentation'; break; default: return null; break; } return array( 'ancestorList' => caNavUrl($po_request, $vs_module, $vs_controller, 'GetHierarchyAncestorList'), 'levelList' => caNavUrl($po_request, $vs_module, $vs_controller, 'GetHierarchyLevel'), 'search' => caNavUrl($po_request, $vs_module, $vs_controller, 'Get'), 'idno' => caNavUrl($po_request, $vs_module, $vs_controller, 'IDNo'), 'intrinsic' => caNavUrl($po_request, $vs_module, $vs_controller, 'intrinsic') ); } # ------------------------------------------------------------------------------------------------ ?>