Add option to automatically connect family members

This commit is contained in:
Michael Erdely 2024-12-14 16:30:45 -05:00
parent 2975a830fc
commit 64baf4332f
Signed by: mike
SSH key fingerprint: SHA256:ukbnfrRMaRYlBZXENtBTyO2jLnql5AA5m+SzZCfYQe0
3 changed files with 118 additions and 78 deletions

View file

@ -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,

View file

@ -223,7 +223,9 @@ 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 " .
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 " .
@ -232,11 +234,11 @@ $stmt = $smarty->dbh()->prepare("SELECT u.userid, u.fullname, u.comment, u.list_
"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()) {
$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'] = '-';
}
@ -245,9 +247,9 @@ while ($row = $stmt->fetch()) {
$row['list_stamp'] = $listStampDate->format($opt["date_format"]);
}
$shoppees[] = $row;
}
}
$stmt = $smarty->dbh()->prepare("SELECT DISTINCT u.userid, u.fullname, s.pending " .
$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 <> ? " .
@ -259,13 +261,43 @@ $stmt = $smarty->dbh()->prepare("SELECT DISTINCT u.userid, u.fullname, s.pending
"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()) {
$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 " .

View file

@ -433,6 +433,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</div> <!-- card body -->
</div> <!-- card -->
</div> <!-- col -->
{if !$opt.auto_connect_family_members}
<div class="col mb-3">
<div class="card h-100">
<div class="card-header">Available People To Shopping For</div>
@ -470,6 +471,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</div> <!-- card body -->
</div> <!-- card -->
</div> <!-- col -->
{/if}
<div class="col mb-3">
<div class="card h-100">
<div class="card-header">Messages</div>