From 190da415bd3ad258d2cf31d1735d071da245c4a7 Mon Sep 17 00:00:00 2001 From: Michael Erdely Date: Tue, 31 Dec 2024 12:03:08 -0500 Subject: [PATCH] Add ability to archive items --- src/archive.php | 398 ++++++++++++++++++++++++++++ src/images/archive-fill-dark.png | Bin 0 -> 628 bytes src/images/archive-fill-light.png | Bin 0 -> 614 bytes src/images/basket3-fill-dark.png | Bin 0 -> 708 bytes src/images/basket3-fill-light.png | Bin 0 -> 672 bytes src/includes/config.php | 7 + src/includes/config.php.dist | 7 + src/index.php | 2 +- src/item.php | 28 ++ src/shop.php | 20 +- src/templates/archive.tpl | 418 ++++++++++++++++++++++++++++++ src/templates/home.tpl | 11 + src/templates/navbar.tpl | 1 + 13 files changed, 882 insertions(+), 10 deletions(-) create mode 100644 src/archive.php create mode 100644 src/images/archive-fill-dark.png create mode 100644 src/images/archive-fill-light.png create mode 100644 src/images/basket3-fill-dark.png create mode 100644 src/images/basket3-fill-light.png create mode 100644 src/templates/archive.tpl diff --git a/src/archive.php b/src/archive.php new file mode 100644 index 0000000..059bc38 --- /dev/null +++ b/src/archive.php @@ -0,0 +1,398 @@ +opt(); + +session_start(); +if (!isset($_SESSION["userid"])) { + header("Location: " . getFullPath("login.php")); + exit; +} +else { + $userid = $_SESSION["userid"]; +} + +if (!empty($_GET["message"])) { + $message = filter_var(trim($_GET["message"], FILTER_SANITIZE_STRING));; + $message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); +} + +/* if we've got `page' on the query string, set the session page indicator. */ +if (isset($_GET["offset"])) { + $offset = filter_var(trim($_GET["offset"]), FILTER_SANITIZE_NUMBER_INT); + if (filter_var($offset, FILTER_SANITIZE_NUMBER_INT) === false || $offset == "" || !is_numeric($offset) || $offset < 0) { + die("Invalid page offset ({$_GET["offset"]})"); + } + $_SESSION["offset"] = $offset; +} +else if (isset($_SESSION["offset"])) { + $offset = $_SESSION["offset"]; +} +else { + $offset = 0; +} + +if (!empty($_GET["action"])) { + $action = $_GET["action"]; + if ($action == "ack") { + $stmt = $smarty->dbh()->prepare("UPDATE {$opt["table_prefix"]}messages SET isread = 1 WHERE messageid = ?"); + $stmt->bindValue(1, (int) $messageid, PDO::PARAM_INT); + $stmt->execute(); + } + else if ($action == "approve") { + $stmt = $smarty->dbh()->prepare("UPDATE {$opt["table_prefix"]}shoppers SET pending = 0 WHERE shopper = ? AND mayshopfor = ?"); + $stmt->bindValue(1, (int) $shopper, PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->execute(); + sendMessage($userid,(int) $shopper,$_SESSION["fullname"] . " has approved your request to shop for him/her.", $smarty->dbh(), $smarty->opt()); + } + else if ($action == "decline") { + $stmt = $smarty->dbh()->prepare("DELETE FROM {$opt["table_prefix"]}shoppers WHERE shopper = ? AND mayshopfor = ?"); + $stmt->bindValue(1, (int) $shopper, PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->execute(); + sendMessage($userid,(int) $shopper,$_SESSION["fullname"] . " has declined your request to shop for him/her.", $smarty->dbh(), $smarty->opt()); + } + else if ($action == "request") { + $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}shoppers(shopper,mayshopfor,pending) VALUES(?, ?, ?)"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindValue(2, (int) $shopfor, PDO::PARAM_INT); + $stmt->bindValue(3, $opt["shop_requires_approval"], PDO::PARAM_BOOL); + $stmt->execute(); + if ($opt["shop_requires_approval"]) { + sendMessage($userid,(int) $shopfor,$_SESSION["fullname"] . " has requested to shop for you. Please approve or decline this request.", $smarty->dbh(), $smarty->opt()); + } + } + else if ($action == "cancel") { + // this works for either cancelling a request or "unshopping" for a user. + $stmt = $smarty->dbh()->prepare("DELETE FROM {$opt["table_prefix"]}shoppers WHERE shopper = ? AND mayshopfor = ?"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindValue(2, (int) $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 {$opt["table_prefix"]}shoppers WHERE shopper = ? AND mayshopfor = ?"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindValue(2, (int) $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) $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) $shoppee, PDO::PARAM_INT); + $stmt->bindParam(2, $userid, PDO::PARAM_INT); + $stmt->execute(); + } +} + +$reset_sortdir = false; +if (!empty($_GET["mysort"])) { + $mysort = filter_var(trim($_GET["mysort"]), FILTER_SANITIZE_STRING); + $mysort = htmlspecialchars($mysort, ENT_QUOTES, 'UTF-8'); + if (isset($_SESSION["mysort"]) && $_SESSION["mysort"] != $mysort) { + $reset_sortdir = true; + } + $_SESSION["mysort"] = $mysort; +} + +if (!empty($_GET["sortdir"]) && !$reset_sortdir) { + $sortdir = strtoupper(trim($_GET["sortdir"])) == "DESC" ? "DESC" : "ASC"; + $_SESSION["sortdir"] = $sortdir; +} + +if (!isset($_SESSION["sortdir"]) || $reset_sortdir) { + $sortdir = "ASC"; + $_SESSION["sortdir"] = $sortdir; +} + +if (!isset($_SESSION["mysort"])) { + $sortby = "rankorder {$_SESSION['sortdir']}, i.name"; + $_SESSION["mysort"] = "ranking"; +} +else { + switch ($_SESSION["mysort"]) { + case "name": + $sortby = "i.name {$_SESSION['sortdir']}"; + break; + case "source": + $sortby = "source {$_SESSION['sortdir']}, rankorder, i.name"; + break; + case "quantity": + $sortby = "quantity {$_SESSION['sortdir']}, rankorder, i.name"; + break; + case "price": + $sortby = "price {$_SESSION['sortdir']}, rankorder, i.name"; + break; + case "category": + $sortby = "c.category {$_SESSION['sortdir']}, rankorder, i.name"; + break; + default: + $sortby = "rankorder {$_SESSION['sortdir']}, i.name"; + } +} +$stmt = $smarty->dbh()->prepare("SELECT itemid, name, description, i.category as catid, c.category, price, price as pricenum, source, url, i.ranking as rankid, rendered, comment, quantity, image_filename, public FROM {$opt["table_prefix"]}items i LEFT OUTER JOIN {$opt["table_prefix"]}categories c ON c.categoryid = i.category LEFT OUTER JOIN {$opt["table_prefix"]}ranks r ON r.ranking = i.ranking WHERE userid = ? and i.archive = true ORDER BY " . $sortby); +$stmt->bindParam(1, $userid, PDO::PARAM_INT); +$stmt->execute(); +$myitems_count = 0; +$myitems = array(); +for ($i = 0; $i < $offset; $i++, ++$myitems_count) { + $row = $stmt->fetch(); +} +$i = 0; +while ($i++ < $opt["items_per_page"] && $row = $stmt->fetch()) { + $row['price'] = formatPrice($row['price'], $opt); + $row['urlhost'] = preg_replace("/^(https?:\/\/)?(www\.)?([^\/]+)(\/.*)?$/", "$3", $row['url']); + $myitems[] = $row; + ++$myitems_count; +} +while ($stmt->fetch()) { + ++$myitems_count; +} + +$stmt = $smarty->dbh()->prepare("SELECT categoryid, category FROM {$opt["table_prefix"]}categories ORDER BY category"); +$stmt->execute(); +$categories = array(); +while ($row = $stmt->fetch()) { + $categories[] = $row; +} + +$stmt = $smarty->dbh()->prepare("SELECT ranking, title FROM {$opt["table_prefix"]}ranks ORDER BY rankorder"); +$stmt->execute(); +$ranks = array(); +while ($row = $stmt->fetch()) { + $ranks[] = $row; +} + +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; + } + + $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; + } + $prospects = array(); +} + +$stmt = $smarty->dbh()->prepare("SELECT messageid, u.fullname, message, created " . + "FROM {$opt["table_prefix"]}messages m " . + "INNER JOIN {$opt["table_prefix"]}users u ON u.userid = m.sender " . + "WHERE m.recipient = ? " . + "AND m.isread = 0 " . + "ORDER BY created DESC"); +$stmt->bindParam(1, $userid, PDO::PARAM_INT); +$stmt->execute(); +$messages = array(); +while ($row = $stmt->fetch()) { + $createdDateTime = new DateTime($row['created']); + $row['created'] = $createdDateTime->format($opt["date_format"]); + $messages[] = $row; +} + +$query = "SELECT CONCAT(YEAR(CURDATE()),'-',MONTH(eventdate),'-',DAYOFMONTH(eventdate)) AS DateThisYear, " . + "TO_DAYS(CONCAT(YEAR(CURDATE()),'-',MONTH(eventdate),'-',DAYOFMONTH(eventdate))) AS ToDaysDateThisYear, " . + "CONCAT(YEAR(CURDATE()) + 1,'-',MONTH(eventdate),'-',DAYOFMONTH(eventdate)) AS DateNextYear, " . + "TO_DAYS(CONCAT(YEAR(CURDATE()) + 1,'-',MONTH(eventdate),'-',DAYOFMONTH(eventdate))) AS ToDaysDateNextYear, " . + "TO_DAYS(CURDATE()) AS ToDaysToday, " . + "TO_DAYS(eventdate) AS ToDaysEventDate, " . + "e.userid, u.fullname, description, eventdate, recurring, s.pending " . + "FROM {$opt["table_prefix"]}events e " . + "LEFT OUTER JOIN {$opt["table_prefix"]}users u ON u.userid = e.userid " . + "LEFT OUTER JOIN {$opt["table_prefix"]}shoppers s ON s.mayshopfor = e.userid AND s.shopper = ? "; +if ($opt["show_own_events"]) + $query .= "WHERE (pending = 0 OR pending IS NULL)"; +else + $query .= "WHERE (e.userid <> ? OR e.userid IS NULL) AND (pending = 0 OR pending IS NULL)"; +$query .= "ORDER BY u.fullname"; +$stmt = $smarty->dbh()->prepare($query); +$stmt->bindParam(1, $userid, PDO::PARAM_INT); +if (!$opt["show_own_events"]) + $stmt->bindParam(2, $userid, PDO::PARAM_INT); +$stmt->execute(); +$events = array(); +while ($row = $stmt->fetch()) { + $event_fullname = $row["fullname"]; + $days_left = -1; + if (!$row["recurring"] && (($row["ToDaysEventDate"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysEventDate"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) { + $days_left = $row["ToDaysEventDate"] - $row["ToDaysToday"]; + $event_date = new DateTime($row["eventdate"]); + } + else if ($row["recurring"] && (($row["ToDaysDateThisYear"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysDateThisYear"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) { + $days_left = $row["ToDaysDateThisYear"] - $row["ToDaysToday"]; + $event_date = new DateTime($row["DateThisYear"]); + } + else if ($row["recurring"] && (($row["ToDaysDateNextYear"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysDateNextYear"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) { + $days_left = $row["ToDaysDateNextYear"] - $row["ToDaysToday"]; + $event_date = new DateTime($row["DateNextYear"]); + } + if ($days_left >= 0) { + $thisevent = array( + 'fullname' => $event_fullname, + 'eventname' => $row['description'], + 'daysleft' => $days_left, + 'date' => $event_date->format($opt["date_format"]) + ); + $events[] = $thisevent; + } +} + +function compareEvents($a, $b) { + if ($a["daysleft"] == $b["daysleft"]) + return 0; + else + return ($a["daysleft"] > $b["daysleft"]) ? 1 : -1; +} + +// i couldn't figure out another way to do this, so here goes. +// sort() wanted to sort based on the array keys, which were 0..n - 1, so that was useless. +usort($events, "compareEvents"); + +if ($opt["shop_requires_approval"]) { + $query = "SELECT u.userid, u.fullname " . + "FROM {$opt["table_prefix"]}shoppers s " . + "INNER JOIN {$opt["table_prefix"]}users u ON u.userid = s.shopper " . + "WHERE s.mayshopfor = ? " . + "AND s.pending = 1 " . + "ORDER BY u.fullname"; + $stmt = $smarty->dbh()->prepare($query); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->execute(); + $pending = array(); + while ($row = $stmt->fetch()) { + $pending[] = $row; + } +} + +if (($_SESSION["admin"] == 1) && $opt["newuser_requires_approval"]) { + $query = "SELECT userid, fullname, email, approved, initialfamilyid, familyname " . + "FROM {$opt["table_prefix"]}users u " . + "LEFT OUTER JOIN {$opt["table_prefix"]}families f ON f.familyid = u.initialfamilyid " . + "WHERE approved = 0 " . + "ORDER BY fullname"; + $stmt = $smarty->dbh()->prepare($query); + $stmt->execute(); + $approval = array(); + while ($row = $stmt->fetch()) { + $approval[] = $row; + } +} + +$smarty->assign('fullname', $_SESSION['fullname']); +if (isset($message)) { + $smarty->assign('message', $message); +} +$smarty->assign('mysort', $_SESSION['mysort']); +$smarty->assign('sortdir', $_SESSION['sortdir']); +$smarty->assign('categories', $categories); +$smarty->assign('ranks', $ranks); +$smarty->assign('myitems', $myitems); +$smarty->assign('myitems_count', $myitems_count); +$smarty->assign('offset', $offset); +$smarty->assign('shoppees', $shoppees); +$smarty->assign('prospects', $prospects); +$smarty->assign('messages', $messages); +$smarty->assign('events', $events); +if (isset($pending)) { + $smarty->assign('pending', $pending); +} +if (isset($approval)) { + $smarty->assign('approval', $approval); +} +$smarty->assign('userid', $userid); +$smarty->display('archive.tpl'); +?> diff --git a/src/images/archive-fill-dark.png b/src/images/archive-fill-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..c0dad799268719e3c6aebbabecf463b6ffa5d6c8 GIT binary patch literal 628 zcmV-)0*n2LP)EX>4Tx04R}tkv&MmKpe$iQ;Q-M1v`icW~fefQ4z;lg(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2EW9h?+hq{ROvg%&X$9QWhhy~o`LWs)DGUg;H1>f;?j{slqVm!;ArbawX991=)@`bF& zD(5ZETBXKX_v9}O=k=9kuG1Vr5{p=Z1Q7~qD5C-!F(eS z1EX>4Tx04R}tkv&MmKpe$iQ;Q-M1v`icW~fefQ4z;lg(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2EW9h?+hq{ROvg%&X$9QWhhy~o`LWs)DGUg;H1>f;?j{slqVm!;ArbawX991=)@`bF& zD(5ZETBXKX_v9}O=k=9kuG1Vr5{p=Z1Q7~qD5C-!F6)6!~X!eydxJVMD8fCxKAi zd4zvO_+B6j-0TGoL16dK3~WGoQJ?~>z|^D3+>>%6(DEX5xBvhE07*qoM6N<$f@a|R AQUCw| literal 0 HcmV?d00001 diff --git a/src/images/basket3-fill-dark.png b/src/images/basket3-fill-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..992b8b052043390458b234210d70e14c97afceaa GIT binary patch literal 708 zcmV;#0z3VQP)EX>4Tx04R}tkv&MmKpe$iQ;Q-M1v`icW~fefQ4z;lg(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2EW9h?+hq{ROvg%&X$9QWhhy~o`LWs)DGUg;H1>f;?j{slqVm!;ArbawX991=)@`bF& zD(5ZETBXKX_v9}O=k=9kuG1Vr5{p=Z1Q7~qD5C-!FVE~Yqbz1D%n02Pm+~+F&i|cr?z!-5NvcSS9DXFJ z^6ZBWMi1ya`~lE?36N9=YCy*UXaiMAjl9tdlD4@8X#-tVbWP9#HfA=;1DM$uSOd+> z3ncAIN{g qGqCsoFi$fNKXC}eZ-nEt7Jv&<(n%=4Qrgo10000EX>4Tx04R}tkv&MmKpe$iQ;Q-M1v`icW~fefQ4z;lg(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2EW9h?+hq{ROvg%&X$9QWhhy~o`LWs)DGUg;H1>f;?j{slqVm!;ArbawX991=)@`bF& zD(5ZETBXKX_v9}O=k=9kuG1Vr5{p=Z1Q7~qD5C-!F)5pKoAAs&lKV< zyp4rd@(_9te=ZS3#3rTS71T}(i)gb639KYp5FacoGw;otS!VeGrYIuuBIH`gBE%Ke zk@yD7F83KOm_%}8oH73=SYX%Vjdp=s8?%;*f0QY0iv_8`oWe;%~xZnffctcarXs(U`0000 1, + /* Whether or not clicking the Archive Item link requires a JavaScript-based + confirmation. + 0 = don't show confirmation, + 1 = show confirmation + */ + "confirm_item_archives" => 1, + /* Whether or not clicking the Delete Item link requires a JavaScript-based confirmation. 0 = don't show confirmation, diff --git a/src/includes/config.php.dist b/src/includes/config.php.dist index c28a417..62ecd39 100644 --- a/src/includes/config.php.dist +++ b/src/includes/config.php.dist @@ -61,6 +61,13 @@ function getGlobalOptions() { */ "show_helptext" => 0, + /* Whether or not clicking the Archive Item link requires a JavaScript-based + confirmation. + 0 = don't show confirmation, + 1 = show confirmation + */ + "confirm_item_archives" => 0, + /* Whether or not clicking the Delete Item link requires a JavaScript-based confirmation. 0 = don't show confirmation, diff --git a/src/index.php b/src/index.php index 69c75e6..f6e4c26 100644 --- a/src/index.php +++ b/src/index.php @@ -190,7 +190,7 @@ else { $sortby = "rankorder {$_SESSION['sortdir']}, i.name"; } } -$stmt = $smarty->dbh()->prepare("SELECT itemid, name, description, i.category as catid, c.category, price, price as pricenum, source, url, i.ranking as rankid, rendered, comment, quantity, image_filename, public FROM {$opt["table_prefix"]}items i LEFT OUTER JOIN {$opt["table_prefix"]}categories c ON c.categoryid = i.category LEFT OUTER JOIN {$opt["table_prefix"]}ranks r ON r.ranking = i.ranking WHERE userid = ? ORDER BY " . $sortby); +$stmt = $smarty->dbh()->prepare("SELECT itemid, name, description, i.category as catid, c.category, price, price as pricenum, source, url, i.ranking as rankid, rendered, comment, quantity, image_filename, public FROM {$opt["table_prefix"]}items i LEFT OUTER JOIN {$opt["table_prefix"]}categories c ON c.categoryid = i.category LEFT OUTER JOIN {$opt["table_prefix"]}ranks r ON r.ranking = i.ranking WHERE userid = ? and i.archive = false ORDER BY " . $sortby); $stmt->bindParam(1, $userid, PDO::PARAM_INT); $stmt->execute(); $myitems_count = 0; diff --git a/src/item.php b/src/item.php index be8c6c7..28cf1a6 100644 --- a/src/item.php +++ b/src/item.php @@ -202,6 +202,34 @@ if (!empty($_REQUEST["action"])) { } } + if ($action == "archive") { + try { + $stmt = $smarty->dbh()->prepare("UPDATE {$opt["table_prefix"]}items SET archive=true WHERE itemid = ?"); + $stmt->bindValue(1, (int) $_REQUEST["itemid"], PDO::PARAM_INT); + $stmt->execute(); + + header("Location: " . getFullPath("index.php?message=Item+archived.")); + exit; + } + catch (PDOException $e) { + die("sql exception: " . $e->getMessage()); + } + } + + if ($action == "unarchive") { + try { + $stmt = $smarty->dbh()->prepare("UPDATE {$opt["table_prefix"]}items SET archive=false WHERE itemid = ?"); + $stmt->bindValue(1, (int) $_REQUEST["itemid"], PDO::PARAM_INT); + $stmt->execute(); + + header("Location: " . getFullPath("archive.php?message=Item+unarchived.")); + exit; + } + catch (PDOException $e) { + die("sql exception: " . $e->getMessage()); + } + } + if ($action == "delete") { try { /* find out if this item is bought or reserved. */ diff --git a/src/shop.php b/src/shop.php index 55ad7f5..efe45d4 100644 --- a/src/shop.php +++ b/src/shop.php @@ -163,14 +163,16 @@ if (!empty($_GET["action"])) { } } -if ($public_view == 0) { - $stmt = $smarty->dbh()->prepare("SELECT * FROM {$opt["table_prefix"]}shoppers WHERE shopper = ? AND mayshopfor = ? AND pending = 0"); - $stmt->bindParam(1, $userid, PDO::PARAM_INT); - $stmt->bindParam(2, $shopfor, PDO::PARAM_INT); - $stmt->execute(); - if (!($stmt->fetch())) { - echo "Nice try! (You can't shop for someone who hasn't approved it.)"; - exit; +if (!$opt["auto_connect_family_members"]) { + if ($public_view == 0) { + $stmt = $smarty->dbh()->prepare("SELECT * FROM {$opt["table_prefix"]}shoppers WHERE shopper = ? AND mayshopfor = ? AND pending = 0"); + $stmt->bindParam(1, $userid, PDO::PARAM_INT); + $stmt->bindParam(2, $shopfor, PDO::PARAM_INT); + $stmt->execute(); + if (!($stmt->fetch())) { + echo "Nice try! (You can't shop for someone who hasn't approved it.)"; + exit; + } } } @@ -231,7 +233,7 @@ $sql = "SELECT i.itemid, name, description, price, price as pricenum, source, i. "LEFT OUTER JOIN {$opt["table_prefix"]}allocs a ON a.itemid = i.itemid AND i.quantity = 1 " . // only join allocs for single-quantity items. "LEFT OUTER JOIN {$opt["table_prefix"]}users ub ON ub.userid = a.userid AND a.bought = 1 " . "LEFT OUTER JOIN {$opt["table_prefix"]}users ur ON ur.userid = a.userid AND a.bought = 0 " . - "WHERE i.userid = ? "; + "WHERE i.userid = ? AND i.archive = false "; if ($public_view) { $sql .= "AND public = 1 "; } diff --git a/src/templates/archive.tpl b/src/templates/archive.tpl new file mode 100644 index 0000000..20bf651 --- /dev/null +++ b/src/templates/archive.tpl @@ -0,0 +1,418 @@ +{* +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*} + + + + + {$opt.app_name} - Archive for {$fullname|escape:'htmlall'} + + + + + + + + + + + + + + + {include file='navbar.tpl'} +
+
+ {if isset($message)} + + {/if} + {if $opt.show_helptext} +
+
Help
+
+
    +
  • You can click the column headers to sort by that attribute.
  • +
  • List each item seperately on your list - do not combine items. (i.e. list each book of a 4-part series separately.)
  • +
  • Once you've bought or decided not to buy an item, remember to return to the recipient's gift lists and mark it accordingly.
  • +
  • If someone purchases an item on your list, click to mark it as received.
  • +
  • To unarchive an item on your list, click .
  • +
+
+
+ {/if} +
+

My Items

+
+
+ + + + + + + + + + + + + + {foreach from=$myitems item=row} + + + + + + + + + + {/foreach} + +
Name{if $mysort == "name"} {/if}Ranking{if $mysort == "ranking"} {/if}Quantity{if $mysort == "quantity"} {/if}Category{if $mysort == "category"} {/if}Store{if $mysort == "source"} {/if}Price{if $mysort == "price"} {/if}Actions
+
+ +
+ + {$row.name|truncate:50|escape:'htmlall'} + + + {if $row.public == 1}   Item is Public{/if} +
{$row.rankid}{$row.quantity}{$row.category|default:" "}{$row.source|default:" "}{$row.price} + {if $row.url != ''} + Link  + {/if} + {if $row.image_filename != '' && $opt.allow_images} + Image  + {/if} + Mark Item Received  + Edit Item  + Unarchive Item + Delete Item +
+
+ {if $myitems_count > $opt.items_per_page || $offset > 0} + + {/if} +
+ +
+
+
+ {include file='footer.tpl'} + + diff --git a/src/templates/home.tpl b/src/templates/home.tpl index 89c5183..8326a36 100644 --- a/src/templates/home.tpl +++ b/src/templates/home.tpl @@ -30,6 +30,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA