<% # only a logged in user may view the bookmarks $Session->{'user'} || $Response->Redirect('index.asp'); my $error; if($Form->{submit} =~ /create/i) { unless($Form->{new_url}) { $error = "The Url must be ". "filled in to create a new bookmark"; goto ERROR; } my $sth = $Db->prepare_cached( "select url from bookmarks where username=? and url=?" ); $sth->execute($Session->{'user'}, $Form->{new_url}); if($sth->fetchrow_array) { $error = "You already have $Form->{new_url} ". "for a bookmark"; goto ERROR; } else { $sth = $Db->prepare_cached(<Lock(); $sth->execute( ++$Application->{max_bookmark_id}, $Session->{'user'}, $Form->{new_url}, $Form->{new_title} ); $Application->UnLock(); } } if($Query->{delete}) { my $sth = $Db->prepare_cached(<execute($Query->{delete}, $Session->{user}); if(my $data = $sth->fetchrow_hashref) { my $sth = $Db->prepare_cached(<execute($Query->{delete}, $Session->{user}); $Form->{new_url} = $data->{'url'}; $Form->{new_title} = $data->{'title'}; } } # get all the bookmarks ERROR: my $sth = $Db->prepare_cached( "select * from bookmarks where username=? ". "order by bookmark_id" ); $sth->execute($Session->{'user'}); my @bookmarks; while(my $bookmark = $sth->fetchrow_hashref()) { push(@bookmarks, $bookmark); } %> <% if(@bookmarks) { %> Welcome to your bookmarks! <% } else { %> You don't have any bookmarks. Please feel free to add some using the below form. <% } %>
<% if($error) { %>

* <%=$error%> <% } %>

method=POST> <% for ('new_url', 'new_title') { my $name = $_; my $title = join(' ', map { ucfirst $_ } split(/_/, $name)); %> <% } %>
<%=$title%>: value="<%=$Form->{$name}%>" size=40 maxlength=120>
  >
<% if(@bookmarks) { my $half_index = int((@bookmarks+1)/2); %>

cellspacing=0>
> <% for(my $i=0; $i<$half_index; $i++) { %> <% for($i, $i+$half_index) { my $data = ($_ < @bookmarks) ? $bookmarks[$_] : undef; $data->{title} ||= $data->{'url'}; my $text = $data->{bookmark_id} ? "{'url'} >$data->{'title'}" : " "; %> <% } %> <% } %>
Bookmarks
<% if($data->{bookmark_id}) { %> {bookmark_id}" %>>[DEL] <% } else { %>   <% } %> <%= $text || ' '%>

<% } %>