Parent Directory
|
Revision Log
|
Revision Graph
|
Patch
| revision 1.38.2.2, Fri Nov 23 18:38:33 2007 UTC | revision 1.38.2.3, Sat Jun 28 21:22:10 2008 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | <?php | <?php |
| 2 | /* $Id: wishlist.module,v 1.38.2.1 2007/11/23 17:52:41 smclewin Exp $ */ | /* $Id: wishlist.module,v 1.38.2.2 2007/11/23 18:38:33 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 | ||
| // D5 conversion steps: http://drupal.org/node/64279 | ||
| 7 | /** PHP4 compatibliibility **/ | /** PHP4 compatibliibility **/ |
| 8 | if (!function_exists("stripos")) { | if (!function_exists('stripos')) { |
| 9 | function stripos($str,$needle) { | function stripos($str, $needle) { |
| 10 | return strpos(strtolower($str),strtolower($needle)); | return strpos(strtolower($str), strtolower($needle)); |
| 11 | } | } |
| 12 | } | } |
| 13 | ||
| 14 | /** | /** |
| 15 | * Hook to return permission supported by this module | * Hook to return permission supported by this module. |
| 16 | * | * |
| 17 | * @return | * @return |
| 18 | * create wishlists - authority to do "create content -> wishlist" | * create wishlists - authority to do "create content -> wishlist" |
| 19 | * edit own wishlist - authority to edit your own wishlist | * edit own wishlist - authority to edit your own wishlist |
| 20 | * admin wishlist - authority to administer the wishlist module | * admin wishlist - authority to administer the wishlist module |
| 21 | * access wishlists - rights to view, purchase and return items on wishlists | * access wishlists - rights to view, purchase and return items on wishlists |
| 22 | * reveal purchase status - authority to reveal purchase status | |
| 23 | */ | */ |
| 24 | function wishlist_perm() { | function wishlist_perm() { |
| 25 | return array ("create wishlists", "edit own wishlist", "admin wishlist", "access wishlists", 'reveal purchase status'); | return array ('create wishlists', 'edit own wishlist', 'admin wishlist', 'access wishlists', 'reveal purchase status'); |
| 26 | } | } |
| 27 | ||
| 28 | /** | /** |
| 29 | * load hook to bring in the wishlist specific node fields | * Load hook to bring in the wishlist specific node fields. |
| 30 | * | * |
| 31 | * @param $node | * @param $node |
| 32 | * Core node record entries | * Core node record entries. |
| 33 | * @return | * @return |
| 34 | * A wishlist object, which will be combined with $node | * A wishlist object, which will be combined with $node. |
| 35 | */ | */ |
| 36 | function wishlist_load($node) { | function wishlist_load($node) { |
| 37 | $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)); |
| 38 | $wishlist->item_quantity_purchased = _wishlist_get_node_quantity_purchased($node->nid); | $wishlist->item_quantity_purchased = _wishlist_get_node_quantity_purchased($node->nid); |
| 39 | return $wishlist; | return $wishlist; |
| 40 | } | } |
| 41 | ||
| 42 | /** | /** |
| 43 | * node_name hook to return this module's name for nodes it creates | * Hook node_name to return this module's name for nodes it creates. |
| 44 | * | * |
| 45 | * @return | * @return |
| 46 | * Name of the node type created by this module | * Name of the node type created by this module. |
| 47 | */ | */ |
| 48 | function wishlist_node_name() { | function wishlist_node_name() { |
| 49 | return 'wishlist'; | return 'wishlist'; |
| 50 | } | } |
| 51 | ||
| 52 | /** | /** |
| 53 | * node_info hook to return this module's name and description for wishlist nodes | * Hook node_info to return this module's name and description for wishlist nodes. |
| 54 | * | * |
| 55 | * @return | * @return |
| 56 | * Name of the node type created by this module | * Name of the node type created by this module. |
| 57 | */ | */ |
| 58 | function wishlist_node_info() { | function wishlist_node_info() { |
| 59 | return array( | return array( |
| 60 | 'wishlist' => | 'wishlist' => array( |
| 61 | array( | 'name' => t('Wishlist item'), |
| 62 | 'name' => t('Wishlist'), | 'module' => 'wishlist', |
| 63 | 'module' => 'wishlist', | 'description' => t('A wishlist allows you maintain a collection of items you want for a special occasion, such as a holiday, birthday or just for the fun of it. The wishlist is just a list, to purchase items users will be directed to the appropriate source.'), |
| 64 | 'description' => t('A wishlist allows you maintain a collection | ), |
| 65 | of items you want for a special occasion, such as a holiday, | ); |
| birthday or just for the fun of it. The wishlist is just a list, | ||
| to purchase items users will be directed to the appropriate source.') | ||
| ) | ||
| ); | ||
| 66 | } | } |
| 67 | ||
| 68 | /** | /** |
| 69 | * Help hook | * Implementation of hook_help(). |
| 70 | * | * |
| 71 | * @param $section | * @param $section |
| 72 | * Which help URL has been requested | * Which help URL has been requested. |
| 73 | * @return | * @return |
| 74 | * Help text to display | * Help text to display. |
| 75 | */ | */ |
| 76 | function wishlist_help($section = '') { | function wishlist_help($section = '') { |
| 77 | $output =""; | $output = ''; |
| 78 | switch ($section) { | switch ($section) { |
| 79 | case 'admin/help#wishlist': | case 'admin/help#wishlist': |
| 80 | break; | break; |
| 81 | case 'node/add#wishlist': | case 'node/add#wishlist': |
| 82 | $output = t("Add an item to one of your wishlist categories."); | $output = t('Add an item to one of your wishlist categories.'); |
| 83 | break; | break; |
| 84 | } | } |
| 85 | return $output; | return $output; |
| 86 | } | } |
| 87 | ||
| 88 | /** | /** |
| 89 | * Access hook for the wishlist module | * Access hook for the wishlist module. |
| 90 | * | * |
| 91 | * @param $op | * @param $op |
| 92 | * Operation the user is requesting | * Operation the user is requesting. |
| 93 | * @param $node | * @param $node |
| 94 | * Node on which the user is requesting the operation | * Node on which the user is requesting the operation. |
| 95 | * @return | * @return |
| 96 | * TRUE/FALSE based on checking permissions | * TRUE/FALSE based on checking permissions. |
| 97 | */ | */ |
| 98 | function wishlist_access($op, $node) { | function wishlist_access($op, $node) { |
| 99 | global $user; | global $user; |
| 100 | if ($op == 'create') { | if ($op == 'create') { |
| 101 | return user_access('create wishlists'); | return user_access('create wishlists'); |
| 102 | } | } |
| 103 | if ($op == 'update' || $op == 'delete' || $op == 'view') { | if ($op == 'update' || $op == 'delete' || $op == 'view') { |
| 104 | if (user_access('edit own wishlist') && ($user->uid == $node->uid)) { | if (user_access('edit own wishlist') && ($user->uid == $node->uid)) { |
| 105 | return TRUE; | return TRUE; |
| 106 | } | } |
| 107 | } | } |
| 108 | } | } |
| 109 | ||
| 110 | /** | /** |
| 111 | * Generates the optional links under the node display | * Implementation of hook_link(). |
| * | ||
| * @param | ||
| * See hook_link documentation | ||
| * @return | ||
| * Array of structured links | ||
| 112 | */ | */ |
| 113 | function wishlist_link($type, $node = 0, $main=0) { | function wishlist_link($type, $node = 0, $main = 0) { |
| 114 | global $user; | global $user; |
| 115 | $links = array(); | $links = array(); |
| 116 | if ($type == 'node' && $node->type == 'wishlist') { | if ($type == 'node' && $node->type == 'wishlist') { |
| 117 | // Don't display a redundant edit link if they are node administrators. | // Don't display a redundant edit link if they are node administrators. |
| 118 | if (wishlist_access('update', $node) && !user_access('administer nodes')) { | if (wishlist_access('update', $node) && !user_access('administer nodes')) { |
| 119 | // $links[] = l(t('edit this wishlist item'), "node/$node->nid/edit"); | $links['wishlist_edit_this_item'] = array( |
| 120 | $links['wishlist_edit_this_item'] = array( | 'title' => t('Edit this wishlist item'), |
| 121 | 'title' => t('Edit this wishlist item'), | 'href' => "node/$node->nid/edit", |
| 122 | 'href' => "node/$node->nid/edit" | ); |
| ); | ||
| 123 | } | } |
| 124 | // If the user has access rights to wishlists, then add links to handle purchases. | |
| // If the user has access rights to wishlists, then add links to handle purchases | ||
| 125 | if (user_access('access wishlists') && !_wishlist_hide_purchase_info($node)) { | if (user_access('access wishlists') && !_wishlist_hide_purchase_info($node)) { |
| 126 | // Only place the purchase link up if there are any items left | // Only place the purchase link up if there are any items left. |
| 127 | if($node->item_quantity_purchased < $node->item_quantity_requested) { | if($node->item_quantity_purchased < $node->item_quantity_requested) { |
| 128 | // $links[] = l(t('get this gift'), "wishlist/item/$node->nid/purchase"); | $links['wishlist_get_this_gift'] = array( |
| 129 | $links['wishlist_get_this_gift'] = array( | 'title' => t('Get this gift'), |
| 130 | 'title' => t('Get this gift'), | 'href' => "wishlist/item/$node->nid/purchase", |
| 131 | 'href' => "wishlist/item/$node->nid/purchase" | ); |
| ); | ||
| 132 | } | } |
| 133 | } else if(!$user->uid) { | } else if(!$user->uid) { |
| 134 | // 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. |
| 135 | // $links [] = l(t("login"), "user/login").t(" or ").l(t("register"), "user/register").t(" to purchase wishlist items"); | $links['wishlist_login_or_register'] = array( |
| 136 | $links['wishlist_login_or_register'] = array( | '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'))), |
| 137 | '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'))), | 'html' => TRUE, |
| 138 | 'html' => TRUE | ); |
| ); | ||
| 139 | } | } |
| 140 | } | } |
| 141 | return $links; | return $links; |
| 142 | } | } |
| 143 | ||
| 144 | /** | |
| 145 | * Implementation of hook_cron(). | |
| 146 | */ | |
| 147 | function wishlist_cron() { | function wishlist_cron() { |
| 148 | $expire_days = variable_get('wishlist_item_expire_days', 30); | $expire_days = variable_get('wishlist_item_expire_days', 30); |
| 149 | // If the automatic expiration feature is disabled, return. | // If the automatic expiration feature is disabled, return. |
| 150 | if($expire_days == 0) { | if($expire_days == 0) { |
| 151 | return; | return; |
| 152 | } | } |
| 153 | // Calculate the time before which we will go looking for items that are fully purchased. | |
| 154 | // Calculate the time before which we will go looking for items that are fully purchased. | $time = time() - ($expire_days*24*60*60); |
| 155 | $time = time() - ($expire_days*24*60*60); | watchdog('wishlist', t('Removing items purchased before @date', array('@date' => format_date($time)))); |
| 156 | // Pull back all of the items that have been fully purchased where the last | |
| 157 | watchdog('wishlist', "Removing items purchased before ".format_date($time)); | // transaction was over 'wishlist_item_expire_days' ago and is public. Move |
| 158 | // these to the user's private list. Do this in batches of 100. | |
| 159 | // Pull back all of the items that have been fully purchased where the last | // For wishlist installations that pre-date the addition of the purch_date field, the bought items |
| 160 | // transaction was over 'wishlist_item_expire_days' ago and is public. Move | // will be moved into the user's private list reguardless of when the last purchase was. |
| 161 | // these to the user's private list. Do this in batches of 100. | $result = db_query('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 w.item_is_public = 1 AND p.purch_date != 0 GROUP BY n.nid HAVING purchased >= w.item_quantity_requested AND compare_date < %d ORDER BY compare_date LIMIT 100', $time); |
| 162 | // For wishlist installations that pre-date the addition of the purch_date field, the bought items | while($row = db_fetch_object($result)) { |
| 163 | // will be moved into the user's private list reguardless of when the last purchase was. | watchdog('wishlist', t('Hiding purchased item @title. It now appears only on the users private list.', array('@title' => $row->title))); |
| 164 | /* $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 | db_query('UPDATE {node} SET status=0 WHERE nid = %d', $row->nid); |
| 165 | INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid | db_query('UPDATE {wishlist} SET item_is_public = 0 WHERE nid = %d', $row->nid); |
| 166 | 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";*/ | ||
| $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 w.item_is_public = 1 | ||
| AND p.purch_date != 0 | ||
| GROUP BY n.nid | ||
| HAVING purchased >= w.item_quantity_requested | ||
| AND compare_date < %d | ||
| ORDER BY compare_date LIMIT 100"; | ||
| $result = db_query($sql, $time); | ||
| while($row = db_fetch_object($result)) { | ||
| watchdog('wishlist', t('Hiding purchased item @title. It now appears only on the users private list.', array('@title' => $row->title.' '))); | ||
| db_query("UPDATE {node} SET status=0 WHERE nid=%d", $row->nid); | ||
| db_query('UPDATE {wishlist} SET item_is_public=0 WHERE nid=%d', $row->nid); | ||
| } | ||
| 167 | } | } |
| 168 | ||
| 169 | /** | /** |
| 170 | * Wishlist node specific form edit/entry generation through hook_form. | * Wishlist node specific form edit/entry generation through hook_form(). |
| 171 | * | * |
| 172 | * @param $node | * @param $node |
| 173 | * See hook_form on http://www.drupaldocs.org for parameter details | * See hook_form on http://www.drupaldocs.org for parameter details. |
| 174 | * @return | * @return |
| 175 | * See hook_form on http://www.drupaldocs.org for return value details | * See hook_form on http://www.drupaldocs.org for return value details. |
| 176 | */ | */ |
| 177 | function wishlist_form(&$node) { | function wishlist_form(&$node) { |
| 178 | $output = ''; | $output = ''; |
| 179 | $form['title'] = array( | $form['title'] = array( |
| 180 | '#type' => 'textfield', | '#type' => 'textfield', |
| 181 | '#title' => t('Title'), | '#title' => t('Title'), |
| # | Line 238 function wishlist_form(&$node) { | Line 186 function wishlist_form(&$node) { |
| 186 | '#attributes' => NULL, | '#attributes' => NULL, |
| 187 | '#required' => TRUE, | '#required' => TRUE, |
| 188 | ); | ); |
| 189 | // In order to be able to attach taxonomy terms to this node, we need | // In order to be able to attach taxonomy terms to this node, we need |
| 190 | // to display the appropriate form elements. | // to display the appropriate form elements. |
| 191 | if (function_exists('taxonomy_node_form')) { | if (function_exists('taxonomy_node_form')) { |
| 192 | $output .= implode('', taxonomy_node_form('wishlist', $node)); | $output .= implode('', taxonomy_node_form('wishlist', $node)); |
| 193 | } | } |
| 194 | // If the item_priority field is set to 0 then assume this is a newly initialized | |
| // IF the item_priority field is set to 0 then assume this is a newly initialized | ||
| 195 | // record and set reasonable defaults on other entries as well. | // record and set reasonable defaults on other entries as well. |
| 196 | if ($node->item_priority == 0) { | if ($node->item_priority == 0) { |
| 197 | $node->item_priority = 3; | $node->item_priority = 3; |
| 198 | $node->item_is_public = TRUE; | $node->item_is_public = TRUE; |
| 199 | } | } |
| 200 | if ($node->item_currency == '') { | |
| 201 | if ($node->item_currency == "") { | $node->item_currency = variable_get('wishlist_default_currency', 'USD'); |
| $node->item_currency = variable_get("wishlist_default_currency", "USD"); | ||
| 202 | } | } |
| 203 | $form['item_is_public'] = array( | |
| $form["item_is_public"] = array( | ||
| 204 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 205 | '#title' => t("Public wish list item"), | '#title' => t('Public wish list item'), |
| 206 | '#return_value' => TRUE, | '#return_value' => TRUE, |
| 207 | '#default_value' => $node->item_is_public, | '#default_value' => $node->item_is_public, |
| 208 | '#description' => t("Makes this item visible to anybody. If you uncheck this only you will be able to view the entry and this node will be set to 'unpublished'."), | '#description' => t("Makes this item visible to anybody. If you uncheck this only you will be able to view the entry and this node will be set to 'unpublished'."), |
| 209 | ); | ); |
| 210 | $form['body'] = array( | |
| $form["body"] = array( | ||
| 211 | '#type' => 'textarea', | '#type' => 'textarea', |
| 212 | '#title' => t("Item Description"), | '#title' => t('Item Description'), |
| 213 | '#default_value' => $node->body, | '#default_value' => $node->body, |
| 214 | '#cols' => 60, | '#cols' => 60, |
| 215 | '#rows' => 18, | '#rows' => 18, |
| 216 | '#description' => t("Give a brief description of the item that you are adding to your wishlist and/or note why you want it"), | '#description' => t('Give a brief description of the item that you are adding to your wishlist and/or note why you want it.'), |
| 217 | ); | ); |
| 218 | // If the admin has hidden the currency field then add the currency to the | |
| // If the admin has hidden the currency field then add the currency to the | ||
| 219 | // title of the estimated cost field. | // title of the estimated cost field. |
| 220 | if(false == variable_get("wishlist_show_currency", TRUE)) { | if(FALSE == variable_get('wishlist_show_currency', TRUE)) { |
| 221 | $est_cost_currency = t(' (in @currency)', array('@currency' => $node->item_currency)); | $est_cost_currency = t(' (in @currency)', array('@currency' => $node->item_currency)); |
| 222 | } else { | } else { |
| 223 | $est_cost_currency = ''; | $est_cost_currency = ''; |
| 224 | } | } |
| 225 | $form['item_est_cost'] = array( | |
| $form["item_est_cost"] = array( | ||
| 226 | '#type' => 'textfield', | '#type' => 'textfield', |
| 227 | '#title' => t("Estimated Cost").$est_cost_currency, | '#title' => t('Estimated Cost') . $est_cost_currency, |
| 228 | '#default_value' => $node->item_est_cost, | '#default_value' => $node->item_est_cost, |
| 229 | '#size' => 5, | '#size' => 5, |
| 230 | '#maxlength' => 5, | '#maxlength' => 5, |
| 231 | '#description' => t("If you know about how much the item will cost, entere it here."), | '#description' => t('If you know about how much the item will cost, entere it here.'), |
| 232 | ); | ); |
| 233 | if(variable_get('wishlist_show_currency', TRUE)) { | |
| 234 | if(variable_get("wishlist_show_currency", TRUE)) { | $form['item_currency'] = array( |
| 235 | $form["item_currency"] = array( | '#type' => 'textfield', |
| 236 | '#type' => 'textfield', | '#title' => t("Currency"), |
| 237 | '#title' => t("Currency"), | '#default_value' => $node->item_currency, |
| 238 | '#default_value' => $node->item_currency, | '#size' => 5, |
| 239 | '#size' => 5, | '#maxlength' => 5, |
| 240 | '#maxlength' => 5, | '#description' => t('Enter the three character ISO currency code for the value in the Estimated Cost field. e.g. USD for US Dollars, THB for Thai Baht, etc.'), |
| 241 | '#description' => t("Enter the three character ISO currency code for the value in the Estimated Cost field. e.g. USD for US Dollars, THB for Thai Baht, etc"), | ); |
| 242 | ); | } |
| 243 | } else { | else { |
| 244 | // If the currency value is not shown we still need to pass through | // If the currency value is not shown we still need to pass through |
| 245 | // the default. Do that through a hidden field. | // the default. Do that through a hidden field. |
| 246 | $form["item_currency"] = array( | $form['item_currency'] = array( |
| 247 | '#type' => 'hidden', | '#type' => 'hidden', |
| 248 | '#default_value' => $node->item_currency, | '#default_value' => $node->item_currency, |
| 249 | '#size' => 5, | '#size' => 5, |
| 250 | '#maxlength' => 5, | '#maxlength' => 5, |
| 251 | ); | ); |
| 252 | } | } |
| 253 | $form["item_url1"] = array( | $form['item_url1'] = array( |
| 254 | '#type' => 'textfield', | '#type' => 'textfield', |
| 255 | '#title' => t("Primary URL"), | '#title' => t('Primary URL'), |
| 256 | '#default_value' => $node->item_url1, | '#default_value' => $node->item_url1, |
| 257 | '#size' => 60, | '#size' => 60, |
| 258 | '#maxlength' => 250, | '#maxlength' => 250, |
| 259 | '#description' => t("Enter the URL from which the item can be purchased. Use the form 'http://www.example.com'"), | '#description' => t("Enter the URL from which the item can be purchased. Use the form 'http://www.example.com'."), |
| 260 | ); | ); |
| 261 | $form['item_url2'] = array( | |
| $form["item_url2"] = array( | ||
| 262 | '#type' => 'textfield', | '#type' => 'textfield', |
| 263 | '#title' => t("Secondary URL"), | '#title' => t('Secondary URL'), |
| 264 | '#default_value' => $node->item_url2, | '#default_value' => $node->item_url2, |
| 265 | '#size' => 60, | '#size' => 60, |
| 266 | '#maxlength' => 250, | '#maxlength' => 250, |
| 267 | '#description' => t("Optionally enter another URL from which the item can be purchased. Use the form 'http://www.example.com'"), | '#description' => t("Optionally enter another URL from which the item can be purchased. Use the form 'http://www.example.com'."), |
| 268 | ); | ); |
| 269 | $form['item_quantity_requested'] = array( | |
| $form["item_quantity_requested"] = array( | ||
| 270 | '#type' => 'textfield', | '#type' => 'textfield', |
| 271 | '#title' => t("Quantity Requested"), | '#title' => t('Quantity Requested'), |
| 272 | '#default_value' => $node->item_quantity_requested, | '#default_value' => $node->item_quantity_requested, |
| 273 | '#size' => 5, | '#size' => 5, |
| 274 | '#maxlength' => 5, | '#maxlength' => 5, |
| 275 | '#description' => t("Enter the number of this item that you would like if one is not enough"), | '#description' => t('Enter the number of this item that you would like if one is not enough.'), |
| 276 | ); | ); |
| 277 | $options = _wishlist_get_item_priority_array(); | $options = _wishlist_get_item_priority_array(); |
| 278 | $form['item_priority'] = array( | |
| $form["item_priority"] = array( | ||
| 279 | '#type' => 'select', | '#type' => 'select', |
| 280 | '#title' => t("Priority"), | '#title' => t('Priority'), |
| 281 | '#default_value' => $node->item_priority, | '#default_value' => $node->item_priority, |
| 282 | '#options' => $options, | '#options' => $options, |
| 283 | '#description' => t("Rate the importance of this item to help your friends and family select a gift"), | '#description' => t('Rate the importance of this item to help your friends and family select a gift.'), |
| 284 | '#extra' => FALSE, | '#extra' => FALSE, |
| 285 | ); | ); |
| 286 | return $form; | return $form; |
| 287 | } | } |
| 288 | ||
| 289 | /** | /** |
| 290 | * Implementation of wishlist_validate(). | * Implementation of wishlist_validate(). |
| 291 | * | * |
| 292 | * Our "quantity" field requires a number to be entered. This hook lets | * Our "quantity" field requires a number to be entered. This hook lets |
| 293 | * us ensure that the user entered an appropriate value before we try | * us ensure that the user entered an appropriate value before we try |
| 294 | * inserting anything into the database. | * inserting anything into the database. |
| * | ||
| * Errors should be signaled with form_set_error(). | ||
| 295 | */ | */ |
| 296 | function wishlist_validate(&$node) { | function wishlist_validate(&$node) { |
| 297 | // We allow 0 as a quantity for placeholder wishlist items, such as pointers to a wishlist | // We allow 0 as a quantity for placeholder wishlist items, such as pointers to a wishlist |
| 298 | // on a shopping web site. | // on a shopping web site. |
| 299 | if($node->item_quantity_requested == '') { | if($node->item_quantity_requested == '') { |
| 300 | form_set_error('item_quantity_requested', t('Please enter the quantity requested.')); | form_set_error('item_quantity_requested', t('Please enter the quantity requested.')); |
| 301 | } else if (!is_numeric($node->item_quantity_requested)) { | } |
| 302 | form_set_error('item_quantity_requested', t('The requested quantity must be a number.')); | elseif (!is_numeric($node->item_quantity_requested)) { |
| 303 | } else if($node->item_quantity_requested < 0) { | form_set_error('item_quantity_requested', t('The requested quantity must be a number.')); |
| 304 | form_set_error('item_quantity_requested', t('The requested quantitiy cannot be negative.')); | } |
| 305 | } | elseif($node->item_quantity_requested < 0) { |
| 306 | form_set_error('item_quantity_requested', t('The requested quantitiy cannot be negative.')); | |
| 307 | if($node->item_est_cost == '') { | } |
| 308 | form_set_error('item_est_cost', t('You must enter a cost for this wishlist item')); | if($node->item_est_cost == '') { |
| 309 | } else if (!is_numeric($node->item_est_cost)) { | form_set_error('item_est_cost', t('You must enter a cost for this wishlist item')); |
| 310 | form_set_error('item_est_cost', t('You must enter a numeric value for the cost.')); | } |
| 311 | } | elseif (!is_numeric($node->item_est_cost)) { |
| 312 | } | form_set_error('item_est_cost', t('You must enter a numeric value for the cost.')); |
| 313 | } | |
| 314 | } | |
| 315 | ||
| 316 | /** | /** |
| 317 | * Implementation of wishlist_insert(). | * Implementation of wishlist_insert(). |
| 318 | * | * |
| # | Line 389 function wishlist_validate(&$node) { | Line 322 function wishlist_validate(&$node) { |
| 322 | function wishlist_insert($node) { | function wishlist_insert($node) { |
| 323 | $node->item_url1 = _wishlist_correct_url($node->item_url1); | $node->item_url1 = _wishlist_correct_url($node->item_url1); |
| 324 | $node->item_url2 = _wishlist_correct_url($node->item_url2); | $node->item_url2 = _wishlist_correct_url($node->item_url2); |
| 325 | db_query("INSERT INTO {wishlist} (nid, item_is_public, item_est_cost, item_url1, item_url2, item_quantity_requested, item_priority, item_currency) VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s')", $node->nid, $node->item_is_public, $node->item_est_cost, $node->item_url1, $node->item_url2, $node->item_quantity_requested, $node->item_priority[0], $node->item_currency); | |
| 326 | db_query("INSERT INTO {wishlist} (nid, item_is_public, item_est_cost, item_url1, item_url2, item_quantity_requested, item_priority, item_currency) VALUES | // If this item is not public, then unpublish it. I personally think this is a little hack, |
| (%d, %d, %d, '%s', '%s', %d, %d, '%s')", | ||
| $node->nid, $node->item_is_public, $node->item_est_cost, $node->item_url1, $node->item_url2, $node->item_quantity_requested, $node->item_priority[0], $node->item_currency); | ||
| // If this item is not public, then unpublish it. I personally think this is a little hack, | ||
| 327 | // but I was unable to work out how to prevent a node from loading if it is "private". wishlist_load | // but I was unable to work out how to prevent a node from loading if it is "private". wishlist_load |
| 328 | // cannot return a value that prevents the node from being brought in. While the display logic in | // cannot return a value that prevents the node from being brought in. While the display logic in |
| 329 | // wishlist_view can be suppressed, that only gets rid of the wishlist specific display elements. | // wishlist_view can be suppressed, that only gets rid of the wishlist specific display elements. |
| 330 | // The item name and description, which are in the node table, are both displayed. | // The item name and description, which are in the node table, are both displayed. |
| 331 | // Before running this logic, test to see if the item_is_public member even exists. If it does not, | // Before running this logic, test to see if the item_is_public member even exists. If it does not, |
| 332 | // then it means this call to hook_validate is taking place as the $node is being built for the first | // then it means this call to hook_validate is taking place as the $node is being built for the first |
| 333 | // time. Don't go setting the status to unpublished in that case. | // time. Don't go setting the status to unpublished in that case. |
| 334 | if (!$node->item_is_public) { | if (!$node->item_is_public) { |
| 335 | db_query("UPDATE {node} SET status=0 WHERE nid=%d", $node->nid); | db_query("UPDATE {node} SET status = 0 WHERE nid = %d", $node->nid); |
| 336 | } | } |
| 337 | } | } |
| 338 | ||
| 339 | /** | /** |
| 340 | * Implementation of wishlist_update(). | * Implementation of wishlist_update(). |
| 341 | * | * |
| # | Line 416 function wishlist_insert($node) { | Line 343 function wishlist_insert($node) { |
| 343 | * database updates. | * database updates. |
| 344 | */ | */ |
| 345 | function wishlist_update($node) { | function wishlist_update($node) { |
| 346 | $node->item_url1 = _wishlist_correct_url($node->item_url1); | $node->item_url1 = _wishlist_correct_url($node->item_url1); |
| 347 | $node->item_url2 = _wishlist_correct_url($node->item_url2); | $node->item_url2 = _wishlist_correct_url($node->item_url2); |
| 348 | db_query("UPDATE {wishlist} SET item_is_public= %d, item_est_cost= '%s', item_url1= '%s', item_url2= '%s', item_quantity_requested= %d, item_currency='%s', item_priority=%d WHERE nid=%d", $node->item_is_public, $node->item_est_cost, $node->item_url1, $node->item_url2, $node->item_quantity_requested, $node->item_currency, $node->item_priority[0], $node->nid); | db_query("UPDATE {wishlist} SET item_is_public = %d, item_est_cost = '%s', item_url1 = '%s', item_url2 = '%s', item_quantity_requested = %d, item_currency = '%s', item_priority = %d WHERE nid = %d", $node->item_is_public, $node->item_est_cost, $node->item_url1, $node->item_url2, $node->item_quantity_requested, $node->item_currency, $node->item_priority[0], $node->nid); |
| 349 | // If this item is not public, then unpublish it. I personally think this is a little hack, | // If this item is not public, then unpublish it. I personally think this is a little hack, |
| 350 | // but I was unable to work out how to prevent a node from loading if it is "private". wishlist_load | // but I was unable to work out how to prevent a node from loading if it is "private". wishlist_load |
| 351 | // cannot return a value that prevents the node from being brought in. While the display logic in | // cannot return a value that prevents the node from being brought in. While the display logic in |
| 352 | // wishlist_view can be suppressed, that only gets rid of the wishlist specific display elements. | // wishlist_view can be suppressed, that only gets rid of the wishlist specific display elements. |
| 353 | // The item name and description, which are in the node table, are both displayed. | // The item name and description, which are in the node table, are both displayed. |
| 354 | // Before running this logic, test to see if the item_is_public member even exists. If it does not, | // Before running this logic, test to see if the item_is_public member even exists. If it does not, |
| 355 | // then it means this call to hook_validate is taking place as the $node is being built for the first | // then it means this call to hook_validate is taking place as the $node is being built for the first |
| 356 | // time. Don't go setting the status to unpublished in that case. | // time. Don't go setting the status to unpublished in that case. |
| 357 | if (!$node->item_is_public) { | if (!$node->item_is_public) { |
| 358 | db_query("UPDATE {node} SET status=0 WHERE nid=%d", $node->nid); | db_query("UPDATE {node} SET status = 0 WHERE nid = %d", $node->nid); |
| 359 | } | } |
| 360 | } | } |
| 361 | ||
| 362 | /** | /** |
| 363 | * Implementation of wishlist_delete(). | * Implementation of wishlist_delete(). |
| 364 | * | * |
| # | Line 443 function wishlist_update($node) { | Line 367 function wishlist_update($node) { |
| 367 | function wishlist_delete($node) { | function wishlist_delete($node) { |
| 368 | db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_nid = %d', $node->nid); | db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_nid = %d', $node->nid); |
| 369 | db_query('DELETE FROM {wishlist} WHERE nid = %d', $node->nid); | db_query('DELETE FROM {wishlist} WHERE nid = %d', $node->nid); |
| 370 | } | } |
| 371 | ||
| 372 | /** | /** |
| 373 | * hook_menu implementation | * Implementation if hook_menu(). |
| 374 | * | * |
| 375 | * @param | * @param |
| 376 | * See hook_menu in http://www.drupaldocs.org for parameter details | * See hook_menu in http://www.drupaldocs.org for parameter details. |
| 377 | * @return | * @return |
| 378 | * See hook_menu in http://www.drupaldocs.org for return code details | * See hook_menu in http://www.drupaldocs.org for return code details. |
| 379 | */ | */ |
| 380 | function wishlist_menu($may_cache) { | function wishlist_menu($may_cache) { |
| 381 | drupal_add_css(drupal_get_path('module', 'wishlist') .'/wishlist.css'); | drupal_add_css(drupal_get_path('module', 'wishlist') .'/wishlist.css'); |
| 382 | if ($may_cache) { | if ($may_cache) { |
| 383 | $items[] = array( | $items[] = array( |
| 384 | 'path' => 'admin/settings/wishlist', | 'path' => 'admin/settings/wishlist', |
| 385 | 'title' => t('Wishlist'), | 'title' => t('Wishlist'), |
| 386 | 'description' => t('Configure the wishlist module\'s settings.'), | 'description' => t('Configure the wishlist module\'s settings.'), |
| 387 | 'callback' => 'drupal_get_form', | 'callback' => 'drupal_get_form', |
| 388 | 'callback arguments' => 'wishlist_admin_settings', | 'callback arguments' => 'wishlist_admin_settings', |
| 389 | 'access' => user_access('administer site configuration'), | 'access' => user_access('administer site configuration'), |
| 390 | 'type' => MENU_NORMAL_ITEM, // optional | 'type' => MENU_NORMAL_ITEM, // optional |
| 391 | ); | ); |
| 392 | $items[] = array('path' => 'node/add/wishlist', 'title' => t('Wishlist'), 'access' => user_access('create wishlists')); | $items[] = array( |
| 393 | $items[] = array('path' => 'wishlist', 'title' => t('Wish lists'), 'callback' => 'wishlist_page', 'access' => user_access('access wishlists'), 'type' => MENU_NORMAL_ITEM); | 'path' => 'node/add/wishlist', |
| 394 | $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.')); | 'title' => t('Wishlist item'), |
| 395 | $items[] = array('path' => 'admin/content/wishlist/delete', 'title' => t('Wishlist'), 'callback' => '_wishlist_admin_delete_item', 'access' => user_access('admin wishlist'), 'type' => MENU_CALLBACK); | 'access' => user_access('create wishlists'), |
| 396 | ); | |
| 397 | } | $items[] = array( |
| 398 | 'path' => 'wishlist', | |
| 399 | 'title' => t('Wish lists'), | |
| 400 | 'callback' => 'wishlist_page', | |
| 401 | 'access' => user_access('access wishlists'), | |
| 402 | 'type' => MENU_NORMAL_ITEM, | |
| 403 | ); | |
| 404 | $items[] = array( | |
| 405 | 'path' => 'admin/content/wishlist', | |
| 406 | 'title' => t('Wishlist purchases'), | |
| 407 | 'callback' => 'wishlist_admin_page', | |
| 408 | 'access' => user_access('admin wishlist'), | |
| 409 | 'type' => MENU_NORMAL_ITEM, | |
| 410 | 'description' => t('Manage and view the wishlist purchase records for your site.') | |
| 411 | ); | |
| 412 | $items[] = array( | |
| 413 | 'path' => 'admin/content/wishlist/delete', | |
| 414 | 'title' => t('Wishlist'), | |
| 415 | 'callback' => '_wishlist_admin_delete_item', | |
| 416 | 'access' => user_access('admin wishlist'), | |
| 417 | 'type' => MENU_CALLBACK, | |
| 418 | ); | |
| 419 | } | |
| 420 | return $items ? $items : array(); | return $items ? $items : array(); |
| 421 | } | } |
| 422 | ||
| 423 | /** | /** |
| 424 | * hook_block implementation | * Implementation of hook_block(). |
| * | ||
| * @param | ||
| * See hook_block in http://www.drupaldocs.org for parameter details | ||
| * @return | ||
| * See hook_block in http://www.drupaldocs.org for return code details | ||
| 425 | */ | */ |
| 426 | function wishlist_block($op = "list", $delta = 0) { | function wishlist_block($op = 'list', $delta = 0) { |
| 427 | if ($op == "list") { | if ($op == 'list') { |
| 428 | $blocks[0]["info"] = t("Wishlists"); | $blocks[0]["info"] = t('Wishlists'); |
| 429 | return $blocks; | return $blocks; |
| 430 | } | } |
| 431 | elseif ($op == 'view') { | if ($op == 'view') { |
| 432 | $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 = 'wishlist' GROUP BY u.uid ORDER BY u.name DESC"), 0, variable_get('wishlist_block_max_names', '5')); |
| 433 | // If the site has no wishlists, then return an empty block. | |
| 434 | // If the site has no wishlists, then return an empty block | if(0 == db_num_rows($result)) { |
| 435 | if(0==db_num_rows($result)) { | $block['subject'] = ''; |
| 436 | $block["subject"] = ""; | $block['content'] = ''; |
| 437 | $block["content"] = ""; | return $block; |
| return $block; | ||
| 438 | } | } |
| 439 | while ($account = db_fetch_object($result)) { | while ($account = db_fetch_object($result)) { |
| 440 | $items[] = format_wishlists($account); | $items[] = format_wishlists($account); |
| 441 | } | } |
| 442 | $block_content = theme('item_list', $items); | $block_content = theme('item_list', $items); |
| 443 | // Add a more link to our page that displays all the links. | |
| 444 | // add a more link to our page that displays all the links | $block_content .= '<div class="more-link">'. l(t('More'), 'wishlist', array('title' => t('View all wishlists.'))) .'</div>'; |
| 445 | $block_content .= | $block['subject'] = t('Wishlists'); |
| 446 | "<div class='more-link'>". | $block['content'] = $block_content; |
| l(t("More"), "wishlist", array("title" => t("View all wishlists."))) | ||
| ."</div>"; | ||
| $block["subject"] = t("Wishlists"); | ||
| $block["content"] = $block_content; | ||
| 447 | return $block; | return $block; |
| 448 | } | } |
| 449 | } | } |
| 450 | ||
| 451 | /** | /** |
| 452 | * Allows for a site to theme the username. An example reason to do this | * Allows for a site to theme the username. An example reason to do this |
| 453 | * would be to display the user's real name from a site specific profile system | * would be to display the user's real name from a site specific profile system |
| 454 | * rather than to use the name in the Drupal user record. The output will be | * rather than to use the name in the Drupal user record. The output will be |
| 455 | * truncated to 15 characters. It should contain no markup. | * truncated to 15 characters. It should contain no markup. |
| * | ||
| 456 | */ | */ |
| 457 | function theme_wishlist_username($uid, $defaultname) { | function theme_wishlist_username($uid, $defaultname) { |
| 458 | return $defaultname; | return $defaultname; |
| 459 | } | } |
| 460 | ||
| 461 | /** | /** |
| 462 | * Formats the wishlist item title with (or without) appropriate links to the full record | * Formats the wishlist item title with (or without) appropriate links to the full record. |
| 463 | * | * |
| 464 | * @param $object | * @param $object |
| 465 | * The wishlist node to format | * The wishlist node to format. |
| 466 | * @param $append_text | * @param $append_text |
| 467 | * Optional text to tack on the end of the user's name. | * Optional text to tack on the end of the user's name. |
| 468 | * @return | * @return |
| 469 | * Formatted text ready for display | * Formatted text ready for display. |
| 470 | */ | */ |
| 471 | function format_wishlists($object, $append_text="") { | function format_wishlists($object, $append_text = '') { |
| 472 | global $user; | global $user; |
| 473 | if ($object->uid && $object->name) { | if ($object->uid && $object->name) { |
| 474 | $fullname = theme('wishlist_username', $object->uid, $object->name); | $fullname = theme('wishlist_username', $object->uid, $object->name); |
| 475 | // Shorten the name when it is too long or it will break many tables. | // Shorten the name when it is too long or it will break many tables. |
| 476 | if (drupal_strlen($fullname) > 20) { | if (drupal_strlen($fullname) > 20) { |
| 477 | $name = truncate_utf8($fullname, 15) .'...'; | $name = truncate_utf8($fullname, 15) .'...'; |
| 478 | } else { | } else { |
| 479 | $name = $fullname; | $name = $fullname; |
| 480 | } | } |
| 481 | $output = l($name . $append_text, 'wishlist/'. $object->uid, array('title' => t('View wishlist items for @user', array('@user' => check_plain($fullname))))); | |
| $output = l($name.$append_text, 'wishlist/'. $object->uid, array('title' => t('View wishlist items for ').check_plain($fullname))); | ||
| 482 | } | } |
| 483 | else if ($object->name) { | else if ($object->name) { |
| 484 | // Sometimes modules display content composed by people who are | // Sometimes modules display content composed by people who are |
| # | Line 560 function format_wishlists($object, $appe | Line 486 function format_wishlists($object, $appe |
| 486 | // aggregator modules). This clause enables modules to display | // aggregator modules). This clause enables modules to display |
| 487 | // the true author of the content. | // the true author of the content. |
| 488 | if ($object->homepage) { | if ($object->homepage) { |
| 489 | $output = '<a href="'. $object->homepage .'">'. check_plain($object->name.$append_text).'</a>'; | $output = '<a href="'. $object->homepage .'">'. check_plain($object->name . $append_text) .'</a>'; |
| 490 | } | } |
| 491 | else { | else { |
| 492 | $output = check_plain($object->name.$append_text); | $output = check_plain($object->name . $append_text); |
| 493 | } | } |
| 494 | $output .= ' ('. t('not verified') .')'; | $output .= ' ('. t('not verified') .')'; |
| 495 | } | } |
| 496 | else { | else { |
| 497 | $output = variable_get('anonymous', 'Anonymous'); | $output = variable_get('anonymous', 'Anonymous'); |
| 498 | } | } |
| 499 | // If the curent user is logged in, then also look for new items. | // If the curent user is logged in, then also look for new items. |
| 500 | if($user->uid && $object->uid) { | if($user->uid && $object->uid) { |
| 501 | $sql = "SELECT COUNT(n.nid) FROM {node} n | $new_count = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d WHERE n.status = 1 AND u.uid = %d AND n.type = 'wishlist' AND n.created > %d AND h.nid IS NULL"), $user->uid, $object->uid, NODE_NEW_LIMIT)); |
| 502 | INNER JOIN {users} u ON n.uid = u.uid | if($new_count > 0) { |
| 503 | LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d | $output .= '<span class="new-wishlist-items">'. t('@count new', array('@count' => $new_count)) .'</span>'; |
| 504 | WHERE n.status = 1 | } |
| AND u.uid = %d | ||
| AND n.type = 'wishlist' | ||
| AND n.created > %d | ||
| AND h.nid IS NULL"; | ||
| $sql = db_rewrite_sql($sql); | ||
| $new_count = db_result(db_query($sql, $user->uid, $object->uid, NODE_NEW_LIMIT)); | ||
| if($new_count > 0) { | ||
| $output .= '<span class="new-wishlist-items">'.t('@count new', array('@count' => $new_count)).'</span>'; | ||
| } | ||
| 505 | } | } |
| 506 | return $output; | return $output; |
| 507 | } | } |
| 508 | ||
| 509 | /** | /** |
| 510 | * Administration settings for the wishlist module | * Administration settings for the wishlist module. |
| * | ||
| 511 | */ | */ |
| 512 | function wishlist_admin_settings() { | function wishlist_admin_settings() { |
| // Drupal 4.7 forms api overview http://drupal.org/node/33338 | ||
| // Permission Check | ||
| 513 | if (!user_access('admin wishlist')) { | if (!user_access('admin wishlist')) { |
| 514 | return drupal_access_denied(); | return drupal_access_denied(); |
| 515 | } | } |
| 516 | $form['wishlist_help'] = array( | |
| $form["wishlist_help"] = array( | ||
| 517 | '#type' => 'textarea', | '#type' => 'textarea', |
| 518 | '#title' => t("Explanation or submission guidelines"), | '#title' => t('Explanation or submission guidelines'), |
| 519 | '#default_value' => variable_get("wishlist_help", ""), | '#default_value' => variable_get('wishlist_help', ''), |
| 520 | '#cols' => 55, | '#cols' => 55, |
| 521 | '#rows' => 4, | '#rows' => 4, |
| 522 | '#description' => t("This text will be displayed at the top of the wishlist item submission form. Useful for helping or instructing your users."), | '#description' => t('This text will be displayed at the top of the wishlist item submission form. Useful for helping or instructing your users.'), |
| 523 | ); | ); |
| 524 | $form['wishlist_block_max_names'] = array( | |
| $form["wishlist_block_max_names"] = array( | ||
| 525 | '#type' => 'textfield', | '#type' => 'textfield', |
| 526 | '#title' => t("Maximum number of names to show in Wishlists block"), | '#title' => t('Maximum number of names to show in Wishlists block.'), |
| 527 | '#default_value' => variable_get("wishlist_block_max_names", "5"), | '#default_value' => variable_get('wishlist_block_max_names', '5'), |
| 528 | '#size' => 2, | '#size' => 2, |
| 529 | '#maxlength' => 2, | '#maxlength' => 2, |
| 530 | '#description' => t("The maximum number of wishlists to display in the block."), | '#description' => t('The maximum number of wishlists to display in the block.'), |
| 531 | ); | ); |
| 532 | $form['wishlist_currency'] = array( | |
| 533 | $form['wishlist_currency'] = array('#type' => 'fieldset', '#title' => t('Currency'), '#collapsible' => FALSE); | '#type' => 'fieldset', |
| 534 | $form['wishlist_currency']["wishlist_show_currency"] = array( | '#title' => t('Currency'), |
| 535 | '#collapsible' => FALSE, | |
| 536 | ); | |
| 537 | $form['wishlist_currency']['wishlist_show_currency'] = array( | |
| 538 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 539 | '#title' => t('Show the currency field'), | '#title' => t('Show the currency field'), |
| 540 | '#return_value' => TRUE, | '#return_value' => TRUE, |
| 541 | '#default_value' => variable_get("wishlist_show_currency", TRUE), | '#default_value' => variable_get('wishlist_show_currency', TRUE), |
| 542 | '#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.'), | '#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.'), |
| 543 | ); | ); |
| 544 | $form['wishlist_currency']["wishlist_default_currency"] = array( | $form['wishlist_currency']['wishlist_default_currency'] = array( |
| 545 | '#type' => 'textfield', | '#type' => 'textfield', |
| 546 | '#title' => t('Default currency'), | '#title' => t('Default currency'), |
| 547 | '#default_value' => variable_get("wishlist_default_currency", "USD"), | '#default_value' => variable_get('wishlist_default_currency', 'USD'), |
| 548 | '#size' => 3, | '#size' => 3, |
| 549 | '#maxlength' => 3, | '#maxlength' => 3, |
| 550 | '#description' => t("Enter the default three letter ISO currency code for new wishlist items."), | '#description' => t('Enter the default three letter ISO currency code for new wishlist items.'), |
| 551 | ); | ); |
| 552 | $form['wishlist_options'] = array( | |
| 553 | '#type' => 'fieldset', | |
| 554 | $form['wishlist_options'] = array('#type' => 'fieldset', '#title' => t('Misc. options'), '#collapsible' => FALSE); | '#title' => t('Misc. options'), |
| 555 | '#collapsible' => FALSE, | |
| 556 | $form['wishlist_options']["wishlist_url_in_new_window"] = array( | ); |
| 557 | $form['wishlist_options']['wishlist_url_in_new_window'] = array( | |
| 558 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 559 | '#title' => t("Open URL links in new window"), | '#title' => t('Open URL links in new window'), |
| 560 | '#return_value' => TRUE, | '#return_value' => TRUE, |
| 561 | '#default_value' => variable_get("wishlist_url_in_new_window", TRUE), | '#default_value' => variable_get('wishlist_url_in_new_window', TRUE), |
| 562 | '#description' => t("When checked clicking on either the primary or secondary URL fields will open a new browser window."), | '#description' => t('When checked clicking on either the primary or secondary URL fields will open a new browser window.'), |
| 563 | ); | ); |
| 564 | $form['wishlist_hideopts'] = array( | |
| 565 | $form['wishlist_hideopts'] = array('#type' => 'fieldset', '#title' => t('Item purchased status protection options'), '#collapsible' => FALSE); | '#type' => 'fieldset', |
| 566 | $form['wishlist_hideopts']["wishlist_hide_purchase_info_anonymous"] = array( | '#title' => t('Item purchased status protection options'), |
| 567 | '#collapsible' => FALSE, | |
| 568 | ); | |
| 569 | $form['wishlist_hideopts']['wishlist_hide_purchase_info_anonymous'] = array( | |
| 570 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 571 | '#title' => t('Hide the purchase information from anonymous users'), | '#title' => t('Hide the purchase information from anonymous users'), |
| 572 | '#return_value' => TRUE, | '#return_value' => TRUE, |
| 573 | '#default_value' => variable_get("wishlist_hide_purchase_info_anonymous", FALSE), | '#default_value' => variable_get('wishlist_hide_purchase_info_anonymous', FALSE), |
| 574 | '#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.'), | '#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.'), |
| 575 | ); | ); |
| 576 | $form['wishlist_hideopts']['wishlist_hide_purchase_info_own'] = array( | $form['wishlist_hideopts']['wishlist_hide_purchase_info_own'] = array( |
| 577 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 578 | '#title' => t('Hide the purchase information from the user on their own wishlist by default'), | '#title' => t('Hide the purchase information from the user on their own wishlist by default'), |
| # | Line 673 function wishlist_admin_settings() { | Line 587 function wishlist_admin_settings() { |
| 587 | '#default_value' => variable_get('wishlist_hide_admins_own_items', FALSE), | '#default_value' => variable_get('wishlist_hide_admins_own_items', FALSE), |
| 588 | '#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'), | '#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'), |
| 589 | ); | ); |
| 590 | $form['wishlist_item_expire_days'] = array( | |
| $form["wishlist_item_expire_days"] = array( | ||
| 591 | '#type' => 'textfield', | '#type' => 'textfield', |
| 592 | '#title' => t('Days before a fully purchased item is hidden'), | '#title' => t('Days before a fully purchased item is hidden'), |
| 593 | '#default_value' => variable_get('wishlist_item_expire_days', 30), | '#default_value' => variable_get('wishlist_item_expire_days', 30), |
| # | Line 683 function wishlist_admin_settings() { | Line 595 function wishlist_admin_settings() { |
| 595 | '#maxlength' => 2, | '#maxlength' => 2, |
| 596 | '#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."), | '#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."), |
| 597 | ); | ); |
| 598 | $form['wishlist_display_count'] = array( | |
| $form["wishlist_display_count"] = array( | ||
| 599 | '#type' => 'textfield', | '#type' => 'textfield', |
| 600 | '#title' => t('Number of items to display in the user\'s wishlist summary'), | '#title' => t('Number of items to display in the user\'s wishlist summary'), |
| 601 | '#default_value' => variable_get('wishlist_display_count', 10), | '#default_value' => variable_get('wishlist_display_count', 10), |
| 602 | '#size' => 2, | '#size' => 2, |
| 603 | '#maxlength' => 2, | '#maxlength' => 2, |
| 604 | '#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.'), | '#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."), |
| 605 | ); | |
| 606 | $form['wishlist_table'] = array( | |
| 607 | '#type' => 'fieldset', | |
| 608 | '#title' => t('Control which columns are displayed'), | |
| 609 | '#collapsible' => TRUE, | |
| 610 | '#collapsed' => TRUE, | |
| 611 | ); | ); |
| $form['wishlist_table'] = array('#type' => 'fieldset', '#title' => t('Control which columns are displayed'), '#collapsible' => TRUE, '#collapsed' => TRUE); | ||
| 612 | $columns = array( | $columns = array( |
| 613 | 'wishlist_show_action' => t('Action'), | 'wishlist_show_action' => t('Action'), |
| 614 | 'wishlist_show_title' => t('Title'), | 'wishlist_show_title' => t('Title'), |
| # | Line 704 function wishlist_admin_settings() { | Line 619 function wishlist_admin_settings() { |
| 619 | 'wishlist_show_urls' => t('URLs'), | 'wishlist_show_urls' => t('URLs'), |
| 620 | 'wishlist_show_updated' => t('Last updated') | 'wishlist_show_updated' => t('Last updated') |
| 621 | ); | ); |
| 622 | $form['wishlist_table']['wishlist_showcolumn'] = array( | $form['wishlist_table']['wishlist_showcolumn'] = array( |
| 623 | '#type' => 'checkboxes', | '#type' => 'checkboxes', |
| 624 | '#title' => t('Show the following columns in the wishlist table view'), | '#title' => t('Show the following columns in the wishlist table view'), |
| # | Line 713 function wishlist_admin_settings() { | Line 626 function wishlist_admin_settings() { |
| 626 | '#options' => $columns, | '#options' => $columns, |
| 627 | '#description' => t('This controls which column show up in the wishlist summary view.'), | '#description' => t('This controls which column show up in the wishlist summary view.'), |
| 628 | ); | ); |
| 629 | return system_settings_form($form); | return system_settings_form($form); |
| 630 | } | } |
| 631 | ||
| 632 | /** | /** |
| 633 | * Retrieves the default values array for the show-column settings array | * Retrieves the default values array for the show-column settings array. |
| 634 | */ | */ |
| 635 | function _wishlist_get_default_showcolumn_settings_array() { | function _wishlist_get_default_showcolumn_settings_array() { |
| 636 | $default_values['wishlist_show_action'] = true; | $default_values['wishlist_show_action'] = true; |
| # | Line 733 function _wishlist_get_default_showcolum | Line 644 function _wishlist_get_default_showcolum |
| 644 | return $default_values; | return $default_values; |
| 645 | } | } |
| 646 | ||
| 647 | /** | /** |
| 648 | * Function to display the wishlist module's admin page, where and administrator | * Function to display the wishlist module's admin page, where and administrator |
| 649 | * can view all purchase records and delete them if necessary. | * can view all purchase records and delete them if necessary. |
| 650 | */ | */ |
| 651 | function wishlist_admin_page() { | function wishlist_admin_page() { |
| 652 | global $user; | global $user; |
| 653 | $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 '; | |
| 654 | $sql = "SELECT p.*, buyer.name as buyer_name, receiver.name as receiver_name, n.title, n.nid FROM {wishlist_purchased} p | // If the option to suppress having the admin see their own items is on, then remove em from the query. |
| 655 | INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid | if(variable_get('wishlist_hide_admins_own_items', FALSE)) { |
| 656 | INNER JOIN {users} buyer ON buyer.uid = p.wishlist_purch_buyer_uid | $sql .= 'WHERE receiver.uid != %d '; |
| 657 | INNER JOIN {users} receiver ON receiver.uid = n.uid "; | } |
| 658 | // If the option to suppress having the admin see their own items is on, then remove em from the query. | $sql .= 'ORDER BY p.purch_date'; |
| 659 | if(variable_get('wishlist_hide_admins_own_items', FALSE)) { | $result = db_query($sql, $user->uid); |
| 660 | $sql .= "WHERE receiver.uid != %d "; | $header = array( |
| 661 | } | array('data' => t('Purchaser')), |
| 662 | $sql .= "ORDER BY p.purch_date"; | array('data' => t('On')), |
| 663 | $result = db_query($sql, $user->uid); | array('data' => t('Quantity')), |
| 664 | array('data' => t('Item')), | |
| 665 | $header = array( | array('data' => t('For')), |
| 666 | array('data' => t('Purchaser')), | array('data' => t('Action')) |
| 667 | array('data' => t('On')), | ); |
| 668 | array('data' => t('Quantity')), | $rows = array(); |
| 669 | array('data' => t('Item')), | while($row = db_fetch_object($result)) { |
| 670 | array('data' => t('For')), | $rows[] = array( |
| 671 | array('data' => t('Action')) | array('data' => check_plain($row->buyer_name)), |
| 672 | array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')), | |
| 673 | array('data' => $row->wishlist_purch_quantity), | |
| 674 | array('data' => l(check_plain($row->title), 'node/'. $row->nid)), | |
| 675 | array('data' => check_plain($row->receiver_name)), | |
| 676 | array('data' => l(t('Delete'), 'admin/content/wishlist/delete/'. $row->nid .'/'. $row->wishlist_purch_wid)) | |
| 677 | ); | ); |
| 678 | $rows = array(); | } |
| 679 | $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>'; | |
| 680 | while($row = db_fetch_object($result)) { | if(variable_get('wishlist_hide_admins_own_items', FALSE)) { |
| 681 | $rows[] = array( | $header_text .= '<div>'. t('The site is configure to not display your items on this list') .'</div>'; |
| 682 | array('data' => check_plain($row->buyer_name)), | } |
| 683 | array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')), | $output = '<div class="wishlist-admin">'; |
| 684 | array('data' => $row->wishlist_purch_quantity), | $output .= $header_text . theme('table', $header, $rows); |
| 685 | array('data' => l(check_plain($row->title), 'node/'.$row->nid)), | $output .= '</div>'; |
| 686 | array('data' => check_plain($row->receiver_name)), | return $output; |
| 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; | ||
| 687 | } | } |
| 688 | ||
| 689 | /** | /** |
| 690 | * Builds the page to display when a user wants to return an item they already pulled off of a user's wishlist | * Builds the page to display when a user wants to return an item they already pulled off of a user's wishlist. |
| 691 | * | * |
| 692 | * @param $nid | * @param $nid |
| 693 | * The node ID for the item where some of the purchased quantity will be returned | * The node ID for the item where some of the purchased quantity will be returned. |
| 694 | * @param $wpid | * @param $wpid |
| 695 | * The ID of the wishlist_purchased record to delete. | * The ID of the wishlist_purchased record to delete. |
| * | ||
| 696 | * @return | * @return |
| 697 | * HTML ready for display. | * HTML ready for display. |
| 698 | */ | */ |
| 699 | function _wishlist_admin_delete_item() { | function _wishlist_admin_delete_item() { |
| 700 | global $user; | global $user; |
| 701 | if(!user_access('admin wishlist')) { | |
| 702 | if(!user_access('admin wishlist')) { | watchdog('error', t('A non administrative user attempted to delete a wishlist item')); |
| 703 | 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.'); |
| 704 | return t('You are not authorized to delete wishlist items through the administrative interface'); | } |
| 705 | } | $delete_nid = check_plain(arg(4)); |
| 706 | $delete_wp = check_plain(arg(5)); | |
| 707 | $delete_nid = check_plain(arg(4)); | if(!is_numeric($delete_nid)) { |
| 708 | $delete_wp = check_plain(arg(5)); | return t('The fourth parameter must be numeric.'); |
| 709 | } | |
| 710 | if(!is_numeric($delete_nid)) { | if(!is_numeric($delete_wp)) { |
| 711 | return t('The fourth parameter must be numeric'); | return t('The fifth parameter must be numeric.'); |
| 712 | } | } |
| 713 | $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); | |
| 714 | if(!is_numeric($delete_wp)) { | if($wishlist_purch = db_fetch_object($result)) { |
| 715 | return t('The fifth parameter must be numeric'); | if($delete_nid != $wishlist_purch->wishlist_purch_nid) { |
| 716 | } | return t('Inputs do not agree. Node @nid is not related to wpid = @wpid', array('@nid' => $delete_nid, '@wpid' => $delete_wp)); |
| 717 | } | |
| 718 | $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); | } else { |
| 719 | if($wishlist_purch = db_fetch_object($result)) { | return t('Invalid record - item return failed for wpid = @wpid', array('@wpid' => $delete_wp)); |
| 720 | if($delete_nid != $wishlist_purch->wishlist_purch_nid) { | } |
| 721 | return "Inputs do not agree. Node ".$delete_nid." is not related to wpid=".$delete_wp; | // Load all this up just so that we can print a nice information message. |
| 722 | } | $node = node_load($delete_nid); |
| 723 | } else { | $purchaser_account = user_load(array('uid' => $user->uid)); |
| 724 | return "Invalid record - item return failed for wpid=".$delete_wp; | $giftee_account = user_load(array('uid' => $node->uid)); |
| 725 | } | 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))); |
| 726 | db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_wid = %d', $delete_wp); | |
| 727 | // Load all this up just so that we can print a nice information message | // Set a successful return and then go back to the node display for this item. |
| 728 | $node = node_load($delete_nid); | 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))); |
| 729 | $purchaser_account = user_load(array('uid' => $user->uid)); | drupal_goto('admin/content/wishlist'); |
| $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'); | ||
| 730 | } | } |
| 731 | ||
| 732 | /** | /** |
| 733 | * Function to display every wishlist in the system | * Function to display every wishlist in the system. |
| 734 | * | * |
| 735 | * @return | * @return |
| 736 | * A theme("page", ...) with display content showing all available wishlists. | * A theme('page', ...) with display content showing all available wishlists. |
| 737 | */ | */ |
| 738 | function _wishlist_show_all_lists() { | function _wishlist_show_all_lists() { |
| 739 | $output = ""; | $output = ''; |
| 740 | $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")); | |
| 741 | $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)) { |
| 742 | if(0==db_num_rows($result)) { | return t('No wishlists exist on this site.'); |
| 743 | return t("No wishlists exist on this site"); | } |
| 744 | } | $output .= '<div class="wishlist"><div class="all_lists">'; |
| 745 | $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>'; | |
| 746 | $output .= "<div class='wishlist'><div class='all_lists'>"; | while ($account = db_fetch_object($result)) { |
| 747 | $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>'; | $items[] = format_wishlists($account, t("'s wishlist")); |
| 748 | while ($account = db_fetch_object($result)) { | } |
| 749 | $items[] = format_wishlists($account, t("'s wishlist")); | $output .= theme('item_list', $items); |
| 750 | } | $output .= '</div></div>'; |
| 751 | return $output; | |
| $output .= theme('item_list', $items); | ||
| $output .= "</div></div>"; | ||
| return $output; | ||
| 752 | } | } |
| 753 | ||
| 754 | /** | /** |
| 755 | * hook_view implementation | * Implementation of hook_view(). |
| * | ||
| * @param | ||
| * See hook_view in http://www.drupaldocs.org for parameter details | ||
| * @return | ||
| * See hook_view in http://www.drupaldocs.org for return code details | ||
| 756 | */ | */ |
| 757 | function wishlist_view($node, $teaser = FALSE, $page = FALSE) { | function wishlist_view($node, $teaser = FALSE, $page = FALSE) { |
| 758 | $node = node_prepare($node, $teaser); | $node = node_prepare($node, $teaser); |
| 759 | if($page) { | if($page) { |
| 760 | $giftee_account = user_load(array('uid' => $node->uid)); | $giftee_account = user_load(array('uid' => $node->uid)); |
| 761 | $breadcrumb = array(); | |
| 762 | $breadcrumb = array(); | $breadcrumb[] = array('path' => 'wishlist', 'title' => t('all wishlists')); |
| 763 | $breadcrumb[] = array('path' => 'wishlist', 'title' => t('all wishlists')); | $breadcrumb[] = array('path' => 'wishlist/'. $node->uid, 'title' => t("@name's wishlist", array('@name' => $giftee_account->name))); |
| 764 | $breadcrumb[] = array('path' => 'wishlist/'.$node->uid, 'title' => t("@name's wishlist", array('@name' => $giftee_account->name))); | $breadcrumb[] = array('path' => 'node/'. $node->nid); |
| 765 | $breadcrumb[] = array('path' => 'node/'.$node->nid); | menu_set_location($breadcrumb); |
| 766 | menu_set_location($breadcrumb); | } |
| } | ||
| 767 | $node->content['wishlist'] = array( | $node->content['wishlist'] = array( |
| 768 | '#value' => _wishlist_render_view($node, $teaser), | '#value' => _wishlist_render_view($node, $teaser), |
| 769 | '#weight' => 1 | '#weight' => 1 |
| 770 | ); | ); |
| 771 | return $node; | return $node; |
| 772 | } | } |
| 773 | ||
| 774 | /** | /** |
| 775 | * Builds the primary view of a wishlist item. | * Builds the primary view of a wishlist item. |
| 776 | * | * |
| 777 | * @param | * @param |
| 778 | * See hook_view in http://www.drupaldocs.org for parameter details | * See hook_view in http://www.drupaldocs.org for parameter details. |
| 779 | * @return | * @return |
| 780 | * an output buffer ready to do further processing on (such as call theme('page', ...) | * An output buffer ready to do further processing on (such as call theme('page', ...). |
| 781 | */ | */ |
| 782 | function _wishlist_render_view($node, $teaser = FALSE) { | function _wishlist_render_view($node, $teaser = FALSE) { |
| 783 | global $user; | global $user; |
| 784 | $output = '<div class="wishlist">'; | |
| $output = "<div class='wishlist'>"; | ||
| 785 | $output .= '<div class="wl_spacer"> </div>'; | $output .= '<div class="wl_spacer"> </div>'; |
| 786 | $output .= '<div class="main-body">'; | $output .= '<div class="main-body">'; |
| 787 | $output .= "<div class='item_est_cost'>".t("Estimated Cost")." "._wishlist_currency_str($node->item_currency).$node->item_est_cost."</div>"; | $output .= '<div class="item_est_cost">'. t('Estimated Cost @cur@cost', array('@cur' => _wishlist_currency_str($node->item_currency), '@cost' => $node->item_est_cost)) .'</div>'; |
| 788 | $output .= theme('wishlist_node_url', $node->item_url1, $node); | $output .= theme('wishlist_node_url', $node->item_url1, $node); |
| 789 | $output .= theme('wishlist_node_url', $node->item_url2, $node); | $output .= theme('wishlist_node_url', $node->item_url2, $node); |
| 790 | if(!$teaser) { | if(!$teaser) { |
| 791 | $output .= _wishlist_render_purchased_items($node); | $output .= _wishlist_render_purchased_items($node); |
| 792 | } | } |
| 793 | $output .= "<div class='changed'>".t("Last updated on")." ".format_date($node->changed, "small")."</div>"; | $output .= '<div class="changed">'. t('Last updated on @date', array('@date' => format_date($node->changed, 'small'))) .'</div>'; |
| 794 | $output .= '</div>'; | $output .= '</div>'; |
| 795 | $output .= '<div class="purchase-info">'; | $output .= '<div class="purchase-info">'; |
| 796 | $output .= _wishlist_get_reveal_form($node->uid); | $output .= _wishlist_get_reveal_form($node->uid); |
| 797 | $priority_str = _wishlist_get_item_priority_array(); | $priority_str = _wishlist_get_item_priority_array(); |
| 798 | // Depending on the context in which this is called the item priority value is either a value or an array of values | // Depending on the context in which this is called the item priority value is either a value or an array of values. |
| 799 | $output .= "<div class='priority'>".$priority_str[is_array($node->item_priority) ? $node->item_priority[0] : $node->item_priority]."</div>"; | $output .= '<div class="priority">'. $priority_str[is_array($node->item_priority) ? $node->item_priority[0] : $node->item_priority] .'</div>'; |
| 800 | $output .= '<div class="requested">'. t('Requested @cnt', array('@cnt' => $node->item_quantity_requested)) .'</div>'; | |
| $output .= "<div class='requested'>".t("Requested")." ".$node->item_quantity_requested."</div>"; | ||
| 801 | if(_wishlist_hide_purchase_info($node)) { | if(_wishlist_hide_purchase_info($node)) { |
| 802 | $output .= "<div class='purchased'>".t("Purchase details hidden")."</div>"; | $output .= '<div class="purchased">'. t('Purchase details hidden') .'</div>'; |
| 803 | } else { | } else { |
| 804 | $output .= "<div class='purchased'>".t("Purchased")." ".$node->item_quantity_purchased."</div>"; | $output .= '<div class="purchased">'. t('Purchased @cnt', array('@cnt' => $node->item_quantity_purchased)) .'</div>'; |
| 805 | } | } |
| 806 | // 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 | ||
| 807 | if(!is_null($node->nid) && $node->nid > 0) { | if(!is_null($node->nid) && $node->nid > 0) { |
| 808 | // 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. |
| 809 | $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 = @uid AND p.wishlist_purch_nid = @nid', 'p', 'wishlist_purch_buyer_nid'), array('@uid' => $user->uid, '@nid' => $node->nid)); |
| 810 | $header = array( | |
| 811 | $header = array( | array('data' => t('Quantity<br>You<br>Purchased')), |
| 812 | array('data' => t("Quantity<br>You<br>Purchased")), | array('data' => t('Action')) |
| 813 | array('data' => t("Action")) | ); |
| 814 | ); | while($wishlist_purch = db_fetch_object($result)) { |
| 815 | if ($wishlist_purch->wishlist_purch_quantity > 1) { | |
| 816 | while($wishlist_purch = db_fetch_object($result)) { | $action_str = t('Return these items'); |
| 817 | if ($wishlist_purch->wishlist_purch_quantity > 1) { | } else { |
| 818 | $action_str = t("Return these items"); | $action_str = t('Return this item'); |
| 819 | } else { | } |
| 820 | $action_str = t("Return this item"); | $rows[] = array( |
| 821 | } | array('data' => $wishlist_purch->wishlist_purch_quantity), |
| 822 | $rows[] = array( | array('data' => l($action_str, "wishlist/item/$node->nid/return/$wishlist_purch->wishlist_purch_wid")) |
| 823 | array("data" => $wishlist_purch->wishlist_purch_quantity), | ); |
| 824 | array("data" => l($action_str, "wishlist/item/$node->nid/return/$wishlist_purch->wishlist_purch_wid")) | } |
| 825 | ); | if ($rows) { |
| 826 | $output .= '<div class="wishlist_purchased">'. theme('table', $header, $rows). '</div>'; | |
| 827 | } | } |
| if ($rows) { | ||
| $output .= "<div class='wishlist_purchased'>".theme('table', $header, $rows)."</div>"; | ||
| } | ||
| 828 | } | } |
| 829 | // end the purchase-info div | // end the purchase-info div |
| 830 | $output .= '</div>'; | $output .= '</div>'; |
| 831 | $output .= '<div class="wl_spacer"> </div>'; | $output .= '<div class="wl_spacer"> </div>'; |
| 832 | // end the wishlist div | // end the wishlist div |
| 833 | $output .= '</div>'; | $output .= '</div>'; |
| 834 | return $output; | |
| return $output; | ||
| 835 | } | } |
| 836 | ||
| 837 | /** | /** |
| 838 | * Returns the HTML to display a table showing who purchased which gifts for the user, and when. | * Returns the HTML to display a table showing who purchased which gifts for the user, and when. |
| 839 | * This is part of the node display. It will only show for users who have 'admin wishlist' or | * This is part of the node display. It will only show for users who have 'admin wishlist' or |
| 840 | * 'reveal purchase status' permissions. | * 'reveal purchase status' permissions. |
| 841 | * | * |
| 842 | * @param node $node | * @param $node |
| 843 | */ | */ |
| 844 | function _wishlist_render_purchased_items($node) { | function _wishlist_render_purchased_items($node) { |
| 845 | global $user; | global $user; |
| 846 | // Don't show this during a preview. | |
| 847 | // Don't show this during a preview. | if(!$node->nid) { |
| 848 | if(!$node->nid) { | return ''; |
| 849 | return ''; | } |
| 850 | } | // To view this region, the user must either have reveal purchase status |
| 851 | // or be an administrator. | |
| 852 | // To view this region, the user must either have reveal purchase status | if(!user_access('admin wishlist') && !user_access('reveal purchase status')) { |
| 853 | // or be an administrator. | return ''; |
| 854 | if(!user_access('admin wishlist') && !user_access('reveal purchase status')) { | } |
| 855 | return ''; | // If this is not your entry, then you cannot see the |
| 856 | } | // purchase details UNLESS you are an admin. |
| 857 | if($user->uid != $node->uid) { | |
| 858 | // If this is not your entry, then you cannot see the | if(!user_access('admin wishlist')) { |
| 859 | // purchase details UNLESS you are an admin. | return ''; |
| 860 | if($user->uid != $node->uid) { | } |
| 861 | if(!user_access('admin wishlist')) { | } |
| 862 | return ''; | // If the site is configured to hide details from the list owner |
| 863 | } | // then check to see if this user, the owner, has the right to reveal |
| 864 | } | // and reveal mode is turned on. If not, do not show this region. |
| 865 | if(variable_get("wishlist_hide_purchase_info_own", FALSE) && ($user->uid == $node->uid)) { | |
| 866 | // If the site is configured to hide details from the list owner | if(user_access('reveal purchase status') && ($_GET['wl_reveal'] != 1)) { |
| 867 | // then check to see if this user, the owner, has the right to reveal | return ''; |
| 868 | // and reveal mode is turned on. If not, do not show this region. | } |
| 869 | if(variable_get("wishlist_hide_purchase_info_own", FALSE) && ($user->uid == $node->uid)) { | } |
| 870 | if(user_access('reveal purchase status') && ($_GET['wl_reveal'] != 1)) { | $result = db_query('SELECT p.*, u.name FROM {wishlist_purchased} p INNER JOIN {users} u ON u.uid = p.wishlist_purch_buyer_uid WHERE p.wishlist_purch_nid = %d', $node->nid); |
| 871 | return ''; | $header = array( |
| 872 | } | array('data' => t('Purchaser')), |
| 873 | } | array('data' => t('On')), |
| 874 | array('data' => t('Quantity')), | |
| 875 | $sql = "SELECT p.*, u.name FROM {wishlist_purchased} p | ); |
| 876 | INNER JOIN {users} u ON u.uid = p.wishlist_purch_buyer_uid | $rows = array(); |
| 877 | WHERE p.wishlist_purch_nid = %d"; | while($row = db_fetch_object($result)) { |
| 878 | $result = db_query($sql, $node->nid); | $rows[] = array( |
| 879 | array('data' => check_plain($row->name)), | |
| 880 | $header = array( | array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')), |
| 881 | array('data' => t('Purchaser')), | array('data' => $row->wishlist_purch_quantity), |
| array('data' => t('On')), | ||
| array('data' => t('Quantity')) | ||
| 882 | ); | ); |
| 883 | $rows = array(); | } |
| 884 | // If there is no purchaser record, return nothing to display. | |
| 885 | while($row = db_fetch_object($result)) { | if(empty($rows)) { |
| 886 | $rows[] = array( | return ''; |
| 887 | array('data' => check_plain($row->name)), | } |
| 888 | array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')), | $output = '<div class="who-purchased">'; |
| 889 | array('data' => $row->wishlist_purch_quantity) | $output .= '<fieldset><legend>'. t('Gift purchase record') .'</legend>'. theme('table', $header, $rows) .'</fieldset>'; |
| 890 | ); | $output .= '</div>'; |
| 891 | } | return $output; |
| // If there is no purchaser record, return nothing to display | ||
| if(empty($rows)) { | ||
| return ''; | ||
| } | ||
| $output = '<div class="who-purchased">'; | ||
| $output .= '<fieldset><legend>'.t('Gift purchase record').'</legend>'.theme('table', $header, $rows).'</fieldset>'; | ||
| $output .= '</div>'; | ||
| return $output; | ||
| 892 | } | } |
| 893 | ||
| 894 | /** | /** |
| 895 | * Menu callback function to handle the "wishlist" URL | * Menu callback function to handle the "wishlist" URL. |
| 896 | * | * |
| 897 | * @return | * @return |
| 898 | * theme("page",...) ready to display the wishlist page result | * theme("page",...) ready to display the wishlist page result. |
| 899 | */ | */ |
| 900 | function wishlist_page() { | function wishlist_page() { |
| 901 | $arg1 = arg(1); | $arg1 = arg(1); |
| 902 | if (!isset($arg1)) { | if (!isset($arg1)) { |
| 903 | print theme("page", _wishlist_show_all_lists()); | print theme('page', _wishlist_show_all_lists()); |
| 904 | } else if (is_numeric($arg1)){ | } |
| 905 | print theme("page", _wishlist_list_items($arg1)); | elseif (is_numeric($arg1)){ |
| 906 | } else { | print theme('page', _wishlist_list_items($arg1)); |
| 907 | switch ($arg1) { | } |
| 908 | case "item": | else { |
| 909 | print theme("page", _wishlist_item_action_handler(arg(2), arg(3), arg(4))); | switch ($arg1) { |
| 910 | break; | case 'item': |
| 911 | default: | print theme('page', _wishlist_item_action_handler(arg(2), arg(3), arg(4))); |
| 912 | print theme("page", "Invalid argument to wishlist_page [".$arg1."]"); | break; |
| 913 | break; | default: |
| 914 | } | print theme('page', t('Invalid argument to wishlist_page [@arg]', array('@arg' => $arg1))); |
| 915 | break; | |
| 916 | } | |
| 917 | } | } |
| 918 | } | } |
| 919 | ||
| 920 | /** | /** |
| 921 | * Lists out the items for the user $uid | * Lists out the items for the user $uid. |
| 922 | * | * |
| 923 | * @param $uid | * @param $uid |
| 924 | * User for whom we should list out wishlist items. | * User for whom we should list out wishlist items. |
| 925 | * @return | * @return |
| 926 | * $output for display | * $output for display. |
| 927 | */ | */ |
| 928 | function _wishlist_list_items($uid) { | function _wishlist_list_items($uid) { |
| 929 | global $user; | global $user; |
| 930 | if(!is_numeric($uid)) { | |
| 931 | if(!is_numeric($uid)) { | return theme('page', t('Invalid argument to wishlist_list_items [@uid]', array('@uid' => $uid))); |
| 932 | return theme("page", "Invalid argument to wishlist_list_items [".$uid."]"); | } |
| 933 | } | $showcolumns = variable_get('wishlist_showcolumn', _wishlist_get_default_showcolumn_settings_array()); |
| 934 | $header = array(); | |
| 935 | $showcolumns = variable_get('wishlist_showcolumn', _wishlist_get_default_showcolumn_settings_array()); | if($showcolumns['wishlist_show_action'] == true) { |
| 936 | $header[] = array('data' => t('Action')); | |
| 937 | $header = array(); | } |
| 938 | if($showcolumns['wishlist_show_action'] == true) { | if($showcolumns['wishlist_show_title'] == true) { |
| 939 | $header[] = array('data' => t("Action")); | $header[] = array('data' => t('Item Name'), 'field' => 'n.title'); |
| 940 | } | } |
| 941 | if($showcolumns['wishlist_show_title'] == true) { | if($showcolumns['wishlist_show_description'] == true) { |
| 942 | $header[] = array('data' => t("Item Name"), "field" => "n.title"); | $header[] = array('data' => t('Description')); |
| 943 | } | } |
| 944 | if($showcolumns['wishlist_show_description'] == true) { | if($showcolumns['wishlist_show_priority'] == true) { |
| 945 | $header[] = array('data' => t("Description")); | $header[] = array('data' => t('Priority'), 'field' => 'w.item_priority', 'sort' => 'asc'); |
| 946 | } | } |
| 947 | if($showcolumns['wishlist_show_priority'] == true) { | if($showcolumns['wishlist_show_cost'] == true) { |
| 948 | $header[] = array('data' => t("Priority"), "field" => "w.item_priority", "sort" => "asc"); | $header[] = array('data' => t('Cost'), 'field' => 'w.item_est_cost'); |
| 949 | } | } |
| 950 | if($showcolumns['wishlist_show_cost'] == true) { | if($showcolumns['wishlist_show_quantity'] == true) { |
| 951 | $header[] = array('data' => t("Cost"), "field" => "w.item_est_cost"); | $header[] = array('data' => t('Quantity'), 'field' => 'w.item_quantity_requested'); |
| 952 | } | } |
| 953 | if($showcolumns['wishlist_show_quantity'] == true) { | if($showcolumns['wishlist_show_urls'] == true) { |
| 954 | $header[] = array('data' => t("Quantity"), "field" => "w.item_quantity_requested"); | $header[] = array('data' => t('URLs')); |
| 955 | } | } |
| 956 | if($showcolumns['wishlist_show_urls'] == true) { | if($showcolumns['wishlist_show_updated'] == true) { |
| 957 | $header[] = array('data' => t("URLs")); | $header[] = array('data' => t('Last Updated'), 'field' => 'n.changed'); |
| 958 | } | } |
| 959 | if($showcolumns['wishlist_show_updated'] == true) { | if(empty($header)) { |
| 960 | $header[] = array('data' => t("Last Updated"), "field" => "n.changed"); | drupal_set_message(t('The site administrator has removed all columns from this display. No wishlist information will appear.'), 'error'); |
| 961 | } | } |
| 962 |