function update_s_site_plugin_s_attribute_type_map($site_type, $sequence_number, $s_item_type_group, $s_item_type, $s_attribute_type, $lookup_attribute_val_restrict_ind) { if (strlen($s_item_type_group) > 0 && is_numeric($sequence_number)) { $s_item_type_group = strtoupper($s_item_type_group); $s_item_type = strtoupper($s_item_type); $s_attribute_type = strtoupper($s_attribute_type); if (is_lookup_attribute_type($s_attribute_type)) { if ($lookup_attribute_val_restrict_ind == 'Y' || $lookup_attribute_val_restrict_ind == 'y') { $lookup_attribute_val_restrict_ind = 'Y'; } else { $lookup_attribute_val_restrict_ind = 'N'; } } else { $lookup_attribute_val_restrict_ind = 'N'; } // make sure only one of s_item_type_group and s_item_type is configured. if ($s_item_type_group !== FALSE && $s_item_type !== FALSE && strlen($s_item_type) > 0 && strlen($s_item_type_group) > 0 && ($s_item_type != '*' || $s_item_type_group != '*')) { if ($s_item_type != '*') { $s_item_type_group = '*'; } else { if ($s_item_type_group != '*') { $s_item_type = '*'; } } } $query = "UPDATE s_site_plugin_s_attribute_type_map " . "SET variable = variable " . ($s_item_type_group !== FALSE ? ", s_item_type_group = '" . $s_item_type_group . "'" : "") . ($s_item_type !== FALSE ? ", s_item_type = '" . $s_item_type . "'" : "") . ($s_attribute_type !== FALSE ? ", s_attribute_type = '" . $s_attribute_type . "'" : "") . ($lookup_attribute_val_restrict_ind !== FALSE ? ", lookup_attribute_val_restrict_ind = '" . $lookup_attribute_val_restrict_ind . "'" : "") . " WHERE site_type = '{$site_type}' AND sequence_number = {$sequence_number}"; $update = db_query($query); // We should not treat updates that were not actually updated because value did not change as failures. $rows_affected = db_affected_rows(); if ($update && $rows_affected !== -1) { if ($rows_affected > 0) { opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, NULL, array($site_type, $sequence_number, $s_item_type_group, $s_item_type, $s_attribute_type, $lookup_attribute_val_restrict_ind)); } return TRUE; } else { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($site_type, $sequence_number, $s_item_type_group, $s_item_type, $s_attribute_type, $lookup_attribute_val_restrict_ind)); return FALSE; } } //else return FALSE; }
function update_user_addresses($user_r, $address_provided_r, $HTTP_VARS, &$errors) { // No errors recorded at this stage. $errors = NULL; $address_creation_success = TRUE; $address_type_sequence_number_r = NULL; $addr_results = fetch_user_address_type_rs($user_r['user_id'], TRUE); if ($addr_results) { while ($address_type_r = db_fetch_assoc($addr_results)) { $v_address_type = strtolower($address_type_r['s_address_type']); $address_creation_success = TRUE; // address does not currently exist, so create it. if ($address_type_r['sequence_number'] === NULL) { if ($address_provided_r[$v_address_type] !== FALSE) { $new_sequence_number = insert_user_address($user_r['user_id'], $address_type_r['s_address_type'], $HTTP_VARS[$v_address_type]['public_address_ind'], $HTTP_VARS[$v_address_type]['borrow_address_ind']); if ($new_sequence_number !== FALSE) { $address_type_r['sequence_number'] = $new_sequence_number; } else { $address_creation_success = FALSE; } } } else { $new_sequence_number = update_user_address($address_type_r['sequence_number'], $HTTP_VARS[$v_address_type]['public_address_ind'], $HTTP_VARS[$v_address_type]['borrow_address_ind']); } if ($address_creation_success !== FALSE) { if ($address_provided_r[$v_address_type] !== FALSE) { $attr_results = fetch_address_type_attribute_type_rs($address_type_r['s_address_type'], 'update', TRUE); if ($attr_results) { while ($addr_attribute_type_r = db_fetch_assoc($attr_results)) { $fieldname = get_field_name($addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']); if (is_lookup_attribute_type($addr_attribute_type_r['s_attribute_type'])) { $lookup_value_r = NULL; if (is_array($HTTP_VARS[$v_address_type][$fieldname])) { $lookup_value_r =& $HTTP_VARS[$v_address_type][$fieldname]; } else { if (strlen(trim($HTTP_VARS[$v_address_type][$fieldname])) > 0) { $lookup_value_r[] = $HTTP_VARS[$v_address_type][$fieldname]; } } $user_addr_attr_lookup_val_r = fetch_user_address_lookup_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']); if ($user_addr_attr_lookup_val_r !== FALSE) { if (is_not_empty_array($lookup_value_r)) { // insert/update mode if (!update_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $lookup_value_r)) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } else { if (!delete_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'])) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } } else { if (is_not_empty_array($lookup_value_r)) { if (!insert_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $lookup_value_r)) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } } } else { $attribute_val = fetch_user_address_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']); if ($attribute_val !== FALSE) { if (strlen($HTTP_VARS[$v_address_type][$fieldname]) > 0) { if (!update_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $HTTP_VARS[$v_address_type][$fieldname])) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } else { if (!delete_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'])) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } } else { if (strlen($HTTP_VARS[$v_address_type][$fieldname]) > 0) { if (!insert_user_address_attributes($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no'], $HTTP_VARS[$v_address_type][$fieldname])) { $db_error = db_error(); $errors[] = array('error' => get_opendb_lang_var('user_address_not_updated'), 'detail' => $db_error); $address_creation_success = FALSE; } } } } } db_free_result($attr_results); } } else { // existing address, we want to get rid of it here if ($address_type_r['sequence_number'] !== NULL) { if (delete_user_address_attributes($address_type_r['sequence_number'])) { delete_user_address($address_type_r['sequence_number']); } } } } } db_free_result($addr_results); } return $address_creation_success; }
function display_site_plugin_s_attribute_type_map_row($record_r, $row) { global $PHP_SELF; global $ADMIN_TYPE; if (is_not_empty_array($record_r)) { echo "<input type=\"hidden\" name=\"exists_ind[{$row}]\" value=\"Y\">"; echo "<input type=\"hidden\" name=\"sequence_number[{$row}]\" value=\"" . $record_r['sequence_number'] . "\">"; echo "<td class=\"data\">" . get_input_field("variable[{$row}]", NULL, "Variable", "readonly", "Y", $record_r['variable'], FALSE) . "</td>"; } else { echo "<input type=\"hidden\" name=\"exists_ind[{$row}]\" value=\"N\">"; echo "<td class=\"data\">" . get_input_field("variable[{$row}]", NULL, "Variable", "text(10,20)", "Y", NULL, FALSE) . "</td>"; } $item_type_groups[] = '*'; $results = fetch_item_type_group_rs(); if ($results) { while ($item_type_group_r = db_fetch_assoc($results)) { $item_type_groups[] = $item_type_group_r['s_item_type_group']; } db_free_result($results); } // this is to avoid confusion if system data is defined for non-existent s_item_type_groups if (!in_array($record_r['s_item_type_group'], $item_type_groups)) { $item_type_groups[] = $record_r['s_item_type_group']; } echo "\n<td class=\"data\">" . custom_select("s_item_type_group[{$row}]", $item_type_groups, "%value%", 1, $record_r['s_item_type_group'], 'value', NULL, NULL, "if(this.options[this.options.selectedIndex].value != '*'){this.form['s_item_type[{$row}]'].options[0].selected=true;}") . "</td>"; $item_types[] = '*'; $results = fetch_item_type_rs(); if ($results) { while ($item_type_r = db_fetch_assoc($results)) { $item_types[] = $item_type_r['s_item_type']; } db_free_result($results); } // this is to avoid confusion if system data is defined for non-existent s_item_types if (!in_array($record_r['s_item_type'], $item_types)) { $item_types[] = $record_r['s_item_type']; } echo "\n<td class=\"data\">" . custom_select("s_item_type[{$row}]", $item_types, "%value%", 1, $record_r['s_item_type'], 'value', NULL, NULL, "if(this.options[this.options.selectedIndex].value != '*'){this.form['s_item_type_group[{$row}]'].options[0].selected=true;}") . "</td>"; $attribute_types[] = ''; $results = fetch_item_type_s_attribute_type_rs(); if ($results) { while ($attribute_type_r = db_fetch_assoc($results)) { $attribute_types[] = $attribute_type_r['s_attribute_type']; } db_free_result($results); } // this is to avoid confusion if system data is defined for non-existent s_attribute_types if (!in_array($record_r['s_attribute_type'], $attribute_types)) { $attribute_types[] = $record_r['s_attribute_type']; } echo "\n<td class=\"data\">" . custom_select("s_attribute_type[{$row}]", $attribute_types, "%value%", 1, $record_r['s_attribute_type']) . "</td>"; if (is_array($record_r) && is_lookup_attribute_type($record_r['s_attribute_type'])) { echo "<td class=\"data\"><input type=\"checkbox\" class=\"checkbox\" name=\"lookup_attribute_val_restrict_ind[{$row}]\" value=\"Y\"" . (strtoupper($record_r['lookup_attribute_val_restrict_ind']) == 'Y' ? 'CHECKED' : '') . ">"; } else { echo "\n<td class=\"data\"> </td>"; } echo "\n<td class=\"data\">"; if (is_not_empty_array($record_r)) { echo "<a href=\"{$PHP_SELF}?type={$ADMIN_TYPE}&op=delete_site_plugin_s_attribute_type_map&site_type=" . $record_r['site_type'] . "&sequence_number=" . $record_r['sequence_number'] . "\">Delete</a>"; } else { echo " "; } echo "\n</td>"; }
if ($user_r['user_id'] === get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ADMIN_USER_PROFILE)) { echo format_field(get_opendb_lang_var('email'), $user_r['email_addr']); } echo "\n</table>"; $address_header_displayed = FALSE; $addr_results = fetch_user_address_type_rs($user_r['user_id'], TRUE); if ($addr_results) { while ($address_type_r = db_fetch_assoc($addr_results)) { if (is_user_address_visible($HTTP_VARS, $address_type_r)) { $attr_results = fetch_address_type_attribute_type_rs($address_type_r['s_address_type'], 'query', TRUE); if ($attr_results) { echo '<h3>' . $address_type_r['description'] . '</h3>'; echo "<table>"; while ($addr_attribute_type_r = db_fetch_assoc($attr_results)) { $value = NULL; if (is_lookup_attribute_type($addr_attribute_type_r['s_attribute_type'])) { $value = fetch_user_address_lookup_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']); } else { $value = fetch_user_address_attribute_val($address_type_r['sequence_number'], $addr_attribute_type_r['s_attribute_type'], $addr_attribute_type_r['order_no']); } if (strlen($value) > 0) { echo get_item_display_field(NULL, $addr_attribute_type_r, $value); } } db_free_result($attr_results); echo "\n</table>"; } } } db_free_result($addr_results); }
/** * NOTE: PRIVATE FUNCTION. Will return the FROM and WHERE clauses for a selection from the item table. If $owner_id defined, will limit to only items owned by owner_id If $s_item_type defined, will limit to only items of that type. If $category defined, will limit to only items of that category. If $letter defined will limit to item.title starting with that letter. If $interest_level defined will limit to items with that interest level or higher. @param $HTTP_VARS['...'] variables supported: owner_id, s_item_type, s_item_type[], s_item_type_group, title, title_match, category, rating, attribute_type, lookup_attribute_val, attribute_val, attr_match, update_on, datetimemask, update_on_days, letter, start_item_id s_status_type[], status_comment, not_s_status_type[], interest_level */ function from_and_where_clause($HTTP_VARS, $column_display_config_rs = NULL, $query_type = 'LISTING') { // For checking whether count (DISTINCT ...) is supported, and thus // whether we have to do any special processing! $from_r[] = 'item i'; $from_r[] = 'item_instance ii'; $where_r[] = 'ii.item_id = i.id'; // only parent items should ever be listed. // // Owner restriction // if (strlen($HTTP_VARS['owner_id']) > 0) { $where_r[] = 'ii.owner_id = \'' . $HTTP_VARS['owner_id'] . '\''; } else { if (strlen($HTTP_VARS['not_owner_id']) > 0) { //For not showing current user items. $where_r[] = 'ii.owner_id <> \'' . $HTTP_VARS['not_owner_id'] . '\''; } } // // Item Type / Item Type group restriction // if (!is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) > 0) { $where_r[] = 'i.s_item_type = \'' . $HTTP_VARS['s_item_type'] . '\''; } else { if (strlen($HTTP_VARS['s_item_type_group']) > 0) { $from_r[] = 's_item_type_group_rltshp sitgr'; $where_r[] = 'sitgr.s_item_type = i.s_item_type'; $where_r[] = 'sitgr.s_item_type_group = \'' . $HTTP_VARS['s_item_type_group'] . '\''; } else { if (is_not_empty_array($HTTP_VARS['s_item_type'])) { $where_r[] = 'i.s_item_type IN(' . format_sql_in_clause($HTTP_VARS['s_item_type']) . ')'; } } } $from_r[] = 's_status_type sst'; $where_r[] = 'sst.s_status_type = ii.s_status_type'; // // Status Type restriction // if (is_not_empty_array($HTTP_VARS['s_status_type'])) { $where_r[] = 'sst.s_status_type IN(' . format_sql_in_clause($HTTP_VARS['s_status_type']) . ')'; } else { if ($HTTP_VARS['s_status_type'] != 'ALL' && strlen($HTTP_VARS['s_status_type']) > 0) { $where_r[] = 'sst.s_status_type = \'' . $HTTP_VARS['s_status_type'] . '\''; } } // no need for such a restriction if current user is item admin if (!is_user_granted_permission(PERM_ITEM_ADMIN)) { $where_r[] = "( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var('user_id') . "') "; } // // User and Status type restriction // if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) !== 0) { // not current user $from_r[] = 'user u'; $where_r[] = 'u.user_id = ii.owner_id'; $where_r[] = 'u.active_ind = \'Y\''; } // // Status Comment restriction // if (strlen($HTTP_VARS['status_comment']) > 0) { // Escape only the single quote! $HTTP_VARS['status_comment'] = str_replace("'", "\\'", $HTTP_VARS['status_comment']); if ($HTTP_VARS['status_comment_match'] != 'exact') { $parser = new BooleanParser(); $statements = $parser->parseBooleanStatement($HTTP_VARS['status_comment']); if (is_array($statements)) { $where_r[] = build_boolean_clause($statements, 'ii.status_comment', $HTTP_VARS['status_comment_match'], 'AND', $HTTP_VARS['status_comment_case']); } } else { if (is_null($HTTP_VARS['status_comment_case'])) { $where_r[] = 'ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\''; } else { $where_r[] = 'BINARY ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\''; } } } // // Title restriction // if (strlen($HTTP_VARS['title']) > 0) { // Escape only the single quote! $HTTP_VARS['title'] = str_replace("'", "\\'", $HTTP_VARS['title']); if ($HTTP_VARS['title_match'] != 'exact') { $parser = new BooleanParser(); $statements = $parser->parseBooleanStatement($HTTP_VARS['title']); if (is_array($statements)) { $where_r[] = build_boolean_clause($statements, 'i.title', $HTTP_VARS['title_match'], 'AND', $HTTP_VARS['title_case']); } } else { if (is_null($HTTP_VARS['title_case'])) { $where_r[] = 'i.title = \'' . $HTTP_VARS['title'] . '\''; } else { $where_r[] = 'BINARY i.title = \'' . $HTTP_VARS['title'] . '\''; } } } else { if (strlen($HTTP_VARS['letter']) > 0) { // Numeric match. if ($HTTP_VARS['letter'] == '#') { $where_r[] = 'ASCII(LEFT(title,1)) BETWEEN ASCII(\'0\') AND ASCII(\'9\')'; } else { $where_r[] = 'UPPER(LEFT(i.title,1)) = \'' . strtoupper($HTTP_VARS['letter']) . '\''; } } } // // Last Updated support // if (strlen($HTTP_VARS['update_on']) > 0) { if (strlen($HTTP_VARS['datetimemask']) > 0) { $timestamp = get_timestamp_for_datetime($HTTP_VARS['update_on'], $HTTP_VARS['datetimemask']); if ($timestamp !== FALSE) { $where_r[] = 'ii.update_on >= FROM_UNIXTIME(' . $timestamp . ')'; } else { // by default get items from 1 day ago, if update_on can not be parsed correctly. $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-1)'; } } else { $where_r[] = 'ii.update_on >= \'' . $HTTP_VARS['update_on'] . '\''; } } else { if (is_numeric($HTTP_VARS['update_on_days'])) { // GIve us all records updated in the last however many days. $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['update_on_days'] . ')'; } } // // Item Attribute listing/restriction // if (is_array($column_display_config_rs)) { for ($i = 0; $i < count($column_display_config_rs); $i++) { if ($column_display_config_rs[$i]['column_type'] == 's_attribute_type') { if ($column_display_config_rs[$i]['search_attribute_ind'] != 'y') { // either LISTING or COUNT if ($query_type != 'COUNT') { $left_join = 'LEFT JOIN item_attribute ia' . $i . ' ON ' . 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\' AND ia' . $i . '.attribute_no = 1'; // So we can work out which search attribute types to display if (is_numeric($column_display_config_rs[$i]['order_no'])) { $left_join .= ' AND ia' . $i . '.order_no = ' . $column_display_config_rs[$i]['order_no']; } $left_join_from_r[] = $left_join; } } else { // search attribute $from_r[] = 'item_attribute ia' . $i; // now do the where clause. $where_r[] = 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\''; // AND ia'.$i.'.attribute_no = 1'; if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%' && $column_display_config_rs[$i]['attr_match'] != 'exact') { $parser = new BooleanParser(); $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val']))); if (is_array($statements)) { if ($column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') { $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']); } else { $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.attribute_val', $column_display_config_rs[$i]['attr_match'], 'AND', $HTTP_VARS['attr_case']); } } } else { if (strlen($column_display_config_rs[$i]['lookup_attribute_val']) > 0 && $column_display_config_rs[$i]['lookup_attribute_val'] != '%' && $column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') { $value = str_replace("'", "\\'", $column_display_config_rs[$i]['lookup_attribute_val']); $where_r[] = 'ia' . $i . '.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\''; } else { if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%') { if (starts_with($column_display_config_rs[$i]['attribute_val'], '"') && ends_with($column_display_config_rs[$i]['attribute_val'], '"')) { $column_display_config_rs[$i]['attribute_val'] = substr($column_display_config_rs[$i]['attribute_val'], 1, -1); } $value = strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val'])); $where_r[] = 'UPPER(ia' . $i . '.attribute_val) = \'' . str_replace('\\_', '_', $value) . '\''; } } } if (strlen($HTTP_VARS['attr_update_on']) > 0) { if (strlen($HTTP_VARS['datetimemask']) > 0) { $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']); if ($timestamp !== FALSE) { $where_r[] = 'ia' . $i . '.update_on >= FROM_UNIXTIME(' . $timestamp . ')'; } else { // by default get items from 1 day ago, if update_on can not be parsed correctly. $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-1)'; } } else { $where_r[] = 'ia' . $i . '.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\''; } } else { if (is_numeric($HTTP_VARS['attr_update_on_days'])) { // GIve us all records updated in the last however many days. $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')'; } } } } else { if ($column_display_config_rs[$i]['column_type'] == 's_field_type') { if ($column_display_config_rs[$i]['s_field_type'] == 'CATEGORY') { $from_r[] = 's_item_attribute_type catsiat'; $from_r[] = 's_attribute_type catsat'; $where_r[] = 'catsiat.s_item_type = i.s_item_type AND catsat.s_attribute_type = catsiat.s_attribute_type AND catsat.s_field_type = \'CATEGORY\''; $left_join_clause = 'LEFT JOIN item_attribute catia ON ' . 'catia.item_id = i.id AND (catia.instance_no = 0 OR catia.instance_no = ii.instance_no) AND catia.s_attribute_type = catsiat.s_attribute_type AND catia.order_no = catsiat.order_no'; if (strlen($HTTP_VARS['category']) > 0 || strcasecmp($HTTP_VARS['attr_match'], 'category') === 0 && strlen($HTTP_VARS['attribute_val']) > 0) { // Support specifying $attribute_val for $category where $attr_match=="category"! // If item_type && item_type_group are not set! if (strlen($HTTP_VARS['attribute_type']) > 0 && !is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) == 0 && strlen($HTTP_VARS['s_item_type_group']) == 0) { $where_r[] = 'catsat.s_attribute_type = \'' . $HTTP_VARS['attribute_type'] . '\''; } // Escape single quotes only. $value = strtoupper(str_replace("'", "\\'", ifempty($HTTP_VARS['category'], $HTTP_VARS['attribute_val']))); $where_r[] = 'UPPER(catia.lookup_attribute_val) = \'' . str_replace('\\_', '_', $value) . '\''; } else { $left_join_clause .= ' AND catia.attribute_no = 1'; } $left_join_from_r[] = $left_join_clause; } else { if ($column_display_config_rs[$i]['s_field_type'] == 'INTEREST') { // can only restrict interest level if its displayed as a column if (strlen($HTTP_VARS['interest_level']) > 0) { $where_r[] = "it.item_id = ii.item_id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'" . " AND it.level >= " . $HTTP_VARS['interest_level']; $from_r[] = "user_item_interest it"; } else { $left_join_from_r[] = "LEFT JOIN user_item_interest it ON it.item_id = i.id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'"; } } } } } } } // If attribute_val specified without a attribute_type, then do a loose join to item_attribute table, // only on attribute_val column. if (strlen($HTTP_VARS['attribute_type']) == 0 && (strlen($HTTP_VARS['attribute_val']) > 0 || strlen($HTTP_VARS['attr_update_on']) > 0 || strlen($HTTP_VARS['attr_update_on_days']) > 0)) { $from_r[] = 'item_attribute ia'; // now do the where clause. $where_r[] = 'ia.item_id = i.id '; //AND ia.attribute_no = 1'; if ($HTTP_VARS['attr_match'] != 'exact') { $parser = new BooleanParser(); $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $HTTP_VARS['attribute_val']))); if (is_array($statements)) { if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) { $where_r[] = build_boolean_clause($statements, 'ia.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']); } else { $where_r[] = build_boolean_clause($statements, 'ia.attribute_val', $HTTP_VARS['attr_match'], 'AND', $HTTP_VARS['attr_case']); } } } else { // attr_match = 'exact' if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) { $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']); $where_r[] = 'ia.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\''; } else { $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']); if (is_null($HTTP_VARS['attr_case'])) { $where_r[] = '( ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . '\')'; } else { $where_r[] = '( BINARY ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . '\')'; } } } if (strlen($HTTP_VARS['attr_update_on']) > 0) { if (strlen($HTTP_VARS['datetimemask']) > 0) { $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']); if ($timestamp !== FALSE) { $where_r[] = 'ia.update_on >= FROM_UNIXTIME(' . $timestamp . ')'; } else { // by default get items from 1 day ago, if update_on can not be parsed correctly. $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-1)'; } } else { $where_r[] = 'ia.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\''; } } else { if (is_numeric($HTTP_VARS['attr_update_on_days'])) { // GIve us all records updated in the last however many days. $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')'; } } } // // Review restrictions // if (strlen($HTTP_VARS['rating']) > 0) { $where_r[] = 'r.item_id = i.id AND r.rating >= ' . $HTTP_VARS['rating']; $from_r[] = 'review r'; } // // Item ID range restriction (Used by Import script) // if (strlen($HTTP_VARS['item_id_range']) > 0) { $where_r[] = 'i.id IN (' . expand_number_range($HTTP_VARS['item_id_range']) . ')'; } // // Now build the SQL query // if (is_array($from_r)) { $from_clause = ''; for ($i = 0; $i < count($from_r); $i++) { if (strlen($from_clause) > 0) { $from_clause .= ', '; } $from_clause .= $from_r[$i]; } $query .= 'FROM (' . $from_clause . ') '; } if (is_array($left_join_from_r)) { $left_join_from_clause = ''; for ($i = 0; $i < count($left_join_from_r); $i++) { if (strlen($left_join_from_clause) > 0) { $left_join_from_clause .= ' '; } $left_join_from_clause .= $left_join_from_r[$i]; } $query .= $left_join_from_clause . ' '; } if (is_array($where_r)) { $where_clause = ''; for ($i = 0; $i < count($where_r); $i++) { if (strlen($where_clause) > 0) { $where_clause .= ' AND '; } $where_clause .= $where_r[$i]; } $query .= 'WHERE ' . $where_clause; } return $query; }
function get_search_query_matrix($HTTP_VARS) { function get_match_type($match) { if ($match == 'word') { return get_opendb_lang_var('word_match'); } else { if ($match == 'partial') { return get_opendb_lang_var('partial_match'); } else { if ($match == 'exact') { return get_opendb_lang_var('exact_match'); } else { return NULL; } } } } $searches = array(); if (strlen($HTTP_VARS['title']) > 0) { // Default title match is exact match. $HTTP_VARS['title_match'] = ifempty($HTTP_VARS['title_match'], 'exact'); if ($HTTP_VARS['title_match'] == 'word' || $HTTP_VARS['title_match'] == 'partial') { if (is_null($HTTP_VARS['title_case'])) { $searches[] = array(prompt => get_opendb_lang_var('title') . ' (<em>' . get_match_type($HTTP_VARS['title_match']) . '</em>)', field => $HTTP_VARS['title']); } else { $searches[] = array(prompt => get_opendb_lang_var('title') . ' (<em>' . get_match_type($HTTP_VARS['title_match']) . ', ' . get_opendb_lang_var('case_sensitive') . '</em>)', field => $HTTP_VARS['title']); } } else { $searches[] = array(prompt => get_opendb_lang_var('title'), field => $HTTP_VARS['title']); } } if (strlen($HTTP_VARS['category']) > 0) { // If s_item_type defined, we can get at the s_attribute_type of the category value. if (strlen($HTTP_VARS['s_item_type']) > 0) { $attribute_type_r = fetch_sfieldtype_item_attribute_type_r($HTTP_VARS['s_item_type'], 'CATEGORY'); $searches[] = array(prompt => get_opendb_lang_var('category'), field => get_item_display_field(NULL, $attribute_type_r, $HTTP_VARS['category'], FALSE)); } else { $searches[] = array(prompt => get_opendb_lang_var('category'), field => $HTTP_VARS['category']); } } if (strlen($HTTP_VARS['owner_id']) > 0) { $username = fetch_user_name($HTTP_VARS['owner_id']); if (strlen($username) > 0) { $searches[] = array(prompt => get_opendb_lang_var('owner'), field => $username . ' (' . $HTTP_VARS['owner_id'] . ')'); } } if (strlen($HTTP_VARS['s_item_type_group']) > 0) { $searches[] = array(prompt => get_opendb_lang_var('s_item_type_group'), field => $HTTP_VARS['s_item_type_group']); } if (is_array($HTTP_VARS['s_item_type'])) { $field = ''; for ($i = 0; $i < count($HTTP_VARS['s_item_type']); $i++) { $item_type_r = fetch_item_type_r($HTTP_VARS['s_item_type'][$i]); $field .= theme_image($item_type_r['image'], $item_type_r['description'], 's_item_type'); } $searches[] = array(prompt => get_opendb_lang_var('s_item_type'), field => $field); } else { if (strlen($HTTP_VARS['s_item_type']) > 0) { $item_type_r = fetch_item_type_r($HTTP_VARS['s_item_type']); $searches[] = array(prompt => get_opendb_lang_var('s_item_type'), field => theme_image($item_type_r['image'], $item_type_r['description'], 's_item_type')); } } if (is_numeric($HTTP_VARS['rating'])) { $attribute_type_r = fetch_cached_attribute_type_r('S_RATING'); $searches[] = array(prompt => $attribute_type_r['prompt'], field => get_display_field($attribute_type_r['s_attribute_type'], NULL, 'review()', $HTTP_VARS['rating'], FALSE)); } $attribute_type_r = NULL; if (strlen($HTTP_VARS['attribute_type']) > 0) { $attribute_type_r = fetch_cached_attribute_type_r($HTTP_VARS['attribute_type']); if (is_not_empty_array($attribute_type_r)) { $attribute_type_r['listing_link_ind'] = 'N'; // Default title match is exact match. $HTTP_VARS['attr_match'] = ifempty($HTTP_VARS['attr_match'], 'exact'); // Special category search, but ignore if category variable actually specified. if (strlen($HTTP_VARS['category']) == 0 && strlen($HTTP_VARS['attribute_val']) > 0 && $HTTP_VARS['attr_match'] == 'category') { // We do not want the Listing Link to be added to this display field $searches[] = array(prompt => $attribute_type_r['prompt'], field => get_item_display_field(NULL, $attribute_type_r, stripslashes($HTTP_VARS['attribute_val']), FALSE)); } else { if (strlen($HTTP_VARS['attribute_val']) > 0) { $HTTP_VARS['attribute_val'] = stripslashes($HTTP_VARS['attribute_val']); if (starts_with($HTTP_VARS['attribute_val'], '"') && ends_with($HTTP_VARS['attribute_val'], '"')) { $HTTP_VARS['attribute_val'] = substr($HTTP_VARS['attribute_val'], 1, -1); } $search = ifempty(get_item_display_field(NULL, $attribute_type_r, $HTTP_VARS['attribute_val'], FALSE), $HTTP_VARS['attribute_val']); } else { if (strlen($HTTP_VARS['lookup_attribute_val']) > 0) { $search = get_item_display_field(NULL, $attribute_type_r, stripslashes($HTTP_VARS['lookup_attribute_val']), FALSE); } } if (!is_lookup_attribute_type($HTTP_VARS['attribute_type']) && $HTTP_VARS['attr_match'] != 'exact') { $searches[] = array(prompt => $attribute_type_r['prompt'] . ' (<em>' . get_match_type($HTTP_VARS['attr_match']) . '</em>)', field => $search); } else { $searches[] = array(prompt => $attribute_type_r['prompt'], field => $search); } } } //if(is_not_empty_array($attribute_type_r)) } else { if (strlen($HTTP_VARS['attribute_val']) > 0) { // specified a search term without attribute type, this is a global search. if (is_null($HTTP_VARS['attr_case'])) { $searches[] = array(prompt => get_opendb_lang_var('attribute_val') . ' (<em>' . get_match_type(ifempty($HTTP_VARS['attr_match'], 'exact')) . '</em>)', field => stripslashes($HTTP_VARS['attribute_val'])); } else { $searches[] = array(prompt => get_opendb_lang_var('attribute_val') . ' (<em>' . get_match_type(ifempty($HTTP_VARS['attr_match'], 'exact')) . ', ' . get_opendb_lang_var('case_sensitive') . '</em>)', field => stripslashes($HTTP_VARS['attribute_val'])); } } } // add another search field if update_on value also specified. if (strlen($HTTP_VARS['attr_update_on']) > 0) { if (is_not_empty_array($attribute_type_r)) { $prompt = get_opendb_lang_var('attribute_prompt_updated', array('s_attribute_type' => $attribute_type_r['s_attribute_type'], 'prompt' => $attribute_type_r['prompt'])); } else { $prompt = get_opendb_lang_var('attributes_updated'); } if (strlen($HTTP_VARS['datetimemask']) > 0) { $searches[] = array(prompt => $prompt, field => $HTTP_VARS['attr_update_on'] . ' (' . $HTTP_VARS['datetimemask'] . ')'); } else { $searches[] = array(prompt => $prompt, field => $HTTP_VARS['attr_update_on']); } } else { if (is_numeric($HTTP_VARS['attr_update_on_days'])) { if (is_not_empty_array($attribute_type_r)) { $prompt = get_opendb_lang_var('attribute_prompt_updated', array('s_attribute_type' => $attribute_type_r['s_attribute_type'], 'prompt' => $attribute_type_r['prompt'])); } else { $prompt = get_opendb_lang_var('attributes_updated'); } if ($HTTP_VARS['attr_update_on_days'] == '1') { $field = get_opendb_lang_var('one_day_ago'); } else { if ($HTTP_VARS['attr_update_on_days'] == '7') { $field = get_opendb_lang_var('one_week_ago'); } else { if ($HTTP_VARS['attr_update_on_days'] == '28') { $field = get_opendb_lang_var('one_month_ago'); } else { if ($HTTP_VARS['attr_update_on_days'] == '365') { $field = get_opendb_lang_var('one_year_ago'); } } } } $searches[] = array(prompt => $prompt, field => $field); } } if (strlen($HTTP_VARS['update_on']) > 0) { if (strlen($HTTP_VARS['datetimemask']) > 0) { $searches[] = array(prompt => get_opendb_lang_var('updated'), field => $HTTP_VARS['update_on'] . ' (' . $HTTP_VARS['datetimemask'] . ')'); } else { $searches[] = array(prompt => get_opendb_lang_var('updated'), field => $HTTP_VARS['update_on']); } } else { if (is_numeric($HTTP_VARS['update_on_days'])) { if ($HTTP_VARS['update_on_days'] == '1') { $field = get_opendb_lang_var('one_day_ago'); } else { if ($HTTP_VARS['update_on_days'] == '7') { $field = get_opendb_lang_var('one_week_ago'); } else { if ($HTTP_VARS['update_on_days'] == '28') { $field = get_opendb_lang_var('one_month_ago'); } else { if ($HTTP_VARS['update_on_days'] == '365') { $field = get_opendb_lang_var('one_year_ago'); } } } } $searches[] = array(prompt => get_opendb_lang_var('updated'), field => $field); } } if (is_not_empty_array($HTTP_VARS['s_status_type']) > 0) { $search = ''; for ($i = 0; $i < count($HTTP_VARS['s_status_type']); $i++) { if (strlen($search) > 0) { $search .= ' '; } $status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type'][$i]); if (is_not_empty_array($status_type_r)) { $search .= format_display_value('%img%', $status_type_r['img'], 'Y', $status_type_r['description'], 's_status_type'); } } if (strlen($search) > 0) { $searches[] = array(prompt => get_opendb_lang_var('s_status_type'), field => $search); } } if (strlen($HTTP_VARS['status_comment']) > 0) { // Default status_comment match is exact match. $HTTP_VARS['status_comment_match'] = ifempty($HTTP_VARS['status_comment_match'], 'exact'); if ($HTTP_VARS['status_comment_match'] == 'word' || $HTTP_VARS['status_comment_match'] == 'partial' || $HTTP_VARS['status_comment_match'] == 'exact') { if (is_null($HTTP_VARS['status_comment_case'])) { $searches[] = array(prompt => get_opendb_lang_var('status_comment') . ' (<em>' . get_match_type($HTTP_VARS['status_comment_match']) . '</em>)', field => $HTTP_VARS['status_comment']); } else { $searches[] = array(prompt => get_opendb_lang_var('status_comment') . ' (<em>' . get_match_type($HTTP_VARS['status_comment_match']) . ', ' . get_opendb_lang_var('case_sensitive') . '</em>)', field => $HTTP_VARS['status_comment']); } } else { $searches[] = array(prompt => get_opendb_lang_var('status_comment'), field => $HTTP_VARS['status_comment']); } } if (is_numeric($HTTP_VARS['interest_level']) && $HTTP_VARS['interest_level'] > 0) { $searches[] = array(prompt => get_opendb_lang_var('interest'), field => theme_image("interest_1.gif", get_opendb_lang_var('interest'), 's_item_type')); } return $searches; }
/** * The $site_plugin_attributes_r will consist of array entries, each identified by a * alphakey. The value may in fact be another array and this has to be handled * appropriately. */ function get_expanded_and_mapped_site_plugin_item_variables_r($site_type, $s_item_type, $site_item_attributes_r) { $query = "SELECT variable, s_attribute_type, lookup_attribute_val_restrict_ind " . "FROM s_site_plugin_s_attribute_type_map " . "WHERE site_type = '" . $site_type . "' "; $query .= "AND (s_item_type = '*' OR s_item_type = '" . $s_item_type . "') AND "; $query .= "(s_item_type_group = '*' "; $item_type_group_arr = fetch_item_type_groups_for_item_type_r($s_item_type); if (is_array($item_type_group_arr)) { $query .= "OR s_item_type_group IN (" . format_sql_in_clause($item_type_group_arr) . ")) "; } else { $query .= ") "; } $query .= "ORDER BY variable, s_attribute_type"; $new_attributes_r = array(); // cache this, so we can check if lookup_attribute_val_restrict_ind = 'Y' $lookup_attribute_val_restrict_ind = array(); $mapped_attributes_r = array(); $results = db_query($query); if ($results && db_num_rows($results) > 0) { $variable = NULL; while ($attribute_type_map_r = db_fetch_assoc($results)) { $value = NULL; $variable = $attribute_type_map_r['variable']; if (isset($site_item_attributes_r[$variable])) { $value = $site_item_attributes_r[$variable]; // at least one direct mapping - title should not be flagged - as there is requirement for multiple mappings if ($variable != 'title') { $mapped_attributes_r[] = $variable; } } $key = strtolower($attribute_type_map_r['s_attribute_type']); if ($value !== NULL) { if (isset($new_attributes_r[$key])) { if (!is_array($new_attributes_r[$key])) { $new_attributes_r[$key] = array($new_attributes_r[$key]); } if (is_array($value)) { $new_attributes_r[$key] = array_merge($new_attributes_r[$key], $value); } else { $new_attributes_r[$key][] = $value; } } else { $new_attributes_r[$key] = $value; } } if ($attribute_type_map_r['lookup_attribute_val_restrict_ind'] == 'Y') { $lookup_attribute_val_restrict_ind_r[$key] = 'Y'; } } db_free_result($results); } // now for any variables that do not have a mapping, add them to the $new_attributes_r reset($site_item_attributes_r); while (list($key, $value) = @each($site_item_attributes_r)) { $key = strtolower($key); if (isset($new_attributes_r[$key])) { $oldValue = NULL; // we want the direct mapping attributes first. if (is_array($new_attributes_r[$key])) { $oldValue = $new_attributes_r[$key]; } else { $oldValue[] = $new_attributes_r[$key]; } unset($new_attributes_r[$key]); if (is_array($value)) { $new_attributes_r[$key] = $value; } else { $new_attributes_r[$key][] = $value; } while (list(, $value) = each($oldValue)) { if (!in_array($value, $new_attributes_r[$key])) { $new_attributes_r[$key][] = $value; } } } else { if (!in_array($key, $mapped_attributes_r)) { $new_attributes_r[$key] = $value; } } } $site_item_attributes_r = NULL; // now we need to check to see if any lookup mappings exist for each // of the attribute values, and update the $value's appropriately. reset($new_attributes_r); while (list($key, $value) = @each($new_attributes_r)) { // temporary UPPER so we can work with actual s_attribute_type records in database $s_attribute_type = strtoupper($key); if (is_lookup_attribute_type($s_attribute_type)) { $values_r = NULL; // if a lookup attribute type, we want to make sure that the $value's // are all arrays anyway, so lets do that check each time. if (is_array($value)) { $values_r = $value; } else { $values_r[] = $value; } $results = fetch_site_plugin_s_attribute_type_lookup_map_rs($site_type, $s_attribute_type); if ($results) { $found_entries_r = array(); $new_values_r = array(); while ($lookup_map_r = db_fetch_assoc($results)) { for ($i = 0; $i < count($values_r); $i++) { if (strcasecmp($values_r[$i], $lookup_map_r['value']) === 0) { $found_entries_r[] = $values_r[$i]; if (!in_array($lookup_map_r['lookup_attribute_val'], $new_values_r)) { $new_values_r[] = $lookup_map_r['lookup_attribute_val']; } } } } db_free_result($results); // now process all back into $values_r for ($i = 0; $i < count($values_r); $i++) { if (!in_array($values_r[$i], $found_entries_r) && !in_array($values_r[$i], $new_values_r)) { $new_values_r[] = $values_r[$i]; } } $values_r = $new_values_r; } //if($results) // now reassign back. $site_item_attributes_r[strtolower($s_attribute_type)] = $values_r; } else { // the next process prefers arrays to deal with, even if single element $site_item_attributes_r[strtolower($s_attribute_type)] = $value; } } // // now that we have expanded mappings, we need to map to s_item_attribute_type order number mappings // $new_attributes_r = $site_item_attributes_r; $site_item_attributes_r = NULL; // now we want to expand the $new_attributes_r, so we have a set of // variables that include the order_no $fieldname type format. $results = fetch_item_attribute_type_rs($s_item_type, NULL, 's_attribute_type'); if ($results) { // this will be set if array encountered, but not lookup value. $processing_s_attribute_type = FALSE; while ($attribute_type_r = db_fetch_assoc($results)) { $variable = strtolower($attribute_type_r['s_attribute_type']); if (isset($new_attributes_r[$variable])) { $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); if (is_not_empty_array($new_attributes_r[$variable])) { // TODO: Consider adding values not found in the lookup table to the s_attribute_type_lookup. if (is_lookup_attribute_type($attribute_type_r['s_attribute_type'])) { $lookup_attribute_val_restrict_ind = $lookup_attribute_val_restrict_ind_r[strtolower($attribute_type_r['s_attribute_type'])]; // here is where we want some sanity checking of the options $value_r = $new_attributes_r[$variable]; $lookup_value_r = array(); for ($i = 0; $i < count($value_r); $i++) { $raw_value = trim($value_r[$i]); if (strlen($raw_value) > 0) { $value = fetch_attribute_type_lookup_value($attribute_type_r['s_attribute_type'], $raw_value); if ($value !== FALSE) { $lookup_value_r[] = $value; } else { if ($lookup_attribute_val_restrict_ind != 'Y') { // do not include if restricted to lookup values $lookup_value_r[] = $raw_value; } } } } $site_item_attributes_r[$fieldname] = array_unique($lookup_value_r); } else { // This indicates we have a repeated s_attribute_type, and so should act appropriately. if ($processing_s_attribute_type != NULL && $attribute_type_r['s_attribute_type'] == $processing_s_attribute_type) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; // remove it array_splice($new_attributes_r[$variable], 0, 1); } else { if (count($new_attributes_r[$variable]) > 1) { // this is the first occurence of the s_attribute_type, so lets see if its repeated at least once. if (is_numeric(fetch_s_item_attribute_type_next_order_no($s_item_type, $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']))) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; // remove it array_splice($new_attributes_r[$variable], 0, 1); $processing_s_attribute_type = $attribute_type_r['s_attribute_type']; } else { // otherwise just copy the whole thing. $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable]; unset($new_attributes_r[$variable]); } } else { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0]; unset($new_attributes_r[$variable]); } } } } else { if (!is_array($new_attributes_r[$variable])) { $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable]; unset($new_attributes_r[$variable]); } } } else { if ($attribute_type_r['s_field_type'] == 'TITLE' && isset($new_attributes_r['title'])) { // in case developer forgot to setup title mapping. $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']); $site_item_attributes_r[$fieldname] = $new_attributes_r['title']; } } } //while db_free_result($results); } return $site_item_attributes_r; }
function _insert_or_update_user_address_attributes($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val_r) { if (is_lookup_attribute_type($s_attribute_type)) { $insert_cols = "INSERT INTO user_address_attribute (ua_sequence_number, s_attribute_type, order_no, attribute_no, lookup_attribute_val)"; } else { $insert_cols = "INSERT INTO user_address_attribute (ua_sequence_number, s_attribute_type, order_no, attribute_no, attribute_val)"; } if (db_query("LOCK TABLES user_address_attribute WRITE")) { if (delete_user_address_attributes($ua_sequence_number, $s_attribute_type, $order_no)) { if (!is_array($attribute_val_r)) { $value_r[] = addslashes(trim(strip_tags($attribute_val_r))); } else { $value_r = NULL; for ($i = 0; $i < count($attribute_val_r); $i++) { $value = addslashes(trim(strip_tags($attribute_val_r[$i]))); // lets make sure this $value does not already exist if (is_array($value_r)) { for ($j = 0; $j < count($value_r); $j++) { if ($value_r[$j] == $value) { $value = NULL; break; } } } if ($value != null) { $value_r[] = $value; } } } for ($i = 0; $i < count($value_r); $i++) { $attribute_val = $value_r[$i]; $query = $insert_cols . "VALUES ('{$ua_sequence_number}','{$s_attribute_type}', {$order_no}, " . ($i + 1) . ", '{$attribute_val}')"; $insert = db_query($query); if ($insert && db_affected_rows() > 0) { opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, NULL, array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val)); } else { db_query("UNLOCK TABLES"); opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val)); return FALSE; } } db_query("UNLOCK TABLES"); return TRUE; } else { db_query("UNLOCK TABLES"); return FALSE; } } else { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($ua_sequence_number, $s_attribute_type, $order_no, $attribute_val_r)); return FALSE; } }
/** */ function _insert_or_update_item_attributes($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r = NULL) { $is_lookup_attribute_type = is_lookup_attribute_type($s_attribute_type); $attribute_val_r = validate_attribute_val_r($attribute_val_r, $is_lookup_attribute_type); // if not instance item attribute, then discard the $instance_no if (!is_instance_item_attribute_type($s_item_type, $s_attribute_type)) { $instance_no = NULL; } $is_file_resource_attribute_type = is_file_resource_attribute_type($s_attribute_type); if (db_query("LOCK TABLES item_attribute WRITE, item_attribute AS ia READ, s_attribute_type AS sat READ")) { $item_attribute_type_rs = fetch_arrayof_item_attribute_rs($item_id, $instance_no, $s_attribute_type, $order_no); // if same number of attributes, then we can perform an update only. if (count($item_attribute_type_rs) > 0 && count($item_attribute_type_rs) == count($attribute_val_r)) { $op = 'update'; } else { if (count($item_attribute_type_rs) == 0 || delete_item_attributes($item_id, $instance_no, $s_attribute_type, $order_no)) { $op = 'insert'; } else { // if this occurs then the delete_item_attributes function returned FALSE, and that failure would have been logged. db_query("UNLOCK TABLES"); return FALSE; } } // if there is actually something to insert at this point. if (count($attribute_val_r) > 0) { $file_attributes_r = NULL; for ($i = 0; $i < count($attribute_val_r); $i++) { $attribute_no = $i + 1; if ($is_lookup_attribute_type) { if ($op == 'insert') { insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL); } else { if ($item_attribute_type_rs[$i]['lookup_attribute_val'] != $attribute_val_r[$i]) { update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL); } } } else { if ($is_file_resource_attribute_type) { if (is_array($file_r) && is_uploaded_file($file_r['tmp_name'])) { if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i] && is_exists_upload_file_item_attribute($attribute_val_r[$i])) { $attribute_val_r[$i] = get_unique_filename($attribute_val_r[$i]); } if (!save_uploaded_file($file_r['tmp_name'], $attribute_val_r[$i])) { $attribute_val_r[$i] = NULL; } $file_attributes_rs[] = array('file_attribute_ind' => 'Y', 'attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]); } else { $file_attributes_rs[] = array('attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]); } } if (strlen($attribute_val_r[$i]) > 0) { if ($op == 'insert') { insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]); } else { if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i]) { update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]); } } } } } db_query("UNLOCK TABLES"); if (is_array($file_attributes_rs)) { while (list(, $file_attribute_r) = each($file_attributes_rs)) { file_cache_insert_file($file_attribute_r['attribute_val'], NULL, NULL, NULL, 'ITEM', $file_attribute_r['file_attribute_ind'] == 'Y'); } } } else { db_query("UNLOCK TABLES"); } return TRUE; } else { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r)); return FALSE; } }