Gossamer Forum
Home : Products : Gossamer Links : Discussions :

print.cgi modification

Quote Reply
print.cgi modification
I found a great mod listed under the resources section on the GT web site. Unfortunately, it looks like the mod was writting for versions 1.x of Links SQL. The mod, print.cgi, looks fairly easy to setup... however I think several of the perl modules bundled with Links SQL have changed.

Can someone take a look at this code for me and see what needs to be modified? It should be fairly easy.

Code:
#!/usr/bin/perl
# ==============================================================
# -------------
# Links SQL
# -------------
# Links Manager
#
# Author: Alex404
# Email: silberling@t-online.de
#
# for Version: 1.x of Links SQL (c)Gossamer Threads Inc
# ============================================================== # Load required modules.
# ---------------------------------------------------
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links::DBSQL;
use Links::DB_Utils;
use Links::HTML_Templates;
use strict;
use vars qw!$LINKDB $CATDB $GRAND_TOTAL $USE_HTML!;
&main;
# ==============================================================



sub main {
# --------------------------------------------------------------
# Wrap in a subroutine to prevent possible mod_perl probs.
#
my $in = new CGI;
my $id = $in->param('ID') || undef;

# Check the parameter

$id =~ s/[^0-9]//g;

if ($id > 0 ) { &print_page($in,$id) }
else {
print $in->header();
&site_html_error ( { error => "Sorry, I'm not sure what page you are asking for: '$id'" }, $in);
return;
}
}



sub print_page {
# --------------------------------------------------------
# This routine build a single page for printout
#
my ($in,$id) = @_;
my ($link_db, $cat_db, $link, $category, $category_name, $total);




# Create our database objects.



$link_db = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Links.def";
$cat_db = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Category.def";
$link = $link_db->get_record ($id, 'HASH');



# Check if the link exists

if (!$link) {
print $in->header();
&site_html_error ( { error => "Sorry, we don't seem to have link '$id'" }, $in);
return;
}



# We seem to have a valid link

$category = $cat_db->get_record ($link->{'CategoryID'}, 'HASH');
$category_name = $category->{'Name'};
$total = $link_db->total();



print $in->header();
print &print_html ($link,{Total =>$total, CategoryName => $category_name});
}
1;
Code:
sub print_html {
# --------------------------------------------------------
# This routine will build a single page per link for printing
#
# be shure to add it to @EXPORT array in the beginning of HTML_Templates.pm
#
my ($rec, $tags) = @_;
my $template =undef;
my $dynamic = undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";
# Set new and pop to either 1 or undef for templates.
($rec->{'isNew'} eq 'Yes') ? ($rec->{'isNew'} = 1) : (delete $rec->{'isNew'});
($rec->{'isChanged'} eq 'Yes') ? ($rec->{'isChanged'} = 1) : (delete $rec->{'isChanged'});
($rec->{'isPopular'} eq 'Yes') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});
#
defined $dynamic and &load_user ($dynamic, $tags);
my $output = &load_template ('print.html', {%$tags, %$rec, %GLOBALS }, undef, undef );
defined $dynamic and &clean_output($dynamic, \$output);
return $output;
}


Thanks,



Jaron

Last edited by:

pugdog: Mar 17, 2002, 11:11 AM
Quote Reply
Re: [jlbrass] print.cgi modification In reply to
Hi Wink

have you resolved your problem...If yes you could help me.

I would like to create a print.cgi page to print each one of my links (I have LSQL 2.1)

What do I have to do?



thanks

FMP
Quote Reply
Re: [fmp] print.cgi modification In reply to
Actually, it might be as easy as creating a new link.html, such as link_print.html, and then calling page.cgi?p=link_print?d=0 (for static sites) or d=1 for dynamic sites.

The problem would be that in site_HTML.pm the "link" routine does some extra processing.

You could just copy that routine into whatever you call the printable link template.

It would not be portable between upgrades, but it's so simple that it should be easy to recreate (just duplicate the link subroutine in site_HTML.pm

Because there are so many other things that _could_ go intocreating a printable template, this would be a good plugin, for someone who wanted to play with something useful, but fairly simple, since it would not be "coding" thatwas the problem, but more of tweaking interface issues.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] print.cgi modification In reply to
HiWink

I have created the link_print template
I have also altered siteHTML.pm

then I just have to call the printable page


page.cgi?p=link_print?d=0


I would like to print the link with id=13

wich url do I have to call ? where do I specify this ID?

ThanksWink

FMP
Quote Reply
Re: [fmp] print.cgi modification In reply to
Hi,

To load link id 13 call:

page.cgi?p=link_print&d=0&ID=13

Then add a global:

link_info => sub {
return $DB->table('Links')->select( { ID => $_[0]->{ID} })->fetchrow_hashref;
}

and add: <%link_info%> at the top of link_print.html.

Cheers,

Alex
--
Gossamer Threads Inc.