Created
January 20, 2015 23:26
-
-
Save awhedbee22/abf106d2d3a2c2bca480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
allListings.php | |
!!API Page!! | |
revised 11/6/2013 - Michael | |
Creates a JSON array of categories for output to the app | |
In order to work, page must be called with $_GET["com"] = "com.vrp.marketing" | |
*/ | |
header("Access-Control-Allow-Origin: *"); | |
require_once "config.inc.php"; | |
//if(isset($_GET["com"]) && $_GET["com"] == "com.vrp.marketing") { | |
$mysqli->set_charset("utf8"); //need this for using JSON later, otherwise shit freaks out | |
$active = "active"; | |
if(isset($_GET["since"])) { | |
$timeStamp = $_GET["since"] - 200000; | |
$since = gmdate("Y-m-d H:i:s",$timeStamp); | |
} else { | |
$since = "2012-01-01 00:00:00"; | |
} | |
$listers = $mysqli->stmt_init(); | |
$lQuery = "SELECT listers.lister_id, | |
listers.listing_name, | |
listers.street_address, | |
listers.address2, | |
listers.city, | |
listers.state, | |
listers.zip, | |
listers.phone, | |
listers.phone_text, | |
listers.phone_2, | |
listers.phone_2_text, | |
listers.phone_3, | |
listers.phone_3_text, | |
listers.phone_4, | |
listers.phone_4_text, | |
listers.email, | |
listers.email_2, | |
listers.url, | |
listers.url_2, | |
listers.customer_type, | |
listers.logo_file_name, | |
listers.short_comment, | |
listers.hardcopy, | |
listers.member, | |
listers.member_sj, | |
listers.facebook, | |
listers.twitter, | |
listers.latitude, | |
listers.longitude, | |
listers.description, | |
listers.date_modified | |
FROM listers | |
WHERE (listers.status = ? | |
AND listers.date_modified >= ?)"; | |
$listers->prepare($lQuery); | |
$listers->bind_param("ss",$active,$since); | |
$listers->bind_result($listerid,$listingname,$address,$address2,$city,$state,$zip,$phone,$phone_text,$phone2,$phone2_text,$phone3,$phone3_text,$phone4,$phone4_text,$email,$email2,$url,$url2,$customer_type,$logo,$comment,$hardcopy,$member,$member_sj,$facebook,$twitter,$lat,$lng,$description,$modified); | |
if($listers->execute()) { | |
$listers->store_result(); | |
$sCRows = $listers->num_rows(); | |
if($sCRows >= 1) { | |
$resultDocs = array(); | |
while($listers->fetch()) { //drop 'em all into the array' | |
$tags = array(); | |
$resultDoc = array('docId'=>$listerid,'listerName'=>$listingname); | |
$resultDoc["street_address"] = $address; | |
$resultDoc["address2"] = $address2; | |
$resultDoc["city"] = $city; | |
$resultDoc["state"] = $state; | |
$resultDoc["zip"] = $zip; | |
$phones = array(); //honestly, not sure why we do a $phones array, and then re-enter all the phones later, but that's the output I was given, so that's the output I make | |
if ($phone != null) { | |
$phones[$phone] = $phone_text; | |
} | |
if ($phone2 != null) { | |
$phones[$phone2] = $phone2_text; | |
} | |
if ($phone3 != null) { | |
$phones[$phone3] = $phone3_text; | |
} | |
if ($phone4 != null) { | |
$phones[$phone4] = $phone4_text; | |
} | |
$resultDoc['phones'] = $phones; | |
$resultDoc['phone_text'] = $phone_text; | |
$resultDoc['phone'] = $phone; | |
$resultDoc['phone_2_text'] = $phone2_text; | |
$resultDoc['phone_2'] = $phone2; | |
$resultDoc['phone_3_text'] = $phone3_text; | |
$resultDoc['phone_3'] = $phone3; | |
$resultDoc['phone_4_text'] = $phone4_text; | |
$resultDoc['phone_4'] = $phone4; | |
$resultDoc["email"] = $email; | |
$resultDoc["email_2"] = $email2; | |
$resultDoc["url"] = $url; | |
$resultDoc["url_2"] = $url2; | |
$resultDoc["customer_type"] = $customer_type; | |
if($logo != null) { | |
$resultDoc["logo_file_name"] = "http://myrainbowpages.com/custimgs/" . urlencode($logo); | |
} else { | |
$resultDoc["logo_file_name"] = null; | |
} | |
$resultDoc["short_comment"] = $comment; | |
$resultDoc["hardcopy"] = $hardcopy; | |
$resultDoc["member"] = $member; | |
$resultDoc["member_sj"] = $member_sj; | |
$resultDoc["facebook"] = $facebook; | |
$resultDoc["twitter"] = $twitter; | |
$resultDoc["icon_file_name"] = null; | |
$resultDoc["lat"] = $lat; | |
$resultDoc["lng"] = $lng; | |
$resultDoc["distance"] = "999"; | |
$resultDoc["description"] = $description; | |
$resultDoc["modified"] = strtotime($modified); | |
$resultDoc["files"] = array(); //file search...because...I dunno. Grabbing pictures. | |
$fileSearch = $mysqli->stmt_init(); | |
$fSQuery = "SELECT fileName, | |
fileType, | |
title, | |
description | |
FROM lister_files | |
WHERE lister_id = ?"; | |
$fileSearch->prepare($fSQuery); | |
$fileSearch->bind_param("i",$listerid); | |
$fileSearch->bind_result($fileName,$fileType,$title,$descrition); | |
if($fileSearch->execute()) { | |
$fileSearch->store_result(); | |
$fSRows = $fileSearch->num_rows(); | |
if($fSRows >= 1) { | |
$rows = array(); | |
while($fileSearch->fetch()) { | |
$rows[] = array('fileName'=>$fileName,'fileROOT'=>"./custimgs/" ,'fileURL'=>"./custimgs/" .$fileName,'fileType'=>$fileType,'title'=>$title,'description'=>$description); | |
} | |
} else { | |
$rows = null; | |
} | |
} else { | |
echo " break1 " . $mysqli->error; | |
} | |
$fileSearch->close(); | |
$resultDoc["listingCategory"] = array(); //listing categories associated with lister. | |
$listingSearch = $mysqli->stmt_init(); | |
$lSQuery = "SELECT listing_category_id | |
FROM listings | |
WHERE lister_id = ?"; | |
$listingSearch->prepare($lSQuery); | |
$listingSearch->bind_param("i",$listerid); | |
$listingSearch->bind_result($listing_category_id); | |
if($listingSearch->execute()) { | |
$listingSearch->store_result(); | |
$lSRows = $listingSearch->num_rows(); | |
if($lSRows >= 1) { | |
$cats = array(); | |
while($listingSearch->fetch()) { | |
$category = getCategoryName($listing_category_id,$mysqli); | |
if($category["rows"] == 1) { | |
$cats[] = $category["category_name"]; | |
} | |
} | |
} else { | |
$cats = null; | |
} | |
} else { | |
echo " break 2 " . $mysqli->error; | |
} | |
$listingSearch->close(); | |
$resultDoc["files"] = $rows; | |
$resultDoc["listingCategory"] = $cats; | |
$tags = null; | |
// print_r ($tags); | |
$resultDoc['tags'] = $tags; | |
$resultDocs[] = $resultDoc; | |
} | |
$returnInfo["rows"] = $resultDocs; | |
} | |
echo json_encode($returnInfo); | |
} else { | |
echo json_encode($returnInfo); | |
echo " break 3 " . $mysqli->error; | |
} | |
//} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment