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, "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. */ /* Whether or not whom an item is reserved/bought by is hidden. */
"anonymous_purchasing" => 0, "anonymous_purchasing" => 0,

View file

@ -223,49 +223,81 @@ while ($row = $stmt->fetch()) {
$ranks[] = $row; $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"]) {
"FROM {$opt["table_prefix"]}shoppers s " . # When family members are not automatic shoppers
"INNER JOIN {$opt["table_prefix"]}users u ON u.userid = s.mayshopfor " . $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 " .
"LEFT OUTER JOIN {$opt["table_prefix"]}items i ON u.userid = i.userid " . "FROM {$opt["table_prefix"]}shoppers s " .
"LEFT OUTER JOIN {$opt["table_prefix"]}subscriptions sub ON sub.publisher = u.userid AND sub.subscriber = ? " . "INNER JOIN {$opt["table_prefix"]}users u ON u.userid = s.mayshopfor " .
"WHERE s.shopper = ? " . "LEFT OUTER JOIN {$opt["table_prefix"]}items i ON u.userid = i.userid " .
"AND pending = 0 " . "LEFT OUTER JOIN {$opt["table_prefix"]}subscriptions sub ON sub.publisher = u.userid AND sub.subscriber = ? " .
"GROUP BY u.userid, u.fullname, u.list_stamp " . "WHERE s.shopper = ? " .
"ORDER BY u.fullname"); "AND pending = 0 " .
$stmt->bindParam(1, $userid, PDO::PARAM_INT); "GROUP BY u.userid, u.fullname, u.list_stamp " .
$stmt->bindParam(2, $userid, PDO::PARAM_INT); "ORDER BY u.fullname");
$stmt->execute(); $stmt->bindParam(1, $userid, PDO::PARAM_INT);
$shoppees = array(); $stmt->bindParam(2, $userid, PDO::PARAM_INT);
while ($row = $stmt->fetch()) { $stmt->execute();
if ($row['list_stamp'] == 0) { $shoppees = array();
$row['list_stamp'] = '-'; 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 " . $stmt = $smarty->dbh()->prepare("SELECT DISTINCT u.userid, u.fullname, s.pending " .
"FROM {$opt["table_prefix"]}memberships mymem " . "FROM {$opt["table_prefix"]}memberships mymem " .
"INNER JOIN {$opt["table_prefix"]}memberships others " . "INNER JOIN {$opt["table_prefix"]}memberships others " .
"ON others.familyid = mymem.familyid AND others.userid <> ? " . "ON others.familyid = mymem.familyid AND others.userid <> ? " .
"INNER JOIN {$opt["table_prefix"]}users u " . "INNER JOIN {$opt["table_prefix"]}users u " .
"ON u.userid = others.userid " . "ON u.userid = others.userid " .
"LEFT OUTER JOIN {$opt["table_prefix"]}shoppers s " . "LEFT OUTER JOIN {$opt["table_prefix"]}shoppers s " .
"ON s.mayshopfor = others.userid AND s.shopper = ? " . "ON s.mayshopfor = others.userid AND s.shopper = ? " .
"WHERE mymem.userid = ? " . "WHERE mymem.userid = ? " .
"AND (s.pending IS NULL OR s.pending = 1) " . "AND (s.pending IS NULL OR s.pending = 1) " .
"AND u.approved = 1 " . "AND u.approved = 1 " .
"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->bindParam(2, $userid, PDO::PARAM_INT);
$stmt->bindParam(3, $userid, PDO::PARAM_INT); $stmt->bindParam(3, $userid, PDO::PARAM_INT);
$stmt->execute(); $stmt->execute();
$prospects = array(); $prospects = array();
while ($row = $stmt->fetch()) { while ($row = $stmt->fetch()) {
$prospects[] = $row; $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 " . $stmt = $smarty->dbh()->prepare("SELECT messageid, u.fullname, message, created " .

View file

@ -433,43 +433,45 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</div> <!-- card body --> </div> <!-- card body -->
</div> <!-- card --> </div> <!-- card -->
</div> <!-- col --> </div> <!-- col -->
<div class="col mb-3"> {if !$opt.auto_connect_family_members}
<div class="card h-100"> <div class="col mb-3">
<div class="card-header">Available People To Shopping For</div> <div class="card h-100">
<div class="card-body"> <div class="card-header">Available People To Shopping For</div>
<div class="table-responsive"> <div class="card-body">
<table class="table table-bordered table-striped"> <div class="table-responsive">
<thead> <table class="table table-bordered table-striped">
<tr> <thead>
<th class="colheader">Name</th> <tr>
<th>&nbsp;</th> <th class="colheader">Name</th>
</tr> <th>&nbsp;</th>
</thead> </tr>
<tbody> </thead>
{foreach from=$prospects item=row} <tbody>
<tr> {foreach from=$prospects item=row}
<td>{$row.fullname|escape:'htmlall'}</td> <tr>
<td align="right" nowrap> <td>{$row.fullname|escape:'htmlall'}</td>
{if $row.pending} <td align="right" nowrap>
<a href="index.php?action=cancel&shopfor={$row.userid}"><img class="theme-image" data-light-src="images/delete-light.png" data-dark-src="images/delete-dark.png" src="images/delete-light.png" border="0" alt="Cancel" title="Cancel" /></a> {if $row.pending}
{else} <a href="index.php?action=cancel&shopfor={$row.userid}"><img class="theme-image" data-light-src="images/delete-light.png" data-dark-src="images/delete-dark.png" src="images/delete-light.png" border="0" alt="Cancel" title="Cancel" /></a>
<a href="index.php?action=request&shopfor={$row.userid}"> {else}
{if $opt.shop_requires_approval} <a href="index.php?action=request&shopfor={$row.userid}">
<img class="theme-image" data-light-src="images/cloud-add-light.png" data-dark-src="images/cloud-add-dark.png" src="images/cloud-add-light.png" border="0" alt="Request" title="Request" /> {if $opt.shop_requires_approval}
{else} <img class="theme-image" data-light-src="images/cloud-add-light.png" data-dark-src="images/cloud-add-dark.png" src="images/cloud-add-light.png" border="0" alt="Request" title="Request" />
<img class="theme-image" data-light-src="images/cloud-add-light.png" data-dark-src="images/cloud-add-dark.png" src="images/cloud-add-light.png" border="0" alt="Add" title="Add" /> {else}
{/if} <img class="theme-image" data-light-src="images/cloud-add-light.png" data-dark-src="images/cloud-add-dark.png" src="images/cloud-add-light.png" border="0" alt="Add" title="Add" />
</a> {/if}
{/if} </a>
</td> {/if}
</tr> </td>
{/foreach} </tr>
</tbody> {/foreach}
</table> </tbody>
</div> <!-- table-responsive --> </table>
</div> <!-- card body --> </div> <!-- table-responsive -->
</div> <!-- card --> </div> <!-- card body -->
</div> <!-- col --> </div> <!-- card -->
</div> <!-- col -->
{/if}
<div class="col mb-3"> <div class="col mb-3">
<div class="card h-100"> <div class="card h-100">
<div class="card-header">Messages</div> <div class="card-header">Messages</div>