Adding hotpotatoes support in exercises (removed by error)

skala
Julio Montoya 14 years ago
parent e7c88ff91b
commit cddc6478ec
  1. 87
      main/exercice/exercice.php
  2. 35
      main/exercice/hotpotatoes.php
  3. 13
      main/inc/lib/document.lib.php

@ -561,7 +561,7 @@ if ($show == 'test') {
$nbrHpTests = $nbrTests;
} else {
$nbrHpTests = $nbrActiveTests;
}
}
$nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
echo '<span style="float:right">';
@ -739,8 +739,7 @@ if ($show == 'test') {
echo Display::tag('tr',$header_list);
if (!empty($exercise_list))
foreach ($exercise_list as $row) {
foreach ($exercise_list as $row) {
//echo '<div id="tabs-'.$i.'">';
@ -777,7 +776,7 @@ if ($show == 'test') {
//echo '<p>';
//echo $session_img;
$url = '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
$url = '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'"><img src="../img/quiz.gif" alt="HotPotatoes" /> '.$row['title'].'</a>';
$item = Display::tag('td',$url.' '.$session_img);
$exid = $row['id'];
@ -874,12 +873,10 @@ if ($show == 'test') {
//show results student
$rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
}
$uid = api_get_user_id();
//this query might be improved later on by ordering by the new "tms" field rather than by exe_id
//This query might be improved later on by ordering by the new "tms" field rather than by exe_id
$qry = "SELECT * FROM $TBL_TRACK_EXERCICES
WHERE exe_exo_id = '" . $row['id'] . "' and exe_user_id = '" . $uid . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = '" . api_get_session_id() . "'
WHERE exe_exo_id = '" . $row['id'] . "' and exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = '" . api_get_session_id() . "'
ORDER BY exe_id DESC";
$qryres = Database::query($qry);
$num = Database :: num_rows($qryres);
@ -937,6 +934,78 @@ if ($show == 'test') {
echo '</div>';*/
} // end foreach()
//Hot potatoes
if ($is_allowedToEdit) {
$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) ($limitExPage +1); // only .htm or .html files listed
} else {
$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
}
$result = Database::query($sql);
while ($row = Database :: fetch_array($result, 'ASSOC')) {
$attribute['path'][] = $row['path'];
$attribute['visibility'][] = $row['visibility'];
$attribute['comment'][] = $row['comment'];
}
$nbrActiveTests = 0;
if (is_array($attribute['path'])) {
while (list ($key, $path) = each($attribute['path'])) {
$item = '';
list ($a, $vis) = each($attribute['visibility']);
if (strcmp($vis, "1") == 0) {
$active = 1;
} else {
$active = 0;
}
$title = GetQuizName($path, $documentPath);
if ($title == '') {
$title = basename($path);
}
// prof only
if ($is_allowedToEdit) {
$item = Display::tag('td','<img src="../img/hotpotatoes_s.png" alt="HotPotatoes" /> <a href="showinframes.php?file='.$path.'&cid='.$_course['official_code'].'&uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'>'.$title.'</a> ');
$item .= Display::tag('td','-');
$actions = '<a href="adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path.'">
<img src="../img/wizard.gif" border="0" title="'.get_lang('Modify').'" alt="'.api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset).'" /></a>';
// if active
if ($active) {
$nbrActiveTests = $nbrActiveTests +1;
$actions .= ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=disable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/visible.gif" border="0" title="'.get_lang('Deactivate').'" alt="'.api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset).'" /></a>';
} else { // else if not active
$actions .=' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=enable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/invisible.gif" border="0" title="'.get_lang('Activate').'" alt="'.api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset).'" /></a>';
}
$actions .= '<a href="'.$exercicePath.'?'.api_get_cidreq().'&amp;hpchoice=delete&amp;file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset).' '.$title."?").'\')) return false;"><img src="../img/delete.png" border="0" title="'.get_lang('Delete').'" alt="'.api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset).'" /></a>';
//$actions .='<img src="../img/lp_quiz_na.gif" border="0" title="'.get_lang('NotMarkActivity').'" alt="" />';
$item .= Display::tag('td', $actions);
echo Display::tag('tr',$item);
} else { // student only
if ($active == 1) {
$nbrActiveTests = $nbrActiveTests +1;
$item .= Display::tag('td', '<a href="showinframes.php?'.api_get_cidreq().'&amp;file='.$path.'&amp;cid='.$_course['official_code'].'&amp;uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'">'.$title.'</a>');
$item .= Display::tag('td', '');
$item .= Display::tag('td', '');
$item .= Display::tag('td', '');
echo Display::tag('tr',$item);
}
}
}
}
echo '</table>';
echo '</div>';
}

@ -48,8 +48,6 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true);
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
// Setting some variables.
$baseServDir = $_configuration['root_sys'];
$baseServUrl = $_configuration['url_append'].'/';
$document_sys_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$uploadPath = '/HotPotatoes_files';
$finish = (!empty($_POST['finish']) ? $_POST['finish'] : 0);
@ -65,9 +63,9 @@ if (api_is_allowed_to_edit(null, true)) {
// If the directory doesn't exist, create the "HotPotatoes" directory.
$doc_id = add_document($_course, '/HotPotatoes_files', 'folder', 0, get_lang('HotPotatoesFiles'));
// Update properties in dbase (in any case).
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
// Make invisible (in any case) - why?
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id());
}
}
@ -108,21 +106,24 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
//if it's a zip, allow zip upload
$unzip = 1;
}
if ($finish == 0) {
// Generate new test folder if on first step of file upload.
$filename = replace_dangerous_char(trim($_FILES['userFile']['name']), 'strict');
$fld = GenerateHpFolder($document_sys_path.$uploadPath.'/');
$filename = replace_dangerous_char(trim($_FILES['userFile']['name']), 'strict');
$fld = GenerateHpFolder($document_sys_path.$uploadPath.'/');
$doc_id = add_document($_course, '/HotPotatoes_files/'.$fld, 'folder', 0, $fld);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
@mkdir($document_sys_path.$uploadPath.'/'.$fld, api_get_permissions_for_new_directories());
$doc_id = add_document($_course, '/HotPotatoes_files/'.$fld, 'folder', 0, $fld);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
} else {
// It is not the first step... get the filename directly from the system params.
$filename = $_FILES['userFile']['name'];
}
/*if (treat_uploaded_file($_FILES['userFile'], $document_sys_path, $uploadPath."/".$fld, $maxFilledSpace, $unzip))*/
$allow_output_on_success = false;
if (handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath.'/'.$fld, $_user['user_id'], null, null, $maxFilledSpace, $unzip, '', $allow_output_on_success)) {
$allow_output_on_success = false;
if (handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath.'/'.$fld, api_get_user_id(), null, null, $maxFilledSpace, $unzip, '', $allow_output_on_success)) {
if ($finish == 2) {
$imgparams = $_POST['imgparams'];
@ -154,24 +155,19 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
/*, visibility='v' */
Database::query($query);
api_item_property_update($_course, TOOL_QUIZ, $id, 'QuizAdded', $_user['user_id']);
api_item_property_update($_course, TOOL_QUIZ, $id, 'QuizAdded', api_get_user_id());
} else {
if ($finish == 2) {
// delete?
//$dialogBox .= get_lang('NoImg');
}
$finish = 0; // error
if (api_failure::get_last_failure() == 'not_enough_space') {
$dialogBox .= get_lang('NoSpace');
} elseif (api_failure::get_last_failure() == 'php_file_in_zip_file') {
$dialogBox .= get_lang('ZipNoPhp');
}
}
/* if ($oke==1)
{ $enableDocumentParsing=true; $oke=0;}
*/
@ -190,7 +186,7 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
echo '</div>';
if ($finish==2) { // If we are in the img upload process.
$dialogBox .= get_lang('ImgNote_st').$imgcount.get_lang('ImgNote_en').'<br />';
$dialogBox .= get_lang('ImgNote_st').$imgcount.get_lang('ImgNote_en').'<br />';
while (list($key, $string) = each($imgparams)) {
$dialogBox .= $string.'; ';
}
@ -235,11 +231,6 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
</div>';
echo '<div>'.Display::display_icon('hotpotatoes.jpg', get_lang('HotPotatoes')).'</div>';
echo '</div></div>';
?>
<?php
}
// Display the footer.
Display::display_footer();
?>
Display::display_footer();

@ -1109,15 +1109,18 @@ class DocumentManager {
$condition = "AND id_session = $session_id";
// The " d.filetype='file' " let the user see a file even if the folder is hidden see #2198
$sql = "SELECT path FROM $docTable d, $propTable ip " .
"WHERE d.id=ip.ref AND ip.tool='".TOOL_DOCUMENT."' AND d.filetype='file' AND visibility=0 $condition AND d.id = $id";
"WHERE d.id=ip.ref AND ip.tool='".TOOL_DOCUMENT."' AND d.filetype='file' $condition AND d.id = $id";
$result = Database::query($sql);
$is_visible = false;
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
//echo "$row[0] not visible";
return false;
$row = Database::fetch_array($result,'ASSOC');
if ($row['visibility'] == 1) {
$is_visible = $_SESSION ['is_allowed_in_course'] || api_is_platform_admin();
}
}
//improved protection of documents viewable directly through the url: incorporates the same protections of the course at the url of documents: access allowed for the whole world Open, access allowed for users registered on the platform Private access, document accessible only to course members (see the Users list), Completely closed; the document is only accessible to the course admin and teaching assistants.
return $_SESSION ['is_allowed_in_course'] || api_is_platform_admin();
//return $_SESSION ['is_allowed_in_course'] || api_is_platform_admin();
return $is_visible;
}

Loading…
Cancel
Save