forked from science-ation/science-ation
Better statistics, less database queries
This commit is contained in:
parent
89675213bf
commit
7a7f87f892
@ -81,6 +81,14 @@ function openstudentinfo(id)
|
||||
echo "</select>";
|
||||
echo "</form>";
|
||||
|
||||
$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
|
||||
while($r=mysql_fetch_object($q))
|
||||
$cats[$r->id]=$r->category;
|
||||
|
||||
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
|
||||
while($r=mysql_fetch_object($q))
|
||||
$divs[$r->id]=$r->division;
|
||||
|
||||
if($_GET['showstatus']) $wherestatus="AND status='".$_GET['showstatus']."' ";
|
||||
else $wherestatus="";
|
||||
switch($_GET['sort'])
|
||||
@ -133,14 +141,18 @@ else $wherestatus="";
|
||||
$stats_totalstudents=0;
|
||||
$stats_divisions=array();
|
||||
$stats_categories=array();
|
||||
$stats_catdiv=array();
|
||||
$stats_students_catdiv=array();
|
||||
$stats_projects_catdiv=array();
|
||||
$stats_students_schools=array();
|
||||
$stats_projects_schools=array();
|
||||
$schools_names=array();
|
||||
|
||||
while($r=mysql_fetch_object($q))
|
||||
{
|
||||
$stats_totalprojects++;
|
||||
$stats_divisions[$r->projectdivisions_id]++;
|
||||
$stats_categories[$r->projectcategories_id]++;
|
||||
$stats_catdiv[$r->projectcategories_id][$r->projectdivisions_id]++;
|
||||
$stats_projects_catdiv[$r->projectcategories_id][$r->projectdivisions_id]++;
|
||||
|
||||
switch($r->status)
|
||||
{
|
||||
@ -158,22 +170,14 @@ else $wherestatus="";
|
||||
echo "<td>$r->projectnumber</td>";
|
||||
echo "<td><a title=\"".i18n("Click to edit")."\" href=\"project_editor.php?registration_id=$r->reg_id\">$r->title</a></td>";
|
||||
|
||||
|
||||
//now get thh category and division
|
||||
$catq=mysql_query("SELECT category FROM projectcategories WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectcategories_id."'");
|
||||
$catr=mysql_fetch_object($catq);
|
||||
$divq=mysql_query("SELECT division FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
|
||||
$divr=mysql_fetch_object($divq);
|
||||
|
||||
|
||||
echo "<td>".i18n("$catr->category")."</td>";
|
||||
|
||||
echo "<td>".i18n("$divr->division")."</td>";
|
||||
echo "<td>".i18n($cats[$r->projectcategories_id])."</td>";
|
||||
echo "<td>".i18n($divs[$r->projectdivisions_id])."</td>";
|
||||
|
||||
$sq=mysql_query("SELECT students.firstname,
|
||||
students.lastname,
|
||||
students.id,
|
||||
schools.school
|
||||
schools.school,
|
||||
schools.id AS schools_id
|
||||
FROM
|
||||
students,schools
|
||||
WHERE
|
||||
@ -188,11 +192,17 @@ else $wherestatus="";
|
||||
$students="";
|
||||
while($studentinfo=mysql_fetch_object($sq))
|
||||
{
|
||||
// $students.="<a href=\"\" onclick=\"return openstudentinfo($studentinfo->id)\">$studentinfo->firstname $studentinfo->lastname </a><br />";
|
||||
$students.="<a href=\"student_editor.php?registration_id=$r->reg_id\">$studentinfo->firstname $studentinfo->lastname </a><br />";
|
||||
$schools.="$studentinfo->school <br />";
|
||||
$stats_totalstudents++;
|
||||
$stats_students_catdiv[$r->projectcategories_id][$r->projectdivisions_id]++;
|
||||
$stats_students_schools[$r->projectcategories_id][$studentinfo->schools_id]++;
|
||||
$schools_names[$studentinfo->schools_id]=$studentinfo->school;
|
||||
$lastschoolid=$studentinfo->schools_id;
|
||||
}
|
||||
//this really isnt right, its only taking the school from the last student in the project to count towards the school's project totals
|
||||
//but there's really no other way
|
||||
$stats_projects_schools[$r->projectcategories_id][$lastschoolid]++;
|
||||
echo "<td>$schools</td>";
|
||||
echo "<td>$students</td>";
|
||||
echo "<td align=\"center\">";
|
||||
@ -206,44 +216,91 @@ else $wherestatus="";
|
||||
echo "<br />";
|
||||
|
||||
echo "<table style=\"margin-left: 50px;\">";
|
||||
echo "<tr><td colspan=\"2\"><h3>".i18n("Project / Student totals")."</h3></td></tr>";
|
||||
echo "<tr><td><b>".i18n("Total Projects").":</td><td align=\"right\">$stats_totalprojects</td></tr>\n";
|
||||
echo "<tr><td><b>".i18n("Total Students").":</td><td align=\"right\"> $stats_totalstudents</td></tr>\n";
|
||||
echo "<tr><td colspan=\"2\"><hr /></td></tr>";
|
||||
|
||||
echo "<tr><td colspan=\"2\"><h3>".i18n("Projects per age category / division")."</h3></td></tr>";
|
||||
$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
|
||||
while($r=mysql_fetch_object($q))
|
||||
$cats[$r->id]=$r->category;
|
||||
|
||||
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
|
||||
while($r=mysql_fetch_object($q))
|
||||
$divs[$r->id]=$r->division;
|
||||
|
||||
echo "<tr><td colspan=\"2\"><h3>".i18n("Students / projects per age category / division")."</h3></td></tr>";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo "<table class=\"tableview\">";
|
||||
echo "<tr><td></td>";
|
||||
echo "<table class=\"tableview\" width=\"100%\">";
|
||||
echo "<tr><td width=\"50%\"></td>";
|
||||
foreach($cats AS $c=>$cn) {
|
||||
echo "<th>$cn</th>";
|
||||
echo "<th>$cn<br /><nobr>".i18n("Stud | Proj")."</nobr></th>";
|
||||
}
|
||||
echo "<th>".i18n("Total")."</th>";
|
||||
echo "<th>".i18n("Total")."<br /><nobr>".i18n("Stud | Proj")."</th>";
|
||||
echo "</tr>";
|
||||
foreach($divs AS $d=>$dn) {
|
||||
echo "<tr><td><b>$dn</b></td>";
|
||||
echo "<tr><td>$dn</td>";
|
||||
$tstud=0;
|
||||
$tproj=0;
|
||||
foreach($cats AS $c=>$cn)
|
||||
echo "<td align=\"center\">".($stats_catdiv[$c][$d]?$stats_catdiv[$c][$d]:0)."</td>";
|
||||
echo "<td align=\"center\"><b>".($stats_divisions[$d]?$stats_divisions[$d]:0)."</b></td>";
|
||||
{
|
||||
echo "<td align=\"center\">";
|
||||
echo ($stats_students_catdiv[$c][$d]?$stats_students_catdiv[$c][$d]:0);
|
||||
echo " ";
|
||||
echo ($stats_projects_catdiv[$c][$d]?$stats_projects_catdiv[$c][$d]:0);
|
||||
echo "</td>";
|
||||
$tstud+=$stats_students_catdiv[$c][$d];
|
||||
$tproj+=$stats_projects_catdiv[$c][$d];
|
||||
|
||||
$tstudcat[$c]+=$stats_students_catdiv[$c][$d];
|
||||
$tprojcat[$c]+=$stats_projects_catdiv[$c][$d];
|
||||
}
|
||||
echo "<td align=\"center\"><b>";
|
||||
echo ($tstud?$tstud:0);
|
||||
echo " ";
|
||||
echo ($tproj?$tproj:0);
|
||||
echo "</b></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "<tr><td><b>".i18n("Total")."</b></td>";
|
||||
foreach($cats AS $c=>$cn) {
|
||||
echo "<td align=\"center\"><b>".($stats_categories[$c]?$stats_categories[$c]:0)."</b></td>";
|
||||
echo "<td align=\"center\"><b>";
|
||||
echo ($tstudcat[$c]?$tstudcat[$c]:0);
|
||||
echo " ";
|
||||
echo ($tprojcat[$c]?$tprojcat[$c]:0);
|
||||
echo "</b></td>";
|
||||
}
|
||||
echo "<td align=\"center\"><b>".($stats_totalprojects?$stats_totalprojects:0)."</b></td>";
|
||||
echo "<td align=\"center\"><b>";
|
||||
echo ($stats_totalstudents?$stats_totalstudents:0);
|
||||
echo " ";
|
||||
echo ($stats_totalprojects?$stats_totalprojects:0);
|
||||
echo "</b></td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "</table>";
|
||||
echo "</td></tr></table>";
|
||||
echo "</td></tr>";
|
||||
|
||||
echo "<tr><td colspan=\"2\"><br /></td></tr>";
|
||||
echo "<tr><td colspan=\"2\"><h3>".i18n("Students / projects per age category / school")."</h3></td></tr>";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo "<table class=\"tableview\" width=\"100%\">";
|
||||
echo "<tr><td width=\"50%\"></td>";
|
||||
foreach($cats AS $c=>$cn) {
|
||||
echo "<th>$cn<br /><nobr>".i18n("Stud | Proj")."</nobr></th>";
|
||||
}
|
||||
echo "<th>".i18n("Total")."<br /><nobr>".i18n("Stud | Proj")."</nobr></th>";
|
||||
echo "</tr>";
|
||||
|
||||
asort($schools_names);
|
||||
foreach($schools_names AS $id=>$sn)
|
||||
{
|
||||
echo "<tr><td>$sn</td>";
|
||||
$tstud=0;
|
||||
$tproj=0;
|
||||
foreach($cats AS $c=>$cn) {
|
||||
echo "<td align=\"center\">".($stats_students_schools[$c][$id]?$stats_students_schools[$c][$id]:0);
|
||||
echo " ";
|
||||
echo ($stats_projects_schools[$c][$id]?$stats_projects_schools[$c][$id]:0)."</td>";
|
||||
$tstud+=$stats_students_schools[$c][$id];
|
||||
$tproj+=$stats_projects_schools[$c][$id];
|
||||
}
|
||||
echo "<td align=\"center\"><b>".($tstud?$tstud:0);
|
||||
echo " ";
|
||||
echo ($tproj?$tproj:0)."</b></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
echo i18n("%1 schools total",array(count($schools_names)));
|
||||
|
||||
echo "</td></tr>";
|
||||
echo "</table>";
|
||||
|
||||
echo "<br />";
|
||||
echo i18n("Note: statistics reflect the numbers of the current 'Status' selected at the top of the page");
|
||||
|
Loading…
x
Reference in New Issue
Block a user