Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Mod Help: Can't get Category ID

Quote Reply
Mod Help: Can't get Category ID
Hi,

I've written the enclosed sub to modify links that have been set as 'Enhanced' for more than 365 days.

It creates a modify form for each link, allowing me to decide which links I want to demote.

The problem I've got is that I can't seem to get the CategoryID number into the modify form (the link modification won't take without it).

Here's the generated HTML output:

Code:

<form method="POST" action="admin.cgi" name="admin">
<input type="hidden" name="db" value="Links">
<input type="hidden" name="do" value="modify_record">
<input type="hidden" name="ID" value="63">
<input type="hidden" name="CatLinks.CategoryID" value="ARRAY(0x8719a6c)">
<strong>63: LKW Walter</strong><br>
Added: 2002-08-16 - Difference: <em>1606</em>
isTop: <select name="isTop"><option value="3" selected>3</option></select>
<input type=submit value="Modify Record">
</form>


... and here's the sub ...

Code:


sub expire_enhanced {
# ------------------------------------------------------------------
# Check for links that have been enhanced for 365 days or more and
# change them to basic links
use Date::Simple ();
my $output = '';
my $today = GT::Date::date_get();
my $todaydate = Date::Simple->new($today);
my $cat_link = $DB->table('CatLinks');
my $sth = $DB->table('Links')->select( 'ID', 'Title', 'isValidated', 'Description', 'isTop', 'Add_Date');
print $IN->header();
while (my ($id, $title, $isval, $desc, $istop, $add) = $sth->fetchrow) {
my $adddate = Date::Simple->new($add);
my $datediff = $todaydate - $adddate;
if ($istop == 2) {
if ($datediff >= 365) {
my $catid = [$cat_link->select('CategoryID', { LinkID => $id })->fetchrow];
$output .= qq~
<form method="POST" action="admin.cgi" name="admin">
<input type="hidden" name="db" value="Links">
<input type="hidden" name="do" value="modify_record">
<input type="hidden" name="ID" value="$id">
<input type="hidden" name="CatLinks.CategoryID" value="$catid">
<strong>$id: $title</strong><br>
Added: $adddate - Difference: <em>$datediff</em>
isTop: <select name="isTop"><option value="3" selected>3</option></select>
<input type=submit value="Modify Record">
</form>
~;
}
}
}
return { output => $output };
}


Any idea where I've gone wrong?

Thanks in advance Smile
Shaun
Quote Reply
Re: [qango] Mod Help: Can't get Category ID In reply to
Hi Shaun,

Please just try this
Code:
sub expire_enhanced {
# ------------------------------------------------------------------
# Check for links that have been enhanced for 365 days or more and
# change them to basic links
use Date::Simple ();
my $output = '';
my $today = GT::Date::date_get();
my $todaydate = Date::Simple->new($today);
my $cat_link = $DB->table('CatLinks');

$cat_link->select_options("Limit 1");

my $sth = $DB->table('Links')->select( 'ID', 'Title', 'isValidated', 'Description', 'isTop', 'Add_Date');
print $IN->header();
while (my ($id, $title, $isval, $desc, $istop, $add) = $sth->fetchrow) {
my $adddate = Date::Simple->new($add);
my $datediff = $todaydate - $adddate;
if ($istop == 2) {
if ($datediff >= 365) {
my ($catid) = $cat_link->select('CategoryID', { LinkID => $id })->fetchrow_array;
$output .= qq~
<form method="POST" action="admin.cgi" name="admin">
<input type="hidden" name="db" value="Links">
<input type="hidden" name="do" value="modify_record">
<input type="hidden" name="ID" value="$id">
<input type="hidden" name="CatLinks.CategoryID" value="$catid">
<strong>$id: $title</strong><br>
Added: $adddate - Difference: <em>$datediff</em>
isTop: <select name="isTop"><option value="3" selected>3</option></select>
<input type=submit value="Modify Record">
</form>
~;
}
}
}
return { output => $output };
}
Hope that helps!

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Mod Help: Can't get Category ID In reply to
Dat,

Thanks, that works great Smile

Cheers,
Shaun
Quote Reply
Re: [qango] Mod Help: Can't get Category ID In reply to
Hi,

I have a similar problem.

I use a gobal, which gives me the field Kundennummer (Cutomer-no.) from Users-table, and I want to use it in a template detailed.html

My global is called <%Owner%>
Code:
sub {
my $tags = shift;
my $db = $DB->table('Users');
my $sth = $db->select ({ 'Username' => $tags->{LinkOwner} })->fetchrow_hashref;
return my $out = $sth->{Kundennummer};
}

In the template I get that show correct, but if I want to write it in a table like Links , I get this:
in a varchar-field: CODE(0x877 ...
in a int-field: 0

I tried using Limit 1 and fetchrow_array like decribed, but I get an error because array is not allowed because of strict ?!

Using <%DUMP%> to check that, my value for <%Owner%> is always sub { () } , what's wrong.
Thanks a lot for your help,
Christian