/MobileApp/SlowPub_webservicesE.php
PHP | 512 lines | 394 code | 50 blank | 68 comment | 33 complexity | da22ddd294ffcb3325e0b6c72bb84b62 MD5 | raw file
- <?php
-
- /**
- *
- *
- * @version $Id$
- * @copyright 2011
- */
- try{
- $dbc = new DataBaseConnectivity();
- $dbc->connectToDB();
- echo '{"PayLoad":';
- echo '{';
- $dbc->getFoodMenu();
- $dbc->getDrinkCollection();
- $dbc->getWeeklySpecials();
- $dbc->getEvents();
- $dbc->getSuppliers();
- $dbc->getAdditionalInformation();
- echo '},';
- echo '"ErrorCheck":';
- $dbc->errorCheck();
- echo ',';
- echo '"Message":';
- $dbc->getMessages();
- echo '}';
- $dbc->closeConnection();
- }catch(Exception $e){
- echo 'Message:'.$e->getMessage();
- }
-
-
-
- class DataBaseConnectivity{
-
- var $connection;
- var $stringMessage = array();
-
- function connectToDB(){
- $con = mysql_connect("localhost","tester","Allegjdm93");
- //$con = mysql_connect("mysql15.000webhost.com","a3813951_mobile","Allegjdm93");
- if(!$con){
- //echo "Could not connect to db";
- throw new Exception("Could not connect to db.");
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("test_empty");
- //mysql_select_db("a3813951_mobile");
-
- $this->connection = $con;
- }
-
- function closeConnection(){
- mysql_close($this->connection);
- }
-
- function getFoodMenu(){
- echo '"FoodMenu":{';
- $this->getRegularMenu();
- $this->getDailyMenu();
- echo '}';
- }
-
- function getRegularMenu(){
- $select = 1;
- $flag = 0;
- echo '"RegularMenu":';
- do{
- $loopCount = 1;
- $jsonString = '';
- switch($select){
- case 1:
- $query = "SELECT * FROM reg_menu WHERE type = 'soup_salad_appy'";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- if($numberOfFields > 0) {
- $flag = 1;
- $jsonString .= '[';
- }
- $jsonString .= '{"Name":"Soup, Salads & Appys",';
- break;
- case 2:
- $query = "SELECT * FROM reg_menu WHERE type = 'main_forno'";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- if($numberOfFields > 0 && $flag == 0) {
- $flag = 1;
- $jsonString .= '[';
- }
- $jsonString .= '{"Name":"Main & Forno",';
- break;
- case 3:
- $query = "SELECT * FROM reg_menu WHERE type = 'sandwich_pasta'";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- if($numberOfFields > 0 && $flag == 0) {
- $flag = 1;
- $jsonString .= '[';
- }
- $jsonString .= '{"Name":"Pasta & Sandwhich",';
- break;
- }
-
- if($numberOfFields > 0){
- $jsonString .= '"items":[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Description":"'.$row['description'].'",'
- .'"Price":"'.$row['price'].'",'
- .'"Picture":"'.$row['picture'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
-
- }
- $jsonString .= ']}';
- if($select < 3){
- $jsonString .= ',';
- }
-
- echo $jsonString;
-
- }else{
- //$this->addMessage("No items available.");
- }
- $select++;
- }while($select <= 3);
-
- if($flag == 0){
- echo '"No menu available at the moment."';
- }else{
- echo "]";
- }
- }
-
- function getDailyMenu(){
- //Get daily menu
- $query = "SELECT * FROM daily_menu";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString = ',"DailyMenu":';
-
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Description":"'.$row['description'].'",'
- .'"Price":"'.$row['price'].'",'
- .'"Picture":"'.$row['picture'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- //$this->addMessage("No daily menu available.");
- $jsonString .= '"No menu available at the moment."';
- }
-
- echo $jsonString;
- }
-
- function getDrinkCollection(){
- echo ',"DrinkCollection":{';
- $this->getOffsale();
- $this->getOnTap();
- $this->getBottleCans();
- $this->getHouse();
- echo '}';
- }
-
- function getOffsale(){
- $jsonString = '"Offsale":';
- $jsonString .= '{';
-
- $query = "SELECT 'offsaleText' FROM details";
- $result = mysql_query($query);
- $row = mysql_fetch_array($result);
- $jsonString .= '"Text":"'.$row['offsaleText'].'"';
-
- $query = "SELECT * FROM `offsale_prices`";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString .= ',"Prices":';
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Price":"'.$row['price'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- $jsonString .= '"No prices available at the moment."';
- }
-
- $query = "SELECT * FROM drink_collection WHERE offSale = TRUE";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString .= ',"Drinks":';
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Legend":"'.$row['legend'].'",'
- .'"Type":"'.$row['type'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= '],';
- }else{
- $jsonString .= '"No offsale drinks available at the moment."';
- //$this->addMessage("No offsale drinks available.");
- }
- $jsonString .= '}';
-
- echo $jsonString;
- }
-
- function getOnTap(){
- $jsonString = ',"OnTap":';
- $jsonString .= '{';
-
- $query = "SELECT 'onTapText' FROM details";
- $result = mysql_query($query);
- $row = mysql_fetch_array($result);
- $jsonString .= '"Text":"'.$row['onTapText'].'"';
-
-
- $query = "SELECT * FROM drink_collection WHERE onTap = TRUE";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString .= ',"Drinks":';
- if($numberOfFields > 0){
- $jsonString .= "[";
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Origin":"'.$row['origin'].'",'
- .'"Price":"'.$row['price'].'",'
- .'"Type":"'.$row['type'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- $jsonString .= '"No on tap drinks available at the moment.",';
- //$this->addMessage("No drinks on tap available.");
- }
- $jsonString .= '}';
-
- echo $jsonString;
- }
-
- function getBottleCans(){
- $jsonString = ',"BottleCans":';
- $query = "SELECT * FROM drink_collection WHERE bottleCans = TRUE";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- if($numberOfFields > 0){
- $jsonString .= "[";
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Origin":"'.$row['origin'].'",'
- .'"Price":"'.$row['price'].'",'
- .'"Type":"'.$row['type'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- $jsonString .= '"No bottle or can drinks available at the moment."';
- //$this->addMessage("No bottle or can drinks available.");
- }
-
- echo $jsonString;
- }
-
- function getHouse(){
- $jsonString = ',"House":';
- $query = "SELECT * FROM drink_collection WHERE house = TRUE";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- if($numberOfFields > 0){
- $jsonString .= "[";
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Legend":"'.$row['legend'].'",'
- .'"Type":"'.$row['type'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- $jsonString .= '"No house drinks available at the moment."';
- //$this->addMessage("No house drinks available.");
- }
-
- echo $jsonString;
- }
-
- function getWeeklySpecials(){
- $query = "SELECT * FROM weekly_special" ;
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString = ',"WeeklySpecials":';
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Day":"'.$row['day'].'",'
- .'"OnScreen":"'.$row['onScreen'].'",'
- .'"OnBar":"'.$row['onBar'].'",'
- .'"OnStereo":"'.$row['onStereo'].'"'
- .'}';
-
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- //$this->addMessage("Items available in weekly specials.");
- }else{
- $jsonString .= '"No weekly specials available at the moment."';
- //$this->addMessage("No weekly specials available.");
- }
-
- echo $jsonString;
- }
-
- function getEvents(){
- //Get events happening
- $query = "SELECT * FROM events";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString = ',"Events":';
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Description":"'.$row['description'].'",'
- .'"Date":"'.$row['date'].'"'
- .'}';
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- //$this->addMessage("No events available.");
- $jsonString .= '"No events available at the moment."';
- }
-
- echo $jsonString;
- }
-
- function getSuppliers(){
- //Get restaurant's suppliers
- $query = "SELECT * FROM suppliers";
- $result = mysql_query($query);
- $numberOfFields = mysql_num_rows($result);
- $loopCount = 1;
- $jsonString = ',"Suppliers":';
- if($numberOfFields > 0){
- $jsonString .= '[';
- while($row = mysql_fetch_array($result)){
- $jsonString .= '{'
- .'"Name":"'.$row['name'].'",'
- .'"Description":"'.$row['description'].'",'
- .'"Url":"'.$row['url'].'",'
- .'"Picture":"'.$row['picture'].'"'
- .'}';
-
- //add comma if
- if($loopCount < $numberOfFields){
- $jsonString .= ',';
- $loopCount++;
- }
- }
- $jsonString .= ']';
- }else{
- //$this->addMessage("No suppliers available.");
- $jsonString .= '"No suppliers available at the moment."';
- }
-
- echo $jsonString;
- }
-
- // function getGallery(){
- // //Get restaurant's picture gallery
- // $query = "SELECT * FROM gallery";
- // $result = mysql_query($query);
- // $numberOfFields = mysql_num_rows($result);
- // $loopCount = 1;
- // if($numberOfFields > 0){
- // $jsonString = ', "Gallery" : [';
- // while($row = mysql_fetch_array($result)){
- // $jsonString .= '{'
- // .'"url" : "'.$row['url'].'" '
- // .'}';
- // //add comma if
- // if($loopCount < $numberOfFields){
- // $jsonString .= ', ';
- // $loopCount++;
- // }
- // }
- // $jsonString .= '] ';
- // echo $jsonString;
- // }else{
- // $this->addMessage("No gallery available.");
- // }
- // }
-
- function getAdditionalInformation(){
- $query = "SELECT * FROM details";
- $result = mysql_query($query);
- $row = mysql_fetch_array($result);
- $jsonString = ',"Details":{';
- $jsonString .= '"TwitterLink":"'.$row['twitterLink'].'",'
- .'"FacebookLink":"'.$row['facebookLink'].'",'
- .'"Address":"'.$row['address'].'",'
- .'"PostalCode":"'.$row['postalCode'].'",'
- .'"City":"'.$row['city'].'",'
- .'"Province":"'.$row['province'].'",'
- .'"Latitude":"'.$row['latitude'].'",'
- .'"Longitude":"'.$row['longitude'].'",'
- .'"Phone":"'.$row['phone'].'",'
- .'"HoursOfOperation":"'.$row['hoursOfOperation'].'",'
- .'"GalleryUrl":"'.$row['galleryUrl'].'",'
- .'"ImageUrl":"'.$row['imageUrl'].'"'
- .'}';
-
- echo $jsonString;
- }
-
- function addMessage($string){
- $this->stringMessage[] = $string;
- }
-
- function getMessages(){
- //Any error message, update or message in general
- if($this->stringMessage == Null){
- echo '""';
- }else{
- //DO NOTHING FOR NOW
-
- // echo '[';
- // $count = count($this->stringMessage);
- // foreach($this->stringMessage as $value){
- // echo '{ "Message": "'.$value.'"}';
- // if($count!=1){
- // echo ',';
- // $count--;
- // }
- // }
- // echo ']';
- }
- }
-
- function errorCheck(){
- echo 1;
- }
- }
-
-
- ?>