<?
/*-------------------------------------------------------------------
prepare_dnd_question.php Ver. $Revision: 1.3 $ $Date: 2003/05/21 02:00:39 $
*
Copyright (C) 2000 Hong Kong Baptist University
*
This file is part of the Quadrille system.
* This program is free software; it is distributed under the terms of
the GNU General Public License, either version 2, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*
---------------------------------------------------------------------
*/
?>
<?
function main()
{
require "./global_inc.php";
include "./config_inc.php";
include $language_pack;
global $originalimage;
global $addnow1;
global $question_uid;
global $continue;
global $image_warning;
global $question_image_id;
global $question_image;
global $question_image_name;
global $question_image_size;
global $question_image_type;
global $question_sound_id;
global $question_sound;
global $question_sound_name;
global $question_sound_size;
global $question_sound_type;
global $answer_1;
global $answer_1_id;
global $answer_1_name;
global $answer_1_size;
global $answer_1_type;
global $answer_2;
global $answer_2_id;
global $answer_2_name;
global $answer_2_size;
global $answer_2_type;
global $answer_3;
global $answer_3_id;
global $answer_3_name;
global $answer_3_size;
global $answer_3_type;
global $answer_4;
global $answer_4_id;
global $answer_4_name;
global $answer_4_size;
global $answer_4_type;
global $hidden_question_image;
global $hidden_choice_image_1;
global $hidden_choice_image_2;
global $hidden_choice_image_3;
global $hidden_choice_image_4;
global $hidden_choice_image_5;
global $instruction;
global $question_content;
global $description;
global $level;
global $language;
global $hints;
global $answer_image_id;
global $old_image_id;
global $old_answer_1_id;
global $old_answer_2_id;
global $old_answer_3_id;
global $old_answer_4_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
global $next_save;
// 20-May-2003 check upload file size greater than parameter upload_max_filesize in php.ini
global $_FILES;
$image_warning=0;
if($addnow1!=1) // just to display
{
if($question_uid!="")
{
$query_question = "SELECT * FROM QUESTION WHERE UID=".$question_uid;
$result = mysql_query($query_question);
$row = mysql_fetch_array($result);
$questiontype = $row["QTYPE_UID"];
$language = $row["Q_LANG"];
$level = $row["LEVEL"];
$description = $row["Q_DESC"];
$query_tab_name = "SELECT TAB_NAME FROM QUESTION_TYPE WHERE UID=".$questiontype;
$result = mysql_query($query_tab_name);
$row = mysql_fetch_array($result);
$tab_name = $row["TAB_NAME"];
$query = "SELECT * FROM ".$tab_name." WHERE Q_UID=".$question_uid;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$question_image_id = $row["IMAGE_UID"];
$question_sound_id = $row["SOUND_UID"];
$question_content = $row["Q_CONTENT"];
$instruction = $row["INSTRUCTION"];
for($i=0; $i<4; $i++)
{
$j=$i+1;
$answer_image_id[$i] = $row["CHOICE_$j"];
$hints[$i] = $row["HINT_$j"];
eval('$x'.$j.' = $row["TARGETLEFT_$j"];');
eval('$y'.$j.' = $row["TARGETTOP_$j"];');
}
$binary_directory=$binary_directory."/course_".$cookie["course_uid"]."/unit_".$cookie["unit_uid"];
for($i=0; $i<4; $i++)
{
if($answer_image_id[$i]<>0 && $answer_image_id[$i]<>'')
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$answer_image_id[$i];
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$originalimage[$i] =$binary_directory."/".$answer_image_id[$i].strrchr($row["FILENAME"],'.');
}
}
if($question_image_id<>0 && $question_image_id<>"")
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$question_image_id;
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$question_image_name =$row["FILENAME"];
}
if($question_image_id==0 || $question_image_id=='')
$image = "transparent.gif";
else
{
$image = $binary_directory."/".$question_image_id.strrchr($question_image_name,'.');
}
$content = show_with_data(0, $image);
}
else
{
$description = preg_replace ("/".preg_quote("\\'")."/","'",$description);
$description = preg_replace ("/".preg_quote("\\\\")."/","\\",$description);
$content = show_with_data(0, "transparent.gif");
}
}
else if(isset($next_save))
{
if($next_save==$SUBMIT)
{
if($old_image_id<>$question_image_id && $old_image_id<>'' && $old_image_id<>0)
delete_binary_file($old_image_id);
if($answer_1_id<>$old_answer_1_id && $old_answer_1_id<>'' && $old_answer_1_id<>0)
delete_binary_file($old_answer_1_id);
if($answer_2_id<>$old_answer_2_id && $old_answer_2_id<>'' && $old_answer_2_id<>0)
delete_binary_file($old_answer_2_id);
if($answer_3_id<>$old_answer_3_id && $old_answer_3_id<>'' && $old_answer_3_id<>0)
delete_binary_file($old_answer_3_id);
if($answer_4_id<>$old_answer_4_id && $old_answer_4_id<>'' && $old_answer_4_id<>0)
delete_binary_file($old_answer_4_id);
save_to_db();
}
else
{
if($question_image_id<>$old_image_id && $question_image_id<>'' && $question_image_id<>0)
delete_binary_file($question_image_id);
$question_image_id = $old_image_id;
$old_image_id='';
if($question_sound_id)
delete_binary_file($question_sound_id);
if($answer_1_id<>$old_answer_1_id && $answer_1_id<>'' && $answer_1_id<>0)
delete_binary_file($answer_1_id);
$answer_image_id[0] = $old_answer_1_id;
$old_answer_1_id='';
if($answer_2_id<>$old_answer_2_id && $answer_2_id<>'' && $answer_2_id<>0)
delete_binary_file($answer_2_id);
$answer_image_id[1] = $old_answer_2_id;
$old_answer_2_id='';
if($answer_3_id<>$old_answer_3_id && $answer_3_id<>'' && $answer_3_id<>0)
delete_binary_file($answer_3_id);
$answer_image_id[2] = $old_answer_3_id;
$old_answer_3_id='';
if($answer_4_id<>$old_answer_4_id && $answer_4_id<>'' && $answer_4_id<>0)
delete_binary_file($answer_4_id);
$answer_image_id[3] = $old_answer_4_id;
$old_answer_4_id='';
$binary_directory=$binary_directory."/course_".$cookie["course_uid"]."/unit_".$cookie["unit_uid"]; if($question_image_id==0 || $question_image_id=='')
$image = "transparent.gif";
else
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$question_image_id;
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$question_image_name =$row["FILENAME"];
$image = $binary_directory."/".$question_image_id.strrchr($question_image_name,'.');
}
for($i=0; $i<4; $i++)
{
if($answer_image_id[$i]<>0 && $answer_image_id[$i]<>'')
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$answer_image_id[$i];
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$originalimage[$i] =$binary_directory."/".$answer_image_id[$i].strrchr($row["FILENAME"],'.');
}
}
$description = preg_replace ("/".preg_quote("\\'")."/","'",$description);
$description = preg_replace ("/".preg_quote("\\\\")."/","\\",$description);
$instruction = preg_replace ("/".preg_quote("\\'")."/","'",$instruction);
$instruction = preg_replace ("/".preg_quote("\\\\")."/","\\",$instruction);
$question_content = preg_replace ("/".preg_quote("\\'")."/","'",$question_content);
$question_content = preg_replace ("/".preg_quote("\\\\")."/","\\",$question_content);
for($i=0; $i<=3; $i++)
{
$hints[$i] = preg_replace ("/".preg_quote("\\'")."/","'",$hints[$i]);
$hints[$i] = preg_replace ("/".preg_quote("\\\\")."/","\\",$hints[$i]);
}
$content = show_with_data(0, $image);
}
}
else{
if($continue=="")
{
// 20-May-2003 check upload file size greater than parameter upload_max_filesize in php.ini
$vn = array('question_image', 'question_sound', 'answer_1', 'answer_2', 'answer_3', 'answer_4');
$size_error=check_upload_file($_FILES, $vn);
//if($hidden_question_image==1 && $question_image !="none") jenus 23-apr-03
if($hidden_question_image==1 && $question_image_size > 0)
{
$size_error.=check_file_size($question_image,$question_image_name);
$image_warning=check_image_file($question_image);
}
//if($question_sound!="none") jenus-apr-03
if($question_sound_size > 0)
$size_error.=check_file_size($question_sound,$question_sound_name);
//if ($hidden_choice_image_1==1 && $answer_1 != "none") jenus-apr-03
if ($hidden_choice_image_1==1 && $answer_1_size > 0)
$size_error.=check_file_size($answer_1,$answer_1_name);
//if ($hidden_choice_image_2==1 && $answer_2 != "none") jenus-apr-03
if ($hidden_choice_image_2==1 && $answer_2_size > 0)
$size_error.=check_file_size($answer_2,$answer_2_name);
//if ($hidden_choice_image_3==1 && $answer_3 != "none") jenus-apr-03
if ($hidden_choice_image_3==1 && $answer_3_size > 0)
$size_error.=check_file_size($answer_3,$answer_3_name);
//if ($hidden_choice_image_4==1 && $answer_4 != "none") jenus 23-apr-03
if ($hidden_choice_image_4==1 && $answer_4_size > 0)
$size_error.=check_file_size($answer_4,$answer_4_name);
if($size_error!="")
$content = show_with_data($size_error, "transparent.gif");
else if($image_warning!="0")
{
// if ($hidden_question_image==1 && $question_image != "none") jenus 23-apr-03
if ($hidden_question_image==1 && $question_image_size > 0)
{
$old_image_id = $question_image_id;
$question_image_id = store_bin ($question_image,$question_image_name, $question_image_size,$question_image_type);
}
else if($hidden_question_image==0)
{
$old_image_id = $question_image_id;
$question_image_id=0;
}
else
$old_image_id = $question_image_id;
// if ($question_sound != "none") jenus 23-apr-03
if ($question_sound_size > 0)
$question_sound_id = store_bin ($question_sound,$question_sound_name, $question_sound_size,$question_sound_type);
//if ($hidden_choice_image_1==1 && $answer_1 != "none") jenus 23-apr-03
if ($hidden_choice_image_1==1 && $answer_1_size > 0)
{
$old_answer_1_id = $answer_1_id;
$answer_1_id = store_bin ($answer_1,$answer_1_name,$answer_1_size,$answer_1_type);
}
else if($hidden_choice_image_1==0)
{
$old_answer_1_id = $answer_1_id;
$answer_1_id=0;
}
else
$old_answer_1_id = $answer_1_id;
// if ($hidden_choice_image_2==1 && $answer_2 != "none") jenus 23-apr-03
if ($hidden_choice_image_2==1 && $answer_2_size > 0)
{
$old_answer_2_id = $answer_2_id;
$answer_2_id = store_bin ($answer_2,$answer_2_name,$answer_2_size,$answer_2_type);
}
else if($hidden_choice_image_2==0)
{
$old_answer_2_id = $answer_2_id;
$answer_2_id=0;
}
else
$old_answer_2_id = $answer_2_id;
//if ($hidden_choice_image_3==1 && $answer_3 != "none") jenus 23-apr-03
if ($hidden_choice_image_3==1 && $answer_3_size > 0)
{
$old_answer_3_id = $answer_3_id;
$answer_3_id = store_bin ($answer_3,$answer_3_name,$answer_3_size,$answer_3_type);
}
else if($hidden_choice_image_3==0)
{
$old_answer_3_id = $answer_3_id;
$answer_3_id=0;
}
else
$old_answer_3_id = $answer_3_id;
// if ($hidden_choice_image_4==1 && $answer_4 != "none") jenus 23-apr-03
if ($hidden_choice_image_4==1 && $answer_4_size > 0)
{
$old_answer_4_id = $answer_4_id;
$answer_4_id = store_bin ($answer_4,$answer_4_name,$answer_4_size,$answer_4_type);
}
else if($hidden_choice_image_4==0)
{
$old_answer_4_id = $answer_4_id;
$answer_4_id=0;
}
else
$old_answer_4_id = $answer_4_id;
$content = show_warning($image_warning,$question_image_id,$question_sound_id, $answer_1_id, $answer_2_id, $answer_3_id, $answer_4_id);
}
else
{
// if ($hidden_question_image==1 && $question_image != "none") jenus 23-apr-03
if ($hidden_question_image==1 && $question_image_size > 0)
{
$old_image_id = $question_image_id;
$question_image_id = store_bin ($question_image,$question_image_name, $question_image_size,$question_image_type);
}
else if($hidden_question_image==0)
{
$old_image_id = $question_image_id;
$question_image_id=0;
}
else
$old_image_id = $question_image_id;
//if ($question_sound != "none") jenus 23-apr-03
if ($question_sound_size > 0)
$question_sound_id = store_bin ($question_sound,$question_sound_name, $question_sound_size,$question_sound_type);
// if ($hidden_choice_image_1==1 && $answer_1 != "none") jenus 23-apr-03
if ($hidden_choice_image_1==1 && $answer_1_size > 0)
{
$old_answer_1_id = $answer_1_id;
$answer_1_id = store_bin ($answer_1,$answer_1_name,$answer_1_size,$answer_1_type);
}
else if($hidden_choice_image_1==0)
{
$old_answer_1_id = $answer_1_id;
$answer_1_id=0;
}
else
$old_answer_1_id = $answer_1_id;
//if ($hidden_choice_image_2==1 && $answer_2 != "none") jenus 23-apr-03
if ($hidden_choice_image_2==1 && $answer_2_size > 0)
{
$old_answer_2_id = $answer_2_id;
$answer_2_id = store_bin ($answer_2,$answer_2_name,$answer_2_size,$answer_2_type);
}
else if($hidden_choice_image_2==0)
{
$old_answer_2_id = $answer_2_id;
$answer_2_id=0;
}
else
$old_answer_2_id = $answer_2_id;
//if ($hidden_choice_image_3==1 && $answer_3 != "none") jenus 23-apr-03
if ($hidden_choice_image_3==1 && $answer_3_size > 0)
{
$old_answer_3_id = $answer_3_id;
$answer_3_id = store_bin ($answer_3,$answer_3_name,$answer_3_size,$answer_3_type);
}
else if($hidden_choice_image_3==0)
{
$old_answer_3_id = $answer_3_id;
$answer_3_id=0;
}
else
$old_answer_3_id = $answer_3_id;
//if ($hidden_choice_image_4==1 && $answer_4 != "none") jenus 23-apr-03
if ($hidden_choice_image_4==1 && $answer_4_size > 0)
{
$old_answer_4_id = $answer_4_id;
$answer_4_id = store_bin ($answer_4,$answer_4_name,$answer_4_size,$answer_4_type);
}
else if($hidden_choice_image_4==0)
{
$old_answer_4_id = $answer_4_id;
$answer_4_id=0;
}
else
$old_answer_4_id = $answer_4_id;
$content = dnd("");
$DND_Next = 1;
}
}
else if($continue=="yes")
{
$content = dnd("");
$DND_Next = 1;
}
else
{
if($question_image_id<>$old_image_id && $question_image_id<>'' && $question_image_id<>0)
delete_binary_file($question_image_id);
$question_image_id = $old_image_id;
if($question_sound_id)
delete_binary_file($question_sound_id);
if($answer_1_id<>$old_answer_1_id && $answer_1_id<>'' && $answer_1_id<>0)
delete_binary_file($answer_1_id);
$answer_image_id[0] = $old_answer_1_id;
if($answer_2_id<>$old_answer_2_id && $answer_2_id<>'' && $answer_2_id<>0)
delete_binary_file($answer_2_id);
$answer_image_id[1] = $old_answer_2_id;
if($answer_3_id<>$old_answer_3_id && $answer_3_id<>'' && $answer_3_id<>0)
delete_binary_file($answer_3_id);
$answer_image_id[2] = $old_answer_3_id;
if($answer_4_id<>$old_answer_4_id && $answer_4_id<>'' && $answer_4_id<>0)
delete_binary_file($answer_4_id);
$answer_image_id[3] = $old_answer_4_id;
$binary_directory=$binary_directory."/course_".$cookie["course_uid"]."/unit_".$cookie["unit_uid"]; if($question_image_id==0 || $question_image_id=='')
$image = "transparent.gif";
else
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$question_image_id;
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$question_image_name =$row["FILENAME"];
$image = $binary_directory."/".$question_image_id.strrchr($question_image_name,'.');
}
for($i=0; $i<4; $i++)
{
if($answer_image_id[$i]<>0 && $answer_image_id[$i]<>'')
{
$query_binary = "SELECT FILENAME FROM TEMPLATE_BINARY WHERE UID=".$answer_image_id[$i];
$result = mysql_query($query_binary);
$row = mysql_fetch_array($result);
$originalimage[$i] =$binary_directory."/".$answer_image_id[$i].strrchr($row["FILENAME"],'.');
}
}
$description = preg_replace ("/".preg_quote("\\'")."/","'",$description);
$description = preg_replace ("/".preg_quote("\\\\")."/","\\",$description);
$instruction = preg_replace ("/".preg_quote("\\'")."/","'",$instruction);
$instruction = preg_replace ("/".preg_quote("\\\\")."/","\\",$instruction);
$question_content = preg_replace ("/".preg_quote("\\'")."/","'",$question_content);
$question_content = preg_replace ("/".preg_quote("\\\\")."/","\\",$question_content);
for($i=0; $i<=3; $i++)
{
$hints[$i] = preg_replace ("/".preg_quote("\\'")."/","'",$hints[$i]);
$hints[$i] = preg_replace ("/".preg_quote("\\\\")."/","\\",$hints[$i]);
}
$content = show_with_data(0, $image);
}
}
insert_header();
if($DND_Next==1)
{
$java = get_file("javascript/submit_question_back.js");
$java .= get_file("javascript/image_real_position.js");
$java .= get_file("javascript/create_layer.js");
$java .= get_file("javascript/question_dragdrop_next.js");
$java=ereg_replace("<BEGIN>SUBMIT<END>",$SUBMIT,$java);
$java=ereg_replace("<BEGIN>ANSWER1_OUTBOUND<END>",$ANSWER1_OUTBOUND,$java);
$java=ereg_replace("<BEGIN>ANSWER2_OUTBOUND<END>",$ANSWER2_OUTBOUND,$java);
$java=ereg_replace("<BEGIN>ANSWER3_OUTBOUND<END>",$ANSWER3_OUTBOUND,$java);
$java=ereg_replace("<BEGIN>ANSWER4_OUTBOUND<END>",$ANSWER4_OUTBOUND,$java);
$java=ereg_replace("<BEGIN>CREATELAYER<END>",create_layer(),$java);
$java=ereg_replace("<BEGIN>ADDCHILD<END>",add_child(),$java);
}
else if($image_warning==0)
{ /* Insert Javascript */
$java = get_file("javascript/question.js");
$java .= get_file("javascript/question_dragdrop.js");
$java = ereg_replace("<BEGIN>QUESTION_CONTENT_ERROR<END>",$QUESTION_CONTENT_ERROR,$java);
$java = ereg_replace("<BEGIN>BACKGROUND_IMAGE_MUST<END>",$BACKGROUND_IMAGE_MUST,$java);
$java = ereg_replace("<BEGIN>NOT_ENOUGH_CHOICE<END>",$NOT_ENOUGH_CHOICE,$java);
$java = ereg_replace("<BEGIN>IMAGE_TYPE_ERROR<END>",$IMAGE_TYPE_ERROR,$java);
$java = ereg_replace("<BEGIN>SOUND_TYPE_ERROR<END>",$SOUND_TYPE_ERROR,$java);
$java = ereg_replace("<BEGIN>SYSTEM_FIND_ERROR<END>",$SYSTEM_FIND_ERROR,$java);
$java .= "<script src=\"javascript/valid_input_{$lang_name}.js\"></script>";
}
/* Insert Body */
$currentlocation = insert_current_location($cookie["course_uid"],$cookie["unit_uid"],'');
if($DND_Next==1) $html = get_template($template,$template_dir);
else $html = get_template($template,$template_dir);
$html = ereg_replace("<BEGIN>JAVASCRIPT<END>",$java,$html);
if($question_uid<>'')
$html=ereg_replace("<BEGIN>TITLE<END>",$PAGE_TITLE["QUESTION_EDIT"],$html);
else
$html=ereg_replace("<BEGIN>TITLE<END>",$PAGE_TITLE["QUESTION_ADD"],$html);
$html = ereg_replace("<BEGIN>CURRENTLOCATION<END>",$currentlocation,$html);
$html = ereg_replace("<BEGIN>CONTENT<END>",$content,$html);
$html = ereg_replace("<BEGIN>COPYRIGHT<END>",$COPYRIGHT,$html);
return $html;
}
/** Show html content **/
function show_with_data($error , $question_img_source)
{
include ( "./config_inc.php");
include $language_pack;
include $language_pack;
global $question_uid;
global $questiontype;
global $level;
global $language;
global $description;
global $addnow1;
global $question_image;
global $question_image_name;
global $question_image_type;
global $question_image_size;
global $question_sound;
global $question_sound_name;
global $question_sound_type;
global $question_sound_size;
global $question;
global $question_content;
global $instruction;
global $answer_1;
global $answer_2;
global $answer_3;
global $answer_4;
global $answer_5;
global $hints;
global $originalimage;
global $answer_image_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
$content="";
if($error!="0")
$content.="<font color=red>$error</font>";
$content.="\n<form name=\"form1\" method=\"post\" action=\"question_edit.php\" enctype=\"multipart/form-data\" onSubmit=\"MM_validateForm('instruction','','R','answer_1','','R','answer_2','','R');return document.MM_returnValue\">";
$content.="\n<div>";
$content.="\n<table border=\"0\" width=\"469\">";
$content.=question_part($question_img_source);
$content.="\n<tr>";
$content.="\n<td colspan=\"4\"> </td>";
$content.="\n</tr>";
$content.="\n<tr>";
$content.="\n<td colspan=\"4\" class=\"question\">$ANSWER_PART</td>";
$content.="\n</tr>";
$content.="\n<tr>";
$content.="\n<td colspan=\"2\">$ANSWER</td>";
$content.="\n<td>$HINTS_TITLE</td>";
$content.="\n</tr>";
$text_answer[0] = 'A.';
$text_answer[1] = 'B. ';
$text_answer[2] = 'C. ';
$text_answer[3] = 'D. ';
$img_name[0] = 'img_answer_1';
$img_name[1] = 'img_answer_2';
$img_name[2] = 'img_answer_3';
$img_name[3] = 'img_answer_4';
$name[0] = 'answer_1';
$name[1] = 'answer_2';
$name[2] = 'answer_3';
$name[3] = 'answer_4';
$i = 0;
if (!$originalimage[0]) $originalimage[0] = "transparent.gif";
if (!$originalimage[1]) $originalimage[1] = "transparent.gif";
if (!$originalimage[2]) $originalimage[2] = "transparent.gif";
if (!$originalimage[3]) $originalimage[3] = "transparent.gif";
for ($i=0; $i<4; $i++) {
$j=$i+1;
if($i%2==1)
$content.="\n<tr valign=\"middle\" class=\"tableroweven\">";
else
$content.= "\n<tr valign=\"middle\" class=\"tablerowodd\">";
$content.= "\n<td width=\"0\" height=\"0\" nowrap>";
$content.= "<div align=\"left\">".$text_answer[$i]."</div></td>";
$content.= "\n<td width=\"240\" height=\"0\" nowrap>";
$content.= "<div align=\"left\"><img src=\"".$originalimage[$i]."\" height=\"37\" width=\"37\" name=\"".$img_name[$i]."\">";
$content.= "\n<input type=\"file\" name=\"".$name[$i]."\" size=\"10\" onBlur=\"ChangeImage(document.$img_name[$i].src,'".$name[$i]."','".$img_name[$i]."',document.form1.hidden_choice_image_$j)\" value=\"".$originalimage[0]."\">";
if($originalimage[$i]<>'transparent.gif')
{
$content.=" <input type=button name=\"remove_img\" value=\"Drop\" onclick=\"remove_image(document.$img_name[$i], document.form1.hidden_choice_image_$j);\">";
$content.=" <input type=button name=\"restore_img\" value=\"Restore\" onclick=\"restore_image(document.$img_name[$i], document.form1.hidden_choice_image_$j, document.form1.original_choice_image_$j);\">";
$content.="<input type=\"hidden\" name=\"original_choice_image_$j\" value=\"$originalimage[$i]\">";
$content.="<input type=\"hidden\" name=\"hidden_choice_image_$j\" value=\"2\">";
}
else
$content.="<input type=\"hidden\" name=\"hidden_choice_image_$j\" value=\"1\">";
$content.="<input type=\"hidden\" name=\"answer_".$j."_id\" value=\"$answer_image_id[$i]\">";
$content.= "</div></td>";
$content.= "\n<td width=\"0\" height=\"0\" nowrap>";
$content.= "\n<div align=\"left\">";
$content.= "<input type=\"text\" name=\"hints[]\" size=\"30\" value=\"".$hints[$i]."\" onBlur=\"valid_textarea(this,220);\">";
$content.= "</div></td>";
$content.= "</tr>";
}
if($question_img_source=='transparent.gif')
$content.="<input type=\"hidden\" name=\"hidden_question_image\" value=\"1\">";
else
$content.="<input type=\"hidden\" name=\"hidden_question_image\" value=\"2\">";
$content.="\n<input type=\"hidden\" name=\"x1\" value=\"$x1\">";
$content.="\n<input type=\"hidden\" name=\"y1\" value=\"$y1\">";
$content.="\n<input type=\"hidden\" name=\"x2\" value=\"$x2\">";
$content.="\n<input type=\"hidden\" name=\"y2\" value=\"$y2\">";
$content.="\n<input type=\"hidden\" name=\"x3\" value=\"$x3\">";
$content.="\n<input type=\"hidden\" name=\"y3\" value=\"$y3\">";
$content.="\n<input type=\"hidden\" name=\"x4\" value=\"$x4\">";
$content.="\n<input type=\"hidden\" name=\"y4\" value=\"$y4\">";
$content.="<input type=\"hidden\" name=\"questiontype\" value=\"$questiontype\">";
$content.="<input type=\"hidden\" name=\"question_uid\" value=\"$question_uid\">";
$content.="<input type=\"hidden\" name=\"addnow1\" value=\"1\">";
if($question_uid=="")
{
$content.="<input type=\"hidden\" name=\"level\" value=\"$level\">";
$content.="<input type=\"hidden\" name=\"description\" value=\"$description\">";
$content.="<input type=\"hidden\" name=\"language\" value=\"$language\">";
}
else
{
$content.="\n\t\t<tr><td colspan=\"4\"> </td></tr>";
$content.="\n\t\t<tr><td colspan=4>";
$content.="<table border=\"0\" width=\"100%\">";
$content.="\n\t\t<tr><td class=\"tableroweven\">$QUESTION_LEVEL </td>";
$content.="\n\t\t\t<td >";
for($i=0; $i<3; $i++)
{
$content.="\n\t\t\t\t<input type=\"radio\" name=\"level\" value=\"$i\"";
if($level==$i)
$content.=" checked";
$content.=">";
switch($i)
{
case 0:
$content.=$LOW;
break;
case 1:
$content.=$MID;
break;
case 2:
$content.=$HIGH;
break;
}
}
$content.="\n\t\t\t\t</td></tr>";
$content.="\n\t\t\t<tr>";
$content.="\n\t\t<tr><td class=\"tableroweven\">$QUESTION_LANGUAGE </td>";
$content.="\n\t\t\t<td >";
for($i=0; $i<2; $i++)
{
$content.="\n\t\t\t\t<input type=\"radio\" name=\"language\" value=\"$i\"";
if($language==$i)
$content.=" checked";
$content.=">";
switch($i)
{
case 0:
$content.="\n\t\t\t\t$ENGLISH";
break;
case 1:
$content.="\n\t\t\t\t$CHINESE";
break;
}
}
$content.="\n\t\t\t </td></tr>";
$content.="\n\t\t<tr><td class=\"tableroweven\">$QUESTION_DESCRIPTION ";
$content.="<td>";
$content.="<textarea cols=\"50\" rows=\"3\" name=\"description\">$description</textarea></td></tr>";
$content.="</table>";
$content.="\n\t\t\t</td></tr>";
}
$content.="\n<tr>";
$content.="\n<td colspan=\"4\">";
if($question_uid<>'')
$content.="\n<input type=button value=\"$CANCEL\" onclick=\"self.location.href='question_list.php'\">";
else
$content.="\n<input type=button value=\"$CANCEL\" onclick=\"self.location.href='question_add.php'\">";
$content.="\n <input type=submit value=\"$NEXT_STEP\">";
$content.="\n</td>";
$content.="\n</tr>";
$content.="\n</table>";
$content.="\n</div>";
$content.="\n</form>";
$content.="<img src=\"transparent.gif\" name=\"transparent\" width=\"0\" height=\"0\">";
return $content;
}
function show_warning($warning_msg, $question_image_id, $question_sound_id, $answer_1_id, $answer_2_id, $answer_3_id, $answer_4_id)
{
global $questiontype;
global $question_uid;
global $level;
global $language;
global $description;
global $addnow1;
global $question_content;
global $instruction;
global $hints;
global $old_image_id;
global $old_answer_1_id;
global $old_answer_2_id;
global $old_answer_3_id;
global $old_answer_4_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
global $answer_1_id;
global $answer_2_id;
global $answer_3_id;
global $answer_4_id;
$description = preg_replace ("/".preg_quote("\\'")."/","'",$description);
$description = preg_replace ("/".preg_quote("\\\\")."/","\\",$description);
$instruction = preg_replace ("/".preg_quote("\\'")."/","'",$instruction);
$instruction = preg_replace ("/".preg_quote("\\\\")."/","\\",$instruction);
$question_content = preg_replace ("/".preg_quote("\\'")."/","'",$question_content);
$question_content = preg_replace ("/".preg_quote("\\\\")."/","\\",$question_content);
for($i=0; $i<=3; $i++)
{
$hints[$i] = preg_replace ("/".preg_quote("\\'")."/","'",$hints[$i]);
$hints[$i] = preg_replace ("/".preg_quote("\\\\")."/","\\",$hints[$i]);
}
$content.="<p><span class=\"warning\">$warning_msg</span></p>";
$content.="\n<form name=\"form1\" method=\"post\" action=\"question_edit.php\" enctype=\"multipart/form-data\">";
$content.="\n<input type=hidden name=\"questiontype\" value=\"$questiontype\">";
$content.="\n<input type=hidden name=\"question_uid\" value=\"$question_uid\">";
$content.="\n<input type=hidden name=\"level\" value=\"$level\">";
$content.="\n<input type=hidden name=\"language\" value=\"$language\">";
$content.="\n<input type=hidden name=\"description\" value=\"$description\">";
$content.="\n<input type=hidden name=\"addnow1\" value=\"$addnow1\">";
if($question_uid<>'')
$content.="\n<input type=hidden name=\"old_image_id\" value=\"$old_image_id\">";
$content.="\n<input type=hidden name=\"question_image_id\" value=\"$question_image_id\">";
$content.="\n<input type=hidden name=\"question_sound_id\" value=\"$question_sound_id\">";
$content.="\n<input type=hidden name=\"question_content\" value=\"$question_content\">";
$content.="\n<input type=hidden name=\"instruction\" value=\"$instruction\">";
$content.="\n<input type=\"hidden\" name=\"x1\" value=\"$x1\">";
$content.="\n<input type=\"hidden\" name=\"y1\" value=\"$y1\">";
$content.="\n<input type=\"hidden\" name=\"x2\" value=\"$x2\">";
$content.="\n<input type=\"hidden\" name=\"y2\" value=\"$y2\">";
$content.="\n<input type=\"hidden\" name=\"x3\" value=\"$x3\">";
$content.="\n<input type=\"hidden\" name=\"y3\" value=\"$y3\">";
$content.="\n<input type=\"hidden\" name=\"x4\" value=\"$x4\">";
$content.="\n<input type=\"hidden\" name=\"y4\" value=\"$y4\">";
for($i=0; $i<4; $i++)
{
$j=$i+1;
switch($j)
{
case 1:
$content.="\n<input type=hidden name=\"old_answer_1_id\" value=\"$old_answer_1_id\">";
$content.="\n<input type=hidden name=\"answer_".$j."_id\" value=\"".$answer_1_id."\">";
break;
case 2:
$content.="\n<input type=hidden name=\"old_answer_2_id\" value=\"$old_answer_2_id\">";
$content.="\n<input type=hidden name=\"answer_".$j."_id\" value=\"".$answer_2_id."\">";
break;
case 3:
$content.="\n<input type=hidden name=\"old_answer_3_id\" value=\"$old_answer_3_id\">";
$content.="\n<input type=hidden name=\"answer_".$j."_id\" value=\"".$answer_3_id."\">";
break;
case 4:
$content.="\n<input type=hidden name=\"old_answer_4_id\" value=\"$old_answer_4_id\">";
$content.="\n<input type=hidden name=\"answer_".$j."_id\" value=\"".$answer_4_id."\">";
break;
}
$content.="\n<input type=hidden name=\"hints[]\" value=\"$hints[$i]\">";
}
$content.="\n<input type=submit name=\"continue\" value=\"no\">";
$content.="\n<input type=submit name=\"continue\" value=\"yes\">";
$content.="\n</form>";
return $content;
}
function save_to_db()
{
global $question_uid;
global $cookie;
global $level;
global $language;
global $description;
global $question_content;
global $instruction;
global $answer_1_id;
global $answer_2_id;
global $answer_3_id;
global $answer_4_id;
global $hints;
global $question_image_id;
global $question_sound_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
global $questiontype;
if($question_uid=="") // add a new question
{
/* Add to Question */
$q_uid = addquestiontab($questiontype,$cookie["user_uid"],$cookie["unit_uid"],$level,$description,$language);
/* Add to DND */
$query = "INSERT INTO DND (Q_UID, Q_CONTENT, INSTRUCTION, SOUND_UID, IMAGE_UID, CHOICE_1, HINT_1, "
."CHOICE_2, CHOICE_3, CHOICE_4, HINT_2, HINT_3, HINT_4, TARGETTOP_1, TARGETLEFT_1, "
."TARGETTOP_2, TARGETLEFT_2, TARGETTOP_3, TARGETLEFT_3, TARGETTOP_4, TARGETLEFT_4) VALUES "
."('$q_uid', '".text2blob($question_content)."', '".text2blob($instruction)."', '$question_sound_id"
."', '$question_image_id', '$answer_1_id', '".text2blob($hints[0])
."', '$answer_2_id', '$answer_3_id', '$answer_4_id"
."', '".text2blob($hints[1])."','".text2blob($hints[2])."','".text2blob($hints[3])
."', '".text2blob($y1)."', '".text2blob($x1)
."', '".text2blob($y2)."', '".text2blob($x2)
."', '".text2blob($y3)."', '".text2blob($x3)
."', '".text2blob($y3)."', '".text2blob($x4)."')";
mysql_query($query);
header("location:question_add.php");
}
else // Update an existing question
{
updatequestiontab ($questiontype,$cookie["user_uid"],$cookie["unit_uid"],$level,$description,$language,$question_uid);
$query = "UPDATE DND SET Q_CONTENT='".text2blob($question_content)."',INSTRUCTION='".text2blob($instruction)."',"
."IMAGE_UID='$question_image_id',SOUND_UID='$question_sound_id',"
."CHOICE_1='".text2blob($answer_1_id)."',HINT_1='".text2blob($hints[0])."',"
."CHOICE_2='".text2blob($answer_2_id)."',HINT_2='".text2blob($hints[1])."',"
."CHOICE_3='".text2blob($answer_3_id)."',HINT_3='".text2blob($hints[2])."',"
."CHOICE_4='".text2blob($answer_4_id)."',HINT_4='".text2blob($hints[3])."',"
."TARGETTOP_1='".text2blob($y1)."', TARGETLEFT_1='".text2blob($x1)."',"
."TARGETTOP_2='".text2blob($y2)."', TARGETLEFT_2='".text2blob($x2)."',"
."TARGETTOP_3='".text2blob($y3)."', TARGETLEFT_3='".text2blob($x3)."',"
."TARGETTOP_4='".text2blob($y4)."', TARGETLEFT_4='".text2blob($x4)."'"
." WHERE Q_UID = ".$question_uid;
mysql_query($query);
header("location:question_list.php");
}
}
function add_child()
{
global $q_choice;
for ($i=1; $i<=4 ;$i++)
{ if ($q_choice[$i]<>'') {
$addchild.=<<<_HTML_
myLayer.addChild(myLayer$i);
_HTML_;
}
}
return $addchild;
}
function create_layer()
{ include "config_inc.php";
include $language_pack;
global $total_choice_no;
global $boundary_height;
global $q_choice;
global $question_image_id;
global $old_image_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
global $answer_1_id;
global $answer_2_id;
global $answer_3_id;
global $answer_4_id;
$q_choice[1] = $answer_1_id;
$q_choice[2] = $answer_2_id;
$q_choice[3] = $answer_3_id;
$q_choice[4] = $answer_4_id;
$binary_directory=$binary_directory."/course_".$cookie["course_uid"]."/unit_".$cookie["unit_uid"];
$layer="myLayer = new DynLayer(null, get_real_position_of(document.img,'x'), get_real_position_of(document.img,'y'), document.img.width+100, $boundary_height, null);";
$now = 1;
for ($i=1; $i<=4 ;$i++)
{ if ($q_choice[$i]<>'' && $q_choice[$i]<>0) {
$filetype=find_filetype($q_choice[$i]);
$scale=GetImageScaleSize("$binary_directory/$q_choice[$i].$filetype",3);
$img_width=$scale["width"];
$img_height=$scale["height"];
$LAYER='';
if($question_image_id==$old_image_id)
{
switch($i)
{
case 1:
$LAYER = "myLayer$i.moveTo($x1,$y1)";
break;
case 2:
$LAYER = "myLayer$i.moveTo($x2,$y2)";
break;
case 3:
$LAYER = "myLayer$i.moveTo($x3,$y3)";
break;
case 4:
$LAYER = "myLayer$i.moveTo($x4,$y4)";
break;
}
}
$layer.=<<< _HTML_
myLayer$i = new DynLayer(null, document.img.width+40, ($now-1)*{$IMAGE_HEIGHT[3]}, $img_width,$img_height , '');
DragEvent.setDragBoundary(myLayer$i, 0, document.img.width+100, $boundary_height, 0);
DragEvent.enableDragEvents(myLayer$i); // enable myLayer to be dragged
eval('$LAYER;');
myLayer$i.setHTML('<img name="img_$i" src="$binary_directory/$q_choice[$i].$filetype "
_HTML_;
$layer.=image_scale("$binary_directory/$q_choice[$i].$filetype",3);
$layer.=" >');\n";
$now += 1;
}
else {
$layer.="\nmyLayer$i = new DynLayer(null, 0, 0, 0, 0, null,'hidden');";
}
}
return $layer;
}
function dnd($question_uid_list)
{ include "config_inc.php";
include $language_pack;
global $question_uid;
global $questiontype;
global $level;
global $language;
global $description;
global $addnow1;
global $question_image;
global $question_image_name;
global $question_image_type;
global $question_image_size;
global $question_sound;
global $question_sound_name;
global $question_sound_type;
global $question_sound_size;
global $question_content;
global $instruction;
global $answer_1_id;
global $answer_2_id;
global $answer_3_id;
global $answer_4_id;
global $hints;
global $question_image_id;
global $question_sound_id;
global $boundary_height;
global $q_choice;
global $q_img;
global $q_sound;
global $old_answer_1_id;
global $old_answer_2_id;
global $old_answer_3_id;
global $old_answer_4_id;
global $old_image_id;
global $x1;
global $x2;
global $x3;
global $x4;
global $y1;
global $y2;
global $y3;
global $y4;
$q_choice[1] = $answer_1_id;
$q_choice[2] = $answer_2_id;
$q_choice[3] = $answer_3_id;
$q_choice[4] = $answer_4_id;
$description = preg_replace ("/".preg_quote("\\'")."/","'",$description);
$description = preg_replace ("/".preg_quote("\\\\")."/","\\",$description);
$instruction = preg_replace ("/".preg_quote("\\'")."/","'",$instruction);
$instruction = preg_replace ("/".preg_quote("\\\\")."/","\\",$instruction);
$question_content = preg_replace ("/".preg_quote("\\'")."/","'",$question_content);
$question_content = preg_replace ("/".preg_quote("\\\\")."/","\\",$question_content);
for($i=0; $i<=3; $i++)
{
$hints[$i] = preg_replace ("/".preg_quote("\\'")."/","'",$hints[$i]);
$hints[$i] = preg_replace ("/".preg_quote("\\\\")."/","\\",$hints[$i]);
}
//die($question_content."---".$new_content);
if($question_image_id<>"" && $question_image_id<>0) $q_img = $question_image_id.".".find_filetype($question_image_id);
if($question_sound_id<>"" && $question_sound_id<>0) $q_sound = $question_sound_id.strrchr($question_sound_name,'.');
$binary_directory=$binary_directory."/course_".$cookie["course_uid"]."/unit_".$cookie["unit_uid"];
for( $i=4 ; $i>0 ; $i--)
{
if($q_choice[$i]<>'' && $q_choice[$i]<>0)
$total_choice_no += 1;
}
$total_choice_height = 60 * $total_choice_no + 10*($total_choice_no-1);
if($question_image_id<>"" && $question_image_id<>0)
$filetype=find_filetype($question_image_id);
$scale=GetImageScaleSize("$binary_directory/$question_image_id.$filetype",1);
$background_height = $scale["height"];
if($total_choice_height > $background_height)
$boundary_height = $total_choice_height;
else
$boundary_height = $background_height;
$content.="\n\t<form name=\"form1\" method=\"post\" action=\"question_edit.php\" onSubmit=\"MM_validateForm('instruction','','R','answer_1','','R','answer_2','','R');return document.MM_returnValue\">";
$content.="\n\t<p>";
$content.="\n\t\t$instruction";
$content.="\n\t</p>";
$content.="<table width=\"450\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if($question_image_id<>"")
$filetype=find_filetype($question_image_id);
$scale=GetImageScaleSize("$binary_directory/$question_image_id.$filetype",1);
$content.="\n\t<tr><td valign=top height=\"".$boundary_height."\" width=\"".$scale["width"]."\">";
$content.="<img name=\"img\" src=\"$binary_directory/$q_img\" ".image_scale("$binary_directory/$q_img",1)." >";
$content.="</td>";
$content.="</tr>";
$content.="\n\t<tr>";
$content.="\n\t\t<td width=\"425\"class=\"content\">$question_content</td>";
$content.="\n\t</tr>";
$content.="\n\t\t\t<tr><td colspan=\"2\"><p> </p>";
$content.="\n\t\t\t<p>";
$content.="\n<input type=hidden name=\"question_uid\" value=\"$question_uid\">";
$content.="\n<input type=hidden name=\"questiontype\" value=\"$questiontype\">";
$content.="\n<input type=hidden name=\"level\" value=\"$level\">";
$content.="\n<input type=hidden name=\"language\" value=\"$language\">";
$content.="\n<input type=hidden name=\"description\" value=\"$description\">";
$content.="\n<input type=hidden name=\"addnow1\" value=\"$addnow1\">";
$content.="\n<input type=hidden name=\"question_image_id\" value=\"$question_image_id\">";
$content.="\n<input type=hidden name=\"old_image_id\" value=\"$old_image_id\">";
$content.="\n<input type=hidden name=\"question_sound_id\" value=\"$question_sound_id\">";
$content.="\n<input type=hidden name=\"question_content\" value=\"$question_content\">";
$content.="\n<input type=hidden name=\"instruction\" value=\"$instruction\">";
$content.="\n<input type=hidden name=\"answer_1_id\" value=\"$answer_1_id\">";
$content.="\n<input type=hidden name=\"answer_2_id\" value=\"$answer_2_id\">";
$content.="\n<input type=hidden name=\"answer_3_id\" value=\"$answer_3_id\">";
$content.="\n<input type=hidden name=\"answer_4_id\" value=\"$answer_4_id\">";
$content.="\n<input type=hidden name=\"old_answer_1_id\" value=\"$old_answer_1_id\">";
$content.="\n<input type=hidden name=\"old_answer_2_id\" value=\"$old_answer_2_id\">";
$content.="\n<input type=hidden name=\"old_answer_3_id\" value=\"$old_answer_3_id\">";
$content.="\n<input type=hidden name=\"old_answer_4_id\" value=\"$old_answer_4_id\">";
for($i=0; $i<=3; $i++)
$content.="\n<input type=hidden name=\"hints[]\" value=\"$hints[$i]\">";
$content.="\n<input type=\"hidden\" name=\"x1\" value=\"$x1\">";
$content.="\n<input type=\"hidden\" name=\"y1\" value=\"$y1\">";
$content.="\n<input type=\"hidden\" name=\"x2\" value=\"$x2\">";
$content.="\n<input type=\"hidden\" name=\"y2\" value=\"$y2\">";
$content.="\n<input type=\"hidden\" name=\"x3\" value=\"$x3\">";
$content.="\n<input type=\"hidden\" name=\"y3\" value=\"$y3\">";
$content.="\n<input type=\"hidden\" name=\"x4\" value=\"$x4\">";
$content.="\n<input type=\"hidden\" name=\"y4\" value=\"$y4\">";
$content.="\n<input type=\"hidden\" name=\"next_save\" value=\"\">";
$content.="\n\t\t\t\t<input type=\"submit\" value=\"$CANCEL\" onclick=(document.form1.next_save.value=\"$CANCEL\")>";
$content.="\n\t\t\t\t<input type=\"submit\" value=\"$SUBMIT\" onclick=(document.form1.next_save.value=\"$SUBMIT\")>";
$content.="\n\t\t\t</p>";
$content.="\n\t\t\t</td></tr>";
$content.="\n\t\t</table>";
$content.="\n\t</form>";
return $content;
}
?>