Gossamer Forum
Quote Reply
If not modify, add
I posted the following in Discussions, but upon reflection, I believe what I'm looking for amounts to a hack, so I turn to the more knowledgable for suggestions on how to do this:

I would like to create a situation where, when someone chooses to execute the Modify A Link routine and a link does not exist, the Add a Link routine executes, instead of the current practice of displaying an Error Page stating a link does not exist.

In concept, this appears fairly simple. The program appears to know from session/cookie data who is making the modify request, as the error message tells me clearly there are no links to modify. All I want to do is make an automatic assumption: when there are no links to display/list, redirect the request from modify.cgi to add.cgi. This is, in fact, such a logical assumption that many DBMS programs do this on their own.

Can someone show me what is needed here?


Alan Frayer
Don't just read the news - make the news!
Your World News - http://yourworldnews.frayernet.com
Quote Reply
Re: [afrayer] If not modify, add In reply to
I think more information may be needed first about how your site is set up. How are people getting to the modify page if the link doesn't exist?
Quote Reply
Re: [afinlr] If not modify, add In reply to
In Reply To:
I think more information may be needed first about how your site is set up. How are people getting to the modify page if the link doesn't exist?

I have a profile page that a logged in user accesses with an intended link to modify.cgi?d=1 where, when a link exists, the user can modify his ONLY link (1:1 ratio between users and links). I see from testing that the program recognizes the existing link and provides the necessary process to change the data.

When the user does not have a link, I want the user to be provided the process by which he can create the single link (add.cgi?d=1), after which the user would be given to modify.cgi?d=1 for all subsequent clicks.

So, one profile link serves double duty for the user.

I literally know enough Perl to be dangerous.

Pardon the lack of line numbers, as I printed the code from a text editor.
I read in the Modify.pm,

sub _handle {
(comments removed for brevity)
my $link_id = $IN->param('LinkID');
CASE: {
$IN->param('modify') and do { _modify(); last CASE; };
}
}

sub _modify {
(comments removes for brevity)
# If payment is enabled and we are processing a payment
if ($CFG->{payment}->{enabled} and $IN->param('process_payment')) { (not true, so...)
}
# Otherwise, modify the link
else {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_modify_link', \&modify_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('modify', $results);
}
...

This appears to me to be the relevant code, if I read this right.

An error situation does exist; the link doesn't exist and this is the first error handler that is encountered once $link_id is found to be NULL (admittedly, I could have read the code wrong).

Now, what I want to do is check for $link_id (in the sub _handle routine, perhaps), and if I find the link doesn't exist, I'd like to exit to the add.cgi?d=1 and start over.

Might someone tell me what code to insert where (and explain it, if possible), so I can reach my intended goal?

Alan Frayer
Don't just read the news - make the news!
Your World News - http://yourworldnews.frayernet.com
Quote Reply
Re: [afrayer] If not modify, add In reply to
OK - I think I understand. Personally the way I would approach this would be to have a global on the profile page that looks up that user to see whether they own a link. If they do, create a link to the modify page and if they don't create a link to the add page. This wouldn't involve editing the core code and you could change the wording of the link.
Quote Reply
Re: [afinlr] If not modify, add In reply to
In Reply To:
OK - I think I understand. Personally the way I would approach this would be to have a global on the profile page that looks up that user to see whether they own a link. If they do, create a link to the modify page and if they don't create a link to the add page. This wouldn't involve editing the core code and you could change the wording of the link.
Not bad, except the "profile" page is simple HTML (all the testing occured before they got to that point). Hmmm... if I knew how to create a CGI that would do the test and redirect the user to either modify.cgi?d=1 or add.cgi?d=1, that would avoid a change to the core code. I don't know enough Perl to create the file from scratch, but I suppose that would be the more appropriate idea...

I understand the reluctance to change the core code, but I'm also a little surprised the core code didn't have this already, as it doesn't break the code for other purposes... there is no reason to use Modify when a link doesn't already exist, and the desired code doesn't cause problems when links do exist. All it really does is eliminate an error condition.

Still, admittedly, it would make upgrades difficult unless GT chose to include the code in the next release.

I don't suppose anyone would be willing to volunteer a CGI file that would act as the traffic cop, so to speak? The file would be called from a link on an HTML page and would have to take an already logged in user to modify.cgi?d=1, or to add.cgi?d=1 if the user doesn't have a Link to Modify.

Otherwise, I need to find a book that will quickly teach me enough Perl to write it myself...

Alan Frayer
Don't just read the news - make the news!
Your World News - http://yourworldnews.frayernet.com
Quote Reply
Re: [afrayer] If not modify, add In reply to
I'd be happy to write the global for you. What do you mean by the profile page is pure html? Is it written by a template in Links?
Quote Reply
Re: [afinlr] If not modify, add In reply to
In Reply To:
I'd be happy to write the global for you. What do you mean by the profile page is pure html? Is it written by a template in Links?
The page I refer to as a "profile" page is written outside GT, using a web site editing tool. The web site has about 100+ pages of non-GT content, and I have blended into it Links SQL, Forums, and Community. The users are not handed to Links SQL directly, but are presented with HTML links to the desired features via HTML front ends. Browsing is not desired, and the template pages being displayed are heavily modified to remove links to features not desired.

The user logs in through Community, but instead of seeing the Main Community page, the user is sent back to the host site (generating a 2nd cookie on the way, so the login can be used for accessing other, secured, pages).

The page the user is returned to is what I've been calling the "profile" page, because from that page the user can reach his password and, ultimately, his public profile (what you and I know as his Link). This page forms the hub to the web site, with HTML links going to all kinds of places on the site.

I can put the proposed CGI page in with the rest of the Links SQL CGI pages, make a simple HTML call from my "profile" page, and hopefully the CGI will learn what it needs and redirect the user to the appropriate tool. I know enough to edit path information, if needed, but I've had no training in Perl... I've simply spent years sorting through database application programming code and HTML code. Reading the stuff isn't nearly as tricky as writing it.

Thanks for the help!

Alan Frayer
Don't just read the news - make the news!
Your World News - http://yourworldnews.frayernet.com