From 64baf4332fca734c0e1cb2e0ef7e00e1c6240b5b Mon Sep 17 00:00:00 2001 From: Michael Erdely Date: Sat, 14 Dec 2024 16:30:45 -0500 Subject: [PATCH] Add option to automatically connect family members --- src/includes/config.php | 6 +++ src/index.php | 114 +++++++++++++++++++++++++--------------- src/templates/home.tpl | 76 ++++++++++++++------------- 3 files changed, 118 insertions(+), 78 deletions(-) diff --git a/src/includes/config.php b/src/includes/config.php index a4528da..a3e3dbd 100644 --- a/src/includes/config.php +++ b/src/includes/config.php @@ -62,6 +62,12 @@ function getGlobalOptions() { */ "newuser_default_family" => 1, + /* Automatically make family members shoppers for each other + 0 = manual connections + 1 = auto connect family members + */ + "auto_connect_family_members" => 1, + /* Whether or not whom an item is reserved/bought by is hidden. */ "anonymous_purchasing" => 0, diff --git a/src/index.php b/src/index.php index 009d885..efd2d29 100644 --- a/src/index.php +++ b/src/index.php @@ -223,49 +223,81 @@ while ($row = $stmt->fetch()) { $ranks[] = $row; } -$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()) { - if ($row['list_stamp'] == 0) { - $row['list_stamp'] = '-'; +if (!$opt["auto_connect_family_members"]) { + # When family members are not automatic shoppers + $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()) { + if ($row['list_stamp'] == 0) { + $row['list_stamp'] = '-'; + } + else { + $listStampDate = new DateTime($row['list_stamp']); + $row['list_stamp'] = $listStampDate->format($opt["date_format"]); + } + $shoppees[] = $row; } - else { - $listStampDate = new DateTime($row['list_stamp']); - $row['list_stamp'] = $listStampDate->format($opt["date_format"]); - } - $shoppees[] = $row; -} -$stmt = $smarty->dbh()->prepare("SELECT DISTINCT u.userid, u.fullname, s.pending " . - "FROM {$opt["table_prefix"]}memberships mymem " . - "INNER JOIN {$opt["table_prefix"]}memberships others " . - "ON others.familyid = mymem.familyid AND others.userid <> ? " . - "INNER JOIN {$opt["table_prefix"]}users u " . - "ON u.userid = others.userid " . - "LEFT OUTER JOIN {$opt["table_prefix"]}shoppers s " . - "ON s.mayshopfor = others.userid AND s.shopper = ? " . - "WHERE mymem.userid = ? " . - "AND (s.pending IS NULL OR s.pending = 1) " . - "AND u.approved = 1 " . - "ORDER BY u.fullname"); -$stmt->bindParam(1, $userid, PDO::PARAM_INT); -$stmt->bindParam(2, $userid, PDO::PARAM_INT); -$stmt->bindParam(3, $userid, PDO::PARAM_INT); -$stmt->execute(); -$prospects = array(); -while ($row = $stmt->fetch()) { - $prospects[] = $row; + $stmt = $smarty->dbh()->prepare("SELECT DISTINCT u.userid, u.fullname, s.pending " . + "FROM {$opt["table_prefix"]}memberships mymem " . + "INNER JOIN {$opt["table_prefix"]}memberships others " . + "ON others.familyid = mymem.familyid AND others.userid <> ? " . + "INNER JOIN {$opt["table_prefix"]}users u " . + "ON u.userid = others.userid " . + "LEFT OUTER JOIN {$opt["table_prefix"]}shoppers s " . + "ON s.mayshopfor = others.userid AND s.shopper = ? " . + "WHERE mymem.userid = ? " . + "AND (s.pending IS NULL OR s.pending = 1) " . + "AND u.approved = 1 " . + "ORDER BY u.fullname"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->bindParam(3, $userid, PDO::PARAM_INT); + $stmt->execute(); + $prospects = array(); + while ($row = $stmt->fetch()) { + $prospects[] = $row; + } +} else { + # When family members are automatically connected as shoppers + $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"]}users u " . + "JOIN {$opt["table_prefix"]}memberships m ON u.userid = m.userid " . + "LEFT JOIN {$opt["table_prefix"]}items i ON u.userid = i.userid " . + "LEFT JOIN {$opt["table_prefix"]}subscriptions sub ON sub.publisher = u.userid AND sub.subscriber = ? " . + "WHERE m.familyid IN ( " . + "SELECT familyid " . + "FROM {$opt["table_prefix"]}memberships " . + "WHERE userid = ? " . + ") " . + "AND u.userid != ? " . + "GROUP BY u.userid, u.fullname"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->bindParam(3, $userid, PDO::PARAM_INT); + $stmt->execute(); + $shoppees = array(); + while ($row = $stmt->fetch()) { + if ($row['list_stamp'] == 0) { + $row['list_stamp'] = '-'; + } + else { + $listStampDate = new DateTime($row['list_stamp']); + $row['list_stamp'] = $listStampDate->format($opt["date_format"]); + } + $shoppees[] = $row; + } } $stmt = $smarty->dbh()->prepare("SELECT messageid, u.fullname, message, created " . diff --git a/src/templates/home.tpl b/src/templates/home.tpl index 2a7a934..270a377 100644 --- a/src/templates/home.tpl +++ b/src/templates/home.tpl @@ -433,43 +433,45 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -
-
-
Available People To Shopping For
-
-
- - - - - - - - - {foreach from=$prospects item=row} - - - - - {/foreach} - -
Name 
{$row.fullname|escape:'htmlall'} - {if $row.pending} - Cancel - {else} - - {if $opt.shop_requires_approval} - Request - {else} - Add - {/if} - - {/if} -
-
-
-
-
+ {if !$opt.auto_connect_family_members} +
+
+
Available People To Shopping For
+
+
+ + + + + + + + + {foreach from=$prospects item=row} + + + + + {/foreach} + +
Name 
{$row.fullname|escape:'htmlall'} + {if $row.pending} + Cancel + {else} + + {if $opt.shop_requires_approval} + Request + {else} + Add + {/if} + + {/if} +
+
+
+
+
+ {/if}
Messages