<?php
    
    header('Content-Type: text/javascript');
    
    /* CONNECT TO THE DB */
    $link = mysql_connect('internal-db.s21410.gridserver.com','db21410_QoDdb','jU7G4dF30lIlih75sdCv');
    mysql_select_db('db21410_quotesondesign_wp_db',$link);
    
    /* PARAMTERS? */
    $permalink_want = $_GET["link"];
    
    $query = 'SELECT post_content AS quote, post_title AS author, guid AS permalink FROM qOd7g7D1jsCC_posts WHERE post_status = \'publish\' AND post_type = \'post\' ORDER BY rand() LIMIT 1';
    
	$result = mysql_query($query,$link) or die(mysql_error().': '.$query);  
	  
	$row = mysql_fetch_assoc($result);
	
	$quote = str_replace('"','\"',$row['quote']);
    
    if ($permalink_want == "no") {
    
        echo 'function getQuote(id) { document.getElementById(id).innerHTML = "<p class=\'qod-quote\'>Please update to the latest version of the <a href=\'http://quotesondesign.com/the-api/\'>Quotes on Design API</a></p>"; } window.onload = getQuote("quote");';
    
    } else {
    
        echo 'function getQuote(id) { document.getElementById(id).innerHTML = "<p class=\'qod-quote\'>Please update to the latest version of the <a href=\'http://quotesondesign.com/the-api/\'>Quotes on Design API</a></p>"; } window.onload = getQuote("quote");';
    
    }
        
?>
