setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }catch(PDOException $e){ header("HTTP/1.1 500 Internal Server Error"); } // Statement Handle SELECT FROM SITEMAP CACHE try{ $sth = $dbh->prepare("SELECT idm,dealerid,ymm,tray,xml,dateexpires FROM $table WHERE dealerid= :TeamID AND ymm= :ymm AND tray= :tray LIMIT 1"); $sth -> bindParam(':TeamID', $TeamID, PDO::PARAM_STR); $sth -> bindParam(':tray', $tr, PDO::PARAM_STR); $sth -> bindParam(':ymm', $ymm, PDO::PARAM_STR); $sth->execute(); $retrievedrow = $sth->fetch(); }catch(PDOException $e){ header("HTTP/1.1 500 Internal Server Error"); //FAIL @ DATABASE } // Statement Handle SELECT FROM SITEMAP CACHE //CHECK DATE EXPIRY if($retrievedrow != NULL){ //HAS CACHED date_default_timezone_set("America/Chicago"); $todaydate = date("Y-m-d H:i:s"); $DateTime = strftime($todaydate); if($retrievedrow['dateexpires'] != NULL){ //DATE CREATED //retrieve date - check if expired //set a string date for saving to database for next time saved sitemap is accessed $retrieveddate = new DateTime($retrievedrow['dateexpires']); $nowDateTime = new DateTime($DateTime); $retrievedIndex = $retrievedrow['idm']; //NEXT EXP DATE TO SAVE if(($retrieveddate < $nowDateTime) || $forceNew == true ){ //NEEDS CACHE //echo(''); $NeedsFreshCache = true; //NEEDS CACHE }else{ //HAS CACHE USE CACHE VALUES //echo(''); $NeedsFreshCache = false; $success = "1"; $xmlresults = $retrievedrow['xml']; //HAS CACHE USE CACHE VALUES } } }else{ //HAS NO CACHE $NeedsFreshCache = true; //NEEDS CACHE } //CHECK DATE EXPIRY }else{ header("HTTP/1.1 500 Internal Server Error"); //FAIL NO URL PARAMETERS }//IF HAS GET URL / POST REQUESTS if($NeedsFreshCache == true && $tr != ""){ //MAKE PAGE GENERATION include 'LineUpSitemap.php'; }//MAKE PAGE GENERATION if($NeedsFreshCache == true && $tr == "" && $ymm != ""){ //SINGLE PAGE MVP GENERATION include 'SingleSitemap.php'; }//SINGLE PAGE MVP GENERATION if(isset($success)){//OUTPUT RESULTS ! header('Content-Type: application/xml; charset=utf-8'); echo ""; echo($xmlresults); echo(''); //OUTPUT RESULTS ! if($NeedsFreshCache == true){ //SAVE TO DATABASE if( $ymm == " _ _ "){ //:( FIX for magic Value of null ymm _ _ $ymm = ""; } try{ $nextdate = new DateTime($todaydate); $nextdate->add(new DateInterval('P1D')); if(isset($retrievedIndex)){//UPDATE Record At Index //echo(''); $saveth = $dbh->prepare("UPDATE $table SET ( xml , dateexpires ) WHERE ( :idm, :TeamID , :ymm , :tray )"); $saveth -> bindParam(':idm', $retrievedIndex, PDO::PARAM_STR); }else{ //echo(''); $saveth = $dbh->prepare("INSERT INTO $table VALUES ( idm, :TeamID , :ymm , :tray , :xml , :dateexpires )"); } $saveth -> bindParam(':TeamID', $TeamID, PDO::PARAM_STR); $saveth -> bindParam(':tray', $tr, PDO::PARAM_STR); $saveth -> bindParam(':ymm', $ymm, PDO::PARAM_STR); $saveth -> bindParam(':xml', $xmlresults, PDO::PARAM_STR); $saveth -> bindParam(':dateexpires', $nextdate->format('Y-m-d H:i:s'), PDO::PARAM_STR); $saveth->execute(); }catch(PDOException $e){/*fail UPDATE / INSERT*/} }//SAVE TO DATABASE }else{ //FAILURE NO RESULTS header("HTTP/1.1 500 Internal Server Error"); } //FAILURE NO RESULTS ?>