/[drupal]/contributions/modules/openresort/booking/booking.module
ViewVC logotype

Contents of /contributions/modules/openresort/booking/booking.module

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


Revision 1.5 - (show annotations) (download) (as text)
Wed Jan 2 22:14:25 2008 UTC (22 months, 3 weeks ago) by marcingy
Branch: MAIN
CVS Tags: DRUPAL-5--1-15-1, DRUPAL-5--1-15-2, DRUPAL-5--1-16-6, DRUPAL-5--1-16-4, DRUPAL-5--1-16-5, DRUPAL-5--1-16-2, DRUPAL-5--1-16-3, DRUPAL-5--1-16-1, DRUPAL-5--1-15, DRUPAL-5--1-16, HEAD
Changes since 1.4: +0 -0 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: $
3
4 /**
5 * Implmentation of menu_hook()
6 */
7 function booking_menu($may_cache) {
8
9 $items = array();
10
11 if ($may_cache) {
12 $access = user_access('access content');
13 $items[] = array(
14 'path' => 'cart',
15 'title' => t('itinerary'),
16 'callback' => 'cart_view',
17 'access' => user_access('access content'),
18 'type' => MENU_SUGGESTED_ITEM
19 );
20 $items[] = array(
21 'path' => 'store/payment',
22 'title' => t('Payments'),
23 'callback' => 'drupal_get_form',
24 'callback arguments' => array('payment_process_payment',$_GET['txnid']),
25 'access' => 1, // The callback handles the access
26 'type' => MENU_CALLBACK,
27 );
28 $items[] = array(
29 'path' => 'admin/store/transaction/product/edit',
30 'title' => t('Transaction items'),
31 'callback' => 'store_transaction_edit_items',
32 'access' => $access,
33 'type' => MENU_CALLBACK,
34 );
35 //suppress link as no one will have this permission
36 $items[] = array(
37 'path' => 'product',
38 'access' => user_access('booking dummy'),
39 );
40 }
41
42 return $items;
43 }
44
45 function booking_link_alter(&$node, &$links) {
46 if($node->type =='business' ||$node->type =='unit'){
47 unset($links['add_to_cart']);
48 }
49 }
50
51 function booking_perm(){
52 return array('override purchase policy');
53 }
54
55 function booking_form_alter($form_id, &$form) {
56 if (product_form_is_product($form_id, $form)) {
57 if(!user_access('override purchase policy')){
58 unset($form['product']['ec_anon']);
59 }
60 }
61
62 if ($form['type'] && $form_id == $form['type']['#value'] . '_node_form') {
63 if (user_access('administer products') && $form['type']['#value'] != 'product') {
64 if ($form['#node']->ptype) {
65 unset($form['product']);
66 }
67 else {
68 unset($form['product_transform']);
69 }
70 // skip validation if you are turning a node into a product.
71 unset($form['#after_build']);
72 }
73 }
74 if($form['product_cart_addition_by_link']){
75 unset($form['product_cart_addition_by_link']);
76 }
77
78 }
79
80 //hack so as the theme in the ecommerce module is overriden by default on any site theme
81 //this code can be moved to your template.php file
82 //in adition it can be overriden itself by creating a function called
83 //yourtheme_cart_view_form
84 function phptemplate_cart_view_form($form) {
85 drupal_set_title('Itinerary');
86 $total = 0;
87 $header = array(t('nights'),t('arrival date'),t('items'), t('price'), '');
88 $extra = array_filter($form['items'], '_cart_form_filter_extra');
89 if ($extra) {
90 $header[] = '';
91 }
92
93 foreach (element_children($form['items']) as $nid) {
94 $total+= $form['items'][$nid]['#total'];
95 $total+= $form['items'][$nid]['#specials'];
96 $desc = drupal_render($form['items'][$nid]['title']) .'<br />';
97 $desc .= $form['items'][$nid]['#unitname'];
98 $days = $form['items'][$nid]['#days'];
99 $arrive = $form['items'][$nid]['#arrive'];
100 if ($form['items'][$nid]['recurring']) {
101 $desc.= '<div class="recurring-details">'. drupal_render($form['items'][$nid]['recurring']) .'</div>';
102 }
103 if ($form['items'][$nid]['availability']) {
104 $desc.= drupal_render($form['items'][$nid]['availability']);
105 }
106 $payment = payment_format($form['items'][$nid]['#total']+$form['items'][$nid]['#specials']);
107
108 if($form['items'][$nid]['#node']->ptype == 'liftticket'){
109 $row[] = array(
110 //we don't these if it is a lift ticket
111 array('data' => ''),
112 array('data' => ''),
113 array('data' => $desc),
114 array('data' => $payment),
115 array('data' => l(t('Remove'), "cart/delete/$nid"),"align" => "right"),
116 );
117 }else{
118 $row[] = array(
119 //we don't these if it is a lift ticket
120 array('data' => $days),
121 array('data' => $arrive),
122 array('data' => $desc),
123 array('data' => $payment),
124 array('data' => l(t('Remove'), "cart/delete/$nid"),"align" => "right"),
125 );
126 }
127
128
129
130
131 $rows[] = $row;
132 }
133 $rows[] = array('', '', '', '','');
134 $row[] = array(array('data' => ''),array('data' => t('<strong>Subtotal</strong>')),array('data' => ''),array('data' => ''),array("data" => payment_format($total), "align" => "right","class" => "topborder"));
135 $output.= theme('table', $header, $row);
136 $output.= drupal_render($form);
137 $output = theme('box', t('Your Itinerary'), $output);
138 if(module_exists('openresort')){
139 $output = openresort_cartlink($output);
140 }
141 return $output;
142 }
143
144 function phptemplate_cart_review_form(&$form) {
145 $f =& $form['cart'];
146
147 $header = array(t('nights'), t('arrival date'),t('item'), t('price'), t('subtotal'), '');
148 $rows = array();
149 if ($f['items']) {
150 foreach ($f['items'] as $key => $line) {
151 $nodekey = explode('-',$key);
152 if (is_numeric($nodekey[0])) {
153 $subitem = $line['item'];
154 $subitem = $subitem['#value'];
155 $subitem = $subitem->subitem;
156 //unit type is also required
157 //change this so as we use the key - we also need to read from accom inventory
158 //and join on the node table
159 $nodetitle = '';
160 if($line['ptype']['#value'] !='liftticket'){
161 while($key = key($subitem)){
162 //foreach ($subitem as $s){
163 $unitname = db_result(db_query("SELECT title FROM node n inner join accommodation_inventory i on n.nid = i.unit_id inner join accommodation_availability a on a.iid = i.iid where a.aid = " . $key ));
164 break;
165 }
166 $nodetitle = $line['item']['#value']->title .'<br>' . $unitname;
167 $days = $line['days']['#value'];
168 $date= $line['date']['#value'];
169 }else{
170 $nodetitle = $line['item']['#value'];
171 $days = '';
172 $date='';
173 }
174 $rows[] = array(
175 //add date arrival here
176 $days,
177 $date,
178 $nodetitle,
179 array('data' => payment_format($line['price']['#value']), 'align' => 'right'),
180 array('data' => payment_format($line['subtotal']['#value']), 'align' => 'right'),
181 $line['options']['#value']
182 );
183 }
184 }
185 }
186
187 $rows[] = array('', '', '', '', '','');
188 foreach ($f['totals'] as $id => $line) {
189 if (is_numeric($id)) {
190 $rows[] = array(
191 '',
192 "<b>{$line['#title']}</b>",
193 '',
194 array('data' => payment_format($line['#value']), 'align' => 'right'),
195 '',
196 ''
197 );
198 }
199 }
200
201 $content .= theme('table', $header, $rows);
202
203 return theme('box', t('Your Itinerary'), $content);
204 }
205
206 function phptemplate_store_invoice($txn, $print_mode = TRUE, $trial = FALSE) {
207 global $base_url;
208
209 $header = array();
210 $row = array();
211
212 if (empty($txn->mail) && $txn->uid > 0) {
213 $txn->mail = db_result(db_query('SELECT mail FROM {users} WHERE uid = %d', $txn->uid));
214 }
215
216 if ($txn->items) {
217 $header = array(t('Quantity'), t('Item'),t('People'),t('Type'),t('Arrival'),t('Nights'), t('Price'));
218
219 $shippable = FALSE;
220 foreach ($txn->items as $p) {
221 $prod = product_load($p);
222 if (product_is_shippable($p->vid)) $shippable = TRUE;
223
224 $price = store_adjust_misc($txn, $p);
225
226 $subtotal += (product_has_quantity($p) ? $p->qty * $price : $price);
227 $details = '';
228 if (0 && is_array($p->data)) {
229 foreach ($p->data as $key => $value) {
230 if ($value) {
231 $items[] = '<strong>'. check_plain($key). ': </strong>'. check_plain($value);
232 }
233 }
234 if ($items) {
235 $details = theme('item_list', $items);
236 }
237 }
238
239 $first = true;
240 $localsubitem = $p->data->subitem;
241 while($key = key($localsubitem)){
242 if($first == true){
243 $arrivaldate = $localsubitem[$key]->date;
244 $propertyowner = $key;
245 $first = false;
246 }
247 next($localsubitem);
248 }
249 //%night stay at %title arriving on %date
250 //we need to check the type - lift ticket??
251 $occupants = $p->data->occupants;
252 if($p->dataid > 0){
253 $unitname = db_result(db_query("SELECT title FROM node n where n.nid = " . $p->dataid));
254 }else{
255 $unitname ='';
256 }
257 //$items = t('@title for @occupants people staying in a(n) @unitname arriving on @arrival ', array('@title' => $p->title,'@unitname' => $unitname, '@arrival' => $arrivaldate,'@occupants'=>$occupants)). "\r\n\r\n";
258
259
260 //$row[] = array(array('data' => $p->qty, 'align' => 'center', 'valign' => 'top'), '<em>'. check_plain($items). '</em> '. (($prod->sku != '') ? "[". check_plain($prod->sku) ."]" : ''). '<br />'. $details, array('data' => payment_format($price), 'valign' => 'top', 'align' => 'right'));
261 $row[] =array(array('data' => $p->qty, 'align' => 'center', 'valign' => 'top'),array('data' => $p->title, 'align' => 'center', 'valign' => 'top'),array('data' => $occupants, 'align' => 'center', 'valign' => 'top'),array('data' => $unitname, 'align' => 'center', 'valign' => 'top'),array('data' => $arrivaldate, 'align' => 'center', 'valign' => 'top'),array('data' => $p->data->days, 'align' => 'center', 'valign' => 'top'),array('data' => payment_format($price), 'valign' => 'top', 'align' => 'right'));
262 }
263
264 if (is_array($txn->misc)) {
265 foreach ($txn->misc as $misc) {
266 if (!$misc->seen) {
267 $price = $misc->qty ? $misc->price * $misc->qty : $misc->price;
268 $row[] = array(array('data' => t("<strong>{$misc->description}</strong>: %price", array('%price' => payment_format($price))), 'colspan' => 7, 'align' => 'right'));
269 }
270 }
271 }
272
273 $row[] = array(array('data' => '<hr size="1" noshade="noshade" />', 'colspan' => 7, 'align' => 'right'));
274 $row[] = array(array('data' => t('<strong>Total:</strong> %total', array('%total' => payment_format(store_transaction_calc_gross($txn)))), 'colspan' => 7, 'align' => 'right'));
275 }
276
277 $payment_info = t('<strong>Ordered On:</strong> %order-date<br />', array('%order-date' => format_date($txn->created)));
278 //if ($txn->duedate) {
279 // $payment_info.= t('<div><strong>Due Date:</strong> %due-date</div>', array('%due-date' => format_date($txn->duedate)));
280 //}
281 $payment_info .= t('<strong>Transaction ID:</strong> %txnid', array('%txnid' => $trial ? t('Trial Invoice - Not Yet Posted') : $txn->txnid));
282
283 $css = base_path(). drupal_get_path('module', 'store') .'/invoice.css';
284 $site_name = t('%site-name Invoice', array('%site-name' => variable_get("site_name", "drupal")));
285
286 if ($shipping_to = store_format_address($txn, 'shipping', 'html')) {
287 $shipping_label = t('Shipping to');
288 }
289
290 if ($billing_to = store_format_address($txn, 'billing', 'html')) {
291 $billing_label = t('Billing to');
292 }
293
294 if ($txn->ship) {
295 $shipping_method_label = t('Shipping method:');
296 $shipping_method = store_format_shipping_method($txn);
297 }
298 $email_label = t('E-mail:');
299 $items_label = t('Items ordered');
300 $items_view = theme('table', $header, $row, array('cellpadding' => 3, 'cellspacing' => 3));
301
302 $payment_label = t('Payment Info');
303
304 if ($print_mode) {
305 $output .= <<<EOD
306 <html>
307 <head>
308 <style type="text/css" media="all">@import url('$css');</style>
309 </head>
310 <body>
311 EOD;
312 }
313
314 $output .= <<<EOD
315 <div class="invoice">
316 <h2>$site_name</h2>
317
318 <table cellspacing="5">
319 <tr>
320 <th align="left">$shipping_label</th>
321 <th align="left">$billing_label</th>
322 </tr>
323 <tr>
324 <td>$shipping_to</td>
325 <td>$billing_to</td>
326 </tr>
327 </table>
328
329 <p><strong>$shipping_method_label</strong> $shipping_method</p>
330 <p><strong>$email_label</strong> $txn->mail</p>
331
332 <h2>$items_label</h2>
333 $items_view
334
335 <h2>$payment_label</h2>
336 <p>$payment_info</p>
337 </div>
338 EOD;
339
340 if ($print_mode) {
341 $output .= <<<EOD
342 </body>
343 </html>
344 EOD;
345 }
346
347 if (!$print_mode) {
348 return $output;
349 }
350 print $output;
351 }
352
353 function phptemplate_product_price($node) {
354 if($node->ptype != 'liftticket' && $node->type != 'business' && $node->type != 'unit'){
355 return '<div class="price"><strong>'. t('Price') .'</strong>: ' . module_invoke('payment', 'format', product_adjust_price($node, 'product')+product_get_specials($node, 'product', true)) . '</div>';
356 }
357 }
358 ?>

  ViewVC Help
Powered by ViewVC 1.1.2