# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: contributions/modules/ecard/ecard.module --- contributions/modules/ecard/ecard.module Base (1.1.4.11) +++ contributions/modules/ecard/ecard.module Locally Modified (Based On 1.1.4.11) @@ -385,13 +385,38 @@ * Submit handler for ecard_form. */ function ecard_form_submit($form_id, &$form_state) { - unset($random); +// Set up the ecard record. + $ecard = new stdClass; + $ecard->nid = $form_state['values']['nid']; + $ecard->sender_name = $form_state['values']['name']; + $ecard->sender_email = $form_state['values']['from_email']; + $ecard->valid_emails = $form_state['values']['valid_emails']; + $ecard->message = $form_state['values']['message']; + $ecard->send_time = time(); + $ecard->send = 'y'; + $ecard->notify = $form_state['values']['notify']; + $ecard->format = $form_state['values']['format']; + + // Send the e-cards, including copies. + ecard_send_card($ecard); + + // Display a message. + drupal_set_message(format_plural(count($form_state['values']['valid_emails']), 'Your e-card has been sent.', 'Your e-cards have been sent.')); + + // Redirect to thank you page if necessary. + $thank_you_page = variable_get('ecard_thank_you_page', 'ecard/thanks'); + if (!empty($thank_you_page)) { + $form_state['redirect'] = $thank_you_page; + } +} + +/** + * Send e-cards, including copies if necessary. + */ +function ecard_send_card($ecard) { global $base_url; global $language; - $start = 0; - $timestamp = time(); - $send = "y"; - $notify = "n"; + // Set the base variable from the clean url value. if (variable_get('clean_url', 0)) { $base = $base_url .'/'; @@ -400,67 +425,47 @@ $base = $base_url .'/index.php?q='; } - // Make a random variable. - // This loop generate a random and check whether it exist in database if not - // it will store that random else it will generate another one. - while (!$random) { - $random = md5(microtime()); - $result = db_fetch_object(db_query("SELECT random FROM {ecard} WHERE random = '%s'", $random)); - if ($result) { - unset($random); - } - } - $card_copy_url = $base .'ecard/view/'. $random; - - // Making a copy for you else if you click any other recp link it will mail - // notification also there is some problem while we produce random. - $record = new stdClass; - $record->random = $random; - $record->nid = $form_state['values']['nid']; - $record->sender_name = $form_state['values']['name']; - $record->sender_email = $form_state['values']['from_email']; - $record->recp_mail = $form_state['values']['from_email']; - $record->message = $form_state['values']['message']; - $record->send_time = $timestamp; - $record->send = $send; - $record->notify = $notify; - $record->format = $form_state['values']['format']; - drupal_write_record('ecard', $record); - - $cardid = $random; - // Iterate through each emails and send them and store a random number for // each. - foreach ($form_state['values']['valid_emails'] as $email) { - if (variable_get('ecard_notify_enabled', TRUE) && $form_state['values']['notify'] == 1) { - $notify = "y"; + foreach ($ecard->valid_emails as $email) { // Append start value to random number to get cardid. - $cardid = $random . $start; - // Making some number in increment order. - $start = $start + 1; + $cardid = md5(microtime() . $ecard->sender_email . $email); - $record->random = $cardid; - $record->recp_mail = $email; - drupal_write_record('ecard', $record); + if (variable_get('ecard_notify_enabled', TRUE) && $ecard->notify == 1) { + // Save record to the database. + $ecard->notify = 'y'; } + else { + $ecard->notify = 'n'; + } + + $ecard->random = $cardid; + $ecard->recp_mail = $email; + drupal_write_record('ecard', $ecard); + $params['card'] = $base .'ecard/view/'. $cardid; - $params['sender'] = $form_state['values']['name']; - $params['sendermail'] = $form_state['values']['from_email']; + $params['sender'] = $ecard->sender_name; + $params['sendermail'] = $ecard->sender_email; $params['recipient'] = $email; - drupal_mail('ecard', 'ecard-mail', $email, $language, $params, $form_state['values']['from_email']); + drupal_mail('ecard', 'ecard-mail', $email, $language, $params, $ecard->sender_email); } - drupal_set_message(format_plural(count($form_state['values']['valid_emails']), 'Your e-card has been sent.', 'Your e-cards have been sent.')); + if (variable_get('ecard_copy_enabled', TRUE)) { - drupal_set_message(t('You can view the e-card at here.')); + // Making a copy for you else if you click any other recp link it will mail + // notification also there is some problem while we produce random. + $ecard->send = 'y'; + $ecard->notify = 'n'; + $ecard->random = md5(microtime() . $ecard->sender_email); + $ecard->recp_mail = $ecard->sender_email; + drupal_write_record('ecard', $ecard); + + $card_copy_url = $base .'ecard/view/'. $ecard->random; + drupal_set_message(t('You can view the e-card at here.', array('!url' => $card_copy_url))); + $params['card_copy'] = $card_copy_url; - drupal_mail('ecard', 'ecard-copy', $form_state['values']['from_email'], $language, $params, variable_get('site_mail', ini_get('sendmail_from'))); + drupal_mail('ecard', 'ecard-copy', $ecard->sender_email, $language, $params, variable_get('site_mail', ini_get('sendmail_from'))); } - $thank_you_page = variable_get('ecard_thank_you_page', 'ecard/thanks'); - if (!empty($thank_you_page)) { - $form_state['redirect'] = $thank_you_page; } - $form_state['nid'] = $node->nid; -} /** * Function for making copy url letter.