diff --git a/booking.emails.inc b/booking.emails.inc index bf67e7d..6962c93 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -221,9 +221,11 @@ function _booking_manual_email_generate_tableselect() { $options[$data->nid]['group_roles'] = $group_text; } - $values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE; + //$values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE; } - + + return $options; + /* return array ( '#type' => 'tableselect', '#header' => $header, @@ -234,6 +236,7 @@ function _booking_manual_email_generate_tableselect() { '#prefix' => '
', '#suffix' => '
', ); + */ } function _booking_manual_email_selecttype_dropdown_callback($form, &$form_state) { @@ -241,17 +244,43 @@ function _booking_manual_email_selecttype_dropdown_callback($form, &$form_state) //$courseid = $form_state['values']['courseid']; //$scheduleid = $form_state['values']['scheduleid']; - $checkboxes = $form_state['values']['table']; + //$checkboxes = $form_state['values']['table']; $select_type = $form_state['values']['select-type']; $new_default_values = array(); // generate new default values // @todo use a function for this if ($select_type == "Unpaid") { - $new_default_values = array("1814"); + $new_default_values = array("1814" => TRUE); } else { - $new_default_values = array("1815"); + $new_default_values = array("1815" => TRUE); } + + // update cached options for tableselect + $cached_form = form_get_cache($form['#build_id'], $form_state); + $cached_form['table']['#options'] = _booking_manual_email_generate_options(); + form_set_cache($form['#build_id'], $cached_form, $form_state); + + // remove radios from tableselect + $form['new']['table']['#options'] = $options; + foreach (element_children($form['table']) as $key) { + if (is_numeric($key)) { + unset($form['table'][$key]); + } + } + + // add new radios to tableselect + form_builder($form['#form_id'], $form['table'], $form_state); + // remove current value + unset($form['table']['#default_value']); + unset($form['table']['#value']); + watchdog('booking_debug', "
Manual email new form table\n@info
", array('@info' => print_r( $form['table'], true))); + // update the tableselect + $commands = array(); + $commands[] = ajax_command_replace('#manual-email-attendees-items', drupal_render($form['table'])); + return array('#type' => 'ajax', '#commands' => $commands); + + //$options = laycoaches_schedule_course_form_schedule_options($courseid, $scheduleid); // update cached options for tableselect @@ -259,7 +288,7 @@ function _booking_manual_email_selecttype_dropdown_callback($form, &$form_state) //watchdog('booking_debug', "
Manual email cached form\n@info
", array('@info' => print_r( $cached_form, true))); //unset old tableselect - unset($form['table']); + //unset($form['table']); // configure new tableselect based on old table select //$form['table'] = $cached_form['form']['table'];