//Connect To Database
$hostname="localhost";
$username="jt6mm0c_db19116";
$password="pn@IUO?hh8kbHj5A";
$dbname="jt6mm0c_db19116_emocapsule";
mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);
//getting emotion
$emotion = $_POST['emotion'];
$loc = $_REQUEST['loc'];
date_default_timezone_set('EST5EDT');
$now = time();
$date = strftime('%H_%M_%S_%b%d%y',$now);
if(isset($_COOKIE['city']) && isset($_COOKIE['country'])){
$localCity = $_COOKIE['city'];
$localCountry = $_COOKIE['country'];
}
if (!isset($_REQUEST['display'])){
$display = 5;
}else{
$display = $_REQUEST['display'];
}
$location = $_REQUEST['location'];
//////////////////////////////////
//does the time thing and gets the cookies
$now = time();
date_default_timezone_set('EST5EDT');
$date = strftime('%H_%M_%S_%b%d%y',$now);
if(isset($_COOKIE['city']) && isset($_COOKIE['country'])){
$localCity = $_COOKIE['city'];
$localCountry = $_COOKIE['country'];
}
// gets all of the countrys in the database and calculates the frequency of each country
$totalCountry = @mysql_query("SELECT country, count( country ) AS num_times, countryCode FROM webEmotion GROUP BY country ORDER BY `num_times` DESC");
$totalCountryNum=mysql_numrows($totalCountry);
//selects the different countries submitted
$emotionCountryOrdered = @mysql_query("SELECT country FROM webEmotion");
//counts the unique countries
$numCountry=mysql_numrows($emotionCountryOrdered);
$i=0;
//breakes down the array for the frequency of emotions per country
while($i<$totalCountryNum){
$country_[$i] = mysql_result($totalCountry, $i, 'country');
$num_loc_[$i] = mysql_result($totalCountry, $i, 'num_times');
$countryCodeShort[$i] = mysql_result($totalCountry, $i, 'countryCode');
//calculates the percentage of the cities overall from all cities submitted
$percentage[$i] = ceil((($num_loc_[$i]/$numCountry)*100));
//calculates the pixels for the graphs to be displayed
// $num_loc_[$i] = ceil(500-(($num_loc_[$i]/$numCountry)*500));
$num_loc_[$i] = ceil((($num_loc_[$i]/$numCountry)*500));
$i++;
}
//adds the country array into a string for tbe bar graph
$string = '';
foreach($country_ as $key => $value){
$string .="$value|";
}
$string = str_replace(' ', '', $string);
$stringCountryCode = '';
foreach($countryCodeShort as $keyCode => $valueCountryCode){
$stringCountryCode .="$valueCountryCode";
}
$stringCountryCode = str_replace(' ', '', $stringCountryCode);
//echo "Country Code String --> $stringCountryCode";
?>
// *********** THE $num_loc_ VARIABLE DOES NOT TO BE JOINED INTO AN ARRAY!
$test_data = $num_loc_;
//is an array
//echo $test_data;
// Here's where we call the chart, and return the encoded chart data
//echo "
";
//dynamic graph witdh
$graphWidth = ((50*$totalCountryNum)+100);
// And here's the function
function chart_data($values) {
// Port of JavaScript from http://code.google.com/apis/chart/
// http://james.cridland.net/code
// First, find the maximum value from the values given
//$maxValue = max($values);
$maxValue = 500;
// A list of encoding characters to help later, as per Google's example
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
// Return the chart data - and let the Y axis to show the maximum value
return $chartData;
}
//this displayes the map chart
echo "
";
echo "
";
?>