Gossamer Forum
Home : Products : Gossamer Links : Pre Sales :

Please help on Attachment & Modify

Quote Reply
Please help on Attachment & Modify
Hi all, tried it now for the last 15 hours, but i got no solution how to let users modify their upload.
I think its only a small thing, but i really dont understand the ref-things:

In add.cgi there is:


# Connect to the database.
$val = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Validate.def";

# This will set system fields like Validated to their proper values.
foreach $key (keys %{$LINKS{add_system_fields}}) {
$in->param(-name => $key, -value => $LINKS{add_system_fields}->{$key});
}

# Set date variable to today's date.
$today = $val->get_date();
$in->param ( -name => 'Add_Date', -value => $today );
$in->param ( -name => 'Mod_Date', -value => $today );
$in->param ( -name => 'Mode' , -value => 'Validate' );

# Backward compatibility..
$in->param ( -name => 'Contact_Name', -value => $in->param('Contact Name'));
$in->param ( -name => 'Contact_Email', -value => $in->param('Contact Email'));
$in->param ( -name => 'Date', -value => $in->param('Add_Date'));

# # Validate for Confirm first!
$rec = &cgi_to_hash ( $in );
$id = $val->add_record_confirm ( $rec, $in );

...

meaning all the stuff resides in $in->param ...
then we set $rec = &cgi_to_hash and pass BOTH $rec and $in to add_record_confirm (or later to add_record) in dbsql.
Seems for my that we pass a list of values and a list of refs ???

I have some further modifications in add.cgi and dbsql.pm, but that code works fine for me to handle uploads. (ask if you need the code)

BUT: in modify.cgi we have:

# Search for the link.
$db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
$links = $db->query ( { ID => $in->param('ID'), ww => 1 } );
($db->hits > 0) or &site_html_modify_failure ({ Category => $category, error => "CatID unbekannt!", %in}, $homepage, $dynamic ) and return;

# Convert to hash.
$links = $db->array_to_hash ( ${$links}[0] );
foreach $key (keys %{$links}) {
$original->{$key} = $links->{$key};
exists $LINKS{add_system_fields}->{$key} and next;
$links->{$key} = $in->param($key);
}
$links->{'Add_Date'} = $original->{'Add_Date'};
$links->{'Mod_Date'} = $db->get_date;
$links->{'LinkID'} = $original->{'ID'};
$links->{'Mode'} = 'Modify';

# Backward compatibility..
$links->{'Contact_Name'} = $in->param('Contact Name');
$links->{'Contact_Email'} = $in->param('Contact Email');

# Check that the record hasn't been added already.
$val = new Links::DBSQL "$LINKS{admin_root_path}/defs/Validate.def";
$val->query ( { LinkID => $links->{'LinkID'}, ww => 1 } );
$val->hits and &site_html_modify_done( { Category => $category, error => "Ihr Änderungswunsch ist bereits vermerkt.
Bitte versuchen Sie es nach dem nächsten Update wieder!", %in }, $dynamic) and return;

# Validate the record. ## Über add_record_confirm!!!

$val->add_record_confirm ($links) or &site_html_modify_failure ( { Category => $category, error => $Links::DBSQL::error, %in}, $homepage, $dynamic) and return;
...

So here we handle things with $links and pass only $links to add_record_confirm (and later add_record)

Cause my code runs with the add.cgi; i think i must pass the same for the modify.cgi; but i really dont know how:

i have tried it with:

$links->{'ATTACH-ADD'} = $in->param('ATTACH-ADD');

and with:

$val->add_record_confirm ($links, $in)

But then i got:

Can't use string ("G:\Server-HWF\2D.jpg") as a symbol ref while "strict refs" in use at admin/Links/DBSQL.pm line 896.
while try to upload.


What i do in dbsql is:

my $format;

if ($rec_r->{'ATTACH-ADD'} ){
$rec_r->{'ATTACH-ADD'}=~ /^[\w-:\.\/\\]+\.(jpg|gif)$/i;
$format = $1;}
if ($rec_r->{'ATTACH-ADD1'} ){
$rec_r->{'ATTACH-ADD1'} =~ /^[\w-:\.\/\\]+\.(jpg|gif)$/i;
$format = $1;}
if ($rec_r->{'ATTACH-ADD2'} ){
$rec_r->{'ATTACH-ADD2'} =~ /^[\w-:\.\/\\]+\.(jpg|gif)$/i;
$format = $1;}
if ($rec_r->{'ATTACH-ADD3'} ){
$rec_r->{'ATTACH-ADD3'} =~ /^[\w-:\.\/\\]+\.(jpg|gif)$/i;
$format = $1;}

$self->attach_file ($id, "ATTACH-ADD","A", $format, $in) if ($self->{attach_dir} and (ref $in eq 'CGI'));
$self->attach_file ($id, "ATTACH-ADD1","B", $format, $in) if ($self->{attach_dir} and (ref $in eq 'CGI'));
$self->attach_file ($id, "ATTACH-ADD2","C", $format, $in) if ($self->{attach_dir} and (ref $in eq 'CGI'));
$self->attach_file ($id, "ATTACH-ADD3","D", $format, $in) if ($self->{attach_dir} and (ref $in eq 'CGI'));


So as i understand the things right;
i must have $links while $in is passed tru that values and so i need the value

$in->param('ATTACH-ADD') somehow to $links with the function cgi_to_hash

or i try now all things in $links to $in->param.. and after this do the same coding than in add.cgi.

Heaven helps, i dont know if someone could understand this.

Robert