Catalog

 view release on metacpan or  search on metacpan

lib/Catalog/tools/sqledit.pm  view on Meta::CPAN

#	    warn("replace $tag - $utable - $ufield - $uform");
	    my($desc) = $info->{$field};
	    &$func($field, $tag, $desc, $uform);
	}
    }
}

sub remove {
    my($self, $cgi) = @_;
    $self->{'cgi'} = $cgi;
    my($table) = $cgi->param('table');

    my($template) = $self->template("sqledit_remove");

    template_set($template->{'assoc'}, '_TABLE_', $table);
    template_set($template->{'assoc'}, '_SCRIPT_', $cgi->url(-absolute => 1));
    template_set($template->{'assoc'}, '_HIDDEN_', $self->hidden('primary' => $cgi->param('primary')));
    return $self->stemplate_build($template);
}

sub remove_confirm {
    my($self, $cgi) = @_;
    $self->{'cgi'} = $cgi;
    my($table) = $cgi->param('table');

    my($info) = $self->db()->info_table($table);

    $self->db()->mdelete($table, "$info->{'_primary_'} = " . $cgi->param('primary'));

    my($template) = $self->template("sqledit_remove_confirm");

    template_set($template->{'assoc'}, '_TABLE_', $table);
    template_set($template->{'assoc'}, '_SCRIPT_', $cgi->url(-absolute => 1));
    return $self->stemplate_build($template);
}

sub edit {
    my($self, $cgi) = @_;
    my($table) = $cgi->param('table');
    $self->{'cgi'} = $cgi;

    my($info) = $self->db()->info_table($table);
    
    my($row) = $self->db()->sexec_select_one($table, "select * from $table where $info->{'_primary_'} = " . $cgi->param('primary'));

    my($template) = $self->template("sqledit_edit");
    my($assoc) = $template->{'assoc'};
    $assoc->{'_TABLE_'} = $table;
    $assoc->{'_HIDDEN_'} = $self->hidden('primary' => $cgi->param('primary'),
					 'context' => 'supdate');
    $assoc->{'_EDITCOMMENT_'} = $cgi->param('comment') if($cgi->param('comment'));
    if(exists($assoc->{'_DEFAULT_'})) {
	$assoc->{'_DEFAULT_'} = $self->row2edit($table, $row);
    } else {
	$self->row2assoc($table, $row, $assoc);
    }

    return $self->stemplate_build($template);
}

sub update_hook {
    dbg("sqledit:update_hook\n", "sqledit");
}

sub update_check {
    my($self, $field, $value) = @_;
    return $value;
}

sub args2row {
    my($self, $table) = @_;
    my($cgi) = $self->{'cgi'};

    my(%row);

    my($info) = $self->db()->info_table($table);
    my($fields) = $info->{'_fields_'};

    my($field);
    foreach $field (@$fields) {
	my($value) =  $cgi->param("${table}_${field}") || $cgi->param($field);
	if(defined($value)) {
	    $row{$field} = $value;
	}
    }
    
    return \%row;
}

#
# Interactive update
#
sub supdate {
    my($self, $cgi) = @_;
    $self->{'cgi'} = $cgi;
    my($table) = $cgi->param('table');

    my($primary) = $cgi->param('primary');

    my($updated_fields) = $self->supdate_1($table, $primary);
    $cgi->param('context' => 'edit');
    if(@$updated_fields) {
	$cgi->param('comment' => "Updated fields @$updated_fields");
    } else {
	$cgi->param('comment' => "No field modified");
    }
    
    if(defined($cgi->fct_name()) && $cgi->fct_name() eq 'edit') {
	return $self->fct_return($cgi);
    } else {
	return $self->edit($cgi);
    }
}

#
# Update backend
#
sub supdate_1 {
    my($self, $table, $primary) = @_;
    my($cgi) = $self->{'cgi'};

    my($info) = $self->db()->info_table($table);

    my($row) = $self->db()->sexec_select_one($table, "select * from $table where $info->{'_primary_'} = $primary");



( run in 0.849 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )