From 92c6e20b983cd20886f9e360d167bd725663044d Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Fri, 25 Mar 2016 20:01:47 +0000 Subject: [PATCH] add actions; remove debug code; HMAC person_ids --- fulcrm_shoppingcart.module | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index d35614b..e84d3fa 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -104,6 +104,14 @@ function fulcrm_shoppingcart_buy_url( $product_id ) { return url( 'fulcrm/buy/' . $product_id . '/' . $hmac ); } +function _fulcrm_shoppingcart_person_id_hmac( $person_id ) { + return drupal_hmac_base64( 'fulcrm:' . strval( $person_id ) . ':person_id', session_id() . drupal_get_hash_salt() ); +} + +function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) { + +} + function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) { $form = array(); @@ -118,26 +126,26 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe ); if ( array_key_exists( 'id', $person ) ) - $persons = array( $person[ 'id' ] => 'myself' ); + $persons = array( _fulcrm_shoppingcart_person_id_hmac( $person[ 'id' ] ) => 'myself' ); else - $persons = array( 0 => 'myself' ); + $persons = array( 'myself' => 'myself' ); if ( array_key_exists( 'related_from_person2persons', $person ) ) { foreach ( $person[ 'related_from_person2persons' ] as $p2p ) { - $persons[ $p2p[ 'related_from' ][ 'id' ] ] = $p2p[ 'related_from' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')'; + $persons[ _fulcrm_shoppingcart_person_id_hmac( $p2p[ 'related_from' ][ 'id' ] ) ] = $p2p[ 'related_from' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')'; } } if ( array_key_exists( 'related_to_person2persons', $person ) ) { foreach ( $person[ 'related_to_person2persons' ] as $p2p ) { - $persons[ $p2p[ 'related_to' ][ 'id' ] ] = $p2p[ 'related_to' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')'; + $persons[ _fulcrm_shoppingcart_person_id_hmac( $p2p[ 'related_to' ][ 'id' ] ) ] = $p2p[ 'related_to' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')'; } } - $form[ 'tickets_for_persons' ] = array( '#type' => 'checkboxes', - '#title' => 'Who is coming to the event?', - '#description' => 'Tick the box next to each person for whom you want to buy a ticket.', - '#options' => $persons, - ); + $form[ 'ticket_for_persons' ] = array( '#type' => 'checkboxes', + '#title' => 'Who is coming to the event?', + '#description' => 'Tick the box next to each person for whom you want to buy a ticket.', + '#options' => $persons, + ); $form[ 'tickets_for_others' ] = array( '#type' => 'select', '#title' => 'How many tickets would you like for other people?', '#description' => 'Choose how many tickets you are getting for other people. You\'ll be asked their names soon.', @@ -149,12 +157,11 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe ), ); - $form[ 'person' ] = array( '#type' => 'markup', - '#markup' => '
' . print_r( $person, 1 ) . '
' ); - $form[ 'eventbookingtype' ] = array( '#type' => 'markup', - '#markup' => '
' . print_r( $eventbookingtype, 1 ) . '
' ); - $form[ 'product' ] = array( '#type' => 'markup', - '#markup' => '
' . print_r( $product, 1 ) . '
' ); + $form[ 'actions' ] = array( '#type' => 'actions' ); + $form[ 'actions' ][ 'save' ] = array( '#type' => 'submit', + '#value' => t('Add to Basket'), + '#submit' => array( 'fulcrm_shoppingcart_buy_eventbookingtype_form_submit' ), + ); return $form; }