} } } } } $HTTP_VARS['op'] = 'edit-lookups'; } } } } if ($HTTP_VARS['op'] == 'new' || $HTTP_VARS['op'] == 'edit') { echo get_javascript("admin/s_attribute_type/widgettooltips.js"); echo get_widget_tooltip_array(); echo "<p>[<a href=\"{$PHP_SELF}?type={$ADMIN_TYPE}&active_tab=" . $HTTP_VARS['active_tab'] . "\">Back to Main</a>]</p>"; if ($HTTP_VARS['op'] == 'edit') { $attribute_type_r = fetch_s_attribute_type_r($HTTP_VARS['s_attribute_type']); if ($attribute_type_r === FALSE) { $errors[] = 'Attribute type (' . $HTTP_VARS['s_attribute_type'] . ') not found'; } echo "\n<h3>Edit Attribute type</h3>"; $save_op = 'update'; $save_button = 'Update'; } else { echo "\n<h3>New Attribute type</h3>"; $save_op = 'insert'; $save_button = 'Insert'; } if (is_not_empty_array($errors)) { echo format_error_block($errors); } echo "\n<form name=\"s_attribute_type\" action=\"{$PHP_SELF}\" method=\"POST\">";
/** * Generate a complete s_item_type script. * * Data generated: * s_item_type * s_attribute_type's (Those not included in $_ATTRIBUTE_TYPES['core']) * s_item_attribute_type's * s_item_attribute_type_lookup (Those not included in $_ATTRIBUTE_TYPES['core']) */ function generate_s_item_type_sql($s_item_type) { global $_CORE_ATTRIBUTE_TYPES; $CRLF = get_user_browser_crlf(); $s_item_type_r = fetch_s_item_type_r($s_item_type); if ($s_item_type_r !== FALSE) { $type_sql = $CRLF . '#' . $CRLF . '# Item Type' . $CRLF . '#' . $CRLF . 'INSERT INTO s_item_type ( s_item_type, description, image ) VALUES ( \'' . $s_item_type . '\', \'' . addslashes($s_item_type_r['description']) . '\', \'' . addslashes($s_item_type_r['image']) . '\' );' . $CRLF; $results = fetch_item_type_group_rlshp_rs(NULL, $s_item_type); if ($results) { $type_sql .= $CRLF . '#' . $CRLF . '# Item Type Group Relationships' . $CRLF . '#' . $CRLF; while ($item_type_group_rlshp_r = db_fetch_assoc($results)) { $type_sql .= 'INSERT INTO s_item_type_group_rltshp ( s_item_type_group, s_item_type ) VALUES ( \'' . $item_type_group_rlshp_r['s_item_type_group'] . '\', \'' . $item_type_group_rlshp_r['s_item_type'] . '\' );' . $CRLF; } db_fetch_assoc($results); } $attr_sql = ''; $item_attr_sql = $CRLF . '#' . $CRLF . '# Item Attribute Relationships' . $CRLF . '#'; $attr_lookup_sql = ''; $result = fetch_s_item_attribute_type_rs($s_item_type); if ($result) { $attr_added = array(); while ($s_item_attribute_type_r = db_fetch_assoc($result)) { // Ensure to also check that the attribute has not already been encountered, in case we have duplicates // in s_item_attribute_type structure (such as CDTRACK for instance) if (strlen($s_item_attribute_type_r['site_type']) == 0 && (!is_array($_CORE_ATTRIBUTE_TYPES) || !in_array($s_item_attribute_type_r['s_attribute_type'], $_CORE_ATTRIBUTE_TYPES)) && !in_array($s_item_attribute_type_r['s_attribute_type'], $attr_added)) { // Add s_attribute_type, so we do not insert it twice. $attr_added[] = $s_item_attribute_type_r['s_attribute_type']; $s_attribute_type_r = fetch_s_attribute_type_r($s_item_attribute_type_r['s_attribute_type']); $attr_sql .= $CRLF . "INSERT INTO s_attribute_type ( s_attribute_type, description, prompt, input_type, input_type_arg1, input_type_arg2, input_type_arg3, input_type_arg4, input_type_arg5, display_type, display_type_arg1, display_type_arg2, display_type_arg3, display_type_arg4, display_type_arg5, listing_link_ind, file_attribute_ind, lookup_attribute_ind, multi_attribute_ind, s_field_type, site_type ) " . "VALUES ( '" . $s_attribute_type_r['s_attribute_type'] . "', " . "'" . addslashes($s_attribute_type_r['description']) . "', " . "'" . addslashes($s_attribute_type_r['prompt']) . "', " . "'" . $s_attribute_type_r['input_type'] . "', " . (strlen($s_attribute_type_r['input_type_arg1']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg1']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg2']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg2']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg3']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg3']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg4']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg4']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['input_type_arg5']) > 0 ? "'" . addslashes($s_attribute_type_r['input_type_arg5']) . "'" : "NULL") . ", " . "'" . $s_attribute_type_r['display_type'] . "'," . (strlen($s_attribute_type_r['display_type_arg1']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg1']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg2']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg2']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg3']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg3']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg4']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg4']) . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['display_type_arg5']) > 0 ? "'" . addslashes($s_attribute_type_r['display_type_arg5']) . "'" : "NULL") . ", " . "'" . $s_attribute_type_r['listing_link_ind'] . "', " . "'" . $s_attribute_type_r['file_attribute_ind'] . "', " . "'" . $s_attribute_type_r['lookup_attribute_ind'] . "', " . "'" . $s_attribute_type_r['multi_attribute_ind'] . "', " . (strlen($s_attribute_type_r['s_field_type']) > 0 ? "'" . $s_attribute_type_r['s_field_type'] . "'" : "NULL") . ", " . (strlen($s_attribute_type_r['site_type']) > 0 ? "'" . $s_attribute_type_r['s_field_type'] . "'" : "NULL") . ");"; $result2 = fetch_attribute_type_lookup_rs($s_item_attribute_type_r['s_attribute_type'], 'value ASC', FALSE); if ($result2) { $attr_lookup_sql .= $CRLF . '#' . $CRLF . '# Attribute Type Lookup (' . $s_item_attribute_type_r['s_attribute_type'] . ')' . $CRLF . '#'; while ($s_attribute_type_lookup_r = db_fetch_assoc($result2)) { $attr_lookup_sql .= $CRLF . 'INSERT INTO s_attribute_type_lookup ( s_attribute_type, order_no, value, display, img, checked_ind ) VALUES ( \'' . $s_item_attribute_type_r['s_attribute_type'] . '\', ' . (is_numeric($s_attribute_type_lookup_r['order_no']) ? $s_attribute_type_lookup_r['order_no'] : 'NULL') . ', \'' . addslashes($s_attribute_type_lookup_r['value']) . '\', \'' . addslashes($s_attribute_type_lookup_r['display']) . '\', \'' . addslashes($s_attribute_type_lookup_r['img']) . '\', \'' . $s_attribute_type_lookup_r['checked_ind'] . '\' );'; } db_fetch_assoc($result2); $attr_lookup_sql .= $CRLF; } } $item_attr_sql .= $CRLF . 'INSERT INTO s_item_attribute_type ( s_item_type, s_attribute_type, order_no, prompt, instance_attribute_ind, compulsory_ind, printable_ind, rss_ind ) VALUES ( \'' . $s_item_type . '\', \'' . $s_item_attribute_type_r['s_attribute_type'] . '\', ' . $s_item_attribute_type_r['order_no'] . ', ' . (strlen($s_item_attribute_type_r['prompt']) > 0 ? '\'' . $s_item_attribute_type_r['prompt'] . '\'' : 'NULL') . ', \'' . $s_item_attribute_type_r['instance_attribute_ind'] . '\', \'' . $s_item_attribute_type_r['compulsory_ind'] . '\', \'' . $s_item_attribute_type_r['printable_ind'] . '\', \'' . $s_item_attribute_type_r['rss_ind'] . '\' );'; } db_fetch_assoc($result); } if (strlen($attr_sql) > 0) { $attr_sql = $CRLF . '#' . $CRLF . '# Attributes (non-core)' . $CRLF . '#' . $attr_sql; } $sqlscript = '#########################################################' . $CRLF . '# OpenDb ' . get_opendb_version() . ' \'' . $s_item_type . '\' Item Type' . $CRLF . '#########################################################' . $CRLF . $type_sql . $attr_sql . $CRLF . $item_attr_sql . $CRLF . $attr_lookup_sql; return $sqlscript; } else { return NULL; } }