From 512f863058334ca4d465c4abe525f03a940903bd Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 22 Aug 2017 21:18:55 +1000 Subject: [PATCH] add update price to current event query --- booking.prices.inc | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/booking.prices.inc b/booking.prices.inc index 704fc58..e1483b3 100644 --- a/booking.prices.inc +++ b/booking.prices.inc @@ -15,6 +15,7 @@ function booking_price_admin() $header = array ( 'booking_price_active' => t('Active'), + 'booking_eventname' => t('Event Name'), 'booking_eventid' => t('Event ID'), 'booking_price_descrip' => t('Description'), 'booking_price' => t('Early-Bird Price'), @@ -28,13 +29,14 @@ function booking_price_admin() $result = db_query("SELECT pid, p.booking_eventid, booking_price, booking_late_price, booking_late_buttonid, booking_price_descrip, " . "booking_buttonid, booking_price_active, booking_depositonly, e.booking_eventname" . "from {booking_price} p " . - "inner join {booking_event} e on e.booking_eventid = p.booking_eventid"); + "inner join {booking_event} e on e.eid = p.booking_eventid"); foreach($result as $data) { $options[$data->pid] = array ( - 'booking_price_active' => $data->booking_price_active == 1 ? 'Yes' : 'No', + 'booking_price_active' => $data->booking_price_active == 1 ? 'Yes' : 'No', + 'booking_eventname' => $data->booking_eventname, 'booking_eventid' => $data->booking_eventid, 'booking_price_descrip' => $data->booking_price_descrip, 'booking_price' => $data->booking_price, @@ -93,23 +95,36 @@ function booking_price_admin_submit($form, &$form_state) { foreach($checkboxes as $key => $value) { //only set the entries that are ticked - if ($value != 0) - { - if ($form_state['values']['op'] == 'Set Active') - $setting = 1; - else - $setting = 0; + if ($value != 0) { + //just update prices to match current event + if ($form_state['values']['op'] == 'Change to current event') { + db_update('booking_price') + ->fields(array ( + 'booking_eventid' => $event->eid, + )) + ->condition('pid', $key) + ->execute(); + } + //either make a price active or inactive + else { + if ($form_state['values']['op'] == 'Set Active') { + $setting = 1; + } + else { + $setting = 0; + } + db_update('booking_price') + ->fields(array ( + 'booking_eventid' => $event->eid, + 'booking_price_active' => $setting, + )) + ->condition('pid', $key) + ->execute(); + } - db_update('booking_price') - ->fields(array ( - 'booking_eventid' => $event->eid, - 'booking_price_active' => $setting, - )) - ->condition('pid', $key) - ->execute(); - } - } -} + } //value not 0 + } //foreach checkbox +} //end function function booking_price_form($node, &$form_state, $create, $editid = 0) {