PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/MobileApp/SlowPub_webservicesE.php

http://slowpub-development.googlecode.com/
PHP | 512 lines | 394 code | 50 blank | 68 comment | 33 complexity | da22ddd294ffcb3325e0b6c72bb84b62 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. *
  5. * @version $Id$
  6. * @copyright 2011
  7. */
  8. try{
  9. $dbc = new DataBaseConnectivity();
  10. $dbc->connectToDB();
  11. echo '{"PayLoad":';
  12. echo '{';
  13. $dbc->getFoodMenu();
  14. $dbc->getDrinkCollection();
  15. $dbc->getWeeklySpecials();
  16. $dbc->getEvents();
  17. $dbc->getSuppliers();
  18. $dbc->getAdditionalInformation();
  19. echo '},';
  20. echo '"ErrorCheck":';
  21. $dbc->errorCheck();
  22. echo ',';
  23. echo '"Message":';
  24. $dbc->getMessages();
  25. echo '}';
  26. $dbc->closeConnection();
  27. }catch(Exception $e){
  28. echo 'Message:'.$e->getMessage();
  29. }
  30. class DataBaseConnectivity{
  31. var $connection;
  32. var $stringMessage = array();
  33. function connectToDB(){
  34. $con = mysql_connect("localhost","tester","Allegjdm93");
  35. //$con = mysql_connect("mysql15.000webhost.com","a3813951_mobile","Allegjdm93");
  36. if(!$con){
  37. //echo "Could not connect to db";
  38. throw new Exception("Could not connect to db.");
  39. die('Could not connect: ' . mysql_error());
  40. }
  41. mysql_select_db("test_empty");
  42. //mysql_select_db("a3813951_mobile");
  43. $this->connection = $con;
  44. }
  45. function closeConnection(){
  46. mysql_close($this->connection);
  47. }
  48. function getFoodMenu(){
  49. echo '"FoodMenu":{';
  50. $this->getRegularMenu();
  51. $this->getDailyMenu();
  52. echo '}';
  53. }
  54. function getRegularMenu(){
  55. $select = 1;
  56. $flag = 0;
  57. echo '"RegularMenu":';
  58. do{
  59. $loopCount = 1;
  60. $jsonString = '';
  61. switch($select){
  62. case 1:
  63. $query = "SELECT * FROM reg_menu WHERE type = 'soup_salad_appy'";
  64. $result = mysql_query($query);
  65. $numberOfFields = mysql_num_rows($result);
  66. if($numberOfFields > 0) {
  67. $flag = 1;
  68. $jsonString .= '[';
  69. }
  70. $jsonString .= '{"Name":"Soup, Salads & Appys",';
  71. break;
  72. case 2:
  73. $query = "SELECT * FROM reg_menu WHERE type = 'main_forno'";
  74. $result = mysql_query($query);
  75. $numberOfFields = mysql_num_rows($result);
  76. if($numberOfFields > 0 && $flag == 0) {
  77. $flag = 1;
  78. $jsonString .= '[';
  79. }
  80. $jsonString .= '{"Name":"Main & Forno",';
  81. break;
  82. case 3:
  83. $query = "SELECT * FROM reg_menu WHERE type = 'sandwich_pasta'";
  84. $result = mysql_query($query);
  85. $numberOfFields = mysql_num_rows($result);
  86. if($numberOfFields > 0 && $flag == 0) {
  87. $flag = 1;
  88. $jsonString .= '[';
  89. }
  90. $jsonString .= '{"Name":"Pasta & Sandwhich",';
  91. break;
  92. }
  93. if($numberOfFields > 0){
  94. $jsonString .= '"items":[';
  95. while($row = mysql_fetch_array($result)){
  96. $jsonString .= '{'
  97. .'"Name":"'.$row['name'].'",'
  98. .'"Description":"'.$row['description'].'",'
  99. .'"Price":"'.$row['price'].'",'
  100. .'"Picture":"'.$row['picture'].'"'
  101. .'}';
  102. //add comma if
  103. if($loopCount < $numberOfFields){
  104. $jsonString .= ',';
  105. $loopCount++;
  106. }
  107. }
  108. $jsonString .= ']}';
  109. if($select < 3){
  110. $jsonString .= ',';
  111. }
  112. echo $jsonString;
  113. }else{
  114. //$this->addMessage("No items available.");
  115. }
  116. $select++;
  117. }while($select <= 3);
  118. if($flag == 0){
  119. echo '"No menu available at the moment."';
  120. }else{
  121. echo "]";
  122. }
  123. }
  124. function getDailyMenu(){
  125. //Get daily menu
  126. $query = "SELECT * FROM daily_menu";
  127. $result = mysql_query($query);
  128. $numberOfFields = mysql_num_rows($result);
  129. $loopCount = 1;
  130. $jsonString = ',"DailyMenu":';
  131. if($numberOfFields > 0){
  132. $jsonString .= '[';
  133. while($row = mysql_fetch_array($result)){
  134. $jsonString .= '{'
  135. .'"Name":"'.$row['name'].'",'
  136. .'"Description":"'.$row['description'].'",'
  137. .'"Price":"'.$row['price'].'",'
  138. .'"Picture":"'.$row['picture'].'"'
  139. .'}';
  140. //add comma if
  141. if($loopCount < $numberOfFields){
  142. $jsonString .= ',';
  143. $loopCount++;
  144. }
  145. }
  146. $jsonString .= ']';
  147. }else{
  148. //$this->addMessage("No daily menu available.");
  149. $jsonString .= '"No menu available at the moment."';
  150. }
  151. echo $jsonString;
  152. }
  153. function getDrinkCollection(){
  154. echo ',"DrinkCollection":{';
  155. $this->getOffsale();
  156. $this->getOnTap();
  157. $this->getBottleCans();
  158. $this->getHouse();
  159. echo '}';
  160. }
  161. function getOffsale(){
  162. $jsonString = '"Offsale":';
  163. $jsonString .= '{';
  164. $query = "SELECT 'offsaleText' FROM details";
  165. $result = mysql_query($query);
  166. $row = mysql_fetch_array($result);
  167. $jsonString .= '"Text":"'.$row['offsaleText'].'"';
  168. $query = "SELECT * FROM `offsale_prices`";
  169. $result = mysql_query($query);
  170. $numberOfFields = mysql_num_rows($result);
  171. $loopCount = 1;
  172. $jsonString .= ',"Prices":';
  173. if($numberOfFields > 0){
  174. $jsonString .= '[';
  175. while($row = mysql_fetch_array($result)){
  176. $jsonString .= '{'
  177. .'"Name":"'.$row['name'].'",'
  178. .'"Price":"'.$row['price'].'"'
  179. .'}';
  180. //add comma if
  181. if($loopCount < $numberOfFields){
  182. $jsonString .= ',';
  183. $loopCount++;
  184. }
  185. }
  186. $jsonString .= ']';
  187. }else{
  188. $jsonString .= '"No prices available at the moment."';
  189. }
  190. $query = "SELECT * FROM drink_collection WHERE offSale = TRUE";
  191. $result = mysql_query($query);
  192. $numberOfFields = mysql_num_rows($result);
  193. $loopCount = 1;
  194. $jsonString .= ',"Drinks":';
  195. if($numberOfFields > 0){
  196. $jsonString .= '[';
  197. while($row = mysql_fetch_array($result)){
  198. $jsonString .= '{'
  199. .'"Name":"'.$row['name'].'",'
  200. .'"Legend":"'.$row['legend'].'",'
  201. .'"Type":"'.$row['type'].'"'
  202. .'}';
  203. //add comma if
  204. if($loopCount < $numberOfFields){
  205. $jsonString .= ',';
  206. $loopCount++;
  207. }
  208. }
  209. $jsonString .= '],';
  210. }else{
  211. $jsonString .= '"No offsale drinks available at the moment."';
  212. //$this->addMessage("No offsale drinks available.");
  213. }
  214. $jsonString .= '}';
  215. echo $jsonString;
  216. }
  217. function getOnTap(){
  218. $jsonString = ',"OnTap":';
  219. $jsonString .= '{';
  220. $query = "SELECT 'onTapText' FROM details";
  221. $result = mysql_query($query);
  222. $row = mysql_fetch_array($result);
  223. $jsonString .= '"Text":"'.$row['onTapText'].'"';
  224. $query = "SELECT * FROM drink_collection WHERE onTap = TRUE";
  225. $result = mysql_query($query);
  226. $numberOfFields = mysql_num_rows($result);
  227. $loopCount = 1;
  228. $jsonString .= ',"Drinks":';
  229. if($numberOfFields > 0){
  230. $jsonString .= "[";
  231. while($row = mysql_fetch_array($result)){
  232. $jsonString .= '{'
  233. .'"Name":"'.$row['name'].'",'
  234. .'"Origin":"'.$row['origin'].'",'
  235. .'"Price":"'.$row['price'].'",'
  236. .'"Type":"'.$row['type'].'"'
  237. .'}';
  238. //add comma if
  239. if($loopCount < $numberOfFields){
  240. $jsonString .= ',';
  241. $loopCount++;
  242. }
  243. }
  244. $jsonString .= ']';
  245. }else{
  246. $jsonString .= '"No on tap drinks available at the moment.",';
  247. //$this->addMessage("No drinks on tap available.");
  248. }
  249. $jsonString .= '}';
  250. echo $jsonString;
  251. }
  252. function getBottleCans(){
  253. $jsonString = ',"BottleCans":';
  254. $query = "SELECT * FROM drink_collection WHERE bottleCans = TRUE";
  255. $result = mysql_query($query);
  256. $numberOfFields = mysql_num_rows($result);
  257. $loopCount = 1;
  258. if($numberOfFields > 0){
  259. $jsonString .= "[";
  260. while($row = mysql_fetch_array($result)){
  261. $jsonString .= '{'
  262. .'"Name":"'.$row['name'].'",'
  263. .'"Origin":"'.$row['origin'].'",'
  264. .'"Price":"'.$row['price'].'",'
  265. .'"Type":"'.$row['type'].'"'
  266. .'}';
  267. //add comma if
  268. if($loopCount < $numberOfFields){
  269. $jsonString .= ',';
  270. $loopCount++;
  271. }
  272. }
  273. $jsonString .= ']';
  274. }else{
  275. $jsonString .= '"No bottle or can drinks available at the moment."';
  276. //$this->addMessage("No bottle or can drinks available.");
  277. }
  278. echo $jsonString;
  279. }
  280. function getHouse(){
  281. $jsonString = ',"House":';
  282. $query = "SELECT * FROM drink_collection WHERE house = TRUE";
  283. $result = mysql_query($query);
  284. $numberOfFields = mysql_num_rows($result);
  285. $loopCount = 1;
  286. if($numberOfFields > 0){
  287. $jsonString .= "[";
  288. while($row = mysql_fetch_array($result)){
  289. $jsonString .= '{'
  290. .'"Name":"'.$row['name'].'",'
  291. .'"Legend":"'.$row['legend'].'",'
  292. .'"Type":"'.$row['type'].'"'
  293. .'}';
  294. //add comma if
  295. if($loopCount < $numberOfFields){
  296. $jsonString .= ',';
  297. $loopCount++;
  298. }
  299. }
  300. $jsonString .= ']';
  301. }else{
  302. $jsonString .= '"No house drinks available at the moment."';
  303. //$this->addMessage("No house drinks available.");
  304. }
  305. echo $jsonString;
  306. }
  307. function getWeeklySpecials(){
  308. $query = "SELECT * FROM weekly_special" ;
  309. $result = mysql_query($query);
  310. $numberOfFields = mysql_num_rows($result);
  311. $loopCount = 1;
  312. $jsonString = ',"WeeklySpecials":';
  313. if($numberOfFields > 0){
  314. $jsonString .= '[';
  315. while($row = mysql_fetch_array($result)){
  316. $jsonString .= '{'
  317. .'"Day":"'.$row['day'].'",'
  318. .'"OnScreen":"'.$row['onScreen'].'",'
  319. .'"OnBar":"'.$row['onBar'].'",'
  320. .'"OnStereo":"'.$row['onStereo'].'"'
  321. .'}';
  322. //add comma if
  323. if($loopCount < $numberOfFields){
  324. $jsonString .= ',';
  325. $loopCount++;
  326. }
  327. }
  328. $jsonString .= ']';
  329. //$this->addMessage("Items available in weekly specials.");
  330. }else{
  331. $jsonString .= '"No weekly specials available at the moment."';
  332. //$this->addMessage("No weekly specials available.");
  333. }
  334. echo $jsonString;
  335. }
  336. function getEvents(){
  337. //Get events happening
  338. $query = "SELECT * FROM events";
  339. $result = mysql_query($query);
  340. $numberOfFields = mysql_num_rows($result);
  341. $loopCount = 1;
  342. $jsonString = ',"Events":';
  343. if($numberOfFields > 0){
  344. $jsonString .= '[';
  345. while($row = mysql_fetch_array($result)){
  346. $jsonString .= '{'
  347. .'"Name":"'.$row['name'].'",'
  348. .'"Description":"'.$row['description'].'",'
  349. .'"Date":"'.$row['date'].'"'
  350. .'}';
  351. //add comma if
  352. if($loopCount < $numberOfFields){
  353. $jsonString .= ',';
  354. $loopCount++;
  355. }
  356. }
  357. $jsonString .= ']';
  358. }else{
  359. //$this->addMessage("No events available.");
  360. $jsonString .= '"No events available at the moment."';
  361. }
  362. echo $jsonString;
  363. }
  364. function getSuppliers(){
  365. //Get restaurant's suppliers
  366. $query = "SELECT * FROM suppliers";
  367. $result = mysql_query($query);
  368. $numberOfFields = mysql_num_rows($result);
  369. $loopCount = 1;
  370. $jsonString = ',"Suppliers":';
  371. if($numberOfFields > 0){
  372. $jsonString .= '[';
  373. while($row = mysql_fetch_array($result)){
  374. $jsonString .= '{'
  375. .'"Name":"'.$row['name'].'",'
  376. .'"Description":"'.$row['description'].'",'
  377. .'"Url":"'.$row['url'].'",'
  378. .'"Picture":"'.$row['picture'].'"'
  379. .'}';
  380. //add comma if
  381. if($loopCount < $numberOfFields){
  382. $jsonString .= ',';
  383. $loopCount++;
  384. }
  385. }
  386. $jsonString .= ']';
  387. }else{
  388. //$this->addMessage("No suppliers available.");
  389. $jsonString .= '"No suppliers available at the moment."';
  390. }
  391. echo $jsonString;
  392. }
  393. // function getGallery(){
  394. // //Get restaurant's picture gallery
  395. // $query = "SELECT * FROM gallery";
  396. // $result = mysql_query($query);
  397. // $numberOfFields = mysql_num_rows($result);
  398. // $loopCount = 1;
  399. // if($numberOfFields > 0){
  400. // $jsonString = ', "Gallery" : [';
  401. // while($row = mysql_fetch_array($result)){
  402. // $jsonString .= '{'
  403. // .'"url" : "'.$row['url'].'" '
  404. // .'}';
  405. // //add comma if
  406. // if($loopCount < $numberOfFields){
  407. // $jsonString .= ', ';
  408. // $loopCount++;
  409. // }
  410. // }
  411. // $jsonString .= '] ';
  412. // echo $jsonString;
  413. // }else{
  414. // $this->addMessage("No gallery available.");
  415. // }
  416. // }
  417. function getAdditionalInformation(){
  418. $query = "SELECT * FROM details";
  419. $result = mysql_query($query);
  420. $row = mysql_fetch_array($result);
  421. $jsonString = ',"Details":{';
  422. $jsonString .= '"TwitterLink":"'.$row['twitterLink'].'",'
  423. .'"FacebookLink":"'.$row['facebookLink'].'",'
  424. .'"Address":"'.$row['address'].'",'
  425. .'"PostalCode":"'.$row['postalCode'].'",'
  426. .'"City":"'.$row['city'].'",'
  427. .'"Province":"'.$row['province'].'",'
  428. .'"Latitude":"'.$row['latitude'].'",'
  429. .'"Longitude":"'.$row['longitude'].'",'
  430. .'"Phone":"'.$row['phone'].'",'
  431. .'"HoursOfOperation":"'.$row['hoursOfOperation'].'",'
  432. .'"GalleryUrl":"'.$row['galleryUrl'].'",'
  433. .'"ImageUrl":"'.$row['imageUrl'].'"'
  434. .'}';
  435. echo $jsonString;
  436. }
  437. function addMessage($string){
  438. $this->stringMessage[] = $string;
  439. }
  440. function getMessages(){
  441. //Any error message, update or message in general
  442. if($this->stringMessage == Null){
  443. echo '""';
  444. }else{
  445. //DO NOTHING FOR NOW
  446. // echo '[';
  447. // $count = count($this->stringMessage);
  448. // foreach($this->stringMessage as $value){
  449. // echo '{ "Message": "'.$value.'"}';
  450. // if($count!=1){
  451. // echo ',';
  452. // $count--;
  453. // }
  454. // }
  455. // echo ']';
  456. }
  457. }
  458. function errorCheck(){
  459. echo 1;
  460. }
  461. }
  462. ?>