prepare("SELECT t.*, up.user AS 'posteruser' FROM todo t, useridmap up WHERE t.posterid=up.userid AND t.todoid=$id"); $sth->execute; $it = $sth->fetchrow_hashref; unless ($it) { $title = "Not found"; $body = ""; return; } $u = LJ::load_userid($it->{'journalid'}); if ($it->{'security'} eq "private") { unless ($remote && $remote->{'userid'} == $it->{'journalid'}) { $title = "Sorry..."; $body = ""; return; } } if ($it->{'security'} eq "friends") { unless (LJ::is_friend($u, $remote)) { $title = "Sorry..."; $body = ""; return; } } $sth = $dbh->prepare("SELECT k.keyword FROM todokeyword tk, keywords k WHERE tk.todoid=$id AND tk.kwid=k.kwid ORDER BY k.keyword"); $sth->execute; my @kws; push @kws, $_ while ($_ = $sth->fetchrow_array); $it->{'_cats'} = join(", ", @kws); } $sth = $dbh->prepare("SELECT COUNT(*) FROM todo WHERE journalid=$u->{'userid'}"); $sth->execute; my ($todo_count) = $sth->fetchrow_array; LJ::Todo::get_permissions($dbh, \%permission, { 'user' => $u, 'remote' => $remote, 'item' => $it }); if ($FORM{'mode'} eq "save") { unless ($FORM{'subject'} =~ /\S+/) { $title = "Error"; $body = ""; return; } my $todoid = $FORM{'id'}+0; my %q; foreach my $key (qw(statusline security subject des priority datedue progress)) { $q{$key} = $dbh->quote($FORM{$key}); } $q{'datedue'} = $dbh->quote(LJ::html_datetime_decode({ 'name' => 'datedue' }, \%FORM)); if ($todoid) { unless ($permission{'edit'}) { $title = "Error"; $body = ""; return; } $sth = $dbh->prepare("UPDATE todo SET statusline=$q{'statusline'}, subject=$q{'subject'}, security=$q{'security'}, des=$q{'des'}, priority=$q{'priority'}, datedue=$q{'datedue'}, progress=$q{'progress'}, dateupdate=NOW() WHERE todoid=$todoid"); $sth->execute; if ($dbh->err) { $title = "Error"; $body = $dbh->errstr; return; } $title = "Modified"; $body = "here or view the {'user'}\">updated list. p?>"; } else { unless ($permission{'add'}) { $title = "Error"; $body .= ""; return; } ## check to see if user's todo list is full my $max_items = LJ::get_cap($u, "todomax"); if (defined $max_items && $todo_count >= $max_items) { $title = "Sorry..."; my $atype = "account type"; if ($LJ::HELPURL{'accounttype'}) { $atype = "$atype"; } $body .= ""; return; } $sth = $dbh->prepare("INSERT INTO todo (todoid, journalid, posterid, ownerid, statusline, security, subject, des, priority, datecreate, dateupdate, datedue, dateclosed, progress) VALUES (NULL, $u->{'userid'}, $remote->{'userid'}, $u->{'userid'}, $q{'statusline'}, $q{'security'}, $q{'subject'}, $q{'des'}, $q{'priority'}, NOW(), NULL, $q{'datedue'}, NULL, $q{'progress'})"); $sth->execute; if ($dbh->err) { return "db error: " . $dbh->errstr; } $todoid = $sth->{'mysql_insertid'}; $title = "Added"; $body = "here or view the {'user'}\">updated list. p?>"; } if ($it->{'_cats'} ne $FORM{'categories'}) { #### we're inserting/replacing now into memories my @keywords = split(/\s*,\s*/, $FORM{'categories'}); if (scalar(@keywords) > 10) { $title = "Error"; $body = ""; return; } @keywords = grep { s/^\s+//; s/\s+$//; $_; } @keywords; my @kwid; foreach my $kw (@keywords) { if (length($kw) > 20) { $title = "Error"; $body = ""; return; } my $kwid = LJ::get_keyword_id($kw); push @kwid, $kwid; } $dbh->do("DELETE FROM todokeyword WHERE todoid=$todoid"); if (@kwid) { my $sql = "INSERT IGNORE INTO todokeyword (todoid, kwid) VALUES "; # why IGNORE above? with mysql 3.23.x replication, a # partial insert (some in, some dup -> fail) causes all # slaves _not_ replicating that table to stop. fucked # up, huh? so with IGNORE no error is generated. $sql .= join(",", map { "($todoid,$_)" } @kwid); $dbh->do($sql); } } return; } if ($FORM{'mode'} eq "add") { $title = "Add To-Do Item"; $it = { 'todoid' => 0, 'security' => 'public', 'priority' => 3, 'progress' => 0, 'datedue' => '0000-00-00 00:00:00', '_cats' => $FORM{'cat'}, }; unless ($permission{'add'}) { $disabled = "DISABLED"; } my $max_items = LJ::get_cap($u, "todomax"); if (defined $max_items && $todo_count >= $max_items) { $title = "Sorry..."; my $atype = "account type"; if ($LJ::HELPURL{'accounttype'}) { $atype = "$atype"; } $body .= ""; return; } } else { unless ($permission{'edit'}) { $disabled = "DISABLED"; } } $body .= "
\n"; 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?> link: htdocs/todo/index.bml, htdocs/todo/item.bml post: htdocs/todo/item.bml _c?>