function swapdetails($sid) { $sql = "SELECT vouchers.offer_id, swap.id as sid, swap.voucher_id, swap.offer_id, swap.user_id, swap.offering_start_date, swap.offering_end_date, vouchers.view_id, vouchers.price, vouchers.offer_price, vouchers.offer_percent, vouchers.from_date, vouchers.to_date, vouchers.is_used, vouchers.is_active, offers.title, offers.description, offers.image, offers.benefits, offers.merchant_id FROM vouchers , offers, swap WHERE vouchers.offer_id=offers.id and vouchers.id=swap.voucher_id and swap.id=:sid"; $offerId = ''; $offer_image = array(); $restaurant_details = array(); $cur_date = date('Y-m-d H:i:s'); $site_path = SITEURL; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("sid", $sid); $stmt->execute(); $vouchers = $stmt->fetchObject(); //$vouchers->offer_to_date = $offer_to_date; if (!empty($vouchers)) { $today = date('Y-m-d'); $checkdate = date('Y-m-d', strtotime($vouchers->offering_end_date)); if ($checkdate < $today) { $vouchers->Status = 'Expired'; } else { $vouchers->Status = ''; } $to_date = date('d M,Y', strtotime($vouchers->to_date)); //$offer_to_date = date('d M,Y', strtotime($vouchers->offer_to_date)); $vouchers->to_date = $to_date; if ($vouchers->offering_start_date == "0000-00-00 00:00:00") { $vouchers->swap_start_date = ''; } else { $vouchers->swap_start_date = date('m-d-Y', strtotime($vouchers->offering_start_date)); } if ($vouchers->offering_end_date == "0000-00-00 00:00:00") { $vouchers->swap_end_date = ''; $vouchers->swap_expire_date = ''; } else { $vouchers->swap_end_date = date('m-d-Y', strtotime($vouchers->offering_end_date)); $vouchers->swap_expire_date = date('M d,Y H:i:s', strtotime($vouchers->offering_end_date)); } if ($vouchers->offering_end_date >= $cur_date) { $vouchers->swap_expire_date_status = 1; } else { $vouchers->swap_expire_date_status = 0; } if (empty($vouchers->image)) { $image = $site_path . 'voucher_images/default.jpg'; $vouchers->image = $image; } else { // for($i=0;$i<$countrestaurant;$i++){ $image = $site_path . "voucher_images/" . $vouchers->image; $vouchers->image = $image; //$restaurant_details->image = $img; //} } $sql3 = "SELECT voucher_owner.to_user_id FROM voucher_owner WHERE voucher_owner.voucher_id=:vid and is_active=1"; $stmt3 = $db->prepare($sql3); $stmt3->bindParam("vid", $vid); $stmt3->execute(); $voucher_owner = $stmt3->fetchObject(); $sql4 = "SELECT * FROM voucher_resales WHERE voucher_id=:vid and user_id =:to_user_id and is_sold=0 "; $stmt4 = $db->prepare($sql4); $stmt4->bindParam("vid", $vid); $stmt4->bindParam("to_user_id", $voucher_owner->to_user_id); $stmt4->execute(); //$resales = $stmt->fetchObject(); $resale_count = $stmt4->rowCount(); $vouchers->resale = $resale_count; $marchantId = $vouchers->merchant_id; $offerId = $vouchers->offer_id; /*$sql1 = "SELECT * FROM offer_images WHERE offer_images.offer_id=:offerid"; $stmt1 = $db->prepare($sql1); $stmt1->bindParam("offerid", $offerId); $stmt1->execute(); $countvoucherimage = $stmt1->rowCount(); $offer_image = $stmt1->fetchAll(PDO::FETCH_OBJ); if(empty($offer_image)){ $img = $site_path.'voucher_images/default.jpg'; $offer_image[0]['image'] = $img; } else{ //for($i=0;$i<$countvoucherimage;$i++){ $img = $site_path."voucher_images/".$offer_image[$i]->image; $offer_image[$i]['image'] = $img; //} } */ //print_r($offer_image);exit; $sql2 = "SELECT restaurants.title, restaurants.logo, restaurants.address, restaurants.user_id FROM restaurants, offers WHERE offers.merchant_id = restaurants.user_id and offers.restaurant_id = restaurants.id and offers.id=:off_id and restaurants.user_id=:merchantid"; $stmt2 = $db->prepare($sql2); $stmt2->bindParam("off_id", $offerId); $stmt2->bindParam("merchantid", $marchantId); $stmt2->execute(); $countrestaurant = $stmt2->rowCount(); $restaurant_details = $stmt2->fetchObject(); //$offer_to_date = date('d M,Y', strtotime($restaurant_details->offer_to_date)); //$restaurant_details->offer_to_date = $offer_to_date; if (empty($restaurant_details->logo)) { $image = $site_path . 'restaurant_images/default.jpg'; //$restaurant_details->logo = $image; } else { // for($i=0;$i<$countrestaurant;$i++){ $img = $site_path . "restaurant_images/" . $restaurant_details->logo; $restaurant_details->logo = $img; //} } $unique_field = array(); $unique_field['offer_id'] = $offerId; $unique_field['is_active'] = 1; $soldCount = soldCount(json_encode($unique_field), 'vouchers'); //echo $soldCount;exit; $voucher_details = json_encode($vouchers); $restaurant_details = json_encode($restaurant_details); $offer_image = json_encode($offer_image); $voucher_owner = json_encode($voucher_owner); $db = null; $result = '{"type":"success","voucher_details":' . $voucher_details . ',"restaurant_details":' . $restaurant_details . ',"voucher_image":' . $offer_image . ',"voucher_owner":' . $voucher_owner . ',"total_sold":' . $soldCount . '}'; } else { if (empty($vouchers)) { $result = '{"type":"error","message":"No Voucher for swapping found"}'; } } } catch (PDOException $e) { $result = '{"error":{"message":' . $e->getMessage() . '}}'; } echo $result; }
function getOfferDetail($vid) { // $sql = "SELECT * FROM vouchers, offers, users where vouchers.offer_id = offers.id and vouchers.user_id = users.id and vouchers.id=:id"; $sql = "SELECT * FROM offers WHERE offers.id=:id"; $offerId = ''; $offer_image = array(); $restaurant_details = array(); $site_path = SITEURL; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("id", $vid); $stmt->execute(); $vouchers = $stmt->fetchObject(); $to_date = date('d M,Y', strtotime($vouchers->offer_to_date)); //$offer_to_date = date('d M,Y', strtotime($vouchers->offer_to_date)); $vouchers->expire_date = $to_date; //$vouchers->offer_to_date = $offer_to_date; if (!empty($vouchers)) { $marchantId = $vouchers->merchant_id; $offerId = $vouchers->id; $sql1 = "SELECT * FROM offer_images WHERE offer_images.offer_id=:offerid"; $stmt1 = $db->prepare($sql1); $stmt1->bindParam("offerid", $offerId); $stmt1->execute(); $countvoucherimage = $stmt1->rowCount(); $offerr_image = $stmt1->fetchAll(PDO::FETCH_OBJ); //print_r($offer_image); //exit; if (empty($offerr_image)) { $img = $site_path . 'voucher_images/default.jpg'; $offer_image[0]['image'] = $img; } else { for ($i = 0; $i < $countvoucherimage; $i++) { $img = $site_path . "voucher_images/" . $offerr_image[$i]->image; //echo $img; $offer_image[$i]['image'] = $img; } } //print_r($offer_image);exit; /*$sql2 = "SELECT restaurant_details.title, restaurant_details.logo, restaurant_details.address, restaurant_details.user_id FROM restaurant_details, offers WHERE offers.merchant_id = restaurant_details.user_id and offers.restaurant_id = restaurant_details.id and offers.id=:off_id and restaurant_details.user_id=:merchantid"; $stmt2 = $db->prepare($sql2); $stmt2->bindParam("off_id", $offerId); $stmt2->bindParam("merchantid", $marchantId); $stmt2->execute(); $countrestaurant = $stmt2->rowCount(); $restaurant_details = $stmt2->fetchObject(); //$offer_to_date = date('d M,Y', strtotime($restaurant_details->offer_to_date)); //$restaurant_details->offer_to_date = $offer_to_date; if(empty($restaurant_details)){ $image = $site_path.'restaurant_images/default.jpg'; $restaurant_details->logo = $image; } else{ // for($i=0;$i<$countrestaurant;$i++){ $img = $site_path."restaurant_images/".$restaurant_details->logo; $restaurant_details->logo = $img; //} }*/ $unique_field = array(); $unique_field['offer_id'] = $offerId; $unique_field['is_active'] = 1; $soldCount = soldCount(json_encode($unique_field), 'vouchers'); //echo $soldCount;exit; $voucher_details = json_encode($vouchers); //$restaurant_details = json_encode($restaurant_details); $offer_image = json_encode($offer_image); $db = null; $result = '{"type":"success","offer_details":' . $voucher_details . ',"offer_image":' . $offer_image . ',"total_sold":' . $soldCount . '}'; } else { if (empty($vouchers)) { $result = '{"type":"error","message":"Not found Offer Id"}'; } } } catch (PDOException $e) { $result = '{"error":{"message":' . $e->getMessage() . '}}'; } echo $result; }