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

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

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


Revision 1.1 - (show annotations) (download) (as text)
Mon Jan 26 20:15:38 2009 UTC (10 months ago) by rszrama
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/x-php
Updating HEAD from latest work.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Defines administration pages for the node checkout module.
7 */
8
9 // Displays the node checkout settings table/form.
10 function uc_node_checkout_admin() {
11 $nc_map = uc_node_checkout_product_map();
12 $types = node_get_types('types');
13 $rows = array();
14
15 $header = array(t('Node type'), t('Product'), t('View'), t('Actions'));
16
17 // Loop through all the node types on the site.
18 foreach ($types as $type => $info) {
19 // Look for a product node association.
20 if ($nc_map[$type]['nid']) {
21 $product = node_load($nc_map[$type]['nid']);
22 }
23 else {
24 $product = FALSE;
25 }
26
27 // Look for a View association.
28 $view = variable_get('uc_node_checkout_'. $type .'_view', '');
29
30 // Add the node type's data to the table.
31 $rows[] = array(
32 $info->name,
33 $product ? l($product->model, 'node/'. $product->nid) : t('n/a'),
34 $nc_map[$type]['view'] ? check_plain($nc_map[$type]['view']) : t('n/a'),
35 l(t('edit'), 'admin/store/settings/node-checkout/'. $type),
36 );
37 }
38
39 return theme('table', $header, $rows);
40 }
41
42 // Displays the form to map a product to a node type.
43 function uc_node_checkout_type_form(&$form_state, $type) {
44 $nc_map = uc_node_checkout_product_map();
45 $form = array();
46
47 $options = array(0 => t('<None>'));
48
49 $result = db_query("SELECT n.nid, p.model, n.title FROM {uc_products} AS p INNER JOIN {node} AS n ON p.vid = n.vid ORDER BY p.model");
50 while ($product = db_fetch_object($result)) {
51 $options[$product->nid] = '('. $product->model .') '. $product->title;
52 }
53
54 $form['type'] = array(
55 '#type' => 'value',
56 '#value' => $type->type,
57 );
58
59 $form['product_nid'] = array(
60 '#type' => 'textfield',
61 '#title' => t('Product NID'),
62 '#description' => t("When a %type node is created, one of the chosen product is added to the user's cart.<br />Start typing a SKU or title in this field to view autocomplete options.<br />Empty this field to disable node checkout for this node type.", array('%type' => $type->name)),
63 '#default_value' => $nc_map[$type->type]['nid'],
64 '#autocomplete_path' => 'uc_node_checkout/autocomplete',
65 );
66
67 if (module_exists('views')) {
68 $views = array();
69
70 // Generate an option list from all user defined and module defined views.
71 foreach (views_get_all_views() as $view_key => $view_value) {
72 // Only include node Views.
73 if ($view_value->base_table == 'node') {
74 foreach ($view_value->display as $display_key => $display_value) {
75 $views[$view_key .'|'. $display_key] = check_plain($view_key .': '. $display_value->display_title);
76 }
77 }
78 }
79
80 $form['view'] = array(
81 '#type' => 'select',
82 '#title' => t('View'),
83 '#description' => t('Optional. When a user creates a %type node, allow them to choose the associated product from this View.<br />If a View is specified, the Product NID setting will be ignored.', array('%type' => $type->name)),
84 '#options' => array_merge(array('' => ' '), $views),
85 '#default_value' => $nc_map[$type->type]['view'],
86 );
87 }
88
89 $restrictions = variable_get('uc_node_checkout_'. $type->type .'_restrictions', array());
90
91 $form['disable_preview'] = array(
92 '#type' => 'checkbox',
93 '#title' => t('Disable the preview button for this node type for users without %access permission.', array('%access' => t('edit any @type content', array('@type' => $type->type)))),
94 '#description' => t('This setting is recommended when using the general node checkout redirections.'),
95 '#default_value' => in_array('preview', $restrictions),
96 );
97
98 // Integrate w/ content module from CCK to restrict field types from users
99 // without access.
100 if (module_exists('content')) {
101 $cck_type = content_types($type->type);
102
103 if (!empty($cck_type['fields'])) {
104 $options = array();
105
106 foreach ($cck_type['fields'] as $key => $value) {
107 $options[$key] = check_plain($value['widget']['label']);
108 }
109
110 $form['restricted_fields'] = array(
111 '#type' => 'checkboxes',
112 '#title' => t('Restricted node fields'),
113 '#description' => t('Selected fields will only appear on the node form for users with %access permission.', array('%access' => t('edit @type content', array('@type' => $type->type)))),
114 '#options' => $options,
115 '#default_value' => $restrictions,
116 );
117 }
118 }
119
120 $form['submit'] = array(
121 '#type' => 'submit',
122 '#value' => t('Submit'),
123 );
124
125 return $form;
126 }
127
128 function uc_node_checkout_type_form_submit($form, &$form_state) {
129 // Save the product node ID.
130 if ($form_state['values']['product_nid'] || $form_state['values']['view']) {
131 db_query("UPDATE {uc_node_checkout_types} SET product_nid = %d, node_view = '%s' WHERE type = '%s'", $form_state['values']['product_nid'], $form_state['values']['view'], $form_state['values']['type']);
132 if (!db_affected_rows()) {
133 db_query("INSERT INTO {uc_node_checkout_types} (type, product_nid, node_view) VALUES ('%s', %d, '%s')", $form_state['values']['type'], $form_state['values']['product_nid'], $form_state['values']['view']);
134 }
135 }
136 else {
137 db_query("DELETE FROM {uc_node_checkout_types} WHERE type = '%s'", $form_state['values']['type']);
138 }
139
140 // Save the restricted fields settings.
141 $fields = array();
142
143 foreach ((array) $form_state['values']['restricted_fields'] as $key => $value) {
144 if ($value) {
145 $fields[] = $key;
146 }
147 }
148
149 if ($form_state['values']['disable_preview']) {
150 $fields[] = 'preview';
151 }
152
153 variable_set('uc_node_checkout_'. $form_state['values']['type'] .'_restrictions', $fields);
154
155 $form_state['redirect'] = 'admin/store/settings/node-checkout';
156 }
157
158 // Displays the settings form for node checkout behavior/display settings.
159 function uc_node_checkout_settings_form() {
160 $form = array();
161
162 $form['behavior'] = array(
163 '#type' => 'fieldset',
164 '#title' => t('Behavior settings'),
165 );
166 $form['behavior']['uc_node_checkout_add_to_cart_node_form'] = array(
167 '#type' => 'checkbox',
168 '#title' => t('Redirect customers to the node add form when they click add to cart buttons of node checkout associated products.'),
169 '#description' => t('If this setting is turned off, make sure that the associated products are inaccessible to your customers.'),
170 '#default_value' => variable_get('uc_node_checkout_add_to_cart_node_form', TRUE),
171 );
172 $form['behavior']['uc_node_checkout_node_access'] = array(
173 '#type' => 'checkbox',
174 '#title' => t('Use UC Node Checkout to prevent anonymous node add access for node types it governs.'),
175 '#description' => t('Enable anonymous creation of node checkout node types and anonymous users will be instructed to create an account.'),
176 '#default_value' => variable_get('uc_node_checkout_node_access', TRUE),
177 );
178 $form['behavior']['uc_node_checkout_submit_redirect'] = array(
179 '#type' => 'checkbox',
180 '#title' => t('Redirect customers to their cart after adding or editing a node checkout governed node.'),
181 '#description' => t('Users who have "edit node_type content" permission are exempt from this redirect.'),
182 '#default_value' => variable_get('uc_node_checkout_submit_redirect', TRUE),
183 );
184 $form['behavior']['uc_node_checkout_view_redirect'] = array(
185 '#type' => 'checkbox',
186 '#title' => t('Redirect customers to their cart when they try to view a node governed by node checkout.'),
187 '#description' => t('Users who have "edit node_type content" permission are exempt from this redirect.'),
188 '#default_value' => variable_get('uc_node_checkout_view_redirect', TRUE),
189 );
190 $form['behavior']['uc_node_checkout_delete_orphans'] = array(
191 '#type' => 'checkbox',
192 '#title' => t('Delete products associated with nodes from shopping carts when the nodes are deleted.'),
193 '#default_value' => variable_get('uc_node_checkout_delete_orphans', TRUE),
194 );
195 $form['behavior']['uc_node_checkout_delete_nodes'] = array(
196 '#type' => 'checkbox',
197 '#title' => t('Delete nodes whose creators remove the associated product from their cart.'),
198 '#default_value' => variable_get('uc_node_checkout_delete_nodes', TRUE),
199 );
200
201 if (module_exists('uc_stock')) {
202 $form['stock'] = array(
203 '#type' => 'fieldset',
204 '#title' => t('Stock management'),
205 );
206 $form['stock']['uc_node_stock_prevent_checkout'] = array(
207 '#type' => 'checkbox',
208 '#title' => t('Prevent checkout when a customer tries to purchase an out of stock node.'),
209 '#default_value' => variable_get('uc_node_stock_prevent_checkout', TRUE),
210 );
211 $form['stock']['uc_node_stock_prevent_add'] = array(
212 '#type' => 'checkbox',
213 '#title' => t('Prevent node creation when a customer tries to create an out of stock node.'),
214 '#default_value' => variable_get('uc_node_stock_prevent_add', FALSE),
215 );
216 $form['stock']['uc_node_stock_prevent_add_redirect'] = array(
217 '#type' => 'textfield',
218 '#title' => t('Out of stock redirect'),
219 '#description' => t('Specify a redirect page if a customer is prevented from creating a node due to stock.'),
220 '#default_value' => variable_get('uc_node_stock_prevent_add_redirect', 'cart'),
221 '#size' => 32,
222 '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
223 );
224 }
225
226 $form['display'] = array(
227 '#type' => 'fieldset',
228 '#title' => t('Display settings'),
229 );
230 $form['display']['uc_node_checkout_alter_node_submit_button'] = array(
231 '#type' => 'checkbox',
232 '#title' => t('Alter the node form submit button to say "Add to cart" when a node is being created.'),
233 '#default_value' => variable_get('uc_node_checkout_alter_node_submit_button', TRUE),
234 );
235 $form['display']['uc_node_checkout_cart_titles'] = array(
236 '#type' => 'checkbox',
237 '#title' => t('Change cart item titles into edit links for their associated nodes.'),
238 '#description' => t('Only works for the cart view form; you must implement a custom solution for the cart block.'),
239 '#default_value' => variable_get('uc_node_checkout_cart_titles', TRUE),
240 );
241 $form['display']['uc_node_checkout_click_to_edit'] = array(
242 '#type' => 'checkbox',
243 '#title' => t('Display a "click to edit" message on the cart view form for node checkout products.'),
244 '#description' => t('Override theme_uc_cart_click_to_edit() in your theme to alter the display of this.'),
245 '#default_value' => variable_get('uc_node_checkout_click_to_edit', TRUE),
246 );
247 $form['display']['uc_node_cart_teaser'] = array(
248 '#type' => 'checkbox',
249 '#title' => t('Display the node cart teaser on the cart view form for node checkout products.'),
250 '#description' => t('Override theme_uc_node_cart_teaser() in your theme to alter the display of this.'),
251 '#default_value' => variable_get('uc_node_cart_teaser', TRUE),
252 );
253 $form['display']['order'] = array(
254 '#type' => 'fieldset',
255 '#title' => t('Order product display'),
256 '#description' => t('These settings require the Attribute module to be enabled and will add an attribute line to the node checkout product on order view screens.'),
257 );
258 $form['display']['order']['uc_node_order_product_display'] = array(
259 '#type' => 'checkbox',
260 '#title' => t('Display a node teaser as an attribute/option combination for nodes on orders.'),
261 '#default_value' => variable_get('uc_node_order_product_display', TRUE),
262 '#disabled' => !module_exists('uc_attribute'),
263 );
264 $form['display']['order']['uc_node_order_product_teaser_override'] = array(
265 '#type' => 'checkbox',
266 '#title' => t('Add to the default node cart teaser using these settings.'),
267 '#default_value' => variable_get('uc_node_order_product_teaser_override', FALSE),
268 );
269 $form['display']['order']['uc_node_order_product_attribute'] = array(
270 '#type' => 'textfield',
271 '#title' => t('Order product attribute'),
272 '#description' => t('Specify the name of the attribute.'),
273 '#default_value' => variable_get('uc_node_order_product_attribute', 'ID'),
274 );
275 $form['display']['order']['uc_node_order_product_option'] = array(
276 '#type' => 'textfield',
277 '#title' => t('Order product option'),
278 '#description' => t('Specify a pattern for the option string; uses node tokens like [nid] and [title].'),
279 '#default_value' => variable_get('uc_node_order_product_option', '[nid] - [title]'),
280 );
281 $form['display']['order']['tokens'] = array(
282 '#type' => 'fieldset',
283 '#title' => t('Node tokens'),
284 '#description' => t('Use these tokens in the attribute and option fields above. They will be replaced with values from the node checkout nodes on the order pages. Do not use tokens ending in -raw for these settings!'),
285 '#collapsible' => TRUE,
286 '#collapsed' => TRUE,
287 );
288 $form['display']['order']['tokens']['data'] = array(
289 '#value' => '<div>'. theme('token_help', 'node') .'</div>',
290 );
291
292 return system_settings_form($form);
293 }
294
295 // Returns an autocomplete list for nodes on the node type settings form.
296 function uc_node_checkout_autocomplete($string = '') {
297 $matches = array();
298
299 if ($string) {
300 $result = db_query_range("SELECT nid, title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')", $string, 0, 10);
301 while ($node = db_fetch_object($result)) {
302 $matches[$node->nid] = check_plain($node->title);
303 }
304 }
305
306 print drupal_to_js($matches);
307 exit();
308 }
309

  ViewVC Help
Powered by ViewVC 1.1.2