[ic] Nested Loops - Newbie

interchange-users@interchange.redhat.com interchange-users@interchange.redhat.com
Tue Nov 13 01:41:01 2001


This is a multi-part message in MIME format.

------=_NextPart_000_0284_01C16C6A.34BFC200
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

> Hi I am trying to get it so that a menu link for a category only links to
> products in that category and in the area it is displayed under.

Mike posted the attached file that not only makes this process work but it
allows for creating custom cat link searches effortlessly. I have heavily
tested this in 4.8.2 and it works beautifully.

Just dump it into catalog/pages/admin directory of any catalog to try it
out.

Delete it if you want to revert to the default layout_auto.html page. (I
don't think so)

Click on 'Design' and 'auto populate' to use it.






------=_NextPart_000_0284_01C16C6A.34BFC200
Content-Type: text/html;
	name="layout_auto.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="layout_auto.html"

<!-- saved from url=3D(0022)http://internet.e-mail -->
[set page_title]Layout auto-populate[/set]
[set ui_class]Design[/set]
[set page_banner]Layout Editor: Organize your site into categories[/set]
[set page_perm]layout=3De[/set]
[set help_name]layout.edit[/set]
[set icon_name]icon_pages.gif[/set]
[tmp meta_header]
	[include include/table_populator]
	<SCRIPT LANGUAGE=3DJavaScript>
	  function change_ta (ta_field, selector) {
	  	if(selector =3D=3D 'complex') {
			ta_field.rows =3D 20;
			ta_field.disabled =3D false;
		}
		else {
			ta_field.rows =3D 1;
			ta_field.disabled =3D true;
		}
		return;
	  }
	</SCRIPT>
[/tmp]
[seti ui_body_extra][/seti]

@_UI_STD_HEAD_@
<!-- ----- BEGIN REAL STUFF ----- -->

<form action=3D"[area __UI_BASE__/layout]" method=3DGET>
<input type=3Dhidden name=3Dmv_action value=3Dback>

<table border=3D0 __UI_T_PROPERTIES__>
<tr>
<td colspan=3D2 bgcolor=3D__UI_C_TOPBLOCKBAR__><img src=3D"bg.gif" =
width=3D__UI_MAIN_WIDTH__ height=3D1></td>
</tr>

<tr bgcolor=3D"__UI_C_INTBLOCK__">
<td width=3D25%>

1. Choose a table as the source:

</td>
<td>
[if !value area_table]
	[value name=3Darea_table set=3Dproducts hide=3D1]
	[value name=3Darea_column set=3Dprod_group hide=3D1]
	[value name=3Dcat_column set=3Dcategory hide=3D1]
[/if]
<select name=3D"area_table"
	onChange=3D"
		populateTable(
            this.form.area_table.options,
            this.form.area_column.options,
            =
this.form.area_table.options[this.form.area_table.selectedIndex].value
            );
		populateTable(
            this.form.area_table.options,
            this.form.cat_column.options,
            =
this.form.area_table.options[this.form.area_table.selectedIndex].value
            );
	"
size=3D1>
[loop list=3D"[list-databases]" option=3Darea_table]
	<OPTION VALUE=3D"[loop-code]">[loop-code]</OPTION>
[/loop]
</select>
</td>
</tr>
<tr>
<td>
2. Choose a column to populate areas:
</td>
<td>
<select name=3D"area_column">
<option value=3D""> -- none --
[loop list=3D"[db-columns table=3D'[value area_table]']" =
option=3Darea_column]
<option>[loop-code]
[/loop]
</select>
</td>
</tr>
<tr>
<td>
3. Choose a column to populate categories:
</td>
<td>
<select name=3D"cat_column">
<option value=3D""> -- none --
[loop list=3D"[db-columns table=3D'[value area_table]']" =
option=3Dcat_column]
<option>[loop-code]
[/loop]
</select>
</td>
</tr>
<tr>
<td>
4. Choose a search type:
</td>
<td>
<select name=3D"cat_type" =
onChange=3D"change_ta(this.form.search_code,this.form.cat_type.value)">
<option value=3D"narrow"> Narrow search (area and category match)
<option value=3D"simple"> Simple search (only category matches)
<option value=3D"complex"> Complex search (template substitution on =
below)
</select>
</td>
</tr>
<tr>
<td valign=3Dtop>
5. Complex search code:
</td>
<td>
NOTE: Not active unless complex search selected above.<br>
<textarea rows=3D1 cols=3D50 name=3Dsearch_code disabled=3Dtrue>
	fi=3Dproducts
	st=3Ddb
	co=3Dyes

	sf=3Dprod_group
	se=3D~PROD_GROUP~
	op=3Deq

	sf=3Dcategory
	se=3D~CATEGORY~
	op=3Deq

	sf=3Dinactive
	se=3D1
	op=3Dne

	rf=3Dsku

	va=3Dbanner_text=3D~BANNER_TEXT~
</textarea>
</td>
</tr>
<tr bgcolor=3D"__UI_C_INTBLOCK__">
<td>
6. Select the page class:
</td>
<td>
<INPUT NAME=3Dwhich_page VALUE=3Dall>
</td>
</tr>
<tr bgcolor=3D"__UI_C_INTBLOCK__">
<td>
7. Select the page area:
</td>
<td>
<INPUT NAME=3Dsel VALUE=3Dleft>
</td>
</tr>
<tr bgcolor=3D"__UI_C_INTBLOCK__">
<td>
8. Decide whether to remove previous settings:
</td>
<td>
<SELECT NAME=3Dnuke><OPTION VALUE=3D0>No <OPTION VALUE=3D1>Yes</SELECT>
</td>
</tr>
<tr>
<td>
9. Click this button to populate:
</td>
<td>
[button text=3D"Populate"]
[flag type=3Dwrite table=3D"area"]
[flag type=3Dwrite table=3D"cat"]
[seti ui_failure]
[perl tables=3D"area cat [cgi area_table]"]
	my $go_page =3D $CGI->{mv_nextpage};
	$CGI->{mv_nextpage} =3D '@@MV_PAGE@@';
	my $ptab =3D $CGI->{area_table}
		or return "no area source table";
	my $pdb =3D $Db{$ptab}
		or return "area source table bad";
	my $adb =3D $Db{area}
		or return "no area table";
	my $cdb =3D $Db{cat}
		or return "no cat table";
	my $acol =3D $CGI->{area_column};
	my $ccol =3D $CGI->{cat_column};
	if(! $acol and ! $ccol ) {
		return "no column to populate either";
	}

	my $selector =3D '';
	my $selcode =3D '';

	my %area_defaults =3D (
		name =3D> undef,
		which_page	=3D> $CGI->{which_page} || 'all',
		sort	=3D> '05',
		sel	=3D> $CGI->{sel} || 'left',
		display_type =3D> 'name',
	);
	my %catmap;
	my $narrow;
	my $lt;
	my $search_code;
	if($CGI->{cat_type} eq 'simple') {
		$lt =3D 'simple';
		$selector =3D 'category=3D~CATEGORY~';
		$search_code =3D '';
	}
	elsif($CGI->{cat_type} eq 'narrow') {
		$narrow =3D 1;
		$lt =3D 'simple';
		$selector =3D <<EOF;
category=3D~CATEGORY~
prod_group=3D~PROD_GROUP~
EOF
		$search_code =3D '';
	}
	else {
		$lt =3D 'complex';
		$selector =3D '';
		$search_code =3D $CGI->{search_code};
	}

	my %cat_defaults =3D (
		link_type =3D> $lt,
		selector =3D> $selector,
		search =3D> $search_code,
		sort	=3D> '05',
		display_type =3D> 'name'
	);

	if($CGI->{nuke}) {
		$adb->query('delete from area');
		$cdb->query('delete from cat');
	}
	if($acol) {
		$adb->config('AUTO_NUMBER', '1000') if ! $adb->config('_Auto_number');
		return "area column $acol doesn't exist"
			unless $pdb->column_exists($acol);
		my $ary =3D $pdb->query("select distinct $acol from $ptab order by =
$acol")
			or return "area column query failed";
		for(@$ary) {
			my ($area) =3D (@$_);
			my $key =3D $adb->set_row('');
			return "no autonumbering available" if ! $key;
			$catmap{$area} =3D $key;
			for(keys %area_defaults) {
				$adb->set_field($key, $_, $area_defaults{$_} || $area);
			}
		}
	}

	my %catdone;
	if($ccol) {
		$cdb->config('AUTO_NUMBER', '1000') if ! $cdb->config('_Auto_number');
		return "cat column $ccol doesn't exist"
			unless $pdb->column_exists($ccol);
		my ($ary, $fh) =3D $pdb->query(
								"select $acol, $ccol from $ptab order by $ccol",
								)
			or return "cat column query failed";
		foreach my $row (@$ary) {
			my $area =3D $row->[$fh->{$acol}];
			my $cat  =3D $row->[$fh->{$ccol}];
			my $donetag =3D $narrow ? "$area:$cat" : $cat;
			next if $catdone{$donetag}++;
			my $key =3D $cdb->set_row('');
			return "no cat autonumbering available" if ! $key;

			my %defaults =3D %cat_defaults;
			$defaults{name} =3D $cat;
			$defaults{sel} =3D $catmap{$area};
			$defaults{search} =3D~ s/~ (\w+) ~/$row->[$fh->{lc $1}]/gx;
			$defaults{selector} =3D~ s/~ (\w+) ~/$row->[$fh->{lc $1}]/gx;
		=09
			for(keys %defaults) {
				Log("setting col=3D$_ key=3D$key =3D $defaults{$_}");
				$cdb->set_field($key, $_, $defaults{$_});
			}
		}
	}
	$CGI->{mv_nextpage} =3D $go_page;
	my $out =3D $Tag->uneval( { ref =3D> \%catmap } );
	$out =3D~ s/,/,\n/g;
	#return '<XMP>' . $Tag->uneval( { ref =3D> \%catmap } ) . "</XMP";
	return;
[/perl]
[/seti]
[/button]
<BR>
</td>
</tr>

<tr>
<td colspan=3D2 bgcolor=3D__UI_C_TOPBLOCKBAR__><img src=3D"bg.gif" =
width=3D__UI_MAIN_WIDTH__ height=3D1></td>
</tr>

</table>

</form>


<!-- ----- END REAL STUFF ----- -->
@_UI_STD_FOOTER_@
<!-- page: @@MV_PAGE@@ -->







------=_NextPart_000_0284_01C16C6A.34BFC200--