';
echo '';
}
function ealist_postentry($vars) {
global $wpdb, $current_user, $table_prefix;
$date = intval($vars["date"]);
$del = substr($vars["name"], 0, 3);
if ($current_user->ID > 0) {
$name = $vars["name"];
} else {
$name = ereg_replace("[^A-Za-z0-9]", "", $vars["name"]);
}
$vote = intval($vars["vote"]);
$list = ealist_getlist($date);
if ($name != "") {
if ($del == "del") {
$name = substr($name, 3);
$res=$wpdb->query(sprintf("DELETE FROM `".$table_prefix."ealist` WHERE date=%d AND id='%d'",
$date,
$name
));
} else if ($name != "Name") {
if ((int)$name > 0) {
$res=$wpdb->query(sprintf("UPDATE `".$table_prefix."ealist` SET `vote`=%d WHERE `id`='%s' AND `date`='%d' LIMIT 1",
$vote,
$name,
$date
));
} else {
$res=$wpdb->query(sprintf("INSERT INTO `".$table_prefix."ealist` (`date`, `name`, `vote`) VALUES (%d, '%s', %d)",
$date,
$name,
$vote
));
}
}
}
//return $res;
//return "UPDATE `".$table_prefix."ealist` SET `vote`=$vote WHERE `name`='$name' AND date=$date LIMIT 1";
return ealist_htmllist($date);
}
function ealist_getlist($ealist_date) {
global $wpdb, $table_prefix;
$list=array();
$data = $wpdb->get_results("SELECT id, name, vote FROM ".$table_prefix."ealist WHERE date = " . intval($ealist_date) . " ORDER BY vote DESC, name ASC");
if(count($data)>0 && is_array($data)) {
foreach($data as $r) {
$list[$r->name] = array($r->vote, $r->id);
//$list[$r->name] = $r->vote;
}
return $list;
}
return false;
}
function ealist_htmllist($ealist_date) {
global $current_user;
$forbid_edit = get_option("ealist_edit");
echo "";
$list = ealist_getlist($ealist_date);
if (!empty($list)) {
$return .= "
";
foreach ($list as $item=>$vote) {
$return .= "| ";
$return .= ucwords(strtolower($item));
$return .= " | ";
$return .= "";
$return .= ($vote[0] == "1") ? " ![$vote[1]](http://hockey.dasweb.net/wp-content/plugins/ajax-easy-attendance-list/img/yes.gif) " : " ![$vote[1]](http://hockey.dasweb.net/wp-content/plugins/ajax-easy-attendance-list/img/no.gif) ";
$return .= " ";
if ($current_user->ID > 0) {
$return .= " ";
}
$return .= " |
";
}
$return .= "
";
} else {
$return = "" . get_option("ealist_inputtext") . "
";
}
return $return;
}
function ealist_count($ealist_date) {
$list = ealist_getlist($ealist_date);
$j = 0;
if (!empty($list)) {
foreach ($list as $item=>$vote) {
if ($vote[0] == 1) {
$j++;
}
}
}
return $j;
}
function ealist_getstats() {
$list = ealist_getstats_list();
$return .= "";
$i = 0;
foreach($list as $a=>$b) {
$week = (int)ealist_get_week_number($a);
$total[$week] = $total["$week"] + $b;
}
foreach($total as $a=>$b) {
$i++;
$yaxis[$i] = $b;
$xaxis[$i] = $a;
//echo $b;
}
$max = max($yaxis);
if ($max % 5 > 0) {
$max = (floor($max / 5) + 1) * 5;
}
include("pchart/pData.class");
include("pchart/pChart.class");
$stats_width = get_option('ealist_stats_width'); //620 default
if ($stats_width > 0) {
} else {
$stats_width = 620;
}
$DataSet = new pData;
$DataSet->AddPoint($yaxis,"Attendance");
$DataSet->AddPoint($xaxis,"Week");
$DataSet->AddSerie("Attendance");
$DataSet->SetAbsciseLabelSerie("Week");
$DataSet->SetYAxisName("Attendant");
if ($i > 1) {$DataSet->SetXAxisName("Week");}
$Test = new pChart($stats_width,280);
$Test->setFixedScale(0,$max);
$Test->setFontProperties(dirname(__FILE__). "/Fonts/tahoma.ttf",8);
$Test->setGraphArea(70,30,$stats_width-20,230);
$Test->drawFilledRoundedRectangle(7,7,$stats_width-7,273,5,210,210,210);
$Test->drawRoundedRectangle(5,5,$stats_width-5,275,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,220,220,220,50);
// Draw the 0 line
$Test->setFontProperties(dirname(__FILE__). "/Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
$player = get_option('ealist_players');
if ($player > 0) {
$Test->drawTreshold(get_option('ealist_players'),143,55,72,TRUE,TRUE);
}
// Draw the line graph
$Test->setColorPalette(0,153,0,0);
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
// Finish the graph
$Test->setFontProperties(dirname(__FILE__). "/Fonts/tahoma.ttf",8);
//$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties(dirname(__FILE__). "/Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"Attendance",50,50,50,$stats_width-35);
$Test->Render("attendance.png");
return "
";
//return $return;
}
function ealist_getstats_list() {
global $wpdb, $table_prefix;
$date_low = time() - 365*24*60*60;
$list=array();
$result = $wpdb->get_results("SELECT date, vote FROM ".$table_prefix."ealist WHERE vote = 1 AND date > $date_low ORDER BY date ASC");
if(count($result)>0 && is_array($result)) {
foreach($result as $r) {
$j++;
$list[$r->date]++;
}
return $list;
}
return false;
}
function ealist_get_week_number($timestamp) {
$d = GETDATE($timestamp);
$days = ealist_iso_week_days($d[ "yday"], $d[ "wday"]);
IF ($days < 0) {
$d[ "yday"] += 365 + ealist_is_leap_year(--$d[ "year"]);
$days = ealist_iso_week_days($d[ "yday"], $d[ "wday"]);
} ELSE {
$d[ "yday"] -= 365 + ealist_is_leap_year($d[ "year"]);
$d2 = ealist_iso_week_days($d[ "yday"], $d[ "wday"]);
IF (0 <= $d2) {
/* $d["year"]++; */
$days = $d2;
}
}
RETURN (int)($days / 7) + 1;
}
FUNCTION ealist_iso_week_days($yday, $wday) {
RETURN $yday - (($yday - $wday + 382) % 7) + 3;
}
FUNCTION ealist_is_leap_year($year) {
IF ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
RETURN 1;
} ELSE {
RETURN 0;
}
}
?>