[interchange-cvs] interchange - heins modified 5 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Wed Feb 12 09:42:00 2003


User:      heins
Date:      2003-02-12 14:41:57 GMT
Added:     dist/lib/UI/pages/include/Options Matrix Simple
Added:     dist/lib/UI/pages/include/Options/old item_option_matrix
Added:              item_option_modular item_option_simple
Log:
* Put in admin pages for options.

Revision  Changes    Path
1.1                  interchange/dist/lib/UI/pages/include/Options/Matrix


rev 1.1, prev_rev 1.0
Index: Matrix
===================================================================
[perl]
	my $loc = $Config->{Options_repository}{Matrix} || {};
	$CGI->{mv_data_table} = $loc->{table} || 'options';
	$CGI->{mv_variant_table} = $loc->{variant_table} || 'variants';
	return;
[/perl]

<div class=titlebox>
[tmp o_display_type][data table="[cgi mv_data_table]" col=display_type key="[cgi item_id]"][/tmp]
Display type:
	[either][scratch o_display_type][or]default[/either]
	&nbsp;
	&nbsp;
	&nbsp;
	[page 
		href="admin/flex_editor"
		form="
			mv_data_table=[cgi mv_data_table]
			item_id=[cgi mv_item_id]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=item_id=[cgi item_id]
			ui_te_widget:display_type=select
			ui_te_widget:code=hidden_text
			ui_te_label:display_type=Display type
			ui_te_options:display_type=one=One widget,separate=Separate widgets
			ui_te_default:display_type=[scratch o_display_type]
			ui_te_override:code=[cgi item_id]
			page_title=Change Matrix display type for [cgi item_id]
			page_banner=Change Matrix display type for [cgi item_id]
			ui_data_fields=code display_type
			ui_meta_view=matrix_display
		"
		]Change</A>
</div>

[if cgi ui_clone_options]
[and cgi ui_clone_id]
[perl tables="[cgi mv_data_table]"]
	my $db = $Db{$CGI->{mv_data_table}}
		or return;
	my ($k,$v);
	$db->clone_row($CGI->{ui_clone_id}, $CGI->{sku});
	$db->clone_set('sku', $CGI->{ui_clone_id}, $CGI->{sku});
	return;
[/perl]
[/if]
<!--
				fi=[cgi mv_data_table]
				st=db
				co=yes

				se=[cgi item_id]
				sf=sku
				op=eq
				ac=0

				sf=o_matrix
				se=1
				op=ne
				ac=0

				sf=o_master
				se=.
				op=rn
				ac=0

				rf=*

-->
[if cgi explode]
[tmp all_opts][loop
	search="
					fi=[cgi mv_data_table]
					st=db
					co=yes

					se=[cgi item_id]
					sf=sku
					op=eq
					ac=0

					tf=o_sort
					tf=o_group

					rf=o_group,o_value,price
		"][loop-param o_group]	[loop-param o_value]	[loop-param price]
[/loop][/tmp]

[tmp tmp_price][price noformat=1 code="[cgi item_id]"][/tmp]
[tmp tmp_whole][field field=wholesale code="[cgi item_id]"][/tmp]
[tmp tmp_desc][description code="[cgi item_id]"][/tmp]
[perl tables="[cgi mv_data_table] [cgi mv_variant_table] __UI_ITEM_TABLES__"]
#Debug("opts: $Scratch->{all_opts}");
	my $vtab = $CGI->{mv_variant_table};
	my $vdb = $Db{$vtab};
	unless ($vdb) {
		Log("can't open option table '%s'.", $vtab);
		return undef;
	}
	my $id = $CGI->{item_id};
	my %default = (
		wholesale	=> $Scratch->{tmp_whole},
	);
#Debug("opts: $Scratch->{all_opts}");
	my @opts = grep /\S/, split /\n/, $Scratch->{all_opts};
#Debug( "options raw: " . $Tag->uneval( { ref => \@opts } ) );
	return unless @opts;

	my @dimensions;
	for(@opts) {
		my($g, $o, $p) = split /\t/, $_;
		push @optnames, $g;
		my @ary;
		my (@o) = grep /\S/, split /\s*,\s*/, $o;
		my (@p) = grep /\S/, split /\s*,\s*/, $p;
		my %p;
		for(@p) {
			my ($k, $v) = split /\s*=\s*/, $_;
			next unless $k;
			if($v =~ s/\s*%\s*$//) {
				next unless $v;
				$p{$k} = ($v / 100) * $Scratch->{tmp_price};
			}
			else {
				$p{$k} = $v;
			}
			$p{$k} = $v;
		}
		
		for(@o) {
			my ($k, $v) = split /\s*=\s*/, $_;
			$k = '__MV_VARIANT_JOINER__' || '0' if ! length($k);
			$v =~ s/\*$//;
			push @ary, [ $k, $v, $p{$k} ];
		}
		push @dimensions, \@ary;
	}

#Debug( "dimensions: " . $Tag->uneval( { ref => \@dimensions } ) );

	my @pointers;
	my @options;
	my @descriptions;
	my @prices;
	my @hashes;

	sub dosum {
		my $tot = 0;
		for(@_) {
			next unless $_;
			$tot += $_;
		}
		return $tot;
	}

	sub recurse_dim {
			my $dim = $_[0] || 0;
			return if $dim > $#dimensions;
			for (0 .. @{$dimensions[$dim]}-1) {
				$pointers[$dim] = $_;
				if ($dim == $#dimensions) {

					push @descriptions,
					join( ', ',
	map { $dimensions[$_]->[$pointers[$_]]->[1] } (0..$#dimensions)
						)
					;
					push @options,
					join( '-',
	map { $dimensions[$_]->[$pointers[$_]]->[0] } (0..$#dimensions)
						)
					;
					push @prices,
					dosum(
	map { $dimensions[$_]->[$pointers[$_]]->[2] } (0..$#dimensions)
						)
					;

					my %opthash;
					for (my $i = 0; $i < @optnames; $i++) {
						$opthash{$optnames[$i]} =
							$dimensions[$i]->[$pointers[$i]]->[0];
					}
					push @hashes, \%opthash;

				} else {
					recurse_dim($dim + 1);
				}
			}
	}

	recurse_dim();

#Debug( "options: "  . $Tag->uneval( { ref => \@options } ) );
#Debug( "hashes: "  . $Tag->uneval( { ref => \@hashes } ) );
	my $tname = $vdb->name();
	for( my $i = 0; $i < @options; $i++) {
		my $key = "$id-$options[$i]";
		die ::errmsg("No key for create!") unless $key;
#Debug( "creating variant $key in table $tname for item=$id price=$prices[$i]");
		$hashes[$i]->{code} = $id;
		$hashes[$i]->{noformat} = 1;
		$hashes[$i]->{quantity} = 1;
		$price = $Scratch->{tmp_price};
		$price += $prices[$i];
		my $hash = { 
			code => $key,
			sku => $id,
			price => $price,
			description => "$Scratch->{tmp_desc}, $descriptions[$i]",
		};
		for(keys %default) {
			$hash->{$_} = $default{$_}
				if $vdb->test_column($_);
		}
		$vdb->set_slice($key, $hash);
	}

	return;

[/perl]
[/if]

<TABLE CELLSPACING=0 cellpadding=2 cellmargin=3 width="100%">
<TR class=rhead>
<TH ALIGN=LEFT>[L]SKU[/L]</TH>
<TH ALIGN=LEFT>[L]Description[/L]</TH>
<TH ALIGN=RIGHT>[L]Price[/L]</TH>
<TH ALIGN=CENTER>&nbsp;</TH>
</tr>
[loop prefix=variant
		search="
				fi=[cgi mv_variant_table]
				st=db
				co=yes

				sf=sku
				se=[cgi item_id]
				op=eq

				rf=code,sku,description,price
				"]
[list]
<TR [variant-alternate 2]BGCOLOR="__UI_T_ROW_EVEN__"[else]BGCOLOR="__UI_T_ROW_ODD__"[/else][/variant-alternate]>

<TD>[page href=__UI_BASE__/flex_editor form=|
						mv_data_table=[cgi mv_variant_table]
						ui_page_title=[cgi ui_page_title]
						ui_page_title=[cgi ui_page_banner]
						ui_class=Items
						ui_meta_specific=[cgi ui_meta_specific]
						ui_meta_view=variant
						ui_data_fields=code sku description price wholesale inventory:quantity weight
						ui_return_to=@@MV_PAGE@@
						ui_return_to=item_id=[cgi item_id]
						item_id=[variant-code]
					|][variant-code]</A></TD>
<TD>
	[variant-param description]
</td>
<TD ALIGN=right>
	[variant-filter currency][variant-param price][/variant-filter]
</td>
<TD ALIGN=CENTER WIDTH="1"><A
onClick="return confirm('Are you sure you want to delete the [variant-code] variant?')"
HREF="[area
			href='@@MV_PAGE@@'
			form='
				deleterecords=1
				ui_delete_id=[variant-code]
				sku=[cgi item_id]
				mv_data_table=[cgi mv_variant_table]
				mv_click=db_maintenance
				mv_action=back
				mv_nextpage=@@MV_PAGE@@
			'
]"><IMG SRC="delete.gif" ALT="Delete [variant-code] variant" BORDER=0></A></TD>
</tr>
[/list]
[no-match]
<tr>
<td colspan=6 align=center>
<B>No Variants.</B>
</td>
</tr>
[/no-match]
<tr>
<td colspan=3>
	<form action="[area @@MV_PAGE@@]">
	<INPUT TYPE=hidden NAME=debug VALUE=0>
	<INPUT TYPE=hidden NAME=mv_data_table VALUE="[cgi mv_data_table]">
	<INPUT TYPE=hidden NAME=item_id VALUE="[cgi item_id]">
	<INPUT TYPE=hidden NAME=explode VALUE="1">
	<INPUT TYPE=submit VALUE="[L]Create all possible combinations[/L]">
	</form>
</td>
</tr>
</table>
[/loop]

[tmp desc_value][calc]
	$f = qq{[field column=__DescriptionField__ key="[cgi item_id]"]};
	$f =~ s/'/\\'/g;
	return $f;
	[/calc][/tmp]
<FORM ACTION="[area @@MV_PAGE@@]" METHOD=post NAME=simple_options>
<INPUT TYPE=hidden NAME=sku              VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=mv_data_table    VALUE="[cgi mv_data_table]">
<INPUT TYPE=hidden NAME=ui_class         VALUE="Items">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_title]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_banner]">
<INPUT TYPE=hidden NAME=ui_meta_specific VALUE="[cgi ui_meta_specific]">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="@@MV_PAGE@@">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="mv_data_table=[cgi mv_data_table]">
<INPUT TYPE=hidden NAME=ui_return_to VALUE="ui_text_qualification=sku=[cgi item_id]">
<INPUT TYPE=hidden NAME=mv_action        VALUE=back>

<TABLE BORDER=0><TR><TD VALIGN=TOP>

<table __UI_T_PROPERTIES__ WIDTH=100%>
<tr class=rtitle>
	<td class=titlebox colspan=3>
		<H2>[L]Add Variant[/L]</H2>
	</td>
</tr>
<tr class=rtitle>
	<td class=ctitle>[L]Option name[/L]</td>
	<td class=ctitle>[L]Choices[/L]</td>
	<td class=ctitle>&nbsp;</td>
</tr>
[tmp built_js]
<SCRIPT LANGUAGE="JavaScript">
	function set_description(this_form, other_form) {
		other_form.description.value = '[scratch desc_value] - ';
		var joiner = '';
		other_form.code.value = '[cgi item_id]';
		if(! other_form.price.value) {
			other_form.price.value = '[field code="[cgi item_id]" column=price]';
		}
		if(! other_form.wholesale.value) {
			other_form.wholesale.value = '[field code="[cgi item_id]" column=wholesale]';
		}
		if(! other_form.weight.value) {
			other_form.weight.value = '[field weight code="[cgi item_id]"]';
		}
		_NEXT_DESC_
		return true;
	}
</SCRIPT>
[/tmp]

[loop prefix=item
		search="
				fi=[cgi mv_data_table]
				st=db
				co=yes

				se=[cgi item_id]
				sf=sku
				op=eq
				ac=0

				tf=o_sort

				rf=*
				"]
[calc]
	$Scratch->{built_js} =~ s/_NEXT_[A-Z]+_//g;
	return;
[/calc]
[scratch built_js]
[list]
[item-sub do_js]
	my $parm = shift;
	$parm =~ s/'/\\'/g;

	my $line = shift;
	my $piece = <<EOF;
 	if(this_form.$parm\[this_form.$parm.selectedIndex].value != '') {
		other_form.description.value =
							other_form.description.value
							+ joiner
							+ this_form.$parm\[this_form.$parm.selectedIndex].text;
		joiner = ', ';
	}

	other_form.code.value =
			other_form.code.value
			+ '-'
			+ (this_form.$parm\[this_form.$parm.selectedIndex].value || '__MV_VARIANT_JOINER__' || '0');
	_NEXT_DESC_
EOF
	$Scratch->{built_js} =~ s/_NEXT_DESC_/$piece/;
	return;
[/item-sub]
<TR [item-alternate 2]BGCOLOR="__UI_T_ROW_EVEN__"[else]BGCOLOR="__UI_T_ROW_ODD__"[/else][/item-alternate]>

<TD>&nbsp;[page href=__UI_BASE__/flex_editor form=|
									mv_data_table=[cgi mv_data_table]
									ui_page_title=[cgi ui_page_title]
									ui_page_title=[cgi ui_page_banner]
									ui_meta_view=matrix_options
									ui_hide_key=1
									ui_class=Items
									ui_meta_specific=[cgi ui_meta_specific]
									ui_return_to=@@MV_PAGE@@
									item_id=[item-code]
						|][item-param o_group]</A></TD>
<TD>
	[item-exec do_js][item-param o_group][/item-exec]
	[accessories
				js=| onChange="set_description(simple_options, variant)"; |
				type=select
				name="[item-param o_group]"
				passed="=--choose--,[item-param o_value]"
	] </td>
<TD ALIGN=CENTER WIDTH="1"><A
onClick="return confirm('Are you sure you want to delete the [item-param o_group] ([item-code]) option?')"
HREF="[area
			href='@@MV_PAGE@@'
			form='
				deleterecords=1
				ui_delete_id=[item-code]
				sku=[cgi item_id]
				mv_data_table=[cgi mv_data_table]
				mv_click=db_maintenance
				mv_action=back
				mv_nextpage=@@MV_PAGE@@
			'
]"><IMG SRC="delete.gif" ALT="Delete [item-param o_group] option" BORDER=0></A></TD>
</tr>
[/list]
[no-match]
<tr>
<td colspan=6 align=center>
<B>No options.</B>
</td>
</tr>
[/no-match]
</table>
[/loop]

[page href=__UI_BASE__/flex_editor
		form="
			ui_new_item=1
			item_id=new
			sku=[cgi item_id]
			mv_data_table=[cgi mv_data_table]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=ignore_sku=1
			ui_return_to=item_id=[cgi item_id]
			ui_te_override:sku=[cgi item_id]
			ui_data_fields=code sku o_group o_label o_value
			ui_te_widget:sku=hidden_text
		"]<IMG SRC="plus.gif" ALT="[L]Add new option[/L]" BORDER=0 ALIGN=MIDDLE></A> &nbsp;<font size=2>[L]Add new option[/L]</font>
<br>
<SELECT NAME=ui_clone_id>
<OPTION VALUE=""> --
[query
	list=1
	prefix=clone
	db=1
	sql="SELECT DISTINCT sku
		 FROM  [cgi mv_data_table]
		 WHERE   sku      <> '[cgi item_id]'
		"
	more=1]
<OPTION VALUE="[clone-code]">[clone-filter 30.][clone-description][/clone-filter]
[/query]
</SELECT>
[button text="[L]Clone options[/L]"]
ui_clone_options=1
mv_todo=back
mv_nextpage=@@MV_PAGE@@
[/button]

</FORM>

</TD><TD VALIGN=TOP>

[table-editor
	table_width=400
	default.quantity=1
	override.sku=`$CGI->{item_id}`
	extra.description="wrap=auto"
	form_name=variant
	key=""
	table="[cgi mv_variant_table]"
	ui_data_fields="code sku description price wholesale inventory:quantity weight"
	ui_meta_view="variant"
	widget.sku="hidden_text"
]

</TD></TR></TABLE>



1.1                  interchange/dist/lib/UI/pages/include/Options/Simple


rev 1.1, prev_rev 1.0
Index: Simple
===================================================================
[update values]
[calc]
	$Tag->tmp('option_table');
	my $loc = $Config->{Options_repository}{Simple} || {};
	$Scratch->{option_table} = $loc->{table} || 'options';
	return;
[/calc]

<!-- flag write: [flag type=write table="[scratch option_table]"] -->

[if cgi ui_clone_options]
[and cgi ui_clone_id]
[perl tables="[scratch option_table]"]
#Debug("Cloning options for $CGI->{ui_clone_id}...");
	my $db = $Db{$Scratch->{option_table}}
		or return;
#Debug("Have a table=$db clone id=$CGI->{ui_clone_id}");
	my ($k,$v);
	$db->clone_row($CGI->{ui_clone_id}, $CGI->{sku});
	$db->clone_set('sku', $CGI->{ui_clone_id}, $CGI->{sku});
	return;
[/perl]
[/if]

[if cgi sku]
    [perl tables="[scratch option_table]"]
        my $otab = $Scratch->{option_table};
        my $odb = $Db{$otab};

        foreach(sort keys %{$CGI}) {
            next unless /^opt_group_(.*)/;
            my $key = $1;

            my $name = $CGI->{"opt_group_$key"};
            my $value = $Tag->filter('line2options', $CGI->{"opt_value_$key"});
            my $label = $CGI->{"opt_label_$key"};

            next unless $name && $value;

            unless($key) { $key = $CGI->{sku}."-$name"; }

			$key =~ s/_/-/g; # javascript won't handle form names with '-'

            $odb->set_field($key,'sku',$CGI->{sku});
            $odb->set_field($key,'o_group',$name);
            $odb->set_field($key,'o_value',$value);
            $odb->set_field($key,'o_widget','select');
			$odb->set_field($key,'o_label',$label);
        }

        return;
    [/perl]
[/if]


<FORM ACTION="[area @@MV_PAGE@@]" METHOD="POST">
[if scratch ui_failure]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_failure][set ui_failure][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
[if scratch ui_message]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_message][set ui_message][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
<INPUT TYPE=hidden NAME=sku              VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_title]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_banner]">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="@@MV_PAGE@@">
<INPUT TYPE=hidden NAME=mv_action        VALUE=back>

<TABLE BORDER=0><TR><TD VALIGN=TOP>

[query list=1 sql="select * from [scratch option_table] where sku='[filter op=sql interpolate=1][cgi item_id][/filter]' and o_group is not null"]
[list]
[if-sql-data options o_group]
[calc] $Scratch->{mod_code} = q{[sql-code]}; $Scratch->{mod_code} =~ s/-/_/g; return;[/calc]

<div style="border: 1px solid black; margin-bottom: 3px">
<table	border=0
		cellspacing=0 cellpadding=3
		class="[sql-alternate 2]__UI_T_ROW_EVEN__[else]__UI_T_ROW_ODD__[/else][/sql-alternate]"
		>
<tr>
	<td valign=center class=titlebox>
		Option: [filter entities][sql-param o_group][/filter]
<INPUT TYPE=hidden NAME="opt_group_[scratch mod_code]" VALUE="[filter entities][sql-param o_group][/filter]">
	</td>
</tr>
<tr>
	<td valign=center>
		[L]Label[/L]:
			<INPUT TYPE=text SIZE=20 NAME="opt_label_[scratch mod_code]" VALUE="[filter entities][sql-param o_label][/filter]">
<A HREF="[area href='@@MV_PAGE@@'
               form='deleterecords=1
                     ui_delete_id=[sql-code]
                     item_id=[cgi item_id]
                     mv_data_table=options
                     mv_click=db_maintenance
                     mv_action=back
                     mv_nextpage=@@MV_PAGE@@
                    '
         ]"
		 title="Delete [sql-param o_group] option"
		 ><IMG SRC="delete.gif" ALT="[L]Delete[/L]" ALIGN=CENTER BORDER=0></A>

	<input type=hidden
			name="reset_[scratch mod_code]"
			value="[filter entities][sql-param o_label][/filter]">
<script><!--
document.write('<br><INPUT TYPE=checkbox [sql-calc]q{[sql-param o_label]} eq q{[sql-param o_group]} ? 'CHECKED' : undef;[/sql-calc]\n' +
'	onClick="if (this.checked) { this.form.opt_label_[scratch mod_code].value = this.form.opt_group_[scratch mod_code].value; } else { this.form.opt_label_[scratch mod_code].value = this.form.reset_[scratch mod_code].value; }">\n' +
'<font size=2>[L]Set label to name[/L]</font>');
// -->
</script>
</TD></TR>


<TR><TD>
<TEXTAREA ROWS=5 COLS=30 NAME="opt_value_[scratch mod_code]">[filter options2line][sql-param o_value][/filter]</TEXTAREA><br>
<span style="font-size: smaller">
[page href="admin/flex_editor"
		form="
			mv_data_table=options
			nodelete=1
			ui_return_to=@@MV_PAGE@@
			ui_return_to=item_id=[cgi item_id]
			item_id=[sql-code]
			ui_data_fields=code sku o_widget o_width o_height
			ui_te_widget:sku=hidden
		"]edit</A>
Widget: [sql-param o_widget]
<br>
[page href="admin/flex_editor"
		form="
			mv_data_table=options
			nodelete=1
			item_id=[sql-code]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=item_id=[cgi item_id]
			ui_data_fields=code sku o_value price
			ui_te_widget:sku=hidden
			ui_meta_view=simple_price
			ui_te_widget:price=textarea_8_20
			ui_te_widget:o_value=hidden_text
			ui_te_filter:price=line2options
			ui_te_pre_filter:price=options2line
			ui_te_help:price=Standard VALUE=N.NN, VALUE2=N.NN format
			ui_te_help:o_value=Values in this option
		"]edit</A>
Price differential: [sql-param price]
</span>
<br>
</TD></TR>
</TABLE>
</div>
[/if-sql-data]
[/list]
[/query]

<BR><BR><BR>
[button text="[L]Commit Changes[/L]"]
mv_nextpage=@@MV_PAGE@@
ui_return_to=
mv_todo=return
[/button]

</TD><TD><PRE>                          </PRE></TD><TD VALIGN=TOP>

<div class=titlebox style="margin-bottom: 4px">[L]Create a new option[/L]</div>
[L]Name[/L]: <INPUT TYPE=text SIZE=20 NAME="opt_group_" VALUE="">
<br>[L]Label[/L]: <INPUT TYPE=text SIZE=20 NAME="opt_label_">
<script><!--
document.write('<br><INPUT TYPE=checkbox\n' +
'	onClick="if (this.checked) { this.form.opt_label_.value = this.form.opt_group_.value; } else { this.form.opt_label_.value = \'\'; }">\n' +
'<font size=2>[L]Set label to name[/L]</font>');
// -->
</script>
<BR>
<TEXTAREA ROWS=5 COLS=30 NAME="opt_value_"></TEXTAREA>
<BR>
[button text="[L]Create option[/L]"][/button]
<BR>
<BR>

<div class=titlebox style="margin-bottom: 4px">[L]Clone an existing option set[/L]</div>

[query
	list=1
	prefix=clone
	sql="select DISTINCT sku from [scratch option_table] where o_group is not null and o_group != ''"
	more=1]
<SELECT NAME=ui_clone_id>
<OPTION VALUE=""> --
[list]
<OPTION VALUE="[clone-code]">[either][clone-filter 20.][clone-description][/clone-filter][or][clone-code][/either]
[/list]
</SELECT>[more-list]<BR>[more]<BR>[/more-list][/query]&nbsp;[button text="[L]Clone options[/L]"]ui_clone_options=1[/button]
<BR>
</FORM>

</TD></TR></TABLE>




1.1                  interchange/dist/lib/UI/pages/include/Options/old/item_option_matrix


rev 1.1, prev_rev 1.0
Index: item_option_matrix
===================================================================
[if cgi ui_clone_options]
[and cgi ui_clone_id]
[perl tables="[cgi mv_data_table]"]
	my $db = $Db{$CGI->{mv_data_table}}
		or return;
	my ($k,$v);
	$db->clone_row($CGI->{ui_clone_id}, $CGI->{sku});
	$db->clone_set('sku', $CGI->{ui_clone_id}, $CGI->{sku});
	return;
[/perl]
[/if]
<!--
				fi=[cgi mv_data_table]
				st=db
				co=yes

				se=[cgi item_id]
				sf=sku
				op=eq
				ac=0

				sf=o_matrix
				se=1
				op=ne
				ac=0

				sf=o_master
				se=.
				op=rn
				ac=0

				rf=*

-->
[if cgi explode]
[tmp all_opts][loop
	search="
					fi=[cgi mv_data_table]
					st=db
					co=yes

					se=[cgi item_id]
					sf=sku
					op=eq
					ac=0

					sf=o_matrix
					se=1
					op=ne
					ac=0

					rf=o_group,o_value
		"][loop-param o_group]	[loop-param o_value]
[/loop][/tmp]

[tmp tmp_price][price noformat=1 code="[cgi item_id]"][/tmp]
[tmp tmp_whole][field field=wholesale code="[cgi item_id]"][/tmp]
[tmp tmp_desc][description code="[cgi item_id]"][/tmp]
[perl tables="[cgi mv_data_table] __UI_ITEM_TABLES__"]
#Debug("opts: $Scratch->{all_opts}");
	my $otab = $CGI->{mv_data_table};
	my $odb = $Db{$otab};
	unless ($odb) {
		::logError("can't open option table '%s'.", $otab);
		return undef;
	}
	my $id = $CGI->{item_id};
	my %default = (
		price		=> $Scratch->{tmp_price},
		wholesale	=> $Scratch->{tmp_whole},
	);
#Debug("opts: $Scratch->{all_opts}");
	my @opts = grep /\S/, split /\n/, $Scratch->{all_opts};
#Debug( "options raw: " . $Tag->uneval( { ref => \@opts } ) );
	return unless @opts;

	my @dimensions;
	for(@opts) {
		my($g, $o) = split /\t/, $_;
		push @optnames, $g;
		my @ary;
		my (@o) = grep /\S/, split /\s*,\s*/, $o;
		for(@o) {
			my ($k, $v) = split /\s*=\s*/, $_;
			$k = '__MV_VARIANT_JOINER__' || '0' if ! length($k);
			$v =~ s/\*$//;
			push @ary, [ $k, $v ];
		}
		push @dimensions, \@ary;
	}

#Debug( "dimensions: " . $Tag->uneval( { ref => \@dimensions } ) );

	my @pointers;
	my @options;
	my @descriptions;
	my @hashes;

	sub recurse_dim {
			my $dim = $_[0] || 0;
			return if $dim > $#dimensions;
			for (0 .. @{$dimensions[$dim]}-1) {
				$pointers[$dim] = $_;
				if ($dim == $#dimensions) {

					push @descriptions,
					join( ', ',
	map { $dimensions[$_]->[$pointers[$_]]->[1] } (0..$#dimensions)
						)
					;
					push @options,
					join( '-',
	map { $dimensions[$_]->[$pointers[$_]]->[0] } (0..$#dimensions)
						)
					;

					my %opthash;
					for (my $i = 0; $i < @optnames; $i++) {
						$opthash{$optnames[$i]} =
							$dimensions[$i]->[$pointers[$i]]->[0];
					}
					push @hashes, \%opthash;

				} else {
					recurse_dim($dim + 1);
				}
			}
	}

	recurse_dim();

#Debug( "options: "  . $Tag->uneval( { ref => \@options } ) );
#Debug( "hashes: "  . $Tag->uneval( { ref => \@hashes } ) );
	$odb->set_field($id, 'o_matrix', 0);
	for( my $i = 0; $i < @options; $i++) {
		my $key = "$id-$options[$i]";
		die ::errmsg("No key for create!") unless $key;
		$odb->set_field($key, 'description', "$Scratch->{tmp_desc}, $descriptions[$i]");
		$hashes[$i]->{code} = $id;
		$hashes[$i]->{noformat} = 1;
		$hashes[$i]->{quantity} = 1;
		$price = $Tag->price( $id, $hashes[$i] );
		for(keys %default) {
			$odb->set_field($key, $_, $default{$_})
				if $odb->test_column($_);
		}
		$odb->set_field($key, 'price', $price);
		$odb->set_field($key, 'sku', $id);
		$odb->set_field($key, 'o_matrix', 1);
		$odb->set_field($key, 'o_enable', 1);
	}
	$odb->set_field($id, 'o_matrix', 1);

	return;

[/perl]
[/if]

[if scratch ui_failure]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_failure][set ui_failure][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
[if scratch ui_message]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_message][set ui_message][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
<TABLE CELLSPACING=0 cellpadding=2 cellmargin=3 width="100%">
<TR class=rmarq>
<TH ALIGN=LEFT>[L]SKU[/L]</TH>
<TH ALIGN=LEFT>[L]Description[/L]</TH>
<TH ALIGN=RIGHT>[L]Price[/L]</TH>
<TH ALIGN=CENTER>&nbsp;</TH>
</tr>
[loop prefix=variant
		search="
				fi=[cgi mv_data_table]
				st=db
				co=yes

				sf=sku
				se=[cgi item_id]
				op=eq

				sf=o_matrix
				se=1
				op=eq

				rf=code,sku,description,o_value,price
				"]
[list]
<TR [variant-alternate 2]BGCOLOR="__UI_T_ROW_EVEN__"[else]BGCOLOR="__UI_T_ROW_ODD__"[/else][/variant-alternate]>

<TD>[page href=__UI_BASE__/flex_editor form=|
						mv_data_table=[cgi mv_data_table]
						ui_page_title=[cgi ui_page_title]
						ui_page_title=[cgi ui_page_banner]
						ui_class=Items
						ui_meta_specific=[cgi ui_meta_specific]
						ui_meta_view=variant
						ui_data_fields=code sku description price wholesale inventory:quantity weight o_widget o_width o_height
						ui_return_to=@@MV_PAGE@@
						ui_return_to=ui_return_table=[cgi mv_data_table]
						ui_return_to=ui_text_qualification=sku=[cgi item_id]
						item_id=[variant-code]
					|][variant-code]</A></TD>
<TD>
	[variant-data options description]
</td>
<TD ALIGN=right>
	[variant-filter currency][variant-data options price][/variant-filter]
</td>
<TD ALIGN=CENTER WIDTH="1"><A
onClick="return confirm('Are you sure you want to delete the [variant-code] variant?')"
HREF="[area
			href='@@MV_PAGE@@'
			form='
				deleterecords=1
				ui_delete_id=[variant-code]
				sku=[cgi item_id]
				mv_data_table=[cgi mv_data_table]
				mv_click=db_maintenance
				mv_action=back
				mv_nextpage=@@MV_PAGE@@
			'
]"><IMG SRC="delete.gif" ALT="Delete [variant-code] variant" BORDER=0></A></TD>
</tr>
[/list]
[no-match]
<tr>
<td colspan=6 align=center>
<B>No Variants.</B>
</td>
</tr>
[/no-match]
<tr>
<td colspan=3>
	<form action="[area @@MV_PAGE@@]">
	<INPUT TYPE=hidden NAME=debug VALUE=0>
	<INPUT TYPE=hidden NAME=mv_data_table VALUE="[cgi mv_data_table]">
	<INPUT TYPE=hidden NAME=item_id VALUE="[cgi item_id]">
	<INPUT TYPE=hidden NAME=explode VALUE="1">
	<INPUT TYPE=submit VALUE="[L]Create all possible combinations[/L]">
	</form>
</td>
</tr>
</table>
[/loop]

[tmp desc_value][calc]
	$f = qq{[field column=__DescriptionField__ key="[cgi item_id]"]};
	$f =~ s/'/\\'/g;
	return $f;
	[/calc][/tmp]
<FORM ACTION="[area @@MV_PAGE@@]" METHOD=post NAME=simple_options>
<INPUT TYPE=hidden NAME=sku              VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=mv_data_table    VALUE="[cgi mv_data_table]">
<INPUT TYPE=hidden NAME=ui_class         VALUE="Items">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_title]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_banner]">
<INPUT TYPE=hidden NAME=ui_meta_specific VALUE="[cgi ui_meta_specific]">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="@@MV_PAGE@@">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="mv_data_table=[cgi mv_data_table]">
<INPUT TYPE=hidden NAME=ui_return_to VALUE="ui_text_qualification=sku=[cgi item_id]">
<INPUT TYPE=hidden NAME=mv_action        VALUE=back>

<TABLE BORDER=0><TR><TD VALIGN=TOP>

<table __UI_T_PROPERTIES__ WIDTH=100%>
<tr class=rtitle>
	<td class=ctitle colspan=3>
		<H2>[L]Add Variant[/L]</H2>
	</td>
</tr>
<tr class=rtitle>
	<td class=ctitle>[L]Option name[/L]</td>
	<td class=ctitle>[L]Choices[/L]</td>
	<td class=ctitle>&nbsp;</td>
</tr>
[tmp built_js]
<SCRIPT LANGUAGE="JavaScript">
	function set_description(this_form, other_form) {
		other_form.description.value = '[scratch desc_value] - ';
		var joiner = '';
		other_form.code.value = '[cgi item_id]';
		if(! other_form.price.value) {
			other_form.price.value = '[field code="[cgi item_id]" column=price]';
		}
		if(! other_form.wholesale.value) {
			other_form.wholesale.value = '[field code="[cgi item_id]" column=wholesale]';
		}
		if(! other_form.weight.value) {
			other_form.weight.value = '[field weight code="[cgi item_id]"]';
		}
		_NEXT_DESC_
		return true;
	}
</SCRIPT>
[/tmp]
[tmp do_clone]1[/tmp]
[loop prefix=item
		search="
				fi=[cgi mv_data_table]
				st=db
				co=yes

				se=[cgi item_id]
				sf=sku
				op=eq
				ac=0

				sf=o_matrix
				se=1
				op=ne
				ac=0

				sf=o_master
				se=.
				op=rn
				ac=0

				tf=o_sort

				rf=*
				"]
[calc]
	$Scratch->{built_js} =~ s/_NEXT_[A-Z]+_//g;
	return;
[/calc]
[on-match][if type=data term="[cgi mv_data_table]::o_matrix::[cgi item_id]" op=eq compare=2][tmp do_clone][/tmp][/if][/on-match]
[scratch built_js]
[list]
[item-sub do_js]
	my $parm = shift;
	$parm =~ s/'/\\'/g;

	my $line = shift;
	my $piece = <<EOF;
 	if(this_form.$parm\[this_form.$parm.selectedIndex].value != '') {
		other_form.description.value =
							other_form.description.value
							+ joiner
							+ this_form.$parm\[this_form.$parm.selectedIndex].text;
		joiner = ', ';
	}

	other_form.code.value =
			other_form.code.value
			+ '-'
			+ (this_form.$parm\[this_form.$parm.selectedIndex].value || '__MV_VARIANT_JOINER__' || '0');
	_NEXT_DESC_
EOF
	$Scratch->{built_js} =~ s/_NEXT_DESC_/$piece/;
	return;
[/item-sub]
<TR [item-alternate 2]BGCOLOR="__UI_T_ROW_EVEN__"[else]BGCOLOR="__UI_T_ROW_ODD__"[/else][/item-alternate]>

<TD>&nbsp;[page href=__UI_BASE__/flex_editor form=|
									mv_data_table=[cgi mv_data_table]
									ui_page_title=[cgi ui_page_title]
									ui_page_title=[cgi ui_page_banner]
									ui_meta_view=matrix_options
									ui_hide_key=1
									ui_class=Items
									ui_meta_specific=[cgi ui_meta_specific]
									ui_return_to=@@MV_PAGE@@
									item_id=[item-code]
						|][item-param o_group]</A></TD>
<TD>
	[item-exec do_js][item-param o_group][/item-exec]
	[accessories
				js=| onChange="set_description(simple_options, variant)"; |
				type=select
				name="[item-param o_group]"
				passed="=--choose--,[item-param o_value]"
	] </td>
<TD ALIGN=CENTER WIDTH="1"><A
onClick="return confirm('Are you sure you want to delete the [item-param o_group] ([item-code]) option?')"
HREF="[area
			href='@@MV_PAGE@@'
			form='
				deleterecords=1
				ui_delete_id=[item-code]
				sku=[cgi item_id]
				mv_data_table=[cgi mv_data_table]
				mv_click=db_maintenance
				mv_action=back
				mv_nextpage=@@MV_PAGE@@
			'
]"><IMG SRC="delete.gif" ALT="Delete [item-param o_group] option" BORDER=0></A></TD>
</tr>
[/list]
[no-match]
<tr>
<td colspan=6 align=center>
<B>No options.</B>
</td>
</tr>
[/no-match]
</table>
[/loop]

[page href=__UI_BASE__/flex_editor
		form="
			ui_new_item=1
			item_id=new
			sku=[cgi item_id]
			mv_data_table=[cgi mv_data_table]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=ignore_sku=1
			ui_return_to=item_id=[cgi item_id]
			ui_te_override:sku=[cgi item_id]
			ui_data_fields=code sku o_group o_label o_value price
			ui_te_widget:sku=hidden_text
		"]<IMG SRC="plus.gif" ALT="[L]Add new option[/L]" BORDER=0 ALIGN=MIDDLE></A> &nbsp;<font size=2>[L]Add new option[/L]</font>
<br>
[if scratch do_clone]
[query
	list=1
	prefix=clone
	db=1
	sql="SELECT DISTINCT code
		 FROM  [cgi mv_data_table]
		 WHERE o_matrix  >= '1'
		 AND   o_enable  =  '1'
		 AND   o_master  =  '1'
		 AND   code      <> '[cgi item_id]'
		"
	more=1]<SELECT NAME=ui_clone_id>
<OPTION VALUE=""> --
[list]<OPTION VALUE="[clone-code]">[clone-filter 30][clone-description][/clone-filter][/list]
</SELECT>[more-list]<BR>[more]<BR>[/more-list][/query]<br>[button text="[L]Clone options[/L]"]
[flag type=write table="[cgi mv_data_table]"]
ui_clone_options=1
mv_todo=back
mv_nextpage=@@MV_PAGE@@
[/button]
[/if]

</FORM>

</TD><TD VALIGN=TOP>

[table-editor
	table_width=400
	default.o_matrix=1
	default.o_enable=1
	default.quantity=1
	override.sku=`$CGI->{item_id}`
	extra.description="wrap=auto"
	form_name=variant
	key=""
	table=options
	ui_data_fields="code sku description price wholesale inventory:quantity weight o_enable o_matrix"
	ui_display_only=products:description:sku
	ui_meta_view="variant"
	ui_new_item=1
	widget.o_matrix=hidden
	widget.o_enable=hidden
	widget.sku="hidden_text"
]

</TD></TR></TABLE>



1.1                  interchange/dist/lib/UI/pages/include/Options/old/item_option_modular


rev 1.1, prev_rev 1.0
Index: item_option_modular
===================================================================
[if cgi ui_clone_options]
[and cgi ui_clone_id]
[perl interpolate=1 tables="[cgi mv_data_table]"]
	my $db = $Db{[cgi mv_data_table]}
		or return;
	my ($k,$v);
	$db->clone_row($CGI->{ui_clone_id}, $CGI->{sku});
	$db->clone_set('o_master', $CGI->{ui_clone_id}, $CGI->{sku});
	return;
[/perl]
[/if]

[if cgi diagnose]
[tmp testing][tree 
				table="[cgi mv_data_table]"
				pedantic=1
				show_error=1
				full=1
				master=o_master
				sub=sku
				start="[cgi item_id]"][/tree][/tmp]
	[if scratch testing]
	<BLOCKQUOTE class=cmessage>
		[scratch testing]
	</BLOCKQUOTE>
	[else]
	<BLOCKQUOTE class=cmessage>
		Tree appears OK.
	</BLOCKQUOTE>
	[/else]
	[/if]
[/if]

[page href="@@MV_PAGE@@"
		form="
			collapse=1
			sku=[cgi item_id]
	"]Collapse all</A>&nbsp;&nbsp;&nbsp;[page href="@@MV_PAGE@@"
		form="
			explode=1
			sku=[cgi item_id]
	"]Explode all</A>&nbsp;&nbsp;&nbsp;[page href="@@MV_PAGE@@"
		form="
			diagnose=1
			sku=[cgi item_id]
	"]Check integrity</A>

<TABLE CELLSPACING=0 CELLPADDING=2 CELLMARGIN=3 WIDTH="100%">
<TR class=rmarq>
	<TH ALIGN=LEFT>SKU</TH>
	<TH ALIGN=LEFT>Master</TH>
	<TH ALIGN=LEFT>Group</TH>
	<TH ALIGN=LEFT>Description</TH>
	<TH ALIGN=RIGHTPrice</TH>
</TR>
[seti mod_template]
<TR>
<TD>&nbsp;{ui_spacer}{ui_action?}[page href="@@MV_PAGE@@"
							form="
								mv_data_table=[cgi mv_data_table]
								sku=[cgi item_id]
								UI_ACTION=
							"]{/ui_action?}{ui_action_img}{ui_action </A>}&nbsp;[page
				href=__UI_BASE__/flex_editor
				form=|
					mv_data_table=[cgi mv_data_table]
					ui_class=Items
					ui_hide_key=1
					ui_meta_specific=[cgi ui_meta_specific]
					ui_meta_view=modular
					{phantom?}
					ui_te_widget:o_default=text
					ui_te_width:o_default=20
					ui_te_help:o_default=Override the option defaults, select SKU to use instead
					{/phantom?}
					ui_page_banner=[cgi ui_page_banner]
					ui_page_title=[cgi ui_page_title]
					ui_return_to=@@MV_PAGE@@
					ui_return_to=item_id=[cgi item_id]
					ui_return_to=ignore_sku=1
					item_id={code}
				|]{sku|no sku}</A>{o_default *}</TD>
<TD>{o_master}</td>
<TD>{o_group} {phantom?}[page href=__UI_BASE__/flex_editor
			form=|
				mv_data_table=[cgi mv_data_table]
				ui_meta_view=modular_create
				ui_te_default:o_master={sku}
				ui_te_default:o_group={o_group}
				ui_class=Items
				ui_return_to=@@MV_PAGE@@
				ui_return_to=item_id=[cgi item_id]
				ui_return_to=ignore_sku=1
			|]add</A>{/phantom?}</TD></td>
<TD>{description|{products.description}}</td>
<TD ALIGN=RIGHT>{price|{products.price}}</td>
</tr>
[/seti]
[comment]
[set mod_template]master={o_master}|sku={sku}|action={ui_action}|leval={level}|enable={o_enable}|{q}
[/set]
[/comment]
[perl tables="products [cgi mv_data_table]"]
	for(qw/ ui_mod_expand ui_mod_explode /) {
		$Session->{$_} = {} 
			if ! $Session->{$_};
	}
	if($CGI->{expand}) {
		$Session->{ui_mod_expand}{$CGI->{item_id}}{$CGI->{expand}} = 1;
	}
	elsif($CGI->{contract}) {
		$Session->{ui_mod_expand}{$CGI->{item_id}}{$CGI->{contract}} = 0;
	}
	elsif($CGI->{collapse}) {
		delete $Session->{ui_mod_explode}{$CGI->{item_id}};
		delete $Session->{ui_mod_expand}{$CGI->{item_id}};
	}
	elsif($CGI->{explode}) {
		delete $Session->{ui_mod_expand}{$CGI->{item_id}};
		$Session->{ui_mod_explode}{$CGI->{item_id}} = 1;
	}
	$Session->{ui_mod_expand}{$CGI->{item_id}} = {}
		unless $Session->{ui_mod_expand}{$CGI->{item_id}};
	$expand = $Session->{ui_mod_expand}{$CGI->{item_id}};
	$explode = $Session->{ui_mod_explode}{$CGI->{item_id}};
	$otab = $CGI->{mv_data_table};
	$ptab = '__ProductFiles_0__';
	$Scratch->{mod_template} =~ s/\%7b/{/g;
	$Scratch->{mod_template} =~ s/\%7d/}/g;
	$Scratch->{mod_template} =~ s/UI_ACTION=/{ui_action}/g;
	$odb = $Db{$otab}
		or return "bad options database";
	$pdb = $Db{$ptab}
		or return "bad products database";
	my $price_fld = $pdb->column_exists('__PriceField__')
						? '__PriceField__'
						: 'price';
	delete $Scratch->{debug_body};
	sub display_template {
		my ($ref) = @_;
		my $sku = $ref->{sku};
		my $code = $ref->{code};
		$ref->{"products.description"} = tag_data($ptab, '__DescriptionField__', $sku);
		$ref->{"url.description"} = $Tag->filter('urlencode', $ref->{"products.description"});
		$ref->{"products.price"} =  tag_data($ptab, $price_fld, $sku);

#### Just used to set up some levels in test data
#		my %dict = qw/
#						0 First
#						1 Second
#						2 Third
#						3 Fourth
#						4 Fifth
#						5 Sixth
#						/;
#		$dict{''} = 'First';
#		$dict = $dict{$ref->{level}};
#		if ($dict
#			and $ref->{"products.description"}
#			)
#		{
#			my $cat = tag_data('products', 'category', $sku);
#			$ref->{"products.description"} =~ s/^option\s+/$cat /i;
#			$pdb->set_field($sku, 'description', $ref->{"products.description"});
#		}
#
		if($ref->{level}) {
			my $level = $ref->{level} * 28;
			$ref->{ui_spacer} = qq{<IMG SRC="bg.gif" HEIGHT=1 WIDTH=$level>};
		}
		for(qw/ products.description description /) {
			if(length($ref->{$_}) >=30) {
				substr($ref->{$_}, 27) = '...';
			}
		}
		my $indent = $ref->{level} + 1;
		if($ref->{o_enable}) {
			if($expand->{$code} or $explode && ! defined $expand->{$code}) {
				$ref->{ui_action} = "contract=$code";
				$ref->{ui_action_img} = 
					 qq{<FONT size=1>$indent</FONT><IMG SRC="down.gif" height=11 width=14 BORDER=0>};
			}
			else {
				$ref->{ui_action} = "expand=$code";
				$ref->{ui_action_img} = 
					 qq{<FONT size=1>$indent</FONT><IMG SRC="right.gif" height=11 width=14 BORDER=0>};
			}
		}
		else {
			$ref->{ui_action_img} = 
				 qq{<IMG SRC="bg.gif" HEIGHT=1 WIDTH=14>};
		}
		my $body = $Scratch->{mod_template};
#Log("body first:\n$body\n\n") unless $Scratch->{debug_body};
		$body =~ s!(\{\w+)\%2e(\w+\})!$1.$2!g;
		$body =~ s!\{([-\w.]+)\}!$ref->{$1}!g;
		$body =~ s!\{([-\w.]+)\|([\000-\377]*?)\}!$ref->{$1} || $2!eg;
		$body =~ s!\{([-\w.]+)\s+([\000-\377]*?)\}! $ref->{$1} ? $2 : ''!eg;
		$body =~ s!\{([-\w.]+)\?\}([\000-\377]*?){/\1\?\}! $ref->{$1} ? $2 : ''!eg;
		$body =~ s!\{([-\w.]+):\}([\000-\377]*?){/\1:\}! $ref->{$1} ? '' : $2!eg;
#Log("body now:\n$body\n\n") unless $Scratch->{debug_body}++;
		return $body;
	}
	return;
[/perl]







[query
	hashref=master
	sql="SELECT * FROM options
			WHERE o_master = '[cgi name=item_id filter=sql]'
			ORDER BY o_group, o_sort
		"]
[sql-sub o_display]
	return shift;
[/sql-sub]
[sql-exec o_display][sql-code][/sql-exec]
[/query]

[perl tables=options]
	my $item_id = $Tag->cgi({name => 'item_id', filter => 'sql'});
	my $sql = "SELECT * FROM options WHERE o_master='$item_id' ORDER BY o_group, o_sort";
#Log("sql=$sql");
	my $hash_results = $Tag->query({ sql => $sql, hashref => 'my_results'});

	my %above;
	my @rows;
	foreach my $row (@{$hash_results}) {
		my $master = $row->{code};
#Log("master=$master");
		$above{$CGI->{item_id}} = 1;
		$above{$master} = 1;
		my @stack = ( [ $row ] );
		ARY: for (;;) {
			my $ary;
			$ary = pop(@stack)
				or last ARY;
			ROW: for(;;) {
				$row = shift @$ary
					or last ROW;
				$row->{level} = scalar(@stack);
				push(@rows, $row);
				my $sku = $row->{sku};
				next ROW if ! $row->{o_enable};
				my $code = $row->{code};
				if($above{$sku}) {
					$row->{description} = errmsg("ENDLESS TREE") . " $row->{description}";
					display_template($_);
					next ROW;
				}
				if( $expand->{$code}
						or 
					($explode and ! defined $expand->{$code})
					)
				{
					push(@stack, $ary);
					my $key = $odb->quote($sku, 'sku');
					my $q = "SELECT * FROM options WHERE o_master = $key ORDER BY o_sort",
					$ary = $odb->query(
							{ 
								hashref => 1,
								sql => "SELECT * FROM options
										WHERE o_master = $key
										ORDER BY o_sort
									",
							}
					);
					$above{$sku} = 1 if $ary and scalar @{$ary};
					
				}
			}  # END ROW
		}  # END ARY
	}
	my $out;
	for(@rows) {
		$out .= display_template($_);
	}
	return $out;
[/perl]

</table>

[page href=__UI_BASE__/flex_editor
		form="
			mv_data_table=[cgi mv_data_table]
			ui_class=Admin
			ui_data_fields=code sku o_master o_group phantom o_enable description
			ui_te_default:o_master=[cgi item_id]
			ui_meta_view=modular_create
			ui_hide_key=1
			ui_new_item=1
			ui_page_banner=[cgi ui_page_banner]
			ui_page_title=[cgi ui_page_title]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=item_id=[cgi item_id]
			ui_return_to=ignore_sku=1
		"]<IMG SRC="plus.gif" ALT="Add new option" BORDER=0>Add option</A>
&nbsp;&nbsp;


[page href=__UI_BASE__/item_option_phantom
		form="
			mv_data_table=[cgi mv_data_table]
			ui_class=Items
			item_id=[cgi item_id]
			ui_return_to=@@MV_PAGE@@
			ui_return_to=ui_return_table=[cgi mv_data_table]
			ui_return_to=item_id=[cgi item_id]
			ui_return_to=ignore_sku=1
		"]<IMG SRC="plus.gif" ALT="Add phantom" BORDER=0> Add phantom</A>
&nbsp;&nbsp;
<FORM ACTION="[area @@MV_PAGE@@]">
<input type=hidden name=mv_action value=back>
<input type=hidden name=mv_data_table value="[cgi mv_data_table]">
<INPUT TYPE=hidden NAME=sku VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=item_id VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=ignore_sku	VALUE="1">

[loop
	prefix=clone
	search="
		st=db
		fi=[cgi mv_data_table]
		co=yes

		se=1
		sf=o_modular

		un=yes
	"
	more=1]<SELECT NAME=ui_clone_id>
<OPTION VALUE=""> --
[list]
<OPTION VALUE="[clone-code]">[clone-filter 20][clone-description][/clone-filter]
[/list]
</SELECT>[more-list]<BR>[more]<BR>[/more-list][/loop]&nbsp;[button text="Clone options"]
[flag type=write table="[cgi mv_data_table]"]
ui_clone_options=1
mv_todo=back
mv_nextpage=@@MV_PAGE@@
[/button]
</FORM>



1.1                  interchange/dist/lib/UI/pages/include/Options/old/item_option_simple


rev 1.1, prev_rev 1.0
Index: item_option_simple
===================================================================
[update values]
[if cgi ui_clone_options]
[and cgi ui_clone_id]
[perl interpolate=1 tables="[cgi mv_data_table]"]
	my $db = $Db{[cgi mv_data_table]}
		or return;
	my ($k,$v);
	$db->clone_row($CGI->{ui_clone_id}, $CGI->{sku});
	$db->clone_set('sku', $CGI->{ui_clone_id}, $CGI->{sku});
	return;
[/perl]
[/if]

[if cgi sku]
    [tag flag write]options[/tag]
    [perl tables="options __UI_ITEM_TABLES__"]
        my $otab = 'options';
        my $odb = $Db{$otab};

        foreach(sort keys %{$CGI}) {
            next unless /^opt_group_(.*)/;
            my $key = $1;

            my $name = $CGI->{"opt_group_$key"};
            my $value = $CGI->{"opt_value_$key"};
            my $label = $CGI->{"opt_label_$key"};

            next unless $name && $value;

            unless($key) { $key = $CGI->{sku}."-$name"; }

            my @value = split("\r\n",$value);

            my %seen = ();
            my $hasdefault = 0;

            my($left,$right);
            map {
                my $default = 0;
                s/[,\r\n]//g;
                if(s/\*//g) { $default = 1; $hasdefault = 1; }

                if($v) {
                    if(/=/) {
                        ($left,$right) = split('=',$_);
                    } else {
                        $right = $_;
                        $left = substr($right,0,3);
                    }

                    while($seen{$left}++) { $left++; }

                    $_ = join('=',$left,$right);
                    if($default) { $_ .= "*"; }
                }
            } @value;

            my $value = join(",\n",@value);

			$key =~ s/_/-/g; # javascript won't handle form names with '-'

            $odb->set_field($key,'sku',$CGI->{sku});
            $odb->set_field($key,'o_group',$name);
            $odb->set_field($key,'o_value',$value);
            $odb->set_field($key,'o_widget','select');
			$odb->set_field($key,'o_label',$label);
        }

        return '';
    [/perl]
[/if]


<FORM ACTION="[area @@MV_PAGE@@]" METHOD="post">
[if scratch ui_failure]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_failure][set ui_failure][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
[if scratch ui_message]
<P>
<BLOCKQUOTE>
<FONT COLOR="__CONTRAST__">[scratch ui_message][set ui_message][/set]</FONT>
</BLOCKQUOTE>
<P>
&nbsp;
[/if]
<INPUT TYPE=hidden NAME=sku              VALUE="[cgi item_id]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_title]">
<INPUT TYPE=hidden NAME=ui_page_title    VALUE="[cgi ui_page_banner]">
<INPUT TYPE=hidden NAME=ui_return_to     VALUE="@@MV_PAGE@@">
<INPUT TYPE=hidden NAME=mv_action        VALUE=back>

<TABLE BORDER=0><TR><TD VALIGN=TOP>

[query list=1 sql="select * from options where sku='[filter op=sql interpolate=1][cgi item_id][/filter]' and o_group is not null"]
[list]
[if-sql-data options o_group]
[calc] $Scratch->{mod_code} = q{[sql-code]}; $Scratch->{mod_code} =~ s/-/_/g; return;[/calc]
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3 BGCOLOR="[sql-alternate 2]__UI_T_ROW_EVEN__[else]__UI_T_ROW_ODD__[/else][/sql-alternate]">
<TR><TD VALIGN=CENTER>Name: <INPUT TYPE=text SIZE=20 NAME="opt_group_[scratch mod_code]" VALUE="[filter entities][sql-param o_group][/filter]">

<A HREF="[area href='@@MV_PAGE@@'
               form='deleterecords=1
                     ui_delete_id=[sql-code]
                     item_id=[cgi item_id]
                     mv_data_table=options
                     mv_click=db_maintenance
                     mv_action=back
                     mv_nextpage=@@MV_PAGE@@
                    '
         ]"><IMG SRC="delete.gif" ALT="[L]Delete[/L]" ALIGN=CENTER BORDER=0></A>
<br>[L]Label[/L]: <INPUT TYPE=text SIZE=20 NAME="opt_label_[scratch mod_code]" VALUE="[filter entities][sql-param o_label][/filter]">
<INPUT TYPE=hidden NAME="reset_[scratch mod_code]" VALUE="[filter entities][sql-param o_label][/filter]">
<script><!--
document.write('<br><INPUT TYPE=checkbox [sql-calc]q{[sql-param o_label]} eq q{[sql-param o_group]} ? 'CHECKED' : undef;[/sql-calc]\n' +
'	onClick="if (this.checked) { this.form.opt_label_[scratch mod_code].value = this.form.opt_group_[scratch mod_code].value; } else { this.form.opt_label_[scratch mod_code].value = this.form.reset_[scratch mod_code].value; }">\n' +
'<font size=2>[L]Set label to name[/L]</font>');
// -->
</script>
</TD></TR>
[tmp o_value][perl]
    my @vals = split(',',q{[sql-param o_value]});
    map { s/[\r\n]//g; } @vals;
    return join("\n",@vals);
[/perl][/tmp]

<TR><TD>
<TEXTAREA ROWS=5 COLS=30 NAME="opt_value_[scratch mod_code]">[scratch o_value]</TEXTAREA><br>
[page href="admin/flex_editor"
		form="
			mv_data_table=options
			item_id=[sql-code]
			ui_return_to=admin/item_option
			ui_return_to=item_id=[cgi item_id]
			ui_data_fields=code o_widget o_width o_height
		"]Widget type edit</A>
</TD></TR>
</TABLE>
[/if-sql-data]
[/list]
[/query]

<BR><BR><BR>
[button text="[L]Commit Changes[/L]"]
mv_nextpage=admin/item
[/button]

</TD><TD><PRE>                          </PRE></TD><TD VALIGN=TOP>

<B>[L]Create a new option[/L]:</B><BR>
[L]Name[/L]: <INPUT TYPE=text SIZE=20 NAME="opt_group_" VALUE="">
<br>[L]Label[/L]: <INPUT TYPE=text SIZE=20 NAME="opt_label_">
<script><!--
document.write('<br><INPUT TYPE=checkbox\n' +
'	onClick="if (this.checked) { this.form.opt_label_.value = this.form.opt_group_.value; } else { this.form.opt_label_.value = \'\'; }">\n' +
'<font size=2>[L]Set label to name[/L]</font>');
// -->
</script>
<BR>
<TEXTAREA ROWS=5 COLS=30 NAME="opt_value_"></TEXTAREA>
<BR>
[button text="[L]Create option[/L]"][/button]
<BR><BR>

<HR>

<BR><BR><B>[L]Clone an existing option set[/L]:</B><BR>

[query
	list=1
	prefix=clone
	sql="select DISTINCT sku from [cgi mv_data_table] where o_group != ''"
	more=1]
<SELECT NAME=ui_clone_id>
<OPTION VALUE=""> --
[list]
[if-clone-data options o_enable]
<OPTION VALUE="[clone-code]">[clone-filter 20][clone-description][/clone-filter]
[/if-clone-data]
[/list]
</SELECT>[more-list]<BR>[more]<BR>[/more-list][/query]&nbsp;[button text="[L]Clone options[/L]"]ui_clone_options=1[/button]<BR>
</FORM>

</TD></TR></TABLE>