{'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 .= "
\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 .= ""; 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 .= ""; 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?>