Ejemplo n.º 1
0
 function OnExceedsThresholds($money, $userid)
 {
     //validity test
     $db =& JFactory::getDBO();
     $query = "SELECT * FROM #__license";
     $db->setQuery($query, 0, 1);
     $rows = $db->loadObjectList();
     foreach ($rows as $code) {
         $code->security_code;
     }
     $test = new test_dependent();
     $valid = $test->start_rs($_SERVER['HTTP_HOST'], $code->security_code);
     if ($valid == 0) {
         return;
     }
     //end validity test
     $sql_cpn = "select *  from #__virtuemart_coupontype where type=2 and published=1 order by `order` asc";
     $db->setQuery($sql_cpn);
     $moneytype = $db->loadObjectList();
     $order_num = NULL;
     foreach ($moneytype as $moneythr) {
         $threshold = $moneythr->typevalue;
         $time = time();
         $timee = time() + $moneythr->validity * 24 * 60 * 60;
         $coupon_id = $moneythr->id;
         if ($threshold <= $money) {
             if ($order_num == NULL) {
                 $order_num = $moneythr->order;
             }
             if ($order_num !== $moneythr->order) {
                 break;
             }
             $userinfo =& JFactory::getUser($userid);
             $username = $userinfo->username;
             $email = $userinfo->email;
             $coupon = RSCoupons::genRandomString();
             $cpn_ins = "insert into #__virtuemart_generatedcoupon set name='" . $coupon . "',\r\n\t\t\t\t\tawd_userid=" . $userid . ",\r\n\t\t\t\t\tawd_user='******',\r\n\t\t\t\t\tawd_amount=" . $moneythr->amount . ",\r\n\t\t\t\t\tcoupon_id='" . $coupon_id . "',\r\n\t\t\t\t\tamounttype=" . $moneythr->amounttype . ",\r\n\t\t\t\t\tvalid_from=" . $time . ", valid_till=" . $timee . ",\r\n\t\t\t\t\tremain_use=" . $moneythr->awarded . ",\r\n\t\t\t\t\tpublished=1,\r\n\t\t\t\t\tcoupontype=2, minamount=" . $moneythr->minamount . "";
             $db->setQuery($cpn_ins);
             $db->Query();
             JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_vmcoupons' . DS . 'tables');
             $query = "SELECT * FROM #__virtuemart_parameters LIMIT 1";
             $db->setQuery($query);
             $parameter = $db->loadObject();
             $ad_email = $parameter->ad_email;
             $currency = $parameter->currency;
             $emailsubject = $parameter->exceedthr_email_subject;
             $emailbody = $parameter->exceedthr_email_body;
             $clickatell_user = $parameter->clickatell_user;
             $clickatell_pass = $parameter->clickatell_pass;
             $clickatell_api_id = $parameter->clickatell_api_id;
             $clickatell_sender = $parameter->clickatell_sender;
             if ($moneythr->mailtocustomer == 1) {
                 RSCoupons::sendmailtouser($coupon, $moneythr->validity, $moneythr->amount, $moneythr->amounttype, $currency, $moneythr->awarded, $ad_email, $email, $username, $emailsubject, $emailbody);
             }
             if ($moneythr->mailtoadmin == 1) {
                 RSCoupons::sendmailtoadmin($coupon, $moneythr->validity, $moneythr->amount, $moneythr->amounttype, $currency, $moneythr->awarded, $ad_email, $emailsubject);
             }
             if ($moneythr->sendsms == 1) {
                 RSCoupons::sendthesms($coupon, $moneythr->validity, $moneythr->amounttype, $moneythr->amount, $userid, $clickatell_user, $clickatell_pass, $clickatell_api_id, $clickatell_sender, $currency);
             }
             break;
         }
     }
 }