1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
<%
# 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(<<SQL);
insert into bookmarks (bookmark_id, username, url, title)
values (?,?,?,?)
SQL
;
$Application->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(<<SQL);
select * from bookmarks
where bookmark_id = ?
and username = ?
SQL
;
$sth->execute($Query->{delete}, $Session->{user});
if(my $data = $sth->fetchrow_hashref) {
my $sth = $Db->prepare_cached(<<SQL);
delete from bookmarks
where bookmark_id = ?
and username = ?
SQL
;
$sth->execute($Query->{delete}, $Session->{user});
$Form->{new_url} = $data->{'url'};
$Form->{new_title} = $data->{'title'};
}
}
# get all the bookmarks
ERROR:
my $rows = $Db->selectall_arrayref(
"select bookmark_id, username, title, url from bookmarks where username=? ".
"order by bookmark_id",
undef,
$Session->{'user'}
);
my @bookmarks;
for my $row ( @$rows ) {
push(@bookmarks, {
bookmark_id => $row->[0],
username => $row->[1],
title => $row->[2],
url => $row->[3],
});
}
%>
<% if(@bookmarks) { %>
Welcome to your bookmarks!
<% } else { %>
You don't have any bookmarks. Please feel free to
add some using the below form.
<% } %>
<center>
<% if($error) { %>
<p><b><font color=red size=-1>* <%=$error%></font></b>
<% } %>
<form src=<%=$Basename%> method=POST>
<table border=0>
<% for ('new_url', 'new_title') {
my $name = $_;
my $title = join(' ',
map { ucfirst $_ } split(/_/, $name));
%>
<tr>
<td><b><%=$title%>:</b></td>
<td><input type=text name=<%=$name%>
value="<%=$Form->{$name}%>"
size=40 maxlength=120>
</td>
</tr>
<% } %>
<tr>
<td> </td>
<td>
<font <%=$FontBase%>>
<input type=submit name=submit
value="Create Bookmark"></td></tr>
</font>
</td>
</form>
</table>
<% if(@bookmarks) {
my $half_index = int((@bookmarks+1)/2);
%>
<p>
<table border=0 width=80% bgcolor=<%= $DarkColor %> cellspacing=0>
<tr><td align=center>
<table border=0 width=100% cellspacing=1 cellpadding=3>
<tr bgcolor=<%= $DarkColor %>><td align=center colspan=4>
<font color=yellow><b>Bookmarks</b></font>
</td></tr>
<% for(my $i=0; $i<$half_index; $i++) { %>
<tr>
<% for($i, $i+$half_index) {
my $data = ($_ < @bookmarks) ?
$bookmarks[$_] : undef;
$data->{title} ||= $data->{'url'};
my $text = $data->{bookmark_id} ?
"<a href=$data->{'url'}
>$data->{'title'}</a>"
: " ";
%>
<td bgcolor=#c0c0c0 width=30 align=center>
<% if($data->{bookmark_id}) { %>
<font size=-1><tt>
<a href=<%=
"$Basename?delete=$data->{bookmark_id}"
%>>[DEL]</a>
</tt></font>
<% } else { %>
<% } %>
</td>
<td bgcolor=white><%= $text || ' '%></td>
<% } %>
</tr>
<% } %>
</table>
</td></tr></table>
<br>
<% } %>
</center>
|