implements feature request #46 to monitor other people's lists
http://sourceforge.net/p/phpgiftreg/feature-requests/46/
This commit is contained in:
parent
6513d8a14c
commit
a3bbdabbaa
6 changed files with 76 additions and 2 deletions
BIN
src/images/podcast.png
Normal file
BIN
src/images/podcast.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -92,6 +92,37 @@ function getExistingQuantity($itemid, $userid, $bought, $dbh, $opt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processSubscriptions($publisher, $action, $dbh, $opt) {
|
||||||
|
// join the users table as a cheap way to get the guy's name without having to pass it in.
|
||||||
|
$stmt = $dbh->prepare("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) {
|
function sendMessage($sender, $recipient, $message, $dbh, $opt) {
|
||||||
$stmt = $dbh->prepare("INSERT INTO {$opt["table_prefix"]}messages(sender,recipient,message,created) VALUES(?, ?, ?, ?)");
|
$stmt = $dbh->prepare("INSERT INTO {$opt["table_prefix"]}messages(sender,recipient,message,created) VALUES(?, ?, ?, ?)");
|
||||||
$stmt->bindParam(1, $sender, PDO::PARAM_INT);
|
$stmt->bindParam(1, $sender, PDO::PARAM_INT);
|
||||||
|
|
|
@ -81,6 +81,32 @@ if (!empty($_GET["action"])) {
|
||||||
$stmt->bindValue(2, (int) $_GET["shopfor"], PDO::PARAM_INT);
|
$stmt->bindValue(2, (int) $_GET["shopfor"], PDO::PARAM_INT);
|
||||||
$stmt->execute();
|
$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"]))
|
if (!empty($_GET["mysort"]))
|
||||||
|
@ -126,15 +152,17 @@ while ($stmt->fetch()) {
|
||||||
++$myitems_count;
|
++$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 " .
|
"FROM {$opt["table_prefix"]}shoppers s " .
|
||||||
"INNER JOIN {$opt["table_prefix"]}users u ON u.userid = s.mayshopfor " .
|
"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"]}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 = ? " .
|
"WHERE s.shopper = ? " .
|
||||||
"AND pending = 0 " .
|
"AND pending = 0 " .
|
||||||
"GROUP BY u.userid, u.fullname, u.list_stamp " .
|
"GROUP BY u.userid, u.fullname, u.list_stamp " .
|
||||||
"ORDER BY u.fullname");
|
"ORDER BY u.fullname");
|
||||||
$stmt->bindParam(1, $userid, PDO::PARAM_INT);
|
$stmt->bindParam(1, $userid, PDO::PARAM_INT);
|
||||||
|
$stmt->bindParam(2, $userid, PDO::PARAM_INT);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$shoppees = array();
|
$shoppees = array();
|
||||||
while ($row = $stmt->fetch()) {
|
while ($row = $stmt->fetch()) {
|
||||||
|
|
|
@ -138,6 +138,8 @@ if (!empty($_REQUEST["action"])) {
|
||||||
// TODO: are we leaking allocs records here?
|
// TODO: are we leaking allocs records here?
|
||||||
|
|
||||||
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
||||||
|
processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt());
|
||||||
|
|
||||||
header("Location: " . getFullPath("index.php?message=Item+deleted."));
|
header("Location: " . getFullPath("index.php?message=Item+deleted."));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -192,6 +194,7 @@ if (!empty($_REQUEST["action"])) {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
||||||
|
processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt());
|
||||||
|
|
||||||
header("Location: " . getFullPath("index.php"));
|
header("Location: " . getFullPath("index.php"));
|
||||||
exit;
|
exit;
|
||||||
|
@ -229,6 +232,7 @@ if (!empty($_REQUEST["action"])) {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
stampUser($userid, $smarty->dbh(), $smarty->opt());
|
||||||
|
processSubscriptions($userid, $action, $smarty->dbh(), $smarty->opt());
|
||||||
|
|
||||||
header("Location: " . getFullPath("index.php"));
|
header("Location: " . getFullPath("index.php"));
|
||||||
exit;
|
exit;
|
||||||
|
|
6
src/sql/2.0.0-to-2.1.0.sql
Normal file
6
src/sql/2.0.0-to-2.1.0.sql
Normal file
|
@ -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`)
|
||||||
|
);
|
|
@ -168,7 +168,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
<td align="right">{$row.itemcount}</td>
|
<td align="right">{$row.itemcount}</td>
|
||||||
<td align="right" nowrap>
|
<td align="right" nowrap>
|
||||||
{if $row.itemcount > 0}
|
{if $row.itemcount > 0}
|
||||||
<a href="shop.php?shopfor={$row.userid}"><img alt="Shop for {$row.fullname|escape:'htmlall'}" src="images/store.png" border="0" alt="Shop" title="Shop"></a>
|
<a href="shop.php?shopfor={$row.userid}"><img alt="Shop for {$row.fullname|escape:'htmlall'}" src="images/store.png" border="0" title="Shop for {$row.fullname|escape:'htmlall'}"></a>
|
||||||
|
{/if}
|
||||||
|
{if !$row.is_unsubscribed}
|
||||||
|
<a href="index.php?action=unsubscribe&shoppee={$row.userid}"><img alt="Unsubscribe from {$row.fullname|escape:'htmlall'}'s updates" src="images/delete.png" border="0" title="Unsubscribe from {$row.fullname|escape:'htmlall'}'s updates"></a>
|
||||||
|
{else}
|
||||||
|
<a href="index.php?action=subscribe&shoppee={$row.userid}"><img alt="Subscribe to {$row.fullname|escape:'htmlall'}'s updates" src="images/podcast.png" border="0" title="Subscribe to {$row.fullname|escape:'htmlall'}'s updates"></a>
|
||||||
{/if}
|
{/if}
|
||||||
<a rel="confirmunshop" data-content="{$row.fullname|escape:'htmlall'}" href="index.php?action=cancel&shopfor={$row.userid}"><img src="images/bin.png" border="0" alt="Don't shop for {$row.fullname|escape:'htmlall'} anymore" title="Don't shop for {$row.fullname|escape:'htmlall'} anymore" /></a>
|
<a rel="confirmunshop" data-content="{$row.fullname|escape:'htmlall'}" href="index.php?action=cancel&shopfor={$row.userid}"><img src="images/bin.png" border="0" alt="Don't shop for {$row.fullname|escape:'htmlall'} anymore" title="Don't shop for {$row.fullname|escape:'htmlall'} anymore" /></a>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue