From a3bbdabbaa328de861c41c0dcb2f2691bccc0fc7 Mon Sep 17 00:00:00 2001 From: Ryan Walberg Date: Fri, 30 Nov 2012 03:25:55 +0000 Subject: [PATCH] implements feature request #46 to monitor other people's lists http://sourceforge.net/p/phpgiftreg/feature-requests/46/ --- src/images/podcast.png | Bin 0 -> 1288 bytes src/includes/funcLib.php | 31 +++++++++++++++++++++++++++++++ src/index.php | 30 +++++++++++++++++++++++++++++- src/item.php | 4 ++++ src/sql/2.0.0-to-2.1.0.sql | 6 ++++++ src/templates/home.tpl | 7 ++++++- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/images/podcast.png create mode 100644 src/sql/2.0.0-to-2.1.0.sql diff --git a/src/images/podcast.png b/src/images/podcast.png new file mode 100644 index 0000000000000000000000000000000000000000..841707f723cac080b001d51a30cbc2385ef476a6 GIT binary patch literal 1288 zcmbVMZEO=|96uzog_i`0lR;*<90){g@1^ba?pVRK*K?h_(X>tM7iG7*XY0}33wJl$ z4JXMm)FzOOOg~6S(ZrY_3-~exU&3PG!KkYvvPhUG2WL%iwpz{aFbv>zruXNgAC_PO<>fq!=9l zjcHOBNB~Lc-CF{U2(mPzrqWJYY~^G_^GYtpo7YUpMv%sxc~g?Jz(G4em#T-b+h31i zsH%jpmjWUonh}suoBJ$~>}yNOeOZ}Ru$?>5#ykfVXuy%sywE+ z2XV3?Y~HD~7)K+91<-((@W=#BqO{*j`U%$0K8I2SN#G=f6G0D2aDgC4kZ9$>pfyYB z1PtpKXfLf{&*NnjuMs ziO`WS?IZahEifci)v*|th%n)x5QtC$9VW>r#qd#_z)PZ{B&)hBaSJpbFApsBRiFr#p`mjb z=G4VJU>JfVgMK1diCmy5J`(k@fpC}*0s>ayD*q>IICKVg+v7j&QWe1-bhiu54-X6D z19Uhu795UW^mDfnWC4xAXO`Pp}-2WRTO zdWw5|a7Q8eZOmMAb1U=Wdq0$pum1SFJ-K~yi@N99w&~*iWBZK1i-Qxd{~<^t2REb- z|N7?s;yyWBe!BbOXtA8eK00{d@bIp}+VY;!rpqm(2ZFor7VGZb z7~j@9k$SN5fiw1nK?l6jv*PK@!_zbEPprVL#Fblh)|Z!jm+QxB$jwLYiLXf`lQ*+g z;7Iv;^3O{@MX?Wm+q6H^KQ;Txm21OMXXen%h5B{732g1e%C~0wR*-v}8~RH(&bNNE zo)&MF#;?}PM~{^nz8gPu@yyxjEi)dvcDkmsy-oYEVN>uprepare("SELECT subscriber, fullname FROM subscriptions sub INNER JOIN users u ON u.userid = sub.publisher WHERE publisher = ? AND (last_notified IS NULL OR DATE_ADD(last_notified, INTERVAL {$opt["notify_threshold_minutes"]} MINUTE) < NOW())"); + $stmt->bindParam(1, $publisher, PDO::PARAM_INT); + $stmt->execute(); + + $msg = ""; + while ($row = $stmt->fetch()) { + if ($msg == "") { + // same message for each user but we need the fullname from the first row before we can assemble it. + if ($action == "insert") { + $msg = $row["fullname"] . " has added an item to their list."; + } + else if ($action == "update") { + $msg = $row["fullname"] . " has updated an item on their list."; + } + else if ($action == "delete") { + $msg = $row["fullname"] . " has deleted an item from their list."; + } + $msg .= "\r\n\r\nYou are receiving this message because you are subscribed to their updates. You will not receive another message for their updates for the next " . $opt["notify_threshold_minutes"] . " minutes."; + } + sendMessage($publisher, $row["subscriber"], $msg, $dbh, $opt); + + // stamp the subscription. + $stmt2 = $dbh->prepare("UPDATE subscriptions SET last_notified = NOW() WHERE publisher = ? AND subscriber = ?"); + $stmt2->bindParam(1, $publisher, PDO::PARAM_INT); + $stmt2->bindParam(2, $row["subscriber"], PDO::PARAM_INT); + $stmt2->execute(); + } +} + function sendMessage($sender, $recipient, $message, $dbh, $opt) { $stmt = $dbh->prepare("INSERT INTO {$opt["table_prefix"]}messages(sender,recipient,message,created) VALUES(?, ?, ?, ?)"); $stmt->bindParam(1, $sender, PDO::PARAM_INT); diff --git a/src/index.php b/src/index.php index 02eef82..6fce4c0 100644 --- a/src/index.php +++ b/src/index.php @@ -81,6 +81,32 @@ if (!empty($_GET["action"])) { $stmt->bindValue(2, (int) $_GET["shopfor"], PDO::PARAM_INT); $stmt->execute(); } + else if ($action == "subscribe") { + // ensure the current user can shop for that user first. + $stmt = $smarty->dbh()->prepare("SELECT pending FROM shoppers WHERE shopper = ? AND mayshopfor = ?"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindValue(2, (int) $_GET["shoppee"], PDO::PARAM_INT); + $stmt->execute(); + if ($row = $stmt->fetch()) { + if ($row["pending"]) { + die("You aren't allowed to shop for that user yet."); + } + } + else { + die("You aren't allowed to shop for that user."); + } + + $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}subscriptions(publisher, subscriber) VALUES(?, ?)"); + $stmt->bindValue(1, (int) $_GET["shoppee"], PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->execute(); + } + else if ($action == "unsubscribe") { + $stmt = $smarty->dbh()->prepare("DELETE FROM {$opt["table_prefix"]}subscriptions WHERE publisher = ? AND subscriber = ?"); + $stmt->bindValue(1, (int) $_GET["shoppee"], PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->execute(); + } } if (!empty($_GET["mysort"])) @@ -126,15 +152,17 @@ while ($stmt->fetch()) { ++$myitems_count; } -$stmt = $smarty->dbh()->prepare("SELECT u.userid, u.fullname, u.comment, u.list_stamp, COUNT(i.itemid) AS itemcount " . +$stmt = $smarty->dbh()->prepare("SELECT u.userid, u.fullname, u.comment, u.list_stamp, ISNULL(sub.subscriber) AS is_unsubscribed, COUNT(i.itemid) AS itemcount " . "FROM {$opt["table_prefix"]}shoppers s " . "INNER JOIN {$opt["table_prefix"]}users u ON u.userid = s.mayshopfor " . "LEFT OUTER JOIN {$opt["table_prefix"]}items i ON u.userid = i.userid " . + "LEFT OUTER JOIN {$opt["table_prefix"]}subscriptions sub ON sub.publisher = u.userid AND sub.subscriber = ? " . "WHERE s.shopper = ? " . "AND pending = 0 " . "GROUP BY u.userid, u.fullname, u.list_stamp " . "ORDER BY u.fullname"); $stmt->bindParam(1, $userid, PDO::PARAM_INT); +$stmt->bindParam(2, $userid, PDO::PARAM_INT); $stmt->execute(); $shoppees = array(); while ($row = $stmt->fetch()) { diff --git a/src/item.php b/src/item.php index b0f797b..4e39826 100644 --- a/src/item.php +++ b/src/item.php @@ -138,6 +138,8 @@ if (!empty($_REQUEST["action"])) { // TODO: are we leaking allocs records here? stampUser($userid, $smarty->dbh(), $smarty->opt()); + processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt()); + header("Location: " . getFullPath("index.php?message=Item+deleted.")); exit; } @@ -192,6 +194,7 @@ if (!empty($_REQUEST["action"])) { $stmt->execute(); stampUser($userid, $smarty->dbh(), $smarty->opt()); + processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt()); header("Location: " . getFullPath("index.php")); exit; @@ -229,6 +232,7 @@ if (!empty($_REQUEST["action"])) { $stmt->execute(); stampUser($userid, $smarty->dbh(), $smarty->opt()); + processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt()); header("Location: " . getFullPath("index.php")); exit; diff --git a/src/sql/2.0.0-to-2.1.0.sql b/src/sql/2.0.0-to-2.1.0.sql new file mode 100644 index 0000000..da316f3 --- /dev/null +++ b/src/sql/2.0.0-to-2.1.0.sql @@ -0,0 +1,6 @@ +CREATE TABLE `subscriptions` ( + `publisher` int(11) NOT NULL, + `subscriber` int(11) NOT NULL, + `last_notified` datetime DEFAULT NULL, + PRIMARY KEY (`publisher`,`subscriber`) +); diff --git a/src/templates/home.tpl b/src/templates/home.tpl index 69bf56b..25d7438 100644 --- a/src/templates/home.tpl +++ b/src/templates/home.tpl @@ -168,7 +168,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {$row.itemcount} {if $row.itemcount > 0} - Shop for {$row.fullname|escape:'htmlall'}  + Shop for {$row.fullname|escape:'htmlall'} + {/if} + {if !$row.is_unsubscribed} + Unsubscribe from {$row.fullname|escape:'htmlall'}'s updates + {else} + Subscribe to {$row.fullname|escape:'htmlall'}'s updates {/if} Don't shop for {$row.fullname|escape:'htmlall'} anymore