Skip to content

Commit

Permalink
Merge pull request #149 from CCALI/quizwright/release
Browse files Browse the repository at this point in the history
Quizwright/release
  • Loading branch information
emasters authored Jan 7, 2020
2 parents db48cbb + d6f4c89 commit 4f4814e
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 55 deletions.
9 changes: 6 additions & 3 deletions includes/build-xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Added: Yes/No question type
08/16/2017
Added: Quiz table ID for use by Drupal
02/04/2019
Added: ®
*/
function makeQuestionTextXML($text)
{ // 05/11/2017 SJG Helper function
Expand Down Expand Up @@ -55,16 +57,17 @@ function BuildXML($mysqli,$lid,$data,$author)
.'<BR />'.htmlspecialchars($author['authortitle'])
.'<BR />'.htmlspecialchars($author['authorschool'])
.'</DIV>';


$qwinfo='<p>Quiz automatically generated by QuizWright®.</p>';
$info=array(
'TITLE'=>htmlspecialchars($data['title']),
'VERSION'=> date("Y-m-d H:i:s"),
'GENERATOR'=>'QW', // QuizWright
'QWID'=> $lid, // Quiz ID
'SUBJECTAREA'=>htmlspecialchars($data['subjectarea']),
'COMPLETIONTIME'=>htmlspecialchars($data['completiontime']),
'NOTES'=>'Book automatically created by QuizWright',
'DESCRIPTION'=> ( $description)
'NOTES'=>$qwinfo,
'DESCRIPTION'=> $description . $qwinfo
);
$xml.='<INFO>';
foreach ($info as $key=>$value) $xml.='<'.$key.'>'. $value .'</'.$key.'>';
Expand Down
4 changes: 2 additions & 2 deletions includes/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">CALI QuizWright</a>
<a class="navbar-brand" href="#">CALI QuizWright®</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
Expand Down Expand Up @@ -94,7 +94,7 @@
<div id="main-panel">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Welcome to QuizWright</h4>
<h4>Welcome to QuizWright®</h4>
</div>
<div class="panel-body">
<p>QuizWright is a web app that lets teachers write individual MC, T/F, Y/N questions,
Expand Down
1 change: 1 addition & 0 deletions includes/question-list-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$author = json_decode($row['profile'], TRUE);
$pid = $row['pid'];
$pageText = $page['page-question'];
$pageTopic = $page['page-topic'];
$pageAuthor = $author['authorfullname'];
if ($bank)
{
Expand Down
2 changes: 2 additions & 0 deletions includes/quiz-detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<div class="col-sm-3 control-label" for="submit">This quiz was published <?=$publishdate?></div>
<div class="col-sm-8">
<a id="quiz-run" class="btn btn-primary" target=_blank href="<?=$published?>">Run the Quiz</a>
<a id="quiz-text" class="btn btn-default" target=_blank href="./includes/quiz-report.php?lid=<?php echo $lid;?>">Full Quiz Report</a>
<a id="quiz-clone" class="btn btn-default">Duplicate Quiz</a>
</div>
</div>
Expand All @@ -97,6 +98,7 @@
<a id="quiz-publish" class="btn btn-primary" target=_blank data-href="./includes/quiz-publish.php?lid=<?php echo $lid;?>">Publish Quiz</a>
<a id="quiz-page-order" class="btn btn-default">Change Questions</a>
<a id="quiz-info-edit" class="btn btn-default">Edit Description</a>
<a id="quiz-text" class="btn btn-default" target=_blank href="./includes/quiz-report.php?lid=<?php echo $lid;?>">Full Quiz Report</a>
<a id="quiz-cancel" class="btn btn-default">Publish Later</a>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions includes/quiz-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$publishlid=intval($_GET['lid']);

$sql = "SELECT * FROM `info` WHERE uid = '$uid'";
$sql = "SELECT * FROM `info` WHERE uid = '$uid' order by lid desc";
if ($result = $mysqli->query($sql))
{
while ($row = $result->fetch_assoc())
Expand Down Expand Up @@ -51,7 +51,9 @@
<a class="btn btn-default" title="Review details of my quiz" href="./includes/quiz-detail.php?lid=<?=$lid?>">Details</a>
<a class="btn btn-default glyphicon glyphicon-pencil" title="Edit quiz information" href="./includes/quiz-info-edit.php?lid=<?=$lid?>"> </a>
<a class="btn btn-default glyphicon glyphicon-th-list" title="Change questions in the quiz" href="./includes/quiz-page-order.php?lid=<?=$lid?>"></a>
<a class="btn btn-default" title="Preview the quiz in the test viewer" target=_blank href="./cav/web/preview/index.php?quiz=<?=$lid?>">Preview</a>
<!--
<a class="btn btn-default" title="Preview the quiz in the test viewer" target=_blank href="./cav/web/preview/index.php?quiz=<?=$lid?>">Preview</a>
-->
<a class="btn btn-default" title="View the XML data that makes up a quiz" target=_blank href="./book-data-xml.php?lid=<?=$lid?>">XML</a>
</td>
<?php } ?>
Expand Down
100 changes: 55 additions & 45 deletions includes/quiz-publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,67 @@

// Note: user id is ignored since students will need this
$lid = intval($_GET['lid']);
//$SQL="select data from info where lid = $lid";


// Query to get lesson and author data
$SQL="select info.data, people.profile from info,people where lid = $lid and info.uid = people.uid";

if ($result = $mysqli->query($SQL))
{
while ($row = $result->fetch_assoc())
{
$data = json_decode($row['data'], TRUE);
$profile = json_decode($row['profile'], TRUE);
$jqbookdata = BuildXML($mysqli,$lid,$data,$profile);

//some CURL stuff
//$URL = "https://d7.calidev.org/autopublish/upload";

//setting the curl parameters.
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,PUBLISH_URL);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $jqbookdata);

if (curl_errno($ch))
{
// moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
// $response is a bit of XML
//echo $response;
$xml = new SimpleXMLElement($response);
// var_dump($xml);
$apURL = $xml->URL[0];
header("Location: $apURL");
//echo $response;
//echo "<script type='text/javascript'>window.open('$apURL', '_blank')</script>";
}
curl_close($ch);

}

while ($row = $result->fetch_assoc())
{
$data = json_decode($row['data'], TRUE);
$profile = json_decode($row['profile'], TRUE);
$jqbookdata = BuildXML($mysqli,$lid,$data,$profile);
// Create quiz folder and add/update jqBookData.
$dir = "../quizzes/$lid";
if (!is_dir($dir))
{
mkdir($dir);
}
file_put_contents($dir.'/jqBookData.xml',$jqbookdata);
//some CURL stuff
//setting the curl parameters.
$ch = curl_init();
$upload_url = PUBLISH_URL."/".$lid;
$cfile = curl_file_create($dir.'/jqBookData.xml','application/xml','jqBookData.xml');
$data = array('quiz_files' => $cfile);
$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_URL,$upload_url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

if (curl_errno($ch))
{
// moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
// $response is a bit of XML
//echo $response;
//die;
$xml = new SimpleXMLElement($response);
// var_dump($xml);
$apURL = $xml->URL[0];
header("Location: $apURL");
//echo $response;
//echo "<script type='text/javascript'>window.open('$apURL', '_blank')</script>";
}
curl_close($ch);

}

return;
}

Expand Down
162 changes: 162 additions & 0 deletions includes/quiz-report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<html><body><h1>CALI QuizWright® Report</h1>
<?php
/*
06/17/19 Short form LessonText of the Quiz including all meta, introduction/concllusion and question/answers.
*/
require ("user-session.php");
$lid = intval($_GET['lid']);
// Note: user id is required so only author can see report
$sql="select info.data, people.profile from info,people where info.uid = '$uid' and lid = $lid and info.uid = people.uid";

// Load author/quiz info
if ($result = $mysqli->query($sql))
{
if ($row = $result->fetch_assoc())
{
$data = json_decode($row['data'], TRUE);
$profile = json_decode($row['profile'], TRUE);
//$published=$row['location'];
//$publishdate=$row['publishdate'];
//$numPages = count($data['pages']); // .pages is array of pid's, order matches lesson order.
PrintLessonText($mysqli,$lid,$data,$profile);
}
}





function PrintLessonText($mysqli,$lid,$data,$author)
{ // 06/18/19
echo '<table>';
$qwinfo='<p>Quiz automatically generated by QuizWright®.</p>';
niceTuples(['Title'=>htmlspecialchars($data['title'])]);

alt();
niceTuples([
'Description'=> textBlock($data['calidescription'] ),
'Subject Area'=>htmlspecialchars($data['subjectarea']),
'Completion Time'=>htmlspecialchars($data['completiontime']),
'Author Name'=>htmlspecialchars($author['authorfullname']),
'Title'=>htmlspecialchars($author['authortitle']),
'School'=>htmlspecialchars($author['authorschool']),
'Version'=> date("Y-m-d H:i:s"),
'Notes'=>$qwinfo]);

// 05/11/2017 SJG Introduction and conclusion are optional, grab them and incorporate at the right spots.
$pageIntroText = textBlock($data['quiz-intro']);
$pageConclusionText = textBlock($data['quiz-conclusion']);
$numPages = count($data['pages']);
if( $pageIntroText != "")
{
alt();
niceTuples(['Introduction'=>$pageIntroText]);
}
$pageNum=0;
if ($numPages>0)
{
// Load each question for this quiz.
foreach ($data['pages'] as $pid)
{
$pid=intval($pid);
$sql = "SELECT data FROM `page` WHERE pid = $pid";
if ($result = $mysqli->query($sql))
{
if ($row = $result->fetch_assoc())
{
// Check page type so we get accurate detail (but as of 3/2017 there are all quiz type) which translates to Multiple Choice type.
$page = json_decode($row['data'], TRUE);
$pagetype = $page['page-type'];
$pageNum += 1;
$pageTypeText='';
$pageCorrect='';
$pageChoices='';
alt();
niceTuples([
'Question' => $pageNum,
'Text'=>textBlock($page['page-question'])]);
switch ($pagetype)
{
case 'quiz-yn': // ### Yes/No style of quiz question
$pageTypeText='Yes/No';
$isyes = $page['yes-is-correct']=='true';
$pageCorrect=$isyes?"Yes":"No";
niceTuples(['Correct'=>$pageCorrect]);
break;

case 'quiz-tf': // ### True/False style of quiz question
$istrue = $page['true-is-correct']=='true';
$pageCorrect=$istrue?'True':'False';;
niceTuples(['Correct'=>$pageCorrect]);
break;

case 'Quiz':// ### Standard quiz question which is multiple choice:
case 'quiz-mc':
case '':
$pageCorrect=$page['page-choice-correct-text'];
niceTuples(['Correct'=>$pageCorrect]);
for ($wrong=1;$wrong<=7;$wrong++)
{
if (isset($page['page-choice-wrong-'.$wrong.'-text']))
{
$wrongText = $page['page-choice-wrong-'.$wrong.'-text'];
if ($wrongText!='')
{
niceTuples(['Wrong #'.$wrong=>textBlock ($wrongText)]);
}
}
}
break;

default:
// Should not get here.
}
niceTuples([
'Feedback'=>textBlock($page['page-feedback']),
'Notes'=>textBlock(htmlspecialchars('Topic: '. $page['page-topic'])),
'Attribution'=>$page['page-attribution']
]);
}
}
}
}
if($pageConclusionText != "")
{
alt();
niceTuples(['Conclusion'=>$pageConclusionText]);
}
}

function alt()
{
echo '<tr bgcolor=#888><td colspan=2> </td></tr>';
}
function textBlock($text)
{ // 05/11/2017 SJG Helper function
return HTML2XML($text);
}
function HTML2XML($str)
{ // Convert HTML encoding (clean CKEditor HTML markup) into XML encodings.
$str = str_replace( array('&lt;','&gt;','&amp;'),array(chr(1),chr(2),chr(3)),$str);
$str= html_entity_decode($str,0,'UTF-8');
$str = str_replace(array(chr(1),chr(2),chr(3)),array('&lt;','&gt;','&amp;'),$str);
//$str = '<![CDATA['.$str.']]>'; Would be best but Viewer doesn't understand it.??
return $str;
}

function niceTuples($tuples)
{
foreach ($tuples as $key=>$value)
{
if ($value!='')
{
echo '<tr valign=top><td align=right>'.$key.':</td><td>'.$value.'</td></tr>';
}
}
}


?>


</body></html>
2 changes: 1 addition & 1 deletion includes/utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function mergeObjects($old,$new)
return $old;
}

define('MAXCHARS',120);
function oneLinerHTML($html)
{ // 06/28/2017 SJG Strip html of HTML tags and shorten to MAXCHARS characters for use in lists of questions/quizzes.
// Ideally, use CSS markup for wrapping. This hack works for now and reduces traffic a bit.
define('MAXCHARS',120);
$text = trim(strip_tags($html));
if (strlen($text)>MAXCHARS)
{
Expand Down
4 changes: 2 additions & 2 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $("#page").click(function(){
});

$("#question-new").click(function(){
$("#main-panel").load("./includes/page-quiz.inc");
$("#main-panel").load("./includes/page-quiz.php");
});

$("#quiz-new").click(function(){
Expand All @@ -44,7 +44,7 @@ $("#profile-edit, #author-edit").click(function(){

// homepage buttons
$("#add-question").click(function(){
$("#main-panel").load("./includes/page-quiz.inc");
$("#main-panel").load("./includes/page-quiz.php");
});
$("#add-quiz").click(function(){
$("#main-panel").load("./includes/quiz-prep-pages.php");
Expand Down
File renamed without changes.

0 comments on commit 4f4814e

Please sign in to comment.