Advertisement
Kermit66

Untitled

Jan 7th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.24 KB | None | 0 0
  1. <?php
  2. require_once("../include/session.php");
  3. require_once("../include/business.php");
  4. require_once("../include/newcategory.php");
  5.  
  6.  
  7.  
  8. if(isset($_POST['action'])){
  9. $module = $_POST['action'];
  10. switch($module){
  11. case 'login2':
  12. login2($_POST['regid']);
  13. break;
  14. case 'login':
  15. login($_POST['password'],$_POST['remember'],$_POST['email']);
  16. break;
  17.  
  18. case 'register':
  19. registerUser($_POST['email'],$_POST['password'],$_POST['gender'],$_POST['mobile'],$_POST['categoryid'], $_POST['facebookid']);
  20. break;
  21.  
  22. case 'updatePassword':
  23. changePassword($_POST['currpass'],$_POST['newpass'],$_POST['userid']);
  24. break;
  25.  
  26. default:
  27. return "Unknown Request. Please Contact Customer Care.";
  28.  
  29. }
  30. }
  31.  
  32. if(isset($_GET['action'])){
  33.  
  34. $module = $action = $_GET['action'];
  35.  
  36. switch ($module){
  37.  
  38. case 'register_device_uid3':
  39. register_device_uid3($_GET['device_uid'],$_GET['device_type'],$_GET['regid']);
  40. break;
  41.  
  42. case 'register_device_uid2':
  43. register_device_uid2($_GET['device_uid'],$_GET['device_type'],$_GET['regid']);
  44. break;
  45.  
  46. case 'register_device_uid':
  47. register_device_uid($_GET['device_uid'],$_GET['device_type']);
  48. break;
  49.  
  50. case 'getDeals':
  51. getDeals($_GET['categoryid'],$_GET['dealid']);
  52. break;
  53.  
  54. case 'savedeal':
  55. saveDeal($_GET['dealid'],$_GET['custid']);
  56. break;
  57.  
  58. case 'savebusiness':
  59. saveBusiness($_GET['userid'],$_GET['businessid']);
  60. break;
  61.  
  62. case 'getCategory':
  63. getCategory(); //this will output all the category
  64. break;
  65.  
  66. case 'getSubCategory':
  67. getSubCategory($_GET['catid']); //will output all the subcategory which falls under the given category.
  68. break;
  69.  
  70. case 'updateLatLong':
  71. updateLatLong($_GET['lat'], $_GET['long'],$_GET['device_token'], $_GET['userid']);
  72. break;
  73.  
  74. case 'logout':
  75. logOut();
  76. break;
  77.  
  78. case 'forgotPass':
  79. forgotPass($_GET['email']);
  80. break;
  81.  
  82. case 'getBusinessInfo':
  83. getBusinessInfo($_GET['businessid']);
  84. break;
  85.  
  86. case 'getFavBusiness':
  87. if(isset($_GET['catid'])){
  88. getFavBusiness($_GET['userid'], $_GET['catid']);
  89. }else{
  90. getFavBusiness($_GET['userid']);
  91. }
  92.  
  93. break;
  94.  
  95. case 'getProfile':
  96. getProfile($_GET['userid']);
  97. break;
  98.  
  99. case 'updateGender':
  100. updateGender($_GET['gender'],$_GET['userid']);
  101. break;
  102.  
  103. case 'saveBusiness':
  104. saveFavBusiness($_GET['businessid'], $_GET['userid'], $_GET['mode']);
  105. break;
  106.  
  107. case 'saveCategory':
  108. saveFavCategory($_GET['catid'], $_GET['userid'], $_GET['mode']);
  109. break;
  110.  
  111. case 'updateCategory';
  112. updateFavCategories($_GET['catid'], $_GET['userid']);
  113. break;
  114.  
  115. case 'updateNotification':
  116. updateNotificationStatus($_GET['userid'], $_GET['status']);
  117. break;
  118.  
  119. case 'getBusinessWithDeal':
  120. getBusinessWithDeal($_GET['entityid'],$_GET['userid'],$_GET['mode']);
  121. break;
  122. case 'searchBusiness':
  123. searchBusiness($_GET['business_name'],$_GET['userid']);
  124. break;
  125. default:
  126. print "Unknown Request.";
  127. break;
  128. }
  129.  
  130. }
  131.  
  132. function register_device_uid3($device_uid,$device_type,$regid){
  133. global $database,$session,$business, $form;
  134. error_log("saurabh");
  135. $user = $database->findOrCreateUserForDevice3($device_uid,$device_type,$regid);
  136.  
  137. $xml = new DOMDocument("1.0");
  138.  
  139. if($user){
  140. $response = $xml->appendChild($xml->createElement("response"));
  141.  
  142. $status = $response->appendChild($xml->createElement("status"));
  143. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  144.  
  145. $message = $response->appendChild($xml->createElement("message"));
  146. $messageTxt = $message->appendChild($xml->createTextNode($user['userid']));
  147.  
  148. $userXML = $response->appendChild($xml->createElement("user"));
  149.  
  150. $id = $userXML->appendChild($xml->createElement("id"));
  151. $idTxt = $id->appendChild($xml->createTextNode($user['userid']));
  152.  
  153. $notification = $userXML->appendChild($xml->createElement("notification"));
  154. $notification = $notification->appendChild($xml->createTextNode($user['notification']));
  155.  
  156. //getsaved categories
  157. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $user['userid']);
  158. $resultCategory = $database->query($query) or die(mysql_error());
  159. if(mysql_num_rows($resultCategory) < 1){
  160. $catids = Null;
  161. }
  162. else{
  163. while($categoryid = mysql_fetch_assoc($resultCategory)){
  164. $catids[] = $categoryid['catid'];
  165. }
  166. $catids = implode(",", $catids);
  167. }
  168. //var_dump('hiren:',$catids);
  169. $savedCategory = $userXML->appendChild($xml->createElement("savedCategory"));
  170. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  171. //
  172.  
  173. //get all categories
  174. $XMLcategories = $response->appendChild($xml->createElement("categories"));
  175. $q = "SELECT * FROM category ORDER BY categoryName";
  176. $result = $database->query($q) or die(mysql_error());
  177.  
  178. while($category = mysql_fetch_array($result)){
  179. $image = getCategoryImage($category['catid']);
  180. $XMLcategory = $XMLcategories->appendChild($xml->createElement("category"));
  181. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  182. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  183.  
  184. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  185. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  186.  
  187. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  188. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  189.  
  190. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  191. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  192. }
  193.  
  194. $xml->formatOutput=true;
  195. $result = $xml->saveXML();
  196.  
  197. print $result;
  198. }
  199. else{
  200. $Output = $form->error("user").$form->error("email").$form->error("pass").$form->error("notactivated");
  201.  
  202. $xml = new DOMDocument("1.0");
  203.  
  204. $response = $xml->appendChild($xml->createElement("response"));
  205.  
  206. $status = $response->appendChild($xml->createElement("status"));
  207. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  208.  
  209. $message = $response->appendChild($xml->createElement("message"));
  210. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  211.  
  212. $xml->formatOutput=true;
  213. $result = $xml->saveXML();
  214. print $result;
  215. }
  216. }
  217.  
  218. function register_device_uid2($device_uid,$device_type,$regid){
  219. global $database,$session,$business, $form;
  220. error_log("saurabh");
  221. $user = $database->findOrCreateUserForDevice2($device_uid,$device_type,$regid);
  222.  
  223. $xml = new DOMDocument("1.0");
  224.  
  225. if($user){
  226. $response = $xml->appendChild($xml->createElement("response"));
  227.  
  228. $status = $response->appendChild($xml->createElement("status"));
  229. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  230.  
  231. $message = $response->appendChild($xml->createElement("message"));
  232. $messageTxt = $message->appendChild($xml->createTextNode($user['userid']));
  233.  
  234. $userXML = $response->appendChild($xml->createElement("user"));
  235.  
  236. $id = $userXML->appendChild($xml->createElement("id"));
  237. $idTxt = $id->appendChild($xml->createTextNode($user['userid']));
  238.  
  239. $notification = $userXML->appendChild($xml->createElement("notification"));
  240. $notification = $notification->appendChild($xml->createTextNode($user['notification']));
  241.  
  242. //getsaved categories
  243. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $user['userid']);
  244. $resultCategory = $database->query($query) or die(mysql_error());
  245. if(mysql_num_rows($resultCategory) < 1){
  246. $catids = Null;
  247. }
  248. else{
  249. while($categoryid = mysql_fetch_assoc($resultCategory)){
  250. $catids[] = $categoryid['catid'];
  251. }
  252. $catids = implode(",", $catids);
  253. }
  254. $savedCategory = $userXML->appendChild($xml->createElement("savedCategory"));
  255. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  256. //
  257.  
  258. //get all categories
  259. $XMLcategories = $response->appendChild($xml->createElement("categories"));
  260. $q = "SELECT * FROM category ORDER BY categoryName";
  261. $result = $database->query($q) or die(mysql_error());
  262.  
  263. while($category = mysql_fetch_array($result)){
  264. $image = getCategoryImage($category['catid']);
  265. $XMLcategory = $XMLcategories->appendChild($xml->createElement("category"));
  266. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  267. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  268.  
  269. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  270. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  271.  
  272. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  273. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  274.  
  275. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  276. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  277. }
  278.  
  279. $xml->formatOutput=true;
  280. $result = $xml->saveXML();
  281.  
  282. print $result;
  283. }
  284. else{
  285. $Output = $form->error("user").$form->error("email").$form->error("pass").$form->error("notactivated");
  286.  
  287. $xml = new DOMDocument("1.0");
  288.  
  289. $response = $xml->appendChild($xml->createElement("response"));
  290.  
  291. $status = $response->appendChild($xml->createElement("status"));
  292. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  293.  
  294. $message = $response->appendChild($xml->createElement("message"));
  295. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  296.  
  297. $xml->formatOutput=true;
  298. $result = $xml->saveXML();
  299. print $result;
  300. }
  301. }
  302.  
  303. function register_device_uid($device_uid,$device_type){
  304. global $database,$session,$business, $form;
  305. error_log("saurabh");
  306. $user = $database->findOrCreateUserForDevice($device_uid,$device_type);
  307.  
  308. $xml = new DOMDocument("1.0");
  309.  
  310. if($user){
  311. $response = $xml->appendChild($xml->createElement("response"));
  312.  
  313. $status = $response->appendChild($xml->createElement("status"));
  314. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  315.  
  316. $message = $response->appendChild($xml->createElement("message"));
  317. $messageTxt = $message->appendChild($xml->createTextNode($user['userid']));
  318.  
  319. $userXML = $response->appendChild($xml->createElement("user"));
  320.  
  321. $id = $userXML->appendChild($xml->createElement("id"));
  322. $idTxt = $id->appendChild($xml->createTextNode($user['userid']));
  323.  
  324. $notification = $userXML->appendChild($xml->createElement("notification"));
  325. $notification = $notification->appendChild($xml->createTextNode($user['notification']));
  326.  
  327. //getsaved categories
  328. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $user['userid']);
  329. $resultCategory = $database->query($query) or die(mysql_error());
  330. if(mysql_num_rows($resultCategory) < 1){
  331. $catids = Null;
  332. }
  333. else{
  334. while($categoryid = mysql_fetch_assoc($resultCategory)){
  335. $catids[] = $categoryid['catid'];
  336. }
  337. $catids = implode(",", $catids);
  338. }
  339. $savedCategory = $userXML->appendChild($xml->createElement("savedCategory"));
  340. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  341. //
  342.  
  343. //get all categories
  344. $XMLcategories = $response->appendChild($xml->createElement("categories"));
  345. $q = "SELECT * FROM category ORDER BY categoryName";
  346. $result = $database->query($q) or die(mysql_error());
  347.  
  348. while($category = mysql_fetch_array($result)){
  349. $image = getCategoryImage($category['catid']);
  350. $XMLcategory = $XMLcategories->appendChild($xml->createElement("category"));
  351. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  352. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  353.  
  354. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  355. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  356.  
  357. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  358. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  359.  
  360. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  361. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  362. }
  363.  
  364. $xml->formatOutput=true;
  365. $result = $xml->saveXML();
  366.  
  367. print $result;
  368. }
  369. else{
  370. $Output = $form->error("user").$form->error("email").$form->error("pass").$form->error("notactivated");
  371.  
  372. $xml = new DOMDocument("1.0");
  373.  
  374. $response = $xml->appendChild($xml->createElement("response"));
  375.  
  376. $status = $response->appendChild($xml->createElement("status"));
  377. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  378.  
  379. $message = $response->appendChild($xml->createElement("message"));
  380. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  381.  
  382. $xml->formatOutput=true;
  383. $result = $xml->saveXML();
  384. print $result;
  385. }
  386. }
  387.  
  388. function getDeals($categoryid=NULL, $dealid=NULL){
  389.  
  390. global $business,$session,$database;
  391.  
  392. if(isset($dealid) && strlen($dealid=trim($dealid)) != 0){
  393.  
  394. $q = sprintf("SELECT * FROM deals WHERE dealid = '%s'", mysql_real_escape_string($dealid));
  395. $result = $database->query($q) or die(mysql_error());
  396.  
  397. $xml = new DOMDocument("1.0");
  398. $root = $xml->appendChild($xml->createElement("response"));
  399.  
  400. while($dealid = mysql_fetch_array($result)){
  401.  
  402. $queryCat = sprintf("select catid from business where businessid= '%s'", mysql_real_escape_string($dealid['businessid']));
  403. $result2 = $database->query($queryCat) or die(mysql_error());
  404. $catid2 = mysql_fetch_array($result2);
  405. $catid = $catid2['catid'];
  406.  
  407. $dealinfo = $business->getDealInfo($dealid['dealid']);
  408. $businessid = $business->getBusinessId($dealid['dealid']);
  409. $businessinfo = $business->getBusinessInfo($businessid);
  410.  
  411. $dealImageLocation = $business->getDealImage($dealid['dealid']);
  412. $businessImageLocation = $business->getBusinessImage($businessid);
  413.  
  414. $dealCat = $business->getCat($catid);
  415.  
  416.  
  417. $deal = $root->appendChild($xml->createElement("deal"));
  418.  
  419. $dealid = $deal->appendChild($xml->createElement("dealId"));
  420. $dealid = $dealid->appendChild($xml->createTextNode($dealinfo['dealid']));
  421.  
  422. $dealname = $deal->appendChild($xml->createElement("dealName"));
  423. $dealname = $dealname->appendChild($xml->createTextNode($dealinfo['dealname']));
  424.  
  425. $dealDescription = $deal->appendChild($xml->createElement("dealDescription"));
  426. $dealDescription = $dealDescription->appendChild($xml->createTextNode($dealinfo['desc']));
  427.  
  428. $dealPrice = $deal->appendChild($xml->createElement("dealPrice"));
  429. $dealPrice = $dealPrice->appendChild($xml->createTextNode($dealinfo['dealoffer']));
  430.  
  431. $dealExpiryDate = $deal->appendChild($xml->createElement("dealExpiry"));
  432. $dealExpiryDate = $dealExpiryDate->appendChild($xml->createTextNode($dealinfo['expirytimestamp']));
  433.  
  434.  
  435. $dealImage = $deal->appendChild($xml->createElement("dealImage"));
  436. $dealImage = $dealImage->appendChild($xml->createTextNode($dealImageLocation));
  437.  
  438. $dealCategory = $deal->appendChild($xml->createElement("dealCategoryId"));
  439. $dealCategory = $dealCategory->appendChild($xml->createTextNode($catid));
  440.  
  441. $dealCatName = $deal->appendChild($xml->createElement("dealCatName"));
  442. $dealCatName = $dealCatName->appendChild($xml->createTextNode($dealCat));
  443.  
  444. $lat = $deal->appendChild($xml->createElement("lat"));
  445. $lat = $lat->appendChild($xml->createTextNode($businessinfo['lattitude']));
  446.  
  447. $long = $deal->appendChild($xml->createElement("long"));
  448. $long = $long->appendChild($xml->createTextNode($businessinfo['longitude']));
  449.  
  450. $merchantId = $deal->appendChild($xml->createElement("merchantId"));
  451. $merchantId = $merchantId->appendChild($xml->createTextNode($businessinfo['businessid']));
  452.  
  453. $merchantName = $deal->appendChild($xml->createElement("merchantName"));
  454. $merchantName = $merchantName->appendChild($xml->createTextNode($businessinfo['bname']));
  455.  
  456. $merchantAddress = $deal->appendChild($xml->createElement("merchantAddress"));
  457. $merchantName = $merchantAddress->appendChild($xml->createTextNode($businessinfo['street'].", ".$businessinfo['suburb'].", ".$businessinfo['state']));
  458.  
  459.  
  460.  
  461. }
  462. $xml->formatOutput=true;
  463. print ($result= $xml->saveXML());
  464.  
  465. }
  466.  
  467.  
  468. elseif(isset($categoryid) && strlen($categoryid=trim($categoryid)) !=0){
  469.  
  470. $catids = getTree($categoryid);
  471. print_r($catids);
  472.  
  473. if(count($catids) < 1){
  474. return "No deals";
  475. }
  476.  
  477. $xml = new DOMDocument("1.0");
  478.  
  479. $root = $xml->appendChild($xml->createElement("response"));
  480.  
  481. foreach($catids as $catid){
  482. $time = gmdate("Y-m-d H:i:s");
  483. $q = sprintf("SELECT deals.*, business.catid from deals LEFT JOIN business ON deals.businessid = business.businessid
  484. WHERE business.catid ='%s' AND deals.expirytimestamp >= '%s' AND UTC_TIMESTAMP() >= deals.dealtimestamp AND deals.status = 1",
  485. mysql_real_escape_string($catid),
  486. $time
  487. );
  488. $result = $database->query($q) or die(mysql_error());
  489.  
  490.  
  491. while($dealid = mysql_fetch_array($result)){
  492.  
  493. $dealinfo = $business->getDealInfo($dealid['dealid']);
  494. $businessid = $business->getBusinessId($dealid['dealid']);
  495.  
  496. $dealImageLocation = $business->getDealImage($dealid['dealid']);
  497. $businessImageLocation = $business->getBusinessImage($businessid);
  498.  
  499.  
  500. $dealCat = $business->getCat($catid);
  501.  
  502.  
  503. $deal = $root->appendChild($xml->createElement("deal"));
  504.  
  505. $dealid = $deal->appendChild($xml->createElement("dealId"));
  506. $dealid = $dealid->appendChild($xml->createTextNode($dealinfo['dealid']));
  507.  
  508. $dealname = $deal->appendChild($xml->createElement("dealName"));
  509. $dealname = $dealname->appendChild($xml->createTextNode($dealinfo['dealname']));
  510.  
  511. $dealDescription = $deal->appendChild($xml->createElement("dealDescription"));
  512. $dealDescription = $dealDescription->appendChild($xml->createTextNode($dealinfo['desc']));
  513.  
  514. $dealPrice = $deal->appendChild($xml->createElement("dealPrice"));
  515. $dealPrice = $dealPrice->appendChild($xml->createTextNode($dealinfo['dealoffer']));
  516.  
  517. $dealExpiryDate = $deal->appendChild($xml->createElement("dealExpiry"));
  518. $dealExpiryDate = $dealExpiryDate->appendChild($xml->createTextNode($dealinfo['expirytimestamp']));
  519.  
  520. $dealImage = $deal->appendChild($xml->createElement("dealImage"));
  521. $dealImage = $dealImage->appendChild($xml->createTextNode($dealImageLocation));
  522.  
  523. $dealCategory = $deal->appendChild($xml->createElement("dealCategoryId"));
  524. $dealCategory = $dealCategory->appendChild($xml->createTextNode($catid));
  525.  
  526. $dealCatName = $deal->appendChild($xml->createElement("dealCatName"));
  527. $dealCatName = $dealCatName->appendChild($xml->createTextNode($dealCat));
  528.  
  529. $lat = $deal->appendChild($xml->createElement("lat"));
  530. $lat = $lat->appendChild($xml->createTextNode($businessinfo['lattitude']));
  531.  
  532. $long = $deal->appendChild($xml->createElement("long"));
  533. $long = $long->appendChild($xml->createTextNode($businessinfo['longitude']));
  534.  
  535. $merchantId = $deal->appendChild($xml->createElement("merchantId"));
  536. $merchantId = $merchantId->appendChild($xml->createTextNode($businessinfo['businessid']));
  537.  
  538. $merchantName = $deal->appendChild($xml->createElement("merchantName"));
  539. $merchantName = $merchantName->appendChild($xml->createTextNode($businessinfo['bname']));
  540.  
  541. $merchantAddress = $deal->appendChild($xml->createElement("merchantAddress"));
  542. $merchantName = $merchantAddress->appendChild($xml->createTextNode($businessinfo['street'].", ".$businessinfo['suburb'].", ".$businessinfo['state']));
  543.  
  544.  
  545. }
  546.  
  547. }
  548. //$catid = $categoryid;
  549.  
  550. $xml->formatOutput=true;
  551. print ($result= $xml->saveXML());
  552. }
  553.  
  554. else{ //when neither category or subcategory is given the server will output all the deals...
  555.  
  556.  
  557. $time = gmdate("Y-m-d H:i:s");
  558. $q = sprintf("SELECT * FROM deals WHERE deals.expirytimestamp >= '%s' AND deals.status = 1", $time);
  559. $result = $database->query($q) or die(mysql_error());
  560.  
  561. $xml = new DOMDocument("1.0");
  562.  
  563. $root = $xml->appendChild($xml->createElement("response"));
  564.  
  565. while($dealid = mysql_fetch_array($result)){
  566.  
  567. $dealinfo = $business->getDealInfo($dealid['dealid']);
  568. $businessid = $business->getBusinessId($dealid['dealid']);
  569. $businessinfo = $business->getBusinessInfo($businessid);
  570.  
  571. $dealImageLocation = $business->getDealImage($dealid['dealid']);
  572. $businessImageLocation = $business->getBusinessImage($businessid);
  573.  
  574. $dealCat = $business->getCat($dealinfo['catid']);
  575.  
  576. $deal = $root->appendChild($xml->createElement("deal"));
  577.  
  578. $dealid = $deal->appendChild($xml->createElement("dealId"));
  579. $dealid = $dealid->appendChild($xml->createTextNode($dealinfo['dealid']));
  580.  
  581. $dealname = $deal->appendChild($xml->createElement("dealName"));
  582. $dealname = $dealname->appendChild($xml->createTextNode($dealinfo['dealname']));
  583.  
  584. $dealDescription = $deal->appendChild($xml->createElement("dealDescription"));
  585. $dealDescription = $dealDescription->appendChild($xml->createTextNode($dealinfo['desc']));
  586.  
  587. $dealPrice = $deal->appendChild($xml->createElement("dealPrice"));
  588. $dealPrice = $dealPrice->appendChild($xml->createTextNode($dealinfo['dealoffer']));
  589.  
  590. $dealExpiryDate = $deal->appendChild($xml->createElement("dealExpiry"));
  591. $dealExpiryDate = $dealExpiryDate->appendChild($xml->createTextNode($dealinfo['expirytimestamp']));
  592.  
  593. $dealImage = $deal->appendChild($xml->createElement("dealImage"));
  594. $dealImage = $dealImage->appendChild($xml->createTextNode($dealImageLocation));
  595.  
  596. $dealCategory = $deal->appendChild($xml->createElement("dealCategoryId"));
  597. $dealCategory = $dealCategory->appendChild($xml->createTextNode($dealinfo['catid']));
  598.  
  599. $dealCatName = $deal->appendChild($xml->createElement("dealCatName"));
  600. $dealCatName = $dealCatName->appendChild($xml->createTextNode($dealCat));
  601.  
  602. $lat = $deal->appendChild($xml->createElement("lat"));
  603. $lat = $lat->appendChild($xml->createTextNode($dealinfo['lattitude']));
  604.  
  605. $long = $deal->appendChild($xml->createElement("long"));
  606. $long = $long->appendChild($xml->createTextNode($dealinfo['longitude']));
  607.  
  608. $merchantId = $deal->appendChild($xml->createElement("merchantId"));
  609. $merchantId = $merchantId->appendChild($xml->createTextNode($dealinfo['businessid']));
  610.  
  611. $merchantName = $deal->appendChild($xml->createElement("merchantName"));
  612. $merchantName = $merchantName->appendChild($xml->createTextNode($dealinfo['bname']));
  613.  
  614. $merchantAddress = $deal->appendChild($xml->createElement("merchantAddress"));
  615. $merchantName = $merchantAddress->appendChild($xml->createTextNode($dealinfo['street'].", ".$dealinfo['suburb'].", ".$dealinfo['state']));
  616.  
  617.  
  618.  
  619. }
  620. $xml->formatOutput=true;
  621. print ($result= $xml->saveXML());
  622. }
  623. }
  624.  
  625.  
  626. function registerUser($subemail,$subpassword1,$subgender,$submobile=NULL,$subcategoryid=NULL, $facebookid=NULL){
  627. global $database,$business, $session, $form;
  628.  
  629. if(isset($subcategoryid) && strlen($subcategoryid) > 0){
  630. $catids = explode("," ,$subcategoryid);
  631. }
  632.  
  633. $result = $session->registeriPhone($subemail,$subpassword1,$subgender,$submobile,$catids);
  634.  
  635. if($result == 0){
  636.  
  637.  
  638. $xml = new DOMDocument("1.0");
  639.  
  640. $response = $xml->appendChild($xml->createElement("response"));
  641.  
  642. $status = $response->appendChild($xml->createElement("status"));
  643. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  644.  
  645. $message = $response->appendChild($xml->createElement("message"));
  646. $messageTxt = $message->appendChild($xml->createTextNode("CONGRATULATIONS! Welcome to MyPype. You may now log in with the details you had registered with."));
  647.  
  648. $result = $xml->saveXML();
  649. print $result;
  650. }
  651.  
  652. elseif($result == 1){
  653. $xml = new DOMDocument("1.0");
  654.  
  655. $response = $xml->appendChild($xml->createElement("response"));
  656.  
  657. $status = $response->appendChild($xml->createElement("status"));
  658. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  659.  
  660. $message = $response->appendChild($xml->createElement("message"));
  661. $messageTxt = $message->appendChild($xml->createTextNode($form->error("email").$form->error("password").$form->error("mobile")));
  662.  
  663. $result = $xml->saveXML();
  664. $xml->formatOutput=true;
  665. print $result;
  666. }
  667.  
  668. elseif($result == 2){
  669. $xml = new DOMDocument("1.0");
  670.  
  671. $response = $xml->appendChild($xml->createElement("response"));
  672.  
  673. $status = $response->appendChild($xml->createElement("status"));
  674. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  675.  
  676. $message = $response->appendChild($xml->createElement("message"));
  677. $messageTxt = $message->appendChild($xml->createTextNode("Oops Something's wrong. Please Try again Later."));
  678.  
  679. $result = $xml->saveXML();
  680. $xml->formatOutput=true;
  681. print $result;
  682. }
  683.  
  684. }
  685.  
  686. function saveDeal($custid,$dealid,$dealcategory,$dealsubcategory){
  687. global $database;
  688. $q = sprintf("INSERT into savedeal VALUES('%s','%s,'%s','%s')",
  689. mysql_real_escape_string($custid),
  690. mysql_real_escape_string($dealid),
  691. mysql_real_escape_string($dealcategoryid),
  692. mysql_real_escape_string($dealsubcategoryid)
  693. );
  694.  
  695. if($result = $database->query($q) or die(mysql_error())){
  696. $xml = new DOMDocument("1.0");
  697.  
  698. $response = $xml->appendChild($xml->createElement("response"));
  699.  
  700. $status = $response->appendChild($xml->createElement("status"));
  701. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  702.  
  703. $message = $response->appendChild($xml->createElement("message"));
  704. $messageTxt = $message->appendChild($xml->createTextNode(""));
  705.  
  706. $result = $xml->saveXML();
  707. print $result;
  708.  
  709. }
  710. else{
  711. $xml = new DOMDocument("1.0");
  712.  
  713. $response = $xml->appendChild($xml->createElement("response"));
  714.  
  715. $status = $response->appendChild($xml->createElement("status"));
  716. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  717.  
  718. $message = $response->appendChild($xml->createElement("message"));
  719. $messageTxt = $message->appendChild($xml->createTextNode(""));
  720. $xml->formatOutput=true;
  721. $result = $xml->saveXML();
  722.  
  723. print $result;
  724. }
  725. }
  726.  
  727. function updateGender($gender, $userid){
  728. global $database;
  729. $q = sprintf("UPDATE users set users.gender='%s' where userid = '%s'",
  730. mysql_real_escape_string($gender),
  731. mysql_real_escape_string($userid));
  732.  
  733. if($result = $database->query($q) or die(mysql_error())){
  734.  
  735. $xml = new DOMDocument("1.0");
  736.  
  737. $response = $xml->appendChild($xml->createElement("response"));
  738.  
  739. $status = $response->appendChild($xml->createElement("status"));
  740. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  741. $message = $response->appendChild($xml->createElement("message"));
  742. $messageTxt = $message->appendChild($xml->createTextNode("Gender updated successfully"));
  743. $xml->formatOutput=true;
  744. $result = $xml->saveXML();
  745. print $result;
  746.  
  747. }
  748. else{
  749. $xml = new DOMDocument("1.0");
  750.  
  751. $response = $xml->appendChild($xml->createElement("response"));
  752.  
  753. $status = $response->appendChild($xml->createElement("status"));
  754. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  755.  
  756. $message = $response->appendChild($xml->createElement("message"));
  757. $messageTxt = $message->appendChild($xml->createTextNode("Fail to update"));
  758.  
  759. $xml->formatOutput=true;
  760. $result = $xml->saveXML();
  761.  
  762. print $result;
  763. }
  764. }
  765.  
  766. function login2($regid){
  767.  
  768. global $database,$session,$business, $form;
  769.  
  770. $result = $session->login2($regid);
  771.  
  772.  
  773. if($result){
  774. $q = "SELECT * FROM " . TBL_USERS . " WHERE device_uid ='$regid'";
  775. $valid = $database -> query($q);
  776. $valid = mysql_fetch_array($valid);
  777. // $Output = $session->userinfo['userid'];
  778. $output=$valid['userid'];
  779. $xml = new DOMDocument("1.0");
  780.  
  781. $response = $xml->appendChild($xml->createElement("response"));
  782.  
  783. $status = $response->appendChild($xml->createElement("status"));
  784. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  785.  
  786. $message = $response->appendChild($xml->createElement("message"));
  787. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  788.  
  789.  
  790. $user = $response->appendChild($xml->createElement("user"));
  791.  
  792. $id = $user->appendChild($xml->createElement("id"));
  793. $idTxt = $id->appendChild($xml->createTextNode($Output));
  794.  
  795. $notification = $user->appendChild($xml->createElement("notification"));
  796. $notification = $notification->appendChild($xml->createTextNode($session->userinfo['notification']));
  797.  
  798. ////////getsaved categories
  799. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $Output);
  800. $resultCategory = $database->query($query) or die(mysql_error());
  801.  
  802. if(mysql_num_rows($resultCategory) < 1){
  803. $catids = Null;
  804. }
  805.  
  806. else{
  807. while($categoryid = mysql_fetch_assoc($resultCategory)){
  808. $catids[] = $categoryid['catid'];
  809. }
  810. $catids = implode(",", $catids);
  811. }
  812. $savedCategory = $user->appendChild($xml->createElement("savedCategory"));
  813. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  814. /////////////categories added to xml
  815.  
  816.  
  817.  
  818. $XMLcategories = $response->appendChild($xml->createElement("categories"));
  819.  
  820. $q = "SELECT * FROM category ORDER BY categoryName";
  821. $result = $database->query($q) or die(mysql_error());
  822.  
  823.  
  824. while($category = mysql_fetch_array($result)){
  825.  
  826. $image = getCategoryImage($category['catid']);
  827.  
  828.  
  829.  
  830. $XMLcategory = $XMLcategories->appendChild($xml->createElement("category"));
  831.  
  832. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  833. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  834.  
  835. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  836. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  837.  
  838. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  839. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  840.  
  841. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  842. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  843. }
  844.  
  845. $xml->formatOutput=true;
  846. $result = $xml->saveXML();
  847.  
  848. print $result;
  849. }
  850.  
  851. if(!$result){
  852. // $Output = $form->error("user").$form->error("email").$form->error("pass").$form->error("notactivated");
  853.  
  854. $q = "INSERT INTO users(regid) VALUES('$regid')";
  855. $valid = $database -> query($q);
  856.  
  857. $Output=0;
  858. $xml = new DOMDocument("1.0");
  859.  
  860. $response = $xml->appendChild($xml->createElement("response"));
  861. $reg_status = $response->appendChild($xml->createElement("reg_status"));
  862. $responseText = $reg_status->appendChild($xml->createTextNode("1"));
  863. $status = $response->appendChild($xml->createElement("status"));
  864. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  865.  
  866. $message = $response->appendChild($xml->createElement("message"));
  867. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  868.  
  869. $xml->formatOutput=true;
  870. $result = $xml->saveXML();
  871. print $result;
  872. }
  873.  
  874. }
  875.  
  876. function login($password, $remember=NULL, $email){
  877.  
  878. global $database,$session,$business, $form;
  879.  
  880. $checkLogin = $session->checkLoginMobile();
  881.  
  882. if($checkLogin){
  883. print $Output = "Already Logged in";
  884.  
  885. }
  886.  
  887. else{
  888.  
  889. $result = $session->login($email,$password,$remember);
  890.  
  891. if($result){
  892.  
  893. $Output = $session->userinfo['userid'];
  894.  
  895. $xml = new DOMDocument("1.0");
  896.  
  897. $response = $xml->appendChild($xml->createElement("response"));
  898.  
  899. $status = $response->appendChild($xml->createElement("status"));
  900. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  901.  
  902. $message = $response->appendChild($xml->createElement("message"));
  903. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  904.  
  905.  
  906. $user = $response->appendChild($xml->createElement("user"));
  907.  
  908. $id = $user->appendChild($xml->createElement("id"));
  909. $idTxt = $id->appendChild($xml->createTextNode($Output));
  910.  
  911. $notification = $user->appendChild($xml->createElement("notification"));
  912. $notification = $notification->appendChild($xml->createTextNode($session->userinfo['notification']));
  913.  
  914. ////////getsaved categories
  915. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $Output);
  916. $resultCategory = $database->query($query) or die(mysql_error());
  917.  
  918. if(mysql_num_rows($resultCategory) < 1){
  919. $catids = Null;
  920. }
  921.  
  922. else{
  923. while($categoryid = mysql_fetch_assoc($resultCategory)){
  924. $catids[] = $categoryid['catid'];
  925. }
  926. $catids = implode(",", $catids);
  927. }
  928. $savedCategory = $user->appendChild($xml->createElement("savedCategory"));
  929. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  930. /////////////categories added to xml
  931.  
  932.  
  933.  
  934. $XMLcategories = $response->appendChild($xml->createElement("categories"));
  935.  
  936. $q = "SELECT * FROM category ORDER BY categoryName";
  937. $result = $database->query($q) or die(mysql_error());
  938.  
  939.  
  940. while($category = mysql_fetch_array($result)){
  941.  
  942. $image = getCategoryImage($category['catid']);
  943.  
  944.  
  945.  
  946. $XMLcategory = $XMLcategories->appendChild($xml->createElement("category"));
  947.  
  948. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  949. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  950.  
  951. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  952. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  953.  
  954. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  955. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  956.  
  957. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  958. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  959. }
  960.  
  961. $xml->formatOutput=true;
  962. $result = $xml->saveXML();
  963.  
  964. print $result;
  965. }
  966.  
  967. if(!$result){
  968. $Output = $form->error("user").$form->error("email").$form->error("pass").$form->error("notactivated");
  969.  
  970. $xml = new DOMDocument("1.0");
  971.  
  972. $response = $xml->appendChild($xml->createElement("response"));
  973.  
  974. $status = $response->appendChild($xml->createElement("status"));
  975. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  976.  
  977. $message = $response->appendChild($xml->createElement("message"));
  978. $messageTxt = $message->appendChild($xml->createTextNode($Output));
  979.  
  980. $xml->formatOutput=true;
  981. $result = $xml->saveXML();
  982. print $result;
  983. }
  984. }
  985. }
  986.  
  987. function logOut(){
  988. global $database,$session,$business;
  989. $result = $session->logout();
  990. if($result){
  991. $xml = new DOMDocument("1.0");
  992.  
  993. $response = $xml->appendChild($xml->createElement("response"));
  994.  
  995. $status = $response->appendChild($xml->createElement("status"));
  996. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  997. $message = $response->appendChild($xml->createElement("message"));
  998. $messageTxt = $message->appendChild($xml->createTextNode("Logged Out"));
  999.  
  1000. $result = $xml->saveXML();
  1001. print $result;
  1002. }
  1003.  
  1004. else{
  1005. $xml = new DOMDocument("1.0");
  1006.  
  1007. $response = $xml->appendChild($xml->createElement("response"));
  1008.  
  1009. $status = $response->appendChild($xml->createElement("status"));
  1010. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1011.  
  1012. $message = $response->appendChild($xml->createElement("message"));
  1013. $messageTxt = $message->appendChild($xml->createTextNode("Fail to logOut"));
  1014.  
  1015. $result = $xml->saveXML();
  1016. $xml->formatOutput=true;
  1017. print $result;
  1018. }
  1019. }
  1020.  
  1021. function getCategory(){
  1022. global $database, $session,$business;
  1023. $q = "SELECT * FROM category ORDER BY categoryName";
  1024. $result = $database->query($q) or die(mysql_error());
  1025.  
  1026. $xml = new DOMDocument("1.0");
  1027. $root = $xml->appendChild($xml->createElement("response"));
  1028.  
  1029. while($category = mysql_fetch_array($result)){
  1030.  
  1031. $image = getCategoryImage($category['catid']);
  1032.  
  1033. $XMLcategory = $root->appendChild($xml->createElement("category"));
  1034.  
  1035. $categoryid = $XMLcategory->appendChild($xml->createElement("categoryID"));
  1036. $categoryid = $categoryid->appendChild($xml->createTextNode($category['catid']));
  1037.  
  1038. $categoryName= $XMLcategory->appendChild($xml->createElement("categoryName"));
  1039. $categoryName = $categoryName->appendChild($xml->createTextNode($category['categoryName']));
  1040.  
  1041. $categoryParentId = $XMLcategory->appendChild($xml->createElement("categoryParentID"));
  1042. $categoryParentId = $categoryParentId->appendChild($xml->createTextNode($category['parent_id']));
  1043.  
  1044. $categoryImage = $XMLcategory->appendChild($xml->createElement("catImage"));
  1045. $categoryImage = $categoryImage->appendChild($xml->createTextNode($image));
  1046. }
  1047. $xml->formatOutput=true;
  1048. $myXML = $xml->saveXML();
  1049. print $myXML;
  1050. }
  1051.  
  1052. function updateLatLong($lat=NULL, $long=NULL, $devicetoken, $userid ){
  1053. global $database, $business;
  1054. $devicetoken = strtoupper($devicetoken);
  1055.  
  1056. if(($lat || strlen(trim($lat)) !== 0) && (!$long || strlen(trim($long)) !== 0)){
  1057. $query = sprintf("INSERT INTO push VALUES($lat,$long,'%s','%s',1)
  1058. ON DUPLICATE KEY UPDATE push.lat=$lat, push.long=$long", mysql_real_escape_string($devicetoken), mysql_real_escape_string($userid));
  1059.  
  1060. $result = $database->query($query) or die(mysql_error());
  1061. $messageresult = "Latitude Longitude updated";
  1062. }
  1063.  
  1064. else{
  1065. $query = sprintf("INSERT INTO push (device_token,userid, notification) VALUES('%s','%s',1)
  1066. ON DUPLICATE KEY UPDATE push.device_token='%s'",
  1067. mysql_real_escape_string($devicetoken),
  1068. mysql_real_escape_string($userid),
  1069. mysql_real_escape_string($devicetoken));
  1070.  
  1071. $result = $database->query($query) or die(mysql_error());
  1072. $messageresult = "Device Token updated";
  1073. }
  1074.  
  1075. if($result){
  1076. //-----GET THE API FOR GETTING NEARBY DEALS OF THE SUBSCRIBED CATEGORY------//
  1077. $catids = $business->getSavedCategories($userid);
  1078.  
  1079. $xml = new DOMDocument("1.0");
  1080. $response = $xml->appendChild($xml->createElement("response"));
  1081.  
  1082. $status = $response->appendChild($xml->createElement("status"));
  1083. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  1084. $message = $response->appendChild($xml->createElement("message"));
  1085. $messageTxt = $message->appendChild($xml->createTextNode($messageresult));
  1086. $xml->formatOutput=true;
  1087. $result = $xml->saveXML();
  1088. print $result;
  1089.  
  1090. }
  1091.  
  1092. else{
  1093. $xml = new DOMDocument("1.0");
  1094.  
  1095. $response = $xml->appendChild($xml->createElement("response"));
  1096.  
  1097. $status = $response->appendChild($xml->createElement("status"));
  1098. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1099.  
  1100. $message = $response->appendChild($xml->createElement("message"));
  1101. $messageTxt = $message->appendChild($xml->createTextNode("SEVER BUSY.. TRY AGAIN LATER"));
  1102.  
  1103. $xml->formatOutput=true;
  1104. $result = $xml->saveXML();
  1105. print $result;
  1106. }
  1107.  
  1108. }
  1109.  
  1110. function forgotPass($email){
  1111. global $session;
  1112.  
  1113. $result = $session->forgotPassMobile($email);
  1114.  
  1115. if($result == 1){
  1116. $xml = new DOMDocument("1.0");
  1117. $response = $xml->appendChild($xml->createElement("response"));
  1118.  
  1119. $status = $response->appendChild($xml->createElement("status"));
  1120. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  1121. $message = $response->appendChild($xml->createElement("message"));
  1122. $messageTxt = $message->appendChild($xml->createTextNode("A new Password has been sent to the provided Email Address"));
  1123. $xml->formatOutput=true;
  1124. $result = $xml->saveXML();
  1125. print $result;
  1126.  
  1127. }
  1128.  
  1129. else{
  1130. $xml = new DOMDocument("1.0");
  1131.  
  1132. $response = $xml->appendChild($xml->createElement("response"));
  1133.  
  1134. $status = $response->appendChild($xml->createElement("status"));
  1135. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1136.  
  1137. $message = $response->appendChild($xml->createElement("message"));
  1138. $messageTxt = $message->appendChild($xml->createTextNode("Email Address provided was not found on our records"));
  1139.  
  1140. $xml->formatOutput=true;
  1141. $result = $xml->saveXML();
  1142.  
  1143. print $result;
  1144. }
  1145. }
  1146.  
  1147. /*-------Business and deal XML----------//
  1148. * 2 scenarios are handled depending upon mode.
  1149. * In business mode business is extracted first and
  1150. * if a non expired deal is availble is passed through
  1151. * In deal mode , the specific deal is extracted first
  1152. * and the its associated business is passed through
  1153. */
  1154.  
  1155. function getBusinessWithDeal($entityid,$userid,$mode){
  1156.  
  1157. global $database,$business;
  1158.  
  1159. if($mode == "business"){
  1160. //get business from entityid
  1161. $businessinfo = $business->getBusinessInfo($entityid);
  1162. //get deals of business
  1163. $time = gmdate("Y-m-d H:i:s");
  1164. $q = sprintf("SELECT * FROM deals WHERE businessid = '%d' AND deals.expirytimestamp >= '%s' AND UTC_TIMESTAMP() >= deals.dealtimestamp AND deals.status = '1'",
  1165. mysql_real_escape_string($entityid),$time);
  1166. $deals = $database->query($q) or die(mysql_error());
  1167. //create xml
  1168. createBusinessAndDealsXml($businessinfo,$deals,$userid);
  1169. }
  1170.  
  1171. else if($mode == "deal"){
  1172. //get deal from entity id
  1173. $q = sprintf("SELECT * FROM deals WHERE dealid = '%s'", mysql_real_escape_string($entityid));
  1174. $deals = $database->query($q) or die(mysql_error());
  1175. //get business for the deal
  1176. $deal = mysql_fetch_array($deals);
  1177. $businessinfo = $business->getBusinessInfo($deal['businessid']);
  1178.  
  1179. $deals = $database->query($q) or die(mysql_error());
  1180. createBusinessAndDealsXml($businessinfo,$deals,$userid);
  1181. }
  1182. }
  1183.  
  1184. function createBusinessAndDealsXml($businessinfo,$deals,$userid){
  1185. global $database,$business;
  1186.  
  1187. $timing = array(
  1188. 'monday' => $businessinfo['monday'],
  1189. 'tuesday' => $businessinfo['tuesday'],
  1190. 'wednesday' => $businessinfo['wednesday'],
  1191. 'thursday' => $businessinfo['thursday'],
  1192. 'friday' => $businessinfo['friday'],
  1193. 'saturday' => $businessinfo['saturday'],
  1194. 'sunday' => $businessinfo['sunday']);
  1195.  
  1196. // print_r($timing);
  1197.  
  1198.  
  1199. $opentime; $closetime;
  1200. foreach($timing as $day=>$time){
  1201. if($time!=""){
  1202. list($open, $close) = explode("-", $time);
  1203. list($openhour, $openminutes, $openseconds) = explode(":", $open);
  1204. list($closehour, $closeminutes, $closeseconds) = explode(":", $close);
  1205. if(isset($openhour) && isset($openminutes) && isset($openseconds)){
  1206. $opentime[$day]= date("h:i:s A", mktime($openhour,$openminutes, $openseconds));
  1207. $closetime[$day] =date("h:i:s A", mktime($closehour,$closeminutes, $closeseconds));
  1208.  
  1209. }
  1210. }else{
  1211. $opentime[$day]="";
  1212. $closetime[$day]="";
  1213. }
  1214.  
  1215. }
  1216.  
  1217.  
  1218. $businessImage = $business->getBusinessImage($businessinfo['businessid']);
  1219. $businessCategory = $business->getCat($businessinfo['catid']);
  1220.  
  1221. $xml = new DOMDocument("1.0");
  1222. $root = $xml->appendChild($xml->createElement("response"));
  1223.  
  1224. $businessXML = $root->appendChild($xml->createElement("business"));
  1225.  
  1226. $businessId = $businessXML->appendChild($xml->createElement("businessID"));
  1227. $businessId = $businessId->appendChild($xml->createTextNode($businessinfo['businessid']));
  1228.  
  1229. $businessname = $businessXML->appendChild($xml->createElement("businessName"));
  1230. $businessname = $businessname->appendChild($xml->createTextNode($businessinfo['bname']));
  1231.  
  1232. $businessDesc = $businessXML->appendChild($xml->createElement("businessDescription"));
  1233. $businessDesc = $businessDesc->appendChild($xml->createTextNode($businessinfo['bdesc']));
  1234.  
  1235. $businessCatId = $businessXML->appendChild($xml->createElement("businessCatId"));
  1236. $businessCatId = $businessCatId->appendChild($xml->createTextNode($businessinfo['catid']));
  1237.  
  1238. $businessCatName = $businessXML->appendChild($xml->createElement("businessCatName"));
  1239. $businessCatName = $businessCatName->appendChild($xml->createTextNode($businessCategory));
  1240.  
  1241. $businessAdd = $businessXML->appendChild($xml->createElement("businessAddress"));
  1242. $businessname = $businessAdd->appendChild($xml->createTextNode($businessinfo['street'].", ".$businessinfo['suburb'].", ".$businessinfo['state']));
  1243.  
  1244. $businessSite = $businessXML->appendChild($xml->createElement("businessWebsite"));
  1245. $businessSite = $businessSite->appendChild($xml->createTextNode($businessinfo['site']));
  1246.  
  1247. $businessContact = $businessXML->appendChild($xml->createElement("businessContact"));
  1248. $businessContact = $businessContact->appendChild($xml->createTextNode($businessinfo['phone']));
  1249.  
  1250. $businessLat = $businessXML->appendChild($xml->createElement("businessLat"));
  1251. $businessLat = $businessLat->appendChild($xml->createTextNode($businessinfo['lattitude']));
  1252.  
  1253. $businessLong = $businessXML->appendChild($xml->createElement("businessLong"));
  1254. $businessLong = $businessLong->appendChild($xml->createTextNode($businessinfo['longitude']));
  1255.  
  1256. $businessImg = $businessXML->appendChild($xml->createElement("businessImage"));
  1257. $businessImage = $businessImg->appendChild($xml->createTextNode($businessImage));
  1258.  
  1259. $businessTiming = $businessXML->appendChild($xml->createElement("timing"));
  1260.  
  1261. $businessMonday = $businessTiming->appendChild($xml->createElement("monday"));
  1262. if($opentime['monday']!=""){
  1263. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['monday']." - ".$closetime['monday']));
  1264. }else{
  1265. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1266. }
  1267.  
  1268. $businessMonday = $businessTiming->appendChild($xml->createElement("tuesday"));
  1269. if($opentime['tuesday']!=""){
  1270. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['tuesday']." - ".$opentime['tuesday']));
  1271. }else{
  1272. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1273. }
  1274.  
  1275. $businessMonday = $businessTiming->appendChild($xml->createElement("wednesday"));
  1276. if($opentime['wednesday']!=""){
  1277. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['wednesday']." - ".$opentime['wednesday']));
  1278. }else{
  1279. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1280. }
  1281.  
  1282.  
  1283. $businessMonday = $businessTiming->appendChild($xml->createElement("thursday"));
  1284. if($opentime['thursday']!=""){
  1285. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['thursday']." - ".$opentime['thursday']));
  1286. }else{
  1287. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1288. }
  1289. $businessMonday = $businessTiming->appendChild($xml->createElement("friday"));
  1290. if($opentime['friday']!=""){
  1291. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['friday']." - ".$opentime['friday']));
  1292. }else{
  1293. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1294. }
  1295.  
  1296.  
  1297. $businessMonday = $businessTiming->appendChild($xml->createElement("saturday"));
  1298. if($opentime['saturday']!=""){
  1299. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['saturday']." - ".$opentime['saturday']));
  1300. }else{
  1301. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1302. }
  1303.  
  1304. $businessMonday = $businessTiming->appendChild($xml->createElement("sunday"));
  1305. if($opentime['wednesday']!=""){
  1306. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['wednesday']." - ".$opentime['sunday']));
  1307. }else{
  1308. $businessMonday = $businessMonday->appendChild($xml->createTextNode(''));
  1309. }
  1310.  
  1311. $queryrow = sprintf("SELECT * FROM savedbusiness where userid = '%s' and businessid='%s'", mysql_real_escape_string($userid),mysql_real_escape_string($businessinfo['businessid']));
  1312.  
  1313. $businessSaved = $businessXML->appendChild($xml->createElement("businessSaved"));
  1314.  
  1315. $results = $database->query($queryrow) or die(mysql_error());
  1316. $resultrow = mysql_num_rows($results);
  1317. //print $resultrow;
  1318. if($resultrow >= 1){
  1319. //$messageoutput = "This business is already one of your loved businesses";
  1320.  
  1321. $businessSaved = $businessSaved->appendChild($xml->createTextNode("1"));
  1322. }
  1323. else{
  1324. $businessSaved = $businessSaved->appendChild($xml->createTextNode("0"));
  1325.  
  1326. }
  1327.  
  1328.  
  1329.  
  1330. if(mysql_num_rows($deals) >0){
  1331. $dealsXML = $root->appendChild($xml->createElement("deals"));
  1332.  
  1333. while($dealid = mysql_fetch_array($deals)){
  1334.  
  1335. $dealinfo = $business->getDealInfo($dealid['dealid']);
  1336. //$businessid = $business->getBusinessId($dealid['dealid']);
  1337. //$businessinfo = $business->getBusinessInfo($businessid);
  1338. //$dealCat = $business->getCat($dealinfo['catid']);
  1339. $dealImageLocation = $business->getDealImage($dealid['dealid']);
  1340. //$businessImageLocation = $business->getBusinessImage($businessid);
  1341.  
  1342. $deal = $dealsXML->appendChild($xml->createElement("deal"));
  1343.  
  1344. $dealid = $deal->appendChild($xml->createElement("dealId"));
  1345. $dealid = $dealid->appendChild($xml->createTextNode($dealinfo['dealid']));
  1346.  
  1347. $dealname = $deal->appendChild($xml->createElement("dealName"));
  1348. $dealname = $dealname->appendChild($xml->createTextNode($dealinfo['dealname']));
  1349.  
  1350. $dealDescription = $deal->appendChild($xml->createElement("dealDescription"));
  1351. $dealDescription = $dealDescription->appendChild($xml->createTextNode($dealinfo['desc']));
  1352.  
  1353. $dealPrice = $deal->appendChild($xml->createElement("dealPrice"));
  1354. $dealPrice = $dealPrice->appendChild($xml->createTextNode($dealinfo['dealoffer']));
  1355.  
  1356. $dealExpiryDate = $deal->appendChild($xml->createElement("dealExpiry"));
  1357. $dealExpiryDate = $dealExpiryDate->appendChild($xml->createTextNode($dealinfo['expirytimestamp']));
  1358.  
  1359. $dealImage = $deal->appendChild($xml->createElement("dealImage"));
  1360. $dealImage = $dealImage->appendChild($xml->createTextNode($dealImageLocation));
  1361.  
  1362. // $dealCategory = $deal->appendChild($xml->createElement("dealCategoryId"));
  1363. // $dealCategory = $dealCategory->appendChild($xml->createTextNode($dealinfo['catid']));
  1364. //
  1365. // $dealCatName = $deal->appendChild($xml->createElement("dealCatName"));
  1366. // $dealCatName = $dealCatName->appendChild($xml->createTextNode($dealCat));
  1367. //
  1368. // $lat = $deal->appendChild($xml->createElement("lat"));
  1369. // $lat = $lat->appendChild($xml->createTextNode($dealinfo['lattitude']));
  1370. //
  1371. // $long = $deal->appendChild($xml->createElement("long"));
  1372. // $long = $long->appendChild($xml->createTextNode($dealinfo['longitude']));
  1373. //
  1374. // $merchantId = $deal->appendChild($xml->createElement("merchantId"));
  1375. // $merchantId = $merchantId->appendChild($xml->createTextNode($dealinfo['businessid']));
  1376. //
  1377. // $merchantName = $deal->appendChild($xml->createElement("merchantName"));
  1378. // $merchantName = $merchantName->appendChild($xml->createTextNode($dealinfo['bname']));
  1379. //
  1380. // $merchantAddress = $deal->appendChild($xml->createElement("merchantAddress"));
  1381. // $merchantName = $merchantAddress->appendChild($xml->createTextNode($dealinfo['street'].", ".$dealinfo['suburb'].", ".$dealinfo['state']));
  1382. //
  1383.  
  1384.  
  1385. }
  1386. }
  1387.  
  1388. $xml->formatOutput=true;
  1389. $result = $xml->saveXML();
  1390.  
  1391. print $result;
  1392.  
  1393. }
  1394. //fetching full detail of business
  1395. function getBusinessInfo($businessid){
  1396. global $business;
  1397.  
  1398. $businessinfo = $business->getBusinessInfo($businessid);
  1399.  
  1400.  
  1401. $timing = array(
  1402. monday => $businessinfo['monday'],
  1403. tuesday => $businessinfo['tuesday'],
  1404. wednesday => $businessinfo['wednesday'],
  1405. thursday => $businessinfo['thursday'],
  1406. friday => $businessinfo['friday'],
  1407. saturday => $businessinfo['saturday'],
  1408. sunday => $businessinfo['sunday']);
  1409.  
  1410. // print_r($timing);
  1411.  
  1412.  
  1413. $opentime; $closetime;
  1414. foreach($timing as $day=>$time){
  1415.  
  1416. list($open, $close) = explode("-", $time);
  1417. list($openhour, $openminutes, $openseconds) = explode(":", $open);
  1418. list($closehour, $closeminutes, $closeseconds) = explode(":", $close);
  1419. if(isset($openhour) && isset($openminutes) && isset($openseconds)){
  1420. $opentime[$day]= date("h:i:s A", mktime($openhour,$openminutes, $openseconds));
  1421. $closetime[$day] =date("h:i:s A", mktime($closehour,$closeminutes, $closeseconds));
  1422.  
  1423. }
  1424. }
  1425.  
  1426.  
  1427. $businessImage = $business->getBusinessImage($businessid);
  1428. $businessCategory = $business->getCat($businessinfo['catid']);
  1429.  
  1430. $xml = new DOMDocument("1.0");
  1431. $root = $xml->appendChild($xml->createElement("response"));
  1432.  
  1433.  
  1434. $businessId = $root->appendChild($xml->createElement("businessID"));
  1435. $businessId = $businessId->appendChild($xml->createTextNode($businessinfo['businessid']));
  1436.  
  1437. $businessname = $root->appendChild($xml->createElement("businessName"));
  1438. $businessname = $businessname->appendChild($xml->createTextNode($businessinfo['bname']));
  1439.  
  1440. $businessDesc = $root->appendChild($xml->createElement("businessDescription"));
  1441. $businessDesc = $businessDesc->appendChild($xml->createTextNode($businessinfo['bdesc']));
  1442.  
  1443. $businessCatId = $root->appendChild($xml->createElement("businessCatId"));
  1444. $businessCatId = $businessCatId->appendChild($xml->createTextNode($businessinfo['catid']));
  1445.  
  1446. $businessCatName = $root->appendChild($xml->createElement("businessCatName"));
  1447. $businessCatName = $businessCatName->appendChild($xml->createTextNode($businessCategory));
  1448.  
  1449. $businessAdd = $root->appendChild($xml->createElement("businessAddress"));
  1450. $businessname = $businessAdd->appendChild($xml->createTextNode($businessinfo['street'].", ".$businessinfo['suburb'].", ".$businessinfo['state']));
  1451.  
  1452. $businessSite = $root->appendChild($xml->createElement("businessWebsite"));
  1453. $businessSite = $businessSite->appendChild($xml->createTextNode($businessinfo['site']));
  1454.  
  1455. $businessContact = $root->appendChild($xml->createElement("businessContact"));
  1456. $businessContact = $businessContact->appendChild($xml->createTextNode($businessinfo['phone']));
  1457.  
  1458. $businessLat = $root->appendChild($xml->createElement("businessLat"));
  1459. $businessLat = $businessLat->appendChild($xml->createTextNode($businessinfo['lattitude']));
  1460.  
  1461. $businessLong = $root->appendChild($xml->createElement("businessLong"));
  1462. $businessLong = $businessLong->appendChild($xml->createTextNode($businessinfo['longitude']));
  1463.  
  1464. $businessImg = $root->appendChild($xml->createElement("businessImage"));
  1465. $businessImage = $businessImg->appendChild($xml->createTextNode($businessImage));
  1466.  
  1467. $businessTiming = $root->appendChild($xml->createElement("timing"));
  1468.  
  1469. $businessMonday = $businessTiming->appendChild($xml->createElement("monday"));
  1470. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['monday']." - ".$closetime['monday']));
  1471.  
  1472. $businessMonday = $businessTiming->appendChild($xml->createElement("tuesday"));
  1473. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['tuesday']." - ".$closetime['tuesday']));
  1474.  
  1475. $businessMonday = $businessTiming->appendChild($xml->createElement("wednesday"));
  1476. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['wednesday']." - ".$closetime['wednesday']));
  1477.  
  1478. $businessMonday = $businessTiming->appendChild($xml->createElement("thursday"));
  1479. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['thursday']." - ".$closetime['thursday']));
  1480.  
  1481. $businessMonday = $businessTiming->appendChild($xml->createElement("friday"));
  1482. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['friday']." - ".$closetime['friday']));
  1483.  
  1484. $businessMonday = $businessTiming->appendChild($xml->createElement("saturday"));
  1485. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['saturday']." - ".$closetime['saturday']));
  1486.  
  1487. $businessMonday = $businessTiming->appendChild($xml->createElement("sunday"));
  1488. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['sunday']." - ".$closetime['sunday']));
  1489.  
  1490. $xml->formatOutput=true;
  1491. $result = $xml->saveXML();
  1492.  
  1493. print $result;
  1494. }
  1495.  
  1496. function getProfile($userid){
  1497. global $session, $database, $business;
  1498.  
  1499. $q = sprintf("SELECT users.*, savedbusiness.businessid from users LEFT JOIN
  1500. savedbusiness on users.userid = savedbusiness.userid WHERE users.userid= '%s'", mysql_real_escape_string($userid));
  1501.  
  1502. $result = $database->query($q) or die(mysql_error());
  1503.  
  1504. if(!$result || mysql_num_rows($result) < 1){
  1505. return;
  1506. }
  1507.  
  1508. $userinfo = mysql_fetch_assoc($result);
  1509.  
  1510. $query = sprintf(" SELECT catid from user_category where userid = '%s'", $userid);
  1511. $resultCategory = $database->query($query) or die(mysql_error());
  1512.  
  1513. if(mysql_num_rows($resultCategory) < 1){
  1514. $catids = Null;
  1515. }
  1516.  
  1517. else{
  1518. while($categoryid = mysql_fetch_assoc($resultCategory)){
  1519. $catids[] = $categoryid['catid'];
  1520. }
  1521. $catids = implode(",", $catids);
  1522. }
  1523.  
  1524. //$category = $business->getCat($categoryid['catid']);
  1525.  
  1526. $businessinfo = $business->getBusinessInfo($userinfo['businessid']);
  1527.  
  1528.  
  1529. $xml = new DOMDocument("1.0");
  1530. $root = $xml->appendChild($xml->createElement("response"));
  1531.  
  1532. $email = $root->appendChild($xml->createElement("email"));
  1533. $email = $email->appendChild($xml->createTextNode($userinfo['email']));
  1534.  
  1535. $gender = $root->appendChild($xml->createElement("gender"));
  1536. $gender = $gender->appendChild($xml->createTextNode($userinfo['gender']));
  1537.  
  1538. $savedBusiness = $root->appendChild($xml->createElement("savedBusiness"));
  1539. $saveBusiness = $savedBusiness->appendChild($xml->createTextNode($businessinfo['bname']));
  1540.  
  1541. $notification = $root->appendChild($xml->createElement("notification"));
  1542. $notification = $notification->appendChild($xml->createTextNode($userinfo['notification']));
  1543.  
  1544. $savedCategory = $root->appendChild($xml->createElement("savedCategory"));
  1545. $savedCategory = $savedCategory->appendChild($xml->createTextNode($catids));
  1546.  
  1547. $xml->formatOutput=true;
  1548. $result = $xml->saveXML();
  1549.  
  1550. print $result;
  1551.  
  1552.  
  1553.  
  1554.  
  1555. }
  1556.  
  1557. function changePassword($currentPass, $newPass, $userid){
  1558. global $database, $session;
  1559.  
  1560. $status = $database->confirmUserPassword($userid, md5($currentPass));
  1561.  
  1562.  
  1563.  
  1564. if($status == 1 || $status == 2){
  1565. $xml = new DOMDocument("1.0");
  1566.  
  1567. $response = $xml->appendChild($xml->createElement("response"));
  1568.  
  1569. $status = $response->appendChild($xml->createElement("status"));
  1570. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1571.  
  1572. $message = $response->appendChild($xml->createElement("message"));
  1573. $messageTxt = $message->appendChild($xml->createTextNode("Current Password or userid is invalid"));
  1574.  
  1575. $xml->formatOutput=true;
  1576. $result = $xml->saveXML();
  1577.  
  1578. print $result;
  1579. }
  1580.  
  1581. elseif($status == 0){
  1582. $q = sprintf("UPDATE users set password = '%s' where userid='%s'", md5($newPass), $userid);
  1583. $result = $database->query($q) or die(mysql_error());
  1584.  
  1585. if($result){
  1586. $xml = new DOMDocument("1.0");
  1587. $response = $xml->appendChild($xml->createElement("response"));
  1588.  
  1589. $status = $response->appendChild($xml->createElement("status"));
  1590. $statusTxt = $status->appendChild($xml->createTextNode("Success"));
  1591. $message = $response->appendChild($xml->createElement("message"));
  1592. $messageTxt = $message->appendChild($xml->createTextNode("Your Password has been changed successfully"));
  1593. $xml->formatOutput=true;
  1594. $result = $xml->saveXML();
  1595. print $result;
  1596. }
  1597. }
  1598. }
  1599.  
  1600. function saveFavCategory($catid, $userid, $mode){
  1601. global $database;
  1602. if($mode == "save"){
  1603.  
  1604. $queryrow = sprintf("SELECT * FROM user_category where userid = '%s' and catid='%s'", mysql_real_escape_string($userid),
  1605. mysql_real_escape_string($catid));
  1606.  
  1607. $results = $database->query($queryrow) or die(mysql_error());
  1608. $resultrow = mysql_num_rows($results);
  1609. //print $resultrow;
  1610. if($resultrow >= 1){
  1611. $messageoutput = "Category already Added as Favourite";
  1612.  
  1613. }
  1614. else{
  1615. $queryinsert = sprintf("INSERT INTO user_category VALUES('%s', '%s')",
  1616. mysql_real_escape_string($userid),
  1617. mysql_real_escape_string($catid));
  1618.  
  1619. $resultinsert = $database->query($queryinsert) or die(mysql_error());
  1620. $messageoutput ="Category added successfully to your favourite list";
  1621. }
  1622. }
  1623. elseif($mode == "delete"){
  1624.  
  1625. $query = sprintf("DELETE FROM user_category WHERE catid = '%s'", mysql_real_escape_string($catid));
  1626. $resultdelete = $database->query($query);
  1627. $messageoutput ="Category removed successfully from your fav list";
  1628. }
  1629.  
  1630. if($resultdelete || $resultinsert){
  1631. $xml = new DOMDocument("1.0");
  1632.  
  1633. $response = $xml->appendChild($xml->createElement("response"));
  1634.  
  1635. $status = $response->appendChild($xml->createElement("status"));
  1636. $responseText = $status->appendChild($xml->createTextNode("Success"));
  1637.  
  1638. $message = $response->appendChild($xml->createElement("message"));
  1639. $messageTxt = $message->appendChild($xml->createTextNode($messageoutput));
  1640.  
  1641. $xml->formatOutput=true;
  1642. $result = $xml->saveXML();
  1643.  
  1644. print $result;
  1645. }
  1646.  
  1647. else{
  1648. $xml = new DOMDocument("1.0");
  1649.  
  1650. $response = $xml->appendChild($xml->createElement("response"));
  1651.  
  1652. $status = $response->appendChild($xml->createElement("status"));
  1653. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1654.  
  1655. $message = $response->appendChild($xml->createElement("message"));
  1656. $message = $message->appendChild($xml->createTextNode($messageoutput));
  1657.  
  1658. $xml->formatOutput=true;
  1659. $result = $xml->saveXML();
  1660.  
  1661. print $result;
  1662.  
  1663.  
  1664. }
  1665. }
  1666.  
  1667. function saveFavBusiness($businessid, $userid, $mode){
  1668. global $database;
  1669. if($mode == "save"){
  1670.  
  1671. $queryrow = sprintf("SELECT * FROM savedbusiness where userid = '%s' and businessid='%s'", mysql_real_escape_string($userid),
  1672. mysql_real_escape_string($businessid));
  1673.  
  1674. $results = $database->query($queryrow) or die(mysql_error());
  1675. $resultrow = mysql_num_rows($results);
  1676. //print $resultrow;
  1677. if($resultrow >= 1){
  1678. $messageoutput = "This place is already one of your 'myLoved' places";
  1679.  
  1680. }
  1681. else{
  1682. $queryinsert = sprintf("INSERT INTO savedbusiness VALUES('%s', '%s')",
  1683. mysql_real_escape_string($userid),
  1684. mysql_real_escape_string($businessid));
  1685. $resultinsert = $database->query($queryinsert);
  1686.  
  1687. $queryinsertloved = sprintf("INSERT INTO loved (userid,businessid,action) VALUES('%s', '%s','0')",
  1688. mysql_real_escape_string($userid),
  1689. mysql_real_escape_string($businessid));
  1690.  
  1691. $resultinsertloved = $database->query($queryinsertloved) or die(mysql_error());
  1692. }
  1693. }
  1694. elseif($mode == "delete"){
  1695.  
  1696. $query = sprintf("DELETE FROM savedbusiness WHERE businessid = '%s' and userid = '%s'",
  1697. mysql_real_escape_string($businessid),
  1698. mysql_real_escape_string($userid));
  1699. $resultdelete = $database->query($query);
  1700.  
  1701. $queryloved = sprintf("INSERT INTO loved (userid,businessid,action) VALUES('%s', '%s','1')",
  1702. mysql_real_escape_string($userid),
  1703. mysql_real_escape_string($businessid)
  1704. );
  1705. $resultdeleteloved = $database->query($queryloved);
  1706.  
  1707.  
  1708. }
  1709.  
  1710. if($resultdelete || $resultinsert){
  1711. $xml = new DOMDocument("1.0");
  1712.  
  1713. $response = $xml->appendChild($xml->createElement("response"));
  1714.  
  1715. $status = $response->appendChild($xml->createElement("status"));
  1716. $responseText = $status->appendChild($xml->createTextNode("Success"));
  1717.  
  1718. $message = $response->appendChild($xml->createElement("message"));
  1719. $messageTxt = $message->appendChild($xml->createTextNode("Your Favourite business has been updated successfully"));
  1720.  
  1721. $xml->formatOutput=true;
  1722. $result = $xml->saveXML();
  1723.  
  1724. print $result;
  1725. }
  1726.  
  1727. else{
  1728. $xml = new DOMDocument("1.0");
  1729.  
  1730. $response = $xml->appendChild($xml->createElement("response"));
  1731.  
  1732. $status = $response->appendChild($xml->createElement("status"));
  1733. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1734.  
  1735. $message = $response->appendChild($xml->createElement("message"));
  1736. $message = $message->appendChild($xml->createTextNode($messageoutput));
  1737.  
  1738. $xml->formatOutput=true;
  1739. $result = $xml->saveXML();
  1740.  
  1741. print $result;
  1742. }
  1743.  
  1744.  
  1745.  
  1746. }
  1747.  
  1748. function updateNotificationStatus($userid, $status){
  1749. global $database;
  1750.  
  1751. $q = sprintf("SELECT * FROM push where userid='%s'", mysql_real_escape_string($userid));
  1752. $result = mysql_num_rows($database->query($q));
  1753.  
  1754. if($status == "on"){
  1755. global $database;
  1756. $query = sprintf("UPDATE users SET users.notification = '1' WHERE userid='%s'", mysql_real_escape_string($userid));
  1757.  
  1758. $result = $database->query($query) or die(mysql_error());
  1759. $outputMsg = "Notification has been turned On Successfully";
  1760. }
  1761.  
  1762. if($status == "off"){
  1763. global $database;
  1764. $query = sprintf("UPDATE users SET users.notification = '0' WHERE userid='%s'", mysql_real_escape_string($userid));
  1765.  
  1766. $result = $database->query($query) or die(mysql_error());
  1767. $outputMsg = "Notification has been turned Off Successfully";
  1768. }
  1769.  
  1770.  
  1771. if($result){
  1772. $xml = new DOMDocument("1.0");
  1773.  
  1774. $response = $xml->appendChild($xml->createElement("response"));
  1775.  
  1776. $status = $response->appendChild($xml->createElement("status"));
  1777. $responseText = $status->appendChild($xml->createTextNode("Success"));
  1778.  
  1779. $message = $response->appendChild($xml->createElement("message"));
  1780. $messageTxt = $message->appendChild($xml->createTextNode($outputMsg));
  1781.  
  1782. $xml->formatOutput=true;
  1783. $result = $xml->saveXML();
  1784.  
  1785. print $result;
  1786. }
  1787.  
  1788. else{
  1789. $xml = new DOMDocument("1.0");
  1790.  
  1791. $response = $xml->appendChild($xml->createElement("response"));
  1792.  
  1793. $status = $response->appendChild($xml->createElement("status"));
  1794. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  1795.  
  1796. $message = $response->appendChild($xml->createElement("message"));
  1797. $message = $message->appendChild($xml->createTextNode($outputMsg));
  1798.  
  1799. $xml->formatOutput=true;
  1800. $result = $xml->saveXML();
  1801.  
  1802. print $result;
  1803. }
  1804. }
  1805.  
  1806. function getFavBusiness($userid, $catid = NULL){
  1807. global $database, $business, $session;
  1808.  
  1809. if(isset($catid) && strlen(trim($catid)) !== 0){
  1810.  
  1811. $allCatIds = getTree($catid);
  1812. $xml = new DOMDocument("1.0");
  1813. $root = $xml->appendChild($xml->createElement("response"));
  1814.  
  1815. foreach($allCatIds as $catid){
  1816.  
  1817. $q = sprintf("SELECT business.businessid, savedbusiness.* FROM business
  1818. INNER JOIN savedbusiness ON business.businessid= savedbusiness.businessid
  1819. WHERE business.catid= '$catid'
  1820. AND savedbusiness.userid = '%s'", mysql_real_escape_string($userid));
  1821.  
  1822. $data = $database->query($q) or die(mysql_error());
  1823.  
  1824.  
  1825.  
  1826. while($businessinfo = mysql_fetch_assoc($data)){
  1827. $bid = $businessinfo['businessid'];
  1828. $image = $business->getBusinessImage($bid);
  1829.  
  1830. $info = $business->getBusinessInfo($bid);
  1831. $businessCategoryName = $business->getCat($businessinfo['catid']);
  1832. $time = gmdate("Y-m-d H:i:s");
  1833. $q = sprintf("SELECT * FROM deals WHERE businessid = '%s' AND deals.expirytimestamp >= '$time' AND UTC_TIMESTAMP() >= deals.dealtimestamp AND deals.status = 1",
  1834. mysql_real_escape_string($bid));
  1835.  
  1836. $resultdeals = $database->query($q) or die(mysql_error());
  1837.  
  1838. $numrow = mysql_num_rows($resultdeals);
  1839.  
  1840.  
  1841. $businessnode = $root->appendChild($xml->createElement("business"));
  1842.  
  1843. $businessid = $businessnode->appendChild($xml->createElement("businessid"));
  1844. $businessid = $businessid->appendChild($xml->createTextNode($info['businessid']));
  1845.  
  1846. $businessname = $businessnode->appendChild($xml->createElement("businessname"));
  1847. $businessname = $businessname->appendChild($xml->createTextNode($info['bname']));
  1848.  
  1849. $businessDesc = $businessnode->appendChild($xml->createElement("businessDescription"));
  1850. $businessDesc = $businessDesc->appendChild($xml->createTextNode($info['bdesc']));
  1851.  
  1852. $businessCategory = $businessnode->appendChild($xml->createElement("businessCatId"));
  1853. $businessCategory = $businessCategory->appendChild($xml->createTextNode($info['catid']));
  1854.  
  1855. $businessCatName = $businessnode->appendChild($xml->createElement("businessCatName"));
  1856. $businessCatName = $businessCatName->appendChild($xml->createTextNode($businessCategoryName));
  1857.  
  1858. $businessAdd = $businessnode->appendChild($xml->createElement("businessAddress"));
  1859. $businessname = $businessAdd->appendChild($xml->createTextNode($info['suburb']));
  1860.  
  1861. $businessSite = $businessnode->appendChild($xml->createElement("businessWebsite"));
  1862. $businessSite = $businessSite->appendChild($xml->createTextNode($info['site']));
  1863.  
  1864. $businessContact = $businessnode->appendChild($xml->createElement("businessContact"));
  1865. $businessContact = $businessContact->appendChild($xml->createTextNode($info['phone']));
  1866.  
  1867. $businessLat = $businessnode->appendChild($xml->createElement("businessLat"));
  1868. $businessLat = $businessLat->appendChild($xml->createTextNode($info['lattitude']));
  1869.  
  1870. $businessLong = $businessnode->appendChild($xml->createElement("businessLong"));
  1871. $businessLong = $businessLong->appendChild($xml->createTextNode($info['longitude']));
  1872.  
  1873. $businessImg = $businessnode->appendChild($xml->createElement("businessImage"));
  1874. $businessImage = $businessImg->appendChild($xml->createTextNode($image));
  1875.  
  1876. $businessDeals = $businessnode->appendChild($xml->createElement("availableDeals"));
  1877. $businessDeals = $businessDeals->appendChild($xml->createTextNode($numrow));
  1878.  
  1879.  
  1880.  
  1881. }
  1882. }
  1883.  
  1884. $xml->formatOutput=true;
  1885. $result = $xml->saveXML();
  1886.  
  1887. print $result;
  1888.  
  1889. }
  1890.  
  1891. else{
  1892. $info = $business->getSavedBusiness($userid);
  1893. $num = count($info);
  1894. $xml = new DOMDocument("1.0");
  1895. $root = $xml->appendChild($xml->createElement("response"));
  1896.  
  1897. for($i=0; $i<$num; $i++){
  1898. //-------CHECKING FOR THE DEALS NOW---------//
  1899.  
  1900. $image = $business->getBusinessImage($info[$i]['businessid']);
  1901. $businessCategoryName = $business->getCat($info[$i]['catid']);
  1902. $time = gmdate("Y-m-d H:i:s");
  1903. $q = sprintf("SELECT * FROM deals WHERE businessid = '%s' AND deals.expirytimestamp >= '$time' AND UTC_TIMESTAMP() >= deals.dealtimestamp AND deals.status = 1",
  1904. mysql_real_escape_string($info[$i]['businessid']));
  1905.  
  1906. $resultdeals = $database->query($q) or die(mysql_error());
  1907.  
  1908. $numrow = mysql_num_rows($resultdeals);
  1909.  
  1910.  
  1911. $businessnode = $root->appendChild($xml->createElement("business"));
  1912.  
  1913. $businessid = $businessnode->appendChild($xml->createElement("businessid"));
  1914. $businessid = $businessid->appendChild($xml->createTextNode($info[$i]['businessid']));
  1915.  
  1916. $businessname = $businessnode->appendChild($xml->createElement("businessname"));
  1917. $businessname = $businessname->appendChild($xml->createTextNode($info[$i]['bname']));
  1918.  
  1919. $businessDesc = $businessnode->appendChild($xml->createElement("businessDescription"));
  1920. $businessDesc = $businessDesc->appendChild($xml->createTextNode($info[$i]['bdesc']));
  1921.  
  1922. $businessCategory = $businessnode->appendChild($xml->createElement("businessCatId"));
  1923. $businessCategory = $businessCategory->appendChild($xml->createTextNode($info[$i]['catid']));
  1924.  
  1925. $businessCatName = $businessnode->appendChild($xml->createElement("businessCatName"));
  1926. $businessCatName = $businessCatName->appendChild($xml->createTextNode($businessCategoryName));
  1927.  
  1928. $businessAdd = $businessnode->appendChild($xml->createElement("businessAddress"));
  1929. $businessname = $businessAdd->appendChild($xml->createTextNode($info[$i]['suburb']));
  1930.  
  1931. $businessSite = $businessnode->appendChild($xml->createElement("businessWebsite"));
  1932. $businessSite = $businessSite->appendChild($xml->createTextNode($info[$i]['site']));
  1933.  
  1934. $businessContact = $businessnode->appendChild($xml->createElement("businessContact"));
  1935. $businessContact = $businessContact->appendChild($xml->createTextNode($info[$i]['phone']));
  1936.  
  1937. $businessLat = $businessnode->appendChild($xml->createElement("businessLat"));
  1938. $businessLat = $businessLat->appendChild($xml->createTextNode($info[$i]['lattitude']));
  1939.  
  1940. $businessLong = $businessnode->appendChild($xml->createElement("businessLong"));
  1941. $businessLong = $businessLong->appendChild($xml->createTextNode($info[$i]['longitude']));
  1942.  
  1943. $businessImg = $businessnode->appendChild($xml->createElement("businessImage"));
  1944. $businessImage = $businessImg->appendChild($xml->createTextNode($image));
  1945.  
  1946. $businessDeals = $businessnode->appendChild($xml->createElement("availableDeals"));
  1947. $businessDeals = $businessDeals->appendChild($xml->createTextNode($numrow));
  1948.  
  1949.  
  1950. }
  1951.  
  1952. $xml->formatOutput=true;
  1953. $result = $xml->saveXML();
  1954.  
  1955. print $result;
  1956. }
  1957.  
  1958. }
  1959.  
  1960. function updateFavCategories($subcatids=NULL, $userid){
  1961. global $database;
  1962.  
  1963.  
  1964. $querydel = sprintf("DELETE FROM user_category WHERE userid = '%s'", mysql_real_escape_string($userid));
  1965. $resultdel = $database->query($querydel) or die(mysql_error());
  1966.  
  1967. if($resultdel && strlen(trim($subcatids)) !== 0){
  1968.  
  1969. $q = "INSERT INTO user_category(userid, catid) VALUES ";
  1970.  
  1971. $subcatids = explode("," ,$subcatids);
  1972. foreach ($subcatids as $catid){
  1973. $values[] = "('".$userid."','".$catid."')";
  1974. }
  1975.  
  1976. $newvalues = implode(",", $values);
  1977. $q .= $newvalues;
  1978.  
  1979. $result = $database->query($q) or die(mysql_error());
  1980. }
  1981. file_put_contents("response.txt", $subcatids);
  1982. if($result){
  1983. $xml = new DOMDocument("1.0");
  1984.  
  1985. $response = $xml->appendChild($xml->createElement("response"));
  1986.  
  1987. $status = $response->appendChild($xml->createElement("status"));
  1988. $responseText = $status->appendChild($xml->createTextNode("Success"));
  1989.  
  1990. $message = $response->appendChild($xml->createElement("message"));
  1991. $messageTxt = $message->appendChild($xml->createTextNode("Your fav category list has been Updated"));
  1992.  
  1993. $xml->formatOutput=true;
  1994. $result = $xml->saveXML();
  1995.  
  1996. print $result;
  1997. }
  1998.  
  1999. else{
  2000. $xml = new DOMDocument("1.0");
  2001.  
  2002. $response = $xml->appendChild($xml->createElement("response"));
  2003.  
  2004. $status = $response->appendChild($xml->createElement("status"));
  2005. $responseText = $status->appendChild($xml->createTextNode("Failure"));
  2006.  
  2007. $message = $response->appendChild($xml->createElement("message"));
  2008. $message = $message->appendChild($xml->createTextNode("Category list update failed. Please try again later"));
  2009.  
  2010. $xml->formatOutput=true;
  2011. $result = $xml->saveXML();
  2012.  
  2013. print $result;
  2014. }
  2015. }
  2016.  
  2017. function searchBusiness($business_name,$userid)
  2018. {
  2019. global $database, $session,$business;
  2020. $querySearch = "select * FROM business WHERE bname like '%".$business_name."%'";
  2021. $resultSearch = $database->query($querySearch) or die(mysql_error());
  2022.  
  2023.  
  2024.  
  2025. $xml = new DOMDocument("1.0");
  2026. $root = $xml->appendChild($xml->createElement("response"));
  2027. $opentime; $closetime;
  2028. while($business_search = mysql_fetch_array($resultSearch)){
  2029.  
  2030.  
  2031. $businessid=$business_search['businessid'];
  2032. $businessinfo = $business->getBusinessInfo($businessid);
  2033. $queryrow = sprintf("SELECT * FROM savedbusiness where userid = '%s' and businessid='%s'", mysql_real_escape_string($userid),
  2034. mysql_real_escape_string($businessid));
  2035.  
  2036. $results = $database->query($queryrow) or die(mysql_error());
  2037. $resultrow = mysql_num_rows($results);
  2038.  
  2039. if(isset($businessinfo['monday']))
  2040. {
  2041. $timing = array('monday' => $businessinfo['monday'],
  2042. 'tuesday' => $businessinfo['tuesday'],
  2043. 'wednesday' => $businessinfo['wednesday'],
  2044. 'thursday' => $businessinfo['thursday'],
  2045. 'friday' => $businessinfo['friday'],
  2046. 'saturday' => $businessinfo['saturday'],
  2047. 'sunday' => $businessinfo['sunday']);
  2048.  
  2049. }
  2050. foreach($timing as $day=>$time)
  2051. {
  2052. if($time!='')
  2053. {
  2054. list($open, $close) = explode("-", $time);
  2055. }
  2056. list($openhour, $openminutes, $openseconds) = explode(":", $open);
  2057. list($closehour, $closeminutes, $closeseconds) = explode(":", $close);
  2058. if(isset($openhour) && isset($openminutes) && isset($openseconds))
  2059. {
  2060. $opentime[$day]= date("h:i:s A", mktime($openhour,$openminutes, $openseconds));
  2061. $closetime[$day] =date("h:i:s A", mktime($closehour,$closeminutes, $closeseconds));
  2062.  
  2063. }
  2064. }
  2065.  
  2066. $businessImage = $business->getBusinessImage($business_search['businessid']);
  2067. $businessCategory = $business->getCat($business_search['catid']);
  2068.  
  2069. $XMLbusiness = $root->appendChild($xml->createElement("business"));
  2070.  
  2071. $businessid = $XMLbusiness->appendChild($xml->createElement("businessid"));
  2072. $businessid = $businessid->appendChild($xml->createTextNode($business_search['businessid']));
  2073.  
  2074. $businessname = $XMLbusiness->appendChild($xml->createElement("businessname"));
  2075. $businessname = $businessname->appendChild($xml->createTextNode($business_search['bname']));
  2076.  
  2077. $businessDesc = $XMLbusiness->appendChild($xml->createElement("businessDescription"));
  2078. $businessDesc = $businessDesc->appendChild($xml->createTextNode($business_search['bdesc']));
  2079.  
  2080. $businessCatId = $XMLbusiness->appendChild($xml->createElement("businessCatId"));
  2081. $businessCatId = $businessCatId->appendChild($xml->createTextNode($business_search['catid']));
  2082.  
  2083. $businessCatName = $XMLbusiness->appendChild($xml->createElement("businessCatName"));
  2084. $businessCatName = $businessCatName->appendChild($xml->createTextNode($businessCategory));
  2085.  
  2086. $businessAdd = $XMLbusiness->appendChild($xml->createElement("businessAddress"));
  2087. $businessname = $businessAdd->appendChild($xml->createTextNode($business_search['street'].", ".$business_search['suburb'].", ".$business_search['state']));
  2088.  
  2089. $businessSite = $XMLbusiness->appendChild($xml->createElement("businessWebsite"));
  2090. $businessSite = $businessSite->appendChild($xml->createTextNode($business_search['site']));
  2091.  
  2092. $businessContact = $XMLbusiness->appendChild($xml->createElement("businessContact"));
  2093. $businessContact = $businessContact->appendChild($xml->createTextNode($business_search['phone']));
  2094.  
  2095. $businessLat = $XMLbusiness->appendChild($xml->createElement("businessLat"));
  2096. $businessLat = $businessLat->appendChild($xml->createTextNode($business_search['lattitude']));
  2097.  
  2098. $businessLong = $XMLbusiness->appendChild($xml->createElement("businessLong"));
  2099. $businessLong = $businessLong->appendChild($xml->createTextNode($business_search['longitude']));
  2100.  
  2101. $businessImg = $XMLbusiness->appendChild($xml->createElement("businessImage"));
  2102. $businessImage = $businessImg->appendChild($xml->createTextNode($businessImage));
  2103.  
  2104. $businessTiming = $XMLbusiness->appendChild($xml->createElement("businessTiming"));
  2105. if(isset($opentime['monday']) && isset($closetime['monday']))
  2106. {
  2107. $businessMonday = $XMLbusiness->appendChild($xml->createElement("businessMonday"));
  2108. $businessMonday = $businessMonday->appendChild($xml->createTextNode($opentime['monday']." - ".$closetime['monday']));
  2109. }
  2110. if(isset($opentime['tuesday']) && isset($closetime['tuesday']))
  2111. {
  2112. $businessTuesday = $XMLbusiness->appendChild($xml->createElement("businessTuesday"));
  2113. $businessTuesday = $businessTuesday->appendChild($xml->createTextNode($opentime['tuesday']." - ".$closetime['tuesday']));
  2114. }
  2115. if(isset($opentime['wednesday']) && isset($closetime['wednesday']))
  2116. {
  2117. $businessWednesday = $XMLbusiness->appendChild($xml->createElement("businessWednesday"));
  2118. $businessWednesday = $businessWednesday->appendChild($xml->createTextNode($opentime['wednesday']." - ".$closetime['wednesday']));
  2119. }
  2120. if(isset($opentime['thursday']) && isset($closetime['thursday']))
  2121. {
  2122. $businessThursday = $XMLbusiness->appendChild($xml->createElement("businessThursday"));
  2123. $businessThursday = $businessThursday->appendChild($xml->createTextNode($opentime['thursday']." - ".$closetime['thursday']));
  2124. }
  2125. if(isset($opentime['friday']) && isset($closetime['friday']))
  2126. {
  2127. $businessFriday = $XMLbusiness->appendChild($xml->createElement("businessFriday"));
  2128. $businessFriday = $businessFriday->appendChild($xml->createTextNode($opentime['friday']." - ".$closetime['friday']));
  2129. }
  2130. if(isset($opentime['saturday']) && isset($closetime['saturday']))
  2131. {
  2132. $businessSaturday = $XMLbusiness->appendChild($xml->createElement("businessSaturday"));
  2133. $businessSaturday = $businessSaturday->appendChild($xml->createTextNode($opentime['saturday']." - ".$closetime['saturday']));
  2134. }
  2135. if(isset($opentime['sunday']) && isset($closetime['sunday']))
  2136. {
  2137. $businessSunday = $XMLbusiness->appendChild($xml->createElement("businessSunday"));
  2138. $businessSunday = $businessSunday->appendChild($xml->createTextNode($opentime['sunday']." - ".$closetime['sunday']));
  2139. }
  2140. $businessSaved = $XMLbusiness->appendChild($xml->createElement("businessSaved"));
  2141. $businessSaved = $businessSaved->appendChild($xml->createTextNode($resultrow));
  2142.  
  2143. }
  2144. $xml->formatOutput=true;
  2145. $myXML = $xml->saveXML();
  2146. print $myXML;
  2147.  
  2148. }
  2149.  
  2150. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement