Fixed Partial \"Import a test from qti2\"

skala
Ronny Velasquez 15 years ago
parent dbe4fc0f3e
commit 84feb58304
  1. 29
      main/exercice/exercice.php
  2. 1174
      main/exercice/export/exercise_import.inc.php
  3. 101
      main/exercice/qti2.php
  4. 8
      main/exercice/question.class.php

@ -427,10 +427,10 @@ if ($show != 'result') {
require_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
require_once ('export/qti2/qti2_export.php');
require_once 'export/qti2/qti2_export.php';
$export = export_exercise($exerciseId, true);
require_once (api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php');
require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$temp_dir_short = uniqid();
$temp_zip_dir = $archive_path . "/" . $temp_dir_short;
@ -786,6 +786,8 @@ if (($is_allowedToEdit) and ($origin != 'learnpath')) {
echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_test.gif', get_lang('NewEx')) . get_lang('NewEx') . '</a>';
echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('question_add.gif', get_lang('AddQuestionToExercise')) . get_lang('AddQuestionToExercise') . '</a>';
echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('jqz.gif', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
// link to import qti2 ...
echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('jqz.gif', get_lang('ImportQtiQuiz')) . get_lang('ImportQtiQuiz') . '</a>';
echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
}
@ -869,9 +871,9 @@ if ($show == 'test') {
$myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
$mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
$mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
$token = Security::get_token();
$token = Security::get_token();
while ($row = Database :: fetch_array($result)) {
//validacion when belongs to a session
$session_img = api_get_session_image($row['session_id'], $_user['status']);
@ -907,15 +909,13 @@ if ($show == 'test') {
} else {
echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
}
//echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
?>
<td>
<a href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
<a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
<a href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
<a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
<a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=clean_results&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;" ><img width="16" src="../img/clean_group.gif" border="0" title="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" /></a>
<?php
if ($row['results_disabled']) {
@ -948,8 +948,13 @@ if ($show == 'test') {
// else if not active
?>
<a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=enable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0" title="<?php echo get_lang('Activate'); ?>" alt="<?php echo api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
<?php
}
// export qti ...
echo '<a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a>';
echo "</td>";
echo "</tr>\n";
} else { // student only
@ -1365,7 +1370,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
}
$parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
$table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
$table->set_additional_parameters($parameters);
if ($is_allowedToEdit || $is_tutor) {

File diff suppressed because it is too large Load Diff

@ -0,0 +1,101 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Code for Qti2 import integration.
* @package chamilo.exercise
* @author Ronny Velasquez
* @version $Id: qti2.php 2010-03-12 12:14:25Z $
*/
// name of the language file that needs to be included
$language_file = 'exercice';
// including the global Chamilo file
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
// including additional libraries
require_once 'exercise.class.php';
require_once 'question.class.php';
require_once 'answer.class.php';
// section (for the tabs)
$this_section = SECTION_COURSES;
// access restriction: only teachers are allowed here
if (!api_is_allowed_to_edit(null, true)) {
api_not_allowed();
}
// the breadcrumbs
$interbreadcrumb[]= array ("url"=>"./exercice.php", "name"=> get_lang('Exercices'));
$is_allowedToEdit = api_is_allowed_to_edit(null, true);
/**
* This function displays the form for import of the zip file with qti2
*/
function ch_qti2_display_form() {
$name_tools = get_lang('ImportQtiQuiz');
$form = '<div class="actions">';
$form .= '<a href="exercice.php?show=test">' . Display :: return_icon('message_reply_forum.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
$form .= '</div>';
$form .= '<form action='.api_get_self()."?".api_get_cidreq().' method="post" enctype="multipart/form-data">';
$form .= '<div class="row"><div class="form_header">'.$name_tools.'</div></div>';
$form .= '<div class="row">';
$form .= '<div class="label" style="padding:10px">';
$form .= '<span class="form_required">*</span>';
$form .= get_lang('DownloadFile').' :';
$form .= '</div>';
$form .= '<div class="formw">';
$form .= '<div style="padding:10px">
<input type="file" name="userFile"><br /><br />
<button type="submit" class="upload" name="submit" value="'.get_lang('Send').'">'.get_lang('SendFile').'</button>
</div>';
$form .= '</div></div>';
echo $form;
}
/**
* This function will import the zip file with the respective qti2
* @param array $uploaded_file ($_FILES)
*/
function ch_qti2_import_file($array_file) {
$unzip = 0;
$lib_path = api_get_path(LIBRARY_PATH);
require_once $lib_path.'fileUpload.lib.php';
require_once $lib_path.'fileManage.lib.php';
$process = process_uploaded_file($array_file);
if (preg_match('/\.zip$/i', $array_file['name'])) {
// if it's a zip, allow zip upload
$unzip = 1;
}
if ($process == true && $unzip == 1) {
$main_path = api_get_path(SYS_CODE_PATH);
require_once $main_path.'exercice/export/exercise_import.inc.php';
require_once $main_path.'exercice/export/qti2/qti2_classes.php';
$imported = import_exercise($array_file['name']);
if ($imported == true) {
header('Location: exercice.php?' . Security::remove_XSS(api_get_cidreq()) .'');
} else {
Display::display_error_message(get_lang('The import was not performed'));
return false;
}
}
}
// import file
if ((api_is_allowed_to_edit(null, true))) {
if (isset($_POST['submit'])) {
ch_qti2_import_file($_FILES['userFile']);
}
}
// display header
Display::display_header($name_tools, get_lang('Exercise'));
// display qti form
ch_qti2_display_form();
// display the footer
Display::display_footer();
?>

@ -775,11 +775,11 @@ abstract class Question
* @param - integer $exerciseId - exercise ID
* @param - boolean $fromSave - comming from $this->save() or not
*/
function addToList($exerciseId, $fromSave=FALSE) {
global $TBL_EXERCICE_QUESTION;
$id=$this->id;
function addToList($exerciseId, $fromSave = FALSE) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$id = $this->id;
// checks if the exercise ID is not in the list
if(!in_array($exerciseId,$this->exerciseList)) {
if (!in_array($exerciseId,$this->exerciseList)) {
$this->exerciseList[]=$exerciseId;
$sql="INSERT INTO $TBL_EXERCICE_QUESTION (question_id, exercice_id) VALUES('".Database::escape_string($id)."','".Database::escape_string($exerciseId)."')";
Database::query($sql);

Loading…
Cancel
Save