public function Action() { $return = ""; if (!empty($_POST['master_coupon'])) { $db = JFactory::getDBO(); $cph = new CouponHandler(); $cph->load($_POST['master_coupon']); if (is_object($cph->coupon)) { for ($i = 0; $i < $_POST['amount']; $i++) { $newcode = $cph->coupon->generateCouponCode(); $newcodes[] = $newcode; $cph->coupon->id = 0; $cph->coupon->coupon_code = $newcode; $cph->coupon->active = 1; $cph->restrictions['usecount'] = 0; if (!empty($_POST['create_new_coupons'])) { $cph->restrictions['max_reuse'] = $_POST['max_reuse']; } else { $cph->restrictions['max_reuse'] = 1; } $cph->coupon->storeload(); if (!empty($_POST['switch_type'])) { $cph->switchType(); } } } $return .= '<table class="adminlist">'; foreach ($newcodes as $code) { $return .= '<tr>'; $return .= '<td>' . $code . '</td>'; $return .= '</tr>'; } $return .= '</table><br /><br />'; } return $return; }
public function action($request) { $db = JFactory::getDBO(); $userflags = $request->metaUser->focusSubscription->getMIflags($request->plan->id, $this->id); $total_coupons = array(); $existing_coupons = array(); if (is_array($userflags)) { if (!empty($userflags['coupons'])) { $existing_coupons = explode(',', $userflags['coupons']); $total_coupons = array_merge($total_coupons, $existing_coupons); if (!empty($this->settings['inc_old_coupons'])) { foreach ($existing_coupons as $cid) { $ocph = new couponHandler(); $ocph->load($cid); $ocph->coupon->active = 1; $ocph->restrictions['max_reuse'] += $this->settings['inc_old_coupons']; $ocph->coupon->setParams($ocph->restrictions, 'restrictions'); $ocph->coupon->check(); $ocph->coupon->store(); } } } } $newcodes = array(); if (!empty($existing_coupons) && !empty($this->settings['always_new_coupons']) || empty($existing_coupons)) { if (!empty($this->settings['create_new_coupons']) && !empty($this->settings['master_coupon'])) { $cph = new CouponHandler(); $cph->load($this->settings['master_coupon']); if (is_object($cph->coupon)) { for ($i = 0; $i < $this->settings['create_new_coupons']; $i++) { $newcode = $cph->coupon->generateCouponCode(); $newcodes[] = $newcode; $cph->coupon->id = 0; $cph->coupon->coupon_code = $newcode; $cph->coupon->active = 1; $cph->restrictions['usecount'] = 0; if (!empty($this->settings['max_reuse'])) { $cph->restrictions['max_reuse'] = $this->settings['max_reuse']; } else { $cph->restrictions['max_reuse'] = 1; } if (!empty($this->settings['bind_subscription'])) { $cph->restrictions['depend_on_subscr_id'] = 1; $cph->restrictions['subscr_id_dependency'] = $request->metaUser->focusSubscription->id; } $cph->coupon->storeload(); if (!empty($this->settings['switch_type'])) { $cph->switchType(); } } if (!empty($this->settings['mail_out_coupons'])) { $this->mailOut($request, $newcodes); } } } } $total_coupons = array_merge($total_coupons, $newcodes); $newflags['coupons'] = implode(',', $total_coupons); $request->metaUser->focusSubscription->setMIflags($request->plan->id, $this->id, $newflags); return true; }