285 lines
8.8 KiB
PHP
285 lines
8.8 KiB
PHP
<?php
|
|
// $Id: booking.prices.inc,v 0.1 2012/02/28
|
|
|
|
/**
|
|
* @file
|
|
* Admin pages for configuring prices for a registration event
|
|
*/
|
|
function booking_price_admin()
|
|
{
|
|
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
|
$form = array ();
|
|
$options = array ();
|
|
$prefix = t("<p>!link</p>",
|
|
array ('!link' => l('Add New Price Entry', 'admin/config/booking/prices/create')));
|
|
|
|
$header = array (
|
|
'booking_price_active' => t('Active'),
|
|
'booking_eventid' => t('Event ID'),
|
|
'booking_price_descrip' => t('Description'),
|
|
'booking_price' => t('Early-Bird Price'),
|
|
//'booking_buttonid' => t('Button ID'),
|
|
'booking_late_price' => t('Late Booking Price'),
|
|
//'booking_late_buttonid' => t('Late Booking Button ID'),
|
|
'booking_depositonly' => t('Deposit Only'),
|
|
'booking_edit' => t('Edit Price'),
|
|
);
|
|
|
|
$result = db_query("SELECT pid, booking_eventid, booking_price, booking_late_price, booking_late_buttonid, booking_price_descrip, booking_buttonid, booking_price_active, " .
|
|
"booking_depositonly from {booking_price}");
|
|
|
|
foreach($result as $data)
|
|
{
|
|
$options[$data->pid] = array
|
|
(
|
|
'booking_price_active' => $data->booking_price_active == 1 ? 'Yes' : 'No',
|
|
'booking_eventid' => $data->booking_eventid,
|
|
'booking_price_descrip' => $data->booking_price_descrip,
|
|
'booking_price' => $data->booking_price,
|
|
//'booking_buttonid' => $data->booking_buttonid,
|
|
'booking_late_price' => $data->booking_late_price,
|
|
//'booking_late_buttonid' => $data->booking_late_buttonid,
|
|
'booking_depositonly' => $data->booking_depositonly == 1 ? 'Yes' : 'No',
|
|
'booking_edit' => l('Edit', t('admin/config/booking/prices/!pid/edit', array('!pid' => $data->pid))),
|
|
);
|
|
}
|
|
|
|
$form['table'] = array (
|
|
'#type' => 'tableselect',
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
'#multiple' => true,
|
|
);
|
|
|
|
$form['submit_active'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Set Active'),
|
|
);
|
|
|
|
$form['submit_inactive'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Set Inactive'),
|
|
);
|
|
|
|
//watchdog('booking', 'Setting button form: @info', array ('@info' => var_export($form, TRUE)));
|
|
|
|
return array (
|
|
/*
|
|
'first_para' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $prefix,
|
|
),
|
|
*/
|
|
'form' => $form,
|
|
);
|
|
}
|
|
|
|
function booking_price_admin_submit($form, &$form_state) {
|
|
|
|
$checkboxes = $form_state['values']['table']; //$values['booking_price_active'];
|
|
//watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE)));
|
|
|
|
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
|
|
|
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;
|
|
|
|
db_update('booking_price')
|
|
->fields(array (
|
|
'booking_price_active' => $setting,
|
|
))
|
|
->condition('pid', $key)
|
|
->execute();
|
|
}
|
|
}
|
|
}
|
|
|
|
function booking_price_form($node, &$form_state, $create, $editid = 0)
|
|
{
|
|
$form = array ();
|
|
$prefix = "<p>Add a new payment option</p>";
|
|
|
|
if ($create == true)
|
|
{
|
|
$data = $node;
|
|
watchdog('booking', 'Creating new price entry: @info', array ('@info' => var_export($node, TRUE)));
|
|
}
|
|
else
|
|
{
|
|
//verify that $editid is a number
|
|
if (! preg_match('/^[0-9]+$/', $editid)) {
|
|
drupal_set_message("Error: Invalid price ID supplied. Unable to update price entry.", 'error', FALSE);
|
|
drupal_goto('admin/config/booking/prices');
|
|
return "";
|
|
}
|
|
|
|
//$data = $form_state['input'];
|
|
$data = db_query("SELECT * FROM {booking_price} WHERE pid = :id",
|
|
array(':id' => $editid))
|
|
->fetchObject();
|
|
$prefix = t("<p>Update the !event price details.</p>", array('!event' => $data->booking_price_descrip));
|
|
//add this to the form in a hidden field so we can update the right price
|
|
$form['booking_pid'] = array (
|
|
'#type' => 'hidden',
|
|
'#value' => $editid,
|
|
);
|
|
watchdog('booking', 'Editing existing price entry: @info',
|
|
array ('@info' => var_export($data, TRUE)));
|
|
}
|
|
|
|
$form['booking_price_descrip'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('Description of this price'),
|
|
'#size' => 60,
|
|
'#maxlength' => 150,
|
|
'#required' => TRUE,
|
|
'#default_value' => !empty($data->booking_price_descrip) ? $data->booking_price_descrip : '',
|
|
);
|
|
$form['booking_price'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('The earlybird price relating to this entry. Set this to match the normal price if not using a discount for early bookings.'),
|
|
'#field_prefix' => '$',
|
|
'#size' => 5,
|
|
'#maxlength' => 10,
|
|
'#required' => TRUE,
|
|
'#default_value' => !empty($data->booking_price) ? $data->booking_price : '',
|
|
);
|
|
$form['booking_late_price'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('The normal booking price relating to this entry.'),
|
|
'#field_prefix' => '$',
|
|
'#size' => 5,
|
|
'#maxlength' => 10,
|
|
'#required' => TRUE,
|
|
'#default_value' => !empty($data->booking_late_price) ? $data->booking_late_price : '',
|
|
);
|
|
/*
|
|
$form['booking_buttonid'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('The PayPal button ID. This setting is deprecated.'),
|
|
'#size' => 20,
|
|
'#maxlength' => 20,
|
|
'#default_value' => !empty($data->booking_buttonid) ? $data->booking_buttonid : '',
|
|
);
|
|
$form['booking_late_buttonid'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('The PayPal button ID for late bookings. This setting is deprecated.'),
|
|
'#size' => 20,
|
|
'#maxlength' => 20,
|
|
'#default_value' => !empty($data->booking_late_buttonid) ? $data->booking_late_buttonid : '',
|
|
);
|
|
*/
|
|
$form['booking_price_active'] = array(
|
|
'#type' => 'checkbox',
|
|
'#title' => t('Tick to make this price active for the current event.'),
|
|
'#default_value' => !empty($data->booking_price_active) ? $data->booking_price_active : '',
|
|
);
|
|
|
|
$form['booking_depositonly'] = array(
|
|
'#type' => 'checkbox',
|
|
'#title' => t('Tick to indicate that this is a deposit only price.'),
|
|
'#default_value' => !empty($data->booking_depositonly) ? $data->booking_depositonly : 0,
|
|
);
|
|
|
|
if ($create == true)
|
|
{
|
|
$form['submit'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Create'),
|
|
);
|
|
} else {
|
|
$form['Update'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Update'),
|
|
);
|
|
$form['Delete'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Delete'),
|
|
);
|
|
}
|
|
|
|
return array (
|
|
'first_para' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $prefix,
|
|
),
|
|
'form' => $form,
|
|
);
|
|
}
|
|
|
|
|
|
function booking_price_form_submit($form, &$form_state) {
|
|
global $event;
|
|
$values = $form_state['input'];
|
|
|
|
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
|
if ($form_state['values']['op'] == 'Create')
|
|
{
|
|
db_insert('booking_price')
|
|
->fields(array(
|
|
'booking_eventid' => $event->eid,
|
|
'booking_price' => $values['booking_price'],
|
|
'booking_late_price' => $values['booking_late_price'],
|
|
'booking_price_descrip' => $values['booking_price_descrip'],
|
|
//'booking_buttonid' => $values['booking_buttonid'],
|
|
'booking_price_active' => $values['booking_price_active'] == 1 ? 1 : 0,
|
|
'booking_depositonly' => $values['booking_depositonly'] == 1 ? 1 : 0,
|
|
))
|
|
->execute();
|
|
}
|
|
elseif ($form_state['values']['op'] == 'Delete')
|
|
{
|
|
//verify that booking_pid is a number
|
|
if (! preg_match('/^[0-9]+$/', $values['booking_pid'])) {
|
|
drupal_set_message("Error: Invalid price ID supplied. Unable to delete price entry.", 'error', FALSE);
|
|
return "";
|
|
}
|
|
|
|
//TODO: Confirmation
|
|
//return confirm_form($form, "Really delete price?", 'admin/config/booking/prices');
|
|
|
|
$num_deleted = db_delete('booking_price')
|
|
->condition('pid', $values['booking_pid'])
|
|
->execute();
|
|
|
|
$message = t("Successfully deleted !num row(s), corresponding to event price '!price'",
|
|
array('!num' => $num_deleted, '!price' => $values['booking_price_descrip']));
|
|
drupal_set_message($message, $type = 'status');
|
|
|
|
} else {
|
|
|
|
//verify that booking_pid is a number
|
|
if (! preg_match('/^[0-9]+$/', $values['booking_pid'])) {
|
|
drupal_set_message("Error: Invalid price ID supplied. Unable to update price entry.", 'error', FALSE);
|
|
return "";
|
|
}
|
|
|
|
//update the event
|
|
db_update('booking_price')
|
|
->fields(array (
|
|
'booking_eventid' => $event->eid,
|
|
'booking_price' => $values['booking_price'],
|
|
'booking_late_price' => $values['booking_late_price'],
|
|
'booking_price_descrip' => $values['booking_price_descrip'],
|
|
//'booking_buttonid' => $values['booking_buttonid'],
|
|
'booking_price_active' => $values['booking_price_active'] == 1 ? 1 : 0,
|
|
'booking_depositonly' => $values['booking_depositonly'] == 1 ? 1 : 0,
|
|
))
|
|
->condition('pid', $values['booking_pid'])
|
|
->execute();
|
|
}
|
|
|
|
$form_state['redirect'] = array('admin/config/booking/prices');
|
|
}
|