/** return a database value for $item_id based on whether $mask_variable points to title or to an item_attribute. for item_attribute references there are some further options. a legal mask item can include the following: {s_attribute_type} {s_attribute_type.img} {s_attribute_type.value} // the .value will result in the same as if no .option was specified. {s_attribute_type.display} {title} {s_item_type} {item_id} {instance_no} {s_status_type} */ function _get_mask_variable_value($mask_variable, $item_instance_r) { $value = ''; if (is_array($mask_variable) && isset($mask_variable['s_attribute_type']) && isset($mask_variable['option'])) { $value = NULL; // the options that require a item_id context if (is_numeric($item_instance_r['item_id'])) { if ($mask_variable['option'] == 'img') { $lookup_attr_r = fetch_attribute_type_lookup_r($mask_variable['s_attribute_type'], fetch_attribute_val($item_instance_r['item_id'], $item_instance_r['instance_no'], $mask_variable['s_attribute_type'])); if ($lookup_attr_r !== false) { if (strlen($lookup_attr_r['img']) > 0 && $lookup_attr_r['img'] != 'none') { $value = theme_image($lookup_attr_r['img'], $lookup_attr_r['display']); } else { // if no image, then use (value). $value = '(' . $lookup_attr_r['value'] . ')'; } } } else { if ($mask_variable['option'] == 'display' && is_numeric($item_instance_r['item_id'])) { $value = fetch_attribute_type_lookup_r($mask_variable['s_attribute_type'], fetch_attribute_val($item_instance_r['item_id'], $item_instance_r['instance_no'], $mask_variable['s_attribute_type']), 'display'); } else { if ($mask_variable['option'] == 'display_type' && is_numeric($item_instance_r['item_id'])) { //$value = get_display_field($mask_variable['s_attribute_type'], $mask_variable['prompt'], $mask_variable['display_type'], fetch_attribute_val($item_instance_r['item_id'], $item_instance_r['instance_no'], $mask_variable['s_attribute_type']), FALSE); $value = get_item_display_field($item_instance_r, $mask_variable, fetch_attribute_val($item_instance_r['item_id'], $item_instance_r['instance_no'], $mask_variable['s_attribute_type']), FALSE); } } } // as a last resort. if (strlen($value) == 0) { $value = fetch_attribute_val($item_instance_r['item_id'], $item_instance_r['instance_no'], $mask_variable['s_attribute_type']); } } else { if (strlen($item_instance_r['s_item_type']) > 0) { if ($mask_variable['option'] == 'prompt') { $value = fetch_s_item_type_attr_prompt($item_instance_r['s_item_type'], $mask_variable['s_attribute_type']); } } } return $value; } else { if (!is_array($mask_variable) && $mask_variable == 'title') { return $item_instance_r['title']; } else { if (!is_array($mask_variable) && $mask_variable == 's_item_type') { return $item_instance_r['s_item_type']; } else { if (!is_array($mask_variable) && $mask_variable == 'item_id') { return $item_instance_r['item_id']; } else { if (!is_array($mask_variable) && $mask_variable == 'instance_no') { return $item_instance_r['instance_no']; } else { if (!is_array($mask_variable) && $mask_variable == 's_status_type') { return $item_instance_r['s_status_type']; } else { return $mask_variable; } } } } } } }
$listingObject->addColumn(); } } else { $listingObject->addColumn(); } } for ($i = 0; $i < count($v_column_display_config_rs); $i++) { if ($v_column_display_config_rs[$i]['include_in_listing'] !== FALSE) { if ($v_column_display_config_rs[$i]['column_type'] == 's_attribute_type') { if ($v_column_display_config_rs[$i]['search_attribute_ind'] == 'y') { $attribute_val = $item_r[$v_column_display_config_rs[$i]['fieldname']]; } else { if ($v_column_display_config_rs[$i]['multi_attribute_ind'] == 'Y' || $v_column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') { $attribute_val = fetch_attribute_val_r($item_r['item_id'], $item_r['instance_no'], $v_column_display_config_rs[$i]['s_attribute_type']); } else { $attribute_val = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $v_column_display_config_rs[$i]['s_attribute_type']); } } if ($attribute_val !== FALSE && $attribute_val !== NULL) { $listingObject->addAttrDisplayColumn($item_r, fetch_cached_attribute_type_r($v_column_display_config_rs[$i]['s_attribute_type']), $attribute_val); } else { $listingObject->addColumn(); } } else { if ($v_column_display_config_rs[$i]['column_type'] == 's_field_type') { if ($v_column_display_config_rs[$i]['s_field_type'] == 'RATING') { $rating = fetch_review_rating($item_r['item_id']); if ($rating !== FALSE) { $attribute_type_r = fetch_cached_attribute_type_r($v_column_display_config_rs[$i]['s_attribute_type']); if (strlen($attribute_type_r['display_type']) == 0 || $attribute_type_r['display_type'] == 'hidden') { $attribute_type_r['display_type'] = 'review';
/** * */ function copy_item_to_http_vars($old_item_r, $new_item_type) { $HTTP_VARS = array(); $results = fetch_item_attribute_type_rs($old_item_r['s_item_type'], 'not_instance_field_types'); if ($results) { $attr_order_no_r = array(); while ($item_attribute_type_r = db_fetch_assoc($results)) { if ($item_attribute_type_r['s_field_type'] == 'TITLE') { $order_no = fetch_s_item_attribute_type_next_order_no($new_item_type, $item_attribute_type_r['s_attribute_type']); $fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $order_no); $HTTP_VARS[$fieldname] = $old_item_r['title']; } else { $last_order_no = NULL; if (is_numeric($attr_order_no_r[$item_attribute_type_r['s_attribute_type']])) { $last_order_no = $attr_order_no_r[$item_attribute_type_r['s_attribute_type']]; } $order_no = fetch_s_item_attribute_type_next_order_no($new_item_type, $item_attribute_type_r['s_attribute_type'], $last_order_no); if ($order_no !== FALSE) { $fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $order_no); // update with latest order no $attr_order_no_r[$item_attribute_type_r['s_attribute_type']] = $order_no; if ($item_attribute_type_r['lookup_attribute_ind'] == 'Y' || $item_attribute_type_r['multi_attribute_ind'] == 'Y') { $attribute_val_r = fetch_attribute_val_r($old_item_r['item_id'], $old_item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); if (is_not_empty_array($attribute_val_r)) { $HTTP_VARS[$fieldname] = $attribute_val_r; } } else { $attribute_val = fetch_attribute_val($old_item_r['item_id'], $old_item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); if (strlen($attribute_val) > 0) { $HTTP_VARS[$fieldname] = $attribute_val; } } } } } db_free_result($results); } return $HTTP_VARS; }
function get_related_items_listing($item_r, $HTTP_VARS, $related_mode) { global $PHP_SELF; $buffer = ''; $results = fetch_item_instance_relationship_rs($item_r['item_id'], $item_r['instance_no'], $related_mode); if ($results) { $listingObject = new HTML_Listing($PHP_SELF, $HTTP_VARS); $listingObject->setBufferOutput(TRUE); $listingObject->setNoRowsMessage(get_opendb_lang_var('no_items_found')); $listingObject->setShowItemImages(TRUE); $listingObject->setIncludeFooter(FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('type'), 'type', FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('title'), 'title', FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('action'), 'action', FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('status'), 'status', FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('status_comment'), 'status_comment', FALSE); $listingObject->addHeaderColumn(get_opendb_lang_var('category'), 'category', FALSE); $listingObject->startListing(NULL); while ($related_item_r = db_fetch_assoc($results)) { $listingObject->startRow(); $listingObject->addItemTypeImageColumn($related_item_r['s_item_type']); $listingObject->addTitleColumn($related_item_r); $action_links_rs = NULL; if (is_user_granted_permission(PERM_ITEM_OWNER) && get_opendb_session_var('user_id') === $item_r['owner_id'] || is_user_granted_permission(PERM_ITEM_ADMIN)) { $action_links_rs[] = array(url => 'item_input.php?op=edit&item_id=' . $related_item_r['item_id'] . '&instance_no=' . $related_item_r['instance_no'], img => 'edit.gif', text => get_opendb_lang_var('edit')); if (get_opendb_config_var('listings', 'show_refresh_actions') && is_item_legal_site_type($related_item_r['s_item_type'])) { $action_links_rs[] = array(url => 'item_input.php?op=site-refresh&item_id=' . $related_item_r['item_id'] . '&instance_no=' . $related_item_r['instance_no'], img => 'refresh.gif', text => get_opendb_lang_var('refresh')); } $action_links_rs[] = array(url => 'item_input.php?op=delete&item_id=' . $related_item_r['item_id'] . '&instance_no=' . $related_item_r['instance_no'] . '&parent_item_id=' . $item_r['item_id'] . '&parent_instance_no=' . $item_r['instance_no'], img => 'delete.gif', text => get_opendb_lang_var('delete')); $action_links_rs[] = array(url => 'item_input.php?op=delete-relation&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'] . '&parent_item_id=' . $related_item_r['item_id'] . '&parent_instance_no=' . $related_item_r['instance_no'], img => 'delete.gif', text => get_opendb_lang_var('delete_relationship')); } $listingObject->addActionColumn($action_links_rs); $status_type_r = fetch_status_type_r($related_item_r['s_status_type']); $listingObject->addThemeImageColumn($status_type_r['img'], $status_type_r['description'], $status_type_r['description'], 's_status_type'); //type // If a comment is allowed and defined, add it in. if ($status_type_r['status_comment_ind'] == 'Y' || get_opendb_session_var('user_id') === $related_item_r['owner_id'] || is_user_granted_permission(PERM_ITEM_ADMIN)) { // support newlines in this field $listingObject->addColumn(nl2br($related_item_r['status_comment'])); } else { $listingObject->addColumn(get_opendb_lang_var('not_applicable')); } $attribute_type_r = fetch_sfieldtype_item_attribute_type_r($related_item_r['s_item_type'], 'CATEGORY'); if (is_array($attribute_type_r)) { if ($attribute_type_r['lookup_attribute_ind'] === 'Y') { $attribute_val = fetch_attribute_val_r($related_item_r['item_id'], $related_item_r['instance_no'], $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); } else { $attribute_val = fetch_attribute_val($related_item_r['item_id'], $related_item_r['instance_no'], $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); } $listingObject->addAttrDisplayColumn($related_item_r, $attribute_type_r, $attribute_val); } $listingObject->endRow(); } $listingObject->endListing(); $buffer =& $listingObject->getContents(); unset($listingObject); return $buffer; } else { return NULL; } }
$display_type = trim($item_attribute_type_r['display_type']); if ($HTTP_VARS['mode'] == 'printable' && $item_attribute_type_r['printable_ind'] != 'Y' || strlen($display_type) == 0 && $item_attribute_type_r['input_type'] == 'hidden') { // We allow the get_display_field to handle hidden variable, in case at some stage // we might want to change the functionality of 'hidden' to something other than ignore. $display_type = 'hidden'; } if ($item_attribute_type_r['s_field_type'] == 'ITEM_ID') { $value = $item_r['item_id']; } else { if ($item_attribute_type_r['s_field_type'] == 'UPDATE_ON') { $value = $item_r['update_on']; } else { if (is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) { $value = fetch_attribute_val_r($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); } else { $value = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); } } } if (is_not_empty_array($value) || !is_array($value) && strlen($value) > 0) { $item_attribute_type_r['display_type'] = $display_type; $item_attribute_type_r['compulsory_ind'] = 'N'; $field = get_item_display_field($item_r, $item_attribute_type_r, $value, FALSE); if (strlen($field) > 0) { echo format_item_data_field($item_attribute_type_r, $field, $prompt_mask, NULL); // field mask } } } } db_free_result($results);
function get_edit_item_form($op, $item_r, $HTTP_VARS, &$upload_file_fields) { // is at least one field a compulsory field? $compulsory_fields = FALSE; $upload_file_fields = FALSE; $results = fetch_item_attribute_type_rs($item_r['s_item_type'], 'not_instance_field_types'); if ($results) { $formContents .= "\n<table>"; while ($item_attribute_type_r = db_fetch_assoc($results)) { if ($item_attribute_type_r['s_field_type'] == 'ITEM_ID') { continue; } // need to provide a proper encoded form if upload encountered, assume upload where file attribute encountered if ($item_attribute_type_r['file_attribute_ind'] == 'Y') { $upload_file_fields = TRUE; } if ($op == 'refresh' || $op == 'edit' || $op == 'newinstance') { if (is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) { $item_attribute_type_r['attribute_val'] = fetch_attribute_val_r($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); } else { $item_attribute_type_r['attribute_val'] = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']); } } if ($op == 'refresh') { $old_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']); $new_value = get_field_value($op, $item_r, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val'], $HTTP_VARS); // this represents multiple selections for a single value, lookup / multi value attributes will // be dealt with together. if (is_not_empty_array($new_value) && !is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) { foreach ($new_value as $key => $val) { $new_value[$key] = filter_item_input_field($item_attribute_type_r, $val); } } else { $new_value = filter_item_input_field($item_attribute_type_r, $new_value); // If no HTTP value, especially where FILE UPLOAD is being concerned, attempt to get from database again. if (($op == 'edit' || $op == 'newinstance') && $new_value === NULL) { $new_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']); } } } else { //if($op == 'refresh') $old_value = FALSE; $new_value = get_field_value($op, $item_r, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val'], $HTTP_VARS); if (is_not_empty_array($new_value) && !is_multivalue_attribute_type($item_attribute_type_r['s_attribute_type'])) { foreach ($new_value as $key => $val) { $new_value[$key] = filter_item_input_field($item_attribute_type_r, $val); } } else { $new_value = filter_item_input_field($item_attribute_type_r, $new_value); // If no HTTP value, especially where FILE UPLOAD is being concerned, attempt to get from database again. if (($op == 'edit' || $op == 'newinstance') && $new_value === NULL) { $new_value = get_old_field_value($item_r, $item_attribute_type_r['s_field_type'], $item_attribute_type_r['attribute_val']); } } } // Enforce compulsory indicator for TITLE. if ($item_attribute_type_r['s_field_type'] == 'TITLE') { $item_attribute_type_r['compulsory_ind'] = 'Y'; $override_title_articles_r = get_opendb_config_var('item_input', 'title_articles'); if (is_not_empty_array($override_title_articles_r)) { if (is_not_empty_array($new_value)) { foreach ($new_value as $key => $val) { $new_value[$key] = trim(format_title_grammar_article($val, $override_title_articles_r)); } } else { $new_value = trim(format_title_grammar_article($new_value, $override_title_articles_r)); } } } $formContents .= get_item_form_row($op, $item_r, $item_attribute_type_r, $old_value, $new_value); if ($item_attribute_type_r['compulsory_ind'] == 'Y') { $compulsory_fields = TRUE; } } //while db_free_result($results); $formContents .= "\n</table>"; $help_block_r = NULL; if ($op == 'refresh') { $help_block_r[] = array('img' => 'rs.gif', 'text' => get_opendb_lang_var('refreshed')); } $help_block_r[] = array('img' => 'compulsory.gif', 'text' => get_opendb_lang_var('compulsory_field'), id => 'compulsory'); $formContents .= format_help_block($help_block_r); return $formContents; } else { return FALSE; } }
function get_last_num_items_rs($num_of_items, $owner_id = NULL, $s_item_type = NULL, $update_on = NULL, $not_owner_id = NULL, $site_url_prefix = NULL, $title_mask_id = NULL) { if (strlen($owner_id) > 0) { $search_vars_r['owner_id'] = $owner_id; } if (strlen($s_item_type) > 0) { $search_vars_r['s_item_type'] = $s_item_type; } if (strlen($update_on) > 0) { $search_vars_r['update_on'] = $update_on; } if (strlen($not_owner_id) > 0) { $search_vars_r['not_owner_id'] = $not_owner_id; } $dummy_r = NULL; $results = fetch_item_listing_rs($search_vars_r, $dummy_r, 'update_on', 'DESC', 0, $num_of_items); if ($results) { if ($title_mask_id == 'feeds') { $title_mask_group = array('feeds', 'item_display'); } else { $title_mask_group = array('last_items_list', 'item_listing'); } $titleMaskCfg = new TitleMask($title_mask_group); $image_attribute_type_rs = NULL; while ($item_r = db_fetch_assoc($results)) { $item_r['title'] = $titleMaskCfg->expand_item_title($item_r); $item_r['update_on'] = get_localised_timestamp(get_opendb_config_var('welcome.last_items_list', 'datetime_mask'), $item_r['update_on']); $item_r['item_display_url'] = 'item_display.php?item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no']; if ($site_url_prefix != NULL) { $item_r['item_display_url'] = $site_url_prefix . $item_r['item_display_url']; } $item_type_r = fetch_item_type_r($item_r['s_item_type']); $itemtypeimagesrc = theme_image_src($item_type_r['image']); $size = @getimagesize($itemtypeimagesrc); if (is_array($size)) { $item_r['itemtypeimage']['width'] = $size[0]; $item_r['itemtypeimage']['height'] = $size[1]; } $item_r['itemtypeimage']['url'] = $itemtypeimagesrc; if ($site_url_prefix != NULL) { $item_r['itemtypeimage']['url'] = $site_url_prefix . $item_r['itemtypeimage']['url']; } $item_r['itemtypeimage']['title'] = $item_type_r['description']; $item_r['itemtypeimage']['s_item_type'] = $item_r['s_item_type']; if (get_opendb_config_var('welcome.last_items_list', 'show_item_image') !== FALSE) { if (!is_array($image_attribute_type_rs) || !is_array($image_attribute_type_rs[$item_r['s_item_type']])) { $image_attribute_type_rs[$item_r['s_item_type']] = fetch_sfieldtype_item_attribute_type_r($item_r['s_item_type'], 'IMAGE'); } // of a IMAGE s_attribute defined for this s_item_type if (is_array($image_attribute_type_rs[$item_r['s_item_type']])) { $attribute_type_r = $image_attribute_type_rs[$item_r['s_item_type']]; $imageurl = fetch_attribute_val($item_r['item_id'], NULL, $attribute_type_r['s_attribute_type']); $file_r = file_cache_get_image_r($imageurl, 'display'); $item_r['imageurl']['url'] = $file_r['thumbnail']['url']; if ($site_url_prefix != NULL) { $item_r['imageurl']['url'] = $site_url_prefix . $item_r['imageurl']['url']; } $item_r['imageurl']['width'] = $file_r['thumbnail']['width']; $item_r['imageurl']['height'] = $file_r['thumbnail']['height']; $item_r['imageurl']['title'] = $item_r['title']; } } $item_rs[] = $item_r; unset($item_r); } //while db_free_result($results); } return $item_rs; }
/** * @param $item_r */ function addTitleColumn($item_r) { $s_item_type = $item_r['s_item_type']; $is_item_reviewed = FALSE; if (is_item_reviewed($item_r['item_id'])) { $is_item_reviewed = TRUE; } $is_borrowed_or_returned = FALSE; if (is_item_borrowed_or_returned_by_user($item_r['item_id'], $item_r['instance_no'], get_opendb_session_var('user_id'))) { $is_borrowed_or_returned = TRUE; } $item_cover_image = FALSE; $header_column_r = $this->findHeaderColumnByFieldname('title'); if ($header_column_r['cover_image_support'] === TRUE) { $item_cover_image = NULL; if (strlen($this->_item_type_rs[$s_item_type]['image_attribute_type']) === 0) { $this->_item_type_rs[$s_item_type]['image_attribute_type_r'] = fetch_sfieldtype_item_attribute_type_r($s_item_type, 'IMAGE'); } if (is_array($this->_item_type_rs[$s_item_type]['image_attribute_type_r'])) { $attribute_type_r = $this->_item_type_rs[$s_item_type]['image_attribute_type_r']; $item_cover_image = fetch_attribute_val($item_r['item_id'], $item_r['instance_no'], $attribute_type_r['s_attribute_type']); // a kludge to use FALSE to test whether a default image should be displayed if ($item_cover_image === FALSE) { $item_cover_image = NULL; } } } $item_r['title'] = $this->_titleMaskCfg->expand_item_title($item_r); $title_href_link = 'item_display.php?item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no']; if ($item_cover_image !== FALSE) { $this->_row_column_rs[] = array(column_type => 'coverimage', title_href_link => $title_href_link, item_cover_image => $item_cover_image); } $this->_row_column_rs[] = array(column_type => 'title', item_title => $item_r['title'], title_href_link => $title_href_link, is_item_reviewed => $is_item_reviewed, is_borrowed_or_returned => $is_borrowed_or_returned); }