rendered paste body/**
* electorate / headoffice form to register a new member or supporter
*/
function nzg_civicrm_newregistration_form($form_values = NULL) {
$form['#multistep'] = TRUE ;
// print_r($form_values);
$step = isset($form_values) ? (int) $form_values['step'] : 1 ;
// work out what step we're on
$form['step'] = array(
'#type' => 'hidden',
'#value' => $step + 1
);
// each step is different
switch( $step ) {
case 1:
$form['#redirect'] = FALSE ;
$form['basic'] = array(
'#type' => 'fieldset',
'#title' => t('Basic Details'),
);
$form['basic']['firstname'] = array( '#type' => 'textfield',
'#title' => 'First Name',
'#size' => '18' ) ;
$form['basic']['lastname'] = array( '#type' => 'textfield',
'#title' => 'Last Name',
'#size' => '18' ) ;
/*
$e_options['-1'] = "No electoral match (yet)" ;
$args = array( 'forenames' => 'chris', 'surname' => 'burgess' ) ;
if ( $res = nzg_electoral_search($args) ) {
foreach( $res as $k => $val ) {
$e_options[$k] = nzg_electoral_persondetails_oneliner($val) ;
}
}
$form['basic']['electoral_id'] = array( '#type' => 'radios',
'#title' => t("Matches on Electoral Roll"),
'#options' => $e_options ) ;
*/
$form['basic']['help'] = array(
'#prefix' => '<p>',
'#value' => "You only need to enter basic details on this page; on the next screen we'll look for a match in the electoral roll and current contacts database.",
'#suffix' => '</p>'
);
$form['basic']['submit'] = array( '#type' => 'submit',
'#value' => 'Next' ) ;
break ;
case 2:
$form['#redirect'] = FALSE ;
$form['basic'] = array( '#type' => 'fieldset',
'#title' => t('Basic Details') );
$form['basic']['firstname'] = array( '#type' => 'hidden',
'#value' => $form_values['firstname'] );
$form['basic']['lastname'] = array( '#type' => 'hidden',
'#value' => $form_values['lastname'] ) ;
$form['basic']['help'] = array( '#prefix' => '<p>',
'#value' => "Looking for <strong>" . $form_values['firstname'] . " / " . $form_values['lastname'] . "</strong>" );
$e_options['-1'] = "No electoral match (yet)" ;
if ( !empty($form_values['firstname']) && !empty($form_values['lastname']) ) {
$args = array( 'forenames' => $form_values['firstname'], 'surname' => $form_values['lastname'] ) ;
if ( $res = nzg_electoral_search($args) ) {
foreach( $res as $k => $v ) {
$e_options[$k] = nzg_electoral_persondetails_oneliner($v);
}
}
}
$form['basic']['electoral_id'] = array( '#type' => 'radios',
'#title' => t("Matches on Electoral Roll"),
'#options' => $e_options ) ;
}
return $form ;
}
/**
* search for an electoral roll match, given some arguments (currently forenames, surname)
*/
function nzg_electoral_search($args = array()) {
$qry = "select * from green_electoralroll.electoral_roll where forenames like '%s%' and surname like '%s%' order by surname, forenames" ;
$res = db_query($qry, $args['forenames'], $args['surname']) ;
while ( $data = db_fetch_array( $res ) ) {
$matches[] = $data ;
}
return $matches ;
}
/**
* format a person's electoral roll listing to make them as identifiable as possible in a single line
*
* @todo need to ask michael what's important here
*/
function nzg_electoral_persondetails_oneliner($val) {
$addr = '' ;
if ( !empty($val['dwelling_name']) ) {
$addr .= $val['dwelling_name'] ;
}
if ( !empty($val['flat_no']) ) {
$addr .= $val['flat_no'] . '/' ;
}
if ( !empty($val['house_no']) ) {
$addr .= $val['house_no'] ;
}
if ( !empty($val['house_alpha']) ) {
$addr .= $val['house_alpha'] ;
}
if ( !empty($val['street']) ) {
$addr .= ' ' . $val['street'] . ', ' ;
}
if ( !empty($val['suburb_town']) ) {
$addr .= $val['suburb_town'] . ', ' ;
}
if ( !empty($val['city']) ) {
$addr .= $val['city'] . ' ' ;
}
if ( !empty($val['postcode']) ) {
$addr .= $val['postcode'] ;
}
$result = $val['title'] . ' ' . $val['forenames'] . " " . $val['surname'] .
' <em><small>' . $addr . '</small></em>' ;
return $result ;
}