{'user'}; } my $u = undef; if ($user && $FORM{'mode'} ne "pickuser") { $u = LJ::load_user($user); unless ($u) { $body .= "Unknown user: " . LJ::ehtml($user) . " p?>\n"; } } unless ($u) { $title = "To-Do List"; $body .= "
"; $body .= "Enter the username of the user whose to-do list you would like to view:
\n"; return; } LJ::Todo::get_permissions($dbh, \%permission, { 'user' => $u, 'remote' => $remote }); $title = "To-Do List: $user"; $body .= "go here. de?>"; #### ### security stuff ## my $where; unless ($remote && $remote->{'userid'} == $u->{'userid'}) { my $friendclause; if ($remote) { # check to see if this user's a friend $sth = $dbh->prepare("SELECT COUNT(*) AS 'isfriend' FROM friends WHERE userid=$u->{'userid'} AND friendid=$remote->{'userid'}"); $sth->execute; my ($isfriend) = $sth->fetchrow_array; if ($isfriend) { $friendclause = ", 'friends'"; } } $where .= "AND t.security IN ('public' $friendclause)"; } #### ### load the todo items ## my %keyword; my %itemkws; my @tdids; my @delete; my $total; $sth = $dbh->prepare("SELECT t.todoid, tk.kwid, k.keyword FROM todo t LEFT JOIN todokeyword tk ON t.todoid=tk.todoid LEFT JOIN keywords k ON tk.kwid=k.kwid WHERE t.journalid=$u->{'userid'} $where"); $sth->execute; while (my ($id, $kwid, $keyword) = $sth->fetchrow_array) { if ($kwid) { $keyword{$kwid}->{'count'}++; $keyword{$kwid}->{'keyword'} = $keyword; push @{$itemkws{$id}}, $kwid; } $total++; if (! $FORM{'cat'} || ($kwid && $keyword eq $FORM{'cat'})) { push @tdids, $id; if ($FORM{"delete_$id"}) { push @delete, $id; } } } ### deleting? if (@delete) { unless ($permission{'delete'}) { $title = "Error"; $body = ""; return; } my $in = join(",", @delete); $dbh->do("DELETE FROM todo WHERE todoid IN ($in)"); $dbh->do("DELETE FROM tododep WHERE todoid IN ($in)"); $dbh->do("DELETE FROM tododep WHERE depid IN ($in)"); $dbh->do("DELETE FROM todokeyword WHERE todoid IN ($in)"); $title = "Deleted"; $body = ""; $body .= "{'user'}\"><< To-Do List"; $body .= ""; return; } $body .= "
"; $body .= "\n" if ($FORM{'user'}); $body .= "{'keyword'}) cmp lc($keyword{$b}->{'keyword'}) } keys %keyword) { my $cat = $keyword{$kwid}->{'keyword'}; if ($FORM{'cat'} eq $cat) { $body .= "" . LJ::ehtml($cat) . " ($keyword{$kwid}->{'count'}), "; } else { $body .= " $u->{'user'}, 'cat' => $cat }) . "\">" . LJ::ehtml($cat) . " ($keyword{$kwid}->{'count'}), "; } } if ($FORM{'cat'}) { $body .= " $u->{'user'}, 'cat' => '' }) . "\">(Show All), " } if (keys %keyword) { chop $body; chop $body; # remove final ", " } else { $body .= "No categories to filter on."; } $body .= " p?>"; unless (@tdids) { $body .= ""; } ### ## links # { my @actions = (); if ($permission{'add'}) { push @actions, [ "item.bml?user=$u->{'user'}&mode=add&cat=" . LJ::eurl($FORM{'cat'}), "Add Item" ]; } if (@actions) { $body .= "[0]\">$_->[1] ]"; } $body .= " p?>"; } } unless (@tdids) { $body .= "
"; return; } $sth = $dbh->prepare("SELECT todoid, posterid, ownerid, statusline, security, subject, des, priority, UNIX_TIMESTAMP(datecreate) AS 'datecreate_unix', dateupdate, datedue, dateclosed, progress FROM todo WHERE todoid IN (" . join(",", @tdids) . ")"); $sth->execute; my @items; push @items, $_ while ($_ = $sth->fetchrow_hashref); foreach my $it (@items) { $it->{'_duesort'} = $it->{'datedue'}; if ($it->{'_duesort'} =~ s/^0000-/9999-/) { $it->{'datedue'} = ""; } elsif (length($it->{'datedue'})==0) { $it->{'_duesort'} = "9999"; } } ### ## sort # $FORM{'sort'} ||= "due"; if ($FORM{'sort'} eq "due") { @items = sort { $b->{'priority'} <=> $a->{'priority'} } @items; @items = sort { $a->{'_duesort'} cmp $b->{'_duesort'} } @items; } if ($FORM{'sort'} eq "priority") { @items = sort { $a->{'_duesort'} cmp $b->{'_duesort'} } @items; @items = sort { $b->{'priority'} <=> $a->{'priority'} } @items; } if ($FORM{'sort'} eq "status") { @items = sort { $b->{'progress'} <=> $a->{'progress'} } @items; } if ($FORM{'sort'} eq "item") { @items = sort { lc($a->{'subject'}) cmp lc($b->{'subject'}) } @items; } $body .= "

\n"; $body .= " ALIGN=LEFT VALIGN=BOTTOM>\n"; $body .= "\n" if ($permission{'delete'}); { my @cols = (["Status", "status"], ["P", "priority"], ["Item", "item"], ["Date Due", "due"], ["Category", ""]); foreach my $col (@cols) { if ($col->[1] eq "") { $body .= ""; } elsif ($col->[1] eq $FORM{'sort'}) { $body .= ""; } else { $body .= ""; } } } $body .= "\n"; foreach my $it (@items) { my $val; my @vals; ## status $val = $it->{'progress'} . "%
" . LJ::ehtml($it->{'statusline'}); push @vals, $val; ## priority { my $color; if ($it->{'priority'} < 3) { $val = "-"; $color = "#0000C0"; } if ($it->{'priority'} == 1) { $val = "--"; } if ($it->{'priority'} > 3) { $val = "!"; $color = "#FF0000"; } if ($it->{'priority'} == 5) { $val = "!!"; } $val = $color ? "$val" : " "; } push @vals, $val; ## item & description { my $des = LJ::auto_linkify(LJ::ehtml($it->{'des'})); $val = "{'todoid'}\">" . LJ::ehtml($it->{'subject'}) . "
$des"; push @vals, $val; } ## due { $val = " "; my $due = $it->{'datedue'}; $due =~ s/:00$//; $due =~ s/00:00$//; if ($due) { $val = "$due"; } push @vals, $val; } ## categories { $val = ""; foreach my $kwid (@{$itemkws{$it->{'todoid'}}}) { if ($val) { $val .= ", "; } $val .= $keyword{$kwid}->{'keyword'}; } $val = $val ? "$val" : " "; push @vals, $val; } ## print the row $body .= "\n"; $body .= "\n" if ($permission{'delete'}); foreach $val (@vals) { $body .= ""; } $body .= "\n"; } $body .= "
 $col->[0]>$col->[0] $u->{'user'}, 'sort' => $col->[1] }) . "\">$col->[0]
{'todoid'}\">$val
\n"; $body .= "

" if ($permission{'delete'}); $body .= "

"; return; _code?> body=>

Note: The to-do list system is in beta. We're well aware it has a lot of work needed, and it definitely needs to be documented-- especially the security related things. standout?> page?> form: htdocs/todo/index.bml post: htdocs/todo/index.bml link: htdocs/todo/index.bml, htdocs/todo/item.bml _c?>