Minor - format code.

1.9.x
Julio Montoya 10 years ago
parent e479f4b744
commit 8446f11b3c
  1. 55
      main/exercice/question_admin.inc.php
  2. 27
      main/exercice/question_create.php
  3. 347
      main/exercice/question_list_admin.inc.php
  4. 15
      main/exercice/testheaderpage.php
  5. 1
      main/exercice/unique_answer.class.php
  6. 7
      main/exercice/upload_exercise.php

@ -1,15 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Statement (?) administration
* This script allows to manage the statements of questions.
* It is included from the script admin.php
* @package chamilo.exercise
* @author Olivier Brouckaert
* @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
*/
/**
* Code
* Statement (?) administration
* This script allows to manage the statements of questions.
* It is included from the script admin.php
* @package chamilo.exercise
* @author Olivier Brouckaert
* @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
*/
// INIT QUESTION
@ -44,7 +42,6 @@ if (is_object($objQuestion)) {
$objQuestion->createForm($form);
// answer form elements
$objQuestion->createAnswersForm($form);
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
@ -56,29 +53,29 @@ if (is_object($objQuestion)) {
if (isset($_POST['submitQuestion']) && $form->validate()) {
// question
$objQuestion->processCreation($form, $objExercise);
$objQuestion->processCreation($form, $objExercise);
// answers
$nb_answers = isset($nb_answers) ? $nb_answers : 0;
$objQuestion->processAnswersCreation($form, $nb_answers);
// answers
$nb_answers = isset($nb_answers) ? $nb_answers : 0;
$objQuestion->processAnswersCreation($form, $nb_answers);
// TODO: maybe here is the better place to index this tool, including answers text
// TODO: maybe here is the better place to index this tool, including answers text
// redirect
if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
if(isset($_GET['editQuestion'])) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
} else {
//New question
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
}
} else {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
}
// redirect
if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
if(isset($_GET['editQuestion'])) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
} else {
//New question
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
}
} else {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
}
} else {
if (isset($questionName)) {
echo '<h3>'.$questionName.'</h3>';
}
if (isset($questionName)) {
echo '<h3>'.$questionName.'</h3>';
}
if (!empty($pictureName)) {
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
}

@ -1,12 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercise
* @package chamilo.exercise
*/
/**
* Code
*/
// name of the language file that needs to be included
$language_file='exercice';
@ -36,7 +35,7 @@ $form->addElement('header','',get_lang('AddQuestionToExercise'));
$question_list = Question::get_question_type_list();
$question_list_options = array();
foreach ($question_list as $key=> $value) {
foreach ($question_list as $key=> $value) {
$question_list_options[$key] = addslashes(get_lang($value[1]));
}
$form->addElement('select', 'question_type_hidden', get_lang('QuestionType'), $question_list_options, array('id' => 'question_type_hidden'));
@ -72,26 +71,26 @@ $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validqu
if ($form->validate()) {
$values = $form->exportValues();
$answer_type = $values['question_type_hidden'];
// check feedback_type from current exercise for type of question delineation
$exercise_id = intval($values['exercice']);
$exercise_id = intval($values['exercice']);
$sql = "SELECT feedback_type FROM $tbl_exercices WHERE c_id = $course_id AND id = '$exercise_id'";
$rs_feedback_type = Database::query($sql);
$row_feedback_type = Database::fetch_row($rs_feedback_type);
$feedback_type = $row_feedback_type[0];
// if question type does not belong to self-evaluation (immediate feedback) it'll send an error
if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
header('Location: question_create.php?'.api_get_cidreq().'&error=true');
exit;
}
exit;
}
header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
exit;
} else {
// header
Display::display_header($nameTools);
echo '<div class="actions">';
echo '<a href="exercice.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
@ -104,13 +103,13 @@ if ($form->validate()) {
}
function check_question_type($parameter) {
$question_list = Question::get_question_type_list();
$question_list = Question::get_question_type_list();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
}
}
if (in_array($parameter, $valid_question_types)) {
return true;
} else {
return false;
}
}
}

@ -1,128 +1,127 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Code library for HotPotatoes integration.
* @package chamilo.exercise
* @author Olivier Brouckaert & Julio Montoya & Hubert Borderiou 21-10-2011 (Question by category)
* Code library for HotPotatoes integration.
* @package chamilo.exercise
* @author Olivier Brouckaert & Julio Montoya & Hubert Borderiou 21-10-2011 (Question by category)
* QUESTION LIST ADMINISTRATION
*
* This script allows to manage the question list
* It is included from the script admin.php
*/
* QUESTION LIST ADMINISTRATION
*
* This script allows to manage the question list
* It is included from the script admin.php
*/
// deletes a question from the exercise (not from the data base)
if ($deleteQuestion) {
// if the question exists
if ($objQuestionTmp = Question::read($deleteQuestion)) {
$objQuestionTmp->delete($exerciseId);
// if the question exists
if ($objQuestionTmp = Question::read($deleteQuestion)) {
$objQuestionTmp->delete($exerciseId);
// if the question has been removed from the exercise
if ($objExercise->removeFromList($deleteQuestion)) {
$nbrQuestions--;
}
}
// destruction of the Question object
unset($objQuestionTmp);
// if the question has been removed from the exercise
if ($objExercise->removeFromList($deleteQuestion)) {
$nbrQuestions--;
}
}
// destruction of the Question object
unset($objQuestionTmp);
}
$ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."&exercise_id=".intval($exerciseId);
?>
<style>
.ui-state-highlight { height: 30px; line-height: 1.2em; }
/*Fixes edition buttons*/
.ui-accordion-icons .ui-accordion-header .edition a {
padding-left:4px;
}
</style>
<style>
.ui-state-highlight { height: 30px; line-height: 1.2em; }
/*Fixes edition buttons*/
.ui-accordion-icons .ui-accordion-header .edition a {
padding-left:4px;
}
</style>
<div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
<p>
<div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
<p>
<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0; display:none;">
</span>
<?php echo get_lang("AreYouSureToDelete"); ?>
</p>
</div>
<script>
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
autoOpen: false,
show: "blind",
resizable: false,
height:150,
modal: false
});
<?php echo get_lang("AreYouSureToDelete"); ?>
</p>
</div>
$(".opener").click(function() {
var targetUrl = $(this).attr("href");
$( "#dialog-confirm" ).dialog({
modal: true,
buttons: {
"<?php echo get_lang("Yes"); ?>": function() {
location.href = targetUrl;
$( this ).dialog( "close" );
},
"<?php echo get_lang("No"); ?>": function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-confirm" ).dialog("open");
return false;
});
<script>
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
autoOpen: false,
show: "blind",
resizable: false,
height:150,
modal: false
});
var stop = false;
$( "#question_list h3" ).click(function( event ) {
if ( stop ) {
event.stopImmediatePropagation();
event.preventDefault();
stop = false;
}
});
$(".opener").click(function() {
var targetUrl = $(this).attr("href");
$( "#dialog-confirm" ).dialog({
modal: true,
buttons: {
"<?php echo get_lang("Yes"); ?>": function() {
location.href = targetUrl;
$( this ).dialog( "close" );
var icons = {
header: "ui-icon-circle-arrow-e",
headerSelected: "ui-icon-circle-arrow-s"
};
},
"<?php echo get_lang("No"); ?>": function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-confirm" ).dialog("open");
return false;
});
var stop = false;
$( "#question_list h3" ).click(function( event ) {
if ( stop ) {
event.stopImmediatePropagation();
event.preventDefault();
stop = false;
}
});
/* We can add links in the accordion header */
$("div > div > div > .edition > div > a").click(function() {
//Avoid the redirecto when selecting the delete button
if (this.id.indexOf('delete') == -1) {
newWind = window.open(this.href,"_self");
newWind.focus();
return false;
}
});
var icons = {
header: "ui-icon-circle-arrow-e",
headerSelected: "ui-icon-circle-arrow-s"
};
$( "#question_list" ).accordion({
icons: icons,
autoHeight: false,
active: false, // all items closed by default
collapsible: true,
header: ".header_operations"
})
/* We can add links in the accordion header */
$("div > div > div > .edition > div > a").click(function() {
//Avoid the redirecto when selecting the delete button
if (this.id.indexOf('delete') == -1) {
newWind = window.open(this.href,"_self");
newWind.focus();
return false;
}
});
.sortable({
cursor: "move", // works?
update: function(event, ui) {
var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']);?>";
$.post("<?php echo $ajax_url ?>", order, function(reponse){
$("#message").html(reponse);
$( "#question_list" ).accordion({
icons: icons,
autoHeight: false,
active: false, // all items closed by default
collapsible: true,
header: ".header_operations"
})
.sortable({
cursor: "move", // works?
update: function(event, ui) {
var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']);?>";
$.post("<?php echo $ajax_url ?>", order, function(reponse){
$("#message").html(reponse);
});
},
axis: "y",
placeholder: "ui-state-highlight", //defines the yellow highlight
handle: ".moved", //only the class "moved"
stop: function() {
stop = true;
}
});
},
axis: "y",
placeholder: "ui-state-highlight", //defines the yellow highlight
handle: ".moved", //only the class "moved"
stop: function() {
stop = true;
}
});
});
</script>
});
</script>
<?php
//we filter the type of questions we can add
@ -136,7 +135,7 @@ unset($_SESSION['less_answer']);
// If we are in a test
$inATest = isset($exerciseId) && $exerciseId > 0;
if (!$inATest) {
echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
} else {
// Title line
echo "<div>";
@ -149,7 +148,7 @@ if (!$inATest) {
echo "<div style='clear:both'>&nbsp;</div>";
echo '<div id="question_list">';
if ($nbrQuestions) {
if ($nbrQuestions) {
//Always getting list from DB
$questionList = $objExercise->selectQuestionList(true);
@ -161,65 +160,69 @@ if (!$inATest) {
$styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
if (is_array($questionList)) {
foreach ($questionList as $id) {
//To avoid warning messages
if (!is_numeric($id)) {
continue;
}
$objQuestionTmp = Question::read($id);
$question_class = get_class($objQuestionTmp);
foreach ($questionList as $id) {
//To avoid warning messages
if (!is_numeric($id)) {
continue;
}
$objQuestionTmp = Question::read($id);
$question_class = get_class($objQuestionTmp);
$clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
/*$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
$clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
/*$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
if ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) {
$edit_link = '<a>'.Display::return_icon('edit_na.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
}*/
$edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
'<a>'.Display::return_icon(
'edit_na.png',
get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
array(),
ICON_SIZE_SMALL
).'</a>' :
'<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
Display::return_icon(
'edit.png',
get_lang('Modify'),
array(),
ICON_SIZE_SMALL
).'</a>';
'<a>'.Display::return_icon(
'edit_na.png',
get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
array(),
ICON_SIZE_SMALL
).'</a>' :
'<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
Display::return_icon(
'edit.png',
get_lang('Modify'),
array(),
ICON_SIZE_SMALL
).'</a>';
$delete_link = null;
if ($objExercise->edit_exercise_in_lp == true) {
$delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';
}
if ($objExercise->edit_exercise_in_lp == true) {
$delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';
}
$edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
$actions = Display::tag('div', $edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
$edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
$actions = Display::tag('div', $edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
$title = Security::remove_XSS($objQuestionTmp->selectTitle());
$move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
// Question name
$questionName = Display::tag('div', '<a href="#" title = "'.htmlentities($title).'">'.$move.' '.cut($title, 42).'</a>', array('style'=>$styleQuestion));
$questionName = Display::tag(
'div',
'<a href="#" title = "'.htmlentities($title).'">'.$move.' '.cut($title, 42).'</a>',
array('style'=>$styleQuestion)
);
// Question type
list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
// Question type
list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
// Question category
$txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
if (empty($txtQuestionCat)) {
$txtQuestionCat = "-";
}
$questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
// Question category
$txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
if (empty($txtQuestionCat)) {
$txtQuestionCat = "-";
}
$questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
// Question level
$txtQuestionLevel = $objQuestionTmp->level;
// Question level
$txtQuestionLevel = $objQuestionTmp->level;
if (empty($objQuestionTmp->level)) {
$txtQuestionLevel = '-';
}
@ -229,32 +232,32 @@ if (!$inATest) {
$questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
echo '<div id="question_id_list_'.$id.'" >';
echo '<div class="header_operations">';
echo $questionName;
echo $questionType;
echo $questionCategory;
echo $questionLevel;
echo $questionScore;
echo $actions;
echo '</div>';
echo '<div class="question-list-description-block">';
echo '<p>';
//echo get_lang($question_class.$label);
echo get_lang($question_class);
echo '<br />';
//echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
echo '<br />';
showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
echo '</p>';
echo '</div>';
echo '<div class="header_operations">';
echo $questionName;
echo $questionType;
echo $questionCategory;
echo $questionLevel;
echo $questionScore;
echo $actions;
echo '</div>';
echo '<div class="question-list-description-block">';
echo '<p>';
//echo get_lang($question_class.$label);
echo get_lang($question_class);
echo '<br />';
//echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
echo '<br />';
showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
echo '</p>';
echo '</div>';
echo '</div>';
unset($objQuestionTmp);
}
}
}
}
}
}
if (!$nbrQuestions) {
echo Display::display_warning_message(get_lang('NoQuestion'));
}
echo '</div>'; //question list div
if (!$nbrQuestions) {
echo Display::display_warning_message(get_lang('NoQuestion'));
}
echo '</div>'; //question list div
}

@ -1,13 +1,12 @@
<?php //$id: $
<?php
/* For licensing terms, see /license.txt */
/**
* Code library for HotPotatoes integration.
* @package chamilo.exercise
* @author Istvan Mandak
*/
/**
* Code
*/
// name of the language file that needs to be included
$language_file='exercice';
@ -16,9 +15,7 @@ require '../inc/global.inc.php';
require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
$documentPath= api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
$my_file = Security::remove_XSS($_GET['file']);
$my_file=str_replace(array('../','\\..','\\0','..\\'),array('','','',''),urldecode($my_file));
$title = GetQuizName($my_file,$documentPath);
if ($title =='') {
$title = basename($my_file);
@ -31,9 +28,9 @@ if (isset($_SESSION['gradebook'])){
if (!empty($gradebook) && $gradebook=='view') {
$interbreadcrumb[]= array (
'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
'name' => get_lang('ToolGradebook')
);
'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
'name' => get_lang('ToolGradebook')
);
}
$interbreadcrumb[]= array ("url"=>"./exercice.php", "name"=> get_lang('Exercices'));
Display::display_header($nameTools,"Exercise");

@ -12,7 +12,6 @@
* @author Julio Montoya
* @package chamilo.exercise
**/
class UniqueAnswer extends Question
{
static $typePicture = 'mcua.png';

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Upload quiz: This script shows the upload quiz feature
* Initial work by Isaac flores on Nov 4 of 2010
@ -327,15 +328,15 @@ function lp_upload_quiz_action_handling() {
$globalScore = null;
$objAnswer = new Answer($question_id, $courseId);
$globalScore = $score_list[$i][3];
// Calculate the number of correct answers to divide the
// Calculate the number of correct answers to divide the
// score between them when importing from CSV
$numberRightAnswers = 0;
foreach ($answers_data as $answer_data) {
if (strtolower($answer_data[3]) == 'x') {
$numberRightAnswers++;
}
}
}
foreach ($answers_data as $answer_data) {
$answerValue = $answer_data[2];
$correct = 0;

Loading…
Cancel
Save