[ic] Adding Images to Tree Mod

Dog Tags interchange-users@icdevgroup.org
Mon Jun 24 05:50:00 2002


Hi All

Would anyone know how to display an image next to each category and subcat in the Tree Mod ??

My guess is that you could add an image field to the tree table and that the values in the image field in the category table could be pulled over during the Tree Building process. I'm just not sure how to get the tree building code to pull the values from the category table.

Here is the Tree Building code:

[code][perl tables="products tree"]

    my $db = $Db{products};
    my $ary = $db->query('select sku,comb_category from products');
    my $out = '';
    my $code = '00000';
    my $cc  = '0000';
    my %done;
    my @levels;
    foreach $row ( @$ary) {
        my ($sku, $cat) = @$row;
        next if $done{$cat};
        my $parent = 'TOP';
        my @parts = split /:/, $cat;
        my $combname = '';
        for( my $i = 0; $i < @parts; $i++) {
            my $name = $parts[$i];
            my $comb = join ":", @parts[0 .. $i];
            my $level = $levels[$i] ||= {};
       ## if(! $level->{$name}) {
            if(! $level->{$comb}) { 
            # Changed from $name to $comb
            ##    $level->{$name} = [ ++$code, $parent, ++$cc, $name, $comb ];
                $level->{$comb} = [ ++$code, $parent, ++$cc, $name, $comb ]; 
            # Changed $name to $comb 

                $parent = $cc;
            }
            else {
          ##  $parent = $level->{$name}->[2];
                $parent = $level->{$comb}->[2]; 
            # Changed $name to $comb 
            }
        }
    }

    my $tdb = $Db{tree};
    $tdb->query('delete from tree');
    my @flds = qw/parent_fld child_fld name category/;
    my $count++;
    for(@levels) {
        my $hash = $_;
        for(sort keys %$hash) {
            my $rec = $hash->{$_};
            my $code = shift @$rec;
            $tdb->set_slice($code, \@flds, $rec);
	    $count++;
        }
    }
    return $count;
[/perl][/code]

Here is the Tree Populating code:

[code]    [flag type=write table=products]
    [perl tables=products]
	my $db = $Db{products};
	my $ary = $db->query('select sku,prod_group,category from products');
	my $out = '';
	foreach $row ( @$ary) {
	    my ($sku, $pg, $cat) = @$row;
	    $db->set_field($sku, 'comb_category', "$pg:$cat")
		and $out .= "$sku = $pg:$cat<br>\n";
	}
	return $out;
    [/perl][/code]

And, here is the final Tree Display code:

[code]<table>
[if cgi toggle]
    [calc]
	my $par = '[data table=tree col=parent_fld key="[cgi toggle]"]';
	delete $Scratch->{memo} if $par eq 'TOP';
	return;
    [/calc]
[/if]

[tree   start=TOP
		table=tree
		master=parent_fld
		subordinate=child_fld
		autodetect=1
		toggle=toggle
		memo=memo
		collapse=collapse
		explode=explode
		spacing=4
		]
	<tr>
	<td>
	[if-item-param mv_level]
			[item-calc]
					return '&nbsp' x [item-param mv_spacing];
			[/item-calc]
	[/if-item-param]
	[if-item-param mv_children]
		<A HREF="[area href=@@MV_PAGE@@ form='toggle=[item-param code]']">
		[item-calc] $Scratch->{memo}{'[item-code]'} ? '-' : '+' [/item-calc]
		</A>
	[/if-item-param]
		[page search="
			fi=products
			st=db
			bs=1
			tf=comb_category
			sf=comb_category
			se=[item-param category]
			ml=10
		"][item-param name]</A>
	</td>

	</tr>
[/tree]
</table>[/code]

I appreciate any help. Thanks! :) :)
-- 
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Save up to $160 by signing up for NetZero Platinum Internet service.
http://www.netzero.net/?refcd=N2P0602NEP8