Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*The business.php contains the business class and methods
- * which will simplify the operations that are
- * associated with business.
- *
- * definelabs.com
- *
- */
- require_once (APP_ROOT."include/session.php");
- require_once (APP_ROOT."include/category.php");
- require_once (APP_ROOT."push/pushAPI.php");
- require_once (APP_ROOT."time.php");
- require_once (APP_ROOT."timezone.php");
- class Business {
- public $info = array();
- public $totaldeals;
- public $deals = array();
- public $id;
- public $timezoneoffset;
- function __Construct() {
- global $session, $database, $form;
- $q = sprintf("SELECT * FROM business WHERE userid= '%s'", mysql_real_escape_string($session -> userid));
- $result = $database -> query($q) or die(mysql_error());
- $info = mysql_fetch_assoc($result);
- $this -> info = $info;
- $this -> id = $info['businessid'];
- $timezone = $info['timezone'];
- if (isset($timezone) && strlen($timezone) !== 0) {
- $this -> timezoneoffset = getTimeZoneOffset($timezone);
- } else {
- $this -> timezoneoffset = "36000";
- }
- }
- //function to add new business if the advertiser have not added any.
- function addNewBusiness($bname, $street, $suburb, $city, $state, $zipcode, $desc, $lattitude, $longitude, $website, $phone, $timezone, $catid, $selectedcategory) {
- global $session, $form, $database;
- //Validation for business name
- $field = "bname";
- if (!$bname || strlen($bname = trim($bname)) == 0) {
- $form -> setError($field, " * Business name is required");
- }
- $field = "suburb";
- if (!($suburb) || strlen($suburb = trim($suburb)) == 0) {
- $form -> setError($field, "* Suburb is not mentioned");
- }
- $field = "street";
- if (!$street || strlen($street = trim($street)) == 0) {
- $form -> setError($field, "* Street is not mentioned");
- }
- //validation for city
- $field = "city";
- if (!$city || strlen($city = trim($city)) == 0) {
- $form -> setError($field, "* city is not mentioned");
- }
- //validation for state
- $field = "state";
- if (!$state || strlen($state = trim($state)) == 0) {
- $form -> setError($field, "* state is not mentioned");
- }
- //validation for postal code
- $field = "zipcode";
- if (!$zipcode || strlen($zipcode = trim($zipcode)) == 0) {
- $form -> setError($field, "* Please enter correct zipcode");
- }
- if (strlen($zipcode = trim($zipcode)) !== 4) {
- $form -> setError($field, "* Please enter correct zipcode");
- } else if (!preg_match("/^[0-9]+$/", $zipcode)) {
- $form -> setError($field, "* Zip code can only be Numbers");
- }
- //validation for lattitude
- $field = "lattitude";
- if (!$lattitude || strlen($lattitude = trim($lattitude)) == 0) {
- $form -> setError($field, "* Please enter Latitude");
- } else if (!preg_match("/^[\-0-9]+[\.][0-9]+$/", $lattitude)) {
- $form -> setError($field, "* Please enter correct lattitude");
- }
- $field = "phone";
- if (!$phone || strlen($phone = trim($phone)) == 0) {
- $form -> setError($field, "* Please enter your business phone number");
- }
- else if (!preg_match("/^[0-9a-z A-Z _ \- \+ \( \)]+$/", $phone)) {
- $form -> setError($field, "* Please enter valid phone number.");
- }
- //validation for longitude
- $field = "longitude";
- if (!$longitude || strlen($longitude = trim($longitude)) == 0) {
- $form -> setError($field, "* Please enter Longitude");
- } else if (!preg_match("/^[\-0-9]+[\.][0-9]+$/", $longitude)) {
- $form -> setError($field, "* Please enter correct Longitude");
- }
- //validation for website
- $field = "website";
- if (!$website || strlen($website = trim($website)) == 0) {
- $form -> setError($field, "* Please enter your business website");
- }
- if (!isValidURL($website)) {
- $form -> setError($field, "* Website is invalid!");
- }
- $field = "category";
- if (!$catid || strlen($catid = trim($catid)) == 0) {
- $form -> setError($field, "* Select a deal category" . $catid);
- }
- //Validation for the business description... So users can get a little idea about the business.
- $field = "description";
- if (!$desc || strlen($desc = trim($desc)) == 0) {
- $form -> setError($field, "* You have to tell people a little bit about your business");
- }
- if ($form -> num_errors > 0) {
- return 2;
- }
- // $userid=$session->userid;
- $connection = $database -> connection;
- //business id generation.
- $businessid = $session -> generateRandID();
- unset($_SESSION['business']);
- $_SESSION['business'] = array("businessid" => $businessid, "name" => $bname, "street" => $street, "suburb" => $suburb, "city" => $city, "state" => $state, "zipcode" => $zipcode, "description" => $desc, "latitude" => $lattitude, "longitude" => $longitude, "website" => $website, "phone" => $phone, "timezone" => $timezone, "catid" => $catid, "selectedcategory" => $selectedcategory);
- return $businessid;
- }
- //This function will add new deal for an advertiser.
- function addNewDeal($dealname, $dealtime, $expirytime, $about, $sendto) {
- global $session, $form, $database, $mailer;
- //validation for deal name
- $field = "dealname";
- if (!$dealname || strlen($dealname = trim($dealname)) == 0) {
- $form -> setError($field, " * Deal name is not entered");
- }
- // else{
- // $field="dealname";
- // if(!preg_match("/^([0-9 a-z A-Z % \.\$])+$/", $dealname)){
- // $form->setError($field, "* Deal name can only be alphanumeric");
- // }
- // }
- //
- //validation for deal's date
- // $field = "dealdate";
- // if(!$dealdate || strlen($dealdate = trim($dealdate)) == 0 ){
- // $form->setError($field, " * Deal date is required");
- // }
- // else{
- // $field="dealdate";
- // if(!preg_match("/^([0-9\-\/])+$/", $dealdate)){
- // $form->setError($field, "* Deal date can only be Numbers");
- // }
- // }
- // //validation for deal's time
- // $field = "dealtime";
- // if(!$dealtime || strlen($dealtime = trim($dealtime)) == 0 ){
- // $form->setError($field, " * Deal time is required");
- // }
- // else{
- // $field="dealtime";
- // if(!preg_match("/^([0-9:])+$/", $dealtime)){
- // $form->setError($field, "* Deal time can only be Numbers");
- // }
- // }
- //
- // //validation for expiry date
- // $field="expirydate";
- // if(!preg_match("/^([0-9\-\/])+$/", $expirydate)){
- // $form->setError($field, "* Expiry date can only be Numbers");
- // }
- //
- // //validation for expiry time
- // $field = "expirytime";
- // if(!$expirytime || strlen($expirytime = trim($expirytime)) == 0 ){
- // $form->setError($field, " * Expiry time is required");
- // }
- // else{
- // $field="exprirytime";
- // if(!preg_match("/^([0-9:])+$/", $expirytime)){
- // $form->setError($field, "* Expiry time can only be Numbers");
- // }
- // }
- //validation for the deal description
- $field = "about";
- if (!$about || strlen($about = trim($about)) == 0) {
- $form -> setError($field, " * Deal Description is required");
- }
- // else{
- // $field="about";
- // if(!preg_match("/^([a-z A-Z 0-9 \% \.])+$/", $about)){
- // $form->setError($field, "* Deal description can only be Numbers and letters");
- // }
- // }
- //
- $field = "submittedcat";
- //$dealid = $session->generateRandID();
- $businessid = $this -> info['businessid'];
- error_log("business id ".$businessid);
- if ($form -> num_errors > 0) {
- return 2;
- }
- // Convert deal name to uppercse
- $dealname = strtoupper($dealname);
- if ($database -> addNewDeal($businessid, $about, $dealtime, $expirytime, $dealname, $sendto)) {
- $dealid = mysql_insert_id();
- //automaticaly send push if deal is created
- $info = $this -> getBusinessInfo($businessid);
- $dealOwnerUserId=$info['userid'];
- error_log("asurabh".$dealOwnerUserId);
- error_log($dealtime);
- $userinfo = getUserInfoById($dealOwnerUserId);
- //$mail=$mailer->sendApproveDeal($userinfo['email'], $info['bname'],$_POST['dealname'],$userinfo['firstname']);
- $resultPush = pushBusiness($businessid, $dealname, $dealid, $dealtime, $sendto);
- return $dealid;
- } else {
- return 1;
- }
- }
- function addNewDealSales($dealname, $dealtime, $expirytime, $about,$businessid) {
- global $session, $form, $database,$mailer;
- //validation for deal name
- $field = "dealname";
- if (!$dealname || strlen($dealname = trim($dealname)) == 0) {
- $form -> setError($field, " * Deal name is not entered");
- }
- // else{
- // $field="dealname";
- // if(!preg_match("/^([0-9 a-z A-Z % \.\$])+$/", $dealname)){
- // $form->setError($field, "* Deal name can only be alphanumeric");
- // }
- // }
- //
- //validation for deal's date
- // $field = "dealdate";
- // if(!$dealdate || strlen($dealdate = trim($dealdate)) == 0 ){
- // $form->setError($field, " * Deal date is required");
- // }
- // else{
- // $field="dealdate";
- // if(!preg_match("/^([0-9\-\/])+$/", $dealdate)){
- // $form->setError($field, "* Deal date can only be Numbers");
- // }
- // }
- // //validation for deal's time
- // $field = "dealtime";
- // if(!$dealtime || strlen($dealtime = trim($dealtime)) == 0 ){
- // $form->setError($field, " * Deal time is required");
- // }
- // else{
- // $field="dealtime";
- // if(!preg_match("/^([0-9:])+$/", $dealtime)){
- // $form->setError($field, "* Deal time can only be Numbers");
- // }
- // }
- //
- // //validation for expiry date
- // $field="expirydate";
- // if(!preg_match("/^([0-9\-\/])+$/", $expirydate)){
- // $form->setError($field, "* Expiry date can only be Numbers");
- // }
- //
- // //validation for expiry time
- // $field = "expirytime";
- // if(!$expirytime || strlen($expirytime = trim($expirytime)) == 0 ){
- // $form->setError($field, " * Expiry time is required");
- // }
- // else{
- // $field="exprirytime";
- // if(!preg_match("/^([0-9:])+$/", $expirytime)){
- // $form->setError($field, "* Expiry time can only be Numbers");
- // }
- // }
- //validation for the deal description
- $field = "about";
- if (!$about || strlen($about = trim($about)) == 0) {
- $form -> setError($field, " * Deal Description is required");
- }
- // else{
- // $field="about";
- // if(!preg_match("/^([a-z A-Z 0-9 \% \.])+$/", $about)){
- // $form->setError($field, "* Deal description can only be Numbers and letters");
- // }
- // }
- //
- $field = "submittedcat";
- //$dealid = $session->generateRandID();
- if ($form -> num_errors > 0) {
- return 2;
- }
- // Convert deal name to uppercse
- $dealname = strtoupper($dealname);
- if ($database -> addNewDeal($businessid, $about, $dealtime, $expirytime, $dealname)) {
- $dealid = mysql_insert_id();
- //if created by moderator or admin
- if($session->userlevel == 9 || $session->userlevel == 7 ){
- $businessinfo = getBusinessDetail($businessid);
- $dealOwnerUserId = $businessinfo['userid'];
- error_log("asurabh".$dealOwnerUserId);
- error_log($dealtime);
- $userinfo = getUserInfoById($dealOwnerUserId);
- //$mail=$mailer->sendApproveDeal($userinfo['email'], $businessinfo['bname'],$dealname,$userinfo['firstname']);
- $resultPush = pushBusiness($businessid, $dealname, $dealid, $dealtime);
- //error_log($resultPush);
- }
- return $dealid;
- } else {
- return 1;
- }
- }
- // function addNewCat will add a new Category whenever applicable
- function addNewCat($newcategory) {
- global $database;
- $q = sprintf("insert into category values('','%s')", mysql_real_escape_string($newcategory));
- return $database -> query($q) or die(mysql_error());
- }
- function addCat($dealid, $catid) {
- global $database;
- $q = sprintf("insert into dealcat values('%s','$catid')", mysql_real_escape_string($dealid));
- return $database -> query($q) or die(mysql_error());
- }
- function updateCat($dealid, $catid, $oldcatid) {
- global $database;
- $q = sprintf("update dealcat set dealcat.catid = '%s' where dealid = '%s')", mysql_real_escape_string($catid), mysql_real_escape_string($dealid));
- $database -> query($q) or die(mysql_error());
- $q = sprintf("update catsubcat set catsubcat.catid='%s' where catid='%s'", mysql_real_escape_string($catid), mysql_real_escape_string($oldcatid));
- $database -> query($q) or die(mysql_error());
- }
- function addNewSubCat($newsubcategory) {
- global $database;
- $q = sprintf("insert into subcategory values('','%s')", mysql_real_escape_string($newsubcategory));
- return $database -> query($q) or die(mysql_error());
- }
- function addSubCat($catid, $subcatid, $dealid) {
- global $database;
- $q = sprintf("insert into catsubcat values('%s','%s')", mysql_real_escape_string($catid), mysql_real_escape_string($subcatid));
- $database -> query($q) or die(mysql_error());
- $q = sprintf("insert into dealsubcat values('%s','$subcatid')", mysql_real_escape_string($dealid));
- $database -> query($q) or die(mysql_error());
- }
- function updateSubCat($catid, $subcatid, $dealid, $oldsubcatid) {
- global $database;
- $q = sprintf("update catsubcat set catsubcat.subcatid='%s' where subcatid='%s'", mysql_real_escape_string($subcatid), mysql_real_escape_string($oldsubcatid));
- $database -> query($q) or die(mysql_error());
- $q = sprintf("update dealsubcat set dealsubcat.subcatid ='%s' where dealid='%s'", mysql_real_escape_string($subcatid), mysql_real_escape_string($dealid));
- $database -> query($q) or die(mysql_error());
- }
- function getCatId($category) {
- global $database;
- $q = sprintf("select catid from category where categoryName = '%s'", mysql_real_escape_string($category));
- $array = $database -> query($q);
- $result = mysql_fetch_array($array);
- $catid = $result['catid'];
- return $catid;
- }
- function getSubCatId($subcategory) {
- global $database;
- $q = sprintf("select subcatid from subcategory where subcat = '%s'", mysql_real_escape_string($subcategory));
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array);
- $subcatid = $result['subcatid'];
- return $subcatid;
- }
- function getCat($catid) {
- global $database;
- $q = sprintf("select * from category where catid = '%d'", $catid);
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_assoc($array);
- $cat = $result['categoryName'];
- return $cat;
- }
- function getSubCat($subcatid) {
- global $database;
- $q = sprintf("select subcat from subcategory where subcatid = '%s'", mysql_real_escape_string($subcatid));
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array);
- $subcat = $result['subcat'];
- return $subcat;
- }
- function getDealInfo($dealid) {
- global $database;
- $q = sprintf("SELECT deals.*, business.*
- FROM deals LEFT JOIN business ON deals.businessid = business.businessid
- WHERE dealid = '%d'", $dealid);
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_assoc($array);
- $result['dealname'] = stripslashes($result['dealname']);
- $result['desc'] = stripslashes($result['desc']);
- return $result;
- }
- //To obtain a businessid from a corresponding deal.
- function getBusinessId($dealid) {
- global $database;
- $q = sprintf("select businessid from deals where dealid = '%s'", mysql_real_escape_string($dealid));
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array);
- return $result['businessid'];
- }
- //This function is required for the iphone app. when the iphone app wants to get deal info. It will get the business info by quering the
- //the business table using the businessid
- //from the deals table.
- function getBusinessInfo($businessid) {
- global $database;
- $q = sprintf("select * from business LEFT JOIN business_timing ON business.businessid = business_timing.business_id where business.businessid= '%d'", mysql_real_escape_string($businessid));
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array, MYSQL_ASSOC);
- return $result;
- }
- function updateDeal($dealname, $desc, $dealtime, $expirytime, $dealoffer, $dealid) {
- global $database;
- $q = sprintf("UPDATE deals SET deals.dealname='%s', deals.desc='%s', deals.dealtimestamp='%s',deals.expirytimestamp='%s',
- deals.dealoffer='$dealoffer' WHERE deals.dealid='%s'", mysql_real_escape_string($dealname), mysql_real_escape_string($desc), mysql_real_escape_string($dealtime), mysql_real_escape_string($expirytime), mysql_real_escape_string($dealid));
- $result = $database -> query($q) or die(mysql_error());
- return $result;
- }
- function addNewProduct($productname, $productprice, $productdetail) {
- global $database;
- $q = sprintf("INSERT into PRODUCTS VALUES('','%s','%s','$productprice')", mysql_real_escape_string($productname), mysql_real_escape_string($productdetail));
- $result = $database -> query($q) or die(mysql_error());
- return $result;
- }
- function isSubscribed() {
- global $database;
- $q = sprintf("select * from subscription where businessid = '%s'", mysql_real_escape_string($this -> id));
- $array = $database -> query($q) or die(mysql_error());
- if (mysql_num_rows($array) < 1) {
- return false;
- } else {
- $data = mysql_fetch_assoc($array);
- $rebillID = $data['rebill_customer_id'];
- return $rebillID;
- }
- }
- function getProductInfo($productid) {
- global $database;
- $q = "select * from products where product_id='$productid'";
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array);
- return $result;
- }
- function getDealImage($dealid) {
- global $database;
- $q = sprintf("select * from dealimage where dealid = '%s'", mysql_real_escape_string($dealid));
- $result = $database -> query($q) or die(mysql_error);
- if (mysql_num_rows($result) < 1) {
- $location = "../images/deals/default.png";
- return $location;
- } else {
- $name = mysql_fetch_array($result);
- $location = $name['directory'] . $name['imagename'];
- return $location;
- }
- }
- function getBusinessImage($businessid) {
- global $database;
- $q = sprintf("select * from businessimage where businessid = '%s'", mysql_real_escape_string($businessid));
- $result = $database -> query($q) or die(mysql_error);
- if (mysql_num_rows($result) < 1) {
- $location = "../images/business/default.jpg";
- return $location;
- } else {
- $name = mysql_fetch_array($result);
- $location = $name['directory'].$name['imagename'];
- return $location;
- }
- }
- /*-----To get all info regarding the saved business------*/
- function isRevision($dealid, $token, $userid) {
- global $database;
- $q = sprintf("SELECT * from pushed WHERE dealid = '%d' and device_token = '%s' and userid='%s'", $dealid, mysql_real_escape_string($token), mysql_real_escape_string($userid));
- $result = mysql_num_rows($database -> query($q));
- if ($result > 0) {
- return true;
- } else {
- return false;
- }
- }
- function getSavedBusiness($userid) {
- global $database;
- $q = sprintf("SELECT savedbusiness.*, business.*, businessimage.directory, businessimage.imagename FROM
- (savedbusiness LEFT JOIN business ON savedbusiness.businessid = business.businessid) LEFT JOIN businessimage
- ON savedbusiness.businessid = businessimage.businessid WHERE savedbusiness.userid = '%s'", mysql_real_escape_string($userid));
- $result = $database -> query($q) or die(mysql_error());
- while ($info = mysql_fetch_assoc($result)) {
- $infoFinal[] = $info;
- }
- return $infoFinal;
- }
- //---Return all the catids of the saved categories as well as the sibling categories of the category---//
- function getSavedCategories($userid) {
- global $database;
- $q = sprintf("SELECT * from user_category WHERE userid = '%s'", mysql_real_escape_string($userid));
- $result = $database -> query($q) or die(mysql_error());
- $catIds = array();
- $ids = array();
- $id = array();
- while ($info = mysql_fetch_assoc($result)) {
- $catIds[] = $info['catid'];
- }
- if (!empty($catIds)) {
- foreach ($catIds as $catid) {
- $ids[] = getTree($catid);
- }
- } else {
- $ids[] = getTree(0);
- }
- foreach ($ids as $array) {
- foreach ($array as $key => $value) {
- $id[] = $value;
- }
- }
- $filtArray = array_unique($id);
- return $filtArray;
- //Returned the unique array of catids.
- }
- function getDealsOfSavedCategories($catids, $token, $userid) {
- echo "In getDealsOfSavedCategories Function<br />";
- global $database, $dealids;
- foreach ($catids as $catid) {
- $query = "SELECT businessid FROM business WHERE catid = '$catid'";
- $resultid = $database -> query($query) or die(mysql_error());
- while ($ids = mysql_fetch_assoc($resultid)) {
- $businessids[] = $ids['businessid'];
- }
- }
- foreach ($businessids as $businessid) {
- $time = gmdate("Y-m-d H:i:s");
- $q = sprintf("SELECT dealid FROM deals WHERE businessid = '%s' AND deals.expirytimestamp >= '$time' AND UTC_TIMESTAMP() >= deals.dealtimestamp AND deals.status='1' ", mysql_real_escape_string($businessid));
- $result = $database -> query($q);
- while ($ids2 = mysql_fetch_assoc($result)) {
- var_dump($ids2);
- if (!$this -> isRevision($ids2['dealid'], $token, $userid)) {
- $dealids[] = $ids2['dealid'];
- }
- }
- }
- return $dealids;
- }
- function getDealsUnderRadius($dealids, $userLat, $userLong) {
- echo "<br /> In Radius Function<br />";
- global $database;
- foreach ($dealids as $dealid) {
- $q = sprintf("SELECT deals.businessid, business.lattitude, business.longitude, business.radius FROM
- deals LEFT JOIN business ON deals.businessid = business.businessid WHERE deals.dealid = '%d'", $dealid);
- $result = $database -> query($q) or die(mysql_error());
- $info = mysql_fetch_assoc($result);
- $lat = $info['lattitude'];
- $long = $info['longitude'];
- $radius = $info['radius'];
- $distance = getDistanceBetweenPoints($userLat, $userLong, $lat, $long, $unit = 'Km');
- if ($distance <= $radius) {
- if ($distance < 1) {
- $distance = $distance * 1000;
- $distance = $distance . " m";
- } else {
- $distance = $distance . " Km";
- }
- $pushdealIds[] = array("dealid" => $dealid, "distance" => $distance);
- }
- }
- return $pushdealIds;
- }
- function getDealsBySavedCategory($userid, $userLat, $userLong, $token) {
- echo "<br /> In getDealsBySavedCategory Function<br />";
- global $database;
- $catids = $this -> getSavedCategories($userid);
- if (count($catids) != 0) {
- $dealids = $this->getDealsOfSavedCategories($catids, $token, $userid);
- }
- if (count($dealids) > 0) {
- $deals = $this->getDealsUnderRadius($dealids, $userLat, $userLong);
- }
- return $deals;
- }
- function getDealsUpdatePush($userid, $userLat, $userLong, $token) {
- global $database;
- $catids = $this -> getSavedCategories($userid);
- if (count($catids) != 0) {
- $dealids = $this -> getDealsOfSavedCategories($catids, $token);
- }
- return $dealids;
- }
- /*Function to check if the user has and active deal.
- * If so find out the time when the deal ends and notify the user
- * */
- function checkActiveDeal() {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' ORDER BY dealid DESC limit 1", mysql_real_escape_string($this -> id));
- $status = checkBusiness($session -> userid);
- //$data = $database -> query($q) or die(mysql_error());
- // $deal = mysql_fetch_assoc($data);
- // $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- // $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- // $usernow = gmdate("Y-m-d H:i:s");
- // $usernow = getRealTime($usernow, $business -> timezoneoffset);
- // $deal_midnight = strtotime($nextday_time);
- // $difference = $deal_midnight - $usernow;
- // if ($difference <= 0 && $status == 0) {
- // return false;
- // } else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- }
- // else {
- // $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- // $endDate = date("l F d, Y h:i:s A", $end_time);
- // return "You have {$status} deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- // <p> Your new deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- // }
- // }
- }
- function checkActiveDeal_location() {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' AND sendto='location' ORDER BY dealid DESC limit 1", mysql_real_escape_string($this -> id));
- $status = checkBusiness($session -> userid);
- $data = $database -> query($q) or die(mysql_error());
- $deal = mysql_fetch_assoc($data);
- $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- $usernow = gmdate("Y-m-d H:i:s");
- $usernow = getRealTime($usernow, $business -> timezoneoffset);
- $deal_midnight = strtotime($nextday_time);
- $difference = $deal_midnight - $usernow;
- if ($difference <= 0 && $status == 0) {
- return false;
- } else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- } else {
- $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- $endDate = date("l F d, Y h:i:s A", $end_time);
- return "You have {$status} 'location' deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- <p> Your new deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- }
- }
- }
- function checkActiveDeal_all() {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' AND sendto='all' ORDER BY dealid DESC limit 1", mysql_real_escape_string($this -> id));
- $status = checkBusiness($session -> userid);
- $data = $database -> query($q) or die(mysql_error());
- $deal = mysql_fetch_assoc($data);
- $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- $usernow = gmdate("Y-m-d H:i:s");
- $usernow = getRealTime($usernow, $business -> timezoneoffset);
- $deal_midnight = strtotime($nextday_time);
- $difference = $deal_midnight - $usernow;
- if ($difference <= 0 && $status == 0) {
- return false;
- } else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- } else {
- $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- $endDate = date("l F d, Y h:i:s A", $end_time);
- return "You have {$status} 'all' deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- <p> Your new deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- }
- }
- }
- function checkActiveDealSales($businessid)
- {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' ORDER BY dealid DESC limit 1", $businessid);
- $status = checkBusinessSales($businessid);
- $data = $database -> query($q) or die(mysql_error());
- $deal = mysql_fetch_assoc($data);
- $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- $usernow = gmdate("Y-m-d H:i:s");
- $usernow = getRealTime($usernow, $business -> timezoneoffset);
- $deal_midnight = strtotime($nextday_time);
- $difference = $deal_midnight - $usernow;
- if ($difference <= 0 && $status == 0) {
- return false;
- }
- else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- } //else {
- // $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- // $endDate = date("l F d, Y h:i:s A", $end_time);
- // return "Business has {$status} deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- // <p> New business deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- // }
- }
- }
- function checkActiveDealSales_all($businessid)
- {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' and sendto='all' ORDER BY dealid DESC limit 1", $businessid);
- $status = checkBusinessSales($businessid);
- $data = $database -> query($q) or die(mysql_error());
- $deal = mysql_fetch_assoc($data);
- $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- $usernow = gmdate("Y-m-d H:i:s");
- $usernow = getRealTime($usernow, $business -> timezoneoffset);
- $deal_midnight = strtotime($nextday_time);
- $difference = $deal_midnight - $usernow;
- if ($difference <= 0 && $status == 0) {
- return false;
- }
- else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- } else {
- $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- $endDate = date("l F d, Y h:i:s A", $end_time);
- return "Business has {$status} 'all' deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- <p> New business deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- }
- }
- }
- function checkActiveDealSales_location($businessid)
- {
- global $database, $session, $business;
- $q = sprintf("SELECT dealname, dealtimestamp, status, expirytimestamp FROM deals WHERE businessid = '%s' and sendto='all' ORDER BY dealid DESC limit 1", $businessid);
- $status = checkBusinessSales($businessid);
- $data = $database -> query($q) or die(mysql_error());
- $deal = mysql_fetch_assoc($data);
- $end_time = getRealTime($deal['expirytimestamp'], $business -> timezoneoffset);
- $nextday_time = date("l F d, Y h:i:s A", mktime(0, 0, 0, date("m", $end_time), date("d", $end_time) + 1, date("Y", $end_time)));
- $usernow = gmdate("Y-m-d H:i:s");
- $usernow = getRealTime($usernow, $business -> timezoneoffset);
- $deal_midnight = strtotime($nextday_time);
- $difference = $deal_midnight - $usernow;
- if ($difference <= 0 && $status == 0) {
- return false;
- }
- else {
- if ($status == 2) {
- if($session->userlevel==9)
- {
- $status=0;
- }else
- {
- return "<h1>You don't appear to have any registered business.</h1>";
- }
- } elseif ($status == 1) {
- return "<h1>Your business is not approved yet. Check back soon.</h1>";
- } elseif ($status == 3) {
- return "<h1>Your business has been banned. Please contact administrator.</h1>";
- } else {
- $status = $deal['status'] == 0 ? "a Pending " : "an Active ";
- $endDate = date("l F d, Y h:i:s A", $end_time);
- return "Business has {$status} 'location' deal called <b><i>" . $deal['dealname'] . "</i></b> which ends on " . $endDate . " (Business's local time)<br /> You can add a new deal from " . $nextday_time . "
- <p> New business deal is " . $hours = round($difference / 3600) . " hours " . date("i", $difference) . " minutes " . date("s", $difference) . " seconds away </p>";
- }
- }
- }
- };
- $business = new Business;
- //------FUNCTION TO CHECK STATUS OF A BUSINESS---------//
- function checkBusiness($userid) {
- global $database;
- $q = sprintf("SELECT status from business WHERE userid = '%s'", mysql_real_escape_string($userid));
- $result = $database -> query($q) or die(mysql_error());
- $numrow = mysql_num_rows($result);
- if ($numrow < 1) {
- return 2;
- //Business has not been created.
- }
- $status = mysql_fetch_assoc($result);
- if ($status['status'] == 0) {
- return 1;
- //Business has been created but not approved by admin
- } elseif ($status['status'] == 1) {
- return 0;
- //Business has been created and approve.
- } elseif ($status['status'] == 2) {
- return 3;
- //Business has been banned.
- }
- }
- function checkBusinessSales($businessid) {
- global $database;
- $q = sprintf("SELECT status from business WHERE businessid = '%s'",$businessid);
- $result = $database -> query($q) or die(mysql_error());
- $numrow = mysql_num_rows($result);
- if ($numrow < 1) {
- return 2;
- //Business has not been created.
- }
- $status = mysql_fetch_assoc($result);
- if ($status['status'] == 0) {
- return 1;
- //Business has been created but not approved by admin
- } elseif ($status['status'] == 1) {
- return 0;
- //Business has been created and approve.
- } elseif ($status['status'] == 2) {
- return 3;
- //Business has been banned.
- }
- }
- function checkNotification($userid) {
- global $database;
- $q = sprintf("SELECT notification FROM users WHERE userid = '%s'", mysql_real_escape_string($userid));
- $data = $database -> query($q) or die(mysql_error());
- $row = mysql_fetch_assoc($data);
- $status = $row['notification'];
- if ($status == 1) {
- return true;
- } else {
- return false;
- }
- }
- function notificationsCountDeliveredForBusiness($businessId) {
- global $database;
- $date = gmdate('Y-m-d H:i:s');
- $alreadyStartedDealsArray = array();
- $q = sprintf("select dealid from deals where businessid='%s' and dealtimestamp < '%s'", mysql_real_escape_string($businessId),mysql_real_escape_string($date));
- $alreadyStartedDeals = $database->query($q) or die(mysql_error());
- while($row = mysql_fetch_assoc($alreadyStartedDeals)){
- $alreadyStartedDealsArray[] = $row['dealid'];
- }
- if(count($alreadyStartedDealsArray) == 0)
- return 0;
- $alreadyStartedDealsCSV = implode(",", $alreadyStartedDealsArray);
- $q1 = sprintf("select count(dealid) as deal_count from pushed where dealid in (%s)", mysql_real_escape_string($alreadyStartedDealsCSV));
- $result_alert1 = $database->query($q1) or die(mysql_error());
- $data3 = mysql_fetch_assoc($result_alert1);
- return $data3['deal_count'];
- }
- function isExpired($dealid) {
- global $database;
- $q = sprintf("SELECT expirytimestamp FROM deals WHERE dealid = '%s'", $dealid);
- $data = $database -> query($q) or die(mysql_error());
- $row = mysql_fetch_assoc($data);
- $status = $row['notification'];
- if ($status == 1) {
- return true;
- } else {
- return false;
- }
- }
- function getCat($catid) {
- global $database;
- $q = sprintf("select * from category where catid = '%d'", $catid);
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array);
- $cat = $result['categoryName'];
- return $cat;
- }
- function isValidURL($url) {
- return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
- }
- function getBusinessDetail($businessid) {
- global $database;
- $q = sprintf("select * from business LEFT JOIN business_timing ON business.businessid = business_timing.business_id where business.businessid= '%s'", mysql_real_escape_string($businessid));
- $array = $database -> query($q) or die(mysql_error());
- $result = mysql_fetch_array($array, MYSQL_ASSOC);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement