'; echo ''; echo ''; echo ''; echo ''; 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"]; $name = strtolower($name); } else { $name = $vars["name"]; $name = strtolower($name); $was = array("ä", "ö", "ü", "Ä", "Ö", "Ü", "ß"); $wie = array("ae", "oe", "ue", "Ae", "Oe", "Ue", "ss"); $name = str_replace($was, $wie, $name); $allowed = "/[^a-z0-9\\040\\.\\-\\_\\\\]/i"; $name = preg_replace($allowed,"",$name); } $vote = intval($vars["vote"]); $list = ealist_getlist($date); $data = $wpdb->get_results("SELECT id, name, vote FROM ".$table_prefix."ealist WHERE date = " . intval($date) . " AND name = '" . $name . "'"); if (count($data) > 0) { $ealist_message = "Double entry!"; } else { 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 )); } } else { $ealist_message = "Do not use Name!"; } } } //return $res; //return "UPDATE `".$table_prefix."ealist` SET `vote`=$vote WHERE `name`='$name' AND date=$date LIMIT 1"; ealist_getstats(); // Creating and loading new Stats ealist_display_message($ealist_message); // Display error message 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; $list = ealist_getlist($ealist_date); $ealist_names = ealist_names(); array_walk($ealist_names, ealist_lower_u); $ealist_names = array_unique($ealist_names); $forbid_edit = get_option("ealist_edit"); echo ""; if (!empty($list)) { // $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(); if (get_option('ealist_attendant')) { $attendant = get_option('ealist_attendant'); } else { $attendant = "Attendant"; } $i = 0; foreach($list as $a=>$b) { $week = (int)ealist_get_week_number($a); $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->drawGraphAreaGradient(200,200,200,-20); $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(ABSPATH . "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; } } function ealist_get_td_width() { $list_width = get_option("ealist_list_width"); if ($list_width == "") { $list_width = 238; } //$td_width = $list_width - 64 - 16; $td_width = $list_width; return $td_width; } function ealist_display_message($data) { if ($data > "") { $code = ''; } echo $code; } function ealist_names() { global $wpdb, $table_prefix; $results=$wpdb->get_col("SELECT name FROM ".$table_prefix."ealist"); return $results; } function ealist_lower_u(&$string) { $string = ucwords(strtolower($string)); } ?>