Execute("select * from " . TABLE_COUPONS . " where coupon_code = '" . zen_db_input($_POST['lookup_discount_coupon']) . "' and coupon_type != 'G'"); $_POST['lookup_discount_coupon'] = zen_sanitize_string($_POST['lookup_discount_coupon']); if ($coupon->RecordCount() < 1) { // invalid discount coupon code $text_coupon_help = sprintf(TEXT_COUPON_FAILED, zen_output_string_protected($_POST['lookup_discount_coupon'])); } else { // valid discount coupon code $lookup_coupon_id = $coupon->fields['coupon_id']; $coupon_desc = $db->Execute("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . (int)$lookup_coupon_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'"); $text_coupon_help = TEXT_COUPON_HELP_HEADER; $text_coupon_help .= sprintf(TEXT_COUPON_HELP_NAME, $coupon_desc->fields['coupon_name']); if (zen_not_null($coupon_desc->fields['coupon_description'])) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DESC, $coupon_desc->fields['coupon_description']); $coupon_amount = $coupon->fields['coupon_amount']; switch ($coupon->fields['coupon_type']) { case 'F': $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, $currencies->format($coupon->fields['coupon_amount'])); break; case 'P': $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, number_format($coupon->fields['coupon_amount'],2). '%'); break; case 'S': $text_coupon_help .= TEXT_COUPON_HELP_FREESHIP; break; default: } if ($coupon->fields['coupon_minimum_order'] > 0 ) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_MINORDER, $currencies->format($coupon->fields['coupon_minimum_order'])); $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DATE, zen_date_short($coupon->fields['coupon_start_date']),zen_date_short($coupon->fields['coupon_expire_date'])); $text_coupon_help .= TEXT_COUPON_HELP_RESTRICT; if ($coupon->fields['coupon_zone_restriction'] > 0) { $text_coupon_help .= TEXT_COUPON_GV_RESTRICTION_ZONES; } $text_coupon_help .= TEXT_COUPON_HELP_CATEGORIES; $get_result=$db->Execute("select * from " . TABLE_COUPON_RESTRICT . " where coupon_id='" . (int)$lookup_coupon_id . "' and category_id !='0'"); $cats = array(); $skip_cat_restriction = true; while (!$get_result->EOF) { if ($get_result->fields['coupon_restrict'] == 'N') { $restrict = TEXT_CAT_ALLOWED; } else { $restrict = TEXT_CAT_DENIED; } if ($get_result->RecordCount() != 1 and $get_result->fields['category_id'] != '-1') { $result = $db->Execute("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' and c.categories_id='" . $get_result->fields['category_id'] . "'"); $cats[] = array("validity"=> ($get_result->fields['coupon_restrict'] =='N' ? 'A' : 'D'), 'name'=> $result->fields["categories_name"], 'link'=>'' . $result->fields["categories_name"] . '' . $restrict); } $get_result->MoveNext(); } if ($skip_cat_restriction == false || sizeof($cats) == 0) $cats[] = array("link" => TEXT_NO_CAT_RESTRICTIONS); sort($cats); $mycats = array(); foreach($cats as $key=>$value) { $mycats[] = $value["link"]; } $cats = '