Gossamer Forum
Quote Reply
my_image... new mod
As I am just now getting more time to continue updated from links -> linksSQL, I have created a mod that lets a user set his or her own image...

The original worked with cookies: http://www.magicdirectory.com/...

This one works with the SQL database (and cookies since a user login is required): http://www.magicdirectory.com/linksSQL/...

Note: This works with or without community installed...


********Installation************

- create a field in your linksSQL table defintions called 'Image'... (Text, char(20) -- depending on your needs)


Everything else pretty much works off of that.


Here is the cgi file:

Code:

#!/usr/bin/perl
#================================
use strict;
use lib '/your pathss....;
use Links qw/:objects/;
use Links::SiteHTML;
Links::init('/your paths...');
Links::init_user();

my $path = "you path to images directory";

local $SIG{__DIE__} = \&Links::fatal;
main();
sub main {
#---------------------------------------------------
#
my $do = GT::CGI->param('do');
# check to see if your logged in
if (!$USER) {
if ($do eq "display") {
print $IN->header();
print qq|<img src="$path/myimage.gif" border=0>\n|;
exit;

}
else {
print $IN->redirect('http://www.magicdirectory.com/cgi-bin/linksSQL/user.cgi');
}
}
if ($do eq "display") {
display();
}
elsif ($do eq "edit") {
edit();
}
else {
print $IN->header();
print Links::SiteHTML::display('my_image');
}
}
sub display {
# --------------------------------------------------------
# get the image from the user database
my ($table, $image);
$table = $DB->table('Users');
$image = $table->select(['Image'], { Username => $USER->{Username} } )->fetchrow;
# print the output
print $IN->header();
print qq|<a href="$CFG->{db_cgi_url}/myimage.cgi">\n|;

if ($image eq "none") {
print qq|<img src="$path/myimage.gif" border=0>|;

}
elsif ($image) {
print qq|<img src="$path/f$image.gif" border=0>|;

}
else { print "Error getting the image from the database!"; }
print "</a>\n";
}
sub edit {
# --------------------------------------------------------
#define your path
my $new_image = GT::CGI->param('image');
my $image;
if ($new_image eq "none") {
$image = "No image has been set!\n";
}
else {
$image = qq|<img src="$path/f$new_image.gif" border=0>\n|;
}
# update the user table
my ($table, $update);
$table = $DB->table('Users');
$update = $table->update( { Image => $new_image }, { Username => $USER->{Username} } );
# print the output
my $rec;
$rec->{image} = $image;
print $IN->header();
print Links::SiteHTML::display('my_image_success', $rec);
}


I have this setup for my needs. I use myimage.gif for the blank image, and I use f(magician name).gif for the rest of them. Obviously this can be easily altered to what you might want.

I also use 2 templates... my_image, and my_image_success...

my_image contains pictures of your image and ratio buttons to select it.

You will need to submit the form to the cgi script (myimage.cgi) with:

<input type=hidden name=do value=edit>


The image success template just says Thank You and uses <%image%> to print the image.

(I would show you my templates, but since they are so simple I don't feel like posting them.)



I have not covered errors very well and I have not optimized the code, but any ideas, suggestions, or tweaks are greatly appreciated.

This mod is very simple, but I hope someone can find it useful...

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] my_image... new mod In reply to
jdgamble wrote:
As I am just now getting more time to continue updated from links -> linksSQL, I have created a mod that lets a user set his or her own image...

The original worked with cookies: http://www.magicdirectory.com/...

This one works with the SQL database (and cookies since a user login is required): http://www.magicdirectory.com/linksSQL/...

Note: This works with or without community installed...


********Installation************

- create a field in your linksSQL table defintions called 'Image'... (Text, char(20) -- depending on your needs)


Everything else pretty much works off of that.


Here is the cgi file:

Code:


#!/usr/bin/perl
#================================
use strict;
use lib '/your pathss....;
use Links qw/:objects/;
use Links::SiteHTML;
Links::init('/your paths...');
Links::init_user();

my $path = "you path to images directory";

local $SIG{__DIE__} = \&Links::fatal;
main();
sub main {
#---------------------------------------------------
#
my $do = GT::CGI->param('do');
# check to see if your logged in
if (!$USER) {
if ($do eq "display") {
print $IN->header();
print qq|<img src="$path/myimage.gif" border=0>\n|;
exit;

}
else {
print $IN->redirect('http://www.magicdirectory.com/cgi-bin/linksSQL/user.cgi');
}
}
if ($do eq "display") {
display();
}
elsif ($do eq "edit") {
edit();
}
else {
print $IN->header();
print Links::SiteHTML::display('my_image');
}
}
sub display {
# --------------------------------------------------------
# get the image from the user database
my ($table, $image);
$table = $DB->table('Users');
$image = $table->select(['Image'], { Username => $USER->{Username} } )->fetchrow;
# print the output
print $IN->header();
print qq|<a href="$CFG->{db_cgi_url}/myimage.cgi">\n|;

if ($image eq "none") {
print qq|<img src="$path/myimage.gif" border=0>|;

}
elsif ($image) {
print qq|<img src="$path/f$image.gif" border=0>|;

}
else { print "Error getting the image from the database!"; }
print "</a>\n";
}
sub edit {
# --------------------------------------------------------
#define your path
my $new_image = GT::CGI->param('image');
my $image;
if ($new_image eq "none") {
$image = "No image has been set!\n";
}
else {
$image = qq|<img src="$path/f$new_image.gif" border=0>\n|;
}
# update the user table
my ($table, $update);
$table = $DB->table('Users');
$update = $table->update( { Image => $new_image }, { Username => $USER->{Username} } );
# print the output
my $rec;
$rec->{image} = $image;
print $IN->header();
print Links::SiteHTML::display('my_image_success', $rec);
}



I have this setup for my needs. I use myimage.gif for the blank image, and I use f(magician name).gif for the rest of them. Obviously this can be easily altered to what you might want.

I also use 2 templates... my_image, and my_image_success...

my_image contains pictures of your image and ratio buttons to select it.

You will need to submit the form to the cgi script (myimage.cgi) with:

<input type=hidden name=do value=edit>


The image success template just says Thank You and uses <%image%> to print the image.

(I would show you my templates, but since they are so simple I don't feel like posting them.)



I have not covered errors very well and I have not optimized the code, but any ideas, suggestions, or tweaks are greatly appreciated.

This mod is very simple, but I hope someone can find it useful...

Thanks,
Quote Reply
Re: [courierb] my_image... new mod In reply to
Hi,

Was there meant to be a reply? All I see is a long quote :D

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!