| 1 |
<?php |
<?php |
| 2 |
/* $Id: wishlist.module,v 1.38.2.2 2007/11/23 18:38:33 smclewin Exp $ */ |
/* $Id: wishlist.module,v 1.40 2007/11/23 18:39:24 smclewin Exp $ */ |
| 3 |
// Wishlist management module for Drupal |
// Wishlist management module for Drupal |
| 4 |
// Written by Scott McLewin and Melanie Paul-McLewin |
// Written by Scott McLewin and Melanie Paul-McLewin |
| 5 |
// drupal AT mclewin DOT com |
// drupal AT mclewin DOT com |
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
|
// D5 conversion steps: http://drupal.org/node/64279 |
|
|
|
|
|
|
|
| 9 |
/** PHP4 compatibliibility **/ |
/** PHP4 compatibliibility **/ |
| 10 |
if (!function_exists("stripos")) { |
if (!function_exists("stripos")) { |
| 11 |
function stripos($str,$needle) { |
function stripos($str,$needle) { |
| 36 |
* A wishlist object, which will be combined with $node |
* A wishlist object, which will be combined with $node |
| 37 |
*/ |
*/ |
| 38 |
function wishlist_load($node) { |
function wishlist_load($node) { |
| 39 |
$wishlist = db_fetch_object(db_query("SELECT * FROM {wishlist} WHERE nid = '$node->nid'")); |
$wishlist = db_fetch_object(db_query('SELECT * FROM {wishlist} WHERE nid = %d', $node->nid)); |
| 40 |
|
|
| 41 |
$wishlist->item_quantity_purchased = _wishlist_get_node_quantity_purchased($node->nid); |
$wishlist->item_quantity_purchased = _wishlist_get_node_quantity_purchased($node->nid); |
| 42 |
|
|
| 76 |
); |
); |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
|
/** |
| 80 |
|
* @desc Register the wishlist module's theme functions |
| 81 |
|
*/ |
| 82 |
|
function wishlist_theme() { |
| 83 |
|
return array( |
| 84 |
|
'wishlist_username' => array( |
| 85 |
|
'arguments' => array('uid' => null, 'defaultname' => null) |
| 86 |
|
), |
| 87 |
|
'wishlist_node_url' => array( |
| 88 |
|
'arguments' => array('url' => null, 'node' => null) |
| 89 |
|
) |
| 90 |
|
); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
/** |
/** |
| 99 |
* @return |
* @return |
| 100 |
* Help text to display |
* Help text to display |
| 101 |
*/ |
*/ |
| 102 |
function wishlist_help($section = '') { |
function wishlist_help($path, $arg) { |
| 103 |
$output =""; |
$output =""; |
| 104 |
|
|
| 105 |
switch ($section) { |
switch ($path) { |
| 106 |
case 'admin/help#wishlist': |
case 'admin/help#wishlist': |
| 107 |
break; |
break; |
| 108 |
case 'node/add#wishlist': |
case 'node/add#wishlist': |
| 153 |
if ($type == 'node' && $node->type == 'wishlist') { |
if ($type == 'node' && $node->type == 'wishlist') { |
| 154 |
// Don't display a redundant edit link if they are node administrators. |
// Don't display a redundant edit link if they are node administrators. |
| 155 |
if (wishlist_access('update', $node) && !user_access('administer nodes')) { |
if (wishlist_access('update', $node) && !user_access('administer nodes')) { |
|
// $links[] = l(t('edit this wishlist item'), "node/$node->nid/edit"); |
|
| 156 |
$links['wishlist_edit_this_item'] = array( |
$links['wishlist_edit_this_item'] = array( |
| 157 |
'title' => t('Edit this wishlist item'), |
'title' => t('Edit this wishlist item'), |
| 158 |
'href' => "node/$node->nid/edit" |
'href' => "node/$node->nid/edit" |
| 163 |
if (user_access('access wishlists') && !_wishlist_hide_purchase_info($node)) { |
if (user_access('access wishlists') && !_wishlist_hide_purchase_info($node)) { |
| 164 |
// Only place the purchase link up if there are any items left |
// Only place the purchase link up if there are any items left |
| 165 |
if($node->item_quantity_purchased < $node->item_quantity_requested) { |
if($node->item_quantity_purchased < $node->item_quantity_requested) { |
|
// $links[] = l(t('get this gift'), "wishlist/item/$node->nid/purchase"); |
|
| 166 |
$links['wishlist_get_this_gift'] = array( |
$links['wishlist_get_this_gift'] = array( |
| 167 |
'title' => t('Get this gift'), |
'title' => t('Get this gift'), |
| 168 |
'href' => "wishlist/item/$node->nid/purchase" |
'href' => "wishlist/item/$node->nid/purchase" |
| 170 |
} |
} |
| 171 |
} else if(!$user->uid) { |
} else if(!$user->uid) { |
| 172 |
// If the user is not logged in, then give them the opportunity to do so. |
// If the user is not logged in, then give them the opportunity to do so. |
|
// $links [] = l(t("login"), "user/login").t(" or ").l(t("register"), "user/register").t(" to purchase wishlist items"); |
|
| 173 |
$links['wishlist_login_or_register'] = array( |
$links['wishlist_login_or_register'] = array( |
| 174 |
'title' => t('<a href="@login">Login</a> or <a href="@register">register</a> to purchase wishlist items', array('@login' => url('user/login'), '@register' => url('user/register'))), |
'title' => t('<a href="@login">Login</a> or <a href="@register">register</a> to purchase wishlist items', array('@login' => url('user/login'), '@register' => url('user/register'))), |
| 175 |
'html' => TRUE |
'html' => TRUE |
| 191 |
// Calculate the time before which we will go looking for items that are fully purchased. |
// Calculate the time before which we will go looking for items that are fully purchased. |
| 192 |
$time = time() - ($expire_days*24*60*60); |
$time = time() - ($expire_days*24*60*60); |
| 193 |
|
|
| 194 |
watchdog('wishlist', "Removing items purchased before ".format_date($time)); |
watchdog('wishlist', "Removing items purchased before @dt", array('@dt' =>format_date($time))); |
| 195 |
|
|
| 196 |
// Pull back all of the items that have been fully purchased where the last |
// Pull back all of the items that have been fully purchased where the last |
| 197 |
// transaction was over 'wishlist_item_expire_days' ago and is public. Move |
// transaction was over 'wishlist_item_expire_days' ago and is public. Move |
| 198 |
// these to the user's private list. Do this in batches of 100. |
// these to the user's private list. Do this in batches of 100. |
| 199 |
// For wishlist installations that pre-date the addition of the purch_date field, the bought items |
// For wishlist installations that pre-date the addition of the purch_date field, the bought items |
| 200 |
// will be moved into the user's private list reguardless of when the last purchase was. |
// will be moved into the user's private list reguardless of when the last purchase was. |
|
/* $sql = "SELECT p.*, MAX(p.purch_date) as compare_date, SUM(p.wishlist_purch_quantity) as purchased, n.title, n.nid, w.item_is_public, w.item_quantity_requested FROM {wishlist_purchased} p |
|
|
INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid |
|
|
INNER JOIN {wishlist} w ON n.nid = w.nid |
|
|
WHERE p.purch_date < %d |
|
|
AND w.item_is_public = 1 |
|
|
GROUP BY n.nid |
|
|
HAVING purchased >= w.item_quantity_requested |
|
|
ORDER BY compare_date LIMIT 100";*/ |
|
| 201 |
$sql = "SELECT p.*, MAX(p.purch_date) as compare_date, SUM(p.wishlist_purch_quantity) as purchased, n.title, n.nid, w.item_is_public, w.item_quantity_requested FROM {wishlist_purchased} p |
$sql = "SELECT p.*, MAX(p.purch_date) as compare_date, SUM(p.wishlist_purch_quantity) as purchased, n.title, n.nid, w.item_is_public, w.item_quantity_requested FROM {wishlist_purchased} p |
| 202 |
INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid |
INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid |
| 203 |
INNER JOIN {wishlist} w ON n.nid = w.nid |
INNER JOIN {wishlist} w ON n.nid = w.nid |
| 210 |
$result = db_query($sql, $time); |
$result = db_query($sql, $time); |
| 211 |
|
|
| 212 |
while($row = db_fetch_object($result)) { |
while($row = db_fetch_object($result)) { |
| 213 |
watchdog('wishlist', t('Hiding purchased item @title. It now appears only on the users private list.', array('@title' => $row->title.' '))); |
watchdog('wishlist', 'Hiding purchased item @title. It now appears only on the users private list.', array('@title' => $row->title.' ')); |
| 214 |
db_query("UPDATE {node} SET status=0 WHERE nid=%d", $row->nid); |
db_query("UPDATE {node} SET status=0 WHERE nid=%d", $row->nid); |
| 215 |
db_query('UPDATE {wishlist} SET item_is_public=0 WHERE nid=%d', $row->nid); |
db_query('UPDATE {wishlist} SET item_is_public=0 WHERE nid=%d', $row->nid); |
| 216 |
} |
} |
| 444 |
db_query('DELETE FROM {wishlist} WHERE nid = %d', $node->nid); |
db_query('DELETE FROM {wishlist} WHERE nid = %d', $node->nid); |
| 445 |
} |
} |
| 446 |
|
|
| 447 |
|
|
| 448 |
|
/** |
| 449 |
|
* @desc Hook_init implementation |
| 450 |
|
* |
| 451 |
|
* Add the wishlist css file to the page. |
| 452 |
|
*/ |
| 453 |
|
function wishlist_init() { |
| 454 |
|
drupal_add_css(drupal_get_path('module', 'wishlist') .'/wishlist.css'); |
| 455 |
|
} |
| 456 |
|
|
| 457 |
/** |
/** |
| 458 |
* hook_menu implementation |
* hook_menu implementation |
| 459 |
* |
* |
| 462 |
* @return |
* @return |
| 463 |
* See hook_menu in http://www.drupaldocs.org for return code details |
* See hook_menu in http://www.drupaldocs.org for return code details |
| 464 |
*/ |
*/ |
| 465 |
function wishlist_menu($may_cache) { |
function wishlist_menu() { |
| 466 |
drupal_add_css(drupal_get_path('module', 'wishlist') .'/wishlist.css'); |
$items['admin/settings/wishlist'] = array( |
| 467 |
|
'title' => 'Wishlist settings', |
| 468 |
if ($may_cache) { |
'description' => 'Configure the wishlist module\'s settings.', |
| 469 |
$items[] = array( |
'page callback' => 'drupal_get_form', |
| 470 |
'path' => 'admin/settings/wishlist', |
'page arguments' => array('wishlist_admin_settings'), |
| 471 |
'title' => t('Wishlist'), |
'access arguments' => array('administer site configuration'), |
| 472 |
'description' => t('Configure the wishlist module\'s settings.'), |
'type' => MENU_NORMAL_ITEM, |
| 473 |
'callback' => 'drupal_get_form', |
'file' => 'wishlist.admin.inc' |
|
'callback arguments' => 'wishlist_admin_settings', |
|
|
'access' => user_access('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM, // optional |
|
| 474 |
); |
); |
| 475 |
$items[] = array('path' => 'node/add/wishlist', 'title' => t('Wishlist'), 'access' => user_access('create wishlists')); |
$items['wishlist/%'] = array( |
| 476 |
$items[] = array('path' => 'wishlist', 'title' => t('Wish lists'), 'callback' => 'wishlist_page', 'access' => user_access('access wishlists'), 'type' => MENU_NORMAL_ITEM); |
'title' => 'Wish lists', |
| 477 |
$items[] = array('path' => 'admin/content/wishlist', 'title' => t('Wishlist'), 'callback' => 'wishlist_admin_page', 'access' => user_access('admin wishlist'), 'type' => MENU_NORMAL_ITEM, 'description' => t('Manage and view the wishlist purchase records for your site.')); |
'page callback' => 'wishlist_page', |
| 478 |
$items[] = array('path' => 'admin/content/wishlist/delete', 'title' => t('Wishlist'), 'callback' => '_wishlist_admin_delete_item', 'access' => user_access('admin wishlist'), 'type' => MENU_CALLBACK); |
'access arguments' => array('access wishlists'), |
| 479 |
|
'type' => MENU_NORMAL_ITEM, |
| 480 |
} |
'file' => 'wishlist.page.inc' |
| 481 |
|
); |
| 482 |
|
$items['wishlist'] = array( |
| 483 |
|
'title' => 'Wish lists', |
| 484 |
|
'page callback' => 'wishlist_page', |
| 485 |
|
'access arguments' => array('access wishlists'), |
| 486 |
|
'type' => MENU_NORMAL_ITEM, |
| 487 |
|
'file' => 'wishlist.page.inc' |
| 488 |
|
); |
| 489 |
|
$items['admin/content/wishlist'] = array( |
| 490 |
|
'title' => 'Wishlist purchases', |
| 491 |
|
'page callback' => 'wishlist_admin_page', |
| 492 |
|
'access arguments' => array('admin wishlist'), |
| 493 |
|
'description' => 'Manage and view the wishlist purchase records for your site.', |
| 494 |
|
'type' => MENU_NORMAL_ITEM, |
| 495 |
|
'file' => 'wishlist.admin.inc' |
| 496 |
|
); |
| 497 |
|
$items['admin/content/wishlist/delete'] = array( |
| 498 |
|
'title' => 'Delete wishlist item', |
| 499 |
|
'page callback' => '_wishlist_admin_delete_item', |
| 500 |
|
'access arguments' => array('admin wishlist'), |
| 501 |
|
'type' => MENU_CALLBACK, |
| 502 |
|
'file' => 'wishlist.admin.inc' |
| 503 |
|
); |
| 504 |
|
return $items; |
| 505 |
|
} |
| 506 |
|
|
| 507 |
return $items ? $items : array(); |
/** |
| 508 |
|
* @desc use hook_menu_alter to put the proper permissions on the wishlist add menu |
| 509 |
|
*/ |
| 510 |
|
function wishlist_menu_alter(&$callbacks) { |
| 511 |
|
$callbacks['node/add/wishlist']['access callback'] = 'user_access'; |
| 512 |
|
$callbacks['node/add/wishlist']['access arguments'] = array('create wishlists'); |
| 513 |
} |
} |
| 514 |
|
|
| 515 |
|
|
| 516 |
|
|
| 517 |
|
|
| 518 |
/** |
/** |
| 519 |
* hook_block implementation |
* hook_block implementation |
| 529 |
return $blocks; |
return $blocks; |
| 530 |
} |
} |
| 531 |
elseif ($op == 'view') { |
elseif ($op == 'view') { |
| 532 |
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.uid, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type='wishlist' GROUP BY u.uid ORDER BY u.name DESC"), 0, variable_get("wishlist_block_max_names", "5")); |
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.uid, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type='%s' GROUP BY u.uid ORDER BY u.name DESC"), 'wishlist', 0, variable_get("wishlist_block_max_names", "5")); |
| 533 |
|
|
| 534 |
// If the site has no wishlists, then return an empty block |
$has_rows = false; |
|
if(0==db_num_rows($result)) { |
|
|
$block["subject"] = ""; |
|
|
$block["content"] = ""; |
|
|
return $block; |
|
|
} |
|
| 535 |
while ($account = db_fetch_object($result)) { |
while ($account = db_fetch_object($result)) { |
| 536 |
$items[] = format_wishlists($account); |
$items[] = format_wishlists($account); |
| 537 |
|
$has_rows = true; |
| 538 |
} |
} |
| 539 |
|
// If the site has no wishlists, then return an empty block |
| 540 |
|
if(false == $has_rows) { |
| 541 |
|
$block["subject"] = ""; |
| 542 |
|
$block["content"] = ""; |
| 543 |
|
return $block; |
| 544 |
|
} |
| 545 |
|
|
| 546 |
|
|
| 547 |
$block_content = theme('item_list', $items); |
$block_content = theme('item_list', $items); |
| 548 |
|
|
| 549 |
// add a more link to our page that displays all the links |
// add a more link to our page that displays all the links |
| 550 |
$block_content .= |
$block_content .= |
| 551 |
"<div class='more-link'>". |
"<div class='more-link'>". |
| 552 |
l(t("More"), "wishlist", array("title" => t("View all wishlists."))) |
l(t("More"), "wishlist", array('attributes' => array("title" => t("View all wishlists.")))) |
| 553 |
."</div>"; |
."</div>"; |
| 554 |
|
|
| 555 |
$block["subject"] = t("Wishlists"); |
$block["subject"] = t("Wishlists"); |
| 632 |
} |
} |
| 633 |
|
|
| 634 |
|
|
|
/** |
|
|
* Administration settings for the wishlist module |
|
|
* |
|
|
*/ |
|
|
function wishlist_admin_settings() { |
|
|
|
|
|
// Drupal 4.7 forms api overview http://drupal.org/node/33338 |
|
|
// Permission Check |
|
|
if (!user_access('admin wishlist')) { |
|
|
return drupal_access_denied(); |
|
|
} |
|
|
|
|
|
$form["wishlist_help"] = array( |
|
|
'#type' => 'textarea', |
|
|
'#title' => t("Explanation or submission guidelines"), |
|
|
'#default_value' => variable_get("wishlist_help", ""), |
|
|
'#cols' => 55, |
|
|
'#rows' => 4, |
|
|
'#description' => t("This text will be displayed at the top of the wishlist item submission form. Useful for helping or instructing your users."), |
|
|
); |
|
|
|
|
|
$form["wishlist_block_max_names"] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t("Maximum number of names to show in Wishlists block"), |
|
|
'#default_value' => variable_get("wishlist_block_max_names", "5"), |
|
|
'#size' => 2, |
|
|
'#maxlength' => 2, |
|
|
'#description' => t("The maximum number of wishlists to display in the block."), |
|
|
); |
|
|
|
|
|
$form['wishlist_currency'] = array('#type' => 'fieldset', '#title' => t('Currency'), '#collapsible' => FALSE); |
|
|
$form['wishlist_currency']["wishlist_show_currency"] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Show the currency field'), |
|
|
'#return_value' => TRUE, |
|
|
'#default_value' => variable_get("wishlist_show_currency", TRUE), |
|
|
'#description' => t('By default the currency field for the price can be set by the user on each wishlist item. If your site only needs to deal in a single currency, you can hide the field. All entries will be saved with the default currency set below.'), |
|
|
); |
|
|
$form['wishlist_currency']["wishlist_default_currency"] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Default currency'), |
|
|
'#default_value' => variable_get("wishlist_default_currency", "USD"), |
|
|
'#size' => 3, |
|
|
'#maxlength' => 3, |
|
|
'#description' => t("Enter the default three letter ISO currency code for new wishlist items."), |
|
|
); |
|
|
|
|
|
|
|
|
$form['wishlist_options'] = array('#type' => 'fieldset', '#title' => t('Misc. options'), '#collapsible' => FALSE); |
|
|
|
|
|
$form['wishlist_options']["wishlist_url_in_new_window"] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t("Open URL links in new window"), |
|
|
'#return_value' => TRUE, |
|
|
'#default_value' => variable_get("wishlist_url_in_new_window", TRUE), |
|
|
'#description' => t("When checked clicking on either the primary or secondary URL fields will open a new browser window."), |
|
|
); |
|
|
|
|
|
$form['wishlist_hideopts'] = array('#type' => 'fieldset', '#title' => t('Item purchased status protection options'), '#collapsible' => FALSE); |
|
|
$form['wishlist_hideopts']["wishlist_hide_purchase_info_anonymous"] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Hide the purchase information from anonymous users'), |
|
|
'#return_value' => TRUE, |
|
|
'#default_value' => variable_get("wishlist_hide_purchase_info_anonymous", FALSE), |
|
|
'#description' => t('Select this box to hide the purchase information about an item for anonymous users. When this is checked, only authenticated users will be able to see whether an item remains available to purchase. This will also remove all links from purchase URLs to prevent an unwitting anonymous user from purchasing an item without indicating it was purchased. This is a way to prevent your users from peeking at the wishlist by visiting the site anonymously.'), |
|
|
); |
|
|
|
|
|
$form['wishlist_hideopts']['wishlist_hide_purchase_info_own'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Hide the purchase information from the user on their own wishlist by default'), |
|
|
'#return_value' => TRUE, |
|
|
'#default_value' => variable_get('wishlist_hide_purchase_info_own', FALSE), |
|
|
'#description' => t('Select this box to hide the purchase information about an item for the owner of the wishlist. When this is checked users will not see the purchased information on their wishlist entries by default. They will need to explicitly choose to reveal purchased items.'), |
|
|
); |
|
|
$form['wishlist_hideopts']['wishlist_hide_admins_own_items'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Hide your (the admin) wishlist items when viewing the wishlist administration screen'), |
|
|
'#return_value' => TRUE, |
|
|
'#default_value' => variable_get('wishlist_hide_admins_own_items', FALSE), |
|
|
'#description' => t('This only applies to site administrators. If checked, the site administrator will not see information about their own items in the wishlist administration screen'), |
|
|
); |
|
|
|
|
|
|
|
|
$form["wishlist_item_expire_days"] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Days before a fully purchased item is hidden'), |
|
|
'#default_value' => variable_get('wishlist_item_expire_days', 30), |
|
|
'#size' => 2, |
|
|
'#maxlength' => 2, |
|
|
'#description' => t("The number of days to leave an item on a user's public wishlist after it has been fully purchased. After this many days, the item will be moved to the user's private wishlist. It will not be deleted. Set to 0 to disable automatic purchased item hiding."), |
|
|
); |
|
|
|
|
|
$form["wishlist_display_count"] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Number of items to display in the user\'s wishlist summary'), |
|
|
'#default_value' => variable_get('wishlist_display_count', 10), |
|
|
'#size' => 2, |
|
|
'#maxlength' => 2, |
|
|
'#description' => t('This is the number of items to display on the wishlist summary page. This value will be applied to both the public wishlist and the user\'s private wishlist.'), |
|
|
); |
|
|
|
|
|
$form['wishlist_table'] = array('#type' => 'fieldset', '#title' => t('Control which columns are displayed'), '#collapsible' => TRUE, '#collapsed' => TRUE); |
|
|
$columns = array( |
|
|
'wishlist_show_action' => t('Action'), |
|
|
'wishlist_show_title' => t('Title'), |
|
|
'wishlist_show_description' => t('Description'), |
|
|
'wishlist_show_priority' => t('Priority'), |
|
|
'wishlist_show_cost' => t('Cost'), |
|
|
'wishlist_show_quantity' => t('Quantity'), |
|
|
'wishlist_show_urls' => t('URLs'), |
|
|
'wishlist_show_updated' => t('Last updated') |
|
|
); |
|
|
|
|
|
|
|
|
$form['wishlist_table']['wishlist_showcolumn'] = array( |
|
|
'#type' => 'checkboxes', |
|
|
'#title' => t('Show the following columns in the wishlist table view'), |
|
|
'#default_value' => variable_get('wishlist_showcolumn', array('wishlist_show_action', 'wishlist_show_title', 'wishlist_show_description','wishlist_show_priority','wishlist_show_cost','wishlist_show_quantity','wishlist_show_urls','wishlist_show_updated')), |
|
|
'#options' => $columns, |
|
|
'#description' => t('This controls which column show up in the wishlist summary view.'), |
|
|
); |
|
|
|
|
|
|
|
|
return system_settings_form($form); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Retrieves the default values array for the show-column settings array |
|
|
*/ |
|
|
function _wishlist_get_default_showcolumn_settings_array() { |
|
|
$default_values['wishlist_show_action'] = true; |
|
|
$default_values['wishlist_show_title'] = true; |
|
|
$default_values['wishlist_show_description'] = true; |
|
|
$default_values['wishlist_show_priority'] = true; |
|
|
$default_values['wishlist_show_cost'] = true; |
|
|
$default_values['wishlist_show_quantity'] = true; |
|
|
$default_values['wishlist_show_urls'] = true; |
|
|
$default_values['wishlist_show_updated'] = true; |
|
|
return $default_values; |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
* Function to display the wishlist module's admin page, where and administrator |
|
|
* can view all purchase records and delete them if necessary. |
|
|
*/ |
|
|
function wishlist_admin_page() { |
|
|
global $user; |
|
|
|
|
|
$sql = "SELECT p.*, buyer.name as buyer_name, receiver.name as receiver_name, n.title, n.nid FROM {wishlist_purchased} p |
|
|
INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid |
|
|
INNER JOIN {users} buyer ON buyer.uid = p.wishlist_purch_buyer_uid |
|
|
INNER JOIN {users} receiver ON receiver.uid = n.uid "; |
|
|
// If the option to suppress having the admin see their own items is on, then remove em from the query. |
|
|
if(variable_get('wishlist_hide_admins_own_items', FALSE)) { |
|
|
$sql .= "WHERE receiver.uid != %d "; |
|
|
} |
|
|
$sql .= "ORDER BY p.purch_date"; |
|
|
$result = db_query($sql, $user->uid); |
|
|
|
|
|
$header = array( |
|
|
array('data' => t('Purchaser')), |
|
|
array('data' => t('On')), |
|
|
array('data' => t('Quantity')), |
|
|
array('data' => t('Item')), |
|
|
array('data' => t('For')), |
|
|
array('data' => t('Action')) |
|
|
); |
|
|
$rows = array(); |
|
|
|
|
|
while($row = db_fetch_object($result)) { |
|
|
$rows[] = array( |
|
|
array('data' => check_plain($row->buyer_name)), |
|
|
array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')), |
|
|
array('data' => $row->wishlist_purch_quantity), |
|
|
array('data' => l(check_plain($row->title), 'node/'.$row->nid)), |
|
|
array('data' => check_plain($row->receiver_name)), |
|
|
array('data' => l(t('Delete'), 'admin/content/wishlist/delete/'.$row->nid.'/'.$row->wishlist_purch_wid)) |
|
|
); |
|
|
} |
|
|
|
|
|
$header_text = '<div>'.t('This is a list of all purchase records for your site. The Delete action will delete the record of the purchase, not the item itself.').'</div>'; |
|
|
|
|
|
if(variable_get('wishlist_hide_admins_own_items', FALSE)) { |
|
|
$header_text .= '<div>'.t('The site is configure to not display your items on this list').'</div>'; |
|
|
} |
|
|
|
|
|
$output = '<div class="wishlist-admin">'; |
|
|
$output .= $header_text.theme('table', $header, $rows); |
|
|
$output .= '</div>'; |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Builds the page to display when a user wants to return an item they already pulled off of a user's wishlist |
|
|
* |
|
|
* @param $nid |
|
|
* The node ID for the item where some of the purchased quantity will be returned |
|
|
* @param $wpid |
|
|
* The ID of the wishlist_purchased record to delete. |
|
|
* |
|
|
* @return |
|
|
* HTML ready for display. |
|
|
*/ |
|
|
function _wishlist_admin_delete_item() { |
|
|
global $user; |
|
|
|
|
|
if(!user_access('admin wishlist')) { |
|
|
watchdog('error', t('A non administrative user attempt to delete a wishlist item')); |
|
|
return t('You are not authorized to delete wishlist items through the administrative interface'); |
|
|
} |
|
|
|
|
|
$delete_nid = check_plain(arg(4)); |
|
|
$delete_wp = check_plain(arg(5)); |
|
|
|
|
|
if(!is_numeric($delete_nid)) { |
|
|
return t('The fourth parameter must be numeric'); |
|
|
} |
|
|
|
|
|
if(!is_numeric($delete_wp)) { |
|
|
return t('The fifth parameter must be numeric'); |
|
|
} |
|
|
|
|
|
$result = db_query("SELECT p.wishlist_purch_nid, p.wishlist_purch_wid, p.wishlist_purch_buyer_uid, p.wishlist_purch_quantity FROM {wishlist_purchased} p WHERE p.wishlist_purch_wid=%d", $delete_wp); |
|
|
if($wishlist_purch = db_fetch_object($result)) { |
|
|
if($delete_nid != $wishlist_purch->wishlist_purch_nid) { |
|
|
return "Inputs do not agree. Node ".$delete_nid." is not related to wpid=".$delete_wp; |
|
|
} |
|
|
} else { |
|
|
return "Invalid record - item return failed for wpid=".$delete_wp; |
|
|
} |
|
|
|
|
|
// Load all this up just so that we can print a nice information message |
|
|
$node = node_load($delete_nid); |
|
|
$purchaser_account = user_load(array('uid' => $user->uid)); |
|
|
$giftee_account = user_load(array('uid' => $node->uid)); |
|
|
watchdog('content', t('The administrator forced a return of @purchase_quantity of "@node_title" from @purchaser_name for @giftee_name', array('@purchaser_name' => $purchaser_account->name, '@purchase_quantity' => $wishlist_purch->wishlist_purch_quantity, '@node_title' => $node->title, '@giftee_name' => $giftee_account->name))); |
|
|
|
|
|
db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_wid = %d', $delete_wp); |
|
|
|
|
|
// Set a successful return and then go back to the node display for this item. |
|
|
drupal_set_message(t('You have deleted the record for a purchase of @purchase_quantity unit for <i>@node_title</i>', array('@purchase_quantity' => $wishlist_purch->wishlist_purch_quantity, '@node_title' => $node->title))); |
|
|
drupal_goto('admin/content/wishlist'); |
|
|
} |
|
|
|
|
| 635 |
|
|
| 636 |
|
|
|
/** |
|
|
* Function to display every wishlist in the system |
|
|
* |
|
|
* @return |
|
|
* A theme("page", ...) with display content showing all available wishlists. |
|
|
*/ |
|
|
function _wishlist_show_all_lists() { |
|
|
$output = ""; |
|
| 637 |
|
|
|
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.uid, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type='wishlist' GROUP BY u.uid ORDER BY u.name DESC")); |
|
|
if(0==db_num_rows($result)) { |
|
|
return t("No wishlists exist on this site"); |
|
|
} |
|
|
|
|
|
$output .= "<div class='wishlist'><div class='all_lists'>"; |
|
|
$output .= '<p>'.t("Wishlists allow their owners to maintain a running list of items they may want to purchase or have purchased for them on a birthday or special occasion. The items on these lists are not sold through this web site, but point to other stores and vendors who do sell them. This list is the on-line version of the birthday list you may have given to your mother growing up. It was her job to make sure that no two people purchased the same gift for you.").'</p>'; |
|
|
while ($account = db_fetch_object($result)) { |
|
|
$items[] = format_wishlists($account, t("'s wishlist")); |
|
|
} |
|
|
|
|
|
$output .= theme('item_list', $items); |
|
|
$output .= "</div></div>"; |
|
| 638 |
|
|
|
return $output; |
|
|
} |
|
| 639 |
|
|
| 640 |
|
|
| 641 |
/** |
/** |
| 652 |
if($page) { |
if($page) { |
| 653 |
$giftee_account = user_load(array('uid' => $node->uid)); |
$giftee_account = user_load(array('uid' => $node->uid)); |
| 654 |
|
|
| 655 |
$breadcrumb = array(); |
$breadcrumb[] = l(t('Home'), NULL); |
| 656 |
$breadcrumb[] = array('path' => 'wishlist', 'title' => t('all wishlists')); |
$breadcrumb[] = l(t('All wishlists'), 'wishlist'); |
| 657 |
$breadcrumb[] = array('path' => 'wishlist/'.$node->uid, 'title' => t("@name's wishlist", array('@name' => $giftee_account->name))); |
$breadcrumb[] = l(t("@name's wishlist", array('@name' => $giftee_account->name)), 'wishlist/'.$node->uid); |
| 658 |
$breadcrumb[] = array('path' => 'node/'.$node->nid); |
drupal_set_breadcrumb($breadcrumb); |
|
menu_set_location($breadcrumb); |
|
| 659 |
} |
} |
| 660 |
|
|
| 661 |
$node->content['wishlist'] = array( |
$node->content['wishlist'] = array( |
| 706 |
// Under a preview of a new node there is nothing to see and no nid value just yet. Skip this code |
// Under a preview of a new node there is nothing to see and no nid value just yet. Skip this code |
| 707 |
if(!is_null($node->nid) && $node->nid > 0) { |
if(!is_null($node->nid) && $node->nid > 0) { |
| 708 |
// Retrieve all of the records showing what the currently logged in user purchaed on this item. |
// Retrieve all of the records showing what the currently logged in user purchaed on this item. |
| 709 |
$result = db_query(db_rewrite_sql("SELECT p.wishlist_purch_wid, p.wishlist_purch_buyer_uid, p.wishlist_purch_quantity FROM {wishlist_purchased} p WHERE p.wishlist_purch_buyer_uid=".$user->uid." AND p.wishlist_purch_nid=".$node->nid, "p", "wishlist_purch_buyer_nid")); |
$result = db_query(db_rewrite_sql("SELECT p.wishlist_purch_wid, p.wishlist_purch_buyer_uid, p.wishlist_purch_quantity FROM {wishlist_purchased} p WHERE p.wishlist_purch_buyer_uid=%d AND p.wishlist_purch_nid=%d", "p", "wishlist_purch_buyer_nid"),$user->uid, $node->nid); |
| 710 |
|
|
| 711 |
$header = array( |
$header = array( |
| 712 |
array('data' => t("Quantity<br>You<br>Purchased")), |
array('data' => t("Quantity<br>You<br>Purchased")), |
| 811 |
|
|
| 812 |
|
|
| 813 |
|
|
|
/** |
|
|
* Menu callback function to handle the "wishlist" URL |
|
|
* |
|
|
* @return |
|
|
* theme("page",...) ready to display the wishlist page result |
|
|
*/ |
|
|
function wishlist_page() { |
|
|
$arg1 = arg(1); |
|
|
|
|
|
if (!isset($arg1)) { |
|
|
print theme("page", _wishlist_show_all_lists()); |
|
|
} else if (is_numeric($arg1)){ |
|
|
print theme("page", _wishlist_list_items($arg1)); |
|
|
} else { |
|
|
switch ($arg1) { |
|
|
case "item": |
|
|
print theme("page", _wishlist_item_action_handler(arg(2), arg(3), arg(4))); |
|
|
break; |
|
|
default: |
|
|
print theme("page", "Invalid argument to wishlist_page [".$arg1."]"); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Lists out the items for the user $uid |
|
|
* |
|
|
* @param $uid |
|
|
* User for whom we should list out wishlist items. |
|
|
* @return |
|
|
* $output for display |
|
|
*/ |
|
|
function _wishlist_list_items($uid) { |
|
|
global $user; |
|
|
|
|
|
if(!is_numeric($uid)) { |
|
|
return theme("page", "Invalid argument to wishlist_list_items [".$uid."]"); |
|
|
} |
|
|
|
|
|
$showcolumns = variable_get('wishlist_showcolumn', _wishlist_get_default_showcolumn_settings_array()); |
|
|
|
|
|
$header = array(); |
|
|
if($showcolumns['wishlist_show_action'] == true) { |
|
|
$header[] = array('data' => t("Action")); |
|
|
} |
|
|
if($showcolumns['wishlist_show_title'] == true) { |
|
|
$header[] = array('data' => t("Item Name"), "field" => "n.title"); |
|
|
} |
|
|
if($showcolumns['wishlist_show_description'] == true) { |
|
|
$header[] = array('data' => t("Description")); |
|
|
} |
|
|
if($showcolumns['wishlist_show_priority'] == true) { |
|
|
$header[] = array('data' => t("Priority"), "field" => "w.item_priority", "sort" => "asc"); |
|
|
} |
|
|
if($showcolumns['wishlist_show_cost'] == true) { |
|
|
$header[] = array('data' => t("Cost"), "field" => "w.item_est_cost"); |
|
|
} |
|
|
if($showcolumns['wishlist_show_quantity'] == true) { |
|
|
$header[] = array('data' => t("Quantity"), "field" => "w.item_quantity_requested"); |
|
|
} |
|
|
if($showcolumns['wishlist_show_urls'] == true) { |
|
|
$header[] = array('data' => t("URLs")); |
|
|
} |
|
|
if($showcolumns['wishlist_show_updated'] == true) { |
|
|
$header[] = array('data' => t("Last Updated"), "field" => "n.changed"); |
|
|
} |
|
|
|
|
|
if(empty($header)) { |
|
|
drupal_set_message('The site administrator has removed all columns from this display. No wishlist information will appear.', 'error'); |
|
|
} |
|
|
|
|
|
// Load up the user account information for the giftee so that we can include it in the display and in the breadcrumb |
|
|
$giftee_account = user_load(array('uid' => $uid)); |
|
|
|
|
|
$breadcrumb = array(); |
|
|
$breadcrumb[] = array('path' => 'wishlist', 'title' => t('All wishlists')); |
|
|
$breadcrumb[] = array('path' => 'wishlist/'.$giftee_account->uid, 'title' => t("@name's wishlist", array('@name' => $giftee_account->name))); |
|
|
menu_set_location($breadcrumb); |
|
|
|
|
|
|
|
|
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.uid, w.item_priority, w.item_est_cost, w.item_currency, r.body, n.changed, n.created, w.item_quantity_requested, w.item_url1, w.item_url2, w.item_is_public FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid LEFT JOIN {wishlist} w ON n.nid = w.nid WHERE n.type='wishlist' AND n.uid=".$uid." AND w.item_is_public ".tablesort_sql($header)), variable_get('wishlist_display_count', 10), 0); |
|
|
|
|
|
$rows = _wishlist_fill_list_table_array($result); |
|
|
|
|
|
|
|
|
if (!$rows) { |
|
|
$rows[] = array(array("data" => t("No wishlist items found."), "colspan" => "5")); |
|
|
} |
|
|
|
|
|
// Add a pager control to the bottom of the table (if necessary) |
|
|
$pager = theme("pager", NULL, variable_get('wishlist_display_count', 10), 0); |
|
|
if (!empty($pager)) { |
|
|
$rows[] = array(array("data" => $pager, "colspan" => "8")); |
|
|
} |
|
|
|
|
|
// Build up the output buffer. |
|
|
$output .= '<div class="wishlist">'; |
|
|
$output .= t("<p>The list below shows all of the items on @giftee_name's wishlist.</p><p>Once you have decided on an item to purchase for @giftee_name, click on 'get this gift' and follow the instructions on the screen that comes up. This will indicate that you have purchased the gift and will prevent somebody else from getting a duplicate. Once you have clicked on 'get this gift' you still need to actually purchase the gift. You don't do that here at this site. You need to visit the store or website described by @giftee_name and complete your transaction there. Please always 'get this gift' here on this website before you purchase it at the store. Somebody else might decide to buy one too while you are out shopping.</p>", array('@giftee_name' => check_plain($giftee_account->name))); |
|
|
$output .= t("<p>If you change your mind about purchasing a particular gift you can put the item back on @giftee_name's wishlist. View the item (by clicking on the 'Item Name' field) and you will be able to return the item to the list. You need to be logged in to this web site to see the 'return' option.</p>", array('@giftee_name' => $giftee_account->name)); |
|
|
$output .= _wishlist_get_reveal_form($uid); |
|
|
$output .= theme('table', $header, $rows) .'</div>'; |
|
|
|
|
|
// If the wishlist being shown belongs to the user who is currently logged in, then also |
|
|
// display a table of the private items below the public ones |
|
|
if($uid == $user->uid) { |
|
|
$output .= "<div class='wishlist_private'>".t("Items which are private and not shown to others who view your wishlist")."</div>"; |
|
|
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.uid, w.item_priority, w.item_est_cost, w.item_currency, r.body, n.changed, n.created, w.item_quantity_requested, w.item_url1, w.item_url2, w.item_is_public FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid LEFT JOIN {wishlist} w ON n.nid = w.nid WHERE n.type='wishlist' AND n.uid=".$uid." AND NOT w.item_is_public ".tablesort_sql($header)), variable_get('wishlist_display_count', 10), 1); |
|
|
|
|
|
$rows = _wishlist_fill_list_table_array($result); |
|
|
if (!$rows) { |
|
|
$rows[] = array(array("data" => t("No private wishlist items found."), "colspan" => "5")); |
|
|
} |
|
|
|
|
|
// Add a pager control to the bottom of the table (if necessary) |
|
|
$pager = theme("pager", NULL, variable_get('wishlist_display_count', 10), 1); |
|
|
if (!empty($pager)) { |
|
|
$rows[] = array(array("data" => $pager, "colspan" => "8")); |
|
|
} |
|
|
|
|
|
$output .= '<div class="wishlist">'. theme('table', $header, $rows) .'</div>'; |
|
|
} |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Fills an associative array for use with a theme('table' call as the $rows argument. |
|
|
* |
|
|
* @param result |
|
|
* Result of a db_query() for a series of node records of type wishlist |
|
|
* |
|
|
* @return |
|
|
* An associative array ready for use with theme('table', ...) call as the $rows argument. |
|
|
*/ |
|
|
function _wishlist_fill_list_table_array($result) { |
|
|
global $user; |
|
|
$priority_str = _wishlist_get_item_priority_array(); |
|
|
|
|
|
$showcolumns = variable_get('wishlist_showcolumn', _wishlist_get_default_showcolumn_settings_array()); |
|
|
|
|
|
|
|
|
while($node = db_fetch_object($result)) { |
|
|
$node->item_quantity_purchased = _wishlist_get_node_quantity_purchased($node->nid); |
|
|
|
|
|
if (drupal_strlen($node->body) > 200) { |
|
|
$body = truncate_utf8($node->body, 200).l("...(more)", "node/$node->nid"); |
|
|
} else { |
|
|
$body = $node->body; |
|
|
} |
|
|
$body = check_markup($body, $node->format); |
|
|
|
|
|
// If the module is configured to toss links open in new windows, then generate the appropriate attributes for the link |
|
|
if(variable_get("wishlist_url_in_new_window", FALSE)) { |
|
|
$url_link_target["target"] = "_wishlist_url_window"; |
|
|
} |
|
|
|
|
|
|
|
|
// In links column display links to the purchase point if there are still items to purchase. |
|
|
// If all have been purchased, don't put the links in the list. This is to cut down |
|
|
// on the folks who will visit, ignore the column about how many are left, click through |
|
|
// to the shop and then end up purchasing a duplicate. We also hide the links when |
|
|
// the module is configured to hide purchase information from anonymous users. |
|
|
if((($node->item_quantity_requested != 0) && ($node->item_quantity_purchased >= $node->item_quantity_requested)) |
|
|
|| _wishlist_hide_purchase_info($node)) { |
|
|
$links = _wishlist_url(check_plain($node->item_url1), 20)."<BR>"._wishlist_url(check_plain($node->item_url2), 20); |
|
|
} else { |
|
|
$links = l(_wishlist_url($node->item_url1, 20), $node->item_url1, $url_link_target)."<BR>".l(_wishlist_url($node->item_url2, 20), $node->item_url2, $url_link_target); |
|
|
} |
|
|
|
|
|
$rowdata = array(); |
|
|
|
|
|
if($showcolumns['wishlist_show_action'] == true) { |
|
|
if(_wishlist_hide_purchase_info($node)) { |
|
|
if($user->uid == $node->uid) { |
|
|
$rowdata[] = array('data' => t('Hidden from you')); |
|
|
} else { |
|
|
$rowdata[] = array('data' => l(t('Login for information on this gift'), "user/login")); |
|
|
} |
|
|
} else { |
|
|
$rowdata[] = array("data" => |
|
|
(user_access('access wishlists') && $node->item_quantity_requested > $node->item_quantity_purchased) ? |
|
|
l(t('Get this gift'), "wishlist/item/$node->nid/purchase") |
|
|
: (($node->item_quantity_purchased >= $node->item_quantity_requested) ? t("(none left to purchase)") |
|
|
: l(t("Login to get this gift"), "user/login"))); |
|
|
} |
|
|
} |
|
|
|
|
|
$newtext = ''; |
|
|
if($user->uid) { |
|
|
$last_viewed = node_last_viewed($node->nid); |
|
|
if(($last_viewed == 0) && ($node->created > NODE_NEW_LIMIT)) { |
|
|
$newtext = '<span class="newitem">'.t('new').'</span>'; |
|
|
} |
|
|
} |
|
|
|
|
|
if($showcolumns['wishlist_show_title'] == true) { |
|
|
$rowdata[] = array("data" => l($node->title, "node/$node->nid").$newtext); |
|
|
} |
|
|
if($showcolumns['wishlist_show_description'] == true) { |
|
|
$rowdata[] = array("data" => $body); |
|
|
} |
|
|
if($showcolumns['wishlist_show_priority'] == true) { |
|
|
$rowdata[] = array("data" => $priority_str[$node->item_priority]); |
|
|
} |
|
|
if($showcolumns['wishlist_show_cost'] == true) { |
|
|
$rowdata[] = array("data" => _wishlist_currency_str($node->item_currency).$node->item_est_cost); |
|
|
} |
|
|
if($showcolumns['wishlist_show_quantity'] == true) { |
|
|
$rowdata[] = array("data" => $node->item_quantity_requested); |
|
|
} |
|
|
if($showcolumns['wishlist_show_urls'] == true) { |
|
|
$rowdata[] = array("data" => $links); |
|
|
} |
|
|
if($showcolumns['wishlist_show_updated'] == true) { |
|
|
$rowdata[] = array("data" => format_date($node->changed, 'small')); |
|
|
} |
|
|
|
|
|
$rows[] = $rowdata; |
|
|
} |
|
|
|
|
|
return $rows; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* |
|
|
* Handler function for actions take on an item - purchase and return |
|
|
* @param $nid |
|
|
* ID of the node on which we are going to act |
|
|
* @param $action |
|
|
* Action to be taken. "purchase" or "return". |
|
|
* @param $wishlist_purch_id |
|
|
* For the return action only, the ID of the wishlist_purchase record that is being returned. |
|
|
* @return |
|
|
* output for display (via theme('page', ...)) |
|
|
*/ |
|
|
function _wishlist_item_action_handler($nid, $action, $wishlist_purch_id) { |
|
|
|
|
|
if(!is_numeric($nid)) { |
|
|
watchdog('error', "Invalid node argument to wishlist_item_action_handler[".$nid."]"); |
|
|
return theme("page", "Invalid node argument to wishlist_item_action_handler[".$nid."]"); |
|
|
} |
|
|
|
|
|
switch($action) { |
|
|
case "purchase": |
|
|
return _wishlist_item_action_purchase($nid); |
|
|
break; |
|
|
case "return": |
|
|
return _wishlist_item_action_return($nid, $wishlist_purch_id); |
|
|
break; |
|
|
|
|
|
default: |
|
|
watchdog("error", "Invalid action argument to wishlist_item_action_handler[".$action."]"); |
|
|
return "Invalid action argument to wishlist_item_action_handler[".$action."]"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
* Builds the page to display when a user wants to purchase an item from a wishlist |
|
|
* |
|
|
* @param $nid |
|
|
* ID of the node on which to act. We assume the user that is currently logged in will be making |
|
|
* the purchase. Purchases by user 0 - anonymous - are not allowed. Purchases off your own list are allowed. |
|
|
* @return |
|
|
* $output for display. |
|
|
*/ |
|
|
function _wishlist_item_action_purchase($nid) { |
|
|
global $user; |
|
|
|
|
|
if($user->uid == 0) { |
|
|
watchdog('error', t('Anonymous user attempted to purchase item off wishlist: nid=@nid. You can prevent this error by removing wishlist permissions from anonymous accounts on your site', array('@nid' => $nid))); |
|
|
return t('Anonymous wishlist purchases are not allowed'); |
|
|
} |
|
|
|
|
|
$node = node_load($nid); |
|
|
|
|
|
drupal_set_title(t('Purchase wishlist item - @title', array('@title' => $node->title))); |
|
|
|
|
|
$output = _wishlist_render_view($node, TRUE); |
|
|
$output .= drupal_get_form("wishlist_action_purchase_form", $node); |
|
|
|
|
|
return $output; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* Returns the form array for the form we display when the user |
|
|
* wants to purchase an item. |
|
|
* |
|
|
* @param $node The node being acted on |
|
|
*/ |
|
|
function wishlist_action_purchase_form($node) { |
|
|
$giftee_account = user_load(array('uid' => $node->uid)); |
|
|
|
|
|
$form["item_action_purchase_quantity"] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t("Quantity that you will purchase"), |
|
|
'#default_value' => $node->item_quantity_requested-$node->item_quantity_purchased, |
|
|
'#size' => 3, |
|
|
'#maxlength' => 3, |
|
|
'#description' => t("Enter the quantity that you intend to purchase for @giftee_name. You should 'purchase' items off the wishlist here before you actually buy the items from the store/website. If you do not, you create the chance for somebody else to get these items instead. Remember, you can always put an item you 'purchase' back on the wishlist.", array('@giftee_name' => $giftee_account->name)), |
|
|
); |
|
|
|
|
|
$form['nid'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#value' => $node->nid |
|
|
); |
|
|
|
|
|
$form[] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Submit'), |
|
|
); |
|
|
|
|
|
return $form; |
|
|
} |
|
|
|
|
|
function wishlist_action_purchase_form_validate($form_id, $form_values) { |
|
|
$item_action_purchase_quantity = check_plain($form_values['item_action_purchase_quantity']); |
|
|
|
|
|
if(!is_numeric($item_action_purchase_quantity)) { |
|
|
form_set_error("item_action_purchase_quantity", t('The purchase quantity must be numeric.')); |
|
|
} |
|
|
|
|
|
if($item_action_purchase_quantity < 0) { |
|
|
form_set_error("item_action_purchase_quantity", t("Your purchase quantity must be a positive number, and not zero.")); |
|
|
} |
|
|
|
|
|
if($item_action_purchase_quantity == 0) { |
|
|
form_set_error("item_action_purchase_quantity", t("Be serious. Zero of them?")); |
|
|
} |
|
|
|
|
|
$node = node_load($form_values['nid']); |
|
|
$items_remaining = $node->item_quantity_requested-_wishlist_get_node_quantity_purchased($form_values['nid']); |
|
|
if($item_action_purchase_quantity > $items_remaining) { |
|
|
form_set_error("item_action_purchase_quantity", t("You cannot purchase more than @items_remaining of this item", array('@items_remaining' => $items_remaining))); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit handler for for the wishlist purchase form |
|
|
* |
|
|
*/ |
|
|
function wishlist_action_purchase_form_submit($form_id, $form_values) { |
|
|
global $user; |
|
|
|
|
|
$node = node_load($form_values['nid']); |
|
|
$purchaser_account = user_load(array('uid' => $user->uid)); |
|
|
$giftee_account = user_load(array('uid' => $node->uid)); |
|
|
|
|
|
// Create the node that tracks what was purchased. |
|
|
db_query("INSERT INTO {wishlist_purchased} (wishlist_purch_nid, wishlist_purch_buyer_uid, wishlist_purch_quantity, purch_date) VALUES |
|
|
(%d, %d, %d, %d)", |
|
|
$node->nid, $purchaser_account->uid, check_plain($form_values['item_action_purchase_quantity']), time()); |
|
|
|
|
|
// Set a successful return and then go back to the node display for this item. |
|
|
watchdog('content', t('@purchaser_name purchased @purchase_quantity of "@node_title" for @giftee_name', array('@purchaser_name' => $purchaser_account->name, '@purchase_quantity' => $item_action_purchase_quantity, '@node_title' => $node->title, '@giftee_name' => $giftee_account->name))); |
|
|
drupal_set_message(t('Your intent to buy @item_purchase_quantity of this item has been recorded. Next you should buy the described item at the store/website that is selling it.', array('@item_purchase_quantity' => $item_action_purchase_quantity))); |
|
|
drupal_goto('node/'.$node->nid); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Builds the page to display when a user wants to return an item they already pulled off of a user's wishlist |
|
|
* |
|
|
* @param $nid |
|
|
* The node ID for the item where some of the purchased quantity will be returned |
|
|
* @param $wpid |
|
|
* The ID of the wishlist_purchased record to delete. |
|
|
* |
|
|
* @return |
|
|
* a theme("page", ...) ready for display. |
|
|
*/ |
|
|
function _wishlist_item_action_return($nid, $wpid) { |
|
|
global $user; |
|
|
|
|
|
if($user->uid == 0) { |
|
|
watchdog('error', t('Anonymous user attempted to return an item from a wishlist: nid=@nid. You can prevent this error by removing wishlist permissions from anonymous accounts on your site', array('@nid' => $nid))); |
|
|
return t("Anonymous wishlist returns are not allowed"); |
|
|
} |
|
|
|
|
|
$result = db_query(db_rewrite_sql("SELECT p.wishlist_purch_nid, p.wishlist_purch_wid, p.wishlist_purch_buyer_uid, p.wishlist_purch_quantity FROM {wishlist_purchased} p WHERE p.wishlist_purch_wid=".$wpid, "p", "wishlist_purch_wid")); |
|
|
if($wishlist_purch = db_fetch_object($result)) { |
|
|
if($nid != $wishlist_purch->wishlist_purch_nid) { |
|
|
return "Inputs do not agree. Node ".$nid." is not related to wpid=".$wpid; |
|
|
} |
|
|
if($user->uid != $wishlist_purch->wishlist_purch_buyer_uid) { |
|
|
return "Inputs do not agree. Node ".$nid."/wpid ".$wpid." was not purchased by user ".$user->uid; |
|
|
} |
|
|
} else { |
|
|
return "Invalid record - item return failed for wpid=".$wpid; |
|
|
} |
|
|
|
|
|
// Load all this up just so that we can print a nice information message |
|
|
$node = node_load($nid); |
|
|
$purchaser_account = user_load(array('uid' => $user->uid)); |
|
|
$giftee_account = user_load(array('uid' => $node->uid)); |
|
|
watchdog('content', t('@purchaser_name returned @purchase_quantity of "@node_title" for @giftee_name', array('@purchaser_name' => $purchaser_account->name, '@purchase_quantity' => $wishlist_purch->wishlist_purch_quantity, '@node_title' => $node->title, '@giftee_name' => $giftee_account->name))); |
|
|
|
|
|
db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_wid = %d', $wpid); |
|
|
|
|
|
// Set a successful return and then go back to the node display for this item. |
|
|
drupal_set_message(t('You have placed @purchase_quantity of <i>@node_title</i> back on the wishlist.', array('@purchase_quantity' => $wishlist_purch->wishlist_purch_quantity, '@node_title' => $node->title))); |
|
|
drupal_goto('node/'.$nid); |
|
|
} |
|
|
|
|
|
|
|
| 814 |
|
|
| 815 |
|
|
| 816 |
/** |
/** |
| 877 |
* A display ready URL fragment |
* A display ready URL fragment |
| 878 |
*/ |
*/ |
| 879 |
function _wishlist_url($url, $maxlength) { |
function _wishlist_url($url, $maxlength) { |
| 880 |
$url = str_replace("http://", "", drupal_strtolower($url)); |
$url = str_replace("http://", "", drupal_strtolower(check_plain($url))); |
| 881 |
if (drupal_strlen($url) > $maxlength) { |
if (drupal_strlen($url) > $maxlength) { |
| 882 |
$url = truncate_utf8($url, $maxlength-3)."..."; |
$url = truncate_utf8($url, $maxlength-3)."..."; |
| 883 |
} |
} |
| 993 |
if(variable_get("wishlist_url_in_new_window", FALSE)) { |
if(variable_get("wishlist_url_in_new_window", FALSE)) { |
| 994 |
$url_link_target["target"] = "_wishlist_url_window"; |
$url_link_target["target"] = "_wishlist_url_window"; |
| 995 |
} |
} |
| 996 |
$output .= t("See")." ".l(_wishlist_url($url, 50), $url, $url_link_target); |
$output .= t("See")." ".l(_wishlist_url($url, 50), $url, array('attributes' => array('target' => $url_link_target))); |
| 997 |
} |
} |
| 998 |
|
|
| 999 |
if(_wishlist_hide_purchase_info($node)) { |
if(_wishlist_hide_purchase_info($node)) { |