| Current Path : /var/www/cesa.co.za/ |
| Current File : /var/www/cesa.co.za/testreportexport.php |
<?php include("php/inc_db.php"); ?>
<?php
function DisplayAnswersExcel($iAnonRespID, $iQuesID, $iIsMulti) {
global $conn;
$arrAnswers=array();
if ($iIsMulti==1) {
$sql = "SELECT DISTINCT Anon_User_Answers.Answer_Text
FROM Anon_User_Answers
WHERE Respondee_ID=".$iAnonRespID." AND Question_ID='".$iQuesID."'";
// echo $sql;
$recA=mysqli_query($conn,$sql);
if ($rowA=mysqli_fetch_assoc($recA)) {
$sql="SELECT Answers.Answer FROM Answers WHERE Answer_ID IN (".$rowA["Answer_Text"].")";
if ($recAB=mysqli_query($conn,$sql)) {
while ($rowAB=mysqli_fetch_assoc($recAB)) {
if (empty($rowAB["Answer"])) {
$arrAnswers[]= $rowA["Answer_Text"];
} else {
$arrAnswers[]= $rowAB["Answer"];
}
}
} else {
$arrAnswers[]= $rowA["Answer_Text"];
while ($rowA=mysqli_fetch_assoc($recA)) {
$arrAnswers[]= $rowA["Answer_Text"];
}
}
}
} else {
$sql = "SELECT Anon_User_Answers.*, Answers.Answer
FROM Anon_User_Answers
INNER JOIN Answers ON (Anon_User_Answers.Answer_ID = Answers.Answer_ID)
WHERE Respondee_ID=".$iAnonRespID." AND Answers.Question_ID='".$iQuesID."'
ORDER BY Answers.Display_Order, Answers.Answer_ID";
// echo $sql;
$recA=mysqli_query($conn,$sql);
while ($rowA=mysqli_fetch_assoc($recA)) {
if (empty($rowA["Answer"])) {
$arrAnswers[]= $rowA["Answer_Text"];
} else {
$arrAnswers[]= $rowA["Answer"];
}
}
}
return $arrAnswers;
}
$GroupID = intval($_GET["id"]);
$Questionnaire_ID = intval($_GET["qid"]);
$conn=$conni;
$sql = "SELECT * FROM Questionnaires WHERE Questionnaire_ID='".$Questionnaire_ID."'";
$rec = mysqli_query($conn,$sql);
if ($row = mysqli_fetch_assoc($rec)) {
extract($row);
}
mysqli_free_result($rec);
if ($_REQUEST["type"]=="wordcs") {
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment; filename='.str_replace(" ","_",$Questionnaire_Name).'_Consolidated.doc');
?>
<style>
body, p, td, th {
font-family: "Calibri", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 11pt;
}
h1 {
font-family: "Calibri Light", "Calibri", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #ED7D31;
font-size:18pt;
}
</style>
<?php
include("inc_testreport.php");
} elseif ($_REQUEST["type"]=="worddt") {
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment; filename='.str_replace(" ","_",$Questionnaire_Name).'_Detailed.doc');
?>
<style>
body, p, td, th {
font-family: "Calibri", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 11pt;
}
h1 {
font-family: "Calibri Light", "Calibri", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #ED7D31;
font-size:18pt;
}
</style>
<?php
include("inc_testreportdetailed.php");
} else {
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=test.xls');
$sql = "SELECT Sections.Section_ID, Section_Name, COUNT(*) AS NumQues
FROM Sections JOIN Questions USING (Section_ID)
WHERE Sections.Questionnaire_ID='".$Questionnaire_ID."' ";
if (isset($_REQUEST["sid"])) $sql.=" AND Sections.Section_ID IN (".$_REQUEST["sid"].") ";
$sql.=" GROUP BY Sections.Section_ID, Section_Name
ORDER BY Sections.Display_Order, Sections.Section_ID";
$recS = mysqli_query($conn,$sql);
$iNumSteps = mysqli_num_rows($recS);
?>
<table border="0" cellspacing="0" cellpadding="5" width="700">
<tr>
<td>Response Date</td>
<?php if ($HasScore==1) echo "<td>Score</td>"; ?>
<?php
while ($rowS = mysqli_fetch_assoc($recS)) {
?>
<td colspan="<?php echo $rowS["NumQues"]; ?>"><?php echo $rowS["Section_Name"]; ?></td>
<?php
}
mysqli_data_seek($recS,0);
?>
</tr>
<tr>
<td></td>
<?php if ($HasScore==1) echo "<td></td>"; ?>
<?php
while ($rowS = mysqli_fetch_assoc($recS)) {
$sql = "SELECT Questions.*
FROM Questions WHERE Questions.Questionnaire_ID='".$Questionnaire_ID."'
AND Section_ID=".$rowS["Section_ID"]." ORDER BY Questions.Display_Order";
$recQ = mysqli_query($conn,$sql);
while ($rowQ = mysqli_fetch_assoc($recQ)) {
?>
<td><?php echo $rowQ["Question"]; ?></td>
<?php
}
}
mysqli_data_seek($recS,0);
?>
</tr>
<?php
$sql="SELECT * FROM AnonRespondees WHERE Questionnaire_ID='".$Questionnaire_ID."'
AND Response_Date>='".date("Y-m-d", strtotime($_GET["startdate"]))."'
AND AnonRespondees.GroupID=".$GroupID."
ORDER BY AnonRespondees.Anon_Respondee_Name";
// echo $sql;
$recResp=mysqli_query($conn,$sql);
$UserNum=0;
$arrCells=array();
while ($rowResp=mysqli_fetch_assoc($recResp)) {
$UserNum++;
$arrCells[]=date("Y-m-d", strtotime($rowResp["Response_Date"]));
if ($HasScore==1) $arrCells[]=$rowResp["Score"];
$iStep=1;
$bHasPrevious=false;
while ($rowS = mysqli_fetch_assoc($recS)) {
extract($rowS);
$sql = "SELECT Questions.*
FROM Questions WHERE Questions.Questionnaire_ID='".$Questionnaire_ID."'
AND Section_ID=".$Section_ID." ORDER BY Questions.Display_Order";
// echo $sql;
$recQ = mysqli_query($conn,$sql);
while ($rowQ = mysqli_fetch_assoc($recQ)) {
extract($rowQ);
$arrAnswers=DisplayAnswersExcel($rowResp["Anon_RespondeeID"], $rowQ["Question_ID"], $rowQ["IsMulti"]);
if (count($arrAnswers)>1) {
$i=0;
foreach ($arrAnswers as $val) {
$i++;
foreach ($arrCells as $val2) {
echo "<td>".$val2."</td>";
}
echo "<td>".$val."</td>";
echo "</tr>
";
if ($i<count($arrAnswers)) echo "<tr>";
}
} else {
$arrCells[]=$arrAnswers[0];
}
}
}
mysqli_free_result($recQ);
echo "<tr>";
foreach ($arrCells as $val2) {
echo "<td>".$val2."</td>";
}
echo "</tr>
";
unset($arrCells);
$arrCells=array();
mysqli_data_seek($recS,0);
}
?>
</table>
<?php
}
?>