# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /var/www/artmyweb/mamamasha/docroot/sites/all/modules/uc_invite_discount
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: uc_invite_discount.module
--- uc_invite_discount.module Базовая редакция (BASE)
+++ uc_invite_discount.module Изменен локально (на основе LOCAL)
@@ -401,6 +401,14 @@
                             }
                         }
 
+                        //limit the coupon generation to the first time the invitee makes a purchase
+                        if(!$denied){
+                          $count = db_fetch_object(db_query("SELECT count(1) AS cnt FROM uc_coupons WHERE name = '%s-%s'", $invitor->name, $order_user->name));
+                          if($count->cnt){
+                            $denied = TRUE;
+                          }
+                        }
+
                         if(!$denied)
                         {
                             $token_filters = array('global' => NULL, 'user' => $user, 'order' => $order, 'uc_invite_discount' => $order);
@@ -458,7 +466,8 @@
                                     $body = token_replace_multiple($body, $token_filters);
                                     $body = token_replace_multiple($body, $token_filters);
 
-                                    drupal_mail($key, $to, $subject, $body, $from);
+                                    //drupal_mail($key, $to, $subject, $body, $from);
+                                    drupal_mail('uc_invite_discount', 'coupon_created', $to, user_preferred_language(user_load(array('mail' => $to))), array('subject' => $subject, 'body' => $body), $from);
                                 }
 
                                 if(variable_get('uc_invite_discount_invitor_notify_setting',TRUE))
@@ -474,7 +483,8 @@
                                     $body = token_replace_multiple($body, $token_filters);
                                     $body = token_replace_multiple($body, $token_filters);
 
-                                    drupal_mail($key, $to, $subject, $body, $from);
+                                    //drupal_mail($key, $to, $subject, $body, $from);
+                                    drupal_mail('uc_invite_discount', 'coupon_created', $to, user_preferred_language(user_load(array('mail' => $to))), array('subject' => $subject, 'body' => $body), $from);
                                 }
                             }
                             else
@@ -489,6 +499,17 @@
     }
 }
 
+function uc_invite_discount_mail($key, &$message, $params) {
+    switch ($key) {
+        case 'coupon_created':
+            $message['subject'] = $params['subject'];
+            $message['body'] = $params['body'];
+            break;
+    }
+}
+
+
+
\ No newline at end of file
 /**
 * Implementation of hook_token_list().
 */
