/[drupal]/contributions/modules/wishlist/wishlist.admin.inc
ViewVC logotype

Contents of /contributions/modules/wishlist/wishlist.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Nov 25 03:34:04 2007 UTC (2 years ago) by smclewin
Branch: MAIN
CVS Tags: DRUPAL-6--2-1-BETA, DRUPAL-6--2-3, DRUPAL-6--2-2, DRUPAL-6--2-1, HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/x-php
First pass port to Drupal 6. All appears to be well, but it could use some other eyes to test and verify.
1 <?php
2 /* $Id:$ */
3 // Wishlist management module for Drupal
4 // Written by Scott McLewin and Melanie Paul-McLewin
5 // drupal AT mclewin DOT com
6
7 /**
8 * Administration settings for the wishlist module
9 *
10 */
11 function wishlist_admin_settings() {
12
13 // Drupal 4.7 forms api overview http://drupal.org/node/33338
14 // Permission Check
15 if (!user_access('admin wishlist')) {
16 return drupal_access_denied();
17 }
18
19 $form["wishlist_help"] = array(
20 '#type' => 'textarea',
21 '#title' => t("Explanation or submission guidelines"),
22 '#default_value' => variable_get("wishlist_help", ""),
23 '#cols' => 55,
24 '#rows' => 4,
25 '#description' => t("This text will be displayed at the top of the wishlist item submission form. Useful for helping or instructing your users."),
26 );
27
28 $form["wishlist_block_max_names"] = array(
29 '#type' => 'textfield',
30 '#title' => t("Maximum number of names to show in Wishlists block"),
31 '#default_value' => variable_get("wishlist_block_max_names", "5"),
32 '#size' => 2,
33 '#maxlength' => 2,
34 '#description' => t("The maximum number of wishlists to display in the block."),
35 );
36
37 $form['wishlist_currency'] = array('#type' => 'fieldset', '#title' => t('Currency'), '#collapsible' => FALSE);
38 $form['wishlist_currency']["wishlist_show_currency"] = array(
39 '#type' => 'checkbox',
40 '#title' => t('Show the currency field'),
41 '#return_value' => TRUE,
42 '#default_value' => variable_get("wishlist_show_currency", TRUE),
43 '#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.'),
44 );
45 $form['wishlist_currency']["wishlist_default_currency"] = array(
46 '#type' => 'textfield',
47 '#title' => t('Default currency'),
48 '#default_value' => variable_get("wishlist_default_currency", "USD"),
49 '#size' => 3,
50 '#maxlength' => 3,
51 '#description' => t("Enter the default three letter ISO currency code for new wishlist items."),
52 );
53
54
55 $form['wishlist_options'] = array('#type' => 'fieldset', '#title' => t('Misc. options'), '#collapsible' => FALSE);
56
57 $form['wishlist_options']["wishlist_url_in_new_window"] = array(
58 '#type' => 'checkbox',
59 '#title' => t("Open URL links in new window"),
60 '#return_value' => TRUE,
61 '#default_value' => variable_get("wishlist_url_in_new_window", TRUE),
62 '#description' => t("When checked clicking on either the primary or secondary URL fields will open a new browser window."),
63 );
64
65 $form['wishlist_hideopts'] = array('#type' => 'fieldset', '#title' => t('Item purchased status protection options'), '#collapsible' => FALSE);
66 $form['wishlist_hideopts']["wishlist_hide_purchase_info_anonymous"] = array(
67 '#type' => 'checkbox',
68 '#title' => t('Hide the purchase information from anonymous users'),
69 '#return_value' => TRUE,
70 '#default_value' => variable_get("wishlist_hide_purchase_info_anonymous", FALSE),
71 '#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.'),
72 );
73
74 $form['wishlist_hideopts']['wishlist_hide_purchase_info_own'] = array(
75 '#type' => 'checkbox',
76 '#title' => t('Hide the purchase information from the user on their own wishlist by default'),
77 '#return_value' => TRUE,
78 '#default_value' => variable_get('wishlist_hide_purchase_info_own', FALSE),
79 '#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.'),
80 );
81 $form['wishlist_hideopts']['wishlist_hide_admins_own_items'] = array(
82 '#type' => 'checkbox',
83 '#title' => t('Hide your (the admin) wishlist items when viewing the wishlist administration screen'),
84 '#return_value' => TRUE,
85 '#default_value' => variable_get('wishlist_hide_admins_own_items', FALSE),
86 '#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'),
87 );
88
89
90 $form["wishlist_item_expire_days"] = array(
91 '#type' => 'textfield',
92 '#title' => t('Days before a fully purchased item is hidden'),
93 '#default_value' => variable_get('wishlist_item_expire_days', 30),
94 '#size' => 2,
95 '#maxlength' => 2,
96 '#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."),
97 );
98
99 $form["wishlist_display_count"] = array(
100 '#type' => 'textfield',
101 '#title' => t('Number of items to display in the user\'s wishlist summary'),
102 '#default_value' => variable_get('wishlist_display_count', 10),
103 '#size' => 2,
104 '#maxlength' => 2,
105 '#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.'),
106 );
107
108 $form['wishlist_table'] = array('#type' => 'fieldset', '#title' => t('Control which columns are displayed'), '#collapsible' => TRUE, '#collapsed' => TRUE);
109 $columns = array(
110 'wishlist_show_action' => t('Action'),
111 'wishlist_show_title' => t('Title'),
112 'wishlist_show_description' => t('Description'),
113 'wishlist_show_priority' => t('Priority'),
114 'wishlist_show_cost' => t('Cost'),
115 'wishlist_show_quantity' => t('Quantity'),
116 'wishlist_show_urls' => t('URLs'),
117 'wishlist_show_updated' => t('Last updated')
118 );
119
120
121 $form['wishlist_table']['wishlist_showcolumn'] = array(
122 '#type' => 'checkboxes',
123 '#title' => t('Show the following columns in the wishlist table view'),
124 '#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')),
125 '#options' => $columns,
126 '#description' => t('This controls which column show up in the wishlist summary view.'),
127 );
128
129
130 return system_settings_form($form);
131 }
132 /**
133 * Function to display the wishlist module's admin page, where and administrator
134 * can view all purchase records and delete them if necessary.
135 */
136 function wishlist_admin_page() {
137 global $user;
138
139 $sql = "SELECT p.*, buyer.name as buyer_name, receiver.name as receiver_name, n.title, n.nid FROM {wishlist_purchased} p
140 INNER JOIN {node} n ON n.nid = p.wishlist_purch_nid
141 INNER JOIN {users} buyer ON buyer.uid = p.wishlist_purch_buyer_uid
142 INNER JOIN {users} receiver ON receiver.uid = n.uid ";
143 // If the option to suppress having the admin see their own items is on, then remove em from the query.
144 if(variable_get('wishlist_hide_admins_own_items', FALSE)) {
145 $sql .= "WHERE receiver.uid != %d ";
146 }
147 $sql .= "ORDER BY p.purch_date";
148 $result = db_query($sql, $user->uid);
149
150 $header = array(
151 array('data' => t('Purchaser')),
152 array('data' => t('On')),
153 array('data' => t('Quantity')),
154 array('data' => t('Item')),
155 array('data' => t('For')),
156 array('data' => t('Action'))
157 );
158 $rows = array();
159
160 while($row = db_fetch_object($result)) {
161 $rows[] = array(
162 array('data' => check_plain($row->buyer_name)),
163 array('data' => ($row->purch_date != 0) ? format_date($row->purch_date, 'custom', 'j M y') : t('unknown')),
164 array('data' => $row->wishlist_purch_quantity),
165 array('data' => l($row->title, 'node/'.$row->nid)),
166 array('data' => check_plain($row->receiver_name)),
167 array('data' => l(t('Delete'), 'admin/content/wishlist/delete/'.$row->nid.'/'.$row->wishlist_purch_wid))
168 );
169 }
170
171 $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>';
172
173 if(variable_get('wishlist_hide_admins_own_items', FALSE)) {
174 $header_text .= '<div>'.t('The site is configure to not display your items on this list').'</div>';
175 }
176
177 $output = '<div class="wishlist-admin">';
178 $output .= $header_text.theme('table', $header, $rows);
179 $output .= '</div>';
180
181 return $output;
182 }
183
184 /**
185 * Builds the page to display when a user wants to return an item they already pulled off of a user's wishlist
186 *
187 * @param $nid
188 * The node ID for the item where some of the purchased quantity will be returned
189 * @param $wpid
190 * The ID of the wishlist_purchased record to delete.
191 *
192 * @return
193 * HTML ready for display.
194 */
195 function _wishlist_admin_delete_item() {
196 global $user;
197
198 if(!user_access('admin wishlist')) {
199 watchdog('error', 'A non administrative user attempt to delete a wishlist item');
200 return t('You are not authorized to delete wishlist items through the administrative interface');
201 }
202
203 $delete_nid = check_plain(arg(4));
204 $delete_wp = check_plain(arg(5));
205
206 if(!is_numeric($delete_nid)) {
207 return t('The fourth parameter must be numeric');
208 }
209
210 if(!is_numeric($delete_wp)) {
211 return t('The fifth parameter must be numeric');
212 }
213
214 $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);
215 if($wishlist_purch = db_fetch_object($result)) {
216 if($delete_nid != $wishlist_purch->wishlist_purch_nid) {
217 return "Inputs do not agree. Node ".$delete_nid." is not related to wpid=".$delete_wp;
218 }
219 } else {
220 return "Invalid record - item return failed for wpid=".$delete_wp;
221 }
222
223 // Load all this up just so that we can print a nice information message
224 $node = node_load($delete_nid);
225 $purchaser_account = user_load(array('uid' => $user->uid));
226 $giftee_account = user_load(array('uid' => $node->uid));
227 watchdog('content', '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));
228
229 db_query('DELETE FROM {wishlist_purchased} WHERE wishlist_purch_wid = %d', $delete_wp);
230
231 // Set a successful return and then go back to the node display for this item.
232 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)));
233 drupal_goto('admin/content/wishlist');
234 }
235
236 ?>

  ViewVC Help
Powered by ViewVC 1.1.2